1
0

y_textrender.inc 53 KB

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