y_text.inc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. #if defined _inc_y_text
  2. #undef _inc_y_text
  3. #endif
  4. // Multiple includes!
  5. #include "..\YSI_Internal\y_unique"
  6. // Need an include guard here.
  7. #if defined _INC_y_text
  8. #endinput
  9. #endif
  10. #define _INC_y_text
  11. /**
  12. * <library name="y_text">
  13. * <section>
  14. * Description
  15. * </section>
  16. * Provides interfaces for displaying text from anywhere by way of native like
  17. * functions using text indexes rather than text. Due to a compile problem a
  18. * number of the stock functions should be static but can't be.
  19. * <section>
  20. * Version
  21. * </section>
  22. * 0.1.1
  23. * <section>
  24. * Functions
  25. * </section>
  26. * <subsection>
  27. * Public
  28. * </subsection><ul>
  29. * <symbol name="Text_ResetAll">Resets the entire text system.</symbol>
  30. * <symbol name="Text_NewLanguage">Sets up to parse a new language.</symbol>
  31. * <symbol name="Text_Parse">Sorts loaded text into a binary tree.</symbol>
  32. * <symbol name="Text_DataSave_data">Saves text appearence data.</symbol>
  33. * <symbol name="Text_DataSave_colours">Saves file colour defines.</symbol>
  34. * <symbol name="Text_DataSave_colors">Wrapper for above function.</symbol>
  35. * </ul><subsection>
  36. * Stock
  37. * </subsection><ul>
  38. * <symbol name="Text_FindTextPointers">Should be static but can't be :(.</symbol>
  39. * <symbol name="Text_AddToBuffer">Saves all passed text for processing.</symbol>
  40. * <symbol name="Text_GetTextFromIndex">Gets text from an array pointer and language.</symbol>
  41. * <symbol name="Text_GetErrorMessage">Gets an unfound message.</symbol>
  42. * <symbol name="Text_GetTextStyle">Gets text's style.</symbol>
  43. * <symbol name="Text_GetTextColour">Gets text's colour.</symbol>
  44. * <symbol name="Text_GetTextTime">Gets text's time.</symbol>
  45. * <symbol name="Text_Send">Sends a message to a player.</symbol>
  46. * <symbol name="Text_SendToAll">Sends a message to all players.</symbol>
  47. * <symbol name="Text_SendToGroup">Sends a message to a defined group.</symbol>
  48. * <symbol name="Text_SendToPlayers">Sends a message to a passed group.</symbol>
  49. * <symbol name="Text_Display">Display an actual string to a player in a given style.</symbol>
  50. * </ul><subsection>
  51. * Static
  52. * </subsection><ul>
  53. * <symbol name="Text_AddText">Adds text to the tree after sorting.</symbol>
  54. * </ul><subsection>
  55. * Inline
  56. * </subsection><ul>
  57. * <symbol name="Text_Text">Constructor - Calls Text_ResetAll.</symbol>
  58. * <symbol name="Text_SetLangPointer">Sets the pointer for a language to a position.</symbol>
  59. * <symbol name="Text_ResetLangPointers">Resets all the pointers for one language.</symbol>
  60. * <symbol name="Text_GetPlayerLanguage">Gets a players language.</symbol>
  61. * <symbol name="Text_GetText">Gets text from an identifier and language.</symbol>
  62. * <symbol name="Text_GetPlayerText">Gets text from an identifier and playerid.</symbol>
  63. * <symbol name="Text_SendFormat">Sends a formatted message to a player.</symbol>
  64. * <symbol name="Text_SendToAllFormat">Sends a formatted message to all players.</symbol>
  65. * <symbol name="Text_SendToGroupFormat">Sends a formatted message to a defined group.</symbol>
  66. * <symbol name="Text_SendToPlayersFormat">Sends a formatted message to a passed group.</symbol>
  67. * </ul><section>
  68. * Definitions
  69. * </section><ul>
  70. * <symbol name="MAX_TEXT_NAME">Maximum length of a text identifier.</symbol>
  71. * <symbol name="MAX_TEXT_ENTRY">Maximum length of a text string.</symbol>
  72. * <symbol name="TEXT_NO_TEXT">Value for no text for that language.</symbol>
  73. * <symbol name="TEXT_NO_POINTERS">Value for no text found.</symbol>
  74. * <symbol name="TEXT_TYPE_CLIENT">Flag for sending a client formatted message (unused).</symbol>
  75. * <symbol name="TEXT_TYPE_GAME">Flag for sending a game text formatted message (unused).</symbol>
  76. * <symbol name="MAX_TEXT_COLOURS">Max number of defined colours in an ini file.</symbol>
  77. * </ul><section>
  78. * Enums
  79. * </section><ul>
  80. * <symbol name="E_TEXT_POINTERS">Structure of the language pointer array.</symbol>
  81. * </ul><section>
  82. * Macros
  83. * </section><ul>
  84. * <symbol name="Text_RegisterTag">Placed as a function, calls Text_AddToBuffer for tags.</symbol>
  85. * </ul><section>
  86. * Variables
  87. * </section>
  88. * <subsection>
  89. * Static
  90. * </subsection><ul>
  91. * <symbol name="YSI_g_sTextTable">Array of all text entries.</symbol>
  92. * <symbol name="YSI_g_sNameTable">Array of all text names and language pointers.</symbol>
  93. * <symbol name="YSI_g_sSearchTree">Binary tree of text hashes.</symbol>
  94. * <symbol name="YSI_g_sTextInited">Flag for text binary sorted.</symbol>
  95. * <symbol name="YSI_g_sBufferIndex">Index of next text slot for the current language.</symbol>
  96. * <symbol name="YSI_g_sTextCount">Count of largest number of texts in one language.</symbol>
  97. * <symbol name="YSI_g_sBufferLang">Current language being loaded.</symbol>
  98. * <symbol name="YSI_g_sLangBuffer">Saves the current position of each language.</symbol>
  99. * <symbol name="YSI_g_sColours">Saves defined colours for use.</symbol>
  100. * </ul>
  101. * </library>
  102. *//** *//*
  103. Legal:
  104. Version: MPL 1.1
  105. The contents of this file are subject to the Mozilla Public License Version
  106. 1.1 the "License"; you may not use this file except in compliance with
  107. the License. You may obtain a copy of the License at
  108. http://www.mozilla.org/MPL/
  109. Software distributed under the License is distributed on an "AS IS" basis,
  110. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  111. for the specific language governing rights and limitations under the
  112. License.
  113. The Original Code is the YSI framework.
  114. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  115. Portions created by the Initial Developer are Copyright C 2011
  116. the Initial Developer. All Rights Reserved.
  117. Contributors:
  118. Y_Less
  119. koolk
  120. JoeBullet/Google63
  121. g_aSlice/Slice
  122. Misiur
  123. samphunter
  124. tianmeta
  125. maddinat0r
  126. spacemud
  127. Crayder
  128. Dayvison
  129. Ahmad45123
  130. Zeex
  131. irinel1996
  132. Yiin-
  133. Chaprnks
  134. Konstantinos
  135. Masterchen09
  136. Southclaws
  137. PatchwerkQWER
  138. m0k1
  139. paulommu
  140. udan111
  141. Thanks:
  142. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  143. ZeeX - Very productive conversations.
  144. koolk - IsPlayerinAreaEx code.
  145. TheAlpha - Danish translation.
  146. breadfish - German translation.
  147. Fireburn - Dutch translation.
  148. yom - French translation.
  149. 50p - Polish translation.
  150. Zamaroht - Spanish translation.
  151. Los - Portuguese translation.
  152. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
  153. me to strive to better.
  154. Pixels^ - Running XScripters where the idea was born.
  155. Matite - Pestering me to release it and using it.
  156. Very special thanks to:
  157. Thiadmer - PAWN, whose limits continue to amaze me!
  158. Kye/Kalcor - SA:MP.
  159. SA:MP Team past, present and future - SA:MP.
  160. Optional plugins:
  161. Gamer_Z - GPS.
  162. Incognito - Streamer.
  163. Me - sscanf2, fixes2, Whirlpool.
  164. */
  165. #include <a_samp>
  166. #include "..\YSI_Internal\y_version"
  167. // Make sure this is included early.
  168. #include "..\YSI_Data\y_playerset"
  169. // Apparently I'd already written the internal code to support this and forgot!
  170. #define Y_TEXT_UNIQUE
  171. #if !defined Y_TEXT_MAX_SETS
  172. #define Y_TEXT_MAX_SETS (16)
  173. #endif
  174. #if !defined Y_TEXT_PER_SET
  175. #define Y_TEXT_PER_SET (64)
  176. #endif
  177. #if !defined MAX_TEXT_ENTRIES
  178. #define MAX_TEXT_ENTRIES (Y_TEXT_PER_SET * Y_TEXT_MAX_SETS)
  179. #endif
  180. #include "..\YSI_Internal\y_version"
  181. #include "..\YSI_Storage\y_xml"
  182. #include "..\YSI_Server\y_td"
  183. #include "..\YSI_Server\y_colours"
  184. //#include "..\y_hooks"
  185. #include "..\YSI_Internal\y_natives"
  186. #include "y_text/styles"
  187. // This is a horribly eclectic collection of libraries from all over the place
  188. // and written at different times with different aims - frankly I'll be AMAZED
  189. // if it all comes together and works.
  190. #include <a_samp>
  191. #include "..\YSI_Core\y_debug"
  192. #include "..\YSI_Server\y_colours"
  193. #include "y_text/load"
  194. #include "..\YSI_Core\y_utils"
  195. #include "..\YSI_Internal\y_shortfunc"
  196. #include "..\YSI_Internal\y_natives"
  197. #include "..\YSI_Coding\y_va"
  198. #include "y_text/render"
  199. #include "..\YSI_Storage\y_amx"
  200. #include "..\YSI_Storage\y_ini"
  201. #include "..\YSI_Data\y_iterate"
  202. #include "..\YSI_Server\y_scriptinit"
  203. #include "..\YSI_Players\y_languages"
  204. #include "..\YSI_Visual\y_dialog"
  205. #include "..\YSI_Coding\y_inline"
  206. #include "..\YSI_Coding\y_hooks"
  207. #include "y_text/impl"
  208. #define UNDO_MOVE|||
  209. #define DO_MOVE|||%0``` %0DO_MOVE|||
  210. #define Text_Send(%0,%1) PSF:_Text_Send(%0,DO_TEXT_SET:%1 UNDO_MOVE|||)
  211. #define Text_Render(%0,%1) _Text_Render(%0,DO_TEXT_SET:%1 UNDO_MOVE|||)
  212. #define Text_Format(%0,%1,%2,%3,%4) _Text_Format(%0,%1,%2,%3,DO_TEXT_SET:%4 UNDO_MOVE|||)
  213. #define Text_Format_GT_0(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_GT_0,%3)
  214. #define Text_Format_GT_1(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_GT_1,%3)
  215. #define Text_Format_GT_2(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_GT_2,%3)
  216. #define Text_Format_GT_3(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_GT_3,%3)
  217. #define Text_Format_GT_4(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_GT_4,%3)
  218. #define Text_Format_GT_5(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_GT_5,%3)
  219. #define Text_Format_GT_6(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_GT_6,%3)
  220. #define Text_Format_TD(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_TD,%3)
  221. #define Text_Format_3D(%0,%1,%2,%3 Text_Format(%0,%1,%2, e_STYLE_TYPE_3D,%3)
  222. #define Text_Format_Client(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_CLIENT,%3)
  223. #define Text_Format_Player(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_PLAYER,%3)
  224. #define Text_Format_Other(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_OTHER,%3)
  225. #define Text_Format_Dialog(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_DIALOG,%3)
  226. //#define _Text_Send(%0YCMD:%1) _Text_Send(%0_:YCMD_REP_0:YCMD_REP_1:%1)
  227. //#define YCMD_REP_0:YCMD_REP_1:%0, Command_GetID(%0),
  228. //#define YCMD_REP_1:%0) Command_GetID(%0))
  229. // This code allows "DEFAULT_TEXT_SET" to propogate through the text one section
  230. // at a time without detecting later matches too early. The design of "DO_MOVE"
  231. // and "UNDO_MOVE" means that the compiler will correctly detect the end of the
  232. // code, regardless of the length, and end.
  233. #define Text_MessageBox(%0,%1,%2,%3,%4,%5) PSF:_Text_DialogBox(%0,DIALOG_STYLE_MSGBOX,%1,DO_TEXT_SET:%2 DO_MOVE|||,DO_TEXT_SET:%3 ```,DO_TEXT_SET:%4 ```,DO_TEXT_SET:%5 UN```)
  234. #define Text_InputBox(%0,%1,%2,%3,%4,%5) PSF:_Text_DialogBox(%0,DIALOG_STYLE_INPUT,%1,DO_TEXT_SET:%2 DO_MOVE|||,DO_TEXT_SET:%3 ```,DO_TEXT_SET:%4 ```,DO_TEXT_SET:%5 UN```)
  235. #define Text_ListBox(%0,%1,%2,%3,%4,%5) PSF:_Text_DialogBox(%0,DIALOG_STYLE_LIST,%1,DO_TEXT_SET:%2 DO_MOVE|||,DO_TEXT_SET:%3 ```,DO_TEXT_SET:%4 ```,DO_TEXT_SET:%5 UN```)
  236. #define Text_PasswordBox(%0,%1,%2,%3,%4,%5) PSF:_Text_DialogBox(%0,DIALOG_STYLE_PASSWORD,%1,DO_TEXT_SET:%2 DO_MOVE|||,DO_TEXT_SET:%3 ```,DO_TEXT_SET:%4 ```,DO_TEXT_SET:%5 UN```)
  237. #define Text_DialogBox(%0,%9,%1,%2,%3,%4,%5) PSF:_Text_DialogBox(%0,%9,%1,DO_TEXT_SET:%2 DO_MOVE|||,DO_TEXT_SET:%3 ```,DO_TEXT_SET:%4 ```,DO_TEXT_SET:%5 UN```)
  238. //#define Text_MessageBox(%0,%1,%2,%3) PSF:_Text_MessageBox(%0,%1,DEFAULT_TEXT_SET,#%2 DO_MOVE|||,DEFAULT_TEXT_SET,#%3 $$$,DEFAULT_TEXT_SET,#%4 $$$,DEFAULT_TEXT_SET,#%5 UN$$$)
  239. //#define _Text_MessageBox(%0YCMD:%1) _Text_MessageBox(%0_:YCMD_REP_0:YCMD_REP_1:%1)
  240. //stock Text_GetAllIDs(
  241. stock formatex(output[], len, const format[], GLOBAL_TAG_TYPES:...)
  242. {
  243. static
  244. sFormat[1024],
  245. sTemp[1024];
  246. // "Format_Standardise" modifies "input" repeatedly.
  247. //strcpy(sTemp, format);
  248. strcpy(sFormat, format);
  249. Format_Standardise(sFormat, sTemp);
  250. new
  251. n = (numargs() - 3) * 4;
  252. if (n)
  253. {
  254. // Push all passed parameters.
  255. new
  256. arg_start,
  257. arg_end;
  258. // Load the real address of the last static parameter. Do this by
  259. // loading the address of the parameter and then adding the value of
  260. // [FRM] (frame pointer).
  261. #emit CONST.alt format
  262. #emit LCTRL 5
  263. #emit ADD
  264. #emit STOR.S.pri arg_start
  265. // Load the address of the last variable parameter. Do this by adding
  266. // the number of variables on the value just loaded.
  267. #emit LOAD.S.alt n
  268. #emit ADD
  269. #emit STOR.S.pri arg_end
  270. new
  271. arg_cur = arg_end;
  272. do
  273. {
  274. #emit LOAD.S.pri arg_cur
  275. #emit LOAD.I
  276. #emit PUSH.pri
  277. arg_cur -= 4;
  278. }
  279. while (arg_cur > arg_start);
  280. Format_Render(INVALID_PLAYER_ID, NO_LANGUAGE, output, len - 1, 0, e_FORMAT_FLAGS_NONE, sTemp, n / 4);
  281. #emit LCTRL 4
  282. #emit LOAD.S.alt n
  283. #emit ADD
  284. #emit SCTRL 4
  285. }
  286. else
  287. {
  288. Format_Render(INVALID_PLAYER_ID, NO_LANGUAGE, output, len - 1, 0, e_FORMAT_FLAGS_NONE, sTemp, 0);
  289. }
  290. }
  291. stock printfex(const format[], GLOBAL_TAG_TYPES:...)
  292. {
  293. static
  294. sFormat[1024],
  295. sTemp[1024];
  296. // "Format_Standardise" modifies "input" repeatedly.
  297. strcpy(sFormat, format);
  298. Format_Standardise(sFormat, sTemp);
  299. new
  300. n = (numargs() - 1) * 4;
  301. if (n)
  302. {
  303. // Push all passed parameters.
  304. new
  305. arg_start,
  306. arg_end;
  307. // Load the real address of the last static parameter. Do this by
  308. // loading the address of the parameter and then adding the value of
  309. // [FRM] (frame pointer).
  310. #emit CONST.alt format
  311. #emit LCTRL 5
  312. #emit ADD
  313. #emit STOR.S.pri arg_start
  314. // Load the address of the last variable parameter. Do this by adding
  315. // the number of variables on the value just loaded.
  316. #emit LOAD.S.alt n
  317. #emit ADD
  318. #emit STOR.S.pri arg_end
  319. new
  320. arg_cur = arg_end;
  321. do
  322. {
  323. #emit LOAD.S.pri arg_cur
  324. #emit LOAD.I
  325. #emit PUSH.pri
  326. arg_cur -= 4;
  327. }
  328. while (arg_cur > arg_start);
  329. Format_Render(INVALID_PLAYER_ID, NO_LANGUAGE, sFormat, sizeof (sFormat) - 1, 0, e_FORMAT_FLAGS_NONE, sTemp, n / 4);
  330. #emit LCTRL 4
  331. #emit LOAD.S.alt n
  332. #emit ADD
  333. #emit SCTRL 4
  334. }
  335. else
  336. {
  337. Format_Render(INVALID_PLAYER_ID, NO_LANGUAGE, sFormat, sizeof (sFormat) - 1, 0, e_FORMAT_FLAGS_NONE, sTemp, 0);
  338. }
  339. print(sFormat);
  340. }