TextTagUtils as a system which should ease the use with texttags for you. Creating a new texttag takes only one texttagconfig struct which contains all the neccessary data. These structs can be saved to easily reuse certain styles, you just have to change the text and position.
API:
Predefined texttagconfigs
Configs
Jass:
TEXTTAG_GOLD //Gold texttag when workers return gold
TEXTTAG_WOOD //Wood texttag when workers return wood
TEXTTAG_BOUNTY //When you kill a neutral creep
TEXTTAG_CRITICAL //Critical Strike-like
TEXTTAG_DEFAULT //Just a texttag with default settings which can be modified for instantly creating new texttags
struct texttagconfig
Members
Jass:
string text
real size
integer red
integer green
integer blue
real lifespan
real fadepoint
real angle
real speed
real x
real y
real z
boolean visible
boolean permanent
NewTextTag
Function
Jass:
function NewTextTag takes texttagconfig data returnstexttag
staticmethod create takestexttag which,unit to,real offset returns AttachedText
method setTextTag takestexttag which returnsnothingmethod setTarget takesunit to returnsnothingmethod setOffset takesreal z returnsnothing
Sample Usage:
Sample
Jass:
//Attaching a textbar to a unit is this simple!local TextBar tb = TextBar.create(10,5,9)call AttachedText.create(tb.getTextTag(), SomeRandomUnit,0)//Creating a custom bounty texttagset TEXTTAG_BOUNTY.text=I2S(GetRandomBounty)set TEXTTAG_BOUNTY.x=GetUnitX(GetDyingUnit())set TEXTTAG_BOUNTY.y=GetUnitY(GetDyingUnit())call NewTextTag(TEXTTAG_BOUNTY)
Jass:
//! zinclibrary TextTagUtils
{
constantstring DEFAULT_TEXT ="";
constantreal DEFAULT_SIZE =10.;
constantinteger DEFAULT_RED =255;
constantinteger DEFAULT_GREEN =255;
constantinteger DEFAULT_BLUE =255;
constantinteger DEFAULT_ALPHA =255;
constantreal DEFAULT_LIFESPAN =3.;
constantreal DEFAULT_FADEPOINT =2.;
constantreal DEFAULT_SPEED =64.;
constantreal DEFAULT_ANGLE =90.;
constantreal DEFAULT_X =0.;
constantreal DEFAULT_Y =0.;
constantreal DEFAULT_Z =0.;
constantboolean DEFAULT_VISIBILITY =true;
constantboolean DEFAULT_PERMANENT =false;
public
{
texttagconfig TEXTTAG_GOLD;
texttagconfig TEXTTAG_WOOD;
texttagconfig TEXTTAG_BOUNTY;
texttagconfig TEXTTAG_CRITICAL;
texttagconfig TEXTTAG_DEFAULT;
}
//Tile used by textbars. Can be changed with structname.setTile(new tile) though.constantstring TEXTBAR_TILE ="|";
//Color which is used for an empty tile.constantstring TEXTBAR_COLOR_EMPTY ="FFFFFF";
//Color which is used for a full tile.constantstring TEXTBAR_COLOR_FULL ="000000";
//How often the attached texttag updates.constantreal UPDATE_INTERVAL =0.02;
//If the texttag should be removed aswell when the struct gets destroyed.constantboolean AUTO_DESTROY =true;
publicstruct texttagconfig
{
string text = DEFAULT_TEXT;
real size = DEFAULT_SIZE;
integer red = DEFAULT_RED;
integer green = DEFAULT_GREEN;
integer blue = DEFAULT_BLUE;
integer alpha = DEFAULT_ALPHA;
real lifespan = DEFAULT_LIFESPAN;
real fadepoint = DEFAULT_FADEPOINT;
real speed = DEFAULT_SPEED;
real angle = DEFAULT_ANGLE;
real x = DEFAULT_X;
real y = DEFAULT_Y;
real z = DEFAULT_Z;
boolean visible = DEFAULT_VISIBILITY;
boolean permanent = DEFAULT_PERMANENT;
privatestaticmethod onInit()
{
TEXTTAG_GOLD =thistype.allocate();
TEXTTAG_GOLD.red=255;
TEXTTAG_GOLD.green=220;
TEXTTAG_GOLD.blue=0;
TEXTTAG_GOLD.lifespan=2;
TEXTTAG_GOLD.fadepoint=1;
TEXTTAG_WOOD =thistype.allocate();
TEXTTAG_WOOD.red=0;
TEXTTAG_WOOD.green=200;
TEXTTAG_WOOD.blue=80;
TEXTTAG_WOOD.lifespan=2;
TEXTTAG_WOOD.fadepoint=1;
TEXTTAG_BOUNTY =thistype.allocate();
TEXTTAG_BOUNTY.red=255;
TEXTTAG_BOUNTY.green=220;
TEXTTAG_BOUNTY.blue=0;
TEXTTAG_CRITICAL =thistype.allocate();
TEXTTAG_CRITICAL.red=255;
TEXTTAG_CRITICAL.green=0;
TEXTTAG_CRITICAL.blue=0;
TEXTTAG_CRITICAL.lifespan=5;
TEXTTAG_CRITICAL.fadepoint=2;
TEXTTAG_DEFAULT =thistype.allocate();
}
}
publicfunction NewTextTag(texttagconfig data)->texttag
{
texttag tt =CreateTextTag();
real vel, xvel, yvel;
SetTextTagText(tt, data.text, data.size*0.0023);
SetTextTagPos(tt, data.x, data.y, data.z);
SetTextTagColor(tt, data.red, data.green, data.blue, data.alpha);
SetTextTagVisibility(tt, data.visible);
SetTextTagPermanent(tt, data.permanent);
vel = data.speed*0.071/128;
xvel = vel*Cos(data.angle*bj_DEGTORAD);
yvel = vel*Sin(data.angle*bj_DEGTORAD);
SetTextTagVelocity(tt, xvel, yvel);
SetTextTagLifespan(tt, data.lifespan);
SetTextTagFadepoint(tt, data.fadepoint);
return tt;
}
publicstruct TextBar
{
string empty = TEXTBAR_COLOR_EMPTY;
string full = TEXTBAR_COLOR_FULL;
private
{
string tile = TEXTBAR_TILE;
texttag tt;
integer filled;
integer maxTiles;
real size;
}
staticmethod create(integer tiles,integer start,real siz)->thistype
{
thistypethis=thistype.allocate();
integer i =0;
string text ="";
this.tt=CreateTextTag();
this.size= siz*0.0023;
this.filled=0;
this.maxTiles= tiles;
if(this.tile=="|") { this.tile="||"; }
if(start >0)
{
while(this.filled< start)
{
text = text +"|cff"+this.full+this.tile+"|r";
this.filled+=1;
}
}
i =this.filled;
if(i <this.maxTiles)
{
while(i <this.maxTiles)
{
text = text +"|cff"+this.empty+this.tile+"|r";
i +=1;
}
}
SetTextTagText(this.tt, text,this.size);
returnthis;
}
method setFilled(integer fld)
{
string text ="";
integer i =0;
this.filled=0;
if(fld >0)
{
while(this.filled< fld)
{
text = text +"|cff"+this.full+this.tile+"|r";
this.filled+=1;
}
}
i =this.filled;
if(i <this.maxTiles)
{
while(i <this.maxTiles)
{
text = text +"|cff"+this.empty+this.tile+"|r";
i +=1;
}
}
SetTextTagText(this.tt, text,this.size);
}
method getFilled()->integer { returnthis.filled; }
method getTiles()->integer { returnthis.maxTiles; }
method getTextTag()->texttag { returnthis.tt; }
method getTile()->string { returnthis.tile; }
method getPercent()->real { returnthis.filled*100./this.maxTiles; }
method setPercent(integer p)
{
if(p >100) { p =100; } elseif(p <0) { p =0; }
this.setFilled(p*this.maxTiles/100);
}
method setTile(string t)
{
if(t =="|") { t ="||"; }
this.tile= t;
this.setPercent(R2I(this.getPercent()));
}
}
publicstruct AttachedText
{
private
{
texttag tt;
unit u;
real z;
staticthistype data[];
staticinteger count =0;
statictimer t =CreateTimer();
}
staticmethod create(texttag which,unit to,real offset)->thistype
{
thistypethis=thistype.allocate();
this.tt= which;
this.u= to;
this.z= offset;
if(this.count==0)
{
TimerStart(this.t, UPDATE_INTERVAL,true,staticmethodthistype.update);
}
this.data[this.count]=this;
this.count+=1;
returnthis;
}
method setTextTag(texttag t) { this.tt= t; }
method setTarget(unit to) { this.u= to; }
method setOffset(real ofs) { this.z= ofs; }
privatestaticmethod update()
{
thistypethis;
integer i =0;
while(i <this.count)
{
this=this.data[i];
SetTextTagPos(this.tt,GetUnitX(this.u),GetUnitY(this.u),this.z);
i +=1;
}
}
privatemethod onDestroy()
{
this.data[this]=this.data[this.count-1];
this.count-=1;
staticif(AUTO_DESTROY) { DestroyTextTag(this.tt); }
}
}
}
//! endzinc
Last edited by YourNameHere; 02-07-2010 at 10:26 AM.
Reason: New jass tag - update :P
Texttags work very differently from other handles, you can for example create them locally, and there is limit of 100 texttags per player, their handle indexes are pre allocated ( or something ).
Texttag recycling is not a good idea. It prevents you from creating local texttags, and doesnt really give you anything in return. ( But timers you should recycle instead of destroying them. Use TimerUtils for systems like these. )
We already have very good natives for handling texttags. How is some timer better than SetTextTagLifespan?
And I dont think that one function for creating texttags is good at all. Of course it is nice to have some own texttag creating functions for stuff like spell critical mesages and for that stuff units say in game, but Id rather use those natives for that kind of functions than some gigantic 12- arguments function.
In the other hand those attach texttag to unit thingies can be useful. You should also make some functions to change texttags size & color -overtime, instead of system like this.
This is really well coded and everything, but it just aint useful now. You should rather create some nice system for lightnings. They lack lifespan natives and need some over time color fading and locking to units in order to look good.
Texttags work very differently from other handles, you can for example create them locally, and there is limit of 100 texttags per player, their handle indexes are pre allocated ( or something ).
And you can't create other handles locally?
Quote:
Texttag recycling is not a good idea. It prevents you from creating local texttags, and doesnt really give you anything in return. ( But timers you should recycle instead of destroying them. Use TimerUtils for systems like these. )
Why would you need to create local texttags if you can use my function? It will also somewhat give you an unuqie, local texttag. And the created texttag get's returned?
localtexttag tt = NewTextTag()
Will work pretty fine at all.
Quote:
We already have very good natives for handling texttags. How is some timer better than SetTextTagLifespan?
The timer is only for recycling. The SetTextTagLifespan is still used.
Quote:
And I dont think that one function for creating texttags is good at all. Of course it is nice to have some own texttag creating functions for stuff like spell critical mesages and for that stuff units say in game, but Id rather use those natives for that kind of functions than some gigantic 12- arguments function.
Well that's your oppinion and I accept that. But I, for one, like this 12+ argument function more than 12+ lines for every texttag I create.
Quote:
In the other hand those attach texttag to unit thingies can be useful. You should also make some functions to change texttags size & color -overtime, instead of system like this.
Yeah that was the other purpose of the Utils. And the size and color over time is a good idea, I will implement it in the next version.
Quote:
This is really well coded and everything, but it just aint useful now. You should rather create some nice system for lightnings. They lack lifespan natives and need some over time color fading and locking to units in order to look good.
It isn't useful in your opinion, in mine it is. I think everyone should ask himself if he prefers this over the natives. You mustn't use my system. You also mustn't use TimerUtils, even if they're good, right? :)
The lightnings might be a good idea, I'll maybe do it when I'm the mood for it after I finished this.
And thanks for your critism. That's what I wanted to see :)
It's just to ease the function of texttags. You don't have to setup all that shit alone each time. If you like 12 lines of configuration for each texttag you create more, than don't use my system.
But, the Attach texttag to unit function is still useful. If I'll add more stuff like that, it'll still be useful for people like you.
But what bugs me mostly is that recycling. Why you even want to recycle texttags? ( Recycling pwns for timers, groups and units, but texttags? )
And since it requires some timer to recycling even work properly, it just adds some useless extra lagg when you use many texttags.
Also a fucntion with 12 arguments is just something really terrible. I dont know if it worked better with some nice struct syntax, it just might.
But yea, attaching texttag to units is something that cant be done with these natives we have, so it is pretty useful. If you add those over time scaling and color change thingies, even better. Some nice texttag movement thingies would be cool too.
Welll basically, you're right, but with the new GetTextTagSize, GetTextTagX, Y and Z I've added you have to recycle them, otherwise you'd just blow an hashtable up when you're using alot of texttags.
But what do you mean with
Quote:
I dont know if it worked better with some nice struct syntax, it just might.
?
edit/
New version posted. With alot more functions like SetTextTagSizeOverTime, set TextTagColorOverTime, GetTextTagSize, X, Y and Z and SetTextTagTextNew, SetTextTagX, Y and Z. Aswell a function for gradient string making (ColorStringGradient).
__________________
--YourNameHere
Last edited by YourNameHere; 08-21-2009 at 03:33 PM.
AHH, sorry, wrong map -_-
Ok yeah you're right, so I can switch from hashtables to arrays. Gonna implement that in the next version(which is already finished, I'll only have to switch to arrays now)
e/ new Version up. I'm still in need of hashtables when it comes to some specific things, but saving the data from the texttags now work with arrays. Also, MoveTextTagTimed and TextBars were added.
__________________
--YourNameHere
Last edited by YourNameHere; 08-25-2009 at 01:41 PM.