y_text_render.inc 54 KB

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