y_td.inc 67 KB

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