y_gui.inc 25 KB

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