[Log in / Register]
| News | Chat | Pastebin | Donations | Tutorials | Rules | Forums | Starcraft II |
| Maps | Skins | Icons | Models | Spells | Tools | Jass | Packs |
(Keeps Hive Alive)
Go Back   The Hive Workshop > Warcraft III Resources > JASS Functions

JASS Functions Approved JASS functions will be located here.
Remember to submit your own resources to the submission forum.

Reply
 
LinkBack Thread Tools
Old 08-20-2009, 02:17 PM   #1 (permalink)
Registered User YourNameHere
wuts dis?
 
Join Date: Apr 2007
Posts: 592
YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)
TextTagUtils

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:

Documentation
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:
  • 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 returns texttag
  • struct TextBar
    Members
    Jass:
    string empty
    string full
    Methods
    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
    Methods
    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
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 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 by YourNameHere; 02-07-2010 at 10:26 AM. Reason: New jass tag - update :P
YourNameHere is offline   Reply With Quote
Old 08-20-2009, 05:31 PM   #2 (permalink)
Registered User aznricepuff
OOP freak.
 
Join Date: Feb 2006
Posts: 751
aznricepuff is a jewel in the rough (181)aznricepuff is a jewel in the rough (181)
Former Staff Member: This user used to be on the Hive Workshop staff. 
Might be useful to allow people to specify lifespan as well as fadepoint.
aznricepuff is offline   Reply With Quote
Old 08-20-2009, 05:49 PM   #3 (permalink)
Registered User YourNameHere
wuts dis?
 
Join Date: Apr 2007
Posts: 592
YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)
I thought everyone who needs that also specifies the fadetime, so you don't have to add that too. But as you wish, added it.

edit/ Does this need any more improvements to get approved? I'm open to every suggestion.
__________________
--YourNameHere

Last edited by YourNameHere; 08-20-2009 at 06:18 PM.
YourNameHere is offline   Reply With Quote
Old 08-20-2009, 09:34 PM   #4 (permalink)
Registered User Viikuna
User
 
Viikuna's Avatar
 
Join Date: Aug 2008
Posts: 338
Viikuna is on a distinguished road (61)Viikuna is on a distinguished road (61)
I dont think this system useful at all.

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.
__________________
No Marlo, no game.
Viikuna is offline   Reply With Quote
Old 08-20-2009, 10:01 PM   #5 (permalink)
Registered User YourNameHere
wuts dis?
 
Join Date: Apr 2007
Posts: 592
YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)
Quote:
Originally Posted by Viikuna View Post
I dont think this system useful at all.

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?
    local texttag 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 :)
__________________
--YourNameHere
YourNameHere is offline   Reply With Quote
Old 08-20-2009, 10:05 PM   #6 (permalink)
Registered User Viikuna
User
 
Viikuna's Avatar
 
Join Date: Aug 2008
Posts: 338
Viikuna is on a distinguished road (61)Viikuna is on a distinguished road (61)
By "creating locally" I mean this for example:


function luls takes nothing returns nothing
   local texttag t
   if GetLocalPlayer() == p then
      set t=CreateTextTag()
      // do something with t
   endif
endfunction

Your recycling, which btw serves no purpose, also fucks this up.

Quote:
But I, for one, like this 12+ argument function more than 12+ lines for every texttag I create.
12 + lines for map specific texttag functions you will need anyways.
__________________
No Marlo, no game.
Viikuna is offline   Reply With Quote
Old 08-20-2009, 10:27 PM   #7 (permalink)
Registered User YourNameHere
wuts dis?
 
Join Date: Apr 2007
Posts: 592
YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)
Quote:
Originally Posted by Viikuna View Post
By "creating locally" I mean this for example:


function luls takes nothing returns nothing
   local texttag t
   if GetLocalPlayer() == p then
      set t=CreateTextTag()
      // do something with t
   endif
endfunction
So, a extra function to create a text tag for a specific player should solve this, shouldn't it?


Quote:
12 + lines for map specific texttag functions you will need anyways.
Yeah, but only once. And if you use alot of texttags..
__________________
--YourNameHere
YourNameHere is offline   Reply With Quote
Old 08-20-2009, 11:51 PM   #8 (permalink)
Forum Moderator TriggerHappy
Spell & Trigger Moderator
 
TriggerHappy's Avatar
 
Join Date: Jun 2007
Posts: 1,055
TriggerHappy is just really nice (378)TriggerHappy is just really nice (378)TriggerHappy is just really nice (378)TriggerHappy is just really nice (378)
Zephyr Challenge #6 - Winner: Dune Worm PayPal Donor: This user has donated to The Hive. 
Just a bunch of BJ's, not very useful in my opinion.
TriggerHappy is offline   Reply With Quote
Old 08-20-2009, 11:58 PM   #9 (permalink)
Registered User YourNameHere
wuts dis?
 
Join Date: Apr 2007
Posts: 592
YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)
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.
__________________
--YourNameHere
YourNameHere is offline   Reply With Quote
Old 08-21-2009, 11:14 AM   #10 (permalink)
Registered User Viikuna
User
 
Viikuna's Avatar
 
Join Date: Aug 2008
Posts: 338
Viikuna is on a distinguished road (61)Viikuna is on a distinguished road (61)
Yea. Attaching texttags to units.

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.
__________________
No Marlo, no game.
Viikuna is offline   Reply With Quote
Old 08-21-2009, 12:12 PM   #11 (permalink)
Registered User YourNameHere
wuts dis?
 
Join Date: Apr 2007
Posts: 592
YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)
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.
YourNameHere is offline   Reply With Quote
Old 08-24-2009, 03:38 AM   #12 (permalink)
Forum Moderator azlier
Blasphemy!
 
Join Date: Oct 2008
Posts: 166
azlier has little to show at this moment (53)
Might I mention that a hashtable isn't needed here? Texttag handle id's are magically below 8191 without you having to lift a finger.
azlier is offline   Reply With Quote
Old 08-25-2009, 11:08 AM   #13 (permalink)
Registered User YourNameHere
wuts dis?
 
Join Date: Apr 2007
Posts: 592
YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)
e/ nvm..
__________________
--YourNameHere

Last edited by YourNameHere; 08-25-2009 at 01:18 PM.
YourNameHere is offline   Reply With Quote
Old 08-25-2009, 12:36 PM   #14 (permalink)
Registered User Viikuna
User
 
Viikuna's Avatar
 
Join Date: Aug 2008
Posts: 338
Viikuna is on a distinguished road (61)Viikuna is on a distinguished road (61)
Those thingies in your screenshot are lightnings. He was talking about texttags.
__________________
No Marlo, no game.
Viikuna is offline   Reply With Quote
Old 08-25-2009, 01:18 PM   #15 (permalink)
Registered User YourNameHere
wuts dis?
 
Join Date: Apr 2007
Posts: 592
YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)YourNameHere has a spectacular aura about (120)
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.
YourNameHere is offline   Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 12:44 PM.






Hosting by SliceHost 
Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.1
Copyright©Ralle