This is a small system that helps to render a texttag following timeline (using algorithm)
Code:
Now all in one
- All you need to use simply is the name of the style and the method .create(parameters) like this:
Code:
Now all in one
JASS:
// ==============================================
library DTT /* DynamicTextTag ver 2.3 - vuongkkk */
/* ==============================================
*
* - What is it for? -
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* The normal texttag is boring, need more dynamic like changing
* its properties overtime and self-destruct when expire. Then this resource is made
*
* - How does it work? -
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* All you must to do is describle how the texxtag change in a loop func
* then attach that to the new instance of the texttag.
* This system will do remain parts that is loop it overtime
* and change the texttag formation
*
* - How to use? -
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* === struct Controller ===
*
* The basic properties of a normal textag:
* - used like a setting with no change when running!
* - can retrieve or change them
real lifespan // Dangerous when change this but still allowed
real age // Dangerous when change this but still allowed
real fadepoint // only used for customization fade-out
integer red
integer green
integer blue
integer alpha
real angle // angle unit is degree
real speed
string text
real size
real posX
real posY
real posZ
* - Have setters to change them and save lines of code
method setupVelocity takes real speed, real angle returns nothing
method setupColor takes integer r,integer g,integer b,integer a returns nothing
method setupText takes string text, real size returns nothing
method setupPosition takes real x, real y, real z returns nothing
*
static method create takes player p, boolexpr func returns TextTag
* p is player that texttag display for.
* if p == null then display for all players
* func is the code control the changing of texttag over-time
*
readonly texttag tag // use to change how it displays with native funtions
*
* === Framework ===
*
* - How create your dynamic texttag:
* + I have build-in stylish texttags. If don't like mines,
* feel free to create another with this framework!
* + Your dynamic texttag struct must to extends array
* + Use the textmacro like this Example:
public struct YourTexttag extends array
integer yourdata
// You can access all members of your struct and Controller
// after onLoop and onCreate like normal method:
//! runtextmacro DTT_onLoop()
// each 0.025s, the code in here will be executed
set .yourdata=.yourdata+1
set .blue=.blue+yourdata
//! runtextmacro DTT_End()
static method create takes player p, unit u, string mes, real height returns thistype
//! runtextmacro DTT_onCreateBeginning("p")
set fadepoint= 1.0
set lifespan= 2.0
call setupText(mes, 10.0)
call setupColor(0, 255, 0, 255)
call setupVelocity(90., 80)
call setupPosition(GetUnitX(u), GetUnitY(u), height)
return this
endmethod
endstruct
*
* - Interfaces of Changing Functions
*
method changeRed takes nothing returns integer
method changeGreen takes nothing returns integer
method changeBlue takes nothing returns integer
method changeAlpha takes nothing returns integer
method changePosition takes nothing returns nothing
method changeHeight takes nothing returns real
method changeSpeed takes nothing returns real
method changeAngle takes nothing returns real
method changeSize takes nothing returns real
*
* + The defination of those functions must be placed before DTT_onLoop
* + Make sure your defination is right else you code in that do NOT work
* + In them, you dont use native func to update texttag, just calculate
* then return the result
* + method changePosition is an exception: change position datas directly in it else nothing changes!
*
* - OnLoopModule (required if using changing funcs)
* + Implement it inside the loop func help the loop func
* to recognize the changing func
* + Define local var before implement this and do something after implement
* Ex:
public struct YourTexttag extends array
method changeAlpha takes nothing returns integer
return Normal.changeAlpha(this) // this func is created to work with fadepoint and create fx like SetTextTagFadepoint
endmethod // then copy this method and paste in your struct if you just want normal fade-out
//! runtextmacro DTT_onLoop()
local real r=0.1
implement OnLoopModule // Not have this line your method "changeAlpha" never runs
set r=r+1.6
//! runtextmacro DTT_End()
static method create takes player p, unit u, string mes, real height returns thistype
//! runtextmacro DTT_onCreateBeginning("p")
set fadepoint= 0.5 // if you implement changeAlpha & not point when to start fade-out fx, default point is 0.0
set lifespan= 1.0
call setupText(mes, 10.0)
call setupColor(0, 0, 255, 255)
call setupVelocity(90, 90)
call setupPosition(GetUnitX(u), GetUnitY(u), height)
return this
endmethod
endstruct
*
* - What do you need to note? -
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* + all angles here use degree is unit
* + SetTextTagFadepoint do NOT work with this resource
* + globals vars are shorter than defining local ones. When you calculate,
* you can use static vars below as temporary vars:
DTT_R
DTT_G
DTT_B
DTT_Al
DTT_A
DTT_Spd
* + never set value for Controller.current!
* + you should change vars: age, fadepoint and lifespan carefully because it may to be the cause of infinitve loop!
*
* - Credit -
* ¯¯¯¯¯¯¯¯¯¯¯
* Nestharus
* + Queue: help this sys have a good destruction behavior
* + Recycler: make allocate method faster
* Tom_Kazansky: fix bug displayer texttag for a player
*
* =======================================================================================
*/
globals
public constant real PERIOD = 0.025 // how smooth texttags changes
public integer R // Red
public integer G // Green
public integer B // Blue
public integer Al // Alpha
public real A // Angle
public real Spd // Speed
endglobals
function SetTextTagVelocityEx takes texttag tag, real speed, real angle returns nothing
call SetTextTagVelocity(tag, speed*Cos(angle* bj_DEGTORAD)*.071/128, speed*Sin(angle* bj_DEGTORAD)*.071/128)
endfunction
public struct Controller extends array
private static integer timerInstanceCount = 0
private static thistype instanceCount = 0
private static integer array recycler
private static timer T = CreateTimer()
private static trigger trig=CreateTrigger()
private triggercondition la // loop action
readonly texttag tag
real lifespan
real age
real fadepoint
integer red
integer green
integer blue
integer alpha
method setupColor takes integer r,integer g,integer b,integer a returns nothing
set this.red = r
set this.green = g
set this.blue = b
set this.alpha = a
call SetTextTagColor(tag,r,g,b,a)
endmethod
real posX
real posY
real posZ
real posOffX
real posOffY
method setupPosition takes real x, real y, real z returns nothing
set posX=x
set posY=y
set posZ=z
call SetTextTagPos(tag, x + posOffX, y + posOffY, z)
endmethod
string text
real size
method setupText takes string text, real size returns nothing
set .text = text
set .size = size
call SetTextTagText(tag, text, size*0.0023)
endmethod
real angle
real speed
method setupVelocity takes real speed, real angle returns nothing
set .angle = angle
set .speed = speed
call SetTextTagVelocityEx(tag, speed, angle)
endmethod
static thistype current
readonly thistype next
private thistype prev
private method remove takes nothing returns nothing
call DestroyTextTag(tag)
call TriggerRemoveCondition(trig, la)
set prev.next = next
set next.prev = prev
endmethod
private static method allocate takes boolean createForPlayer returns thistype
local thistype this = recycler[0]
local texttag tt=CreateTextTag()
if GetHandleId(tt)==0 then
set this = thistype(0).next
call remove()
set tt=CreateTextTag()
endif
if (0 == this) then
set this = instanceCount + 1
set instanceCount = this
else
set recycler[0] = recycler[this]
endif
call SetTextTagVisibility(tt, createForPlayer)
call SetTextTagPermanent(tt,false)
// enqueue
set next = 0
set prev = thistype(0).prev
set thistype(0).prev.next = this
set thistype(0).prev = this
set tag=tt
set age=0
set fadepoint = 0
set red=0
set green=0
set blue=0
set alpha=255
set posX = 0
set posY = 0
set posZ = 0
set posOffX = 0
set posOffY = 0
set text = "No text here"
set size = 10
set angle = 90
set speed = 90
return this
endmethod
static method create takes player p, boolexpr func returns thistype
if p!=null then
set current=allocate(GetLocalPlayer()==p)
else
set current=allocate(true)
endif
set current.la=TriggerAddCondition(trig, func)
if (0 == timerInstanceCount) then
call TimerStart(T, PERIOD, true, function thistype.update)
endif
set timerInstanceCount = timerInstanceCount + 1
return current
endmethod
private static method update takes nothing returns nothing
local thistype this = thistype(0).next
loop
exitwhen 0 == this
if age < lifespan-PERIOD then
set age = age + PERIOD
set this = next
else
call remove()
set recycler[this] = recycler[0]
set recycler[0] = this
set this = next
set timerInstanceCount = timerInstanceCount - 1
endif
endloop
set current=thistype(0).next
if (0 == timerInstanceCount) then
call PauseTimer(T)
else
call TriggerEvaluate(trig)
endif
endmethod
endstruct
//==================================================
//========== The Bone of Framework =================
//! textmacro DTT_onLoop
private delegate Controller tt
static method onLoop takes nothing returns boolean
local thistype this=thistype(Controller.current)
//! endtextmacro
//! textmacro DTT_End
set Controller.current=next
return false
endmethod
private static boolexpr cons
private static method onInit takes nothing returns nothing
set thistype.cons=Condition(function thistype.onLoop)
endmethod
//! endtextmacro
//! textmacro DTT_onCreateBeginning takes agrPlayer
local thistype this=thistype(Controller.create($agrPlayer$, cons))
set tt=this
//! endtextmacro
public module OnLoopModule
// change size
static if thistype.changeSize.exists then
call SetTextTagText(tag,text,.changeSize()*.0023)
endif
//change xoffset, yoffset and hoffset
static if thistype.changeHeight.exists then
static if thistype.changePosition.exists then
call .changePosition()
endif
call SetTextTagPos(tag, posX + posOffX, posY + posOffY, .changeHeight())
elseif thistype.changePosition.exists then
call .changePosition()
static if thistype.changeHeight.exists then
call SetTextTagPos(tag, posX + posOffX, posY + posOffY, .changeHeight())
else
call SetTextTagPos(tag, posX + posOffX, posY + posOffY, posZ)
endif
endif
// change speed and angle
static if thistype.changeSpeed.exists then
set A = angle
set Spd=.changeSpeed()
static if thistype.changeAngle.exists then
set A=.changeAngle()
endif
call SetTextTagVelocityEx(tag,Spd, A)
elseif thistype.changeAngle.exists then
set Spd = speed
set A = .changeAngle()
static if thistype.changeSpeed.exists then
set A=.changeSpeed()
endif
call SetTextTagVelocityEx(tag,Spd, A)
endif
// change color and alpha
static if thistype.changeRed.exists then
set R = changeRed()
else
set R = red
endif
static if thistype.changeGreen.exists then
set G = changeGreen()
else
set G = green
endif
static if thistype.changeBlue.exists then
set B = changeBlue()
else
set B = blue
endif
set Al = alpha
static if thistype.changeAlpha.exists then
if fadepoint<=age then
set Al = .changeAlpha()
if Al>255 then
set Al=255
endif
endif
endif
call SetTextTagColor(tag,R,G,B,Al)
endmodule
//=====================================================
//========== Build-in Stylish TextTag =================
// This func is very useful!
private function Parabol takes real h, real d, real x returns real
return (4 * h / d) * (d - x) * (x / d)
endfunction
public struct Normal extends array
static method changeAlpha takes Controller c returns integer
return R2I(c.alpha/(c.lifespan-c.fadepoint)*(c.lifespan-c.age))
endmethod
endstruct
public struct Attach extends array
unit owner
method changePosition takes nothing returns nothing
set posX=GetUnitX(owner)
set posY=GetUnitY(owner)
set posZ=50+GetUnitFlyHeight(owner)
endmethod
method changeAlpha takes nothing returns integer
return Normal.changeAlpha(this)
endmethod
//! runtextmacro DTT_onLoop()
implement OnLoopModule
//! runtextmacro DTT_End()
static method create takes unit u, player p, string mes returns thistype
//! runtextmacro DTT_onCreateBeginning("p")
set fadepoint= 0.8
set lifespan= 1.6
call setupText(mes, 12.0)
call setupColor(41, 165, 94, 255)
call setupVelocity(70., 90)
set posOffX=-StringLength(mes)*size*.7
call setupPosition(GetUnitX(u), GetUnitY(u), 50+GetUnitFlyHeight(u))
set owner=u
return this
endmethod
endstruct
public struct Jump extends array
method changeSize takes nothing returns real
return size+Parabol(7.7,lifespan, age)
endmethod
method changeSpeed takes nothing returns real
set speed=speed+20/lifespan*PERIOD
return speed+Parabol(45.0,lifespan, age)+age*1.01
endmethod
method changeAngle takes nothing returns real
return angle+Parabol(StringLength(text)*0.42,lifespan, age)
endmethod
method changeAlpha takes nothing returns integer
return Normal.changeAlpha(this)
endmethod
//! runtextmacro DTT_onLoop()
implement OnLoopModule
//! runtextmacro DTT_End()
static method create takes player p, string mes, real x, real y, real h returns thistype
//! runtextmacro DTT_onCreateBeginning("p")
set fadepoint= 0.7
set lifespan= 1.0
call setupText(mes, 4.5)
call setupColor(25, 208, 24, 255)
call setupVelocity(71., 90)
call setupPosition(x, y, h)
return this
endmethod
endstruct
public struct Inclined extends array
method changeSize takes nothing returns real
return size+Parabol(7.0,lifespan, age)
endmethod
method changeAlpha takes nothing returns integer
return Normal.changeAlpha(this)
endmethod
//! runtextmacro DTT_onLoop()
implement OnLoopModule
//! runtextmacro DTT_End()
static method create takes player p, string mes, real x, real y, real h returns thistype
//! runtextmacro DTT_onCreateBeginning("p")
set fadepoint= 0.76
set lifespan= 1.2
call setupText(mes, 5.0)
call setupColor(251, 125, 0, 255)
call setupVelocity(95.00, 84)
call setupPosition(x, y, h)
return this
endmethod
endstruct
public struct Critical extends array
//! runtextmacro DTT_onLoop()
local real period=lifespan/6
if age < period then
call SetTextTagVelocityEx(tag,speed+Parabol(36.0,period*2, age),angle)
call SetTextTagText(tag,text, (size+Parabol(8.0,period, age))*0.0023)
else
if age > period*2 then
call SetTextTagColor(tag,red,green,blue, R2I(245/period/4*(lifespan-age))+10)
endif
endif
//! runtextmacro DTT_End()
static method create takes player p, string mes, real x, real y, real h returns thistype
//! runtextmacro DTT_onCreateBeginning("p")
set lifespan= 1.6
call setupColor(255, 23, 23, 255)
call setupVelocity(46.00, 90)
call setupText(mes, 7.7)
call setupPosition(x, y, h)
return this
endmethod
endstruct
public struct HeadUp extends array
method changeSpeed takes nothing returns real
if age < lifespan/2 then
return speed+Parabol(70.0,lifespan/2, age)
else
return speed
endif
endmethod
method changeAlpha takes nothing returns integer
return Normal.changeAlpha(this)
endmethod
//! runtextmacro DTT_onLoop()
implement OnLoopModule
//! runtextmacro DTT_End()
static method create takes player p, string mes, real x, real y, real h returns thistype
//! runtextmacro DTT_onCreateBeginning("p")
set fadepoint= 0.7
set lifespan= 1.4
call setupText(mes, 10.0)
call setupColor(227, 15, 227, 245)
call setupVelocity(80, 90)
call setupPosition(x, y, h)
return this
endmethod
endstruct
public struct Curved extends array
method changeSize takes nothing returns real
return size+Parabol(8.0,lifespan, age)
endmethod
method changeAngle takes nothing returns real
return angle+Parabol(18.0,lifespan, age)
endmethod
method changeSpeed takes nothing returns real
if age < lifespan/2 then
return (speed+Parabol(49.0,lifespan, age))
else
return (speed+49.0)*(1+0.05*(age-lifespan/2)/PERIOD)
endif
endmethod
method changeAlpha takes nothing returns integer
return Normal.changeAlpha(this)
endmethod
//! runtextmacro DTT_onLoop()
implement OnLoopModule
//! runtextmacro DTT_End()
static method create takes player p, string mes, real x, real y, real h returns thistype
//! runtextmacro DTT_onCreateBeginning("p")
set fadepoint= 0.78
set lifespan= 1.0
call setupText(mes, 5.0)
call setupColor(248, 237, 0, 255)
call setupVelocity(49.00, 90)
call setupPosition(x, y, h)
return this
endmethod
endstruct
public struct Whirl extends array
method changeSize takes nothing returns real
return size+Parabol(7.0,lifespan, age)
endmethod
method changeSpeed takes nothing returns real
return speed+Parabol(42.0,lifespan, age)+age*1.01
endmethod
method changeAngle takes nothing returns real
return angle+Parabol(460.0,lifespan, age)
endmethod
method changeAlpha takes nothing returns integer
return alpha+R2I(Parabol(255-alpha,lifespan, age))
endmethod
//! runtextmacro DTT_onLoop()
implement OnLoopModule
//! runtextmacro DTT_End()
static method create takes player p, string mes, real x, real y, real h returns thistype
//! runtextmacro DTT_onCreateBeginning("p")
set lifespan= 1.3
call setupText(mes, 5.0)
call setupColor(180, 160, 30, 10)
call setupVelocity(29.00, 0)
call setupPosition(x, y, h)
return this
endmethod
endstruct
public struct SpeedUp extends array
method changeSpeed takes nothing returns real
return speed+Parabol(128.0,lifespan*2, age)
endmethod
method changeAlpha takes nothing returns integer
return Normal.changeAlpha(this)
endmethod
//! runtextmacro DTT_onLoop()
implement OnLoopModule
//! runtextmacro DTT_End()
static method create takes player p, string mes, real x, real y, real h returns thistype
//! runtextmacro DTT_onCreateBeginning("p")
set fadepoint= 0.45
set lifespan= 1.2
call setupText(mes, 10.6)
call setupColor(8, 190, 217, 255)
call setupVelocity(10, 90)
call setupPosition(x, y, h)
return this
endmethod
endstruct
public struct UpDown extends array
method changeSpeed takes nothing returns real
set speed=speed - 70/lifespan*PERIOD
return speed+Parabol(140.0,lifespan, age)
endmethod
method changeAlpha takes nothing returns integer
return alpha+R2I(Parabol(305,lifespan, age))
endmethod
//! runtextmacro DTT_onLoop()
implement OnLoopModule
//! runtextmacro DTT_End()
static method create takes player p, string mes, real x, real y, real h returns thistype
//! runtextmacro DTT_onCreateBeginning("p")
set lifespan= 1.2
call setupText(mes, 11.5)
call setupColor(33, 33, 190, 50)
call setupVelocity(10, 90)
call setupPosition(x, y, h)
return this
endmethod
endstruct
public struct Bump extends array
method changeSize takes nothing returns real
return size-(13-Parabol(13,lifespan*2, age+lifespan))
endmethod
method changeAlpha takes nothing returns integer
return Normal.changeAlpha(this)
endmethod
//! runtextmacro DTT_onLoop()
implement OnLoopModule
//! runtextmacro DTT_End()
static method create takes player p, string mes, real x, real y, real h returns thistype
//! runtextmacro DTT_onCreateBeginning("p")
set fadepoint= 0.4
set lifespan = 0.8
call setupText(mes, 15.)
call setupColor(185, 88, 30, 255)
call setupPosition(x, y, h)
return this
endmethod
endstruct
public struct PopUp extends array
method changeSize takes nothing returns real
return size+Parabol(9.0,lifespan, age)
endmethod
method changePosition takes nothing returns nothing
set posOffX=-StringLength(text)*.changeSize()*.467
endmethod
//! runtextmacro DTT_onLoop()
set red=120+R2I(Parabol(100,lifespan, age))
set green=55+R2I(Parabol(65,lifespan, age))
set blue=55+R2I(Parabol(35,lifespan, age))
if age<fadepoint then
call SetTextTagColor(tag,red,green,blue,alpha)
else
call SetTextTagColor(tag,red,green,blue,Normal.changeAlpha(this))
endif
implement OnLoopModule
//! runtextmacro DTT_End()
static method create takes player p, string mes, real x, real y, real h returns thistype
//! runtextmacro DTT_onCreateBeginning("p")
set fadepoint= 0.6
set lifespan= 1.0
call setupText(mes, 3.0)
call setupColor(180, 60, 60, 255)
call setupVelocity(97, 90)
set posOffX=-StringLength(mes)*size*.467
call setupPosition(x, y, h)
return this
endmethod
endstruct
endlibrary
- All you need to use simply is the name of the style and the method .create(parameters) like this:
call Texttag_Critical.create(Player(0),"Critical!", x, y, 70)
Attachments
Last edited: