Warcraft 3 documentation

vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation - Zinc documentation - WC3 Optimizer documentation

TextTag

Guest · 973

0 Members and 1 Guest are viewing this topic.

TextTag
on: August 21, 2011, 07:41:29 AM
Category: Interface
Language: vJASS
Download Demo Map

Code: jass
  1. //==============================================================================
  2. //  TEXT TAG - Floating text system by Cohadar - v5.0
  3. //==============================================================================
  4. //
  5. //  PURPOUSE:
  6. //       * Displaying floating text - the easy way
  7. //       * Has a set of useful and commonly needed texttag functions
  8. //  
  9. //  CREDITS:
  10. //       * DioD - for extracting proper color, fadepoint and lifespan parameters
  11. //         for default warcraft texttags (from miscdata.txt)
  12. //
  13. //  HOW TO IMPORT:
  14. //       * Just create a trigger named TextTag
  15. //         convert it to text and replace the whole trigger text with this one
  16. //==============================================================================
  17.  
  18. library TextTag
  19.  
  20. globals    
  21.     // for custom centered texttags
  22.     private constant real MEAN_CHAR_WIDTH = 5.5
  23.     private constant real MAX_TEXT_SHIFT = 200.0
  24.     private constant real DEFAULT_HEIGHT = 16.0
  25.  
  26.     // for default texttags
  27.     private constant real   SIGN_SHIFT = 16.0
  28.     private constant real   FONT_SIZE = 0.024
  29.     private constant string MISS = "miss"
  30. endglobals
  31.  
  32. //===========================================================================
  33. //   Custom centered texttag on (x,y) position
  34. //   color is in default wc3 format, for example "|cFFFFCC00"
  35. //===========================================================================
  36. public function XY takes real x, real y, string text, string color returns nothing
  37.     local texttag tt = CreateTextTag()
  38.     local real shift = RMinBJ(StringLength(text)*MEAN_CHAR_WIDTH, MAX_TEXT_SHIFT)
  39.     call SetTextTagText(tt, color+text, FONT_SIZE)
  40.     call SetTextTagPos(tt, x-shift, y, DEFAULT_HEIGHT)
  41.     call SetTextTagVelocity(tt, 0.0, 0.04)
  42.     call SetTextTagVisibility(tt, true)
  43.     call SetTextTagFadepoint(tt, 2.5)
  44.     call SetTextTagLifespan(tt, 4.0)
  45.     call SetTextTagPermanent(tt, false)
  46.     set tt = null
  47. endfunction
  48.  
  49. //===========================================================================
  50. //   Custom centered texttag above unit
  51. //===========================================================================
  52. public function Unit takes unit whichUnit, string text, string color returns nothing
  53.     local texttag tt = CreateTextTag()
  54.     local real shift = RMinBJ(StringLength(text)*MEAN_CHAR_WIDTH, MAX_TEXT_SHIFT)
  55.     call SetTextTagText(tt, color+text, FONT_SIZE)
  56.     call SetTextTagPos(tt, GetUnitX(whichUnit)-shift, GetUnitY(whichUnit), DEFAULT_HEIGHT)
  57.     call SetTextTagVelocity(tt, 0.0, 0.04)
  58.     call SetTextTagVisibility(tt, true)
  59.     call SetTextTagFadepoint(tt, 2.5)
  60.     call SetTextTagLifespan(tt, 4.0)
  61.     call SetTextTagPermanent(tt, false)    
  62.     set tt = null
  63. endfunction
  64.  
  65. //===========================================================================
  66. //  Standard wc3 gold bounty texttag, displayed only to killing player
  67. //===========================================================================
  68. public function GoldBounty takes unit whichUnit, integer bounty, player killer returns nothing
  69.     local texttag tt = CreateTextTag()
  70.     local string text = "+" + I2S(bounty)
  71.     call SetTextTagText(tt, text, FONT_SIZE)
  72.     call SetTextTagPos(tt, GetUnitX(whichUnit)-SIGN_SHIFT, GetUnitY(whichUnit), 0.0)
  73.     call SetTextTagColor(tt, 255, 220, 0, 255)
  74.     call SetTextTagVelocity(tt, 0.0, 0.03)
  75.     call SetTextTagVisibility(tt, GetLocalPlayer()==killer)
  76.     call SetTextTagFadepoint(tt, 2.0)
  77.     call SetTextTagLifespan(tt, 3.0)
  78.     call SetTextTagPermanent(tt, false)
  79.     set text = null
  80.     set tt = null
  81. endfunction
  82.  
  83. //==============================================================================
  84. public function LumberBounty takes unit whichUnit, integer bounty, player killer returns nothing
  85.     local texttag tt = CreateTextTag()
  86.     local string text = "+" + I2S(bounty)
  87.     call SetTextTagText(tt, text, FONT_SIZE)
  88.     call SetTextTagPos(tt, GetUnitX(whichUnit)-SIGN_SHIFT, GetUnitY(whichUnit), 0.0)
  89.     call SetTextTagColor(tt, 0, 200, 80, 255)
  90.     call SetTextTagVelocity(tt, 0.0, 0.03)
  91.     call SetTextTagVisibility(tt, GetLocalPlayer()==killer)
  92.     call SetTextTagFadepoint(tt, 2.0)
  93.     call SetTextTagLifespan(tt, 3.0)
  94.     call SetTextTagPermanent(tt, false)
  95.     set text = null
  96.     set tt = null
  97. endfunction
  98.  
  99. //===========================================================================
  100. public function ManaBurn takes unit whichUnit, integer dmg returns nothing
  101.     local texttag tt = CreateTextTag()
  102.     local string text = "-" + I2S(dmg)
  103.     call SetTextTagText(tt, text, FONT_SIZE)
  104.     call SetTextTagPos(tt, GetUnitX(whichUnit)-SIGN_SHIFT, GetUnitY(whichUnit), 0.0)
  105.     call SetTextTagColor(tt, 82, 82 ,255 ,255)
  106.     call SetTextTagVelocity(tt, 0.0, 0.04)
  107.     call SetTextTagVisibility(tt, true)
  108.     call SetTextTagFadepoint(tt, 2.0)
  109.     call SetTextTagLifespan(tt, 5.0)
  110.     call SetTextTagPermanent(tt, false)    
  111.     set text = null
  112.     set tt = null
  113. endfunction
  114.  
  115. //===========================================================================
  116. public function Miss takes unit whichUnit returns nothing
  117.     local texttag tt = CreateTextTag()
  118.     call SetTextTagText(tt, MISS, FONT_SIZE)
  119.     call SetTextTagPos(tt, GetUnitX(whichUnit), GetUnitY(whichUnit), 0.0)
  120.     call SetTextTagColor(tt, 255, 0, 0, 255)
  121.     call SetTextTagVelocity(tt, 0.0, 0.03)
  122.     call SetTextTagVisibility(tt, true)
  123.     call SetTextTagFadepoint(tt, 1.0)
  124.     call SetTextTagLifespan(tt, 3.0)
  125.     call SetTextTagPermanent(tt, false)
  126.     set tt = null
  127. endfunction
  128.  
  129. //===========================================================================
  130. public function CriticalStrike takes unit whichUnit, integer dmg returns nothing
  131.     local texttag tt = CreateTextTag()
  132.     local string text = I2S(dmg) + "!"
  133.     call SetTextTagText(tt, text, FONT_SIZE)
  134.     call SetTextTagPos(tt, GetUnitX(whichUnit), GetUnitY(whichUnit), 0.0)
  135.     call SetTextTagColor(tt, 255, 0, 0, 255)
  136.     call SetTextTagVelocity(tt, 0.0, 0.04)
  137.     call SetTextTagVisibility(tt, true)
  138.     call SetTextTagFadepoint(tt, 2.0)
  139.     call SetTextTagLifespan(tt, 5.0)
  140.     call SetTextTagPermanent(tt, false)
  141.     set text = null
  142.     set tt = null    
  143. endfunction
  144.  
  145. //===========================================================================
  146. public function ShadowStrike takes unit whichUnit, integer dmg, boolean initialDamage returns nothing
  147.     local texttag tt = CreateTextTag()
  148.     local string text = I2S(dmg)
  149.     if initialDamage then
  150.         set text = text + "!"
  151.     endif
  152.     call SetTextTagText(tt, text, FONT_SIZE)
  153.     call SetTextTagPos(tt, GetUnitX(whichUnit), GetUnitY(whichUnit), 0.0)
  154.     call SetTextTagColor(tt, 160, 255, 0, 255)
  155.     call SetTextTagVelocity(tt, 0.0, 0.04)
  156.     call SetTextTagVisibility(tt, true)
  157.     call SetTextTagFadepoint(tt, 2.0)
  158.     call SetTextTagLifespan(tt, 5.0)
  159.     call SetTextTagPermanent(tt, false)    
  160.     set text = null
  161.     set tt = null
  162. endfunction
  163.  
  164.  
  165. endlibrary
  166.  
In the demo map you will find a set of abilities, items and dummy units that prove that some functions in this library create default wc3 texttags.

A word of advice for system-maker-wannabies:
The secret of making good libraries is in having patience.
There is nothing more useless than random pieces of code,
and nothing more useful than a properly coded and tested set of functions that behave exactly as everyone expects them to behave.

I also recommend reading this:
http://www.canonical.org/~kragen/tao-of-programming.html
« Last Edit: December 18, 2017, 01:53:28 AM by moyack »



 

Vivir aprendiendo.co - A place for learning stuff, in Spanish   Chaos Realm - The world of Game modders and wc3 addicts   Diplo, a gaming community   Power of Corruption, an altered melee featuring Naga and Demon. Play it now!!!   WC3JASS.com - The JASS Vault + vJASS and Zinc   Jetcraft - A Starcraft II mod   WormTastic Clan (wTc)