Name | Type | is_array | initial_value |
//TESH.scrollpos=0
//TESH.alwaysfold=0
/*************************************************
* CustomWindow v1.1.1.2 by Maker
*
* Allows the creation of custom windows.
*
* Requires Table by Bribe and TimerUtils by Vexorian
*
* Importing instructions:
* 1. Import all images with the name beginning with Border.
* There are 8 of them. Also copy background.TGA.
* 2. Make sure the image paths are correct in the globals block in this library.
* 3. Copy CustomTextWindow, Table and TimerUtilsEx into your map.
*
*
* API
*
* struct CustowWindow
*
* o method destroy takes nothing returns nothing
* Destroys a custom window
* o method setHeight takes real height returns nothing
* Sets the height of a custom window
* o method setTransparency takes integer alpha returns nothing
* Sets the transparency of a window
* o method show takes boolean show returns nothing
* Shows/hides a custom window
* o static method create takes real scale, real sizeX, real sizeY, real posX, real posY, integer imageType returns thistype
* Creates a custom window
*
* struct CustomTextWindow
*
* o method destroy takes nothing returns nothing
* Destroys a custom text window
* o method show takes boolean show returns nothing
* Shows/hides a custom text window
* o method setTransparency takes integer alpha returns nothing
* Sets the transparency of a custom text window
* o method fadeOut real time, real delay, boolean destroy returns nothing
* Fades out a custom text window. Time is the fade time, delay the time before fading.
* If destroy is true, the window will be destroyed when it has faded out.
* o method setHeight real height returns nothing
* Sets the height of a custom window
* o static method create takes string title, string text, real posX, real posY, real textSize, real borderScale, integer maxWidth, integer imageType returns thistype
* Creates a custom text window
*
*
* Try to avoid large text sizes, over about 28, since
* the game engine will add a line break if text tag width
* would become too large.
*
************************************************/
library CustomWindow requires Table, TimerUtils
globals
private constant string BACKGROUND = "war3mapImported\\background.TGA"
private constant string BOTTOM_L = "war3mapImported\\BorderDownLeftNE.TGA"
private constant string TOP_L = "war3mapImported\\BorderUpLeftNE.TGA"
private constant string BOTTOM_R = "war3mapImported\\BorderDownRightNE.TGA"
private constant string TOP_R = "war3mapImported\\BorderUpRightNE.TGA"
private constant string LEFT = "war3mapImported\\BorderLeftNE.TGA"
private constant string TOP = "war3mapImported\\BorderUpNE.TGA"
private constant string RIGHT = "war3mapImported\\BorderRightNE.TGA"
private constant string BOTTOM = "war3mapImported\\BorderDownNE.TGA"
private constant integer TRANS = 200 // Transparency of the background, 0 = fully transparent, 255 = not transparent
private constant integer MAXCHARS = 38 // Maximum number of characters in a row
private constant real CHARHEIGHT = 4 // Height of a letter in pixels
private constant real CHARWIDTH = 1.5 // Width of a letter in pixels
private constant real BORDERWIDTH = 28 // Width of borders, visible portion of default size
private constant real LOOPTIME = 0.03125
/* Use CHARHEIGHT and CHARWIDTH to adjust the window's wrapping around the text */
endglobals
// Not to be changed
globals
private real X
private real Y
private constant real DEFSIZE = 64 // Size of visible portion of an image
private constant real RATIO = (DEFSIZE+2)/DEFSIZE
private location LOC = Location(0,0)
endglobals
struct CustomWindow extends array
private integer images
private static Table array imgs
private static integer ic = 0
private static integer ir = 0
private thistype rn
method destroy takes nothing returns nothing
local integer i = this.images
loop
exitwhen i == 0
call DestroyImage(imgs[this].image[i])
set i = i - 1
endloop
call imgs[this].destroy()
set .rn = ir
set ir = this
endmethod
method setHeight takes real height returns nothing
local integer i = .images
loop
exitwhen i == 0
call SetImageConstantHeight(imgs[this].image[i], true, height)
set i = i - 1
endloop
endmethod
method show takes boolean show returns nothing
local integer i = .images
loop
exitwhen i == 0
call SetImageRenderAlways(imgs[this].image[i], show)
call ShowImage(imgs[this].image[i], show)
set i = i - 1
endloop
endmethod
method setTransparency takes integer alpha returns nothing
local integer i = .images
loop
exitwhen i == 0
if i != 1 then
call SetImageColor(imgs[this].image[i], 255, 255, 255, alpha)
elseif alpha < TRANS then
call SetImageColor(imgs[this].image[i], 255, 255, 255, alpha)
else
call SetImageColor(imgs[this].image[i], 255, 255, 255, TRANS)
endif
set i = i - 1
endloop
endmethod
private static method addRecycle takes nothing returns thistype
local thistype this
if ir == 0 then
set ic = ic + 1
set this = ic
else
set this = ir
set ir = .rn
endif
return this
endmethod
// posX and posY are the coordinates of the center of the image
static method create takes real borderScale, real sizeX, real sizeY, real posX, real posY, integer imageType returns thistype
local thistype this = thistype.addRecycle()
local integer i = 0 // Image counter
local integer j // For loops
local integer nx = 0 // How many x pieces
local integer ny = 0 // How many y pieces
local real sx = 0 // X size
local real sy = 0 // Y size
local real cx = 0 // X coordinate of lower left corner
local real cy = 0 // Y coordinate of lower left corner
local real bwidth // Border width
local real sxa
local real sya
set X = DEFSIZE*borderScale // Visible image size of one image
set Y = DEFSIZE*borderScale
set bwidth = BORDERWIDTH * borderScale // Visible border width
set imgs[this] = Table.create()
if sizeX < 2*X then
set sizeX = 2*X
endif
set sx = X * RATIO // X size of one block, corners
set nx = R2I((sizeX-2*X) / X) // How many top/bottom blocks, excluding corner blocks
set sxa = (sizeX-2*X) / (nx * X) * sx // X size of one block, top and bottom
set cx = posX - sizeX/2 + X - borderScale
if sizeY < 2*Y then
set sizeY = 2*Y
endif
set sy = Y * RATIO
set ny = R2I((sizeY-2*Y) / Y)
set sya = (sizeY-2*X) / (ny * X) * sy
set cy = posY - sizeY/2 + Y - borderScale
set i = i + 1 // Background
set imgs[this].image[i] = CreateImage(BACKGROUND, sizeX-bwidth, sizeY-bwidth, 0, posX - (sizeX-bwidth)/2, posY - (sizeY-bwidth)/2, 0, 0, 0, 0, imageType)
call SetImageColor(imgs[this].image[i], 255, 255, 255, TRANS)
set posX = posX - borderScale
set posY = posY - borderScale
set i = i + 1 // Down left corner
set imgs[this].image[i] = CreateImage(BOTTOM_L, sx, sy, 0, posX - sizeX/2, posY - sizeY/2, 0, 0, 0, 0, imageType)
set i = i + 1 // Up left corner
set imgs[this].image[i] = CreateImage(TOP_L, sx, sy, 0, posX - sizeX/2, posY + sizeY/2 - sy/RATIO, 0, 0, 0, 0, imageType)
set i = i + 1 // Up right corner
set imgs[this].image[i] = CreateImage(TOP_R, sx, sy, 0, posX + sizeX/2 - X, posY + sizeY/2 - sy/RATIO, 0, 0, 0, 0, imageType)
set i = i + 1 // Down right corner
set imgs[this].image[i] = CreateImage(BOTTOM_R, sx, sy, 0, posX + sizeX/2 - X, posY - sizeY/2, 0, 0, 0, 0, imageType)
set j = 0
loop // Up and down blocks
set i = i + 1
set imgs[this].image[i] = CreateImage(TOP, sxa, sy, 0, cx, posY + sizeY/2 - Y, 0, 0, 0, 0, imageType)
set i = i + 1
set imgs[this].image[i] = CreateImage(BOTTOM, sxa, sy, 0, cx, posY - sizeY/2, 0, 0, 0, 0, imageType)
set j = j + 1
exitwhen j == nx
set cx = cx + sxa/RATIO
endloop
set j = 0
loop // Left and right blocks
set i = i + 1
set imgs[this].image[i] = CreateImage(LEFT, sx, sya, 0, posX - sizeX/2, cy, 0, 0, 0, 0, imageType)
set i = i + 1
set imgs[this].image[i] = CreateImage(RIGHT, sx, sya, 0, posX + sizeX/2 - X, cy, 0, 0, 0, 0, imageType)
set j = j + 1
exitwhen j == ny
set cy = cy + sya/RATIO
endloop
set this.images = i
return this
endmethod
endstruct
struct CustomTextWindow extends array
private real ttPosX
private real ttPosY
private real height
private real ttSize
private integer visibility
private integer fadeRate
private integer fadeOutRate
private timer t
private timer tOut
private string title
private string text
texttag tt
private boolean destroys
private boolean destroysOut
CustomWindow cw
private thistype rn
private static integer ic = 0
private static integer ir = 0
method destroy takes nothing returns nothing
if this.tt != null then
call DestroyTextTag(this.tt)
set this.tt = null
endif
set this.title = null
set this.text = null
set this.destroys = false
if this.t != null then
call ReleaseTimer(this.t)
set this.t = null
endif
if this.tOut != null then
call ReleaseTimer(this.tOut)
set this.tOut = null
endif
call this.cw.destroy()
set this.rn = ir
set ir = this
endmethod
method setTransparency takes integer alpha returns nothing
set this.visibility = alpha
if this.tt == null and alpha > 0 and alpha < 255 then
call this.show(true)
call SetTextTagPermanent(this.tt, false)
call SetTextTagColor(this.tt, 255, 255, 255, alpha)
elseif alpha > 0 then
call SetTextTagColor(this.tt, 255, 255, 255, alpha)
elseif this.tt != null and alpha <= 0 then
call DestroyTextTag(this.tt)
set this.tt = null
endif
call this.cw.setTransparency(alpha)
endmethod
method show takes boolean show returns nothing
if show then
if this.tt == null then
call MoveLocation(LOC, .ttPosX, .ttPosY)
set this.tt = CreateTextTag()
call SetTextTagText(this.tt, this.text, this.ttSize/1000)
call SetTextTagPos(this.tt, this.ttPosX, this.ttPosY, .height - GetLocationZ(LOC))
call SetTextTagColor(this.tt, 255, 255, 255, 255)
call SetTextTagVisibility(this.tt, true)
endif
else
if this.t != null then
call PauseTimer(this.t)
endif
call DestroyTextTag(this.tt)
set this.tt = null
endif
call this.cw.show(show)
endmethod
private static method fade takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
set this.visibility = this.visibility - this.fadeRate
if this.visibility > 0 and this.visibility < 255 then
call this.setTransparency(this.visibility)
else
call PauseTimer(this.t)
if this.destroys then
call this.destroy()
else
if this.fadeRate < 0 then
call this.setTransparency(255)
elseif this.fadeRate > 0 then
call this.setTransparency(0)
endif
if this.t != null then
call ReleaseTimer(this.t)
set this.t = null
endif
endif
endif
endmethod
private static method fadeDelay takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
set this.fadeRate = this.fadeOutRate
set this.destroys = this.destroysOut
call SetTextTagPermanent(this.tt, false)
if this.tOut != null then
call ReleaseTimer(this.tOut)
set this.tOut = null
endif
if this.t == null then
set this.t = NewTimerEx(this)
endif
call TimerStart(this.t, LOOPTIME, true, function thistype.fade)
endmethod
method fadeIn takes real time returns nothing
if .t == null then
set .t = NewTimerEx(this)
endif
if time == 0 then
set time = 0.01
endif
set .destroys = false
set .fadeRate = -(R2I(255*LOOPTIME/time) + 1)
call SetTextTagPermanent(.tt, false)
call TimerStart(.t, LOOPTIME, true, function thistype.fade)
endmethod
method fadeOut takes real time, real delay, boolean destroys returns nothing
if time == 0 then
set time = 0.01
endif
set .fadeOutRate = R2I(255*LOOPTIME/time) + 1
set .destroysOut = destroys
call SetTextTagPermanent(.tt, false)
if delay != 0 then
if .tOut == null then
set .tOut = NewTimerEx(this)
endif
call TimerStart(.tOut, delay, false, function thistype.fadeDelay)
else
if .tOut != null then
call PauseTimer(.tOut)
endif
if .t == null then
set .t = NewTimerEx(this)
endif
set this.fadeRate = this.fadeOutRate
set this.destroys = this.destroysOut
call TimerStart(.t, LOOPTIME, true, function thistype.fade)
endif
endmethod
method setHeight takes real height returns nothing
call MoveLocation(LOC, .ttPosX, .ttPosY)
call SetTextTagPos(.tt, .ttPosX, .ttPosY, height - GetLocationZ(LOC))
call this.cw.setHeight(height)
set .height = height
endmethod
private static method addRecycle takes nothing returns thistype
local thistype this
if 0==ir then
set ic=ic+1
set this=ic
else
set this=ir
set ir=.rn
endif
return this
endmethod
// posX and pos Y are the coordinates of bottom left corner
static method create takes string title, string text, real posX, real posY, real textSize, real borderScale, integer maxWidth, integer imageType returns thistype
local thistype this = thistype.addRecycle()
local integer i
local integer rows = 1
local integer wordlength = 0
local string word = null
local string newStr = null
local string char
local integer chars = 0
local integer charsMax = 0
local real width
local real sizeX
local real sizeY
if maxWidth > MAXCHARS or maxWidth == 0 then
set maxWidth = MAXCHARS
endif
if text != null then
set rows = rows + 1
set width = 0
set i = 0
loop
set char = SubString(text, i, i+1)
if char == " " or char == "" then
if chars < maxWidth then
set newStr = newStr + " " + word
if char == " " then
set chars = chars + 1
endif
if chars > charsMax then
set charsMax = chars
endif
else
if chars - wordlength > charsMax then
set charsMax = chars - wordlength
endif
set newStr = newStr + "\n" + " " + word
set chars = 1 + wordlength
set rows = rows + 1
endif
set word = null
set wordlength = 0
else
set chars = chars + 1
set wordlength = wordlength + 1
set word = word + char
endif
exitwhen char == ""
set i = i + 1
endloop
else
set charsMax = StringLength(title) + 2
endif
call MoveLocation(LOC, posX, posY)
set this.height = GetLocationZ(LOC)
set sizeX = charsMax * CHARWIDTH * textSize/5 + 2*DEFSIZE*borderScale
set sizeY = rows * CHARHEIGHT * textSize/5 + 2*DEFSIZE*borderScale
set this.ttSize = textSize
set this.ttPosX = posX
set this.ttPosY = posY
set this.title = title
set this.text = "|cffffcc00" + this.title + "|r\n" + newStr
set this.cw = CustomWindow.create(borderScale, sizeX, sizeY, posX+sizeX/2-DEFSIZE*borderScale, posY+sizeY/2-DEFSIZE*borderScale, imageType)
set char = null
set newStr = null
return this
endmethod
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Table // made by Bribe, special thanks to Nestharus, version 3.0.0.0
/*
API
------------
struct Table
| static method create takes nothing returns Table
| create a new Table
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush all stored values inside of it
|
| method remove takes integer key returns nothing
| remove the value at index "key"
|
| method operator []= takes integer key, $TYPE$ value returns nothing
| assign "value" to index "key"
|
| method operator [] takes integer key returns $TYPE$
| load the value at index "key"
|
| method has takes integer key returns boolean
| whether or not the key was assigned
|
----------------
struct TableArray
| static method operator [] takes integer array_size returns TableArray
| create a new array of Tables of size "array_size"
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush and destroy it
|
| method operator size takes nothing returns integer
| returns the size of the TableArray
|
| method operator [] takes integer key returns Table
| returns a Table accessible exclusively to index "key"
*/
globals
private hashtable ht = InitHashtable() //The last hashtable you need
private integer more = 2 //Index generation for Tables (above 2)
private integer less = 0 //Index generation for TableArrays (below 0)
endglobals
private struct dex extends array
static method operator size takes nothing returns Table
return 1
endmethod
static method operator list takes nothing returns Table
return 2
endmethod
endstruct
private struct handles extends array
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private struct agents extends array
method operator []= takes integer key, agent value returns nothing
call SaveAgentHandle(ht, this, key, value)
endmethod
endstruct
//! textmacro NEW_ARRAY_BASIC takes SUPER, FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSaved$SUPER$(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSaved$SUPER$(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//! textmacro NEW_ARRAY takes FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$Handle(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$Handle(ht, this, key, value)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//! runtextmacro NEW_ARRAY_BASIC("Real", "Real", "real")
//! runtextmacro NEW_ARRAY_BASIC("Boolean", "Boolean", "boolean")
//! runtextmacro NEW_ARRAY_BASIC("String", "Str", "string")
//! runtextmacro NEW_ARRAY("Player", "player")
//! runtextmacro NEW_ARRAY("Widget", "widget")
//! runtextmacro NEW_ARRAY("Destructable", "destructable")
//! runtextmacro NEW_ARRAY("Item", "item")
//! runtextmacro NEW_ARRAY("Unit", "unit")
//! runtextmacro NEW_ARRAY("Ability", "ability")
//! runtextmacro NEW_ARRAY("Timer", "timer")
//! runtextmacro NEW_ARRAY("Trigger", "trigger")
//! runtextmacro NEW_ARRAY("TriggerCondition", "triggercondition")
//! runtextmacro NEW_ARRAY("TriggerAction", "triggeraction")
//! runtextmacro NEW_ARRAY("TriggerEvent", "event")
//! runtextmacro NEW_ARRAY("Force", "force")
//! runtextmacro NEW_ARRAY("Group", "group")
//! runtextmacro NEW_ARRAY("Location", "location")
//! runtextmacro NEW_ARRAY("Rect", "rect")
//! runtextmacro NEW_ARRAY("BooleanExpr", "boolexpr")
//! runtextmacro NEW_ARRAY("Sound", "sound")
//! runtextmacro NEW_ARRAY("Effect", "effect")
//! runtextmacro NEW_ARRAY("UnitPool", "unitpool")
//! runtextmacro NEW_ARRAY("ItemPool", "itempool")
//! runtextmacro NEW_ARRAY("Quest", "quest")
//! runtextmacro NEW_ARRAY("QuestItem", "questitem")
//! runtextmacro NEW_ARRAY("DefeatCondition", "defeatcondition")
//! runtextmacro NEW_ARRAY("TimerDialog", "timerdialog")
//! runtextmacro NEW_ARRAY("Leaderboard", "leaderboard")
//! runtextmacro NEW_ARRAY("Multiboard", "multiboard")
//! runtextmacro NEW_ARRAY("MultiboardItem", "multiboarditem")
//! runtextmacro NEW_ARRAY("Trackable", "trackable")
//! runtextmacro NEW_ARRAY("Dialog", "dialog")
//! runtextmacro NEW_ARRAY("Button", "button")
//! runtextmacro NEW_ARRAY("TextTag", "texttag")
//! runtextmacro NEW_ARRAY("Lightning", "lightning")
//! runtextmacro NEW_ARRAY("Image", "image")
//! runtextmacro NEW_ARRAY("Ubersplat", "ubersplat")
//! runtextmacro NEW_ARRAY("Region", "region")
//! runtextmacro NEW_ARRAY("FogState", "fogstate")
//! runtextmacro NEW_ARRAY("FogModifier", "fogmodifier")
//! runtextmacro NEW_ARRAY("Hashtable", "hashtable")
struct Table extends array
// Implement modules for intuitive type-syntax
implement realm
implement booleanm
implement stringm
implement playerm
implement widgetm
implement destructablem
implement itemm
implement unitm
implement abilitym
implement timerm
implement triggerm
implement triggerconditionm
implement triggeractionm
implement eventm
implement forcem
implement groupm
implement locationm
implement rectm
implement boolexprm
implement soundm
implement effectm
implement unitpoolm
implement itempoolm
implement questm
implement questitemm
implement defeatconditionm
implement timerdialogm
implement leaderboardm
implement multiboardm
implement multiboarditemm
implement trackablem
implement dialogm
implement buttonm
implement texttagm
implement lightningm
implement imagem
implement ubersplatm
implement regionm
implement fogstatem
implement fogmodifierm
implement hashtablem
method operator handle takes nothing returns handles
return this
endmethod
method operator agent takes nothing returns agents
return this
endmethod
// set this = a[GetSpellAbilityId()]
method operator [] takes integer key returns Table
return LoadInteger(ht, this, key)
endmethod
// set a[389034] = 8192
method operator []= takes integer key, Table a returns nothing
call SaveInteger(ht, this, key, a)
endmethod
// set b = a.has(2493223)
method has takes integer key returns boolean
return HaveSavedInteger(ht, this, key)
endmethod
// call a.remove(294080)
method remove takes integer key returns nothing
call RemoveSavedInteger(ht, this, key)
endmethod
// Remove all data from a Table instance
method flush takes nothing returns nothing
call FlushChildHashtable(ht, this)
endmethod
// local Table a = Table.create()
static method create takes nothing returns Table
local Table this = dex.list[0]
if this == 0 then
set more = more + 1
set this = more
else
set dex.list[0] = dex.list[this]
call dex.list.remove(this)
endif
debug set dex.list[this] = -1
return this
endmethod
// Removes all data from a Table instance and recycles its index.
//
// call a.destroy()
//
method destroy takes nothing returns nothing
debug if dex.list[this] != -1 then
debug call BJDebugMsg("Table Error: Tried to double-free instance: " + I2S(this))
debug return
debug endif
call this.flush()
set dex.list[this] = dex.list[0]
set dex.list[0] = this
endmethod
endstruct
struct TableArray extends array
//Returns a new TableArray to do your bidding. Simply use:
//
// local TableArray ta = TableArray[array_size]
//
static method operator [] takes integer array_size returns TableArray
local Table a = dex.size[array_size] //Get the unique recycle list for this array size
local TableArray this = a[0] //The last-destroyed TableArray that had this array size
debug if array_size <= 0 then
debug call BJDebugMsg("TypeError: Invalid specified TableArray size: " + I2S(array_size))
debug return 0
debug endif
if this == 0 then
set less = less - array_size
set this = less
else
set a[0] = a[this] //Set the last destroyed to the last-last destroyed
call a.remove(this) //Clear hash memory
endif
set dex.size[this] = array_size //This remembers the array size
return this
endmethod
//Returns the size of the TableArray
method operator size takes nothing returns integer
return dex.size[this]
endmethod
//da[integer a].unit[integer b] = unit u
//da[integer a][integer c] = integer d
//
//Inline-friendly when not running in debug mode
//
method operator [] takes integer key returns Table
static if DEBUG_MODE then
local integer i = this.size
if i == 0 then
call BJDebugMsg("IndexError: Tried to get key from invalid TableArray instance: " + I2S(this))
return 0
elseif key < 0 or key >= i then
call BJDebugMsg("IndexError: Tried to get key [" + I2S(key) + "] from outside TableArray bounds: " + I2S(i))
return 0
endif
endif
return this + key
endmethod
//Destroys a TableArray without flushing it; assumed you'd call .flush()
//if you want it flushed too. This is public so that if you are flushing
//instances the whole time you don't waste efficiency when disposing the
//TableArray.
//
method destroy takes nothing returns nothing
local Table a = dex.size[this.size]
debug if this.size <= 0 then
debug call BJDebugMsg("TypeError: Tried to destroy an invalid TableArray: " + I2S(this))
debug return
debug endif
if a == 0 then
//Create an array to index recycled instances with their array size
set a = Table.create()
set dex.size[this.size] = a
endif
call dex.size.remove(this) //Clear the array size from hash memory
set a[this] = a[0]
set a[0] = this
endmethod
//All you need to know about this one is that it won't hit the op limit.
private static method clean takes Table a, integer end returns nothing
local integer i = a + 5000
if i < end then
call clean.evaluate(i, end)
set end = i
endif
loop
call a.flush()
set a = a + 1
exitwhen a == end
endloop
endmethod
//Flushes the TableArray and also destroys it. Doesn't get any more
//similar to the FlushParentHashtable native than this.
//
method flush takes nothing returns nothing
local integer end = this.size + this
debug if this == end then
debug call BJDebugMsg("TypeError: Tried to flush an invalid TableArray instance: " + I2S(this))
debug return
debug endif
call clean.evaluate(this, end)
call this.destroy()
endmethod
endstruct
endlibrary
//TESH.scrollpos=222
//TESH.alwaysfold=0
library TimerUtils initializer init
//*********************************************************************
//* TimerUtils (red+blue+orange flavors for 1.24b+) 2.0
//* ----------
//*
//* To implement it , create a custom text trigger called TimerUtils
//* and paste the contents of this script there.
//*
//* To copy from a map to another, copy the trigger holding this
//* library to your map.
//*
//* (requires vJass) More scripts: htt://www.wc3c.net
//*
//* For your timer needs:
//* * Attaching
//* * Recycling (with double-free protection)
//*
//* set t=NewTimer() : Get a timer (alternative to CreateTimer)
//* set t=NewTimerEx(x) : Get a timer (alternative to CreateTimer), call
//* Initialize timer data as x, instead of 0.
//*
//* ReleaseTimer(t) : Relese a timer (alt to DestroyTimer)
//* SetTimerData(t,2) : Attach value 2 to timer
//* GetTimerData(t) : Get the timer's value.
//* You can assume a timer's value is 0
//* after NewTimer.
//*
//* Multi-flavor:
//* Set USE_HASH_TABLE to true if you don't want to complicate your life.
//*
//* If you like speed and giberish try learning about the other flavors.
//*
//********************************************************************
//================================================================
globals
//How to tweak timer utils:
// USE_HASH_TABLE = true (new blue)
// * SAFEST
// * SLOWEST (though hash tables are kind of fast)
//
// USE_HASH_TABLE = false, USE_FLEXIBLE_OFFSET = true (orange)
// * kinda safe (except there is a limit in the number of timers)
// * ALMOST FAST
//
// USE_HASH_TABLE = false, USE_FLEXIBLE_OFFSET = false (red)
// * THE FASTEST (though is only faster than the previous method
// after using the optimizer on the map)
// * THE LEAST SAFE ( you may have to tweak OFSSET manually for it to
// work)
//
private constant boolean USE_HASH_TABLE = true
private constant boolean USE_FLEXIBLE_OFFSET = false
private constant integer OFFSET = 0x100000
private integer VOFFSET = OFFSET
//Timers to preload at map init:
private constant integer QUANTITY = 256
//Changing this to something big will allow you to keep recycling
// timers even when there are already AN INCREDIBLE AMOUNT of timers in
// the stack. But it will make things far slower so that's probably a bad idea...
private constant integer ARRAY_SIZE = 8190
endglobals
//==================================================================================================
globals
private integer array data[ARRAY_SIZE]
private hashtable ht
endglobals
//It is dependent on jasshelper's recent inlining optimization in order to perform correctly.
function SetTimerData takes timer t, integer value returns nothing
static if(USE_HASH_TABLE) then
// new blue
call SaveInteger(ht,0,GetHandleId(t), value)
elseif (USE_FLEXIBLE_OFFSET) then
// orange
static if (DEBUG_MODE) then
if(GetHandleId(t)-VOFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
set data[GetHandleId(t)-VOFFSET]=value
else
// new red
static if (DEBUG_MODE) then
if(GetHandleId(t)-OFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
set data[GetHandleId(t)-OFFSET]=value
endif
endfunction
function GetTimerData takes timer t returns integer
static if(USE_HASH_TABLE) then
// new blue
return LoadInteger(ht,0,GetHandleId(t) )
elseif (USE_FLEXIBLE_OFFSET) then
// orange
static if (DEBUG_MODE) then
if(GetHandleId(t)-VOFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
return data[GetHandleId(t)-VOFFSET]
else
// new red
static if (DEBUG_MODE) then
if(GetHandleId(t)-OFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
return data[GetHandleId(t)-OFFSET]
endif
endfunction
//==========================================================================================
globals
private timer array tT[ARRAY_SIZE]
private integer tN = 0
private constant integer HELD=0x28829022
//use a totally random number here, the more improbable someone uses it, the better.
private boolean didinit = false
endglobals
private keyword init
//==========================================================================================
// I needed to decide between duplicating code ignoring the "Once and only once" rule
// and using the ugly textmacros. I guess textmacros won.
//
//! textmacro TIMERUTIS_PRIVATE_NewTimerCommon takes VALUE
// On second thought, no.
//! endtextmacro
function NewTimerEx takes integer value returns timer
if (tN==0) then
if (not didinit) then
//This extra if shouldn't represent a major performance drawback
//because QUANTITY rule is not supposed to be broken every day.
call init.evaluate()
set tN = tN - 1
else
//If this happens then the QUANTITY rule has already been broken, try to fix the
// issue, else fail.
debug call BJDebugMsg("NewTimer: Warning, Exceeding TimerUtils_QUANTITY, make sure all timers are getting recycled correctly")
set tT[0]=CreateTimer()
static if( not USE_HASH_TABLE) then
debug call BJDebugMsg("In case of errors, please increase it accordingly, or set TimerUtils_USE_HASH_TABLE to true")
static if( USE_FLEXIBLE_OFFSET) then
if (GetHandleId(tT[0])-VOFFSET<0) or (GetHandleId(tT[0])-VOFFSET>=ARRAY_SIZE) then
//all right, couldn't fix it
call BJDebugMsg("NewTimer: Unable to allocate a timer, you should probably set TimerUtils_USE_HASH_TABLE to true or fix timer leaks.")
return null
endif
else
if (GetHandleId(tT[0])-OFFSET<0) or (GetHandleId(tT[0])-OFFSET>=ARRAY_SIZE) then
//all right, couldn't fix it
call BJDebugMsg("NewTimer: Unable to allocate a timer, you should probably set TimerUtils_USE_HASH_TABLE to true or fix timer leaks.")
return null
endif
endif
endif
endif
else
set tN=tN-1
endif
call SetTimerData(tT[tN],value)
return tT[tN]
endfunction
function NewTimer takes nothing returns timer
return NewTimerEx(0)
endfunction
//==========================================================================================
function ReleaseTimer takes timer t returns nothing
if(t==null) then
debug call BJDebugMsg("Warning: attempt to release a null timer")
return
endif
if (tN==ARRAY_SIZE) then
debug call BJDebugMsg("Warning: Timer stack is full, destroying timer!!")
//stack is full, the map already has much more troubles than the chance of bug
call DestroyTimer(t)
else
call PauseTimer(t)
if(GetTimerData(t)==HELD) then
debug call BJDebugMsg("Warning: ReleaseTimer: Double free!")
return
endif
call SetTimerData(t,HELD)
set tT[tN]=t
set tN=tN+1
endif
endfunction
private function init takes nothing returns nothing
local integer i=0
local integer o=-1
local boolean oops = false
if ( didinit ) then
return
else
set didinit = true
endif
static if( USE_HASH_TABLE ) then
set ht = InitHashtable()
loop
exitwhen(i==QUANTITY)
set tT[i]=CreateTimer()
call SetTimerData(tT[i], HELD)
set i=i+1
endloop
set tN = QUANTITY
else
loop
set i=0
loop
exitwhen (i==QUANTITY)
set tT[i] = CreateTimer()
if(i==0) then
set VOFFSET = GetHandleId(tT[i])
static if(USE_FLEXIBLE_OFFSET) then
set o=VOFFSET
else
set o=OFFSET
endif
endif
if (GetHandleId(tT[i])-o>=ARRAY_SIZE) then
exitwhen true
endif
if (GetHandleId(tT[i])-o>=0) then
set i=i+1
endif
endloop
set tN = i
exitwhen(tN == QUANTITY)
set oops = true
exitwhen not USE_FLEXIBLE_OFFSET
debug call BJDebugMsg("TimerUtils_init: Failed a initialization attempt, will try again")
endloop
if(oops) then
static if ( USE_FLEXIBLE_OFFSET) then
debug call BJDebugMsg("The problem has been fixed.")
//If this message doesn't appear then there is so much
//handle id fragmentation that it was impossible to preload
//so many timers and the thread crashed! Therefore this
//debug message is useful.
elseif(DEBUG_MODE) then
call BJDebugMsg("There were problems and the new timer limit is "+I2S(i))
call BJDebugMsg("This is a rare ocurrence, if the timer limit is too low:")
call BJDebugMsg("a) Change USE_FLEXIBLE_OFFSET to true (reduces performance a little)")
call BJDebugMsg("b) or try changing OFFSET to "+I2S(VOFFSET) )
endif
endif
endif
endfunction
endlibrary
//TESH.scrollpos=8
//TESH.alwaysfold=0
library CustomWindowDemo initializer ExAct requires CustomWindow
globals
private string array tooltipTitles
private string array tooltipTexts
private CustomTextWindow array CTWA
private hashtable ht = InitHashtable()
endglobals
private function initTexts takes nothing returns nothing
set tooltipTitles[1] = "AGILITY"
set tooltipTitles[2] = "INTELLIGENCE"
set tooltipTitles[3] = "STRENGTH"
set tooltipTexts[1] = "Agility increases your attack speed."
set tooltipTexts[2] = "Intelligence increases your mana and mana regeneration."
set tooltipTexts[3] = "Strength is required to appear fearsome to friends and foes. Having lots of strenght allows you to bend crowbars."
set tooltipTexts[3] = "Increases damage done with swords and daggers. Increases the chance for a critical strike when a sword or a dagger is equipped."
set tooltipTitles[4] = "CUSTOM TEXT WINDOW by MAKER"
set tooltipTexts[4] = "This system allows the user to create nice windows easily. Text and border sizes can be configured. The borders are created to wrap around the text. Hover your mouse over the icons to view tooltips created by this system. Restart map to randomize new values for the tooltips."
endfunction
private function Track takes nothing returns nothing
local integer i
local integer hid = GetHandleId(GetTriggeringTrackable())
local integer id = LoadInteger(ht, hid, 2)
local real x = LoadReal(ht, hid, 0) - 100/2
local real y = LoadReal(ht, hid, 1) + 100
local CustomTextWindow ctw
if CTWA[id] == 0 then
set ctw = CustomTextWindow.create(tooltipTitles[id], tooltipTexts[id], x, y, GetRandomReal(15,25), GetRandomReal(.25, .50), GetRandomInt(20, 40), 1)
set CTWA[id] = ctw
endif
call CTWA[id].setTransparency(0) // Makes the window invisible
call CTWA[id].fadeIn(0.2) // Fades in the window over 0.2 second
call CTWA[id].fadeOut(0.3, 3, false) // Makes the window start to fade after 3 second, fades out in 0.3 seconds
set i = 1
loop
if i != id and CTWA[i] != 0 then
call CTWA[i].fadeOut(0.2, 0, false)
//call CTWA[i].show(false)
/*if id == 1 then
call CTWA[i].destroy()
else
call CTWA[i].fadeOut(0.2, 0, false)
endif*/
endif
set i = i + 1
exitwhen i == 4
endloop
endfunction
function ExAct takes nothing returns nothing
local trackable tr
local image im
local real size = 100
local real sizeBonus = 15
local real x = 0
local real y = -300
local real xOff = size//*1.5
local CustomWindow CW
local CustomTextWindow CTW
local trigger t = CreateTrigger()
call initTexts()
call TriggerAddAction(t, function Track)
call TriggerSleepAction(1)
call DisplayTimedTextToPlayer(Player(0), 0, 0, 5, "Creating windows")
call TriggerSleepAction(2)
// MAIN WINDOW ================================================/
set CTW = CustomTextWindow.create(tooltipTitles[4], "|c0000FFFF" + tooltipTexts[4] + "|r", x-500, y, 25., .4, 40, 1)
call CTW.show(true)
call TriggerSleepAction(1.5)
// AGILITY ====================================================/
set tr = CreateTrackable("Doodads\\Terrain\\InvisiblePlatform\\InvisiblePlatform.mdx", x, y, 0)
set im = CreateImage("war3mapImported\\CSagi.blp", size, size, 0, x-size/2, y - size/2, 0, 0, 0, 0, 1)
call SetImageRenderAlways(im, true)
call ShowImage(im, true)
set CW = CustomWindow.create(0.3, size+sizeBonus, size+sizeBonus, x, y, 2)
if GetLocalPlayer() == Player(0) then
call CW.show(true)
endif
//call CW.setHeight(500)
call SaveReal(ht, GetHandleId(tr), 0, x)
call SaveReal(ht, GetHandleId(tr), 1, y)
call SaveInteger(ht, GetHandleId(tr), 2, 1)
call TriggerRegisterTrackableTrackEvent(t, tr)
call TriggerSleepAction(0.8)
// INTELLIGENCE ====================================================/
set x = x + xOff
set tr = CreateTrackable("Doodads\\Terrain\\InvisiblePlatform\\InvisiblePlatform.mdx", x, y, 0)
set im = CreateImage("war3mapImported\\CSint.blp", size, size, 0, x-size/2, y - size/2, 0, 0, 0, 0, 1)
call SetImageRenderAlways(im, true)
call ShowImage(im, true)
set CW = CustomWindow.create(0.3, size+sizeBonus, size+sizeBonus, x, y, 2)
call CW.show(true)
call SaveReal(ht, GetHandleId(tr), 0, x)
call SaveReal(ht, GetHandleId(tr), 1, y)
call SaveInteger(ht, GetHandleId(tr), 2, 2)
call TriggerRegisterTrackableTrackEvent(t, tr)
call TriggerSleepAction(0.8)
// STRENGTH ====================================================/
set x = x + xOff
set tr = CreateTrackable("Doodads\\Terrain\\InvisiblePlatform\\InvisiblePlatform.mdx", x, y, 0)
set im = CreateImage("war3mapImported\\CSstr.blp", size, size, 0, x-size/2, y - size/2, 0, 0, 0, 0, 1)
call SetImageRenderAlways(im, true)
call ShowImage(im, true)
set CW = CustomWindow.create(0.3, size+sizeBonus, size+sizeBonus, x, y, 2)
call CW.show(true)
call SaveReal(ht, GetHandleId(tr), 0, x)
call SaveReal(ht, GetHandleId(tr), 1, y)
call SaveInteger(ht, GetHandleId(tr), 2, 3)
call TriggerRegisterTrackableTrackEvent(t, tr)
// =============================================================/
set t = null
set im = null
set tr = null
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library CamFreeze initializer InitTrig_CF
globals
private constant real TOUT = 0.1 // Camera update rate
private constant real TPAN = 0.1 // Camera pan time
private constant integer PLRS = 1 // Max number of players
endglobals
globals
private integer P = 0
private timer TMR = CreateTimer()
private force FOR = CreateForce()
private trigger TRG = CreateTrigger()
private camerasetup array CSA
private hashtable ht = InitHashtable()
endglobals
function CF_LoadCam takes player p returns nothing
local integer pid = GetPlayerId(p)
if GetLocalPlayer() == p then
call SetCameraPosition(LoadReal(ht, pid, StringHash("camX")), LoadReal(ht, pid, StringHash("camY")))
call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, bj_RADTODEG*LoadReal(ht, pid, StringHash("camAOA")), 0)
call SetCameraField(CAMERA_FIELD_FARZ, LoadReal(ht, pid, StringHash("camFarZ")), 0)
call SetCameraField(CAMERA_FIELD_FIELD_OF_VIEW, bj_RADTODEG*LoadReal(ht, pid, StringHash("camFOW")), 0)
call SetCameraField(CAMERA_FIELD_ROTATION, bj_RADTODEG*LoadReal(ht, pid, StringHash("camRot")), 0)
call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, LoadReal(ht, pid, StringHash("camDist")), 0)
call SetCameraField(CAMERA_FIELD_ZOFFSET, LoadReal(ht, pid, StringHash("camZOff")), 0)
endif
endfunction
function CF_SaveCam takes player p returns nothing
local integer pid = GetPlayerId(p)
if GetLocalPlayer() == p then
if not LoadBoolean(ht, GetPlayerId(p), 0) then
call SaveReal(ht, pid, StringHash("camX"), GetCameraTargetPositionX())
call SaveReal(ht, pid, StringHash("camY"), GetCameraTargetPositionY())
call SaveReal(ht, pid, StringHash("camAOA"), GetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK))
call SaveReal(ht, pid, StringHash("camFarZ"), GetCameraField(CAMERA_FIELD_FARZ))
call SaveReal(ht, pid, StringHash("camFOW"), GetCameraField(CAMERA_FIELD_FIELD_OF_VIEW))
call SaveReal(ht, pid, StringHash("camRot"), GetCameraField(CAMERA_FIELD_ROTATION))
call SaveReal(ht, pid, StringHash("camDist"), GetCameraField(CAMERA_FIELD_TARGET_DISTANCE))
call SaveReal(ht, pid, StringHash("camZOff"), GetCameraField(CAMERA_FIELD_ZOFFSET))
endif
endif
endfunction
private function Updt takes nothing returns boolean
if GetLocalPlayer() == GetFilterPlayer() then
call CameraSetupApplyForceDuration(CSA[GetPlayerId(GetFilterPlayer())], true, TPAN)
endif
return false
endfunction
private function Loop takes nothing returns nothing
call ForceEnumPlayers(FOR, function Updt)
endfunction
function CF_Release takes player p returns nothing
if LoadBoolean(ht, GetPlayerId(p), 0) then
set P = P - 1
if 0 == P then
call PauseTimer(TMR)
endif
call EnableSelect(true, true)
call ForceRemovePlayer(FOR, p)
call SaveBoolean(ht, GetPlayerId(p), 0, false)
endif
endfunction
function CF_LockPos takes player p, real x, real y returns nothing
local integer id = GetPlayerId(p)
set CSA[id] = CSA[id+PLRS]
if not(LoadBoolean(ht, GetPlayerId(p), 0)) then
call ForceAddPlayer(FOR, p)
call SaveBoolean(ht, GetPlayerId(p), 0, true)
set P = P + 1
if 1 == P then
call TimerStart(TMR, TOUT, true, function Loop)
endif
endif
//call EnableSelect(false, false)
endfunction
function CF_LockCam takes player p, camerasetup c returns nothing
local integer id = GetPlayerId(p)
set CSA[id+PLRS] = CSA[id]
set CSA[id] = c
if not(LoadBoolean(ht, GetPlayerId(p), 0)) then
call ForceAddPlayer(FOR, p)
call SaveBoolean(ht, GetPlayerId(p), 0, true)
if GetLocalPlayer() == p then
call CameraSetupApplyForceDuration(CSA[id+PLRS], true, 0)
endif
set P = P + 1
if 1 == P then
call TimerStart(TMR, TOUT, true, function Loop)
endif
endif
//call EnableSelect(false, false)
endfunction
private function InitTrig_CF takes nothing returns nothing
local integer i
local integer j
set i = 0
loop
exitwhen i == PLRS
set CSA[i] = CreateCameraSetup()
set CSA[i+PLRS] = CSA[i]
call CameraSetupSetField(CSA[i], CAMERA_FIELD_ANGLE_OF_ATTACK, 270, 0)
call CameraSetupSetField(CSA[i], CAMERA_FIELD_FARZ, 2000, 0)
call CameraSetupSetField(CSA[i], CAMERA_FIELD_FIELD_OF_VIEW, 90, 0)
call CameraSetupSetField(CSA[i], CAMERA_FIELD_ROLL, 0, 0)
call CameraSetupSetField(CSA[i], CAMERA_FIELD_ROTATION, 90, 0)
call CameraSetupSetField(CSA[i], CAMERA_FIELD_TARGET_DISTANCE, 800, 0)
call CameraSetupSetField(CSA[i], CAMERA_FIELD_ZOFFSET, 0, 0)
call CameraSetupSetDestPosition(CSA[i], 0, 0, 0)
set i = i + 1
endloop
endfunction
endlibrary
//TESH.scrollpos=7
//TESH.alwaysfold=0
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
local location l = Location(0,0)
local CustomTextWindow CTW
local real array x
local real array y
local integer i
set x[0] = -1020
set x[1] = -510
set x[2] = 131
set x[3] = 900
set x[4] = -1020
set y[0] = -1285
set y[1] = -1285
set y[2] = -1285
set y[3] = -1150
set y[4] = -900
set i = 0
loop
exitwhen x[i] == 0
call MoveLocation(l, x[i], y[i])
set CTW = CustomTextWindow.create("STRENGTH", "OMG, this is text!", x[i], y[i], 40, .3, 40, 1)
call CTW.setHeight(GetLocationZ(l))
//call CTW.setHeight(550)
call CTW.show(true)
set i = i + 1
endloop
endfunction
//===========================================================================
function InitTrig_Moar_Examples takes nothing returns nothing
call Trig_Untitled_Trigger_001_Actions()
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
/*************************************************
* CustomWindow v0.9.0.3 by Maker
*
* Allows the creation of custom windows.
*
* Requires Table by Bribe and TimerUtils by Vexorian
*
* Importing instructions:
* 1. Import all images with the name beginning with Border.
* There are 8 of them. Also copy background.TGA.
* 2. Make sure the image paths are correct in the globals block in this library.
* 3. Copy CustomTextWindow, Table and TimerUtilsEx into your map.
*
*
* API
*
* struct CustowWindow
*
* o method destroy takes nothing returns nothing
* Destroys a custom window
* o method setHeight takes real height returns nothing
* Sets the height of a custom window
* o method fade takes integer alpha returns nothing
* Sets the transparency of a window
* o method show takes boolean show returns nothing
* Shows/hides a custom window
* o static method create takes real scale, real sizeX, real sizeY, real posX, real posY, integer imageType returns thistype
* Creates a custom window
*
* struct CustomTextWindow
*
* o method destroy takes nothing returns nothing
* Destroys a custom text window
* o method show takes boolean show returns nothing
* Shows/hides a custom text window
* o method fadeOut real time, real delay, boolean destroy returns nothing
* Fades out a custom text window. Time is the fade time, delay the time before fading.
* If destroy is true, the window will be destroyed when it has faded out.
* o method setHeight real height returns nothing
* Sets the height of a custom window
* o static method create takes string title, string text, real posX, real posY, real textSize, real borderScale, integer maxWidth, integer imageType returns thistype
* Creates a custom text window
*
*
* Try to avoid large text sizes, over about 28, since
* the game engine will add a line break if text tag width
* would become too large.
*
************************************************/
library CustomWindow requires Table, TimerUtils
globals
private constant string BACKGROUND = "war3mapImported\\background.TGA"
private constant string BOTTOM_L = "war3mapImported\\BorderDownLeftNE.TGA"
private constant string TOP_L = "war3mapImported\\BorderUpLeftNE.TGA"
private constant string BOTTOM_R = "war3mapImported\\BorderDownRightNE.TGA"
private constant string TOP_R = "war3mapImported\\BorderUpRightNE.TGA"
private constant string LEFT = "war3mapImported\\BorderLeftNE.TGA"
private constant string TOP = "war3mapImported\\BorderUpNE.TGA"
private constant string RIGHT = "war3mapImported\\BorderRightNE.TGA"
private constant string BOTTOM = "war3mapImported\\BorderDownNE.TGA"
private constant integer MAXCHARS = 38 // Maximum number of characters in a row
private constant real CHARHEIGHT = 8 // Height of a letter in pixels
private constant real CHARWIDTH = 3 // Width of a letter in pixels
private constant real BORDERWIDTH = 28 // Width of borders, visible portion of default size
private constant real LOOPTIME = 0.03125
endglobals
// Not to be changed
globals
private real X
private real Y
private constant real DEFSIZE = 64 // Size of visible portion of an image
private constant real RATIO = (DEFSIZE+2)/DEFSIZE
private location LOC = Location(0,0)
endglobals
struct CustomWindow extends array
private integer images
private static Table array imgs
private static integer ic = 0
private static integer ir = 0
private thistype rn
method destroy takes nothing returns nothing
local integer i = this.images
loop
exitwhen i == 0
call DestroyImage(imgs[this].image[i])
set i = i - 1
endloop
call imgs[this].destroy()
set .rn = ir
set ir = this
endmethod
method setHeight takes real height returns nothing
local integer i = .images
loop
exitwhen i == 0
call SetImageConstantHeight(imgs[this].image[i], true, height)
set i = i - 1
endloop
endmethod
method show takes boolean show returns nothing
local integer i = .images
loop
exitwhen i == 0
call SetImageRenderAlways(imgs[this].image[i], show)
call ShowImage(imgs[this].image[i], show)
set i = i - 1
endloop
endmethod
method fade takes integer alpha returns nothing
local integer i = .images
loop
exitwhen i == 0
if i != 1 then
call SetImageColor(imgs[this].image[i], 255, 255, 255, alpha)
elseif alpha < 200 then
call SetImageColor(imgs[this].image[i], 255, 255, 255, alpha)
else
call SetImageColor(imgs[this].image[i], 255, 255, 255, 200)
endif
set i = i - 1
endloop
endmethod
private static method addRecycle takes nothing returns thistype
local thistype this
if ir == 0 then
set ic = ic + 1
set this = ic
else
set this = ir
set ir = .rn
endif
return this
endmethod
// posX and posY are the coordinates of the center of the image
static method create takes real scale, real sizeX, real sizeY, real posX, real posY, integer imageType returns thistype
local thistype this = thistype.addRecycle()
local integer i = 0 // Image counter
local integer j // For loops
local integer nx = 0 // How many x pieces
local integer ny = 0 // How many y pieces
local real sx = 0 // X size
local real sy = 0 // Y size
local real cx = 0 // X coordinate of lower left corner
local real cy = 0 // Y coordinate of lower left corner
local real bwidth // Border width
set X = DEFSIZE*scale
set Y = DEFSIZE*scale
set bwidth = BORDERWIDTH * scale
set imgs[this] = Table.create()
if sizeX < 2*X then
set sizeX = 2*X
endif
set sx = X * RATIO
set nx = R2I(0.2 + (sizeX-2*X) / X)
set sizeX = (2+nx)*X
set cx = posX - sizeX/2 + X - 1*scale
if sizeY < 2*Y then
set sizeY = 2*Y
endif
set sy = Y * RATIO
set ny = R2I(0.2 + (sizeY-2*Y) / Y)
set sizeY = (2+ny)*Y
set cy = posY - sizeY/2 + Y - 1*scale
set i = i + 1 // Background
set imgs[this].image[i] = CreateImage(BACKGROUND, sizeX-bwidth, sizeY-bwidth, 0, posX - (sizeX-bwidth)/2, posY - (sizeY-bwidth)/2, 0, 0, 0, 0, imageType)
call SetImageColor(imgs[this].image[i], 255, 255, 255, 200)
set posX = posX - 1 * scale
set posY = posY - 1 * scale
set i = i + 1 // Down left corner
set imgs[this].image[i] = CreateImage(BOTTOM_L, sx, sy, 0, posX - sizeX/2, posY - sizeY/2, 0, 0, 0, 0, imageType)
set i = i + 1 // Up left corner
set imgs[this].image[i] = CreateImage(TOP_L, sx, sy, 0, posX - sizeX/2, posY + sizeY/2 - sy/RATIO, 0, 0, 0, 0, imageType)
set i = i + 1 // Up right corner
set imgs[this].image[i] = CreateImage(TOP_R, sx, sy, 0, posX + sizeX/2 - X, posY + sizeY/2 - sy/RATIO, 0, 0, 0, 0, imageType)
set i = i + 1 // Down right corner
set imgs[this].image[i] = CreateImage(BOTTOM_R, sx, sy, 0, posX + sizeX/2 - X, posY - sizeY/2, 0, 0, 0, 0, imageType)
set j = 0
loop // Up and down blocks
set i = i + 1
set imgs[this].image[i] = CreateImage(TOP, sx, sy, 0, cx, posY + sizeY/2 - Y, 0, 0, 0, 0, imageType)
set i = i + 1
set imgs[this].image[i] = CreateImage(BOTTOM, sx, sy, 0, cx, posY - sizeY/2, 0, 0, 0, 0, imageType)
set j = j + 1
exitwhen j == nx
set cx = cx + sx/RATIO
endloop
set j = 0
loop // Left and right blocks
set i = i + 1
set imgs[this].image[i] = CreateImage(LEFT, sx, sy, 0, posX - sizeX/2, cy, 0, 0, 0, 0, imageType)
set i = i + 1
set imgs[this].image[i] = CreateImage(RIGHT, sx, sy, 0, posX + sizeX/2 - X, cy, 0, 0, 0, 0, imageType)
set j = j + 1
exitwhen j == ny
set cy = cy + sy/RATIO
endloop
set this.images = i
return this
endmethod
endstruct
struct CustomTextWindow extends array
private real ttPosX
private real ttPosY
private real height
private integer visibility
private integer fadeRate
private timer t
string title
string text
texttag tt
private boolean destroys
CustomWindow cw
private thistype rn
private static integer ic = 0
private static integer ir = 0
method destroy takes nothing returns nothing
call DestroyTextTag(this.tt)
set this.title = null
set this.text = null
set this.tt = null
set this.destroys = false
if this.t != null then
call ReleaseTimer(this.t)
set this.t = null
endif
call this.cw.destroy()
set this.rn = ir
set ir = this
endmethod
method show takes boolean show returns nothing
if show then
call SetTextTagColor(this.tt, 255, 255, 255, 255)
endif
call SetTextTagVisibility(this.tt, show)
call this.cw.show(show)
endmethod
private static method fade takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
set this.visibility = this.visibility - this.fadeRate
if this.visibility > 0 then
call SetTextTagColor(this.tt, 255, 255, 255, this.visibility)
call this.cw.fade(this.visibility)
else
call ReleaseTimer(this.t)
set this.t = null
call .show(false)
if this.destroys then
call this.destroy()
endif
endif
endmethod
private static method fadeDelay takes nothing returns nothing
call TimerStart(GetExpiredTimer(), LOOPTIME, true, function thistype.fade)
endmethod
method fadeOut takes real time, real delay, boolean destroys returns nothing
if .t == null then
set .t = NewTimerEx(this)
endif
if time == 0 then
set time = 0.01
endif
set .visibility = 255
set .fadeRate = R2I(255*LOOPTIME/time) + 1
set .destroys = destroys
if delay != 0 then
call TimerStart(.t, delay, false, function thistype.fadeDelay)
else
call TimerStart(.t, LOOPTIME, true, function thistype.fade)
endif
call SetTextTagPermanent(.tt, false)
endmethod
method setHeight takes real height returns nothing
call SetTextTagPos(.tt, .ttPosX, .ttPosY, height)
call this.cw.setHeight(.height + height)
endmethod
private static method addRecycle takes nothing returns thistype
local thistype this
if 0==ir then
set ic=ic+1
set this=ic
else
set this=ir
set ir=.rn
endif
return this
endmethod
// posX and pos Y are the coordinates of bottom left corner
static method create takes string title, string text, real posX, real posY, real textSize, real borderScale, integer maxWidth, integer imageType returns thistype
local thistype this = thistype.addRecycle()
local integer i
local integer rows = 1
local integer wordlength = 0
local string word = null
local string newStr = null
local string char
local integer chars = 0
local integer charsMax = 0
local real width
local real sizeX
local real sizeY
if maxWidth > MAXCHARS or maxWidth == 0 then
set maxWidth = MAXCHARS
endif
if text != null then
set rows = rows + 1
set width = 0
set i = 0
loop
set char = SubString(text, i, i+1)
if char == " " or char == "" then
if chars < maxWidth then
set newStr = newStr + " " + word
if char == " " then
set chars = chars + 1
endif
if chars > charsMax then
set charsMax = chars
endif
else
if chars - wordlength > charsMax then
set charsMax = chars - wordlength
endif
set newStr = newStr + "\n" + " " + word
set chars = 1 + wordlength
set rows = rows + 1
endif
set word = null
set wordlength = 0
else
set chars = chars + 1
set wordlength = wordlength + 1
set word = word + char
endif
exitwhen char == ""
set i = i + 1
endloop
else
set charsMax = StringLength(title) + 2
endif
call MoveLocation(LOC, posX, posY)
set this.height = GetLocationZ(LOC)
set sizeX = charsMax * CHARWIDTH * textSize/10 + 2*DEFSIZE*borderScale
set sizeY = rows * CHARHEIGHT * textSize/10 + 2*DEFSIZE*borderScale
set this.ttPosX = posX
set this.ttPosY = posY
set this.title = title
set this.text = text
set this.cw = CustomWindow.create(borderScale, sizeX, sizeY, posX+sizeX/2-DEFSIZE*borderScale, posY+sizeY/2-DEFSIZE*borderScale, imageType)
set this.tt = CreateTextTag()
call SetTextTagText(this.tt, "|cffffcc00" + this.title + "|r\n" + newStr, textSize/1000)
call SetTextTagPos(this.tt, posX, posY, 0)
call SetTextTagVisibility(this.tt, false)
set char = null
set newStr = null
return this
endmethod
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
/*************************************************
* CustomWindow v1.0.0.0 by Maker
*
* Allows the creation of custom windows.
*
* Requires Table by Bribe and TimerUtils by Vexorian
*
* Importing instructions:
* 1. Import all images with the name beginning with Border.
* There are 8 of them. Also copy background.TGA.
* 2. Make sure the image paths are correct in the globals block in this library.
* 3. Copy CustomTextWindow, Table and TimerUtilsEx into your map.
*
*
* API
*
* struct CustowWindow
*
* o method destroy takes nothing returns nothing
* Destroys a custom window
* o method setHeight takes real height returns nothing
* Sets the height of a custom window
* o method fade takes integer alpha returns nothing
* Sets the transparency of a window
* o method show takes boolean show returns nothing
* Shows/hides a custom window
* o static method create takes real scale, real sizeX, real sizeY, real posX, real posY, integer imageType returns thistype
* Creates a custom window
*
* struct CustomTextWindow
*
* o method destroy takes nothing returns nothing
* Destroys a custom text window
* o method show takes boolean show returns nothing
* Shows/hides a custom text window
* o method fadeOut real time, real delay, boolean destroy returns nothing
* Fades out a custom text window. Time is the fade time, delay the time before fading.
* If destroy is true, the window will be destroyed when it has faded out.
* o method setHeight real height returns nothing
* Sets the height of a custom window
* o static method create takes string title, string text, real posX, real posY, real textSize, real borderScale, integer maxWidth, integer imageType returns thistype
* Creates a custom text window
*
*
* Try to avoid large text sizes, over about 28, since
* the game engine will add a line break if text tag width
* would become too large.
*
************************************************/
library CustomWindow requires Table, TimerUtils
globals
private constant string BACKGROUND = "war3mapImported\\background.TGA"
private constant string BOTTOM_L = "war3mapImported\\BorderDownLeftNE.TGA"
private constant string TOP_L = "war3mapImported\\BorderUpLeftNE.TGA"
private constant string BOTTOM_R = "war3mapImported\\BorderDownRightNE.TGA"
private constant string TOP_R = "war3mapImported\\BorderUpRightNE.TGA"
private constant string LEFT = "war3mapImported\\BorderLeftNE.TGA"
private constant string TOP = "war3mapImported\\BorderUpNE.TGA"
private constant string RIGHT = "war3mapImported\\BorderRightNE.TGA"
private constant string BOTTOM = "war3mapImported\\BorderDownNE.TGA"
private constant integer MAXCHARS = 38 // Maximum number of characters in a row
private constant real CHARHEIGHT = 4 // Height of a letter in pixels
private constant real CHARWIDTH = 1.5 // Width of a letter in pixels
private constant real BORDERWIDTH = 28 // Width of borders, visible portion of default size
private constant real LOOPTIME = 0.03125
/* Use CHARHEIGHT and CHARWIDTH to adjust the window's wrapping around the text */
endglobals
// Not to be changed
globals
private real X
private real Y
private constant real DEFSIZE = 64 // Size of visible portion of an image
private constant real RATIO = (DEFSIZE+2)/DEFSIZE
private location LOC = Location(0,0)
endglobals
struct CustomWindow extends array
private integer images
private static Table array imgs
private static integer ic = 0
private static integer ir = 0
private thistype rn
method destroy takes nothing returns nothing
local integer i = this.images
loop
exitwhen i == 0
call DestroyImage(imgs[this].image[i])
set i = i - 1
endloop
call imgs[this].destroy()
set .rn = ir
set ir = this
endmethod
method setHeight takes real height returns nothing
local integer i = .images
loop
exitwhen i == 0
call SetImageConstantHeight(imgs[this].image[i], true, height)
set i = i - 1
endloop
endmethod
method show takes boolean show returns nothing
local integer i = .images
loop
exitwhen i == 0
call SetImageRenderAlways(imgs[this].image[i], show)
call ShowImage(imgs[this].image[i], show)
set i = i - 1
endloop
endmethod
method fade takes integer alpha returns nothing
local integer i = .images
loop
exitwhen i == 0
if i != 1 then
call SetImageColor(imgs[this].image[i], 255, 255, 255, alpha)
elseif alpha < 200 then
call SetImageColor(imgs[this].image[i], 255, 255, 255, alpha)
else
call SetImageColor(imgs[this].image[i], 255, 255, 255, 200)
endif
set i = i - 1
endloop
endmethod
private static method addRecycle takes nothing returns thistype
local thistype this
if ir == 0 then
set ic = ic + 1
set this = ic
else
set this = ir
set ir = .rn
endif
return this
endmethod
// posX and posY are the coordinates of the center of the image
static method create takes real scale, real sizeX, real sizeY, real posX, real posY, integer imageType returns thistype
local thistype this = thistype.addRecycle()
local integer i = 0 // Image counter
local integer j // For loops
local integer nx = 0 // How many x pieces
local integer ny = 0 // How many y pieces
local real sx = 0 // X size
local real sy = 0 // Y size
local real cx = 0 // X coordinate of lower left corner
local real cy = 0 // Y coordinate of lower left corner
local real bwidth // Border width
set X = DEFSIZE*scale
set Y = DEFSIZE*scale
set bwidth = BORDERWIDTH * scale
set imgs[this] = Table.create()
if sizeX < 2*X then
set sizeX = 2*X
endif
set sx = X * RATIO
set nx = R2I(0.2 + (sizeX-2*X) / X)
set sizeX = (2+nx)*X
set cx = posX - sizeX/2 + X - 1*scale
if sizeY < 2*Y then
set sizeY = 2*Y
endif
set sy = Y * RATIO
set ny = R2I(0.2 + (sizeY-2*Y) / Y)
set sizeY = (2+ny)*Y
set cy = posY - sizeY/2 + Y - 1*scale
set i = i + 1 // Background
set imgs[this].image[i] = CreateImage(BACKGROUND, sizeX-bwidth, sizeY-bwidth, 0, posX - (sizeX-bwidth)/2, posY - (sizeY-bwidth)/2, 0, 0, 0, 0, imageType)
call SetImageColor(imgs[this].image[i], 255, 255, 255, 200)
set posX = posX - 1 * scale
set posY = posY - 1 * scale
set i = i + 1 // Down left corner
set imgs[this].image[i] = CreateImage(BOTTOM_L, sx, sy, 0, posX - sizeX/2, posY - sizeY/2, 0, 0, 0, 0, imageType)
set i = i + 1 // Up left corner
set imgs[this].image[i] = CreateImage(TOP_L, sx, sy, 0, posX - sizeX/2, posY + sizeY/2 - sy/RATIO, 0, 0, 0, 0, imageType)
set i = i + 1 // Up right corner
set imgs[this].image[i] = CreateImage(TOP_R, sx, sy, 0, posX + sizeX/2 - X, posY + sizeY/2 - sy/RATIO, 0, 0, 0, 0, imageType)
set i = i + 1 // Down right corner
set imgs[this].image[i] = CreateImage(BOTTOM_R, sx, sy, 0, posX + sizeX/2 - X, posY - sizeY/2, 0, 0, 0, 0, imageType)
set j = 0
loop // Up and down blocks
set i = i + 1
set imgs[this].image[i] = CreateImage(TOP, sx, sy, 0, cx, posY + sizeY/2 - Y, 0, 0, 0, 0, imageType)
set i = i + 1
set imgs[this].image[i] = CreateImage(BOTTOM, sx, sy, 0, cx, posY - sizeY/2, 0, 0, 0, 0, imageType)
set j = j + 1
exitwhen j == nx
set cx = cx + sx/RATIO
endloop
set j = 0
loop // Left and right blocks
set i = i + 1
set imgs[this].image[i] = CreateImage(LEFT, sx, sy, 0, posX - sizeX/2, cy, 0, 0, 0, 0, imageType)
set i = i + 1
set imgs[this].image[i] = CreateImage(RIGHT, sx, sy, 0, posX + sizeX/2 - X, cy, 0, 0, 0, 0, imageType)
set j = j + 1
exitwhen j == ny
set cy = cy + sy/RATIO
endloop
set this.images = i
return this
endmethod
endstruct
struct CustomTextWindow extends array
private real ttPosX
private real ttPosY
private real height
private real ttSize
private integer visibility
private integer fadeRate
private timer t
private string title
private string text
texttag tt
private boolean destroys
CustomWindow cw
private thistype rn
private static integer ic = 0
private static integer ir = 0
method destroy takes nothing returns nothing
if this.tt != null then
call DestroyTextTag(this.tt)
set this.tt = null
endif
set this.title = null
set this.text = null
set this.destroys = false
if this.t != null then
call ReleaseTimer(this.t)
set this.t = null
endif
call this.cw.destroy()
set this.rn = ir
set ir = this
endmethod
method show takes boolean show returns nothing
if show then
if this.tt == null then
set this.tt = CreateTextTag()
call SetTextTagText(this.tt, this.text, this.ttSize/1000)
call SetTextTagPos(this.tt, this.ttPosX, this.ttPosY, 0)
//call UnitApplyTimedLife(CreateUnit(Player(0), 'hfoo', .ttPosX, .ttPosY, 0), 1 ,1)
call SetTextTagColor(this.tt, 255, 255, 255, 255)
call SetTextTagVisibility(this.tt, true)
endif
else
call DestroyTextTag(this.tt)
set this.tt = null
endif
call this.cw.show(show)
endmethod
private static method fade takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
set this.visibility = this.visibility - this.fadeRate
if this.visibility > 0 then
if this.tt != null then
call SetTextTagColor(this.tt, 255, 255, 255, this.visibility)
endif
call this.cw.fade(this.visibility)
else
call PauseTimer(this.t)
call .show(false)
if this.destroys then
call this.destroy()
endif
endif
endmethod
private static method fadeDelay takes nothing returns nothing
call TimerStart(GetExpiredTimer(), LOOPTIME, true, function thistype.fade)
endmethod
method fadeOut takes real time, real delay, boolean destroys returns nothing
if .t == null then
set .t = NewTimerEx(this)
endif
if time == 0 then
set time = 0.01
endif
set .visibility = 255
set .fadeRate = R2I(255*LOOPTIME/time) + 1
set .destroys = destroys
call SetTextTagPermanent(.tt, false)
if delay != 0 then
call TimerStart(.t, delay, false, function thistype.fadeDelay)
else
call TimerStart(.t, LOOPTIME, true, function thistype.fade)
endif
endmethod
method setHeight takes real height returns nothing
call SetTextTagPos(.tt, .ttPosX, .ttPosY, height)
call this.cw.setHeight(.height + height)
endmethod
private static method addRecycle takes nothing returns thistype
local thistype this
if 0==ir then
set ic=ic+1
set this=ic
else
set this=ir
set ir=.rn
endif
return this
endmethod
// posX and pos Y are the coordinates of bottom left corner
static method create takes string title, string text, real posX, real posY, real textSize, real borderScale, integer maxWidth, integer imageType returns thistype
local thistype this = thistype.addRecycle()
local integer i
local integer rows = 1
local integer wordlength = 0
local string word = null
local string newStr = null
local string char
local integer chars = 0
local integer charsMax = 0
local real width
local real sizeX
local real sizeY
if maxWidth > MAXCHARS or maxWidth == 0 then
set maxWidth = MAXCHARS
endif
if text != null then
set rows = rows + 1
set width = 0
set i = 0
loop
set char = SubString(text, i, i+1)
if char == " " or char == "" then
if chars < maxWidth then
set newStr = newStr + " " + word
if char == " " then
set chars = chars + 1
endif
if chars > charsMax then
set charsMax = chars
endif
else
if chars - wordlength > charsMax then
set charsMax = chars - wordlength
endif
set newStr = newStr + "\n" + " " + word
set chars = 1 + wordlength
set rows = rows + 1
endif
set word = null
set wordlength = 0
else
set chars = chars + 1
set wordlength = wordlength + 1
set word = word + char
endif
exitwhen char == ""
set i = i + 1
endloop
else
set charsMax = StringLength(title) + 2
endif
call MoveLocation(LOC, posX, posY)
set this.height = GetLocationZ(LOC)
set sizeX = charsMax * CHARWIDTH * textSize/5 + 2*DEFSIZE*borderScale
set sizeY = rows * CHARHEIGHT * textSize/5 + 2*DEFSIZE*borderScale
set this.ttSize = textSize
set this.ttPosX = posX
set this.ttPosY = posY
set this.title = title
set this.text = "|cffffcc00" + this.title + "|r\n" + newStr
set this.cw = CustomWindow.create(borderScale, sizeX, sizeY, posX+sizeX/2-DEFSIZE*borderScale, posY+sizeY/2-DEFSIZE*borderScale, imageType)
set char = null
set newStr = null
return this
endmethod
endstruct
endlibrary
//TESH.scrollpos=298
//TESH.alwaysfold=0
/*************************************************
* CustomWindow v1.0.1.0 by Maker
*
* Allows the creation of custom windows.
*
* Requires Table by Bribe and TimerUtils by Vexorian
*
* Importing instructions:
* 1. Import all images with the name beginning with Border.
* There are 8 of them. Also copy background.TGA.
* 2. Make sure the image paths are correct in the globals block in this library.
* 3. Copy CustomTextWindow, Table and TimerUtilsEx into your map.
*
*
* API
*
* struct CustowWindow
*
* o method destroy takes nothing returns nothing
* Destroys a custom window
* o method setHeight takes real height returns nothing
* Sets the height of a custom window
* o method setTransparency takes integer alpha returns nothing
* Sets the transparency of a window
* o method show takes boolean show returns nothing
* Shows/hides a custom window
* o static method create takes real scale, real sizeX, real sizeY, real posX, real posY, integer imageType returns thistype
* Creates a custom window
*
* struct CustomTextWindow
*
* o method destroy takes nothing returns nothing
* Destroys a custom text window
* o method show takes boolean show returns nothing
* Shows/hides a custom text window
* o method setTransparency takes integer alpha returns nothing
* Sets the transparency of a custom text window
* o method fadeOut real time, real delay, boolean destroy returns nothing
* Fades out a custom text window. Time is the fade time, delay the time before fading.
* If destroy is true, the window will be destroyed when it has faded out.
* o method setHeight real height returns nothing
* Sets the height of a custom window
* o static method create takes string title, string text, real posX, real posY, real textSize, real borderScale, integer maxWidth, integer imageType returns thistype
* Creates a custom text window
*
*
* Try to avoid large text sizes, over about 28, since
* the game engine will add a line break if text tag width
* would become too large.
*
************************************************/
library CustomWindow requires Table, TimerUtils
globals
private constant string BACKGROUND = "war3mapImported\\background.TGA"
private constant string BOTTOM_L = "war3mapImported\\BorderDownLeftNE.TGA"
private constant string TOP_L = "war3mapImported\\BorderUpLeftNE.TGA"
private constant string BOTTOM_R = "war3mapImported\\BorderDownRightNE.TGA"
private constant string TOP_R = "war3mapImported\\BorderUpRightNE.TGA"
private constant string LEFT = "war3mapImported\\BorderLeftNE.TGA"
private constant string TOP = "war3mapImported\\BorderUpNE.TGA"
private constant string RIGHT = "war3mapImported\\BorderRightNE.TGA"
private constant string BOTTOM = "war3mapImported\\BorderDownNE.TGA"
private constant integer MAXCHARS = 38 // Maximum number of characters in a row
private constant real CHARHEIGHT = 4 // Height of a letter in pixels
private constant real CHARWIDTH = 1.5 // Width of a letter in pixels
private constant real BORDERWIDTH = 28 // Width of borders, visible portion of default size
private constant real LOOPTIME = 0.03125
/* Use CHARHEIGHT and CHARWIDTH to adjust the window's wrapping around the text */
endglobals
// Not to be changed
globals
private real X
private real Y
private constant real DEFSIZE = 64 // Size of visible portion of an image
private constant real RATIO = (DEFSIZE+2)/DEFSIZE
private location LOC = Location(0,0)
endglobals
struct CustomWindow extends array
private integer images
private static Table array imgs
private static integer ic = 0
private static integer ir = 0
private thistype rn
method destroy takes nothing returns nothing
local integer i = this.images
loop
exitwhen i == 0
call DestroyImage(imgs[this].image[i])
set i = i - 1
endloop
call imgs[this].destroy()
set .rn = ir
set ir = this
endmethod
method setHeight takes real height returns nothing
local integer i = .images
loop
exitwhen i == 0
call SetImageConstantHeight(imgs[this].image[i], true, height)
set i = i - 1
endloop
endmethod
method show takes boolean show returns nothing
local integer i = .images
loop
exitwhen i == 0
call SetImageRenderAlways(imgs[this].image[i], show)
call ShowImage(imgs[this].image[i], show)
set i = i - 1
endloop
endmethod
method setTransparency takes integer alpha returns nothing
local integer i = .images
loop
exitwhen i == 0
if i != 1 then
call SetImageColor(imgs[this].image[i], 255, 255, 255, alpha)
elseif alpha < 200 then
call SetImageColor(imgs[this].image[i], 255, 255, 255, alpha)
else
call SetImageColor(imgs[this].image[i], 255, 255, 255, 200)
endif
set i = i - 1
endloop
endmethod
private static method addRecycle takes nothing returns thistype
local thistype this
if ir == 0 then
set ic = ic + 1
set this = ic
else
set this = ir
set ir = .rn
endif
return this
endmethod
// posX and posY are the coordinates of the center of the image
static method create takes real scale, real sizeX, real sizeY, real posX, real posY, integer imageType returns thistype
local thistype this = thistype.addRecycle()
local integer i = 0 // Image counter
local integer j // For loops
local integer nx = 0 // How many x pieces
local integer ny = 0 // How many y pieces
local real sx = 0 // X size
local real sy = 0 // Y size
local real cx = 0 // X coordinate of lower left corner
local real cy = 0 // Y coordinate of lower left corner
local real bwidth // Border width
set X = DEFSIZE*scale
set Y = DEFSIZE*scale
set bwidth = BORDERWIDTH * scale
set imgs[this] = Table.create()
if sizeX < 2*X then
set sizeX = 2*X
endif
set sx = X * RATIO
set nx = R2I(0.2 + (sizeX-2*X) / X)
set sizeX = (2+nx)*X
set cx = posX - sizeX/2 + X - 1*scale
if sizeY < 2*Y then
set sizeY = 2*Y
endif
set sy = Y * RATIO
set ny = R2I(0.2 + (sizeY-2*Y) / Y)
set sizeY = (2+ny)*Y
set cy = posY - sizeY/2 + Y - 1*scale
set i = i + 1 // Background
set imgs[this].image[i] = CreateImage(BACKGROUND, sizeX-bwidth, sizeY-bwidth, 0, posX - (sizeX-bwidth)/2, posY - (sizeY-bwidth)/2, 0, 0, 0, 0, imageType)
call SetImageColor(imgs[this].image[i], 255, 255, 255, 200)
set posX = posX - 1 * scale
set posY = posY - 1 * scale
set i = i + 1 // Down left corner
set imgs[this].image[i] = CreateImage(BOTTOM_L, sx, sy, 0, posX - sizeX/2, posY - sizeY/2, 0, 0, 0, 0, imageType)
set i = i + 1 // Up left corner
set imgs[this].image[i] = CreateImage(TOP_L, sx, sy, 0, posX - sizeX/2, posY + sizeY/2 - sy/RATIO, 0, 0, 0, 0, imageType)
set i = i + 1 // Up right corner
set imgs[this].image[i] = CreateImage(TOP_R, sx, sy, 0, posX + sizeX/2 - X, posY + sizeY/2 - sy/RATIO, 0, 0, 0, 0, imageType)
set i = i + 1 // Down right corner
set imgs[this].image[i] = CreateImage(BOTTOM_R, sx, sy, 0, posX + sizeX/2 - X, posY - sizeY/2, 0, 0, 0, 0, imageType)
set j = 0
loop // Up and down blocks
set i = i + 1
set imgs[this].image[i] = CreateImage(TOP, sx, sy, 0, cx, posY + sizeY/2 - Y, 0, 0, 0, 0, imageType)
set i = i + 1
set imgs[this].image[i] = CreateImage(BOTTOM, sx, sy, 0, cx, posY - sizeY/2, 0, 0, 0, 0, imageType)
set j = j + 1
exitwhen j == nx
set cx = cx + sx/RATIO
endloop
set j = 0
loop // Left and right blocks
set i = i + 1
set imgs[this].image[i] = CreateImage(LEFT, sx, sy, 0, posX - sizeX/2, cy, 0, 0, 0, 0, imageType)
set i = i + 1
set imgs[this].image[i] = CreateImage(RIGHT, sx, sy, 0, posX + sizeX/2 - X, cy, 0, 0, 0, 0, imageType)
set j = j + 1
exitwhen j == ny
set cy = cy + sy/RATIO
endloop
set this.images = i
return this
endmethod
endstruct
struct CustomTextWindow extends array
private real ttPosX
private real ttPosY
private real height
private real ttSize
private integer visibility
private integer fadeRate
private integer fadeOutRate
private timer t
private timer tOut
private string title
private string text
texttag tt
private boolean destroys
private boolean destroysOut
CustomWindow cw
private thistype rn
private static integer ic = 0
private static integer ir = 0
method destroy takes nothing returns nothing
if this.tt != null then
call DestroyTextTag(this.tt)
set this.tt = null
endif
set this.title = null
set this.text = null
set this.destroys = false
if this.t != null then
call ReleaseTimer(this.t)
set this.t = null
endif
if this.tOut != null then
call ReleaseTimer(this.tOut)
set this.tOut = null
endif
call this.cw.destroy()
set this.rn = ir
set ir = this
endmethod
method setTransparency takes integer alpha returns nothing
if this.tt == null and not this.destroys then
call this.show(true)
endif
set this.visibility = alpha
call SetTextTagPermanent(this.tt, false)
call SetTextTagColor(this.tt, 255, 255, 255, alpha)
call this.cw.setTransparency(alpha)
endmethod
method show takes boolean show returns nothing
if show then
if this.tt == null then
set this.tt = CreateTextTag()
call SetTextTagText(this.tt, this.text, this.ttSize/1000)
call SetTextTagPos(this.tt, this.ttPosX, this.ttPosY, 0)
call SetTextTagColor(this.tt, 255, 255, 255, this.visibility)
call SetTextTagVisibility(this.tt, true)
endif
else
/*if this.t != null then
call PauseTimer(this.t)
endif*/
call DestroyTextTag(this.tt)
set this.tt = null
endif
call this.cw.show(show)
endmethod
private static method fade takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
set this.visibility = this.visibility - this.fadeRate
if this.visibility > 0 and this.visibility < 255 then
if this.tt != null then
call SetTextTagColor(this.tt, 255, 255, 255, this.visibility)
endif
call this.cw.setTransparency(this.visibility)
else
call PauseTimer(this.t)
call .show(false)
if this.destroys then
call this.destroy()
else
if this.fadeRate < 0 then
set this.visibility = 255
elseif this.fadeRate > 0 then
set this.visibility = 0
endif
call this.setTransparency(this.visibility)
if this.t != null then
call ReleaseTimer(this.t)
set this.t = null
endif
endif
endif
endmethod
private static method fadeDelay takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
set this.fadeRate = this.fadeOutRate
set this.destroys = this.destroysOut
call SetTextTagPermanent(this.tt, false)
if this.tOut != null then
call ReleaseTimer(this.tOut)
set this.tOut = null
endif
if this.t == null then
set this.t = NewTimerEx(this)
endif
call TimerStart(this.t, LOOPTIME, true, function thistype.fade)
endmethod
method fadeIn takes real time returns nothing
if .t == null then
set .t = NewTimerEx(this)
endif
if time == 0 then
set time = 0.01
endif
set .destroys = false
set .fadeRate = -(R2I(255*LOOPTIME/time) + 1)
call SetTextTagPermanent(.tt, false)
call TimerStart(.t, LOOPTIME, true, function thistype.fade)
endmethod
method fadeOut takes real time, real delay, boolean destroys returns nothing
if time == 0 then
set time = 0.01
endif
set .fadeOutRate = R2I(255*LOOPTIME/time) + 1
set .destroysOut = destroys
call SetTextTagPermanent(.tt, false)
if delay != 0 then
if .tOut == null then
set .tOut = NewTimerEx(this)
endif
call TimerStart(.tOut, delay, false, function thistype.fadeDelay)
else
if .tOut != null then
call PauseTimer(.tOut)
endif
if .t == null then
set .t = NewTimerEx(this)
endif
set this.fadeRate = this.fadeOutRate
set this.destroys = this.destroysOut
call TimerStart(.t, LOOPTIME, true, function thistype.fade)
endif
endmethod
method setHeight takes real height returns nothing
call SetTextTagPos(.tt, .ttPosX, .ttPosY, height)
call this.cw.setHeight(.height + height)
endmethod
private static method addRecycle takes nothing returns thistype
local thistype this
if 0==ir then
set ic=ic+1
set this=ic
else
set this=ir
set ir=.rn
endif
return this
endmethod
// posX and pos Y are the coordinates of bottom left corner
static method create takes string title, string text, real posX, real posY, real textSize, real borderScale, integer maxWidth, integer imageType returns thistype
local thistype this = thistype.addRecycle()
local integer i
local integer rows = 1
local integer wordlength = 0
local string word = null
local string newStr = null
local string char
local integer chars = 0
local integer charsMax = 0
local real width
local real sizeX
local real sizeY
if maxWidth > MAXCHARS or maxWidth == 0 then
set maxWidth = MAXCHARS
endif
if text != null then
set rows = rows + 1
set width = 0
set i = 0
loop
set char = SubString(text, i, i+1)
if char == " " or char == "" then
if chars < maxWidth then
set newStr = newStr + " " + word
if char == " " then
set chars = chars + 1
endif
if chars > charsMax then
set charsMax = chars
endif
else
if chars - wordlength > charsMax then
set charsMax = chars - wordlength
endif
set newStr = newStr + "\n" + " " + word
set chars = 1 + wordlength
set rows = rows + 1
endif
set word = null
set wordlength = 0
else
set chars = chars + 1
set wordlength = wordlength + 1
set word = word + char
endif
exitwhen char == ""
set i = i + 1
endloop
else
set charsMax = StringLength(title) + 2
endif
call MoveLocation(LOC, posX, posY)
set this.height = GetLocationZ(LOC)
set sizeX = charsMax * CHARWIDTH * textSize/5 + 2*DEFSIZE*borderScale
set sizeY = rows * CHARHEIGHT * textSize/5 + 2*DEFSIZE*borderScale
set this.ttSize = textSize
set this.ttPosX = posX
set this.ttPosY = posY
set this.title = title
set this.text = "|cffffcc00" + this.title + "|r\n" + newStr
set this.cw = CustomWindow.create(borderScale, sizeX, sizeY, posX+sizeX/2-DEFSIZE*borderScale, posY+sizeY/2-DEFSIZE*borderScale, imageType)
set char = null
set newStr = null
return this
endmethod
endstruct
endlibrary
//TESH.scrollpos=148
//TESH.alwaysfold=0
/*************************************************
* CustomWindow v1.0.1.1 by Maker
*
* Allows the creation of custom windows.
*
* Requires Table by Bribe and TimerUtils by Vexorian
*
* Importing instructions:
* 1. Import all images with the name beginning with Border.
* There are 8 of them. Also copy background.TGA.
* 2. Make sure the image paths are correct in the globals block in this library.
* 3. Copy CustomTextWindow, Table and TimerUtilsEx into your map.
*
*
* API
*
* struct CustowWindow
*
* o method destroy takes nothing returns nothing
* Destroys a custom window
* o method setHeight takes real height returns nothing
* Sets the height of a custom window
* o method setTransparency takes integer alpha returns nothing
* Sets the transparency of a window
* o method show takes boolean show returns nothing
* Shows/hides a custom window
* o static method create takes real scale, real sizeX, real sizeY, real posX, real posY, integer imageType returns thistype
* Creates a custom window
*
* struct CustomTextWindow
*
* o method destroy takes nothing returns nothing
* Destroys a custom text window
* o method show takes boolean show returns nothing
* Shows/hides a custom text window
* o method setTransparency takes integer alpha returns nothing
* Sets the transparency of a custom text window
* o method fadeOut real time, real delay, boolean destroy returns nothing
* Fades out a custom text window. Time is the fade time, delay the time before fading.
* If destroy is true, the window will be destroyed when it has faded out.
* o method setHeight real height returns nothing
* Sets the height of a custom window
* o static method create takes string title, string text, real posX, real posY, real textSize, real borderScale, integer maxWidth, integer imageType returns thistype
* Creates a custom text window
*
*
* Try to avoid large text sizes, over about 28, since
* the game engine will add a line break if text tag width
* would become too large.
*
************************************************/
library CustomWindow requires Table, TimerUtils
globals
private constant string BACKGROUND = "war3mapImported\\background.TGA"
private constant string BOTTOM_L = "war3mapImported\\BorderDownLeftNE.TGA"
private constant string TOP_L = "war3mapImported\\BorderUpLeftNE.TGA"
private constant string BOTTOM_R = "war3mapImported\\BorderDownRightNE.TGA"
private constant string TOP_R = "war3mapImported\\BorderUpRightNE.TGA"
private constant string LEFT = "war3mapImported\\BorderLeftNE.TGA"
private constant string TOP = "war3mapImported\\BorderUpNE.TGA"
private constant string RIGHT = "war3mapImported\\BorderRightNE.TGA"
private constant string BOTTOM = "war3mapImported\\BorderDownNE.TGA"
private constant integer TRANS = 200 // Transparency of the background, 0 = fully transparent, 255 = not transparent
private constant integer MAXCHARS = 38 // Maximum number of characters in a row
private constant real CHARHEIGHT = 4 // Height of a letter in pixels
private constant real CHARWIDTH = 1.5 // Width of a letter in pixels
private constant real BORDERWIDTH = 28 // Width of borders, visible portion of default size
private constant real LOOPTIME = 0.03125
/* Use CHARHEIGHT and CHARWIDTH to adjust the window's wrapping around the text */
endglobals
// Not to be changed
globals
private real X
private real Y
private constant real DEFSIZE = 64 // Size of visible portion of an image
private constant real RATIO = (DEFSIZE+2)/DEFSIZE
private location LOC = Location(0,0)
endglobals
struct CustomWindow extends array
private integer images
private static Table array imgs
private static integer ic = 0
private static integer ir = 0
private thistype rn
method destroy takes nothing returns nothing
local integer i = this.images
loop
exitwhen i == 0
call DestroyImage(imgs[this].image[i])
set i = i - 1
endloop
call imgs[this].destroy()
set .rn = ir
set ir = this
endmethod
method setHeight takes real height returns nothing
local integer i = .images
loop
exitwhen i == 0
call SetImageConstantHeight(imgs[this].image[i], true, height)
set i = i - 1
endloop
endmethod
method show takes boolean show returns nothing
local integer i = .images
loop
exitwhen i == 0
call SetImageRenderAlways(imgs[this].image[i], show)
call ShowImage(imgs[this].image[i], show)
set i = i - 1
endloop
endmethod
method setTransparency takes integer alpha returns nothing
local integer i = .images
loop
exitwhen i == 0
if i != 1 then
call SetImageColor(imgs[this].image[i], 255, 255, 255, alpha)
elseif alpha < TRANS then
call SetImageColor(imgs[this].image[i], 255, 255, 255, alpha)
else
call SetImageColor(imgs[this].image[i], 255, 255, 255, TRANS)
endif
set i = i - 1
endloop
endmethod
private static method addRecycle takes nothing returns thistype
local thistype this
if ir == 0 then
set ic = ic + 1
set this = ic
else
set this = ir
set ir = .rn
endif
return this
endmethod
// posX and posY are the coordinates of the center of the image
static method create takes real scale, real sizeX, real sizeY, real posX, real posY, integer imageType returns thistype
local thistype this = thistype.addRecycle()
local integer i = 0 // Image counter
local integer j // For loops
local integer nx = 0 // How many x pieces
local integer ny = 0 // How many y pieces
local real sx = 0 // X size
local real sy = 0 // Y size
local real cx = 0 // X coordinate of lower left corner
local real cy = 0 // Y coordinate of lower left corner
local real bwidth // Border width
set X = DEFSIZE*scale
set Y = DEFSIZE*scale
set bwidth = BORDERWIDTH * scale
set imgs[this] = Table.create()
if sizeX < 2*X then
set sizeX = 2*X
endif
set sx = X * RATIO
set nx = R2I(0.2 + (sizeX-2*X) / X)
set sizeX = (2+nx)*X
set cx = posX - sizeX/2 + X - 1*scale
if sizeY < 2*Y then
set sizeY = 2*Y
endif
set sy = Y * RATIO
set ny = R2I(0.2 + (sizeY-2*Y) / Y)
set sizeY = (2+ny)*Y
set cy = posY - sizeY/2 + Y - 1*scale
set i = i + 1 // Background
set imgs[this].image[i] = CreateImage(BACKGROUND, sizeX-bwidth, sizeY-bwidth, 0, posX - (sizeX-bwidth)/2, posY - (sizeY-bwidth)/2, 0, 0, 0, 0, imageType)
call SetImageColor(imgs[this].image[i], 255, 255, 255, 200)
set posX = posX - 1 * scale
set posY = posY - 1 * scale
set i = i + 1 // Down left corner
set imgs[this].image[i] = CreateImage(BOTTOM_L, sx, sy, 0, posX - sizeX/2, posY - sizeY/2, 0, 0, 0, 0, imageType)
set i = i + 1 // Up left corner
set imgs[this].image[i] = CreateImage(TOP_L, sx, sy, 0, posX - sizeX/2, posY + sizeY/2 - sy/RATIO, 0, 0, 0, 0, imageType)
set i = i + 1 // Up right corner
set imgs[this].image[i] = CreateImage(TOP_R, sx, sy, 0, posX + sizeX/2 - X, posY + sizeY/2 - sy/RATIO, 0, 0, 0, 0, imageType)
set i = i + 1 // Down right corner
set imgs[this].image[i] = CreateImage(BOTTOM_R, sx, sy, 0, posX + sizeX/2 - X, posY - sizeY/2, 0, 0, 0, 0, imageType)
set j = 0
loop // Up and down blocks
set i = i + 1
set imgs[this].image[i] = CreateImage(TOP, sx, sy, 0, cx, posY + sizeY/2 - Y, 0, 0, 0, 0, imageType)
set i = i + 1
set imgs[this].image[i] = CreateImage(BOTTOM, sx, sy, 0, cx, posY - sizeY/2, 0, 0, 0, 0, imageType)
set j = j + 1
exitwhen j == nx
set cx = cx + sx/RATIO
endloop
set j = 0
loop // Left and right blocks
set i = i + 1
set imgs[this].image[i] = CreateImage(LEFT, sx, sy, 0, posX - sizeX/2, cy, 0, 0, 0, 0, imageType)
set i = i + 1
set imgs[this].image[i] = CreateImage(RIGHT, sx, sy, 0, posX + sizeX/2 - X, cy, 0, 0, 0, 0, imageType)
set j = j + 1
exitwhen j == ny
set cy = cy + sy/RATIO
endloop
set this.images = i
return this
endmethod
endstruct
struct CustomTextWindow extends array
private real ttPosX
private real ttPosY
private real height
private real ttSize
private integer visibility
private integer fadeRate
private integer fadeOutRate
private timer t
private timer tOut
private string title
private string text
texttag tt
private boolean destroys
private boolean destroysOut
CustomWindow cw
private thistype rn
private static integer ic = 0
private static integer ir = 0
method destroy takes nothing returns nothing
if this.tt != null then
call DestroyTextTag(this.tt)
set this.tt = null
endif
set this.title = null
set this.text = null
set this.destroys = false
if this.t != null then
call ReleaseTimer(this.t)
set this.t = null
endif
if this.tOut != null then
call ReleaseTimer(this.tOut)
set this.tOut = null
endif
call this.cw.destroy()
set this.rn = ir
set ir = this
endmethod
method setTransparency takes integer alpha returns nothing
set this.visibility = alpha
if this.tt == null and alpha > 0 and alpha < 255 then
call this.show(true)
call SetTextTagPermanent(this.tt, false)
call SetTextTagColor(this.tt, 255, 255, 255, alpha)
elseif alpha > 0 then
call SetTextTagColor(this.tt, 255, 255, 255, alpha)
elseif this.tt != null and alpha <= 0 then
call DestroyTextTag(this.tt)
set this.tt = null
endif
call this.cw.setTransparency(alpha)
endmethod
method show takes boolean show returns nothing
if show then
if this.tt == null then
set this.tt = CreateTextTag()
call SetTextTagText(this.tt, this.text, this.ttSize/1000)
call SetTextTagPos(this.tt, this.ttPosX, this.ttPosY, 0)
call SetTextTagColor(this.tt, 255, 255, 255, 255)
call SetTextTagVisibility(this.tt, true)
endif
else
if this.t != null then
call PauseTimer(this.t)
endif
call DestroyTextTag(this.tt)
set this.tt = null
endif
call this.cw.show(show)
endmethod
private static method fade takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
set this.visibility = this.visibility - this.fadeRate
if this.visibility > 0 and this.visibility < 255 then
call this.setTransparency(this.visibility)
else
call PauseTimer(this.t)
if this.destroys then
call this.destroy()
else
if this.fadeRate < 0 then
call this.setTransparency(255)
elseif this.fadeRate > 0 then
call this.setTransparency(0)
endif
if this.t != null then
call ReleaseTimer(this.t)
set this.t = null
endif
endif
endif
endmethod
private static method fadeDelay takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
set this.fadeRate = this.fadeOutRate
set this.destroys = this.destroysOut
call SetTextTagPermanent(this.tt, false)
if this.tOut != null then
call ReleaseTimer(this.tOut)
set this.tOut = null
endif
if this.t == null then
set this.t = NewTimerEx(this)
endif
call TimerStart(this.t, LOOPTIME, true, function thistype.fade)
endmethod
method fadeIn takes real time returns nothing
if .t == null then
set .t = NewTimerEx(this)
endif
if time == 0 then
set time = 0.01
endif
set .destroys = false
set .fadeRate = -(R2I(255*LOOPTIME/time) + 1)
call SetTextTagPermanent(.tt, false)
call TimerStart(.t, LOOPTIME, true, function thistype.fade)
endmethod
method fadeOut takes real time, real delay, boolean destroys returns nothing
if time == 0 then
set time = 0.01
endif
set .fadeOutRate = R2I(255*LOOPTIME/time) + 1
set .destroysOut = destroys
call SetTextTagPermanent(.tt, false)
if delay != 0 then
if .tOut == null then
set .tOut = NewTimerEx(this)
endif
call TimerStart(.tOut, delay, false, function thistype.fadeDelay)
else
if .tOut != null then
call PauseTimer(.tOut)
endif
if .t == null then
set .t = NewTimerEx(this)
endif
set this.fadeRate = this.fadeOutRate
set this.destroys = this.destroysOut
call TimerStart(.t, LOOPTIME, true, function thistype.fade)
endif
endmethod
method setHeight takes real height returns nothing
call SetTextTagPos(.tt, .ttPosX, .ttPosY, height)
call this.cw.setHeight(.height + height)
endmethod
private static method addRecycle takes nothing returns thistype
local thistype this
if 0==ir then
set ic=ic+1
set this=ic
else
set this=ir
set ir=.rn
endif
return this
endmethod
// posX and pos Y are the coordinates of bottom left corner
static method create takes string title, string text, real posX, real posY, real textSize, real borderScale, integer maxWidth, integer imageType returns thistype
local thistype this = thistype.addRecycle()
local integer i
local integer rows = 1
local integer wordlength = 0
local string word = null
local string newStr = null
local string char
local integer chars = 0
local integer charsMax = 0
local real width
local real sizeX
local real sizeY
if maxWidth > MAXCHARS or maxWidth == 0 then
set maxWidth = MAXCHARS
endif
if text != null then
set rows = rows + 1
set width = 0
set i = 0
loop
set char = SubString(text, i, i+1)
if char == " " or char == "" then
if chars < maxWidth then
set newStr = newStr + " " + word
if char == " " then
set chars = chars + 1
endif
if chars > charsMax then
set charsMax = chars
endif
else
if chars - wordlength > charsMax then
set charsMax = chars - wordlength
endif
set newStr = newStr + "\n" + " " + word
set chars = 1 + wordlength
set rows = rows + 1
endif
set word = null
set wordlength = 0
else
set chars = chars + 1
set wordlength = wordlength + 1
set word = word + char
endif
exitwhen char == ""
set i = i + 1
endloop
else
set charsMax = StringLength(title) + 2
endif
call MoveLocation(LOC, posX, posY)
set this.height = GetLocationZ(LOC)
set sizeX = charsMax * CHARWIDTH * textSize/5 + 2*DEFSIZE*borderScale
set sizeY = rows * CHARHEIGHT * textSize/5 + 2*DEFSIZE*borderScale
set this.ttSize = textSize
set this.ttPosX = posX
set this.ttPosY = posY
set this.title = title
set this.text = "|cffffcc00" + this.title + "|r\n" + newStr
set this.cw = CustomWindow.create(borderScale, sizeX, sizeY, posX+sizeX/2-DEFSIZE*borderScale, posY+sizeY/2-DEFSIZE*borderScale, imageType)
set char = null
set newStr = null
return this
endmethod
endstruct
endlibrary