y_text_entry.inc 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. #if defined _INC_y_text
  2. #endinput
  3. #endif
  4. #define _INC_y_text
  5. /*
  6. Legal:
  7. Version: MPL 1.1
  8. The contents of this file are subject to the Mozilla Public License Version
  9. 1.1 the "License"; you may not use this file except in compliance with
  10. the License. You may obtain a copy of the License at
  11. http://www.mozilla.org/MPL/
  12. Software distributed under the License is distributed on an "AS IS" basis,
  13. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14. for the specific language governing rights and limitations under the
  15. License.
  16. The Original Code is the YSI framework.
  17. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  18. Portions created by the Initial Developer are Copyright C 2011
  19. the Initial Developer. All Rights Reserved.
  20. Contributors:
  21. Y_Less
  22. koolk
  23. JoeBullet/Google63
  24. g_aSlice/Slice
  25. Misiur
  26. samphunter
  27. tianmeta
  28. maddinat0r
  29. spacemud
  30. Crayder
  31. Dayvison
  32. Ahmad45123
  33. Zeex
  34. irinel1996
  35. Yiin-
  36. Chaprnks
  37. Konstantinos
  38. Masterchen09
  39. Southclaws
  40. PatchwerkQWER
  41. m0k1
  42. paulommu
  43. udan111
  44. Thanks:
  45. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  46. ZeeX - Very productive conversations.
  47. koolk - IsPlayerinAreaEx code.
  48. TheAlpha - Danish translation.
  49. breadfish - German translation.
  50. Fireburn - Dutch translation.
  51. yom - French translation.
  52. 50p - Polish translation.
  53. Zamaroht - Spanish translation.
  54. Los - Portuguese translation.
  55. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
  56. me to strive to better.
  57. Pixels^ - Running XScripters where the idea was born.
  58. Matite - Pestering me to release it and using it.
  59. Very special thanks to:
  60. Thiadmer - PAWN, whose limits continue to amaze me!
  61. Kye/Kalcor - SA:MP.
  62. SA:MP Team past, present and future - SA:MP.
  63. Optional plugins:
  64. Gamer_Z - GPS.
  65. Incognito - Streamer.
  66. Me - sscanf2, fixes2, Whirlpool.
  67. */
  68. #if defined YSI_TESTS
  69. // Fake `IsPlayerConnected`.
  70. #define _YSI_SPECIAL_DEBUG
  71. #endif
  72. #include "..\..\YSI_Core\y_utils"
  73. // Make sure this is included early.
  74. #include "..\..\YSI_Data\y_playerset"
  75. // Apparently I'd already written the internal code to support this and forgot!
  76. #define Y_TEXT_UNIQUE
  77. #if !defined Y_TEXT_MAX_SETS
  78. #define Y_TEXT_MAX_SETS (16)
  79. #endif
  80. #if !defined Y_TEXT_PER_SET
  81. #define Y_TEXT_PER_SET (64)
  82. #endif
  83. #if !defined MAX_TEXT_ENTRIES
  84. #define MAX_TEXT_ENTRIES (Y_TEXT_PER_SET * Y_TEXT_MAX_SETS)
  85. #endif
  86. #if defined YSI_TESTS
  87. #define MAX_Y_TEXT_TEST_LINES (10)
  88. #define MAX_Y_TEXT_TEST_LENGTH (1024)
  89. // These mocks DO NOT use ALS or stock, so that we get compile-time warnings
  90. // about anything that may interfere. Tests shouldn't really be run on a
  91. // full mode with all other things (unless you are doing integration tests),
  92. // so the warnings are appropriate.
  93. new
  94. YSI_gTextTestPlayer[MAX_Y_TEXT_TEST_LINES],
  95. YSI_gTextTestStyle[MAX_Y_TEXT_TEST_LINES],
  96. YSI_gTextTestTime[MAX_Y_TEXT_TEST_LINES],
  97. YSI_gTextTestOutput[MAX_Y_TEXT_TEST_LINES][MAX_Y_TEXT_TEST_LENGTH],
  98. YSI_gTextTest;
  99. // Hook SA:MP natives, so that calls to print functions are routed to us
  100. // instead. "TxT" = "TextTest".
  101. TxT_SendClientMessage(playerid, color, const message[])
  102. {
  103. YSI_gTextTestPlayer[YSI_gTextTest] = playerid,
  104. YSI_gTextTestStyle[YSI_gTextTest] = color,
  105. strcpy(YSI_gTextTestOutput[YSI_gTextTest], message),
  106. ++YSI_gTextTest;
  107. }
  108. #define SendClientMessage TxT_SendClientMessage
  109. TxT_SendPlayerMessageToPlayer(playerid, senderid, const message[])
  110. {
  111. YSI_gTextTestPlayer[YSI_gTextTest] = playerid,
  112. YSI_gTextTestStyle[YSI_gTextTest] = senderid,
  113. strcpy(YSI_gTextTestOutput[YSI_gTextTest], message),
  114. ++YSI_gTextTest;
  115. }
  116. #define SendPlayerMessageToPlayer TxT_SendPlayerMessageToPlayer
  117. TxT_GameTextForPlayer(playerid, const string[], time, style)
  118. {
  119. YSI_gTextTestPlayer[YSI_gTextTest] = playerid,
  120. YSI_gTextTestStyle[YSI_gTextTest] = style,
  121. YSI_gTextTestTime[YSI_gTextTest] = time,
  122. strcpy(YSI_gTextTestOutput[YSI_gTextTest], string),
  123. ++YSI_gTextTest;
  124. }
  125. #define GameTextForPlayer TxT_GameTextForPlayer
  126. TextTest_Reset()
  127. {
  128. for (new i = 0; i != MAX_Y_TEXT_TEST_LINES; ++i)
  129. {
  130. YSI_gTextTestPlayer[i] = cellmin,
  131. YSI_gTextTestStyle[i] = cellmin,
  132. YSI_gTextTestTime[i] = cellmin,
  133. YSI_gTextTestOutput[i][0] = '\0';
  134. }
  135. YSI_gTextTest = 0;
  136. }
  137. // TODO: TextDraw hooks.
  138. #endif
  139. #include "..\..\YSI_Storage\y_xml"
  140. #include "..\..\YSI_Server\y_td"
  141. #include "..\..\YSI_Server\y_colours"
  142. #include "y_text_styles"
  143. // This is a horribly eclectic collection of libraries from all over the place
  144. // and written at different times with different aims - frankly I'll be AMAZED
  145. // if it all comes together and works.
  146. //
  147. // 2017: I'm still amazed it works!
  148. //
  149. // 2018: Collating core includes, hopefully will still work.
  150. #if !defined MAX_PLAYER_NAME
  151. #define MAX_PLAYER_NAME 24
  152. #elseif MAX_PLAYER_NAME != (24)
  153. #error Unknown MAX_PLAYER_NAME size.
  154. #else
  155. // Strip the brackets off.
  156. #undef MAX_PLAYER_NAME
  157. #define MAX_PLAYER_NAME 24
  158. #endif
  159. //#include <a_samp>
  160. #include "..\..\YSI_Server\y_colours"
  161. #include "..\..\YSI_Data\y_hashmap"
  162. #include "..\..\YSI_Data\y_jaggedarray"
  163. #include "y_text_load"
  164. #include "..\..\YSI_Coding\y_va"
  165. #include "y_text_render"
  166. #include "..\..\YSI_Storage\y_ini"
  167. #include "..\..\YSI_Data\y_iterate"
  168. #include "..\..\YSI_Players\y_languages"
  169. #include "..\..\YSI_Visual\y_dialog"
  170. #include "..\..\YSI_Coding\y_inline"
  171. #include "..\..\YSI_Coding\y_hooks"
  172. #include "y_text_impl"
  173. #define UNDO_MOVE|||
  174. #define DO_MOVE|||%0``` %0DO_MOVE|||
  175. #define Text_Send(%0,%1) PSF:_Text_Send(%0,DO_TEXT_SET:%1 UNDO_MOVE|||)
  176. #define Text_Render(%0,%1) _Text_Render(%0,DO_TEXT_SET:%1 UNDO_MOVE|||)
  177. #define Text_Format(%0,%1,%2,%3,%4) _Text_Format(%0,%1,%2,%3,DO_TEXT_SET:%4 UNDO_MOVE|||)
  178. #define Text_Format_GT_0(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_GT_0,%3)
  179. #define Text_Format_GT_1(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_GT_1,%3)
  180. #define Text_Format_GT_2(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_GT_2,%3)
  181. #define Text_Format_GT_3(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_GT_3,%3)
  182. #define Text_Format_GT_4(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_GT_4,%3)
  183. #define Text_Format_GT_5(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_GT_5,%3)
  184. #define Text_Format_GT_6(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_GT_6,%3)
  185. #define Text_Format_TD(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_TD,%3)
  186. #define Text_Format_3D(%0,%1,%2,%3 Text_Format(%0,%1,%2, e_STYLE_TYPE_3D,%3)
  187. #define Text_Format_Client(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_CLIENT,%3)
  188. #define Text_Format_Player(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_PLAYER,%3)
  189. #define Text_Format_Other(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_OTHER,%3)
  190. #define Text_Format_Dialog(%0,%1,%2,%3) Text_Format(%0,%1,%2, e_STYLE_TYPE_DIALOG,%3)
  191. //#define _Text_Send(%0YCMD:%1) _Text_Send(%0_:YCMD_REP_0:YCMD_REP_1:%1)
  192. //#define YCMD_REP_0:YCMD_REP_1:%0, Command_GetID(%0),
  193. //#define YCMD_REP_1:%0) Command_GetID(%0))
  194. // This code allows "DEFAULT_TEXT_SET" to propogate through the text one section
  195. // at a time without detecting later matches too early. The design of "DO_MOVE"
  196. // and "UNDO_MOVE" means that the compiler will correctly detect the end of the
  197. // code, regardless of the length, and end.
  198. #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```)
  199. #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```)
  200. #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```)
  201. #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```)
  202. #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```)
  203. //#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$$$)
  204. //#define _Text_MessageBox(%0YCMD:%1) _Text_MessageBox(%0_:YCMD_REP_0:YCMD_REP_1:%1)
  205. //stock Text_GetAllIDs(
  206. static stock
  207. YSI_g_sFormat[1024],
  208. YSI_g_sTemp[1024];
  209. stock Text_FormatEx(output[], len, const format[], GLOBAL_TAG_TYPES:...)
  210. {
  211. // "Format_Standardise" modifies "input" repeatedly.
  212. strcpy(YSI_g_sFormat, format);
  213. Format_Standardise(YSI_g_sFormat, YSI_g_sTemp);
  214. Format_Render(INVALID_PLAYER_ID, NO_LANGUAGE, output, len - 1, 0, e_FORMAT_FLAGS_NONE, YSI_g_sTemp, ___(3));
  215. }
  216. stock Text_PrintFEx(const format[], GLOBAL_TAG_TYPES:...)
  217. {
  218. // "Format_Standardise" modifies "input" repeatedly.
  219. strcpy(YSI_g_sFormat, format);
  220. Format_Standardise(YSI_g_sFormat, YSI_g_sTemp);
  221. Format_Render(INVALID_PLAYER_ID, NO_LANGUAGE, YSI_g_sFormat, sizeof (YSI_g_sFormat) - 1, 0, e_FORMAT_FLAGS_NONE, YSI_g_sTemp, ___(1));
  222. print(sFormat);
  223. }
  224. #if defined YSI_TESTS
  225. #include "y_text_tests"
  226. #endif
  227. #if !defined formatex
  228. #define formatex Text_FormatEx
  229. #endif
  230. #if !defined printfex
  231. #define printfex Text_PrintFEx
  232. #endif