1
0

y_gui.inc 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. /**--------------------------------------------------------------------------**\
  2. | y_GUI
  3. </remarks>
  4. \**--------------------------------------------------------------------------**/
  5. #include <a_samp>
  6. #include "y_bit"
  7. /*----------------------------------------------------------------------------*/
  8. #if !defined MAX_GUIS
  9. #define MAX_GUIS (32)
  10. #endif
  11. #if MAX_GUIS < 1
  12. #undef MAX_GUIS
  13. #define MAX_GUIS (1)
  14. #endif
  15. #if !defined MAX_GUI_ELEMENTS
  16. #define MAX_GUI_ELEMENTS (16)
  17. #endif
  18. #if MAX_GUI_ELEMENTS < 1
  19. #undef MAX_GUI_ELEMENTS
  20. #define MAX_GUI_ELEMENTS (1)
  21. #endif
  22. #if !defined MAX_GUI_ELEMENTS_LENGTH
  23. #define MAX_GUI_ELEMENTS_LENGTH (32)
  24. #endif
  25. #if MAX_GUI_ELEMENTS < 1
  26. #undef MAX_GUI_ELEMENTS_LENGTH
  27. #define MAX_GUI_ELEMENTS_LENGTH (16)
  28. #endif
  29. #define NO_GUI (GUI:-1)
  30. /*----------------------------------------------------------------------------*/
  31. #define GUI_IsValid(%0) ((GUI:0 <= (%0) < GUI:MAX_GUIS) && Bit_Get(YSI_g_sGUIBeingUsed, (%0)))
  32. /*----------------------------------------------------------------------------*/
  33. static stock
  34. BitArray: YSI_g_sGUIBeingUsed<MAX_GUIS>, // Being used
  35. // Title variables
  36. BitArray: YSI_g_sGUITitleUsing<MAX_GUIS>, // Using title
  37. YSI_g_sGUITitleText[MAX_GUIS][64 char], // Title text (Packed)
  38. Float: YSI_g_sGUITitlePos[MAX_GUIS][2], // Position
  39. Float: YSI_g_sGUITitleSize[MAX_GUIS][2], // Size
  40. YSI_g_sGUITitleColor[MAX_GUIS], // Text color
  41. BitArray: YSI_g_sGUITitleBox<MAX_GUIS>, // Using box
  42. Float: YSI_g_sGUITitleBPos[MAX_GUIS][2], // Box Position
  43. Float: YSI_g_sGUITitleBSize[MAX_GUIS][2], // Box Size
  44. YSI_g_sGUITitleBColor[MAX_GUIS], // Box color
  45. // Items (buttons)
  46. BitArray: YSI_g_sGUIItemUsing[MAX_GUIS]<MAX_GUI_ELEMENTS>, // Using button
  47. YSI_g_sGUIItemText[MAX_GUIS][MAX_GUI_ELEMENTS][MAX_GUI_ELEMENTS_LENGTH char], // Button text (Packed string)
  48. Float: YSI_g_sGUIItemPos[MAX_GUIS][MAX_GUI_ELEMENTS][2], // Button position
  49. Float: YSI_g_sGUIItemSize[MAX_GUIS][MAX_GUI_ELEMENTS][2], // Button size
  50. Float: YSI_g_sGUIItemBSize[MAX_GUIS][MAX_GUI_ELEMENTS], // Buttom box size
  51. YSI_g_sGUIItemColor[MAX_GUIS][MAX_GUI_ELEMENTS], // Button color
  52. YSI_g_sGUIItemBColor[MAX_GUIS][MAX_GUI_ELEMENTS], // Button box color
  53. // Textdraws
  54. Text: YSI_g_sGUITextTitle[MAX_GUIS][2],
  55. Text: YSI_g_sGUITextButton[MAX_GUIS][MAX_GUI_ELEMENTS],
  56. // Per player variables
  57. BitArray: YSI_g_spGUIUsing<MAX_PLAYERS>,
  58. YSI_g_spGUI[MAX_PLAYERS],
  59. YSI_g_spGUITick[MAX_PLAYERS],
  60. YSI_g_spGUIItem[MAX_PLAYERS];
  61. /*----------------------------------------------------------------------------*/
  62. stock
  63. GUI_ShowForPlayer(playerid, GUI: gui)
  64. {
  65. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:gui))
  66. return 0;
  67. // ---------------------------------------------------------------------
  68. if (!Bit_Get(YSI_g_spGUIUsing, playerid))
  69. Bit_Let(YSI_g_spGUIUsing, playerid);
  70. // ---------------------------------------------------------------------
  71. YSI_g_spGUI[playerid] = _:gui;
  72. YSI_g_spGUIItem[playerid] = 0;
  73. // ---------------------------------------------------------------------
  74. if (Bit_Get(YSI_g_sGUITitleUsing, _:gui))
  75. TextDrawShowForPlayer(playerid, YSI_g_sGUITextTitle[_:gui][0]);
  76. if (Bit_Get(YSI_g_sGUITitleBox, _:gui))
  77. TextDrawShowForPlayer(playerid, YSI_g_sGUITextTitle[_:gui][1]);
  78. // ---------------------------------------------------------------------
  79. // Maybe you can use y_iterate here
  80. for (new pos; pos < MAX_GUI_ELEMENTS; pos ++)
  81. if (Bit_Get(YSI_g_sGUIItemUsing[_:gui], pos))
  82. TextDrawShowForPlayer(playerid, YSI_g_sGUITextButton[_:gui][pos]);
  83. // ---------------------------------------------------------------------
  84. return 1;
  85. }
  86. stock
  87. GUI_HideForPlayer(playerid)
  88. {
  89. if (!Bit_Get(YSI_g_spGUIUsing, playerid))
  90. return 0;
  91. // ---------------------------------------------------------------------
  92. Bit_Vet(YSI_g_spGUIUsing, playerid);
  93. // ---------------------------------------------------------------------
  94. YSI_g_spGUI[playerid] = 0;
  95. YSI_g_spGUIItem[playerid] = 0;
  96. // ---------------------------------------------------------------------
  97. if (Bit_Get(YSI_g_sGUITitleUsing, _:gui))
  98. TextDrawHideForPlayer(playerid, YSI_g_sGUITextTitle[_:gui][0]);
  99. if (Bit_Get(YSI_g_sGUITitleBox, _:gui))
  100. TextDrawHideForPlayer(playerid, YSI_g_sGUITextTitle[_:gui][1]);
  101. // ---------------------------------------------------------------------
  102. // Maybe you can use y_iterate here
  103. for (new pos; pos < MAX_GUI_ELEMENTS; pos ++)
  104. if (Bit_Get(YSI_g_sGUIItemUsing[_:gui], pos))
  105. TextDrawHideForPlayer(playerid, YSI_g_sGUITextButton[_:gui][pos]);
  106. // ---------------------------------------------------------------------
  107. return 1;
  108. }
  109. /*----------------------------------------------------------------------------*/
  110. stock GUI:GUI_Create()
  111. {
  112. for (new pos = 0; pos != MAX_GUIS; ++pos)
  113. {
  114. if (!Bit_Get(YSI_g_sGUIBeingUsed, pos))
  115. {
  116. Bit_Let(YSI_g_sGUIBeingUsed, pos);
  117. return GUI:pos;
  118. }
  119. }
  120. return NO_GUI;
  121. }
  122. /*----------------------------------------------------------------------------*/
  123. stock
  124. GUI_Delete(GUI: Handle)
  125. {
  126. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  127. return 0;
  128. // ---------------------------------------------------------------------
  129. Bit_Vet(YSI_g_sGUIBeingUsed, _:Handle);
  130. // ---------------------------------------------------------------------
  131. return 1;
  132. }
  133. /*----------------------------------------------------------------------------*/
  134. stock
  135. GUI_Title_Use(GUI: Handle)
  136. {
  137. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  138. return 0;
  139. if (Bit_Get(YSI_g_sGUITitleUsing, _:Handle))
  140. return -1;
  141. // ---------------------------------------------------------------------
  142. Bit_Let(YSI_g_sGUITitleUsing, _:Handle);
  143. Bit_Vet(YSI_g_sGUITitleBox, _:Handle);
  144. YSI_g_sGUITitleText[_:Handle][0] = 0;
  145. YSI_g_sGUITitlePos[_:Handle][0] = 0.0;
  146. YSI_g_sGUITitlePos[_:Handle][1] = 0.0;
  147. YSI_g_sGUITitleSize[_:Handle][0] = 0.0;
  148. YSI_g_sGUITitleSize[_:Handle][1] = 0.0;
  149. YSI_g_sGUITitleColor[_:Handle] = 0xFFFFFFFF;
  150. YSI_g_sGUITitleBPos[_:Handle][0] = 0.0;
  151. YSI_g_sGUITitleBPos[_:Handle][1] = 0.0;
  152. YSI_g_sGUITitleBSize[_:Handle][0] = 0.0;
  153. YSI_g_sGUITitleBSize[_:Handle][1] = 0.0;
  154. YSI_g_sGUITitleBColor[_:Handle] = 0x00000077;
  155. // ---------------------------------------------------------------------
  156. return 1;
  157. }
  158. /*----------------------------------------------------------------------------*/
  159. stock
  160. GUI_Title_Remove(GUI: Handle)
  161. {
  162. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  163. return 0;
  164. if (!Bit_Get(YSI_g_sGUITitleUsing, _:Handle))
  165. return -1;
  166. // ---------------------------------------------------------------------
  167. Bit_Vet(YSI_g_sGUITitleUsing, _:Handle);
  168. // ---------------------------------------------------------------------
  169. return 1;
  170. }
  171. /*----------------------------------------------------------------------------*/
  172. stock
  173. GUI_Title_SetText(GUI: Handle, Text[])
  174. {
  175. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  176. return 0;
  177. if (!Bit_Get(YSI_g_sGUITitleUsing, _:Handle))
  178. return -1;
  179. // ---------------------------------------------------------------------
  180. strpack(YSI_g_sGUITitleText[_:Handle], Text, 64);
  181. // ---------------------------------------------------------------------
  182. return 1;
  183. }
  184. stock
  185. GUI_Title_GetText(GUI: Handle, Text[])
  186. {
  187. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  188. return 0;
  189. if (!Bit_Get(YSI_g_sGUITitleUsing, _:Handle))
  190. return -1;
  191. // ---------------------------------------------------------------------
  192. strunpack(Text, YSI_g_sGUITitleText[_:Handle], 64);
  193. // ---------------------------------------------------------------------
  194. return 1;
  195. }
  196. /*----------------------------------------------------------------------------*/
  197. stock
  198. GUI_Title_SetPos(GUI: Handle, Float: posX, Float: posY)
  199. {
  200. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  201. return 0;
  202. if (!Bit_Get(YSI_g_sGUITitleUsing, _:Handle))
  203. return -1;
  204. // ---------------------------------------------------------------------
  205. YSI_g_sGUITitlePos[_:Handle][0] = posX;
  206. YSI_g_sGUITitlePos[_:Handle][1] = posY;
  207. // ---------------------------------------------------------------------
  208. return 1;
  209. }
  210. stock
  211. GUI_Title_GetPos(GUI: Handle, &Float: posX, &Float: posY)
  212. {
  213. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  214. return 0;
  215. if (!Bit_Get(YSI_g_sGUITitleUsing, _:Handle))
  216. return -1;
  217. // ---------------------------------------------------------------------
  218. posX = YSI_g_sGUITitlePos[_:Handle][0];
  219. posY = YSI_g_sGUITitlePos[_:Handle][1];
  220. // ---------------------------------------------------------------------
  221. return 1;
  222. }
  223. /*----------------------------------------------------------------------------*/
  224. stock
  225. GUI_Title_SetSize(GUI: Handle, Float: sizeX, Float: sizeY)
  226. {
  227. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  228. return 0;
  229. if (!Bit_Get(YSI_g_sGUITitleUsing, _:Handle))
  230. return -1;
  231. // ---------------------------------------------------------------------
  232. YSI_g_sGUITitleSize[_:Handle][0] = sizeX;
  233. YSI_g_sGUITitleSize[_:Handle][1] = sizeY;
  234. // ---------------------------------------------------------------------
  235. return 1;
  236. }
  237. stock
  238. GUI_Title_GetSize(GUI: Handle, &Float: sizeX, &Float: sizeY)
  239. {
  240. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  241. return 0;
  242. if (!Bit_Get(YSI_g_sGUITitleUsing, _:Handle))
  243. return -1;
  244. // ---------------------------------------------------------------------
  245. sizeX = YSI_g_sGUITitleSize[_:Handle][0];
  246. sizeY = YSI_g_sGUITitleSize[_:Handle][1];
  247. // ---------------------------------------------------------------------
  248. return 1;
  249. }
  250. /*----------------------------------------------------------------------------*/
  251. #define GUI_Title_SetColour GUI_Title_SetColor
  252. stock
  253. GUI_Title_SetColor(GUI: Handle, Color)
  254. {
  255. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  256. return 0;
  257. if (!Bit_Get(YSI_g_sGUITitleUsing, _:Handle))
  258. return -1;
  259. // ---------------------------------------------------------------------
  260. YSI_g_sGUITitleColor[_:Handle] = Color;
  261. // ---------------------------------------------------------------------
  262. return 1;
  263. }
  264. #define GUI_Title_GetColour GUI_Title_GetColor
  265. stock
  266. GUI_Title_GetColor(GUI: Handle, &Color)
  267. {
  268. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  269. return 0;
  270. if (!Bit_Get(YSI_g_sGUITitleUsing, _:Handle))
  271. return -1;
  272. // ---------------------------------------------------------------------
  273. Color = YSI_g_sGUITitleColor[_:Handle];
  274. // ---------------------------------------------------------------------
  275. return 1;
  276. }
  277. /*----------------------------------------------------------------------------*/
  278. stock
  279. GUI_Title_Box(GUI: Handle, bool: Use)
  280. {
  281. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  282. return 0;
  283. if (!Bit_Get(YSI_g_sGUITitleUsing, _:Handle))
  284. return -1;
  285. // ---------------------------------------------------------------------
  286. if (Use)
  287. {
  288. Bit_Let(YSI_g_sGUITitleBox, _:Handle);
  289. }
  290. else
  291. {
  292. Bit_Vet(YSI_g_sGUITitleBox, _:Handle);
  293. }
  294. // ---------------------------------------------------------------------
  295. return 1;
  296. }
  297. /*----------------------------------------------------------------------------*/
  298. stock
  299. GUI_Title_SetBPos(GUI: Handle, Float: posX, Float: posY)
  300. {
  301. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  302. return 0;
  303. if (!Bit_Get(YSI_g_sGUITitleUsing, _:Handle))
  304. return -1;
  305. if (!Bit_Get(YSI_g_sGUITitleBox, _:Handle))
  306. return -2;
  307. // ---------------------------------------------------------------------
  308. YSI_g_sGUITitleBPos[_:Handle][0] = posX;
  309. YSI_g_sGUITitleBPos[_:Handle][1] = posY;
  310. // ---------------------------------------------------------------------
  311. return 1;
  312. }
  313. stock
  314. GUI_Title_GetBPos(GUI: Handle, &Float: posX, &Float: posY)
  315. {
  316. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  317. return 0;
  318. if (!Bit_Get(YSI_g_sGUITitleUsing, _:Handle))
  319. return -1;
  320. if (!Bit_Get(YSI_g_sGUITitleBox, _:Handle))
  321. return -2;
  322. // ---------------------------------------------------------------------
  323. posX = YSI_g_sGUITitleBPos[_:Handle][0];
  324. posY = YSI_g_sGUITitleBPos[_:Handle][1];
  325. // ---------------------------------------------------------------------
  326. return 1;
  327. }
  328. /*----------------------------------------------------------------------------*/
  329. stock
  330. GUI_Title_SetBSize(GUI: Handle, Float: sizeX, Float: sizeY)
  331. {
  332. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  333. return 0;
  334. if (!Bit_Get(YSI_g_sGUITitleUsing, _:Handle))
  335. return -1;
  336. if (!Bit_Get(YSI_g_sGUITitleBox, _:Handle))
  337. return -2;
  338. // ---------------------------------------------------------------------
  339. YSI_g_sGUITitleBSize[_:Handle][0] = sizeX;
  340. YSI_g_sGUITitleBSize[_:Handle][1] = sizeY;
  341. // ---------------------------------------------------------------------
  342. return 1;
  343. }
  344. stock
  345. GUI_Title_GetBSize(GUI: Handle, &Float: sizeX, &Float: sizeY)
  346. {
  347. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  348. return 0;
  349. if (!Bit_Get(YSI_g_sGUITitleUsing, _:Handle))
  350. return -1;
  351. if (!Bit_Get(YSI_g_sGUITitleBox, _:Handle))
  352. return -2;
  353. // ---------------------------------------------------------------------
  354. sizeX = YSI_g_sGUITitleBSize[_:Handle][0];
  355. sizeY = YSI_g_sGUITitleBSize[_:Handle][1];
  356. // ---------------------------------------------------------------------
  357. return 1;
  358. }
  359. /*----------------------------------------------------------------------------*/
  360. #define GUI_Title_SetBackgroundColor GUI_Title_SetBColor
  361. #define GUI_Title_SetBackgroundColour GUI_Title_SetBColor
  362. #define GUI_Title_SetBColour GUI_Title_SetBColor
  363. stock
  364. GUI_Title_SetBColor(GUI: Handle, Color)
  365. {
  366. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  367. return 0;
  368. if (!Bit_Get(YSI_g_sGUITitleUsing, _:Handle))
  369. return -1;
  370. if (!Bit_Get(YSI_g_sGUITitleBox, _:Handle))
  371. return -2;
  372. // ---------------------------------------------------------------------
  373. YSI_g_sGUITitleBColor[_:Handle] = Color;
  374. // ---------------------------------------------------------------------
  375. return 1;
  376. }
  377. #define GUI_Title_GetBackgroundColor GUI_Title_GetBColor
  378. #define GUI_Title_GetBackgroundColour GUI_Title_GetBColor
  379. #define GUI_Title_GetBColour GUI_Title_GetBColor
  380. stock
  381. GUI_Title_GetBColor(GUI: Handle, &Color)
  382. {
  383. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  384. return 0;
  385. if (!Bit_Get(YSI_g_sGUITitleUsing, _:Handle))
  386. return -1;
  387. if (!Bit_Get(YSI_g_sGUITitleBox, _:Handle))
  388. return -2;
  389. // ---------------------------------------------------------------------
  390. Color = YSI_g_sGUITitleBColor[_:Handle];
  391. // ---------------------------------------------------------------------
  392. return 1;
  393. }
  394. /*----------------------------------------------------------------------------*/
  395. stock
  396. GUI_Item_Use(GUI: Handle, ItemID, bool: Use)
  397. {
  398. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  399. return 0;
  400. // ---------------------------------------------------------------------
  401. if (Use)
  402. {
  403. Bit_Let(YSI_g_sGUIItemUsing[_:Handle], ItemID);
  404. }
  405. else
  406. {
  407. Bit_Vet(YSI_g_sGUIItemUsing[_:Handle], ItemID);
  408. }
  409. // ---------------------------------------------------------------------
  410. return 1;
  411. }
  412. /*----------------------------------------------------------------------------*/
  413. stock
  414. GUI_Item_SetText(GUI: Handle, ItemID, Text[])
  415. {
  416. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  417. return 0;
  418. if (!Bit_Get(YSI_g_sGUIItemUsing[_:Handle], ItemID))
  419. return -1;
  420. // ---------------------------------------------------------------------
  421. strpack(YSI_g_sGUIItemText[_:Handle][ItemID], Text, MAX_GUI_ELEMENTS_LENGTH);
  422. // ---------------------------------------------------------------------
  423. return 1;
  424. }
  425. stock
  426. GUI_Item_GetText(GUI: Handle, ItemID, Dest[])
  427. {
  428. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  429. return 0;
  430. if (!Bit_Get(YSI_g_sGUIItemUsing[_:Handle], ItemID))
  431. return -1;
  432. // ---------------------------------------------------------------------
  433. strunpack(Dest, YSI_g_sGUIItemText, MAX_GUI_ELEMENTS_LENGTH);
  434. // ---------------------------------------------------------------------
  435. return 1;
  436. }
  437. /*----------------------------------------------------------------------------*/
  438. stock
  439. GUI_Item_SetPos(GUI: Handle, ItemID, Float: posX, Float: posY)
  440. {
  441. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  442. return 0;
  443. if (!Bit_Get(YSI_g_sGUIItemUsing[_:Handle], ItemID))
  444. return -1;
  445. // ---------------------------------------------------------------------
  446. YSI_g_sGUIItemPos[_:Handle][ItemID][0] = posX;
  447. YSI_g_sGUIItemPos[_:Handle][ItemID][1] = posY;
  448. // ---------------------------------------------------------------------
  449. return 1;
  450. }
  451. stock
  452. GUI_Item_GetPos(GUI: Handle, ItemID, &Float: posX, &Float: posY)
  453. {
  454. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  455. return 0;
  456. if (!Bit_Get(YSI_g_sGUIItemUsing[_:Handle], ItemID))
  457. return -1;
  458. // ---------------------------------------------------------------------
  459. posX = YSI_g_sGUIItemPos[_:Handle][ItemID][0];
  460. posY = YSI_g_sGUIItemPos[_:Handle][ItemID][1];
  461. // ---------------------------------------------------------------------
  462. return 1;
  463. }
  464. /*----------------------------------------------------------------------------*/
  465. stock
  466. GUI_Item_SetSize(GUI: Handle, ItemID, Float: sizeX, Float: sizeY)
  467. {
  468. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  469. return 0;
  470. if (!Bit_Get(YSI_g_sGUIItemUsing[_:Handle], ItemID))
  471. return -1;
  472. // ---------------------------------------------------------------------
  473. YSI_g_sGUIItemSize[_:Handle][ItemID][0] = sizeX;
  474. YSI_g_sGUIItemSize[_:Handle][ItemID][1] = sizeY;
  475. // ---------------------------------------------------------------------
  476. return 1;
  477. }
  478. stock
  479. GUI_Item_GetSize(GUI: Handle, ItemID, &Float: sizeX, &Float: sizeY)
  480. {
  481. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  482. return 0;
  483. if (!Bit_Get(YSI_g_sGUIItemUsing[_:Handle], ItemID))
  484. return -1;
  485. // ---------------------------------------------------------------------
  486. sizeX = YSI_g_sGUIItemSize[_:Handle][ItemID][0];
  487. sizeY = YSI_g_sGUIItemSize[_:Handle][ItemID][1];
  488. // ---------------------------------------------------------------------
  489. return 1;
  490. }
  491. /*----------------------------------------------------------------------------*/
  492. stock
  493. GUI_Item_SetBSize(GUI: Handle, ItemID, Float: size)
  494. {
  495. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  496. return 0;
  497. if (!Bit_Get(YSI_g_sGUIItemUsing[_:Handle], ItemID))
  498. return -1;
  499. // ---------------------------------------------------------------------
  500. YSI_g_sGUIItemBSize[_:Handle][ItemID] = size;
  501. // ---------------------------------------------------------------------
  502. return 1;
  503. }
  504. stock
  505. GUI_Item_GetBSize(GUI: Handle, ItemID, &Float: size)
  506. {
  507. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  508. return 0;
  509. if (!Bit_Get(YSI_g_sGUIItemUsing[_:Handle], ItemID))
  510. return -1;
  511. // ---------------------------------------------------------------------
  512. size = YSI_g_sGUIItemBSize[_:Handle][ItemID];
  513. // ---------------------------------------------------------------------
  514. return 1;
  515. }
  516. /*----------------------------------------------------------------------------*/
  517. #define GUI_Item_SetColour GUI_Item_SetColor
  518. stock
  519. GUI_Item_SetColor(GUI: Handle, ItemID, Color)
  520. {
  521. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  522. return 0;
  523. if (!Bit_Get(YSI_g_sGUIItemUsing[_:Handle], ItemID))
  524. return -1;
  525. // ---------------------------------------------------------------------
  526. YSI_g_sGUIItemColor[_:Handle][ItemID] = Color;
  527. // ---------------------------------------------------------------------
  528. return 1;
  529. }
  530. #define GUI_Item_GetColour GUI_Item_GetColor
  531. stock
  532. GUI_Item_GetColor(GUI: Handle, ItemID, &Color)
  533. {
  534. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  535. return 0;
  536. if (!Bit_Get(YSI_g_sGUIItemUsing[_:Handle], ItemID))
  537. return -1;
  538. // ---------------------------------------------------------------------
  539. Color = YSI_g_sGUIItemColor[_:Handle][ItemID];
  540. // ---------------------------------------------------------------------
  541. return 1;
  542. }
  543. /*----------------------------------------------------------------------------*/
  544. #define GUI_Item_SetBColor GUI_Item_SetBackgroundColor
  545. #define GUI_Item_SetBColour GUI_Item_SetBackgroundColor
  546. #define GUI_Item_SetBackgroundColour GUI_Item_SetBackgroundColor
  547. stock
  548. GUI_Item_SetBackgroundColor(GUI: Handle, ItemID, Color)
  549. {
  550. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  551. return 0;
  552. if (!Bit_Get(YSI_g_sGUIItemUsing[_:Handle], ItemID))
  553. return -1;
  554. // ---------------------------------------------------------------------
  555. YSI_g_sGUIItemBColor[_:Handle][ItemID] = Color;
  556. // ---------------------------------------------------------------------
  557. return 1;
  558. }
  559. #define GUI_Item_GetBColor GUI_Item_GetBackgroundColor
  560. #define GUI_Item_GetBColour GUI_Item_GetBackgroundColor
  561. #define GUI_Item_GetBackgroundColour GUI_Item_GetBackgroundColor
  562. stock
  563. GUI_Item_GetBackgroundColor(GUI: Handle, ItemID, &Color)
  564. {
  565. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  566. return 0;
  567. if (!Bit_Get(YSI_g_sGUIItemUsing[_:Handle], ItemID))
  568. return -1;
  569. // ---------------------------------------------------------------------
  570. Color = YSI_g_sGUIItemBColor[_:Handle][ItemID];
  571. // ---------------------------------------------------------------------
  572. return 1;
  573. }
  574. /*----------------------------------------------------------------------------*/
  575. stock
  576. GUI_Update(GUI: Handle)
  577. {
  578. if (!Bit_Get(YSI_g_sGUIBeingUsed, _:Handle))
  579. return 0;
  580. // ---------------------------------------------------------------------
  581. if (Bit_Get(YSI_g_sGUITitleUsing, _:Handle))
  582. {
  583. new
  584. szString[64];
  585. strunpack(szString, YSI_g_sGUITitleText[_:Handle]);
  586. // Creating the textdraw -------------------------------------------
  587. YSI_g_sGUITextTitle[_:Handle][0] = TextDrawCreate(
  588. YSI_g_sGUITitlePos[_:Handle][0],
  589. YSI_g_sGUITitlePos[_:Handle][1],
  590. szString
  591. );
  592. // Text size -------------------------------------------------------
  593. TextDrawLetterSize(
  594. YSI_g_sGUITextTitle[_:Handle][0],
  595. YSI_g_sGUITitleSize[_:Handle][0],
  596. YSI_g_sGUITitleSize[_:Handle][1]
  597. );
  598. // Text color ------------------------------------------------------
  599. TextDrawColor(
  600. YSI_g_sGUITextTitle[_:Handle][0],
  601. YSI_g_sGUITitleColor[_:Handle]
  602. );
  603. }
  604. // ---------------------------------------------------------------------
  605. if (Bit_Get(YSI_g_sGUITitleBox, _:Handle))
  606. {
  607. // Creating the box ------------------------------------------------
  608. YSI_g_sGUITextTitle[_:Handle][1] = TextDrawCreate(
  609. YSI_g_sGUITitleBPos[_:Handle][0],
  610. YSI_g_sGUITitleBPos[_:Handle][1],
  611. "_"
  612. );
  613. // Use box ---------------------------------------------------------
  614. TextDrawUseBox(
  615. YSI_g_sGUITextTitle[_:Handle][1],
  616. 1
  617. );
  618. // Box size --------------------------------------------------------
  619. TextDrawTextSize(
  620. YSI_g_sGUITextTitle[_:Handle][1],
  621. YSI_g_sGUITitleBPos[_:Handle][0] + YSI_g_sGUITitleBSize[_:Handle][0],
  622. 0.0
  623. );
  624. TextDrawLetterSize(
  625. YSI_g_sGUITextTitle[_:Handle][1],
  626. 1.0,
  627. YSI_g_sGUITitleBSize[_:Handle][0] * 0.112957 // MAYBE this value isn't perfect
  628. );
  629. // Box color -------------------------------------------------------
  630. TextDrawBoxColor(
  631. YSI_g_sGUITextTitle[_:Handle][1],
  632. YSI_g_sGUITitleBColor[_:Handle]
  633. );
  634. }
  635. // ---------------------------------------------------------------------
  636. new
  637. szString[64];
  638. for (new Pos; Pos < MAX_GUIS; Pos ++)
  639. {
  640. if (Bit_Get(YSI_g_sGUIItemUsing[_:Handle], Pos))
  641. {
  642. strunpack(szString, YSI_g_sGUIItemText[_:Handle][Pos]);
  643. // Create the textdraw -----------------------------------------
  644. YSI_g_sGUITextButton[_:Handle][Pos] = TextDrawCreate(
  645. YSI_g_sGUIItemPos[_:Handle][Pos][0],
  646. YSI_g_sGUIItemPos[_:Handle][Pos][1],
  647. szString);
  648. // Alignment ---------------------------------------------------
  649. TextDrawAlignment(
  650. YSI_g_sGUITextButton[_:Handle][Pos],
  651. 2
  652. );
  653. // Size --------------------------------------------------------
  654. TextDrawLetterSize(
  655. YSI_g_sGUITextButton[_:Handle][Pos],
  656. YSI_g_sGUIItemSize[_:Handle][Pos][0],
  657. YSI_g_sGUIItemSize[_:Handle][Pos][1]
  658. );
  659. // Color -------------------------------------------------------
  660. TextDrawColor(
  661. YSI_g_sGUITextButton[_:Handle][Pos],
  662. YSI_g_sGUIItemColor[_:Handle][Pos]
  663. );
  664. // Use box -----------------------------------------------------
  665. TextDrawUseBox(
  666. YSI_g_sGUITextButton[_:Handle][Pos],
  667. 1
  668. );
  669. // Box size ----------------------------------------------------
  670. TextDrawTextSize(
  671. YSI_g_sGUITextButton[_:Handle][Pos],
  672. 0.0,
  673. YSI_g_sGUIItemBSize[_:Handle][Pos]
  674. );
  675. // Box color ---------------------------------------------------
  676. TextDrawBoxColor(
  677. YSI_g_sGUITextButton[_:Handle][Pos],
  678. YSI_g_sGUIItemBColor[_:Handle][Pos]
  679. );
  680. }
  681. }
  682. // ---------------------------------------------------------------------
  683. return 1;
  684. }
  685. /*-----------------------------------------*/