- Joined
- Apr 29, 2007
- Messages
- 826
So I made this system to ease the use with texttags, which was pretty uncomfortable. I think everything is explained well enough in the documentation.
Requires:
Requires:
TextTagUtils v2.0
by YourName
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:
by YourName
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
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
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
JASS:
function NewTextTag takes texttagconfig data returns texttag
- struct TextBar
JASS:
string empty string full
JASS:static method create takes integer tiles, integer tilesfilled, real size returns TextBar method getFilled takes nothing returns integer method getTiles takes nothing returns integer method getTextTag takes nothing returns texttag method getTile takes nothing returns string method getPercent takes nothing returns real method setFilled takes integer filled returns nothing method setPercent takes integer percent returns nothing method setTile takes string tile returns nothing
- struct AttachedText
JASS:
static method create takes texttag which, unit to, real offset returns AttachedText method setTextTag takes texttag which returns nothing method setTarget takes unit to returns nothing method setOffset takes real z returns nothing
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 texttag
set TEXTTAG_BOUNTY.text = I2S(GetRandomBounty)
set TEXTTAG_BOUNTY.x = GetUnitX(GetDyingUnit())
set TEXTTAG_BOUNTY.y = GetUnitY(GetDyingUnit())
call NewTextTag(TEXTTAG_BOUNTY)
JASS:
//! zinc
library TextTagUtils
{
constant string DEFAULT_TEXT = "";
constant real DEFAULT_SIZE = 10.;
constant integer DEFAULT_RED = 255;
constant integer DEFAULT_GREEN = 255;
constant integer DEFAULT_BLUE = 255;
constant integer DEFAULT_ALPHA = 255;
constant real DEFAULT_LIFESPAN = 3.;
constant real DEFAULT_FADEPOINT = 2.;
constant real DEFAULT_SPEED = 64.;
constant real DEFAULT_ANGLE = 90.;
constant real DEFAULT_X = 0.;
constant real DEFAULT_Y = 0.;
constant real DEFAULT_Z = 0.;
constant boolean DEFAULT_VISIBILITY = true;
constant boolean 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.
constant string TEXTBAR_TILE = "|";
//Color which is used for an empty tile.
constant string TEXTBAR_COLOR_EMPTY = "FFFFFF";
//Color which is used for a full tile.
constant string TEXTBAR_COLOR_FULL = "000000";
//How often the attached texttag updates.
constant real UPDATE_INTERVAL = 0.02;
//If the texttag should be removed aswell when the struct gets destroyed.
constant boolean AUTO_DESTROY = true;
public struct 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;
private static method 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();
}
}
public function 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;
}
public struct TextBar
{
string empty = TEXTBAR_COLOR_EMPTY;
string full = TEXTBAR_COLOR_FULL;
private
{
string tile = TEXTBAR_TILE;
texttag tt;
integer filled;
integer maxTiles;
real size;
}
static method create(integer tiles, integer start, real siz) -> thistype
{
thistype this = 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);
return this;
}
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 { return this.filled; }
method getTiles() -> integer { return this.maxTiles; }
method getTextTag() -> texttag { return this.tt; }
method getTile() -> string { return this.tile; }
method getPercent() -> real { return this.filled*100./this.maxTiles; }
method setPercent(integer p)
{
if (p > 100) { p = 100; } else if (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()));
}
}
public struct AttachedText
{
private
{
texttag tt;
unit u;
real z;
static thistype data[];
static integer count = 0;
static timer t = CreateTimer();
}
static method create(texttag which, unit to, real offset) -> thistype
{
thistype this = thistype.allocate();
this.tt = which;
this.u = to;
this.z = offset;
if (this.count == 0)
{
TimerStart(this.t, UPDATE_INTERVAL, true, static method thistype.update);
}
this.data[this.count] = this;
this.count += 1;
return this;
}
method setTextTag(texttag t) { this.tt = t; }
method setTarget(unit to) { this.u = to; }
method setOffset(real ofs) { this.z = ofs; }
private static method update()
{
thistype this;
integer i = 0;
while(i < this.count)
{
this = this.data[i];
SetTextTagPos(this.tt, GetUnitX(this.u), GetUnitY(this.u), this.z);
i += 1;
}
}
private method onDestroy()
{
this.data[this] = this.data[this.count-1];
this.count -= 1;
static if (AUTO_DESTROY) { DestroyTextTag(this.tt); }
}
}
}
//! endzinc
Last edited: