y_td.inc 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069
  1. #if defined _INC_y_td
  2. #endinput
  3. #endif
  4. #define _INC_y_td
  5. /**
  6. * <library name="y_td">
  7. * <section>
  8. * Description
  9. * </section>
  10. * Provides a wrapper to the SA:MP text_draw functions offering much
  11. * improved functionality including XML definable styles, safe display,
  12. * timed displays, styles and text separated, styles updateable dynamically
  13. * and more.
  14. * <section>
  15. * Version
  16. * </section>
  17. * 1.0
  18. * </library>
  19. *//** *//*
  20. Legal:
  21. Version: MPL 1.1
  22. The contents of this file are subject to the Mozilla Public License Version
  23. 1.1 the "License"; you may not use this file except in compliance with
  24. the License. You may obtain a copy of the License at
  25. http://www.mozilla.org/MPL/
  26. Software distributed under the License is distributed on an "AS IS" basis,
  27. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  28. for the specific language governing rights and limitations under the
  29. License.
  30. The Original Code is the YSI framework.
  31. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  32. Portions created by the Initial Developer are Copyright C 2011
  33. the Initial Developer. All Rights Reserved.
  34. Contributors:
  35. Y_Less
  36. koolk
  37. JoeBullet/Google63
  38. g_aSlice/Slice
  39. Misiur
  40. samphunter
  41. tianmeta
  42. maddinat0r
  43. spacemud
  44. Crayder
  45. Dayvison
  46. Ahmad45123
  47. Zeex
  48. irinel1996
  49. Yiin-
  50. Chaprnks
  51. Konstantinos
  52. Masterchen09
  53. Southclaws
  54. PatchwerkQWER
  55. m0k1
  56. paulommu
  57. udan111
  58. Thanks:
  59. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  60. ZeeX - Very productive conversations.
  61. koolk - IsPlayerinAreaEx code.
  62. TheAlpha - Danish translation.
  63. breadfish - German translation.
  64. Fireburn - Dutch translation.
  65. yom - French translation.
  66. 50p - Polish translation.
  67. Zamaroht - Spanish translation.
  68. Los - Portuguese translation.
  69. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
  70. me to strive to better.
  71. Pixels^ - Running XScripters where the idea was born.
  72. Matite - Pestering me to release it and using it.
  73. Very special thanks to:
  74. Thiadmer - PAWN, whose limits continue to amaze me!
  75. Kye/Kalcor - SA:MP.
  76. SA:MP Team past, present and future - SA:MP.
  77. Optional plugins:
  78. Gamer_Z - GPS.
  79. Incognito - Streamer.
  80. Me - sscanf2, fixes2, Whirlpool.
  81. */
  82. #include "..\YSI_Internal\y_compilerdata"
  83. #include "..\YSI_Internal\y_version"
  84. #include "..\YSI_Core\y_debug"
  85. #include "..\YSI_Data\y_bit"
  86. #include "..\YSI_Storage\y_xml"
  87. #include "..\YSI_Core\y_utils"
  88. #include "..\YSI_Server\y_colours"
  89. #include "..\YSI_Coding\y_stringhash"
  90. #include "..\YSI_Coding\y_timers"
  91. #include "..\YSI_Data\y_iterate"
  92. #include "..\YSI_Coding\y_hooks"
  93. //#include "y_timer"
  94. #include <a_samp>
  95. #if !defined MAX_TEXT_DRAW_STYLES
  96. #define MAX_TEXT_DRAW_STYLES (Style:32)
  97. #endif
  98. #define MAX_TEXT_DRAW_LINE (128)
  99. #define TEXT_DRAW_NO_NEXT (Text:-1)
  100. #define TEXT_DRAW_NAN (0xFFFFFFFF)
  101. //#define TEXT_DRAW_NO_STYLE_NAME
  102. //#tryinclude <sscanf2>
  103. enum td_align
  104. {
  105. td_align_none,
  106. td_align_left,
  107. td_align_center,
  108. td_align_centre = td_align_center,
  109. td_align_right
  110. }
  111. enum e_TD_BITS (<<= 1)
  112. {
  113. e_TD_BITS_SHADOW = 0x000000FF,
  114. e_TD_BITS_OUTLINE = 0x0000FF00,
  115. e_TD_BITS_ALIGN = 0x000F0000,
  116. e_TD_BITS_FONT = 0x00F00000,
  117. e_TD_BITS_BOX = 0x01000000,
  118. e_TD_BITS_PROP
  119. }
  120. enum E_TD_DATA
  121. {
  122. #if !defined TEXT_DRAW_NO_STYLE_NAME
  123. E_TD_DATA_NAME[MAX_XML_ENTRY_NAME char],
  124. #endif
  125. E_TD_DATA_HASH,
  126. Float:E_TD_DATA_X,
  127. Float:E_TD_DATA_Y,
  128. Float:E_TD_DATA_LX,
  129. Float:E_TD_DATA_LY,
  130. Float:E_TD_DATA_TX,
  131. Float:E_TD_DATA_TY,
  132. E_TD_DATA_COLOUR,
  133. e_TD_BITS:E_TD_DATA_BITS,
  134. E_TD_DATA_BOX,
  135. E_TD_DATA_BG,
  136. E_TD_DATA_TIME,
  137. Text:E_TD_DATA_USE,
  138. E_TD_DATA_UPDATE
  139. }
  140. enum E_TD_DISPLAY
  141. {
  142. E_TD_DISPLAY_TEXT[MAX_TEXT_DRAW_LINE char],
  143. Float:E_TD_DISPLAY_X,
  144. Float:E_TD_DISPLAY_Y,
  145. Text:E_TD_DISPLAY_NEXT,
  146. Style:E_TD_DISPLAY_STYLE,
  147. E_TD_DISPLAY_LIFE,
  148. Text:E_TD_DISPLAY_REAL,
  149. E_TD_DISPLAY_REVISION, // Used to protect against ABA errors.
  150. Text:E_TD_DISPLAY_LINKED // Links two TDs together for languages.
  151. }
  152. forward TD_LoadColour();
  153. forward TD_Textdraw();
  154. forward TD_HideForPlayerPub(playerid, Text:textDraw, revision);
  155. static stock
  156. XML:YSI_g_sXMLRules = NO_XML_FILE,
  157. YSI_g_sTDData[MAX_TEXT_DRAW_STYLES][E_TD_DATA],
  158. YSI_g_sTDDisplay[Text:MAX_TEXT_DRAWS][E_TD_DISPLAY],
  159. //YSI_g_sTDTimers[Text:MAX_TEXT_DRAWS][MAX_PLAYERS],
  160. // This is actually dual purpose.
  161. Text:YSI_g_sUnused,
  162. BitArray:YSI_g_sPlayerDraws[MAX_PLAYERS]<MAX_TEXT_DRAWS>;
  163. //Bit:YSI_g_sPlayerDraws[MAX_PLAYERS][Bit_Bits(MAX_TEXT_DRAWS)];
  164. //static stock TD_SetTimer(playerid, Text:td, time, revision)
  165. //{
  166. // SetTimerEx("TD_HideForPlayer", time, 0, "iii", playerid, _:td, revision);
  167. //}
  168. #define TD_SetTimer(%0,%1,%2,%3) SetTimerEx("TD_HideForPlayerPub", (%2), 0, "iii", (%0), _:(%1), (%3))
  169. /*-------------------------------------------------------------------------*//**
  170. * <param name="id">Text draw style to check validity of,</param>
  171. *//*------------------------------------------------------------------------**/
  172. P:D(bool:TD_IsValidStyle(Style:id));
  173. #define TD_IsValidStyle(%1) \
  174. (Style:0 <= (%1) < MAX_TEXT_DRAW_STYLES && YSI_g_sTDData[(%1)][E_TD_DATA_HASH])
  175. #define _TD_IsValid(%1) \
  176. ((%1) < MAX_TEXT_DRAW_STYLES && YSI_g_sTDData[(%1)][E_TD_DATA_HASH])
  177. #define _TD_TextValid(%0) \
  178. (Text:0 <= (%0) < Text:MAX_TEXT_DRAWS && YSI_g_sTDDisplay[(%0)][E_TD_DISPLAY_TEXT][0])
  179. //#define TDL_START(%0) new __tdl_base=%1;do{
  180. //#define TDL_END(%0) %1=YSI_g_sTDDisplay[(%1)][E_TD_DISPLAY_LINKED];}while(%1!=__tdl_base);
  181. #define TDL_START(%1) for (new Text:__tdl_base = %1; ; ) {
  182. #define TDL_END(%1) {%1 = YSI_g_sTDDisplay[(%1)][E_TD_DISPLAY_LINKED]; if (%1 == __tdl_base) break;}}
  183. /*-------------------------------------------------------------------------*//**
  184. * <remarks>
  185. * Constructor.
  186. * </remarks>
  187. *//*------------------------------------------------------------------------**/
  188. hook OnScriptInit()
  189. {
  190. if (YSI_g_sXMLRules == NO_XML_FILE)
  191. {
  192. YSI_g_sXMLRules = XML_New();
  193. if (YSI_g_sXMLRules != NO_XML_FILE)
  194. {
  195. // y_styles has a copy of these rules.
  196. XML_AddHandler(YSI_g_sXMLRules, "color", "TD_LoadColour");
  197. XML_AddHandler(YSI_g_sXMLRules, "colour", "TD_LoadColour");
  198. XML_AddHandler(YSI_g_sXMLRules, "textdraw", "TD_Textdraw");
  199. //XML_AddHandler(YSI_g_sXMLRules, "box", "TD_Box");
  200. //XML_AddHandler(YSI_g_sXMLRules, "background", "TD_Background");
  201. //XML_AddHandler(YSI_g_sXMLRules, "style", "TD_Style");
  202. }
  203. }
  204. for (new Text:i; Text:i < Text:MAX_TEXT_DRAWS; i++)
  205. {
  206. YSI_g_sTDDisplay[i][E_TD_DISPLAY_REAL] = Text:INVALID_TEXT_DRAW;
  207. YSI_g_sTDDisplay[i][E_TD_DISPLAY_NEXT] = i + Text:1;
  208. }
  209. YSI_g_sTDDisplay[Text:(MAX_TEXT_DRAWS - 1)][E_TD_DISPLAY_NEXT] = TEXT_DRAW_NO_NEXT;
  210. return 1;
  211. }
  212. /*-------------------------------------------------------------------------*//**
  213. * <param name="filename">File to parse as a textdraw data file.</param>
  214. *//*------------------------------------------------------------------------**/
  215. stock TD_Parse(filename[])
  216. {
  217. P:3("TD_Parse called: \"%s\"", filename);
  218. return XML_Parse(YSI_g_sXMLRules, filename);
  219. }
  220. /*-------------------------------------------------------------------------*//**
  221. * <remarks>
  222. * XML callback for loading the &lt;colour&gt; tag.
  223. * </remarks>
  224. *//*------------------------------------------------------------------------**/
  225. public TD_LoadColour()
  226. {
  227. P:2("TD_LoadColour called");
  228. static
  229. name[MAX_XML_ENTRY_NAME],
  230. val[MAX_XML_ENTRY_TEXT];
  231. new
  232. colour,
  233. hash;
  234. while (XML_GetKeyValue(name, val))
  235. {
  236. if (!strcmp(name, "name", true))
  237. {
  238. hash = YHash(val, false, hash_bernstein); //COLOUR_NAME_HASH(val);
  239. }
  240. else if (!strcmp(name, "hex", true))
  241. {
  242. #if defined _inc_sscanf2 || defined unformat
  243. unformat(val, "x", colour);
  244. #else
  245. colour = hexstr(val);
  246. #endif
  247. }
  248. else if (!strcmp(name, "value", true))
  249. {
  250. #if defined _inc_sscanf2 || defined unformat
  251. if (unformat(val, "n", colour))
  252. #else
  253. if (ishex(val)) colour = hexstr(val);
  254. else if (isnumeric(val)) colour = strval(val);
  255. else
  256. #endif
  257. colour = GetColour(val);
  258. }
  259. }
  260. //if (hash) Text_SetColour(hash, colour);
  261. if (hash) SetColourHash(hash, colour);
  262. return colour;
  263. }
  264. /*-------------------------------------------------------------------------*//**
  265. * <param name="x">X position the text will appear at.</param>
  266. * <param name="y">Y position the text will appear at,</param>
  267. * <param name="letterX">Letter X size.</param>
  268. * <param name="letterY">Letter Y size.</param>
  269. * <param name="textX">Box X size.</param>
  270. * <param name="textY">Box Y size.</param>
  271. * <param name="colour">Text colour.</param>
  272. * <param name="boxColour">Colour of the text box.</param>
  273. * <param name="bgColour">Colour of the text background.</param>
  274. * <param name="shadow">Text shadow size.</param>
  275. * <param name="outline">Text outline size.</param>
  276. * <param name="align">Text alignment.</param>
  277. * <param name="font">Text font style.</param>
  278. * <param name="proportional">Wether to make the text proportional.</param>
  279. * <param name="box">Wether to use a box.</param>
  280. * <param name="time">Time for the text to display in ms (0 = infinate).</param>
  281. * <param name="name">Name of the style.</param>
  282. * <remarks>
  283. * Creates a text draw style structure according to given
  284. * parameters, can be used to display any text in the given
  285. * style without repeated redefinitions.
  286. * </remarks>
  287. *//*------------------------------------------------------------------------**/
  288. stock Style:TD_Create(Float:x = 0.0, Float:y = 0.0, Float:letterX = 0.48, Float:letterY = 1.12, Float:textX = 1280.0, Float:textY = 1280.0, colour = 0xE1E1E1FF, boxColour = 0x80808080, bgColour = 0x000000FF, shadow = 2, outline = 0, align = _:td_align_none, font = 1, bool:proportional = false, bool:box = false, time = 0, name[] = "\1")
  289. {
  290. P:3("Text:TD_Create called: %f, %f, %f, %f, %f, %f, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, \"%s\"", x, y, letterX, letterY, textX, textY, colour, boxColour, bgColour, shadow, outline, align, font, _:proportional, _:box, time, name);
  291. new
  292. Style:i;
  293. while (_TD_IsValid(i))
  294. {
  295. ++i;
  296. }
  297. if (i == MAX_TEXT_DRAW_STYLES)
  298. {
  299. return MAX_TEXT_DRAW_STYLES;
  300. }
  301. #if !defined TEXT_DRAW_NO_STYLE_NAME
  302. strpack(YSI_g_sTDData[i][E_TD_DATA_NAME], name, MAX_XML_ENTRY_NAME);
  303. #endif
  304. YSI_g_sTDData[i][E_TD_DATA_HASH] = bernstein(name);
  305. YSI_g_sTDData[i][E_TD_DATA_X] = x;
  306. YSI_g_sTDData[i][E_TD_DATA_Y] = y;
  307. YSI_g_sTDData[i][E_TD_DATA_LX] = letterX;
  308. YSI_g_sTDData[i][E_TD_DATA_LY] = letterY;
  309. YSI_g_sTDData[i][E_TD_DATA_TX] = textX;
  310. YSI_g_sTDData[i][E_TD_DATA_TY] = textY;
  311. YSI_g_sTDData[i][E_TD_DATA_COLOUR] = colour;
  312. YSI_g_sTDData[i][E_TD_DATA_BITS] =
  313. ((box) ? (e_TD_BITS_BOX) : (e_TD_BITS:0)) |
  314. ((proportional) ? (e_TD_BITS_PROP) : (e_TD_BITS:0)) |
  315. (e_TD_BITS:(shadow << 0) & e_TD_BITS_SHADOW) |
  316. (e_TD_BITS:(outline << 8) & e_TD_BITS_OUTLINE) |
  317. (e_TD_BITS:(align << 16) & e_TD_BITS_ALIGN) |
  318. (e_TD_BITS:(font << 20) & e_TD_BITS_FONT);
  319. YSI_g_sTDData[i][E_TD_DATA_BOX] = boxColour;
  320. YSI_g_sTDData[i][E_TD_DATA_BG] = bgColour;
  321. YSI_g_sTDData[i][E_TD_DATA_TIME] = time;
  322. YSI_g_sTDData[i][E_TD_DATA_USE] = TEXT_DRAW_NO_NEXT;
  323. YSI_g_sTDData[i][E_TD_DATA_UPDATE] = -1;
  324. return Style:i;
  325. }
  326. /*-------------------------------------------------------------------------*//**
  327. * <remarks>
  328. * XML callback for loading the &lt;textdraw&gt; tag.
  329. * </remarks>
  330. *//*------------------------------------------------------------------------**/
  331. public TD_Textdraw()
  332. {
  333. // Set all the default values quickly.
  334. P:1("TD_Textdraw called");
  335. new
  336. Style:i = TD_Create();
  337. if (i != MAX_TEXT_DRAW_STYLES)
  338. {
  339. P:5("TD_Textdraw: created %i", _:i);
  340. static
  341. name[MAX_XML_ENTRY_NAME],
  342. val[MAX_XML_ENTRY_TEXT];
  343. new
  344. e_TD_BITS:bits,
  345. // Bernstein hash of 1.
  346. hash = -32;
  347. // !"\1"
  348. //YSI_g_sTDData[i][E_TD_DATA_NAME] = 0x01000000;
  349. while (XML_GetKeyValue(name, val))
  350. {
  351. P:7("TD_Textdraw: loop");
  352. if (!strcmp(name, "x", true))
  353. {
  354. YSI_g_sTDData[i][E_TD_DATA_X] = floatstr(val);
  355. }
  356. else if (!strcmp(name, "y", true))
  357. {
  358. YSI_g_sTDData[i][E_TD_DATA_Y] = floatstr(val);
  359. }
  360. else if (!strcmp(name, "letterx", true))
  361. {
  362. YSI_g_sTDData[i][E_TD_DATA_LX] = floatstr(val);
  363. }
  364. else if (!strcmp(name, "lettery", true))
  365. {
  366. YSI_g_sTDData[i][E_TD_DATA_LY] = floatstr(val);
  367. }
  368. else if (!strcmp(name, "textx", true))
  369. {
  370. YSI_g_sTDData[i][E_TD_DATA_TX] = floatstr(val);
  371. }
  372. else if (!strcmp(name, "texty", true))
  373. {
  374. YSI_g_sTDData[i][E_TD_DATA_TY] = floatstr(val);
  375. }
  376. else if (!strcmp(name, "alignment", true))
  377. {
  378. bits &= ~e_TD_BITS_ALIGN;
  379. if (!strcmp(val, "left", true)) bits |= e_TD_BITS:(_:td_align_left << 16) & e_TD_BITS_ALIGN;
  380. else if (!strcmp(val, "right", true)) bits |= e_TD_BITS:(_:td_align_right << 16) & e_TD_BITS_ALIGN;
  381. else if (!strcmp(val, "center", true) || !strcmp(val, "centre", true)) bits |= e_TD_BITS:(_:td_align_center << 16) & e_TD_BITS_ALIGN;
  382. }
  383. else if (!strcmp(name, "color", true) || !strcmp(name, "colour", true))
  384. {
  385. P:2("TD_Textdraw: colour called");
  386. // This could now be done with the sscanf "n" type for "number".
  387. #if defined _inc_sscanf2 || defined unformat
  388. new
  389. colour;
  390. if (!unformat(val, "n", colour)) YSI_g_sTDData[i][E_TD_DATA_COLOUR] = colour;
  391. #else
  392. if (ishex(val)) YSI_g_sTDData[i][E_TD_DATA_COLOUR] = hexstr(val);
  393. else if (isnumeric(val)) YSI_g_sTDData[i][E_TD_DATA_COLOUR] = strval(val);
  394. #endif
  395. else YSI_g_sTDData[i][E_TD_DATA_COLOUR] = GetColour(val);
  396. }
  397. else if (!strcmp(name, "box", true))
  398. {
  399. new
  400. box = strval(val);
  401. if (box)
  402. {
  403. bits |= e_TD_BITS_BOX;
  404. YSI_g_sTDData[i][E_TD_DATA_BOX] = box;
  405. }
  406. }
  407. else if (!strcmp(name, "shadow", true))
  408. {
  409. bits = (bits & ~e_TD_BITS_SHADOW) | (e_TD_BITS:(strval(val)) & e_TD_BITS_SHADOW);
  410. }
  411. else if (!strcmp(name, "outline", true))
  412. {
  413. bits = (bits & ~e_TD_BITS_OUTLINE) | (e_TD_BITS:(strval(val) << 8) & e_TD_BITS_OUTLINE);
  414. }
  415. else if (!strcmp(name, "background", true))
  416. {
  417. #if defined _inc_sscanf2 || defined unformat
  418. new
  419. colour;
  420. if (!unformat(val, "n", colour)) YSI_g_sTDData[i][E_TD_DATA_BG] = colour;
  421. #else
  422. if (ishex(val)) YSI_g_sTDData[i][E_TD_DATA_BG] = hexstr(val);
  423. else if (isnumeric(val)) YSI_g_sTDData[i][E_TD_DATA_BG] = strval(val);
  424. #endif
  425. else YSI_g_sTDData[i][E_TD_DATA_BG] = GetColour(val);
  426. P:5("TD_Textdraw(): Background color: \"%s\", %d, %d: 0x%04x%04x", val, ishex(val), isnumeric(val), YSI_g_sTDData[i][E_TD_DATA_BG] >>> 16, YSI_g_sTDData[i][E_TD_DATA_BG] & 0xFFFF);
  427. }
  428. else if (!strcmp(name, "font", true))
  429. {
  430. bits = (bits & ~e_TD_BITS_FONT) | (e_TD_BITS:(strval(val) << 20) & e_TD_BITS_FONT);
  431. }
  432. else if (!strcmp(name, "proportional", true))
  433. {
  434. P:7("TD_Textdraw: proportional");
  435. bits |= e_TD_BITS_PROP;
  436. }
  437. else if (!strcmp(name, "time", true))
  438. {
  439. YSI_g_sTDData[i][E_TD_DATA_TIME] = strval(val);
  440. }
  441. else if (!strcmp(name, "name", true))
  442. {
  443. #if !defined TEXT_DRAW_NO_STYLE_NAME
  444. strpack(YSI_g_sTDData[i][E_TD_DATA_NAME], val, MAX_XML_ENTRY_NAME);
  445. #endif
  446. hash = bernstein(val);
  447. }
  448. }
  449. YSI_g_sTDData[i][E_TD_DATA_BITS] = bits;
  450. /*if (!(YSI_g_sTDData[i][E_TD_DATA_NAME] & 0xFF000000))
  451. {
  452. YSI_g_sTDData[i][E_TD_DATA_NAME] = 0x01000000;
  453. }*/
  454. //YSI_g_sTDData[i][E_TD_DATA_HASH] = bernstein(YSI_g_sTDData[i][E_TD_DATA_NAME]);
  455. YSI_g_sTDData[i][E_TD_DATA_HASH] = hash;
  456. P:5("TD data: %.2f %.2f %.2f %.2f %.2f %.2f %x %d %x %d %d", YSI_g_sTDData[i][E_TD_DATA_X], YSI_g_sTDData[i][E_TD_DATA_Y], YSI_g_sTDData[i][E_TD_DATA_LX], YSI_g_sTDData[i][E_TD_DATA_LY], YSI_g_sTDData[i][E_TD_DATA_TX], YSI_g_sTDData[i][E_TD_DATA_TY], YSI_g_sTDData[i][E_TD_DATA_COLOUR], YSI_g_sTDData[i][E_TD_DATA_BOX], YSI_g_sTDData[i][E_TD_DATA_BG], YSI_g_sTDData[i][E_TD_DATA_TIME], YSI_g_sTDData[i][E_TD_DATA_BITS]);//, YSI_g_sTDData[i][E_TD_DATA_NAME]);
  457. }
  458. return _:i;
  459. }
  460. /*-------------------------------------------------------------------------*//**
  461. * <param name="name">A style name to get a style index for.</param>
  462. *//*------------------------------------------------------------------------**/
  463. stock Style:TD_GetNamed(name[])
  464. {
  465. new
  466. hash = bernstein(name);
  467. P:3("Text:TD_GetID called: %i", hash);
  468. new
  469. Style:i;
  470. while (i != MAX_TEXT_DRAW_STYLES && YSI_g_sTDData[i][E_TD_DATA_HASH] != hash)
  471. {
  472. ++i;
  473. }
  474. return i;
  475. }
  476. /*-------------------------------------------------------------------------*//**
  477. * <param name="hash">Hash of a style name to get a style index for.</param>
  478. *//*------------------------------------------------------------------------**/
  479. stock Style:TD_GetID(hash)
  480. {
  481. P:3("Text:TD_GetID called: %i", hash);
  482. new
  483. Style:i;
  484. while (i != MAX_TEXT_DRAW_STYLES && YSI_g_sTDData[i][E_TD_DATA_HASH] != hash)
  485. {
  486. ++i;
  487. }
  488. return i;
  489. }
  490. /*-------------------------------------------------------------------------*//**
  491. * <param name="styleID">Style to clone.</param>
  492. * <param name="name">Name of the new style.</param>
  493. * <remarks>
  494. * Copies a text draw style and returns the new handle.
  495. * </remarks>
  496. *//*------------------------------------------------------------------------**/
  497. //#if 0
  498. stock Style:TD_Clone(Style:styleID, name[] = "\1")
  499. {
  500. P:3("Text:TD_Clone called: %i, \"%s\"", _:styleID, name);
  501. if (!TD_IsValidStyle(styleID))
  502. {
  503. return MAX_TEXT_DRAW_STYLES;
  504. }
  505. new
  506. Style:i;
  507. while (_TD_IsValid(i))
  508. {
  509. i++;
  510. }
  511. if (i == MAX_TEXT_DRAW_STYLES)
  512. {
  513. return MAX_TEXT_DRAW_STYLES;
  514. }
  515. YSI_g_sTDData[i] = YSI_g_sTDData[styleID];
  516. #if !defined TEXT_DRAW_NO_STYLE_NAME
  517. strpack(YSI_g_sTDData[i][E_TD_DATA_NAME], name, MAX_XML_ENTRY_NAME);
  518. #endif
  519. YSI_g_sTDData[i][E_TD_DATA_HASH] = bernstein(name);
  520. // memcpy?
  521. /*YSI_g_sTDData[i][E_TD_DATA_X] = YSI_g_sTDData[styleID][E_TD_DATA_X];
  522. YSI_g_sTDData[i][E_TD_DATA_Y] = YSI_g_sTDData[styleID][E_TD_DATA_Y];
  523. YSI_g_sTDData[i][E_TD_DATA_LX] = YSI_g_sTDData[styleID][E_TD_DATA_LX];
  524. YSI_g_sTDData[i][E_TD_DATA_LY] = YSI_g_sTDData[styleID][E_TD_DATA_LY];
  525. YSI_g_sTDData[i][E_TD_DATA_TX] = YSI_g_sTDData[styleID][E_TD_DATA_TX];
  526. YSI_g_sTDData[i][E_TD_DATA_TY] = YSI_g_sTDData[styleID][E_TD_DATA_TY];
  527. YSI_g_sTDData[i][E_TD_DATA_COLOUR] = YSI_g_sTDData[styleID][E_TD_DATA_COLOUR];
  528. YSI_g_sTDData[i][E_TD_DATA_BITS] = YSI_g_sTDData[styleID][E_TD_DATA_BITS];
  529. YSI_g_sTDData[i][E_TD_DATA_BOX] = YSI_g_sTDData[styleID][E_TD_DATA_BOX];
  530. YSI_g_sTDData[i][E_TD_DATA_BG] = YSI_g_sTDData[styleID][E_TD_DATA_BG];
  531. YSI_g_sTDData[i][E_TD_DATA_TIME] = YSI_g_sTDData[styleID][E_TD_DATA_TIME];*/
  532. YSI_g_sTDData[i][E_TD_DATA_USE] = TEXT_DRAW_NO_NEXT;
  533. YSI_g_sTDData[i][E_TD_DATA_UPDATE] = -1;
  534. return Style:i;
  535. }
  536. /*-------------------------------------------------------------------------*//**
  537. * <param name="styleID">Style to get the data of.</param>
  538. * <param name="data">Return array.</param>
  539. *//*------------------------------------------------------------------------**/
  540. stock TD_GetStyleData(Style:styleID, data[E_TD_DATA])
  541. {
  542. if (TD_IsValidStyle(styleID))
  543. {
  544. data = YSI_g_sTDData[styleID];
  545. return 1;
  546. }
  547. return 0;
  548. }
  549. /*-------------------------------------------------------------------------*//**
  550. * <param name="styleID">Style to modify.</param>
  551. * <param name="name">Name to give the style.</param>
  552. *//*------------------------------------------------------------------------**/
  553. stock TD_Name(Style:styleID, name[])
  554. {
  555. P:3("TD_Name called: %i, \"%s\"", _:styleID, name);
  556. if (!TD_IsValidStyle(styleID))
  557. {
  558. return 0;
  559. }
  560. #if !defined TEXT_DRAW_NO_STYLE_NAME
  561. strpack(YSI_g_sTDData[styleID][E_TD_DATA_NAME], name, MAX_XML_ENTRY_NAME);
  562. #endif
  563. YSI_g_sTDData[styleID][E_TD_DATA_HASH] = bernstein(name);
  564. return 1;
  565. }
  566. /*-------------------------------------------------------------------------*//**
  567. * <param name="textID">Text to modify.</param>
  568. * <param name="x">New horizontal position.</param>
  569. * <param name="y">New vertical position.</param>
  570. * <remarks>
  571. * Moves a single bit of text, not all with a style.
  572. * </remarks>
  573. *//*------------------------------------------------------------------------**/
  574. stock TD_TextPosition(Text:textID, Float:x, Float:y)
  575. {
  576. P:3("TD_TextPosition called: %i, %i, %i", _:textID, x, y);
  577. if (!_TD_TextValid(textID))
  578. {
  579. return 0;
  580. }
  581. TDL_START(textID)
  582. {
  583. YSI_g_sTDDisplay[textID][E_TD_DISPLAY_X] = x;
  584. YSI_g_sTDDisplay[textID][E_TD_DISPLAY_Y] = y;
  585. TD_UpdateOne(textID, YSI_g_sTDDisplay[textID][E_TD_DISPLAY_STYLE]);
  586. }
  587. TDL_END(textID)
  588. return 1;
  589. }
  590. /*-------------------------------------------------------------------------*//**
  591. * <param name="textID">Text to modify.</param>
  592. * <param name="x">New horizontal position.</param>
  593. * <remarks>
  594. * Moves a single bit of text, not all with a style.
  595. * </remarks>
  596. *//*------------------------------------------------------------------------**/
  597. stock TD_TextXPos(Text:textID, Float:x)
  598. {
  599. P:3("TD_TextXPos called: %i, %i", _:textID, x);
  600. if (!_TD_TextValid(textID))
  601. {
  602. return 0;
  603. }
  604. TDL_START(textID)
  605. {
  606. YSI_g_sTDDisplay[textID][E_TD_DISPLAY_X] = x;
  607. TD_UpdateOne(textID, YSI_g_sTDDisplay[textID][E_TD_DISPLAY_STYLE]);
  608. }
  609. TDL_END(textID)
  610. return 1;
  611. }
  612. /*-------------------------------------------------------------------------*//**
  613. * <param name="textID">Text to modify.</param>
  614. * <param name="y">New vertical position.</param>
  615. * <remarks>
  616. * Moves a single bit of text, not all with a style.
  617. * </remarks>
  618. *//*------------------------------------------------------------------------**/
  619. stock TD_TextYPos(Text:textID, Float:y)
  620. {
  621. P:3("TD_TextYPos called: %i, %i", _:textID, y);
  622. if (!_TD_TextValid(textID))
  623. {
  624. return 0;
  625. }
  626. TDL_START(textID)
  627. {
  628. YSI_g_sTDDisplay[textID][E_TD_DISPLAY_Y] = y;
  629. TD_UpdateOne(textID, YSI_g_sTDDisplay[textID][E_TD_DISPLAY_STYLE]);
  630. }
  631. TDL_END(textID)
  632. return 1;
  633. }
  634. /*-------------------------------------------------------------------------*//**
  635. * <param name="styleID">Style to modify.</param>
  636. * <param name="x">New horizontal position.</param>
  637. * <param name="y">New vertical position.</param>
  638. * <param name="update">Wether to update the appearence for players.</param>
  639. * <remarks>
  640. * Update is default false to not modify moved texts.
  641. * </remarks>
  642. *//*------------------------------------------------------------------------**/
  643. stock TD_StylePosition(Style:styleID, Float:x, Float:y)
  644. {
  645. P:3("TD_StylePosition called: %i, %i, %i", _:styleID, x, y);
  646. if (!TD_IsValidStyle(styleID))
  647. {
  648. return 0;
  649. }
  650. YSI_g_sTDData[styleID][E_TD_DATA_X] = x;
  651. YSI_g_sTDData[styleID][E_TD_DATA_Y] = y;
  652. if (update) TD_Update(styleID, true);
  653. return 1;
  654. }
  655. /*-------------------------------------------------------------------------*//**
  656. * <param name="styleID">Style to modify.</param>
  657. * <param name="x">New horizontal position.</param>
  658. * <param name="update">Wether to update the appearence for players.</param>
  659. * <remarks>
  660. * Update is default false to not modify moved texts.
  661. * </remarks>
  662. *//*------------------------------------------------------------------------**/
  663. stock TD_StyleXPos(Style:styleID, Float:x)
  664. {
  665. P:3("TD_StyleXPos called: %i, %i", _:styleID, x);
  666. if (!TD_IsValidStyle(styleID))
  667. {
  668. return 0;
  669. }
  670. YSI_g_sTDData[styleID][E_TD_DATA_X] = x;
  671. if (update) TD_Update(styleID, true);
  672. return 1;
  673. }
  674. /*-------------------------------------------------------------------------*//**
  675. * <param name="styleID">Style to modify.</param>
  676. * <param name="y">New vertical position.</param>
  677. * <param name="update">Wether to update the appearence for players.</param>
  678. * <remarks>
  679. * Update is default false to not modify moved texts.
  680. * </remarks>
  681. *//*------------------------------------------------------------------------**/
  682. stock TD_StyleYPos(Style:styleID, Float:y)
  683. {
  684. P:3("TD_StyleYPos called: %i, %i", _:styleID, y);
  685. if (!TD_IsValidStyle(styleID))
  686. {
  687. return 0;
  688. }
  689. YSI_g_sTDData[styleID][E_TD_DATA_Y] = y;
  690. if (update) TD_Update(styleID, true);
  691. return 1;
  692. }
  693. /*-------------------------------------------------------------------------*//**
  694. * <param name="styleID">Style to modify.</param>
  695. * <param name="x">New letter width.</param>
  696. * <param name="y">New letter height.</param>
  697. * <param name="update">Wether to update the appearence for players.</param>
  698. *//*------------------------------------------------------------------------**/
  699. stock TD_LetterSize(Style:styleID, Float:x, Float:y)
  700. {
  701. P:3("TD_LetterSize called: %i, %i, %i", _:styleID, x, y);
  702. if (!TD_IsValidStyle(styleID))
  703. {
  704. return 0;
  705. }
  706. YSI_g_sTDData[styleID][E_TD_DATA_LX] = x;
  707. YSI_g_sTDData[styleID][E_TD_DATA_LY] = y;
  708. TD_Update(styleID);
  709. return 1;
  710. }
  711. /*-------------------------------------------------------------------------*//**
  712. * <param name="styleID">Style to modify.</param>
  713. * <param name="x">New letter width.</param>
  714. * <param name="update">Wether to update the appearence for players.</param>
  715. *//*------------------------------------------------------------------------**/
  716. stock TD_LetterX(Style:styleID, Float:x)
  717. {
  718. P:3("TD_LetterX called: %i, %i", _:styleID, x);
  719. if (!TD_IsValidStyle(styleID))
  720. {
  721. return 0;
  722. }
  723. YSI_g_sTDData[styleID][E_TD_DATA_LX] = x;
  724. TD_Update(styleID);
  725. return 1;
  726. }
  727. /*-------------------------------------------------------------------------*//**
  728. * <param name="styleID">Style to modify.</param>
  729. * <param name="y">New letter height.</param>
  730. * <param name="update">Wether to update the appearence for players.</param>
  731. *//*------------------------------------------------------------------------**/
  732. stock TD_LetterY(Style:styleID, Float:y)
  733. {
  734. P:3("TD_LetterY called: %i, %i", _:styleID, y);
  735. if (!TD_IsValidStyle(styleID))
  736. {
  737. return 0;
  738. }
  739. YSI_g_sTDData[styleID][E_TD_DATA_LY] = y;
  740. TD_Update(styleID);
  741. return 1;
  742. }
  743. /*-------------------------------------------------------------------------*//**
  744. * <param name="styleID">Style to modify.</param>
  745. * <param name="x">New text width.</param>
  746. * <param name="y">New text height.</param>
  747. * <param name="update">Wether to update the appearence for players.</param>
  748. *//*------------------------------------------------------------------------**/
  749. stock TD_TextSize(Style:styleID, Float:x, Float:y)
  750. {
  751. P:3("TD_TextSize called: %i, %i, %i", _:styleID, x, y);
  752. if (!TD_IsValidStyle(styleID))
  753. {
  754. return 0;
  755. }
  756. YSI_g_sTDData[styleID][E_TD_DATA_TX] = x;
  757. YSI_g_sTDData[styleID][E_TD_DATA_TY] = y;
  758. TD_Update(styleID);
  759. return 1;
  760. }
  761. /*-------------------------------------------------------------------------*//**
  762. * <param name="styleID">Style to modify.</param>
  763. * <param name="x">New text width.</param>
  764. * <param name="update">Wether to update the appearence for players.</param>
  765. *//*------------------------------------------------------------------------**/
  766. stock TD_TextX(Style:styleID, Float:x)
  767. {
  768. P:3("TD_TextX called: %i, %i", _:styleID, x);
  769. if (!TD_IsValidStyle(styleID))
  770. {
  771. return 0;
  772. }
  773. YSI_g_sTDData[styleID][E_TD_DATA_TX] = x;
  774. TD_Update(styleID);
  775. return 1;
  776. }
  777. /*-------------------------------------------------------------------------*//**
  778. * <param name="styleID">Style to modify.</param>
  779. * <param name="y">New text height.</param>
  780. * <param name="update">Wether to update the appearence for players.</param>
  781. *//*------------------------------------------------------------------------**/
  782. stock TD_TextY(Style:styleID, Float:y)
  783. {
  784. P:3("TD_TextY called: %i, %i", _:styleID, y);
  785. if (!TD_IsValidStyle(styleID))
  786. {
  787. return 0;
  788. }
  789. YSI_g_sTDData[styleID][E_TD_DATA_TY] = y;
  790. TD_Update(styleID);
  791. return 1;
  792. }
  793. /*-------------------------------------------------------------------------*//**
  794. * <param name="styleID">Style to modify.</param>
  795. * <param name="alignment">Where to align the text in it's box.</param>
  796. * <param name="update">Wether to update the appearence for players.</param>
  797. * <remarks>
  798. * Designed to take ta_align enum values and numbers.
  799. * </remarks>
  800. *//*------------------------------------------------------------------------**/
  801. stock TD_Alignment(Style:styleID, alignment = _:td_align_none)
  802. {
  803. P:3("TD_Alignment called: %i, %i", _:styleID, alignment);
  804. if (!TD_IsValidStyle(styleID))
  805. {
  806. return 0;
  807. }
  808. YSI_g_sTDData[styleID][E_TD_DATA_BITS] = (YSI_g_sTDData[styleID][E_TD_DATA_BITS] & ~e_TD_BITS_ALIGN) | (e_TD_BITS:(alignment << 16) & e_TD_BITS_ALIGN);
  809. TD_Update(styleID);
  810. return 1;
  811. }
  812. /*-------------------------------------------------------------------------*//**
  813. * <param name="styleID">Style to modify.</param>
  814. * <param name="colour">New text colour.</param>
  815. * <param name="update">Wether to update the appearence for players.</param>
  816. *//*------------------------------------------------------------------------**/
  817. stock TD_Colour(Style:styleID, colour)
  818. {
  819. P:3("TD_Colour called: %i, %i", _:styleID, colour);
  820. if (!TD_IsValidStyle(styleID))
  821. {
  822. return 0;
  823. }
  824. YSI_g_sTDData[styleID][E_TD_DATA_COLOUR] = colour;
  825. TD_Update(styleID);
  826. return 1;
  827. }
  828. #define TD_Color TD_Colour
  829. /*-------------------------------------------------------------------------*//**
  830. * <param name="styleID">Style to modify.</param>
  831. * <param name="use">Wether or not to show a box round the text.</param>
  832. * <param name="update">Wether to update the appearence for players.</param>
  833. *//*------------------------------------------------------------------------**/
  834. stock TD_UseBox(Style:styleID, bool:use)
  835. {
  836. P:3("TD_UseBox called: %i, %i", _:styleID, _:use);
  837. if (!TD_IsValidStyle(styleID))
  838. {
  839. return 0;
  840. }
  841. if (use) YSI_g_sTDData[styleID][E_TD_DATA_BITS] |= e_TD_BITS_BOX;
  842. else YSI_g_sTDData[styleID][E_TD_DATA_BITS] &= ~e_TD_BITS_BOX;
  843. TD_Update(styleID);
  844. return 1;
  845. }
  846. /*-------------------------------------------------------------------------*//**
  847. * <param name="styleID">Style to modify.</param>
  848. * <param name="colour">New box colour.</param>
  849. * <param name="update">Wether to update the appearence for players.</param>
  850. *//*------------------------------------------------------------------------**/
  851. stock TD_BoxColour(Style:styleID, colour)
  852. {
  853. P:3("TD_BoxColour called: %i, %i", _:styleID, colour);
  854. if (!TD_IsValidStyle(styleID))
  855. {
  856. return 0;
  857. }
  858. YSI_g_sTDData[styleID][E_TD_DATA_BOX] = colour;
  859. TD_Update(styleID);
  860. return 1;
  861. }
  862. #define TD_BoxColor TD_BoxColour
  863. /*-------------------------------------------------------------------------*//**
  864. * <param name="styleID">Style to modify.</param>
  865. * <param name="size">Size of the letter shadow,</param>
  866. * <param name="update">Wether to update the appearence for players.</param>
  867. *//*------------------------------------------------------------------------**/
  868. stock TD_SetShadow(Style:styleID, size)
  869. {
  870. P:3("TD_SetShadow called: %i, %i", _:styleID, size);
  871. if (!TD_IsValidStyle(styleID))
  872. {
  873. return 0;
  874. }
  875. YSI_g_sTDData[styleID][E_TD_DATA_BITS] = (YSI_g_sTDData[styleID][E_TD_DATA_BITS] & ~e_TD_BITS_SHADOW) | (e_TD_BITS:(size) & e_TD_BITS_SHADOW);
  876. TD_Update(styleID);
  877. return 1;
  878. }
  879. /*-------------------------------------------------------------------------*//**
  880. * <param name="styleID">Style to modify.</param>
  881. * <param name="size">Size of the letter outline.</param>
  882. * <param name="update">Wether to update the appearence for players.</param>
  883. *//*------------------------------------------------------------------------**/
  884. stock TD_SetOutline(Style:styleID, size)
  885. {
  886. P:3("TD_SetOutline called: %i, %i", _:styleID, size);
  887. if (!TD_IsValidStyle(styleID))
  888. {
  889. return 0;
  890. }
  891. YSI_g_sTDData[styleID][E_TD_DATA_BITS] = (YSI_g_sTDData[styleID][E_TD_DATA_BITS] & ~e_TD_BITS_OUTLINE) | (e_TD_BITS:(size << 8) & e_TD_BITS_OUTLINE);
  892. TD_Update(styleID);
  893. return 1;
  894. }
  895. /*-------------------------------------------------------------------------*//**
  896. * <param name="styleID">Style to modify.</param>
  897. * <param name="colour">New background (outline/shadow) colour.</param>
  898. * <param name="update">Wether to update the appearence for players.</param>
  899. *//*------------------------------------------------------------------------**/
  900. stock TD_BackgroundColour(Style:styleID, colour)
  901. {
  902. P:3("TD_BackgroundColour called: %i, %i", _:styleID, colour);
  903. if (!TD_IsValidStyle(styleID))
  904. {
  905. return 0;
  906. }
  907. YSI_g_sTDData[styleID][E_TD_DATA_BG] = colour;
  908. TD_Update(styleID);
  909. return 1;
  910. }
  911. #define TD_BackgroundColor TD_BackgroundColour
  912. /*-------------------------------------------------------------------------*//**
  913. * <param name="styleID">Style to modify.</param>
  914. * <param name="font">New text font style.</param>
  915. * <param name="update">Wether to update the appearence for players.</param>
  916. *//*------------------------------------------------------------------------**/
  917. stock TD_Font(Style:styleID, font)
  918. {
  919. P:3("TD_Font called: %i, %i", _:styleID, font);
  920. if (!TD_IsValidStyle(styleID))
  921. {
  922. return 0;
  923. }
  924. YSI_g_sTDData[styleID][E_TD_DATA_BITS] = (YSI_g_sTDData[styleID][E_TD_DATA_BITS] & ~e_TD_BITS_FONT) | (e_TD_BITS:(font << 20) & e_TD_BITS_FONT);
  925. TD_Update(styleID);
  926. return 1;
  927. }
  928. /*-------------------------------------------------------------------------*//**
  929. * <param name="styleID">Style to modify.</param>
  930. * <param name="set">Wether to make the letters proportional or not.</param>
  931. * <param name="update">Wether to update the appearence for players.</param>
  932. *//*------------------------------------------------------------------------**/
  933. stock TD_SetProportional(Style:styleID, bool:set)
  934. {
  935. P:3("TD_SetProportional called: %i, %i", _:styleID, _:set);
  936. if (!TD_IsValidStyle(styleID))
  937. {
  938. return 0;
  939. }
  940. if (set) YSI_g_sTDData[styleID][E_TD_DATA_BITS] |= e_TD_BITS_PROP;
  941. else YSI_g_sTDData[styleID][E_TD_DATA_BITS] &= ~e_TD_BITS_PROP;
  942. TD_Update(styleID);
  943. return 1;
  944. }
  945. /*-------------------------------------------------------------------------*//**
  946. * <param name="styleID">Style to modify.</param>
  947. * <param name="time">New time for the text to display for.</param>
  948. * <param name="existing">Whether or not to change the display of existing text draws.</param>
  949. * <remarks>
  950. * Doesn't update existing timed texts, just new ones. Now does all of them.
  951. * </remarks>
  952. *//*------------------------------------------------------------------------**/
  953. stock TD_SetTime(Style:styleID, time, bool:existing = false)
  954. {
  955. P:3("TD_SetTime called: %i, %i, %i", _:styleID, time, _:existing);
  956. if (!TD_IsValidStyle(styleID))
  957. {
  958. return 0;
  959. }
  960. YSI_g_sTDData[styleID][E_TD_DATA_TIME] = time;
  961. if (existing)
  962. {
  963. // Hide this after the given time for all players.
  964. new
  965. Text:next = YSI_g_sTDData[styleId][E_TD_DATA_USE],
  966. Text:last = TEXT_DRAW_NO_NEXT;
  967. while (next != TEXT_DRAW_NO_NEXT)
  968. {
  969. // DO update the revision here!
  970. new
  971. index = Bit_Slot(next),
  972. Bit:mod = Bit_Mask(next),
  973. revision = ++YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_REVISION];
  974. foreach (new playerid : Player)
  975. {
  976. if (YSI_g_sPlayerDraws[playerid][index] & mod)
  977. {
  978. TD_SetTimer(playerid, next, time, revision);
  979. }
  980. }
  981. last = next;
  982. next = YSI_g_sTDDisplay[next][E_TD_DISPLAY_NEXT];
  983. }
  984. }
  985. return 1;
  986. }
  987. /*-------------------------------------------------------------------------*//**
  988. * <summary>Text:TD_RenderInternal</summary>
  989. * <param name="text">String to output.</param>
  990. * <param name="id">Text draw style to render the text in.</param>
  991. * <param name="slot">the slot the text is stored in.</param>
  992. * <returns>
  993. * TextDraw id.
  994. * </returns>
  995. * <remarks>
  996. * Basically the application layer, creates a text_draw with the
  997. * saved data.
  998. * </remarks>
  999. *//*------------------------------------------------------------------------**/
  1000. static stock Text:TD_RenderInternal(text[], style[E_TD_DATA], Float:x, Float:y)
  1001. {
  1002. //P:4("Text:TD_Render called: \"%s\", %i, %i", text, _:id, _:slot);
  1003. new
  1004. Text:textDraw = TextDrawCreate(x, y, text);
  1005. if (textDraw != Text:INVALID_TEXT_DRAW)
  1006. {
  1007. new
  1008. e_TD_BITS:bits = style[E_TD_DATA_BITS];
  1009. TextDrawLetterSize(textDraw, style[E_TD_DATA_LX], style[E_TD_DATA_LY]);
  1010. TextDrawTextSize(textDraw, style[E_TD_DATA_TX], style[E_TD_DATA_TY]);
  1011. TextDrawAlignment(textDraw, _:(bits & e_TD_BITS_ALIGN) >> 16);
  1012. TextDrawColor(textDraw, style[E_TD_DATA_COLOUR]);
  1013. TextDrawUseBox(textDraw, (bits & e_TD_BITS_BOX) ? 1 : 0);
  1014. TextDrawBoxColor(textDraw, style[E_TD_DATA_BOX]);
  1015. TextDrawSetShadow(textDraw, _:(bits & e_TD_BITS_SHADOW));
  1016. TextDrawSetOutline(textDraw, _:(bits & e_TD_BITS_OUTLINE) >> 8);
  1017. TextDrawBackgroundColor(textDraw, style[E_TD_DATA_BG]);
  1018. TextDrawFont(textDraw, _:(bits & e_TD_BITS_FONT) >> 20);
  1019. TextDrawSetProportional(textDraw, (bits & e_TD_BITS_PROP) ? 1 : 0);
  1020. }
  1021. return textDraw;
  1022. }
  1023. /*-------------------------------------------------------------------------*//**
  1024. * <summary>Text:TD_Render</summary>
  1025. * <param name="text">String to output.</param>
  1026. * <param name="id">Text draw style to render the text in.</param>
  1027. * <param name="slot">the slot the text is stored in.</param>
  1028. * <returns>
  1029. * TextDraw id.
  1030. * </returns>
  1031. * <remarks>
  1032. * Basically the application layer, creates a text_draw with the
  1033. * saved data.
  1034. * </remarks>
  1035. *//*------------------------------------------------------------------------**/
  1036. static stock Text:TD_Render(text[], Style:id, Text:slot)
  1037. {
  1038. P:4("Text:TD_Render called: \"%s\", %i, %i", text, _:id, _:slot);
  1039. return TD_RenderInternal(text, YSI_g_sTDData[id], YSI_g_sTDDisplay[slot][E_TD_DISPLAY_X], YSI_g_sTDDisplay[slot][E_TD_DISPLAY_Y]);
  1040. }
  1041. /*-------------------------------------------------------------------------*//**
  1042. * <param name="id">Style to update for players.</param>
  1043. * <param name="pos">Wether or not to update children's positions.</param>
  1044. * <remarks>
  1045. * Loops through all texts displayed using the current render style and updates
  1046. * their real display.
  1047. * </remarks>
  1048. *//*------------------------------------------------------------------------**/
  1049. stock TD_Update(Style:id, bool:pos = false)
  1050. {
  1051. P:3("TD_Update called: %i, %i", _:id, _:pos);
  1052. if (!TD_IsValidStyle(id))
  1053. {
  1054. return;
  1055. }
  1056. if (pos)
  1057. {
  1058. // Put this all in one "if" block.
  1059. new
  1060. Text:next = YSI_g_sTDData[id][E_TD_DATA_USE],
  1061. Float:x = YSI_g_sTDData[id][E_TD_DATA_X],
  1062. Float:y = YSI_g_sTDData[id][E_TD_DATA_Y];
  1063. while (next != TEXT_DRAW_NO_NEXT)
  1064. {
  1065. YSI_g_sTDDisplay[next][E_TD_DISPLAY_X] = x;
  1066. YSI_g_sTDDisplay[next][E_TD_DISPLAY_Y] = y;
  1067. next = YSI_g_sTDDisplay[next][E_TD_DISPLAY_NEXT];
  1068. }
  1069. }
  1070. // Update the apperance after a load of updates have been applied.
  1071. if (YSI_g_sTDData[id][E_TD_DATA_UPDATE] == -1)
  1072. {
  1073. YSI_g_sTDData[id][E_TD_DATA_UPDATE] = SetTimerEx("TD_UpdateInternal", 1, 0, "i", _:id);
  1074. }
  1075. }
  1076. forward TD_UpdateInternal(Style:id);
  1077. public TD_UpdateInternal(Style:id)
  1078. {
  1079. new
  1080. Text:next = YSI_g_sTDData[id][E_TD_DATA_USE];
  1081. while (next != TEXT_DRAW_NO_NEXT)
  1082. {
  1083. TD_UpdateOne(next, id);
  1084. next = YSI_g_sTDDisplay[next][E_TD_DISPLAY_NEXT];
  1085. }
  1086. }
  1087. /*-------------------------------------------------------------------------*//**
  1088. * <param name="slot">Text to update.</param>
  1089. * <param name="id">Style to use.</param>
  1090. * <remarks>
  1091. * Updates a single text's appearance. Modified to use a timer with a delay of
  1092. * 1ms, to be called after the current slew of updates. This means that doing
  1093. * a whole load of modifications at once will all be committed to players at
  1094. * the same time. This used to be done with the optional "update" parameter.
  1095. * </remarks>
  1096. *//*------------------------------------------------------------------------**/
  1097. stock TD_UpdateOne(Text:slot, Style:id)
  1098. {
  1099. P:3("TD_UpdateOne called: %i, %i", _:slot, _:id);
  1100. // DON'T update the revision in here - if you show a TD to a player for 5
  1101. // seconds and change it after 2, they should just get the new version for
  1102. // 3 seconds, it shouldn't reset the timer.
  1103. new
  1104. Text:real = YSI_g_sTDDisplay[slot][E_TD_DISPLAY_REAL];
  1105. TextDrawDestroy(real);
  1106. real = TD_Render(YSI_g_sTDDisplay[slot][E_TD_DISPLAY_TEXT], id, slot);
  1107. YSI_g_sTDDisplay[slot][E_TD_DISPLAY_REAL] = real;
  1108. if (real != Text:INVALID_TEXT_DRAW)
  1109. {
  1110. new
  1111. index = Bit_Slot(slot),
  1112. Bit:mod = Bit_Mask(slot);
  1113. foreach (new playerid : Player)
  1114. {
  1115. if (YSI_g_sPlayerDraws[playerid][index] & mod)
  1116. {
  1117. TextDrawShowForPlayer(playerid, real);
  1118. }
  1119. }
  1120. }
  1121. }
  1122. /*-------------------------------------------------------------------------*//**
  1123. * <param name="styleId">Text draw style ID you want to remove.</param>
  1124. * <remarks>
  1125. * Just nulls the name to remove it's active marker.
  1126. * </remarks>
  1127. *//*------------------------------------------------------------------------**/
  1128. stock TD_Delete(Style:styleId)
  1129. {
  1130. P:3("TD_Delete called: %i", _:styleId);
  1131. if (!TD_IsValidStyle(styleId))
  1132. {
  1133. return 0;
  1134. }
  1135. if (YSI_g_sTDData[styleId][E_TD_DATA_UPDATE] != -1)
  1136. {
  1137. KillTimer(YSI_g_sTDData[styleId][E_TD_DATA_UPDATE]);
  1138. YSI_g_sTDData[styleId][E_TD_DATA_UPDATE] = -1;
  1139. }
  1140. new
  1141. Text:next = YSI_g_sTDData[styleId][E_TD_DATA_USE],
  1142. Text:last = TEXT_DRAW_NO_NEXT;
  1143. // Loop through all the TDs using this style.
  1144. while (next != TEXT_DRAW_NO_NEXT)
  1145. {
  1146. TextDrawDestroy(YSI_g_sTDDisplay[next][E_TD_DISPLAY_REAL]);
  1147. YSI_g_sTDDisplay[next][E_TD_DISPLAY_REAL] = Text:INVALID_TEXT_DRAW;
  1148. YSI_g_sTDDisplay[next][E_TD_DISPLAY_TEXT][0] = '\0';
  1149. ++YSI_g_sTDDisplay[next][E_TD_DISPLAY_REVISION];
  1150. new
  1151. index = Bit_Slot(next),
  1152. Bit:mod = ~Bit_Mask(next);
  1153. foreach (new playerid : Player)
  1154. {
  1155. // TODO: Update.
  1156. /*if (YSI_g_sTDTimers[next][playerid])
  1157. {
  1158. KillTimer(YSI_g_sTDTimers[next][playerid]);
  1159. }
  1160. YSI_g_sTDTimers[next][playerid] = 0;*/
  1161. // Kill the update timer.
  1162. // Mark this player as not having this TD.
  1163. YSI_g_sPlayerDraws[playerid][index] &= mod;
  1164. }
  1165. last = next;
  1166. next = YSI_g_sTDDisplay[next][E_TD_DISPLAY_NEXT];
  1167. }
  1168. // Add the entire style list to the unused list at once.
  1169. if (last != TEXT_DRAW_NO_NEXT)
  1170. {
  1171. // There are items to add.
  1172. YSI_g_sTDDisplay[last][E_TD_DISPLAY_NEXT] = YSI_g_sUnused;
  1173. YSI_g_sUnused = YSI_g_sTDData[styleId][E_TD_DATA_USE];
  1174. }
  1175. // Mark the style as unused.
  1176. YSI_g_sTDData[styleId][E_TD_DATA_USE] = TEXT_DRAW_NO_NEXT;
  1177. #if !defined TEXT_DRAW_NO_STYLE_NAME
  1178. YSI_g_sTDData[styleId][E_TD_DATA_NAME] = 0;
  1179. #endif
  1180. YSI_g_sTDData[styleId][E_TD_DATA_HASH] = 0;
  1181. return 1;
  1182. }
  1183. /*-------------------------------------------------------------------------*//**
  1184. * <param name="textDraw">Text draw to destroy safely.</param>
  1185. * <remarks>
  1186. * Destroys this text draw only if it is marked for garbage collection. It
  1187. * does not however check that no-one can see the text draw, so those people
  1188. * who can currently see it will loose it.
  1189. * </remarks>
  1190. *//*------------------------------------------------------------------------**/
  1191. static stock TD_TryDestroy(Text:textDraw)
  1192. {
  1193. P:4("TD_TryDestroy called: %i", _:textDraw);
  1194. // Destroy this if it is marked to be garbage collected.
  1195. if (YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_LIFE] & 0x80000000)
  1196. {
  1197. TD_Destroy(textDraw);
  1198. return 1;
  1199. }
  1200. return 0;
  1201. }
  1202. /*-------------------------------------------------------------------------*//**
  1203. * <param name="textDraw">Text draw to destroy safely.</param>
  1204. * <remarks>
  1205. * Optimised for multiple people. Not very well though...
  1206. * </remarks>
  1207. *//*------------------------------------------------------------------------**/
  1208. stock TD_Destroy(Text:textDraw)
  1209. {
  1210. P:3("TD_Destroy called: %i", _:textDraw);
  1211. if (Text:0 <= textDraw < Text:MAX_TEXT_DRAWS)
  1212. {
  1213. TDL_START(textDraw)
  1214. {
  1215. // Find the TD before this one in the style list.
  1216. new
  1217. Style:style = YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_STYLE],
  1218. Text:next = YSI_g_sTDData[style][E_TD_DATA_USE],
  1219. Text:last = TEXT_DRAW_NO_NEXT;
  1220. while (next != TEXT_DRAW_NO_NEXT)
  1221. {
  1222. if (next == textDraw)
  1223. {
  1224. break;
  1225. }
  1226. last = next;
  1227. next = YSI_g_sTDDisplay[next][E_TD_DISPLAY_NEXT];
  1228. }
  1229. // Destroy the SA:MP text draw.
  1230. new
  1231. Text:real = YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_REAL];
  1232. YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_REAL] = Text:INVALID_TEXT_DRAW;
  1233. YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_TEXT][0] = '\0';
  1234. ++YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_REVISION];
  1235. if (real != Text:INVALID_TEXT_DRAW)
  1236. {
  1237. // TextDrawDestroy
  1238. TextDrawDestroy(real);
  1239. // Now kill timers for players.
  1240. // TODO: Update.
  1241. new
  1242. index = Bit_Slot(textDraw),
  1243. Bit:mod = ~Bit_Mask(textDraw);
  1244. foreach (new playerid : Player)
  1245. {
  1246. /*if (YSI_g_sTDTimers[textDraw][playerid])
  1247. {
  1248. KillTimer(YSI_g_sTDTimers[textDraw][playerid]);
  1249. }
  1250. YSI_g_sTDTimers[textDraw][playerid] = 0;*/
  1251. YSI_g_sPlayerDraws[playerid][index] &= mod;
  1252. }
  1253. }
  1254. // Remove from the style use list and add to the unused list.
  1255. if (next == textDraw)
  1256. {
  1257. if (last == TEXT_DRAW_NO_NEXT)
  1258. {
  1259. YSI_g_sTDData[style][E_TD_DATA_USE] = YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_NEXT];
  1260. }
  1261. else
  1262. {
  1263. YSI_g_sTDDisplay[last][E_TD_DISPLAY_NEXT] = YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_NEXT];
  1264. }
  1265. YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_NEXT] = YSI_g_sUnused;
  1266. YSI_g_sUnused = textDraw;
  1267. }
  1268. P:C(else P:W("Orphaned text draw found."););
  1269. }
  1270. TDL_END(textDraw)
  1271. }
  1272. return 1;
  1273. }
  1274. /*-------------------------------------------------------------------------*//**
  1275. * <param name="td">Text draw to stop updating.</param>
  1276. * <remarks>
  1277. * Unlinks a text draw from another one, so that updating the other one does
  1278. * not update this one.
  1279. * </remarks>
  1280. *//*------------------------------------------------------------------------**/
  1281. stock TD_Unlink(Text:td)
  1282. {
  1283. new
  1284. Text:orig = YSI_g_sTDDisplay[td][E_TD_DISPLAY_LINKED],
  1285. Text:next = orig,
  1286. Text:other = td;
  1287. for ( ; ; )
  1288. {
  1289. if (next == td)
  1290. {
  1291. // Unlinking from no list works fine.
  1292. YSI_g_sTDDisplay[other][E_TD_DISPLAY_LINKED] = orig;
  1293. YSI_g_sTDDisplay[td][E_TD_DISPLAY_LINKED] = td;
  1294. return;
  1295. }
  1296. other = next;
  1297. next = YSI_g_sTDDisplay[next][E_TD_DISPLAY_LINKED];
  1298. }
  1299. }
  1300. /*-------------------------------------------------------------------------*//**
  1301. * <param name="base">Text draw whose updates will be propogated.</param>
  1302. * <param name="other">Text draw that will receive a parent's updates.</param>
  1303. * <remarks>
  1304. * Links two TDs so that manipulating one does the other too. They are already
  1305. * linked through their style, but that's only for style updates. This handles
  1306. * things like screen position updates etc.
  1307. * </remarks>
  1308. *//*------------------------------------------------------------------------**/
  1309. stock TD_Link(Text:base, Text:other)
  1310. {
  1311. if (YSI_g_sTDDisplay[other][E_TD_DISPLAY_LINKED] != other)
  1312. {
  1313. TD_Unlink(other);
  1314. }
  1315. // This is an unordered linked list.
  1316. YSI_g_sTDDisplay[other][E_TD_DISPLAY_LINKED] = YSI_g_sTDDisplay[base][E_TD_DISPLAY_LINKED];
  1317. YSI_g_sTDDisplay[base][E_TD_DISPLAY_LINKED] = other;
  1318. }
  1319. /*-------------------------------------------------------------------------*//**
  1320. * <summary>Text:TD_Display</summary>
  1321. * <param name="text">Text to display onscreen.</param>
  1322. * <param name="id">Style to use to style text.</param>
  1323. * <returns>
  1324. * Internal Text: id, not actual text draw's id.
  1325. * </returns>
  1326. * <remarks>
  1327. * Generates a text draw for to display to people.
  1328. * </remarks>
  1329. *//*------------------------------------------------------------------------**/
  1330. stock Text:TD_Display(text[], Style:id, Float:x = (Float:TEXT_DRAW_NAN), Float:y = (Float:TEXT_DRAW_NAN))
  1331. {
  1332. if (YSI_g_sUnused == TEXT_DRAW_NO_NEXT)
  1333. {
  1334. return Text:INVALID_TEXT_DRAW;
  1335. }
  1336. if (!TD_IsValidStyle(id))
  1337. {
  1338. return Text:INVALID_TEXT_DRAW;
  1339. }
  1340. // if (x != x)
  1341. // Determine the screen position.
  1342. if (_:x == TEXT_DRAW_NAN)
  1343. {
  1344. YSI_g_sTDDisplay[YSI_g_sUnused][E_TD_DISPLAY_X] = YSI_g_sTDData[id][E_TD_DATA_X];
  1345. }
  1346. else
  1347. {
  1348. YSI_g_sTDDisplay[YSI_g_sUnused][E_TD_DISPLAY_X] = x;
  1349. }
  1350. if (_:y == TEXT_DRAW_NAN)
  1351. {
  1352. YSI_g_sTDDisplay[YSI_g_sUnused][E_TD_DISPLAY_Y] = YSI_g_sTDData[id][E_TD_DATA_Y];
  1353. }
  1354. else
  1355. {
  1356. YSI_g_sTDDisplay[YSI_g_sUnused][E_TD_DISPLAY_Y] = y;
  1357. }
  1358. YSI_g_sTDDisplay[YSI_g_sUnused][E_TD_DISPLAY_STYLE] = id;
  1359. // Render the code to an internal TD. All TD_Render does is call SA:MP
  1360. // functions, it does no variable sets.
  1361. new
  1362. Text:textDraw = TD_Render(text, id, YSI_g_sUnused);
  1363. if (textDraw == Text:INVALID_TEXT_DRAW)
  1364. {
  1365. return Text:INVALID_TEXT_DRAW;
  1366. }
  1367. YSI_g_sTDDisplay[YSI_g_sUnused][E_TD_DISPLAY_REAL] = textDraw;
  1368. YSI_g_sTDDisplay[YSI_g_sUnused][E_TD_DISPLAY_LINKED] = YSI_g_sUnused;
  1369. // I don't know wether or not to use strpack here.
  1370. //strcpy(YSI_g_sTDDisplay[YSI_g_sUnused][E_TD_DISPLAY_TEXT], text, MAX_TEXT_DRAW_LINE);
  1371. strpack(YSI_g_sTDDisplay[YSI_g_sUnused][E_TD_DISPLAY_TEXT], text, MAX_TEXT_DRAW_LINE char);
  1372. textDraw = Text:YSI_g_sUnused;
  1373. YSI_g_sUnused = YSI_g_sTDDisplay[YSI_g_sUnused][E_TD_DISPLAY_NEXT];
  1374. // Add to the list of items using this style.
  1375. YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_NEXT] = YSI_g_sTDData[id][E_TD_DATA_USE];
  1376. YSI_g_sTDData[id][E_TD_DATA_USE] = textDraw;
  1377. // Nobody can see it, but don't destroy it.
  1378. YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_LIFE] = 0;
  1379. // Increment this every time this slot is used and cleared.
  1380. ++YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_REVISION];
  1381. return textDraw;
  1382. }
  1383. stock Text:TD_DisplayForPlayer(playerid, text[], Style:id, Float:x = (Float:TEXT_DRAW_NAN), Float:y = (Float:TEXT_DRAW_NAN))
  1384. {
  1385. new
  1386. Text:td = TD_Display(text, id, x, y);
  1387. TD_Garbage(td);
  1388. TD_ShowForPlayer(playerid, td);
  1389. return td;
  1390. }
  1391. stock Text:TD_DisplayForAll(text[], Style:id, Float:x = (Float:TEXT_DRAW_NAN), Float:y = (Float:TEXT_DRAW_NAN))
  1392. {
  1393. new
  1394. Text:td = TD_Display(text, id, x, y);
  1395. TD_Garbage(td);
  1396. TD_ShowForAll(td);
  1397. return td;
  1398. }
  1399. stock Style:TD_GetDisplayStyle(Text:td)
  1400. {
  1401. return YSI_g_sTDDisplay[td][E_TD_DISPLAY_STYLE];
  1402. }
  1403. /*-------------------------------------------------------------------------*//**
  1404. * <param name="td">The text draw to modify.</param>
  1405. * <param name="text">Text to display onscreen.</param>
  1406. * <remarks>
  1407. * Changes the text on people's screens quickly.
  1408. *
  1409. * This function DOES NOT update linked TDs as the point is that they display
  1410. * the same data in different ways, so will need to be updated in different
  1411. * ways.
  1412. * </remarks>
  1413. *//*------------------------------------------------------------------------**/
  1414. stock TD_SetString(Text:td, text[])
  1415. {
  1416. P:3("TD_SetString called: %i, \"%s\"", _:td, text);
  1417. if (_TD_TextValid(td))
  1418. {
  1419. //strcpy(YSI_g_sTDDisplay[td][E_TD_DISPLAY_TEXT], text, MAX_TEXT_DRAW_LINE);
  1420. strpack(YSI_g_sTDDisplay[td][E_TD_DISPLAY_TEXT], text, MAX_TEXT_DRAW_LINE char);
  1421. new
  1422. Text:real = YSI_g_sTDDisplay[td][E_TD_DISPLAY_REAL];
  1423. // This may have lost it's real rendering
  1424. if (real == Text:INVALID_TEXT_DRAW)
  1425. {
  1426. return 0;
  1427. }
  1428. // Get the style information for showing this TD.
  1429. TextDrawSetString(real, text);
  1430. }
  1431. return 1;
  1432. }
  1433. /*-------------------------------------------------------------------------*//**
  1434. * <summary>Text:TD_DisplayHashed</summary>
  1435. * <param name="text">Text to display.</param>
  1436. * <param name="hash">Hashed style name for styling.</param>
  1437. *//*------------------------------------------------------------------------**/
  1438. stock Text:TD_DisplayHashed(text[], hash, Float:x = (Float:TEXT_DRAW_NAN), Float:y = (Float:TEXT_DRAW_NAN))
  1439. {
  1440. new
  1441. Style:id = TD_GetID(hash);
  1442. if (id != MAX_TEXT_DRAW_STYLES)
  1443. {
  1444. return TD_Display(text, id, x, y);
  1445. }
  1446. return Text:INVALID_TEXT_DRAW;
  1447. }
  1448. stock Text:TD_DisplayHashedForPlayer(playerid, text[], hash, Float:x = (Float:TEXT_DRAW_NAN), Float:y = (Float:TEXT_DRAW_NAN))
  1449. {
  1450. new
  1451. Style:id = TD_GetID(hash);
  1452. if (id != MAX_TEXT_DRAW_STYLES)
  1453. {
  1454. return TD_DisplayForPlayer(playerid, text, id, x, y);
  1455. }
  1456. return Text:INVALID_TEXT_DRAW;
  1457. }
  1458. stock Text:TD_DisplayHashedForAll(text[], hash, Float:x = (Float:TEXT_DRAW_NAN), Float:y = (Float:TEXT_DRAW_NAN))
  1459. {
  1460. new
  1461. Style:id = TD_GetID(hash);
  1462. if (id != MAX_TEXT_DRAW_STYLES)
  1463. {
  1464. return TD_DisplayForAll(text, id, x, y);
  1465. }
  1466. return Text:INVALID_TEXT_DRAW;
  1467. }
  1468. /*-------------------------------------------------------------------------*//**
  1469. * <summary>Text:TD_DisplayNamed</summary>
  1470. * <param name="text">Text to display.</param>
  1471. * <param name="style">Named style to display the text with.</param>
  1472. *//*------------------------------------------------------------------------**/
  1473. stock Text:TD_DisplayNamed(text[], style[], Float:x = (Float:TEXT_DRAW_NAN), Float:y = (Float:TEXT_DRAW_NAN))
  1474. {
  1475. return TD_DisplayHashed(text, bernstein(style), x, y);
  1476. }
  1477. stock Text:TD_DisplayNamedForPlayer(playerid, text[], style[], Float:x = (Float:TEXT_DRAW_NAN), Float:y = (Float:TEXT_DRAW_NAN))
  1478. {
  1479. return TD_DisplayHashedForPlayer(playerid, text, bernstein(style), x, y);
  1480. }
  1481. stock Text:TD_DisplayNamedForAll(text[], style[], Float:x = (Float:TEXT_DRAW_NAN), Float:y = (Float:TEXT_DRAW_NAN))
  1482. {
  1483. return TD_DisplayHashedForAll(text, bernstein(style), x, y);
  1484. }
  1485. /*-------------------------------------------------------------------------*//**
  1486. * <param name="playerid">Player to show the text to.</param>
  1487. * <param name="textDraw">ID of the text to show.</param>
  1488. * <remarks>
  1489. * Now destroys any existing text draws using the same style in
  1490. * the same place to avoid overlaps.
  1491. * </remarks>
  1492. *//*------------------------------------------------------------------------**/
  1493. stock TD_ShowForPlayer(playerid, Text:textDraw)
  1494. {
  1495. P:3("TD_ShowForPlayer called: %i, %i", playerid, _:textDraw);
  1496. if (Text:0 <= textDraw < Text:MAX_TEXT_DRAWS && !Bit_GetBit(YSI_g_sPlayerDraws[playerid], _:textDraw))
  1497. {
  1498. new
  1499. Text:real = YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_REAL],
  1500. Style:style = YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_STYLE];
  1501. // This may have lost it's real rendering
  1502. if (real == Text:INVALID_TEXT_DRAW)
  1503. {
  1504. if (!YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_TEXT][0])
  1505. {
  1506. // There is no text to render.
  1507. return 0;
  1508. }
  1509. real = TD_Render(YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_TEXT], style, textDraw);
  1510. if (real == Text:INVALID_TEXT_DRAW)
  1511. {
  1512. return 0;
  1513. }
  1514. YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_REAL] = real;
  1515. }
  1516. // Now show this for a player.
  1517. TextDrawShowForPlayer(playerid, real);
  1518. Bit_Let(YSI_g_sPlayerDraws[playerid], _:textDraw);
  1519. ++YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_LIFE];
  1520. new
  1521. time = YSI_g_sTDData[style][E_TD_DATA_TIME];
  1522. // TODO: Update.
  1523. /*if (YSI_g_sTDTimers[textDraw][playerid])
  1524. {
  1525. KillTimer(YSI_g_sTDTimers[textDraw][playerid]);
  1526. }*/
  1527. if (time)
  1528. {
  1529. //YSI_g_sTDTimers[textDraw][playerid] = SetTimerEx("TD_HideForPlayer", time, 0, "ii", playerid, _:textDraw);
  1530. TD_SetTimer(playerid, textDraw, time, YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_REVISION]);
  1531. }
  1532. return 1;
  1533. }
  1534. return 0;
  1535. }
  1536. /*-------------------------------------------------------------------------*//**
  1537. * <param name="playerid">Player to hide the text for.</param>
  1538. * <param name="textDraw">Text to hide.</param>
  1539. * <param name="revision">The version of the text draw which existed when this was set.</param>
  1540. * <remarks>
  1541. * Public so the timer can call it to hide texts with a time set.
  1542. * </remarks>
  1543. *//*------------------------------------------------------------------------**/
  1544. public TD_HideForPlayerPub(playerid, Text:textDraw, revision)
  1545. {
  1546. // Hide the TD only if it's not changed since last time (avoids ABA errors).
  1547. // It CAN, however, get ABCD...A errors if you manage to change this one
  1548. // over 4,000,000,000 times before the timer is called...
  1549. if (YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_REVISION] == revision)
  1550. {
  1551. //if (playerid == INVALID_PLAYER_ID)
  1552. //{
  1553. // TD_HideForAll(textDraw);
  1554. //}
  1555. //else
  1556. //{
  1557. TD_HideForPlayer(playerid, textDraw);
  1558. //}
  1559. }
  1560. }
  1561. stock TD_HideForPlayer(playerid, Text:textDraw)
  1562. {
  1563. P:3("TD_HideForPlayer called: %i, %i", playerid, _:textDraw);
  1564. if (IsPlayerConnected(playerid))
  1565. {
  1566. // Find the REAL TD for this player from the base TD.
  1567. TDL_START(textDraw)
  1568. {
  1569. if (Text:0 <= textDraw < Text:MAX_TEXT_DRAWS && Bit_GetBit(YSI_g_sPlayerDraws[playerid], _:textDraw))
  1570. {
  1571. // TODO: Update this to find the correct timer.
  1572. /*if (YSI_g_sTDTimers[textDraw][playerid])
  1573. {
  1574. KillTimer(YSI_g_sTDTimers[textDraw][playerid]);
  1575. }
  1576. YSI_g_sTDTimers[textDraw][playerid] = 0;*/
  1577. //YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_LIFE] = (count & 0x80000000) | ((count & 0x7FFFFFFF) - 1);
  1578. if (--YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_LIFE] == 0x80000000)
  1579. {
  1580. // No-one uses this any more, destroy it. Looking back on
  1581. // the code, this doesn't seem well implemented at all!
  1582. // Actually itis, ignore me. I forgot that you have to
  1583. // MANUALLY mark TDs as garbage for collection here.
  1584. TD_Destroy(textDraw);
  1585. }
  1586. else
  1587. {
  1588. Bit_Vet(YSI_g_sPlayerDraws[playerid], _:textDraw);
  1589. TextDrawHideForPlayer(playerid, YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_REAL]);
  1590. }
  1591. return 1;
  1592. }
  1593. }
  1594. TDL_END(textDraw)
  1595. }
  1596. return 0;
  1597. }
  1598. /*-------------------------------------------------------------------------*//**
  1599. * <param name="textDraw">Text to show to all players.</param>
  1600. *//*------------------------------------------------------------------------**/
  1601. stock TD_ShowForAll(Text:textDraw)
  1602. {
  1603. P:3("TD_ShowForAll called: %i", _:textDraw);
  1604. if (Text:0 <= textDraw < Text:MAX_TEXT_DRAWS)
  1605. {
  1606. new
  1607. Text:real = YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_REAL],
  1608. Style:style = YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_STYLE];
  1609. // This may have lost it's real rendering
  1610. if (real == Text:INVALID_TEXT_DRAW)
  1611. {
  1612. if (!YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_TEXT][0])
  1613. {
  1614. // There is no text to render.
  1615. return 0;
  1616. }
  1617. real = TD_Render(YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_TEXT], style, textDraw);
  1618. if (real == Text:INVALID_TEXT_DRAW)
  1619. {
  1620. return 0;
  1621. }
  1622. YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_REAL] = real;
  1623. }
  1624. TextDrawShowForAll(real);
  1625. new
  1626. count = 0,
  1627. index = Bit_Slot(textDraw),
  1628. Bit:mod = Bit_Mask(textDraw),
  1629. time = YSI_g_sTDData[style][E_TD_DATA_TIME],
  1630. revision = YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_REVISION];
  1631. foreach (new playerid : Player)
  1632. {
  1633. // Count the number of players with this TD (destroy it if none).
  1634. YSI_g_sPlayerDraws[playerid][index] |= mod;
  1635. ++count;
  1636. if (time)
  1637. {
  1638. TD_SetTimer(playerid, textDraw, time, revision);
  1639. }
  1640. }
  1641. if (count)
  1642. {
  1643. // People can see it.
  1644. YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_LIFE] = (YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_LIFE] & 0x80000000) | count;
  1645. }
  1646. else
  1647. {
  1648. TD_TryDestroy(textDraw);
  1649. }
  1650. return 1;
  1651. //}
  1652. }
  1653. return 0;
  1654. }
  1655. /*-------------------------------------------------------------------------*//**
  1656. * <param name="textDraw">Text to hide from all players.</param>
  1657. * <remarks>
  1658. * Destroys the real text draw if marked for garbage collection.
  1659. *
  1660. * Hides all linked TDs.
  1661. * </remarks>
  1662. *//*------------------------------------------------------------------------**/
  1663. stock TD_HideForAll(Text:textDraw)
  1664. {
  1665. P:3("TD_HideForAll called: %i", _:textDraw);
  1666. if (Text:0 <= textDraw < Text:MAX_TEXT_DRAWS)
  1667. {
  1668. TDL_START(textDraw)
  1669. {
  1670. new
  1671. Text:real = YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_REAL];
  1672. if (!TD_TryDestroy(textDraw))
  1673. {
  1674. if (real != Text:INVALID_TEXT_DRAW)
  1675. {
  1676. YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_LIFE] = 0;
  1677. new
  1678. index = Bit_Slot(textDraw),
  1679. Bit:inv = ~Bit_Mask(textDraw);//,
  1680. //Bit:inv = ~mod;
  1681. // Hide it for all players but don't destroy it.
  1682. TextDrawHideForAll(real);
  1683. ++YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_REVISION];
  1684. foreach (new playerid : Player)
  1685. {
  1686. YSI_g_sPlayerDraws[playerid][index] &= inv;
  1687. }
  1688. }
  1689. }
  1690. }
  1691. TDL_END(textDraw)
  1692. }
  1693. return 1;
  1694. }
  1695. /*-------------------------------------------------------------------------*//**
  1696. * <param name="playerid">Player who left.</param>
  1697. * <param name="reason">Why they left.</param>
  1698. * <remarks>
  1699. * Required to fix bugs in the textdraw system by hiding all
  1700. * visible ones.
  1701. * </remarks>
  1702. *//*------------------------------------------------------------------------**/
  1703. hook OnPlayerDisconnect(playerid, reason)
  1704. {
  1705. for (new i = 0; i < bits<MAX_TEXT_DRAWS>; i++)
  1706. {
  1707. new
  1708. Bit:s = YSI_g_sPlayerDraws[playerid][i],
  1709. j = 0,
  1710. ix = i << 5;
  1711. while (s)
  1712. {
  1713. // Get rid of data for textdraws which this player can see. We
  1714. // don't need to actually hide the textdraw as the player has left.
  1715. if (s & Bit:1)
  1716. {
  1717. new
  1718. Text:textDraw = Text:(ix + j);
  1719. /*if (YSI_g_sTDTimers[textDraw][playerid])
  1720. {
  1721. // TODO: Update.
  1722. KillTimer(YSI_g_sTDTimers[textDraw][playerid]);
  1723. YSI_g_sTDTimers[textDraw][playerid] = 0;
  1724. }*/
  1725. if (--YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_LIFE] == 0x80000000)
  1726. {
  1727. TD_Destroy(textDraw);
  1728. }
  1729. //TD_TryDestroy(textDraw);
  1730. }
  1731. s >>>= Bit:1;
  1732. ++j;
  1733. }
  1734. YSI_g_sPlayerDraws[playerid][i] = Bit:0;
  1735. }
  1736. }
  1737. /*-------------------------------------------------------------------------*//**
  1738. * <param name="textDraw">Text to mark as garbage.</param>
  1739. * <remarks>
  1740. * Tells the system to remove a text draw when no-one can see it
  1741. * anymore to free up text draw slots.
  1742. *
  1743. * Note that linked TDs don't share garbage status. This is because I said so,
  1744. * not for any good reason (other that I can't be bothered to code it up).
  1745. * Ergo this behaviour is a feature, not a bug!
  1746. * </remarks>
  1747. *//*------------------------------------------------------------------------**/
  1748. stock TD_Garbage(Text:textDraw)
  1749. {
  1750. P:3("TD_Garbage called: %i", _:textDraw);
  1751. if (Text:0 <= textDraw < Text:MAX_TEXT_DRAWS)
  1752. {
  1753. if (YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_LIFE] & 0x7FFFFFFF)
  1754. {
  1755. // Players can still see it.
  1756. YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_LIFE] |= 0x80000000;
  1757. }
  1758. else
  1759. {
  1760. // No-one can see it.
  1761. TD_Destroy(textDraw);
  1762. }
  1763. }
  1764. }
  1765. /*-------------------------------------------------------------------------*//**
  1766. * <param name="textDraw">Text to morph from it's current style to another style.</param>
  1767. * <param name="style">The style to morph to.</param>
  1768. * <param name="time">The time to take in this morph.</param>
  1769. * <param name="defer">In how long to start this morph (default now).</param>
  1770. * <remarks>
  1771. * Entry point for changing the apperance of a text draw to look like another
  1772. * one. How smooth this is depends on the difference and the time given. The
  1773. * default update time is 50ms (20fps), which isn't too bad. Don't modify
  1774. * revision versions in here as if there is a hide timer, it still applies
  1775. * regardless of what style is currently applied.
  1776. *
  1777. * No longer takes a playerid parameter - it's just tough but easy to work
  1778. * around using y_text.
  1779. * </remarks>
  1780. *//*------------------------------------------------------------------------**/
  1781. #if !defined Y_TD_FRAME_TIME
  1782. #define Y_TD_FRAME_TIME 50
  1783. #endif
  1784. forward TD_MorphTDInternal(Text:td, Style:from, Style:to, speed, pos, revision);
  1785. stock TD_Morph(Text:textDraw, Style:style, time, delay = 0)
  1786. {
  1787. P:2("TD_Morph called: %d %d", TD_IsValidStyle(style), _TD_TextValid(textDraw));
  1788. if (TD_IsValidStyle(style) && _TD_TextValid(textDraw))
  1789. {
  1790. //foreach (new playerid : PS(players))
  1791. //{
  1792. //TD_MorphInternal(playerid, textDraw, style);
  1793. SetTimerEx("TD_MorphTDInternal", delay + Y_TD_FRAME_TIME, 0, "iiiiii", _:textDraw, _:TD_GetDisplayStyle(textDraw), _:style, time, Y_TD_FRAME_TIME, YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_REVISION]); //, YSI_g_sTDDisplay[textDraw][E_TD_DISPLAY_REAL]);
  1794. //SetTimerEx("TD_MorphTDInternal", defer + Y_TD_FRAME_TIME, 0, "iiiiii", _:textDraw, TD_GetDisplayStyle());
  1795. //}
  1796. return 1;
  1797. }
  1798. return 0;
  1799. }
  1800. public TD_MorphTDInternal(Text:td, Style:from, Style:to, speed, pos, revision)
  1801. {
  1802. P:2("TD_MorphTDInternal called: %d %d %d %d %d %d", _:td, _:from, _:to, speed, pos, revision);
  1803. if (!(Text:0 <= td < Text:MAX_TEXT_DRAWS))
  1804. {
  1805. return 0;
  1806. }
  1807. if (YSI_g_sTDDisplay[td][E_TD_DISPLAY_REVISION] != revision)
  1808. {
  1809. return 0;
  1810. }
  1811. static
  1812. sFrom[E_TD_DATA],
  1813. sTo[E_TD_DATA];
  1814. // Get the current style data.
  1815. TD_GetStyleData(to, sTo);
  1816. new
  1817. Text:real,
  1818. index,
  1819. Bit:mask;
  1820. if (pos >= speed)
  1821. {
  1822. // We could add a callback here to indicate that the morph is done.
  1823. // Note that the callback should be BEFORE the TDL loop to include the
  1824. // correct "td" value.
  1825. // Show the TD using the end point only (no interpolation).
  1826. new
  1827. Float:x = sTo[E_TD_DATA_X] - YSI_g_sTDDisplay[td][E_TD_DISPLAY_X],
  1828. Float:y = sTo[E_TD_DATA_Y] - YSI_g_sTDDisplay[td][E_TD_DISPLAY_Y];
  1829. TDL_START(td)
  1830. {
  1831. // Hide this TD for everyone.
  1832. new
  1833. Text:old = YSI_g_sTDDisplay[td][E_TD_DISPLAY_REAL];
  1834. //TextDrawDestroy(real);
  1835. // Render the new version.
  1836. real = TD_RenderInternal(YSI_g_sTDDisplay[td][E_TD_DISPLAY_TEXT], sTo, YSI_g_sTDDisplay[td][E_TD_DISPLAY_X] + x, YSI_g_sTDDisplay[td][E_TD_DISPLAY_Y] + y);
  1837. // Show for all players who had it before.
  1838. index = Bit_Slot(_:td);
  1839. mask = Bit_Mask(_:td);
  1840. foreach (new playerid : Player)
  1841. {
  1842. if (YSI_g_sPlayerDraws[playerid][index] & mask)
  1843. {
  1844. TextDrawShowForPlayer(playerid, real);
  1845. }
  1846. }
  1847. // Only update the new location pointer. Things like garbage
  1848. // status stay the same as the TD is technically still visible
  1849. // (even if they are fading it out).
  1850. TextDrawDestroy(old);
  1851. YSI_g_sTDDisplay[td][E_TD_DISPLAY_REAL] = real;
  1852. }
  1853. TDL_END(td)
  1854. }
  1855. else
  1856. {
  1857. // Get the BASE position (linked TDs move REALTIVE to this one, as
  1858. // location is not a style parameter).
  1859. new
  1860. Float:x = (sTo[E_TD_DATA_X] - YSI_g_sTDDisplay[td][E_TD_DISPLAY_X]) * pos / speed,
  1861. Float:y = (sTo[E_TD_DATA_Y] - YSI_g_sTDDisplay[td][E_TD_DISPLAY_Y]) * pos / speed;
  1862. TD_GetStyleData(from, sFrom);
  1863. // Calculate how far between the morph stages we are.
  1864. #define MORPH_TD_FROM_TO(%0) sFrom[E_TD_DATA_%0] += (sTo[E_TD_DATA_%0] - sFrom[E_TD_DATA_%0]) * pos / speed
  1865. MORPH_TD_FROM_TO(LX);
  1866. MORPH_TD_FROM_TO(LY);
  1867. MORPH_TD_FROM_TO(TX);
  1868. MORPH_TD_FROM_TO(TY);
  1869. MORPH_TD_FROM_TO(COLOUR);
  1870. //MORPH_TD_FROM_TO(BITS);
  1871. sFrom[E_TD_DATA_BITS] += e_TD_BITS:(_:(sTo[E_TD_DATA_BITS] - sFrom[E_TD_DATA_BITS]) * pos / speed);
  1872. MORPH_TD_FROM_TO(BOX);
  1873. MORPH_TD_FROM_TO(BG);
  1874. #undef MORPH_TD_FROM_TO
  1875. // Loop through all linked TDs and show them to all players.
  1876. TDL_START(td)
  1877. {
  1878. //printf("TDL_Start");
  1879. // Hide this TD for everyone.
  1880. new
  1881. Text:old = YSI_g_sTDDisplay[td][E_TD_DISPLAY_REAL];
  1882. //printf("Destroyed");
  1883. // Render the new version.
  1884. real = TD_RenderInternal(YSI_g_sTDDisplay[td][E_TD_DISPLAY_TEXT], sFrom, YSI_g_sTDDisplay[td][E_TD_DISPLAY_X] + x, YSI_g_sTDDisplay[td][E_TD_DISPLAY_Y] + y);
  1885. printf("New real: %d %f %f", _:real, YSI_g_sTDDisplay[td][E_TD_DISPLAY_X] + x, YSI_g_sTDDisplay[td][E_TD_DISPLAY_Y] + y);
  1886. // Show for all players who had it before.
  1887. index = Bit_Slot(_:td);
  1888. mask = Bit_Mask(_:td);
  1889. foreach (new playerid : Player)
  1890. {
  1891. //printf("player %d");
  1892. if (YSI_g_sPlayerDraws[playerid][index] & mask)
  1893. {
  1894. //printf("yes");
  1895. TextDrawShowForPlayer(playerid, real);
  1896. }
  1897. }
  1898. TextDrawDestroy(old);
  1899. // Only update the new location pointer. Things like garbage
  1900. // status stay the same as the TD is technically still visible
  1901. // (even if they are fading it out).
  1902. YSI_g_sTDDisplay[td][E_TD_DISPLAY_REAL] = real;
  1903. }
  1904. TDL_END(td)
  1905. // Even though "td" changes in the loop, the end condition is that "td"
  1906. // is the same as when the loop started, meaning that it's fine to reuse
  1907. // it here.
  1908. SetTimerEx("TD_MorphTDInternal", Y_TD_FRAME_TIME, 0, "iiiiii", _:td, _:from, _:to, speed, pos + Y_TD_FRAME_TIME, revision);
  1909. }
  1910. return 1;
  1911. }
  1912. #undef TDL_START
  1913. #undef TDL_END