y_td.inc 67 KB

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