styles.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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. // Load the styles for the current item. I have decided to completely switch
  65. // over to XML as there are just too many options now to make INI files worth
  66. // the effort.
  67. enum e_STYLE_TYPE (+= 0x10000000) // ALWAYS ADD!
  68. {
  69. e_STYLE_TYPE_GT_0 = 0x10000000, // ALWAYS FIRST!
  70. e_STYLE_TYPE_GT_1,
  71. e_STYLE_TYPE_GT_2,
  72. e_STYLE_TYPE_GT_3,
  73. e_STYLE_TYPE_GT_4,
  74. e_STYLE_TYPE_GT_5,
  75. e_STYLE_TYPE_GT_6,
  76. e_STYLE_TYPE_TD,
  77. e_STYLE_TYPE_3D,
  78. // This is the point after which ~n~ is not used for new lines.
  79. e_STYLE_TYPE_CLIENT,
  80. e_STYLE_TYPE_PLAYER,
  81. e_STYLE_TYPE_OTHER,
  82. e_STYLE_TYPE_DIALOG,
  83. e_STYLE_TYPE_MASK = 0xF0000000,
  84. e_STYLE_TYPE_SHIFT = 28
  85. }
  86. enum E_STYLE_DATA
  87. {
  88. e_STYLE_TYPE:E_STYLE_DATA_TYPE = 0,
  89. E_STYLE_DATA_COLOUR = 0, // SCM colour (RRGGBBA (only 1 A)).
  90. E_STYLE_DATA_STYLE = 0, // GT style (set later).
  91. E_STYLE_DATA_TIME = 1, // GT time.
  92. Style:E_STYLE_DATA_TD_ID = 1, // TD style to show this as.
  93. E_STYLE_DATA_3D_ID = 1 // 3D style to show this as.
  94. }
  95. enum e_3D_FLAGS
  96. {
  97. e_3D_FLAGS_VW = 0x0003FFFF, // Max VWs of 262144 (>500 per player).
  98. e_3D_FLAGS_DD = 0x7FFC0000, // Max draw distance of 8192 (1.3x SA).
  99. e_3D_FLAGS_LOS = 0x80000000,
  100. e_3D_FLAGS_VW_SHIFT = 0,
  101. e_3D_FLAGS_DD_SHIFT = 18
  102. }
  103. enum E_3D_DATA
  104. {
  105. Float:E_3D_DATA_X,
  106. Float:E_3D_DATA_Y,
  107. Float:E_3D_DATA_Z,
  108. E_3D_DATA_ATTACH, // -1 = None, < 500 = player, >= 500 = vehicle + 500.
  109. e_3D_FLAGS:E_3D_DATA_FLAGS
  110. }
  111. #if !defined MAX_STYLES
  112. #define MAX_STYLES (MAX_TEXT_ENTRIES)
  113. #endif
  114. #if !defined MAX_3D_STYLES
  115. #define MAX_3D_STYLES (MAX_STYLES / 4)
  116. #endif
  117. #define STYLES_FORMAT_FILE "YSI/%s_LANG_DATA.yml"
  118. static stock
  119. YSI_g_sStyleData[MAX_STYLES][E_STYLE_DATA],
  120. YSI_g_s3DLabelData[MAX_3D_STYLES][E_3D_DATA],
  121. //YSI_g_s3DBlankData[E_3D_DATA],
  122. YSI_g_sStyleBlankData[E_STYLE_DATA] = {e_STYLE_TYPE_CLIENT | e_STYLE_TYPE:0x0FF0000A, -1},
  123. XML:YSI_g_sXMLRules = NO_XML_FILE,
  124. YSI_g_sCurFile[32] = "\1\0",
  125. YSI_g_sCur3D;
  126. stock _Style_Init(id)
  127. {
  128. YSI_g_sStyleData[id] = YSI_g_sStyleBlankData;
  129. }
  130. forward _Styles_SpecialInit();
  131. stock Styles_GetData(index, style[E_STYLE_DATA], label[E_3D_DATA])
  132. {
  133. if (0 <= index < MAX_STYLES)
  134. {
  135. style = YSI_g_sStyleData[index];
  136. if ((style[E_STYLE_DATA_TYPE] & e_STYLE_TYPE_MASK) == e_STYLE_TYPE_3D)
  137. {
  138. label = YSI_g_s3DLabelData[style[E_STYLE_DATA_3D_ID]];
  139. }
  140. }
  141. else
  142. {
  143. style = YSI_g_sStyleBlankData;
  144. }
  145. }
  146. /*-------------------------------------------------------------------------*//**
  147. * <remarks>
  148. * Called to load "&lt;entry&gt;" tags from XML style files.
  149. * </remarks>
  150. *//*------------------------------------------------------------------------**/
  151. forward Styles_EntryTag();
  152. public Styles_EntryTag()
  153. {
  154. P:2("Styles_EntryTag called");
  155. static
  156. name[MAX_XML_ENTRY_NAME],
  157. val[MAX_XML_ENTRY_TEXT],
  158. e_STYLE_TYPE:type = e_STYLE_TYPE_OTHER,
  159. data,
  160. colour,
  161. id,
  162. time;
  163. if (!XML_GetParentValue("name", val))
  164. {
  165. return 0;
  166. }
  167. // "_Text_CheckOwnership" MUST be called before "_Text_LookupName".
  168. if (!_Text_CheckOwnership(YSI_g_sCurFile, val))
  169. {
  170. P:5("Styles_EntryTag: Don't own %s", val);
  171. // This script doesn't own this text group.
  172. return 0;
  173. }
  174. // Got the name of this group that this text entries is in.
  175. while (XML_GetKeyValue(name, val))
  176. {
  177. if (!strcmp(name, "name", true))
  178. {
  179. // Use the parent name to help look this up. Also check if we are
  180. // the owner of this group. Actually, use internal text functions
  181. // to do this given that it will know what file it is currently
  182. // loading and has better knowledge of its own internal structure.
  183. // This means we MUST call a style file parse function from inside
  184. // y_textint.
  185. id = _Text_LookupName(val);
  186. P:5("Styles_EntryTag: %s = %d", val, id);
  187. }
  188. else if (!strcmp(name, "type", true) || !strcmp(name, "style", true))
  189. {
  190. // The searched for strings are very lenient.
  191. if (strfind(val, "Client", true) != -1)
  192. {
  193. type = e_STYLE_TYPE_CLIENT;
  194. }
  195. else if (strfind(val, "Player", true) != -1)
  196. {
  197. type = e_STYLE_TYPE_PLAYER;
  198. }
  199. else if (strfind(val, "Draw", true) != -1)
  200. {
  201. type = e_STYLE_TYPE_TD;
  202. }
  203. else if (strfind(val, "3D", true) != -1)
  204. {
  205. type = e_STYLE_TYPE_3D;
  206. }
  207. else
  208. {
  209. // Better "strval" for short numbers.
  210. new
  211. tmp = (val[0] - '0') + 1;
  212. if (1 <= tmp <= 7)
  213. {
  214. type = e_STYLE_TYPE_GT_0 * e_STYLE_TYPE:tmp;
  215. }
  216. }
  217. }
  218. else if (!strcmp(name, "3d", true))
  219. {
  220. data = strval(val);
  221. type = e_STYLE_TYPE_3D;
  222. }
  223. else if (!strcmp(name, "textdraw", true))
  224. {
  225. type = e_STYLE_TYPE_TD;
  226. if (isnumeric(val))
  227. {
  228. data = strval(val);
  229. }
  230. else
  231. {
  232. data = _:TD_GetNamed(val);
  233. }
  234. }
  235. else if (!strcmp(name, "time", true))
  236. {
  237. time = strval(val);
  238. }
  239. else if (!strcmp(name, "colour", true) || !strcmp(name, "color", true))
  240. {
  241. #if defined _inc_sscanf2 || defined unformat
  242. if (unformat(val, "n", colour))
  243. #else
  244. if (ishex(val)) colour = hexstr(val);
  245. else if (isnumeric(val)) colour = strval(val);
  246. else
  247. #endif
  248. colour = GetColour(val);
  249. }
  250. }
  251. if (0 <= id < MAX_STYLES)
  252. {
  253. //printf("SAVING %d", id);
  254. switch (type)
  255. {
  256. 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:
  257. // This doesn't seem to want to work...
  258. //case e_STYLE_TYPE_GT_0 .. e_STYLE_TYPE_GT_6:
  259. {
  260. YSI_g_sStyleData[id][E_STYLE_DATA_TIME] = time;
  261. // Don't set ANY colours here!
  262. YSI_g_sStyleData[id][E_STYLE_DATA_TYPE] = type;
  263. }
  264. case e_STYLE_TYPE_TD:
  265. {
  266. YSI_g_sStyleData[id][E_STYLE_DATA_TYPE] = type;
  267. YSI_g_sStyleData[id][E_STYLE_DATA_TD_ID] = Style:data;
  268. }
  269. default:
  270. {
  271. //printf("SAVING %d", id);
  272. YSI_g_sStyleData[id][E_STYLE_DATA_3D_ID] = -1;
  273. //printf("SAVING %d", id);
  274. YSI_g_sStyleData[id][E_STYLE_DATA_TYPE] = e_STYLE_TYPE:(colour >>> 4 ) | type;
  275. //printf("SAVING %d", id);
  276. }
  277. /*case e_STYLE_TYPE_PLAYER:
  278. {
  279. }
  280. case e_STYLE_TYPE_TD:
  281. {
  282. }
  283. case e_STYLE_TYPE_3D:
  284. {
  285. }
  286. case e_STYLE_TYPE_OTHER:
  287. {
  288. YSI_g_sStyleData[id] =
  289. }*/
  290. }
  291. }
  292. //printf("SAVING %d", id);
  293. // Return value is not important here.
  294. return 1;
  295. }
  296. forward Styles_3DTag();
  297. public Styles_3DTag()
  298. {
  299. P:2("Styles_EntryTag called");
  300. static
  301. name[MAX_XML_ENTRY_NAME],
  302. val[MAX_XML_ENTRY_TEXT],
  303. #if !defined _inc_sscanf2 && !defined unformat
  304. tmp,
  305. #endif
  306. Float:x,
  307. Float:y,
  308. Float:z,
  309. e_3D_FLAGS:flags;
  310. if (YSI_g_sCur3D == MAX_3D_STYLES)
  311. {
  312. return -1;
  313. }
  314. while (XML_GetKeyValue(name, val))
  315. {
  316. if (!strcmp(name, "x", true))
  317. {
  318. x = floatstr(val);
  319. }
  320. else if (!strcmp(name, "y", true))
  321. {
  322. y = floatstr(val);
  323. }
  324. else if (!strcmp(name, "z", true))
  325. {
  326. z = floatstr(val);
  327. }
  328. else if (!strcmp(name, "pos", true))
  329. {
  330. // A good example of the advantages of sscanf.
  331. #if defined _inc_sscanf2 || defined unformat
  332. unformat(val, "p<,>fff", x, y, z);
  333. #else
  334. x = floatstr(val);
  335. tmp = strfind(val, ",") + 1;
  336. if (tmp)
  337. {
  338. y = floatstr(val[tmp]);
  339. tmp = strfind(val, ",") + 1;
  340. if (tmp)
  341. {
  342. z = floatstr(val[tmp]);
  343. }
  344. }
  345. #endif
  346. }
  347. else if (!strcmp(name, "vw", true) || !strcmp(name, "virtualworld", true))
  348. {
  349. flags = (flags & ~e_3D_FLAGS_VW) | ((e_3D_FLAGS:strval(val)) & e_3D_FLAGS_VW);
  350. }
  351. else if (!strcmp(name, "los", true) || !strcmp(name, "lineofsight", true))
  352. {
  353. if (!strcmp(val, "true", true) || strval(val))
  354. {
  355. flags |= e_3D_FLAGS_LOS;
  356. }
  357. else
  358. {
  359. flags &= ~e_3D_FLAGS_LOS;
  360. }
  361. }
  362. else if (!strcmp(name, "drawdistance", true))
  363. {
  364. flags = (flags & ~e_3D_FLAGS_DD) | ((e_3D_FLAGS:strval(val) << e_3D_FLAGS_DD_SHIFT) & e_3D_FLAGS_DD);
  365. }
  366. }
  367. YSI_g_s3DLabelData[YSI_g_sCur3D][E_3D_DATA_X] = x;
  368. YSI_g_s3DLabelData[YSI_g_sCur3D][E_3D_DATA_Y] = y;
  369. YSI_g_s3DLabelData[YSI_g_sCur3D][E_3D_DATA_Z] = z;
  370. YSI_g_s3DLabelData[YSI_g_sCur3D][E_3D_DATA_FLAGS] = flags;
  371. YSI_g_s3DLabelData[YSI_g_sCur3D][E_3D_DATA_ATTACH] = -1;
  372. return YSI_g_sCur3D++;
  373. }
  374. /*-------------------------------------------------------------------------*//**
  375. * <remarks>
  376. * Loads all the style files relevant to this script. Filters by text group in
  377. * the XML callback. Loops through all publics, then loops through them all
  378. * again to check that the current file hasn't already been loaded. Despite
  379. * the filtering, it is done this way to ensure that all relevant text draw
  380. * styles are loaded for when we are displaying text.
  381. * </remarks>
  382. *//*------------------------------------------------------------------------**/
  383. //hook OnScriptInit()
  384. public _Styles_SpecialInit()
  385. {
  386. if (YSI_g_sXMLRules == NO_XML_FILE)
  387. {
  388. YSI_g_sXMLRules = XML_New();
  389. if (YSI_g_sXMLRules != NO_XML_FILE)
  390. {
  391. // This is copied directly from y_td.
  392. XML_AddHandler(YSI_g_sXMLRules, "color", "TD_LoadColour");
  393. XML_AddHandler(YSI_g_sXMLRules, "colour", "TD_LoadColour");
  394. XML_AddHandler(YSI_g_sXMLRules, "textdraw", "TD_Textdraw");
  395. //XML_AddHandler(YSI_g_sXMLRules, "box", "TD_Box");
  396. //XML_AddHandler(YSI_g_sXMLRules, "background", "TD_Background");
  397. //XML_AddHandler(YSI_g_sXMLRules, "style", "TD_Style");
  398. XML_AddHandler(YSI_g_sXMLRules, "entry", "Styles_EntryTag");
  399. XML_AddHandler(YSI_g_sXMLRules, "3d", "Styles_3DTag");
  400. XML_AddHandler(YSI_g_sXMLRules, "group", NULL);
  401. }
  402. }
  403. YSI_g_sCur3D = 0;
  404. new
  405. idx = 0,
  406. buffer[32],
  407. b2[32],
  408. pos;
  409. // Load the data for ALL the files this script uses (to get textdraw data).
  410. while ((idx = AMX_GetPublicNameSuffix(idx, buffer, _A<@yX_>)))
  411. {
  412. if ((pos = strfind(buffer, "@")) != -1)
  413. {
  414. buffer{pos} = '\0';
  415. if (strcmp(buffer, YSI_g_sCurFile))
  416. {
  417. // Different - check for more matches.
  418. new
  419. i2 = 0;
  420. for ( ; ; )
  421. {
  422. i2 = AMX_GetPublicNameSuffix(i2, b2, _A<@yX_>);
  423. if (i2 == idx)
  424. {
  425. // Unique entry found. Load the file.
  426. strunpack(YSI_g_sCurFile, buffer);
  427. format(b2, sizeof (b2), STYLES_FORMAT_FILE, YSI_g_sCurFile);
  428. XML_Parse(YSI_g_sXMLRules, b2);
  429. break;
  430. }
  431. else if (!strcmp(b2, buffer))
  432. {
  433. break;
  434. }
  435. }
  436. }
  437. }
  438. }
  439. }
  440. /*stock _Styles_ParseOne(file[])
  441. {
  442. new
  443. fname[64];
  444. format(fname, sizeof (fname), STYLES_LANG_DATA, file);
  445. XML_Parse(YSI_g_sXMLRules, fname);
  446. }*/
  447. /*-------------------------------------------------------------------------*//**
  448. * <remarks>
  449. * Reloads all the string styles in all scripts. Use sparingly!
  450. * </remarks>
  451. *//*------------------------------------------------------------------------**/
  452. stock Styles_Reload()
  453. {
  454. CallRemoteFunction("_Styles_SpecialInit", "");
  455. }