y_textrender.inc 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  1. /**--------------------------------------------------------------------------**\
  2. =================================
  3. y_textrender - Show text.
  4. =================================
  5. Description:
  6. Part of the y_text system. Handles formatting loaded text in the correct
  7. manner for display in the currently selected style.
  8. Legal:
  9. Version: MPL 1.1
  10. The contents of this file are subject to the Mozilla Public License Version
  11. 1.1 (the "License"); you may not use this file except in compliance with
  12. the License. You may obtain a copy of the License at
  13. http://www.mozilla.org/MPL/
  14. Software distributed under the License is distributed on an "AS IS" basis,
  15. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  16. for the specific language governing rights and limitations under the
  17. License.
  18. The Original Code is the YSI utils include.
  19. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  20. Portions created by the Initial Developer are Copyright (C) 2011
  21. the Initial Developer. All Rights Reserved.
  22. Contributors:
  23. ZeeX, koolk, JoeBullet/Google63, g_aSlice/Slice
  24. Thanks:
  25. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  26. ZeeX - Very productive conversations.
  27. koolk - IsPlayerinAreaEx code.
  28. TheAlpha - Danish translation.
  29. breadfish - German translation.
  30. Fireburn - Dutch translation.
  31. yom - French translation.
  32. 50p - Polish translation.
  33. Zamaroht - Spanish translation.
  34. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  35. for me to strive to better.
  36. Pixels^ - Running XScripters where the idea was born.
  37. Matite - Pestering me to release it and using it.
  38. Very special thanks to:
  39. Thiadmer - PAWN, whose limits continue to amaze me!
  40. Kye/Kalcor - SA:MP.
  41. SA:MP Team past, present and future - SA:MP.
  42. Version:
  43. 0.1
  44. Changelog:
  45. 25/02/12:
  46. First version.
  47. Functions:
  48. Stock:
  49. -
  50. Inline:
  51. -
  52. Variables:
  53. Global:
  54. -
  55. </remarks>
  56. \**--------------------------------------------------------------------------**/
  57. #include "..\y_utils"
  58. #include "..\y_colours"
  59. #include "..\y_debug"
  60. //#include "..\y_ini"
  61. #include "y_shortfunc"
  62. #include "y_natives"
  63. #include "..\y_va"
  64. #if !defined FORMAT_FADE_STEP
  65. #define FORMAT_FADE_STEP 2
  66. #endif
  67. #define Y_RENDER_SCM_COLOUR_LEN (8)
  68. //#define Y_RENDER_ONE_ARG
  69. // if ((arg = getarg(curArg++) || TRUE))
  70. // Loops through all possible arguments in lists, functions and singles. See
  71. // "case e_COMPRESS_FORMAT_DATA_CUSTOM:" for more details (an expanded macro
  72. // version can be found there).
  73. #define Y_RENDER_ARG for(new i,j,b=4;i!=2;++i)if(!i){if(ch&_:e_COMPRESS_FORMAT_DATA_FUNC){b=1,func="@yR_",va_getstring(func[4],curArg);if(funcidx(func)<0)func[b=2]='r';}else if(ch&_:e_COMPRESS_FORMAT_DATA_LIST)b=3;}else for(;(arg=b==1?W@(func,"iii",pid,(_:l),j):b==2?W@(func,"ii",(_:l),j):b==3?getarg(curArg,j++):getarg(curArg)),arg!=cellmin&&b||++curArg&0;b&=~4,++j)
  74. // Make the correct specifier string for the data stored in the compressed
  75. // specifier data.
  76. #define Y_RENDER_SPECIFIER(%0) ((ch&_:e_COMPRESS_FORMAT_DATA_ZERO)?((ch&_:e_COMPRESS_FORMAT_DATA_LEFT)?(scFormats[3][6]='%0',scFormats[3]):(scFormats[2][5]='%0',scFormats[2])):((ch&_:e_COMPRESS_FORMAT_DATA_LEFT)?(scFormats[1][5]='%0',scFormats[1]):(scFormats[0][4]='%0',scFormats[0])))
  77. // This makes hex and binary format specifiers display correctly with negative
  78. // numbers in all cases (e.g. %5x etc).
  79. #define Y_RENDER_FIX_NEGATIVE(%0:%1) if(width>%1)arg=(ch&_:e_COMPRESS_FORMAT_DATA_LEFT)?((ch&_:e_COMPRESS_FORMAT_DATA_ZERO)?format(ts,130,"%"#%0"%0-*"#%0,arg>>>32/%1,width-(%1-1),arg&(1<<32/%1)-1):format(ts,130,"%"#%0"%-*"#%0,arg>>>32/%1,width-(%1-1),arg&(1<<32/%1)-1)):(ch&_:e_COMPRESS_FORMAT_DATA_ZERO)?format(ts,130,"%0*"#%0"%"#%0,width-1,arg>>>32/%1,arg&(1<<32/%1)-1):format(ts,130,"%*"#%0"%"#%0,width-1,arg>>>32/%1,arg&(1<<32/%1)-1);else format(ts,130,"%"#%0"%"#%0,arg>>>32/%1,arg&(1<<32/%1)-1)
  80. // Try add a string to the current output. This needs modifying to reset the
  81. // whole function after a string is displayed. "onlyOne" is set in the case
  82. // where any line excess is cut off (e.g. in marquees).
  83. //#define Y_RENDER_ADD(%1) switch(Format_DoAddString(pid,output,%1,p,maxlen,llen,strlen(%1),fakepos,fade)){case 1:++one;case 2:Format_DoTryShow(output,fade);}
  84. #define Y_RENDER_DO_DISPLAY() {output[p]='\0';if(!none)Format_DoDisplay(pid,gInitialColour,output);if(onlyOne)return one;output[0]=p=0;llen=maxlen;++one;}
  85. #define Y_RENDER_ADD(%1) for(new __added,__len=strlen((%1)),__done;(__added=Format_DoAddString(output,%1[__done],p,__len,llen,fakePos));__done+=__added,__len-=__added){if(fade)state y_render_fade:y_render_fade_fake;else Y_RENDER_DO_DISPLAY()}
  86. //#define Y_RENDER_ADD_EX(%1,%2,%3) for(new __added,__len=(%3),__done=%2;(__added=Format_DoAddString(output,%1[__done],p,__len,llen,fakePos));__done+=__added,__len-=__added){if(fade)state y_render_fade:y_render_fade_fake;else Y_RENDER_DO_DISPLAY()}
  87. #define Y_RENDER_CHAR(%1) while(!Format_DoAddChar(output,(%1),p,llen,fakePos)){if(fade)state y_render_fade:y_render_fade_fake;else Y_RENDER_DO_DISPLAY()}
  88. // Helper macros to determine what a character is. This could be modified to
  89. // take in to account unicode letters, but that's hard. I don't know enough
  90. // about unicode, and frankly there are WAY too many characters to be listed
  91. // here. If other people want to modify this to support their language then
  92. // good on them.
  93. #define Y_TEXT_LETTER(%0) ('a'<=(%0)<='z'||'A'<=(%0)<='Z')
  94. #define Y_TEXT_NUMBER(%0) ('0'<=(%0)<='9')
  95. #define Y_RENDER_SCM_COLOUR_LEN (8)
  96. #define e_FORMAT_FLAGS_INDEX (0x00FFFFFF)
  97. #define e_FORMAT_FLAGS_REDO (0x01000000)
  98. #define e_FORMAT_FLAGS_ONE (0x02000000)
  99. #define e_FORMAT_FLAGS_NONE (0x04000000)
  100. static stock
  101. YSI_g_sListSep[4] = ", ",
  102. YSI_g_sFadeRedoTarget,
  103. YSI_g_sFadeLength,
  104. YSI_g_sFadeColour,
  105. bool:YSI_g_sJustOne,
  106. YSI_g_sTempStyle[E_STYLE_DATA],
  107. YSI_g_sTemp3D[E_3D_DATA],
  108. YSI_g_sTempMaster,
  109. Text:YSI_g_sBaseTD = TEXT_DRAW_NO_NEXT,
  110. //YSI_g_sExtraText[MAX_INI_ENTRY_TEXT],
  111. gInitialColour;
  112. stock _Text_SetDialogMode()
  113. {
  114. YSI_g_sTempStyle[E_STYLE_DATA_TYPE] = e_STYLE_TYPE_DIALOG;
  115. state y_render_show : y_render_show_scm;
  116. YSI_g_sJustOne = true;
  117. }
  118. stock Format_SetListSeparator(string:lst[])
  119. {
  120. strcpy(YSI_g_sListSep, lst);
  121. }
  122. stock _Format_SetStyleData(master, index, style[E_STYLE_DATA], label[E_3D_DATA])
  123. {
  124. // =========================================================================
  125. //
  126. #pragma unused index
  127. //
  128. // MAJOR WARNING:
  129. //
  130. // "Text_IsLocalOwner" DOES NOT PASS "INDEX" CORRECTLY AS IT DOESN'T KNOW
  131. // WHAT IT SHOULD BE, DON'T FORGET THIS IF YOU EVER USE "index"...
  132. //
  133. // =========================================================================
  134. YSI_g_sTempMaster = master;
  135. YSI_g_sTempStyle = style;
  136. YSI_g_sTemp3D = label;
  137. switch (style[E_STYLE_DATA_TYPE] & e_STYLE_TYPE_MASK)
  138. {
  139. case e_STYLE_TYPE_GT_0, e_STYLE_TYPE_GT_1, e_STYLE_TYPE_GT_2, e_STYLE_TYPE_GT_3, e_STYLE_TYPE_GT_4, e_STYLE_TYPE_GT_5, e_STYLE_TYPE_GT_6:
  140. {
  141. state y_render_show : y_render_show_gt;
  142. // Now that we know the style, we can store only the exact style.
  143. YSI_g_sTempStyle[E_STYLE_DATA_TYPE] = ((style[E_STYLE_DATA_TYPE] & e_STYLE_TYPE_MASK) >>> e_STYLE_TYPE_SHIFT) - e_STYLE_TYPE:1;
  144. YSI_g_sJustOne = true;
  145. return 144;
  146. }
  147. case e_STYLE_TYPE_CLIENT:
  148. {
  149. state y_render_show : y_render_show_scm;
  150. YSI_g_sJustOne = false;
  151. return 256;
  152. }
  153. case e_STYLE_TYPE_TD:
  154. {
  155. state y_render_show : y_render_show_td;
  156. YSI_g_sJustOne = true;
  157. // Anything with the ability to be longer than 1024 will require a
  158. // modification to the declaration of variables.
  159. return 1024;
  160. }
  161. }
  162. state y_render_show : y_render_show_print;
  163. return 1023;
  164. }
  165. static stock Format_InsertColour(str[], pos, &rem, &curCol, newCol, step) <y_render_show : y_render_show_scm>
  166. {
  167. // This code doesn't yet deal with colours which are too close to have their
  168. // differences detected by the human eye (especially when there are spaces).
  169. curCol = newCol & 0x00FFFFFF;
  170. if (pos == 0)
  171. {
  172. gInitialColour = curCol;
  173. // Don't add the colour - this is handled in the text display function.
  174. return 0;
  175. }
  176. // Now try add the string version of the colour.
  177. //printf("rem: %d, required: %d", rem, Y_RENDER_SCM_COLOUR_LEN);
  178. if (rem < Y_RENDER_SCM_COLOUR_LEN + step)
  179. {
  180. // Not enough space to add a new colour.
  181. str[pos] = '\0';
  182. return -1;
  183. }
  184. // This may well cut characters off the end of the string, but don't worry,
  185. // well, you can worry because it may mean that some characters are parsed
  186. // multiple times, but there's not a lot you can do about it... This is one
  187. // of the few places where the extra "+ 1" is taken in to account as format
  188. // uses it internally.
  189. format(str[pos], rem + 1, "{%06x}%s", curCol, str[pos]);
  190. rem -= Y_RENDER_SCM_COLOUR_LEN;
  191. return Y_RENDER_SCM_COLOUR_LEN;
  192. }
  193. #define _COLOUR_GT_SPACE_DEF_0(%0) SAMP_GAME_TEXT_%0
  194. #define _COLOUR_GT_SPACE_DEF_1(%0) SAMP_GAME_TEXT_%0H
  195. #define _COLOUR_GT_SPACE_DEF_2(%0) SAMP_GAME_TEXT_%0HH
  196. #define _COLOUR_GT_SPACE_DEF_3(%0) SAMP_GAME_TEXT_%0HHH
  197. #define _COLOUR_GT_SPACE_DEF_4(%0) SAMP_GAME_TEXT_%0HHHH
  198. #define _COLOUR_GT_SPACE_DEF_5(%0) SAMP_GAME_TEXT_%0HHHHH
  199. #define _COLOUR_GT_SPACE(%0,%1) {('%0'|0x20)|(%1<<8),_COLOUR_GT_SPACE_DEF_%1(%0)>>>24,_COLOUR_GT_SPACE_DEF_%1(%0)>>16&0xFF,_COLOUR_GT_SPACE_DEF_%1(%0)>>8&0xFF}
  200. #define COLOUR_FLOAT_INFINITY (Float:0x7F800000)
  201. static stock Colours_SAMPToGT(colour, start)
  202. {
  203. P:4("Colours_SAMPToGT called: %i", colour);
  204. // Find the closest matching game text colour to the given SA:MP colour.
  205. static const
  206. sc_aColours[][4] =
  207. {
  208. // These can't be used as you can't set text to them. You can
  209. // however use them at the start by not changing.
  210. _COLOUR_GT_SPACE(X,0), _COLOUR_GT_SPACE(X,1),
  211. _COLOUR_GT_SPACE(X,2),
  212. _COLOUR_GT_SPACE(R,0), _COLOUR_GT_SPACE(R,1),
  213. _COLOUR_GT_SPACE(R,2), _COLOUR_GT_SPACE(R,3),
  214. _COLOUR_GT_SPACE(R,4), _COLOUR_GT_SPACE(R,5),
  215. _COLOUR_GT_SPACE(G,0), _COLOUR_GT_SPACE(G,1),
  216. _COLOUR_GT_SPACE(G,2), _COLOUR_GT_SPACE(G,3),
  217. //_COLOUR_GT_SPACE(G,4), // Don't want this twice (see Y2).
  218. _COLOUR_GT_SPACE(B,0), _COLOUR_GT_SPACE(B,1),
  219. _COLOUR_GT_SPACE(B,2), _COLOUR_GT_SPACE(B,3),
  220. _COLOUR_GT_SPACE(Y,0), _COLOUR_GT_SPACE(Y,1),
  221. _COLOUR_GT_SPACE(Y,2),
  222. _COLOUR_GT_SPACE(P,0), _COLOUR_GT_SPACE(P,1),
  223. _COLOUR_GT_SPACE(P,2),
  224. _COLOUR_GT_SPACE(W,0),
  225. _COLOUR_GT_SPACE(L,0)
  226. };
  227. new
  228. Float:dist = COLOUR_FLOAT_INFINITY,
  229. found = '\0',
  230. r = colour >> 16,
  231. g = colour >> 8 & 0xFF,
  232. b = colour & 0xFF,
  233. tr, tg, tb, Float:cur;
  234. for ( ; start < sizeof (sc_aColours); ++start)
  235. {
  236. tr = r - sc_aColours[start][1];
  237. tg = g - sc_aColours[start][2];
  238. tb = b - sc_aColours[start][3];
  239. cur = (tr * tr) + (tg * tg) + (tb * tb);
  240. if (cur < dist)
  241. {
  242. // This may sometimes give odd results in fades for draw results.
  243. // Though I've not seen it happen yet.
  244. dist = cur;
  245. found = sc_aColours[start][0];
  246. }
  247. }
  248. return found;
  249. }
  250. static stock Format_InsertColour(str[], pos, &rem, &curCol, newCol, step) <>
  251. {
  252. #pragma unused str, pos, rem, step
  253. curCol = newCol;
  254. return 0;
  255. }
  256. static stock Format_InsertColour(str[], pos, &rem, &curCol, newCol, step) <y_render_show : y_render_show_gt, y_render_show : y_render_show_td>
  257. {
  258. // First get the closest GameText colour for the true colour. I wrote a
  259. // function for this a LONG time ago, finally got around to using it!
  260. new
  261. ot = curCol & 0xFF,
  262. oc = curCol >>> 8;
  263. if (ot == 0 || ot == 'x')
  264. {
  265. // Still near the start, allow some of the special start colours.
  266. newCol = Colours_SAMPToGT(newCol & 0x00FFFFFF, oc);
  267. }
  268. else
  269. {
  270. // Can't use the oragey colour used at the start.
  271. newCol = Colours_SAMPToGT(newCol & 0x00FFFFFF, 3);
  272. }
  273. new
  274. nt = newCol & 0xFF,
  275. nc = (newCol >>> 8) * 3;
  276. curCol = newCol;
  277. // Compare them.
  278. static
  279. cs_hTags[] = "~x~~h~~h~~h~~h~~h~%s";
  280. if (nt == ot)
  281. {
  282. ot = nc - (oc * 3);
  283. if (ot == 0)
  284. {
  285. // No change, return 0 if there are enough charaters to show the
  286. // text that should come after this new colour.
  287. return rem >= step ? 0 : -1;
  288. }
  289. else if (ot > 0)
  290. {
  291. if (rem >= ot + step)
  292. {
  293. // Add enough "lighter" tags to change the old colour in to the
  294. // new colour.
  295. format(str[pos], rem + 1, cs_hTags[sizeof (cs_hTags) - 3 - ot], str[pos]);
  296. rem -= ot;
  297. return ot;
  298. }
  299. else
  300. {
  301. return -1;
  302. }
  303. }
  304. }
  305. if (rem < nc + step)
  306. {
  307. return -1;
  308. }
  309. // Subtract six from the size : 3 for "%s\0" and 3 for the extra "~x~"
  310. // needed as placeholder for the colour tag (added on the next line).
  311. format(str[pos], rem + 1, cs_hTags[sizeof (cs_hTags) - 6 - nc], str[pos]);
  312. str[pos + 1] = nt;
  313. rem -= nc + 3;
  314. return nc + 3;
  315. }
  316. static stock Format_AddColour(str[], pos, &rem, &curCol, newCol) <y_render_show : y_render_show_scm>
  317. {
  318. // This code doesn't yet deal with colours which are too close to have their
  319. // differences detected by the human eye (especially when there are spaces).
  320. new
  321. rgb = newCol & 0x00FFFFFF;
  322. // Don't add the colour if there's no change from the last one.
  323. if (rgb == curCol)
  324. {
  325. return 0;
  326. }
  327. if (-0x5 <= ((rgb & 0x0FF) - (curCol & 0xFF)) <= 0x5)
  328. {
  329. if (-0x500 <= ((rgb & 0xFF00) - (curCol & 0xFF00)) <= 0x500)
  330. {
  331. if (-0x50000 <= ((rgb & 0xFF0000) - (curCol & 0xFF0000)) <= 0x50000)
  332. {
  333. // Haven't changed the colour.
  334. return 0;
  335. }
  336. }
  337. }
  338. if (YSI_g_sTempStyle[E_STYLE_DATA_TYPE] != e_STYLE_TYPE_DIALOG && pos == 0)
  339. {
  340. gInitialColour = curCol;
  341. // Don't add the colour - this is handled in the text display function.
  342. curCol = rgb;
  343. return 0;
  344. }
  345. // Now try add the string version of the colour.
  346. if (rem < Y_RENDER_SCM_COLOUR_LEN)
  347. {
  348. // Not enough space to add a new colour.
  349. str[pos] = '\0';
  350. return -1;
  351. }
  352. format(str[pos], rem + 1, "{%06x}", rgb);
  353. rem -= Y_RENDER_SCM_COLOUR_LEN;
  354. curCol = newCol;
  355. return Y_RENDER_SCM_COLOUR_LEN;
  356. }
  357. static stock Format_AddColour(str[], pos, &rem, &curCol, newCol) <>
  358. {
  359. #pragma unused str, pos, rem
  360. curCol = newCol;
  361. return 0;
  362. }
  363. static stock Format_AddColour(str[], pos, &rem, &curCol, newCol) <y_render_show : y_render_show_gt, y_render_show : y_render_show_td>
  364. {
  365. // First get the closest GameText colour for the true colour. I wrote a
  366. // function for this a LONG time ago, finally got around to using it!
  367. new
  368. ot = curCol & 0xFF,
  369. oc = curCol >>> 8;
  370. if (ot == 0 || ot == 'x')
  371. {
  372. // Still near the start, allow some of the special start colours.
  373. newCol = Colours_SAMPToGT(newCol & 0x00FFFFFF, oc);
  374. }
  375. else
  376. {
  377. // Can't use the oragey colour used at the start.
  378. newCol = Colours_SAMPToGT(newCol & 0x00FFFFFF, 3);
  379. }
  380. new
  381. nt = newCol & 0xFF,
  382. nc = (newCol >>> 8) * 3;
  383. curCol = newCol;
  384. // Compare them.
  385. static
  386. cs_hTags[] = "~x~~h~~h~~h~~h~~h~";
  387. if (nt == ot)
  388. {
  389. ot = nc - (oc * 3);
  390. if (ot == 0)
  391. {
  392. return 0;
  393. }
  394. else if (ot > 0)
  395. {
  396. if (rem >= ot)
  397. {
  398. // Add enough "lighter" tags to change the old colour in to the
  399. // new colour.
  400. str[pos] = '\0';
  401. strcat(str[pos], cs_hTags[sizeof (cs_hTags) - 1 - ot], rem + 1);
  402. rem -= ot;
  403. return ot;
  404. }
  405. else
  406. {
  407. return -1;
  408. }
  409. }
  410. }
  411. if (rem < nc)
  412. {
  413. return -1;
  414. }
  415. // Subtract six from the size : 3 for "%s\0" and 3 for the extra "~x~"
  416. // needed as placeholder for the colour tag (added on the next line).
  417. //format(str[pos], rem + 1, cs_hTags[sizeof (cs_hTags) - 6 - nc], str[pos]);
  418. str[pos] = '\0';
  419. strcat(str[pos], cs_hTags[sizeof (cs_hTags) - 4 - nc], rem + 1);
  420. str[pos + 1] = nt;
  421. rem -= nc + 3;
  422. return nc + 3;
  423. }
  424. // str = input and output write array.
  425. // pos = start position of the string to be faded.
  426. // len = total remaining space in the string.
  427. // endColour = target colour.
  428. // gInitialColour = start and current colour.
  429. // step = number of characters for each colour.
  430. // offset = number of characters in the fade not being shown.
  431. static stock Format_AddFade(str[], &pos, &len, endColour, &initialColour, step, offset) //<y_render_display : send_client_message>
  432. {
  433. // Add a fade for a SendClientMessage. This is called if a string is filled
  434. // up during a fade or the end of a fade is reached correctly. In either
  435. // case the current fade will constiture the end of the known current string
  436. // so in actual fact no additionl text after the end of the fade will be
  437. // dropped. This is also where we can save the data to appear in the fade
  438. // on the next line and re-show it.
  439. // Work out how many colours can be inserted at the specified step value
  440. // (i.e. how often a new colour appears) within the length from "pos" to the
  441. // end of "str". This may be more than is required. "len" is from "pos" to
  442. // the end of the string, NOT to the end of the characters requiring the
  443. // fade. The length of the required fade is in "YSI_g_sFadeLength" so that the
  444. // value can be used in the future.
  445. new
  446. parts = (YSI_g_sFadeLength + step - 1) / step + offset,
  447. // We can insert all the colours and their texts in the given space.
  448. // Now we just need to figure out how...
  449. // First get the start and end colours.
  450. start = str[pos + 1] & 0x00FFFFFF; //~(Y_FORMAT_START_FADE | Y_FORMAT_ALWAYS_SET);
  451. // Remove the start and end colour markers.
  452. strdel(str, pos, pos + 2);
  453. // Find the colour components and component deltas.
  454. endColour &= 0x00FFFFFF; //~(Y_FORMAT_START_FADE | Y_FORMAT_ALWAYS_SET);
  455. new
  456. red = start >>> 16 & 0xFF,
  457. dred = ((endColour >>> 16 & 0xFF) - red) / parts,
  458. pred = initialColour >>> 16 & 0xFF,
  459. green = start >>> 8 & 0xFF,
  460. dgreen = ((endColour >>> 8 & 0xFF) - green) / parts,
  461. pgreen = initialColour >>> 8 & 0xFF,
  462. blue = start >>> 0 & 0xFF,
  463. dblue = ((endColour >>> 0 & 0xFF) - blue) / parts,
  464. pblue = initialColour >>> 0 & 0xFF;
  465. // Take old strings in to account.
  466. red += dred * offset;
  467. blue += dblue * offset;
  468. green += dgreen * offset;
  469. //strdel(str, pmax, pmax + 2);
  470. //startColour = gInitialColour;
  471. do
  472. {
  473. // Insert the new colour, if it is sufficiently different from the
  474. // existing colour to warrant being added new.
  475. if (-3 <= red - pred <= 3 && -3 <= blue - pblue <= 3 && -3 <= green - pgreen <= 3)
  476. {
  477. pos += step;
  478. }
  479. else
  480. {
  481. new
  482. upd = Format_InsertColour(str, pos, len, initialColour, red << 16 | green << 8 | blue, step);
  483. if (upd == -1)
  484. {
  485. // Didn't quite finish everything. This is the number of
  486. // characters left to process.
  487. return YSI_g_sFadeLength;
  488. }
  489. //initial += step;
  490. pos += step + upd;
  491. pred = red;
  492. pgreen = green;
  493. pblue = blue;
  494. }
  495. YSI_g_sFadeLength -= step;
  496. len -= step;
  497. red = red + dred & 0xFF;
  498. green = green + dgreen & 0xFF;
  499. blue = blue + dblue & 0xFF;
  500. // Could do something with "len" here if it runs out to signify that
  501. // more text needs to go on the next line of output.
  502. }
  503. while (YSI_g_sFadeLength > 0);
  504. // Correct for any excess characters.
  505. pos += YSI_g_sFadeLength;
  506. // This doesn't add the actual destination colour - that is added by virtue
  507. // of the fact that it is actually just a normal colour, so we can use the
  508. // standard colour code (whatever that may be) to add it in a more generic
  509. // way.
  510. return 0;
  511. }
  512. static stock Format_DoEndFade(output[], &start, end, &rem, colour, &initial) //<>
  513. {
  514. // If "colour" is 0 this is the end of a string before the close colour is
  515. // reached. This fact is enforced by "Y_FORMAT_ALWAYS_SET", which ensures
  516. // that all colours, including black, are not 0 in the string to avoid PAWN
  517. // treating the colour as a NULL terminator or, as here, a no-colour marker.
  518. if (colour)
  519. {
  520. new
  521. offset = 0;
  522. if (YSI_g_sFadeLength)
  523. {
  524. initial = YSI_g_sFadeColour;
  525. offset = end - start - YSI_g_sFadeLength;
  526. //printf("parts: %d, %d, %d", offset, YSI_g_sFadeLength, end - start);
  527. }
  528. else
  529. {
  530. YSI_g_sFadeLength = end - start;
  531. }
  532. // "rem" will hold the number of characters AFTER the fade string on
  533. // entry, this needs fixing here to exclude them as they're being messed
  534. // with.
  535. rem += YSI_g_sFadeLength;
  536. //printf("length: %d", YSI_g_sFadeLength);
  537. // I wrote this code for the case where too much data has been found and
  538. // we needed a fake render to get the full length, but then found that
  539. // exactly the same code was needed for the default case too...
  540. //printf("Format_DoEndFade: %d %d %x %x %d", YSI_g_sFadeLength, /*YSI_g_sFadeLength +*/ rem, colour, initial, start);
  541. // Default step value is 1 and there is currently no way to change it.
  542. new
  543. ret = Format_AddFade(output, start, /*YSI_g_sFadeLength +*/ rem, colour, initial, FORMAT_FADE_STEP, offset);
  544. //printf("Format_DoEndFade: %d %d %x %x %d", YSI_g_sFadeLength, /*YSI_g_sFadeLength +*/ rem, colour, initial, start);
  545. YSI_g_sFadeColour = initial;
  546. return ret;
  547. }
  548. else
  549. {
  550. //printf("colour: %d", YSI_g_sFadeColour);
  551. // Quite simply, we just change state and return to the calling
  552. // function. This allows this function to be called again when the true
  553. // fade end is reached and the length to be determined. After that some
  554. // re-parsing will need to be done I'm afraid, but that will be handled
  555. // by code dealing with fades which fall over the end of a string, be it
  556. // due to this or to a known length string being pushed over the end due
  557. // to the insertion of the colour codes. Note that this code is display
  558. // method independent - it works for SendClientMessage, GameText and
  559. // others.
  560. state y_render_fade : y_render_fade_fake;
  561. // The return here causes remaining code to continue as normal, but
  562. // makes certain functions just not run.
  563. }
  564. return 0;
  565. }
  566. /**--------------------------------------------------------------------------**\
  567. <summary>Format_DoAddString</summary>
  568. <param name="out[]">The destination string.</param>
  569. <param name="in[]">The data to add.</param>
  570. <param name="&oidx">The index in "out" at which to add data.</param>
  571. <param name="len">The length of "in".</param>
  572. <param name="&orem">Space remaining in "out".</param>
  573. <param name="&fakePos">Like "oidx", but cumulative over line breaks.</param>
  574. <returns>
  575. The amount of data from "in" not added to "out".
  576. </returns>
  577. <remarks>
  578. Takes an input string and adds it to an output string. If the input string
  579. is too long to fit in the remainder of the output string, what has been
  580. added already (including part of the input string) is displayed and a new
  581. string is added. Format_TryShow handles this, including adding formatting
  582. of colour fades, which may involve fake rendering of more of the string to
  583. determine how much of the remainder of the string needs processing to get
  584. the right colour. This will also require a method of winding back the state
  585. to the point just after the initial input string was added to continue on to
  586. show the next string including newly determined fade data.
  587. </remarks>
  588. \**--------------------------------------------------------------------------**/
  589. static stock Format_DoAddString(out[], const in[], &oidx, const len, &orem, &fakepos) <y_render_fade : y_render_fade_fake>
  590. {
  591. #pragma unused out, in, oidx, orem
  592. fakepos += len;
  593. return 0;
  594. }
  595. static stock Format_DoAddString(out[], const in[], &oidx, const len, &orem, &fakepos) <y_render_fade : y_render_fade_redo>
  596. {
  597. new
  598. temp = fakepos + len - YSI_g_sFadeRedoTarget;
  599. if (temp > 0)
  600. {
  601. state y_render_fade : y_render_fade_real;
  602. // This is where the string passes the target point of re-rendering.
  603. new
  604. other = YSI_g_sFadeRedoTarget - fakepos;
  605. fakepos += other;
  606. return Format_DoAddString(out, in[other], oidx, temp, orem, fakepos);
  607. }
  608. else
  609. {
  610. fakepos += len;
  611. return 0;
  612. }
  613. }
  614. static stock Format_DoAddString(out[], const in[], &oidx, const len, &orem, &fakepos) <y_render_fade : y_render_fade_real>
  615. {
  616. P:4("Format_DoAddString <y_render_fade : render_real> called: \"%s\", \"%s\", %i, %i, %i, %i", out, in, oidx, len, orem, fakepos);
  617. // For now don't worry about fades over boundaries - they're just too hard
  618. // to get the code working on to start with, maybe later once this is all
  619. // working they can be added in. It is a shame though as it will mean fades
  620. // don't always work. I can cheat slightly though and have the full fade on
  621. // both halves of the break. Or just warn people about fades like that.
  622. //
  623. // NOTE: This code assumes that orem (output remaining) is always 1 less
  624. // than the true value. This avoids awkward calculations when appending the
  625. // NULL terminator to strings. When we run out of space it simply appends
  626. // it regardless of wether it thinks there is space or not.
  627. //
  628. fakepos += len;
  629. if (len <= orem)
  630. {
  631. P:5("Format_DoStringSCM: p0.");
  632. memcpy(out[oidx], in, 0, len * 4, orem);
  633. orem -= len;
  634. oidx += len;
  635. // The whole string fit in - return true.
  636. return 0;
  637. }
  638. else
  639. {
  640. // Not the end of the string, but the end is required.
  641. // Change state to ignore future inputs.
  642. P:5("Format_DoStringSCM: p1.");
  643. // Copy as much data as possible.
  644. memcpy(out[oidx], in, 0, orem * 4, orem);
  645. //orem -= orem;
  646. //oidx += orem;
  647. // Don't need to adjust this further down as all the characters will be
  648. // added before the recursive call.
  649. oidx += orem;
  650. return len - orem;
  651. }
  652. }
  653. static stock bool:Format_DoAddChar(out[], const in, &oidx, &orem, &fakepos) <y_render_fade : y_render_fade_fake>
  654. {
  655. #pragma unused out, in, oidx, orem
  656. ++fakepos;
  657. return true;
  658. }
  659. static stock bool:Format_DoAddChar(out[], const in, &oidx, &orem, &fakepos) <y_render_fade : y_render_fade_redo>
  660. {
  661. if (fakepos == YSI_g_sFadeRedoTarget)
  662. {
  663. state y_render_fade : y_render_fade_real;
  664. // This should never actually fail...
  665. if (!orem) return false;
  666. --orem;
  667. out[oidx++] = in;
  668. }
  669. ++fakepos;
  670. return true;
  671. }
  672. static stock bool:Format_DoAddChar(out[], const in, &oidx, &orem, &fakepos) <y_render_fade : y_render_fade_real>
  673. {
  674. P:4("Format_DoAddChar: %c %d %d", in, oidx, orem);
  675. if (!orem) return false;
  676. --orem;
  677. out[oidx++] = in;
  678. ++fakepos;
  679. return true;
  680. }
  681. static stock Format_DoDisplay(playerid, colour, out[]) <y_render_show : y_render_show_scm>
  682. {
  683. P:2("Format_DoDisplay a: %d, %06x, \"%s\"", playerid, colour >>> 8, out);
  684. SendClientMessage(playerid, (colour << 8) | ((YSI_g_sTempStyle[E_STYLE_DATA_COLOUR] & 0x0F) * 0x11), out);
  685. //idx = 0;
  686. //out[0] = '\0';
  687. }
  688. static stock Format_DoDisplay(playerid, colour, out[]) <> //y_render_show : y_render_show_print>
  689. {
  690. P:0("Format_DoDisplay b: %d, %06x, \"%s\"", playerid, colour >>> 8, out);
  691. //idx = 0;
  692. //out[0] = '\0';
  693. }
  694. static stock Format_DoDisplay(playerid, colour, out[]) <y_render_show : y_render_show_gt>
  695. {
  696. #pragma unused colour
  697. P:2("Format_DoDisplay c: %d, %06x, \"%s\"", playerid, colour >>> 8, out);
  698. GameTextForPlayer(playerid, out, YSI_g_sTempStyle[E_STYLE_DATA_TIME], YSI_g_sTempStyle[E_STYLE_DATA_STYLE]);
  699. //SendClientMessage(playerid, (colour << 8) | ((YSI_g_sTempStyle[E_STYLE_DATA_COLOUR] & 0x0F) * 0x11), out);
  700. //GameTextForPlayer(playerid, out,
  701. //SendClientMessage(playerid, colour, out);
  702. //idx = 0;
  703. //out[0] = '\0';
  704. }
  705. static stock Format_DoDisplay(playerid, colour, out[]) <y_render_show : y_render_show_td>
  706. {
  707. #pragma unused colour
  708. P:2("Format_DoDisplay d: %d, %06x, \"%s\"", playerid, colour >>> 8, out);
  709. new
  710. Text:tmp = TD_Display(out, YSI_g_sTempStyle[E_STYLE_DATA_TD_ID]);
  711. out[0] = _:tmp;
  712. out[1] = '\0';
  713. TD_ShowForPlayer(playerid, tmp);
  714. TD_Garbage(tmp);
  715. // Link these TDs together for future manipulations.
  716. if (YSI_g_sBaseTD == TEXT_DRAW_NO_NEXT)
  717. {
  718. YSI_g_sBaseTD = tmp;
  719. }
  720. else
  721. {
  722. TD_Link(YSI_g_sBaseTD, tmp);
  723. }
  724. //SendClientMessage(playerid, (colour << 8) | ((YSI_g_sTempStyle[E_STYLE_DATA_COLOUR] & 0x0F) * 0x11), out);
  725. //GameTextForPlayer(playerid, out,
  726. //SendClientMessage(playerid, colour, out);
  727. //idx = 0;
  728. //out[0] = '\0';
  729. }
  730. /**--------------------------------------------------------------------------**\
  731. <summary>Format_JustShow</summary>
  732. <param name="playerid">Player to show the text to.</param>
  733. <param name="out[]">What the text to show is.</param>
  734. <returns>
  735. -
  736. </returns>
  737. <remarks>
  738. -
  739. </remarks>
  740. \**--------------------------------------------------------------------------**/
  741. stock Format_JustShow(playerid, out[]) <y_render_show : y_render_show_scm>
  742. {
  743. SendClientMessage(playerid, gInitialColour, out);
  744. }
  745. stock Format_JustShow(playerid, out[]) <y_render_show : y_render_show_print>
  746. {
  747. P:0("Format_DoDisplay: %d, \"%s\"", playerid, out);
  748. }
  749. stock Format_JustShow(playerid, out[]) <y_render_show : y_render_show_gt>
  750. {
  751. GameTextForPlayer(playerid, out, YSI_g_sTempStyle[E_STYLE_DATA_TIME], YSI_g_sTempStyle[E_STYLE_DATA_STYLE]);
  752. }
  753. stock Format_JustShow(playerid, out[]) <y_render_show : y_render_show_td>
  754. {
  755. TD_ShowForPlayer(playerid, Text:out[0]);
  756. }
  757. /**--------------------------------------------------------------------------**\
  758. <summary>Text_GetLastID</summary>
  759. <returns>
  760. The basic ID linking all displayed elements together where appropriate (for
  761. example SendClientMessage has no meaningful ID. 3D texts would, but that's
  762. not implemented. So do game texts, but that's not implemented either, so
  763. really it's just text draws.
  764. </returns>
  765. <remarks>
  766. -
  767. </remarks>
  768. \**--------------------------------------------------------------------------**/
  769. stock Text_GetLastID() <y_render_show : y_render_show_td>
  770. {
  771. return _:YSI_g_sBaseTD;
  772. }
  773. stock Text_GetLastID() <>
  774. {
  775. return -1;
  776. }
  777. /**--------------------------------------------------------------------------**\
  778. <summary>-</summary>
  779. <returns>
  780. -
  781. </returns>
  782. <remarks>
  783. -
  784. </remarks>
  785. \**--------------------------------------------------------------------------**/
  786. // Generic function to handle rendering for all types of outputs. Other
  787. // functions such as Format_AddColour are specialised for different text styles.
  788. // The faster way to do this would be to store the characters removed from a
  789. // string when adding in fade data, but this is hard to code. The simpler
  790. // method is to fake re-render the string, having previously determined the
  791. // length of the string which will be faded across. Note that this may mean
  792. // that some parts of the string can get rendered many times, but we can just
  793. // issue a performance warning when the player uses fades which go over a line
  794. // boundary. That is the only time in which it is a problem, more specifically
  795. // it is only a problem when text in a fade goes over a line boundardy before
  796. // the end fade marker has been reached.
  797. //stock Format_Render(pid, Language:l, output[], maxlen, idx, target, string[], {Float,_}:...)
  798. stock Format_Render(pid, Language:l, output[], maxlen, idx, target, string[], argCount, GLOBAL_TAG_TYPES:...)
  799. {
  800. P:3("Format_Render called: %i, %i, %s, %i, %i, %i, %s (+%i)", pid, _:l, output, maxlen, idx, target, argCount, numargs() - 8);
  801. //state y_text_colour_fade:full_render;
  802. gInitialColour = (YSI_g_sTempStyle[E_STYLE_DATA_COLOUR] >>> 4) & 0x00FFFFFF;
  803. new
  804. colour = gInitialColour;
  805. YSI_g_sFadeLength = 0;
  806. YSI_g_sBaseTD = TEXT_DRAW_NO_NEXT;
  807. // Now the (mostly) tail-recursive function call.
  808. Format_Render_start:
  809. static
  810. scFormats[][8] =
  811. {
  812. "%*.*d", // 6 (6)
  813. "%-*.*d", // 7 (13)
  814. "%0*.*d", // 7 (20)
  815. "%0-*.*d" // 8 (28)
  816. },
  817. scSpecifier[8],
  818. // =====================================================================
  819. // UPDATE Y_RENDER_FIX_NEGATIVE MACRO ON CHANGE!!!!!!!
  820. ts[130],
  821. // Max handleable input string length is 128 (hopefully sufficient).
  822. // =====================================================================
  823. func[32],
  824. scNewLineString[] = "~n~",
  825. scDialogLineString[] = "\r\n";
  826. new
  827. ch,
  828. llen = maxlen,
  829. //output[128], // Always 128.
  830. p = 0,
  831. curArg = 8, // Account for additionaly pushed arguments.
  832. numArgs = numargs() + argCount,
  833. //llen = sizeof (output) - 1,
  834. arg,
  835. none = (target & e_FORMAT_FLAGS_NONE),
  836. onlyOne = (target & e_FORMAT_FLAGS_ONE) | none | _:YSI_g_sJustOne,
  837. bool:fade = false,
  838. bool:nlInFade = false,
  839. // flags:
  840. // 1 = Just one output.
  841. // 2 = Newline found in fade.
  842. // 4 = In a fade.
  843. //flags = (target & e_FORMAT_FLAGS_ONE) ? 1 : 0,
  844. fakePos = 0,
  845. // Was only "one" string display used and is this not per-player text?
  846. one = 0,
  847. // Start location of the current fade.
  848. fadeStart,
  849. fadeStartIdx;//,
  850. //fadeStartText;
  851. //#emit LOAD.S.pri string
  852. //#emit STOR.S.pri fadeStartText
  853. if (target & e_FORMAT_FLAGS_REDO)
  854. {
  855. // We need to skip data, ignore everything before "target1".
  856. state y_render_fade : y_render_fade_redo;
  857. }
  858. else
  859. {
  860. state y_render_fade : y_render_fade_real;
  861. }
  862. target &= e_FORMAT_FLAGS_INDEX;
  863. /*new
  864. fadeCurArg,
  865. fadeArg,
  866. fadeIdx;*/
  867. if ((YSI_g_sFadeRedoTarget = target))
  868. {
  869. YSI_g_sFadeRedoTarget &= ~Y_FORMAT_ALWAYS_SET;
  870. state y_render_fade : y_render_fade_redo;
  871. }
  872. else
  873. {
  874. state y_render_fade : y_render_fade_real;
  875. }
  876. /*ch = string[idx];
  877. if (ch > 0)
  878. {
  879. // Copy strings.
  880. ++idx;
  881. Y_RENDER_ADD_EX(string, idx, ch - idx)
  882. idx = ch;
  883. }*/
  884. while ((ch = string[idx++]))
  885. {
  886. // TODO: Add {*} and #* format for variable colours.
  887. switch (ch)
  888. {
  889. case '\01':
  890. {
  891. // Null.
  892. break;
  893. }
  894. case '\02':
  895. {
  896. P:6("Text_Render: Format specifier %d", curArg);
  897. if (curArg == numArgs)
  898. {
  899. // Skip.
  900. P:W("Insufficient parameters to YSI format.");
  901. ts = "(null)";
  902. Y_RENDER_ADD(ts)
  903. continue;
  904. }
  905. // Format.
  906. ch = string[idx++];
  907. new
  908. width = (ch & _:e_COMPRESS_FORMAT_DATA_WIDTH),
  909. prec = (ch & _:e_COMPRESS_FORMAT_DATA_PREC) >>> 12;
  910. // Get the true values of the various data bits.
  911. if (width == 0x0800)
  912. {
  913. width = getarg(curArg++);
  914. }
  915. if (prec == 0x0800)
  916. {
  917. prec = getarg(curArg++);
  918. }
  919. else if (prec == 0x0FFF)
  920. {
  921. prec = -1;
  922. }
  923. // Output the correct data type.
  924. switch (ch & 0xF0000000)
  925. {
  926. case e_COMPRESS_FORMAT_DATA_DEC:
  927. {
  928. P:6("Text_Render: Add d");
  929. scSpecifier = Y_RENDER_SPECIFIER(d);
  930. Y_RENDER_ARG
  931. {
  932. //p += Format_AddInt(output[p], llen, arg, width, ch);
  933. format(ts, sizeof (ts), scSpecifier, width, prec, arg);
  934. Y_RENDER_ADD(ts)
  935. }
  936. }
  937. case e_COMPRESS_FORMAT_DATA_HEX:
  938. {
  939. // This completely fixes (I hope) the problems with
  940. // displaying negative numbers as %h/%x numbers.
  941. P:6("Text_Render: Add h");
  942. scSpecifier = Y_RENDER_SPECIFIER(x);
  943. Y_RENDER_ARG
  944. {
  945. if (arg & 0x80000000)
  946. {
  947. Y_RENDER_FIX_NEGATIVE(x:8);
  948. }
  949. else
  950. {
  951. format(ts, sizeof (ts), scSpecifier, width, prec, arg);
  952. }
  953. Y_RENDER_ADD(ts)
  954. }
  955. }
  956. case e_COMPRESS_FORMAT_DATA_BIN:
  957. {
  958. P:6("Text_Render: Add b");
  959. scSpecifier = Y_RENDER_SPECIFIER(b);
  960. Y_RENDER_ARG
  961. {
  962. if (arg & 0x80000000)
  963. {
  964. Y_RENDER_FIX_NEGATIVE(b:32);
  965. }
  966. else
  967. {
  968. format(ts, sizeof (ts), scSpecifier, width, prec, arg);
  969. }
  970. Y_RENDER_ADD(ts)
  971. }
  972. }
  973. case e_COMPRESS_FORMAT_DATA_CHAR:
  974. {
  975. scSpecifier = Y_RENDER_SPECIFIER(c);
  976. Y_RENDER_ARG
  977. {
  978. //p += Format_AddInt(output[p], llen, arg, width, ch);
  979. format(ts, sizeof (ts), scSpecifier, width, prec, arg);
  980. Y_RENDER_ADD(ts)
  981. }
  982. }
  983. case e_COMPRESS_FORMAT_DATA_FLOAT:
  984. {
  985. scSpecifier = Y_RENDER_SPECIFIER(f);
  986. Y_RENDER_ARG
  987. {
  988. //p += Format_AddInt(output[p], llen, arg, width, ch);
  989. format(ts, sizeof (ts), scSpecifier, width, prec, arg);
  990. Y_RENDER_ADD(ts)
  991. }
  992. }
  993. case e_COMPRESS_FORMAT_DATA_IEEE:
  994. {
  995. Y_RENDER_ARG
  996. {
  997. if ((arg & 0x7F800000) == 0x7F800000)
  998. {
  999. scSpecifier = Y_RENDER_SPECIFIER(s);
  1000. // One of the special numbers.
  1001. if (arg & 0x007FFFFF)
  1002. {
  1003. // NAN.
  1004. if (arg & 0x00400000)
  1005. {
  1006. // QNAN
  1007. format(ts, sizeof (ts), scSpecifier, width, cellmax, "QNAN");
  1008. Y_RENDER_ADD(ts)
  1009. }
  1010. else
  1011. {
  1012. // SNAN
  1013. format(ts, sizeof (ts), scSpecifier, width, cellmax, "SNAN");
  1014. Y_RENDER_ADD(ts)
  1015. }
  1016. }
  1017. else
  1018. {
  1019. if (arg & 0x80000000)
  1020. {
  1021. // -INFINITY
  1022. format(ts, sizeof (ts), scSpecifier, width, cellmax, "-INFINITY");
  1023. Y_RENDER_ADD(ts)
  1024. }
  1025. else
  1026. {
  1027. // INFINITY
  1028. format(ts, sizeof (ts), scSpecifier, width, cellmax, "INFINITY");
  1029. Y_RENDER_ADD(ts)
  1030. }
  1031. }
  1032. }
  1033. else
  1034. {
  1035. scSpecifier = Y_RENDER_SPECIFIER(f);
  1036. format(ts, sizeof (ts), scSpecifier, width, prec, arg);
  1037. Y_RENDER_ADD(ts)
  1038. }
  1039. }
  1040. }
  1041. case e_COMPRESS_FORMAT_DATA_STRING:
  1042. {
  1043. scSpecifier = Y_RENDER_SPECIFIER(s);
  1044. if (ch & _:e_COMPRESS_FORMAT_DATA_FUNC)
  1045. {
  1046. func = "@yR_";
  1047. // Get the function name.
  1048. for (new _k = 4; _k != 32; ++_k)
  1049. {
  1050. if (!(func[_k] = getarg(curArg, _k - 4)))
  1051. {
  1052. break;
  1053. }
  1054. }
  1055. if (funcidx(func) == -1)
  1056. {
  1057. // Normal version. This is ended by a null.
  1058. // Other functions get the count in advance when
  1059. // an index of -1 is passed.
  1060. func[2] = 'r';
  1061. // This code mimicks much of the internal
  1062. // y_master code because wrapping this in a
  1063. // macro is a) pointless and b) hard. This code
  1064. // is ALWAYS like this because of the nature of
  1065. // it.
  1066. new
  1067. lst = setproperty(8, YSIM_CALLER),
  1068. _j = 0;
  1069. setproperty(8, YSIM_CALLER, _@);
  1070. for ( ; ; )
  1071. {
  1072. CallRemoteFunction(func, "ii", _:l, _j);
  1073. // Resolve the string.
  1074. getproperty(8, "", YSIM_STRING, Q@);
  1075. strunpack(Q@, Q@);
  1076. if (Q@[0])
  1077. {
  1078. if (_j)
  1079. {
  1080. // Separate the strings - hard coded
  1081. // list format currently I'm afraid.
  1082. //ts = ", ";
  1083. //Y_RENDER_ADD(ts)
  1084. Y_RENDER_ADD(YSI_g_sListSep)
  1085. }
  1086. format(ts, sizeof (ts), scSpecifier, width, prec, Q@);
  1087. Y_RENDER_ADD(ts)
  1088. }
  1089. else
  1090. {
  1091. break;
  1092. }
  1093. ++_j;
  1094. }
  1095. setproperty(8, YSIM_CALLER, lst);
  1096. }
  1097. else
  1098. {
  1099. // Player specific version.
  1100. // Normal version. This is ended by a null.
  1101. // Other functions get the count in advance when
  1102. // an index of -1 is passed.
  1103. //func[2] = 'r';
  1104. // This code mimicks much of the internal
  1105. // y_master code because wrapping this in a
  1106. // macro is a) pointless and b) hard. This code
  1107. // is ALWAYS like this because of the nature of
  1108. // it.
  1109. new
  1110. lst = setproperty(8, YSIM_CALLER),
  1111. _j = 0;
  1112. setproperty(8, YSIM_CALLER, _@);
  1113. for ( ; ; )
  1114. {
  1115. CallRemoteFunction(func, "iii", pid, _:l, _j);
  1116. // Resolve the string.
  1117. getproperty(8, "", YSIM_STRING, Q@);
  1118. strunpack(Q@, Q@);
  1119. if (Q@[0])
  1120. {
  1121. if (_j)
  1122. {
  1123. // Separate the strings - hard coded
  1124. // list format currently I'm afraid.
  1125. //ts = ", ";
  1126. //Y_RENDER_ADD(ts)
  1127. Y_RENDER_ADD(YSI_g_sListSep)
  1128. }
  1129. // Could do with configuring this to not
  1130. // need to call "Y_RENDER_SPECIFIER" every
  1131. // time.
  1132. format(ts, sizeof (ts), scSpecifier, width, prec, Q@);
  1133. Y_RENDER_ADD(ts)
  1134. }
  1135. else
  1136. {
  1137. break;
  1138. }
  1139. ++_j;
  1140. }
  1141. setproperty(8, YSIM_CALLER, lst);
  1142. // Force the string to be rebuilt every time.
  1143. ++one;
  1144. }
  1145. }
  1146. else
  1147. {
  1148. // Single parameter. Can do this FAR better by just
  1149. // using #emit to re-push the parameter directly.
  1150. for (new _k = 0; _k != sizeof (ts); ++_k)
  1151. {
  1152. if (!(ts[_k] = getarg(curArg, _k)))
  1153. {
  1154. break;
  1155. }
  1156. }
  1157. format(ts, sizeof (ts), scSpecifier, width, prec, ts);
  1158. Y_RENDER_ADD(ts)
  1159. }
  1160. ++curArg;
  1161. }
  1162. /*case e_COMPRESS_FORMAT_DATA_OCT:
  1163. {
  1164. Y_RENDER_ARG
  1165. {
  1166. //p += Format_AddInt(output[p], llen, arg, width, ch);
  1167. //format(ts, sizeof (ts), Y_RENDER_SPECIFIER(f), width, prec, arg);
  1168. ts[Format_AddOct(ts, sizeof (ts) - 1, arg, width, ch)] = '\0';
  1169. Y_RENDER_ADD(ts)
  1170. }
  1171. }*/
  1172. case e_COMPRESS_FORMAT_DATA_COMM:
  1173. {
  1174. scSpecifier = Y_RENDER_SPECIFIER(s);
  1175. // Show a command.
  1176. /*for(new _i=0,_b=4;_i!=2;++_i)
  1177. if(_i==0)
  1178. {
  1179. if(ch&_:e_COMPRESS_FORMAT_DATA_FUNC)
  1180. {
  1181. _b=1,func="@yR_";
  1182. for(new _k=4;_k!=32;++_k)
  1183. if(!(func[_k]=getarg(curArg,_k-4)))
  1184. break;
  1185. if(funcidx(func)==-1)func[2]='r',_b=2;
  1186. }
  1187. else if(ch&_:e_COMPRESS_FORMAT_DATA_LIST)
  1188. _b=3;
  1189. }
  1190. else
  1191. for(new _j=0;(arg=_b==1?W@(func,"iii",pid,(_:l),_j):_b==2?W@(func,"ii",(_:l),_j):_b==3?getarg(curArg,_j++):getarg(curArg)),(_j!=-1&&_b)?TRUE:++curArg&&FALSE;_b=_b==4?0:_b)*/
  1192. Y_RENDER_ARG
  1193. {
  1194. //p += Format_AddInt(output[p], llen, arg, width, ch);
  1195. //format(ts, sizeof (ts), Y_RENDER_SPECIFIER(f), width, prec, arg);
  1196. // "arg" has the ID of the command, not the NAME of
  1197. // the command which may change for different people
  1198. // (need to find a way to return a single name for a
  1199. // player which gets to the specified command).
  1200. #if defined _inc_y_commands
  1201. strcpy(ts, Command_GetDisplay(arg, pid));
  1202. if (ts[0])
  1203. {
  1204. format(ts, sizeof (ts), scSpecifier, width, prec, ts);
  1205. Y_RENDER_ADD(ts)
  1206. }
  1207. #endif
  1208. //ts[Format_AddOct(ts, sizeof (ts) - 1, arg, width, ch)] = '\0';
  1209. //Y_RENDER_ADD(ts)
  1210. }
  1211. }
  1212. /*case e_COMPRESS_FORMAT_DATA_SUFFIX:
  1213. {
  1214. scSpecifier = Y_RENDER_SPECIFIER(s);
  1215. // TODO: Add language to this.
  1216. //p += Format_AddSuffix(output[p], llen, getarg(curArg++), l);
  1217. Y_RENDER_ARG
  1218. {
  1219. format(ts, sizeof (ts), scSpecifier, width, cellmax, Format_AddSuffix(arg, l));
  1220. Y_RENDER_ADD(ts)
  1221. }
  1222. }
  1223. case e_COMPRESS_FORMAT_DATA_UNSIGNED:
  1224. {
  1225. if (prec < 0) prec = 10;
  1226. Y_RENDER_ARG
  1227. {
  1228. //p += Format_AddInt(output[p], llen, arg, width, ch);
  1229. //format(ts, sizeof (ts), Y_RENDER_SPECIFIER(f), width, prec, arg);
  1230. //ts[Format_AddOct(ts, sizeof (ts) - 1, arg, width, ch)] = '\0';
  1231. ts[Format_AddNum(ts, sizeof (ts) - 1, arg, width, ch, prec, false)] = '\0';
  1232. Y_RENDER_ADD(ts)
  1233. }
  1234. }
  1235. case e_COMPRESS_FORMAT_DATA_SIGNED:
  1236. {
  1237. if (prec < 0) prec = 10;
  1238. Y_RENDER_ARG
  1239. {
  1240. //p += Format_AddInt(output[p], llen, arg, width, ch);
  1241. //format(ts, sizeof (ts), Y_RENDER_SPECIFIER(f), width, prec, arg);
  1242. ts[Format_AddNum(ts, sizeof (ts) - 1, arg, width, ch, prec, true)] = '\0';
  1243. Y_RENDER_ADD(ts)
  1244. }
  1245. }*/
  1246. case e_COMPRESS_FORMAT_DATA_PLAYER:
  1247. {
  1248. Y_RENDER_ARG
  1249. {
  1250. //p += Format_AddInt(output[p], llen, arg, width, ch);
  1251. GetPlayerName(arg, ts, sizeof (ts));
  1252. format(ts, sizeof (ts), scSpecifier, width, prec, ts);
  1253. Y_RENDER_ADD(ts)
  1254. }
  1255. }
  1256. case e_COMPRESS_FORMAT_DATA_LOGICAL:
  1257. {
  1258. scSpecifier = Y_RENDER_SPECIFIER(s);
  1259. Y_RENDER_ARG
  1260. {
  1261. //p += Format_AddInt(output[p], llen, arg, width, ch);
  1262. format(ts, sizeof (ts), scSpecifier, width, prec, arg ? ("true") : ("false"));
  1263. Y_RENDER_ADD(ts)
  1264. }
  1265. }
  1266. case e_COMPRESS_FORMAT_DATA_CUSTOM:
  1267. {
  1268. // Get the function we will be calling to do the format.
  1269. // Slice caches these, but we don't because of the
  1270. // extended versions (%k<DATE>) etc.
  1271. new
  1272. ffake[4 char],
  1273. fidx;
  1274. ffake[0] = string[idx];
  1275. if (ffake{1} == '@')
  1276. {
  1277. if (!AMX_GetPublicPointer(0, fidx, ffake))
  1278. {
  1279. continue;
  1280. }
  1281. ++idx;
  1282. }
  1283. else
  1284. {
  1285. static
  1286. sFunc2[32] = "F";
  1287. strunpack(sFunc2[1], string[idx], sizeof (sFunc2) - 1);
  1288. // Limit the function name to the function length.
  1289. sFunc2[sFunc2[1]] = '\0';
  1290. idx += ceildiv(sFunc2[1], 4);
  1291. sFunc2[1] = '@';
  1292. if (!AMX_GetPublicPointer(0, fidx, sFunc2))
  1293. {
  1294. continue;
  1295. }
  1296. }
  1297. //
  1298. // "b":
  1299. //
  1300. // "b" is the source type. "1" = function, "2" = per-
  1301. // player function, "3" = list, "4" = variable. "0" is
  1302. // a special case meaning "processed variable" and tells
  1303. // the system to stop "j != -1 && b".
  1304. //
  1305. // "i":
  1306. //
  1307. // "i" is the current processing stage - there are two.
  1308. // The first looks at all the arguments and collects the
  1309. // function or list data (if any). The second loops
  1310. // over all the passed arguments and does the format.
  1311. // This is where the "b" check comes in, to only do that
  1312. // inner loop once. It is done this way simply to allow
  1313. // us to use braces around the code to do the format.
  1314. //
  1315. // "j":
  1316. //
  1317. // "j" is the main loop variable for the inner loop and
  1318. // tracks which parameter part we are currently doing in
  1319. // the case of function or list inputs.
  1320. //
  1321. for (new i, j, b = 4; i != 2; ++i)
  1322. {
  1323. if (!i)
  1324. {
  1325. if (ch & _:e_COMPRESS_FORMAT_DATA_FUNC)
  1326. {
  1327. b = 1;
  1328. func = "@yR_";
  1329. va_getstring(func[4], curArg);
  1330. if (funcidx(func) == -1)
  1331. {
  1332. b = 2;
  1333. func[2] = 'r';
  1334. }
  1335. }
  1336. else if (ch & _:e_COMPRESS_FORMAT_DATA_LIST)
  1337. {
  1338. b = 3;
  1339. }
  1340. ch &= FORMAT_FLAG_LEFT | FORMAT_FLAG_ZERO;
  1341. }
  1342. else
  1343. {
  1344. for (;
  1345. // These lines ALWAYS get run because
  1346. // they come before a comma in the "for"
  1347. // conditional, but their result is
  1348. // ignored.
  1349. (arg = (b == 1)
  1350. ? W@(func, "iii", pid, (_:l), j)
  1351. : (b == 2)
  1352. ? W@(func, "ii", (_:l), j)
  1353. : (b == 3)
  1354. ? getarg(curArg, j++)
  1355. : getarg(curArg)
  1356. ),
  1357. // This is the true condition. If the
  1358. // first half fails then "curArg" is
  1359. // incremented and the whole check
  1360. // fails, otherwise, thanks to short-
  1361. // circuiting, "curArg" is NOT
  1362. // incremented.
  1363. (arg != cellmin && b) || (++curArg & 0);
  1364. // Only run the loop once when "b = 4".
  1365. b &= ~4, ++j
  1366. )
  1367. {
  1368. // Standard format code goes here.
  1369. #emit PUSH.S prec
  1370. #emit PUSH.S width
  1371. #emit PUSH.S ch
  1372. // Get the source (assume constant for now,
  1373. // i.e. no functions or lists yet).
  1374. #emit PUSH.S arg
  1375. // Get a string if there is one.
  1376. if (b == 1 || b == 2)
  1377. {
  1378. getproperty(8, "", YSIM_STRING, Q@);
  1379. strunpack(Q@, Q@);
  1380. if (isnull(Q@))
  1381. {
  1382. ++curArg;
  1383. // Fix the stack.
  1384. #emit POP.pri
  1385. #emit POP.pri
  1386. #emit POP.pri
  1387. #emit POP.pri
  1388. break;
  1389. }
  1390. #emit PUSH.C Q@
  1391. }
  1392. else
  1393. {
  1394. #emit LCTRL 5
  1395. #emit LOAD.S.alt curArg
  1396. #emit SHL.C.alt 2
  1397. #emit ADD
  1398. #emit LOAD.I
  1399. #emit PUSH.pri
  1400. }
  1401. #emit PUSH.C ts
  1402. // Far more parameters that Slice's.
  1403. #emit PUSH.C 24 // 4 * 6.
  1404. // This code is almost common now!
  1405. #emit LCTRL 6
  1406. #emit ADD.C 28
  1407. #emit PUSH.pri
  1408. #emit LOAD.S.pri fidx
  1409. #emit SCTRL 6
  1410. // Now we have returned from the custom
  1411. // function.
  1412. Y_RENDER_ADD(ts)
  1413. }
  1414. }
  1415. }
  1416. }
  1417. /*case e_COMPRESS_FORMAT_DATA_DATE:
  1418. {
  1419. // Hard one - needs more interaction.
  1420. }*/
  1421. }
  1422. }
  1423. case '\03', -1:
  1424. {
  1425. P:6("Text_Render: Colour %d %d %d %d %d %06x %s", p, llen, fadeStart, fakePos, idx, colour & 0xFFFFFF, string);
  1426. if (fade) //flags & 4)
  1427. {
  1428. p = fadeStart;
  1429. new
  1430. rem = Format_DoEndFade(output, p, fakePos, llen, string[idx], colour);
  1431. if (rem || nlInFade) //(flags & 2))
  1432. {
  1433. // "rem" is the number of characters not processed.
  1434. YSI_g_sFadeColour = colour;
  1435. Y_RENDER_DO_DISPLAY()
  1436. P:6("Format_Render: one stage: \"%s\"", output);
  1437. // Subtract 2 to get the index in to the fade where the
  1438. // letters start. This is not as easy as it used to be
  1439. // as we need to manipulate the stack to push the extra
  1440. // parameters somehow. Now changed to a fake tail-
  1441. // recursive call so that we don't need to worry about
  1442. // the stack. This also explains why labels generate
  1443. // extra stack manipulation code (to reset locals).
  1444. //return Format_Render(pid, l, output, maxlen, fadeStartIdx, fakePos - fadeStart - rem | e_FORMAT_FLAGS_REDO, string);
  1445. //#emit LOAD.S.pri fadeStartText
  1446. //#emit STOR.S.pri string
  1447. idx = fadeStartIdx;
  1448. target = (fakePos - fadeStart - rem) | e_FORMAT_FLAGS_REDO;
  1449. gInitialColour = colour;
  1450. //YSI_g_sTempStyle[E_STYLE_DATA_COLOUR] = (YSI_g_sTempStyle[E_STYLE_DATA_COLOUR] & 0xF000000F) | (gInitialColour << 4);
  1451. goto Format_Render_start;
  1452. // We don't need these as they are only set when you
  1453. // want less than 2 displays, and as to get to this
  1454. // point you need to have shown at least noe item there
  1455. // is no possible way they can be set the second time.
  1456. //| (onlyOne ? e_FORMAT_FLAGS_ONE : 0) | (none ? e_FORMAT_FLAGS_NONE : 0);
  1457. }
  1458. //flags &= ~4;
  1459. fade = false;
  1460. fakePos += p - fadeStart;
  1461. }
  1462. if (string[idx] & Y_FORMAT_CLOSE_CURR)
  1463. {
  1464. // Get the initial display colour.
  1465. //string[idx] |= (YSI_g_sTempStyle[E_STYLE_DATA_COLOUR] >>> 4) & 0x00FFFFFF;
  1466. string[idx] = (string[idx] & 0xFF000000) | ((YSI_g_sTempStyle[E_STYLE_DATA_COLOUR] >>> 4) & 0x00FFFFFF);
  1467. }
  1468. if (string[idx] & Y_FORMAT_START_FADE)
  1469. {
  1470. //flags |= 4;
  1471. fade = true;
  1472. fadeStart = p;
  1473. fadeStartIdx = idx - 1;
  1474. string[fadeStartIdx] = -1;
  1475. //#emit LOAD.S.pri string
  1476. //#emit STOR.S.pri fadeStartText
  1477. if (p < maxlen - 1)
  1478. {
  1479. output[p++] = '\03';
  1480. output[p++] = string[idx++];
  1481. }
  1482. }
  1483. else
  1484. {
  1485. // Just add the colour here normally.
  1486. arg = Format_AddColour(output, p, llen, colour, string[idx++]); //& ~(Y_FORMAT_START_FADE | Y_FORMAT_ALWAYS_SET));
  1487. switch (arg)
  1488. {
  1489. case -1:
  1490. {
  1491. Y_RENDER_DO_DISPLAY()
  1492. }
  1493. case 0:
  1494. {
  1495. // Do nothing.
  1496. }
  1497. default:
  1498. {
  1499. p += arg;
  1500. fakePos += arg;
  1501. }
  1502. }
  1503. /*else
  1504. {
  1505. p += arg;
  1506. }
  1507. currentColour = string[idx++];
  1508. if (maxlen - pos > Y_RENDER_SCM_COLOUR_LEN)
  1509. {
  1510. format(output[pos], maxlen - pos, "{%06x}", currentColour & ~(Y_FORMAT_START_FADE | Y_FORMAT_ALWAYS_SET));
  1511. pos += Y_RENDER_SCM_COLOUR_LEN;
  1512. }
  1513. else
  1514. {
  1515. output[pos] = '\0';
  1516. printf("some stage: \"%s\"", output);
  1517. output[0] = '\0';
  1518. pos = 0;
  1519. }*/
  1520. //++idx;
  1521. }
  1522. }
  1523. case '\04':
  1524. {
  1525. P:6("Text_Render: Key");
  1526. ++idx;
  1527. }
  1528. case '\05':
  1529. {
  1530. // String extension.
  1531. P:6("Text_Render: Extension %d %d %d", YSI_g_sTempMaster, string[idx], string[idx - 1]);
  1532. // TODO!
  1533. // This should change the current input to a new one. May
  1534. // require some more advanced hacking to support fades over
  1535. // these boundaries (or just ban them)... Actually, I don't
  1536. // think it will require extra work...
  1537. // Just use the text directly.
  1538. idx = _Text_GetPointer(YSI_g_sTempMaster, string[idx]);
  1539. #emit LOAD.S.pri idx
  1540. #emit STOR.S.pri string
  1541. idx = 0;
  1542. }
  1543. case '\n':
  1544. {
  1545. P:6("Text_Render: NL");
  1546. // Check for 2 character new lines (\n\r).
  1547. if (string[idx] == '\r') ++idx;
  1548. // Output the last string.
  1549. if (fade) //flags & 4)
  1550. {
  1551. //flags |= 2;
  1552. nlInFade = true;
  1553. state y_render_fade : y_render_fade_fake;
  1554. }
  1555. else if ((YSI_g_sTempStyle[E_STYLE_DATA_TYPE] & e_STYLE_TYPE_MASK) < e_STYLE_TYPE_CLIENT)
  1556. {
  1557. // This works even for GTs which are always 0 by this point.
  1558. Y_RENDER_ADD(scNewLineString)
  1559. }
  1560. else if (YSI_g_sTempStyle[E_STYLE_DATA_TYPE] == e_STYLE_TYPE_DIALOG)
  1561. {
  1562. //printf("NL 1");
  1563. // This works even for GTs which are always 0 by this point.
  1564. Y_RENDER_ADD(scDialogLineString)
  1565. //printf("NL 2");
  1566. }
  1567. else
  1568. {
  1569. Y_RENDER_DO_DISPLAY()
  1570. }
  1571. }
  1572. case '\r':
  1573. {
  1574. P:6("Text_Render: NL");
  1575. // Check for 2 character new lines (\r\n).
  1576. if (string[idx] == '\n') ++idx;
  1577. // Output the last string.
  1578. if (fade) //flags & 4)
  1579. {
  1580. //flags |= 2;
  1581. nlInFade = true;
  1582. state y_render_fade : y_render_fade_fake;
  1583. }
  1584. else if ((YSI_g_sTempStyle[E_STYLE_DATA_TYPE] & e_STYLE_TYPE_MASK) < e_STYLE_TYPE_CLIENT)
  1585. {
  1586. // This works even for GTs which are always 0 by this point.
  1587. Y_RENDER_ADD(scNewLineString)
  1588. }
  1589. else if (YSI_g_sTempStyle[E_STYLE_DATA_TYPE] == e_STYLE_TYPE_DIALOG)
  1590. {
  1591. // This works even for GTs which are always 0 by this point.
  1592. //printf("NL 3");
  1593. Y_RENDER_ADD(scDialogLineString)
  1594. //printf("NL 4");
  1595. }
  1596. else
  1597. {
  1598. Y_RENDER_DO_DISPLAY()
  1599. }
  1600. }
  1601. case '\t':
  1602. {
  1603. // Somehow display a tab. Maybe keep track of characters
  1604. // displayed and show "n % 4" spaces.
  1605. arg = 4 - (p & 0x03); // The number of spaces to add.
  1606. static
  1607. sTabs[] = " ";
  1608. for (new __added; (__added = Format_DoAddString(output, sTabs[4 - arg], p, arg, llen, fakePos)); arg -= __added)
  1609. {
  1610. if (fade) //flags & 4)
  1611. {
  1612. state y_render_fade : y_render_fade_fake;
  1613. }
  1614. else
  1615. {
  1616. Y_RENDER_DO_DISPLAY()
  1617. }
  1618. }
  1619. }
  1620. case '\06' .. '\08', '\11', '\12', '\14' .. '\32':
  1621. {
  1622. // Whitespace. Just show a space, not the fancy character, no
  1623. // idea what it could do. Note that this range includes spaces.
  1624. P:6("Text_Render: Space");
  1625. Y_RENDER_CHAR(' ')
  1626. }
  1627. default:
  1628. {
  1629. P:6("Text_Render: Char");
  1630. Y_RENDER_CHAR(ch)
  1631. }
  1632. }
  1633. /*if (!(ch = string[idx]))
  1634. {
  1635. break;
  1636. }
  1637. // Copy strings.
  1638. ++idx;
  1639. Y_RENDER_ADD_EX(string, idx, ch - idx)
  1640. idx = ch;*/
  1641. P:6("Text_Render: Loop: p = %d, llen = %d, output = \"%s\"", p, llen, (output[p] = '\0', output));
  1642. }
  1643. P:5("Text_Render: Final render?");
  1644. if (p)
  1645. {
  1646. P:5("Text_Render: Yes!");
  1647. output[p] = '\0';
  1648. if (!none) Format_DoDisplay(pid, gInitialColour, output);
  1649. ++one;
  1650. }
  1651. P:5("Text_Render: p = %d, output = \"%s\"", p, output);
  1652. P:C(idx=0;while ((ch = output[idx++]))printf("%04x%04x = %c", ch >>> 16, ch & 0xFFFF, ch););
  1653. P:5("Text_Render end");
  1654. return one;
  1655. }