vuongkkk
New Member
- Reaction score
- 1
VTexttag
System
I have a system and a extension
- DynamicTexttag: this sys provides a very simple method to create your stylish texttag!
Advantages
- Easy create the texttag color with RGB color (can use mspaint to pick a color)
- Setters have the API like Blizzard native function (easy to use)
- Easy implement the way you want how the texttag changes (with function interfaces)
- Code is clean & clear, can read easily, Documentation, too. Have example of usage
- Have 5 my build-in stylish texttags
- No need to care about destroy or recycle problem
Disadvantages
- Need math knowledge to control the changing of the texttag
- Appear the display problem when string is too long or text size is too big if you are careless
Code
DynamicTexttag
VTexttag
TexttagControllers
Demo map
VTexttag Ver 2.1c Demo map
Special thank:
Nestharus, Tom_Kazansky
VTexttag
Version 2.1
System
I have a system and a extension
- DynamicTexttag: this sys provides a very simple method to create your stylish texttag!
- No require
-VTexttag: this ext for anyone only want to use my stylish texttag or create stylish texttag faster!- Require DynamicTexttag
Advantages
- Easy create the texttag color with RGB color (can use mspaint to pick a color)
- Setters have the API like Blizzard native function (easy to use)
- Easy implement the way you want how the texttag changes (with function interfaces)
- Code is clean & clear, can read easily, Documentation, too. Have example of usage
- Have 5 my build-in stylish texttags
- No need to care about destroy or recycle problem
Disadvantages
- Need math knowledge to control the changing of the texttag
- Appear the display problem when string is too long or text size is too big if you are careless
Code
DynamicTexttag
JASS:
// ==============================================
library DynamicTexttag /* ver 2.1c - 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 DTexttag
// The basic properties of a normal textag:
* - used like a setting with no change when running!
* - can retrieve or change them
real age
real fadepoint
real lifespan
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
*
* + How create your dynamic texttag:
* Use the textmacro like this Example:
public struct YourTexttag extends array
integer yourdata
//! runtextmacro DTT_onLoop()
// each 0.025s, the code in here will be executed
// you can access all members of your struct and DTexttag in here like this:
set yourdata=yourdata+1
set tag.color.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
*
* - What do you need to note? -
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* + all angles here use degree is unit
* + SetTextTagFadepoint do NOT work with this resource
* + Your dynamic texttag struct should extends array
* + globals vars are faster than local ones. When you calculate,
* you can use static vars below as temporary vars:
DTexttag.R
DTexttag.G
DTexttag.B
DTexttag.Al
DTexttag.A
DTexttag.Spd
* + never set value for DTexttag.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
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
struct DTexttag 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 age
real fadepoint
real lifespan
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 * .0023)
endmethod
private boolean visible_p
method operator visible takes nothing returns boolean
return visible_p
endmethod
method operator visible= takes boolean visible returns nothing
set visible_p = visible
call SetTextTagVisibility(tag, visible)
endmethod
real angle
real speed
method setupVelocity takes real speed, real angle returns nothing
set .angle = angle
set .speed = speed
call SetTextTagVelocity(tag, speed*Cos(angle* bj_DEGTORAD)*.071/128, speed*Sin(angle* bj_DEGTORAD)*.071/128)
endmethod
static integer R // Red
static integer G // Green
static integer B // Blue
static integer Al // Alpha
static real A // Angle
static real Spd // Speed
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 (createForPlayer) then
call SetTextTagVisibility(tt, true)
endif
if (0 == this) then
set this = instanceCount + 1
set instanceCount = this
else
set recycler[0] = recycler[this]
endif
// 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
call SetTextTagPermanent(tag,false)
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 DTexttag
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
//! textmacro DTT_onLoop
static method onLoop takes nothing returns boolean
local thistype this=thistype(DTexttag.current)
//! endtextmacro
//! textmacro DTT_End
set DTexttag.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
private delegate DTexttag tt
//! endtextmacro
//! textmacro DTT_onCreateBeginning takes agrPlayer
local thistype this=thistype(DTexttag.create($agrPlayer$, cons))
set tt=this
//! endtextmacro
endlibrary
VTexttag
JASS:
// ============================================================
library VTexttag /* ver 2.1 - vuongkkk */uses DynamicTexttag
/* ============================================================
*
* - What is it for? -
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* Same as DynamicTexttag but it's more specific and base on DynamicTexttag
* So that, don't like my way to create dynamic texttag,
* feel free to create another with DynamicTexttag!
*
* - How to use? -
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*
* + Interfaces
*
static method changeRed takes DTexttag t returns integer
static method changeGreen takes DTexttag t returns integer
static method changeBlue takes DTexttag t returns integer
static method changeAlpha takes DTexttag t returns integer
static method changePosition takes DTexttag t returns nothing
static method changeHeight takes DTexttag t returns real
static method changeSpeed takes DTexttag t returns real
static method changeAngle takes DTexttag t returns real
static method changeSize takes DTexttag t returns real
*
* - The defination of those interface must be placed before loop func
* - In them, you dont use native func to update texttag, just calculate
* then return the result
* - method changePosition is an exception: change pos directly in it
*
* + Modules
*
* OnLoopModule (required if using funcs are defined from the interfaces)
* - implement it inside the loop func help the loop func
* to recognize the changing func
* - define local var before implement and do something after implement
* Ex:
//! runtextmacro DTT_onLoop()
local real r=0.1
implement OnLoopModule
set r=r+1.6
//! runtextmacro DTT_End()
*
* - What do you need to note? -
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* - Can re-use the calculating func
* + Copy and paste
* + recall it in the same type calculating func but you must declare it properly
* Ex:
static method changeAlpha takes DTexttag t returns integer
return VTexttag_Normal.changeAlpha(t)
endmethod
* - Your dynamic texttag struct should extends array
*
* =======================================================================================
*/
public module OnLoopModule
//change xoffset, yoffset and hoffset
static if thistype.changeHeight.exists then
static if thistype.changePosition.exists then
call thistype.changePosition(this)
endif
call SetTextTagPos(tag, posX + posOffX, posY + posOffY, thistype.changeHeight(this))
elseif thistype.changePosition.exists then
call thistype.changePosition(this)
static if thistype.changeHeight.exists then
call SetTextTagPos(tag, posX + posOffX, posY + posOffY, thistype.changeHeight(this))
else
call SetTextTagPos(tag, posX + posOffX, posY + posOffY, posZ)
endif
endif
// change speed and angle
static if thistype.changeSpeed.exists then
set DTexttag.A = angle
set DTexttag.Spd=thistype.changeSpeed(this)
static if thistype.changeAngle.exists then
set DTexttag.A=thistype.changeAngle(this)
endif
call SetTextTagVelocityEx(tag,DTexttag.Spd, DTexttag.A)
elseif thistype.changeAngle.exists then
set DTexttag.Spd = speed
set DTexttag.A = thistype.changeAngle(this)
static if thistype.changeSpeed.exists then
set DTexttag.A=thistype.changeSpeed(this)
endif
call SetTextTagVelocityEx(tag,DTexttag.Spd, DTexttag.A)
endif
// change size
static if thistype.changeSize.exists then
call SetTextTagText(tag,text,thistype.changeSize(this)*.0023)
endif
// change color and alpha
static if thistype.changeRed.exists then
set DTexttag.R = thistype.changeRed(this)
else
set DTexttag.R = red
endif
static if thistype.changeGreen.exists then
set DTexttag.G = thistype.changeGreen(this)
else
set DTexttag.G = green
endif
static if thistype.changeBlue.exists then
set DTexttag.B = thistype.changeBlue(this)
else
set DTexttag.B = blue
endif
set DTexttag.Al = alpha
static if thistype.changeAlpha.exists then
if fadepoint<=age and fadepoint>0 then
set DTexttag.Al = thistype.changeAlpha(this)
endif
endif
call SetTextTagColor(tag,DTexttag.R,DTexttag.G,DTexttag.B,DTexttag.Al)
endmodule
/*
* Useful stuffs
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*/
// 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
/*
* = Build-in Stylish TextTag =
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*/
public struct Normal extends array
static method changeAlpha takes DTexttag t returns integer
return R2I(t.alpha/(t.lifespan-t.fadepoint)*(t.lifespan-t.age))
endmethod
static method changeBlue takes DTexttag t returns integer
return (t.blue+R2I(Parabol(255-t.blue,t.lifespan, t.age)))
endmethod
endstruct
public struct Attach extends array
unit owner
static method changePosition takes DTexttag t returns nothing
set t.posX=GetUnitX(thistype(t).owner)
set t.posY=GetUnitY(thistype(t).owner)
endmethod
static method changeAlpha takes DTexttag t returns integer
return VTexttag_Normal.changeAlpha(t)
endmethod
//! runtextmacro DTT_onLoop()
implement OnLoopModule
//! runtextmacro DTT_End()
static method create takes unit u, player p, string mes, real h returns thistype
//! runtextmacro DTT_onCreateBeginning("p")
set fadepoint= 1.0
set lifespan= 2.1
call setupText(mes, 12.0)
call setupColor(65, 238, 34, 255)
call setupVelocity(70., 90)
call setupPosition(GetUnitX(u), GetUnitY(u), h)
set owner=u
return this
endmethod
endstruct
public struct Jump extends array
static method changeAlpha takes DTexttag t returns integer
return VTexttag_Normal.changeAlpha(t)
endmethod
static method changeSpeed takes DTexttag t returns real
return (t.speed+Parabol(52.0,t.lifespan, t.age)+t.age*1.01)
endmethod
static method changeSize takes DTexttag t returns real
return (t.size+Parabol(11.0,t.lifespan, t.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 fadepoint= 0.6
set lifespan= 1.2
call setupText(mes, 8.0)
call setupColor(25, 208, 24, 255)
call setupVelocity(85., 87)
call setupPosition(x, y, h)
return this
endmethod
endstruct
public struct Inclined extends array
static method changeAlpha takes DTexttag t returns integer
return VTexttag_Normal.changeAlpha(t)
endmethod
static method changeSize takes DTexttag t returns real
return (t.size+Parabol(8.0,t.lifespan, t.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 fadepoint= 1.0
set lifespan= 1.8
call setupText(mes, 7.0)
call setupColor(251, 125, 0, 255)
call setupVelocity(95.00, 75)
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(9.0,period, age))*.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= 2.2
call setupColor(255, 23, 23, 255)
call setupVelocity(46.00, 90)
call setupText(mes, 9.0)
call setupPosition(x, y, h)
return this
endmethod
endstruct
public struct HeadUp extends array
static method changeAlpha takes DTexttag t returns integer
return VTexttag_Normal.changeAlpha(t)
endmethod
static method changeHeight takes DTexttag t returns real
if t.age < t.lifespan/2 then
return (t.posZ+Parabol(38.0,t.lifespan/2, t.age))
else
return t.posZ
endif
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= 1.1
set lifespan= 2.0
call setupText(mes, 12.0)
call setupColor(227, 15, 227, 245)
call setupVelocity(90.00, 90)
call setupPosition(x, y, h)
return this
endmethod
endstruct
public struct Curved extends array
static method changeAlpha takes DTexttag t returns integer
return VTexttag_Normal.changeAlpha(t)
endmethod
static method changeSize takes DTexttag t returns real
return (t.size+Parabol(10.0,t.lifespan, t.age))
endmethod
static method changeAngle takes DTexttag t returns real
return (t.angle+Parabol(18.0,t.lifespan, t.age))
endmethod
static method changeSpeed takes DTexttag t returns real
if t.age < t.lifespan/2 then
return (t.speed+Parabol(46.0,t.lifespan, t.age))
else
return (t.speed+36.0)*(1+0.05*(t.age-t.lifespan/2)/DynamicTexttag_PERIOD)
endif
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.9
set lifespan= 1.8
call setupText(mes, 7.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
static method changeAlpha takes DTexttag t returns integer
return R2I(Parabol(255,t.lifespan, t.age))
endmethod
static method changeAngle takes DTexttag t returns real
return (t.angle+Parabol(460.0,t.lifespan, t.age))
endmethod
static method changeSize takes DTexttag t returns real
return (t.size+Parabol(9.0,t.lifespan, t.age))
endmethod
static method changeSpeed takes DTexttag t returns real
return (t.speed+Parabol(42.0,t.lifespan, t.age)+t.age*1.01)
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.01
set lifespan= 1.9
call setupText(mes, 7.0)
call setupColor(224, 200, 27, 0)
call setupVelocity(29.00, 0)
call setupPosition(x, y, h)
return this
endmethod
endstruct
endlibrary
TexttagControllers
JASS:
library TexttagControllers requires VTexttag
//=================================================
// Author: vuongkkk
// Version: 1.6
//=================================================
/*
* You can see the API in there is not change althought VTTexttag is completely different
* So don't worry about anything if you use these func to create a VTexttag
*
* Even this code is not neccessary for who uses vjass
* Just VTexttag and DynamicTexttag is enough
*
* All you need is Math knowledge to create a interesting texttag !
*/
globals
// only for test
constant integer TexttagStyle_Attach = 1
constant integer TexttagStyle_HeadUp = 2
constant integer TexttagStyle_Inclined=3
constant integer TexttagStyle_Jump = 4
constant integer TexttagStyle_Critical =5
constant integer TexttagStyle_Curved =6
constant integer TexttagStyle_Whirl =7
endglobals
// Note:
// - If you don't specify a player (p=null) then texttag will display for all players
function AttachVTexttag_Create takes string mes, player p, unit u, real h returns nothing
call VTexttag_Attach.create(u,p,mes, 50)
endfunction
function JumpVTexttag_Create takes string mes, player p, real x, real y, real h returns nothing
call VTexttag_Jump.create(p,mes,x,y, 70)
endfunction
function InclinedVTexttag_Create takes string mes, player p, real x, real y, real h returns nothing
call VTexttag_Inclined.create(p,mes,x,y, 70)
endfunction
function CriticalVTexttag_Create takes string mes, player p, real x, real y, real h returns nothing
call VTexttag_Critical.create(p,mes,x,y, 70)
endfunction
function HeadUpVTexttag_Create takes string mes, player p, real x, real y, real h returns nothing
call VTexttag_HeadUp.create(p,mes,x,y, 70)
endfunction
function CurvedVTexttag_Create takes string mes, player p, real x, real y, real h returns nothing
call VTexttag_Curved.create(p,mes,x,y, 70)
endfunction
function WhirlVTexttag_Create takes string mes, player p, real x, real y, real h returns nothing
call VTexttag_Whirl.create(p,mes,x,y, 70)
endfunction
// for test performance
// type chat string "/fps" to display FPS
struct VTTTester
private static real x
private static real y
private static unit sheep
static method onTimer takes nothing returns nothing
call VTexttag_Attach.create(.sheep,Player(0),"Attach!", 50)
call VTexttag_Inclined.create(Player(0),"Inclined!",.x-200,.y, 70)
call VTexttag_Jump.create(Player(0),"Jump!",.x+200,.y, 70)
call VTexttag_Critical.create(Player(0),"Critical!",.x,.y+300, 70)
call VTexttag_HeadUp.create(Player(0),"HeadUp!",.x,.y-300, 70)
call VTexttag_Curved.create(Player(0),"Curved!",.x-200,.y-300, 70)
call VTexttag_Whirl.create(Player(0),"Whirl!",.x+200,.y-300, 70)
call VTexttag_Attach.create(.sheep,Player(1),"Attach!", 50)
call VTexttag_Inclined.create(Player(1),"Inclined!",.x-200,.y, 70)
call VTexttag_Jump.create(Player(1),"Jump!",.x+200,.y, 70)
call VTexttag_Critical.create(Player(1),"Critical!",.x,.y+300, 70)
call VTexttag_HeadUp.create(Player(1),"HeadUp!",.x,.y-300, 70)
call VTexttag_Curved.create(Player(1),"Curved!",.x-200,.y-300, 70)
call VTexttag_Whirl.create(Player(1),"Whirl!",.x+200,.y-300, 70)
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterTimerEvent(t, 0.325, true)
call TriggerAddAction(t, function thistype.onTimer)
set .x=GetRectCenterX(bj_mapInitialPlayableArea)
set .y=GetRectCenterY(bj_mapInitialPlayableArea)
set .sheep = CreateUnit(Player(0),039;nsha039;,.x,.y,0)
endmethod
endstruct
endlibrary
Demo map
VTexttag Ver 2.1c Demo map
Special thank:
Nestharus, Tom_Kazansky