1
0

progress2.inc 24 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387
  1. /*==============================================================================
  2. Progress Bar 2.1.4
  3. A SA:MP UI library for rendering progress bars used to visualise all
  4. manner of data from health to a countdown timer.
  5. Library originally written by Flávio Toribio: flavio_toribio@hotmail.com
  6. Now maintained by Southclaw in version 2+ with new features.
  7. ==============================================================================*/
  8. #if defined _progress2_included
  9. #endinput
  10. #endif
  11. #if !defined _samp_included
  12. #tryinclude <a_samp>
  13. #if !defined _samp_included
  14. #error could not locate a_samp.inc file, please check your server includes
  15. #endif
  16. #endif
  17. #if !defined PB_DEBUG
  18. #define PB_DEBUG (false)
  19. #endif
  20. #define _progress2_included
  21. #define _progress2_version 0x211
  22. #define MAX_PLAYER_BARS (MAX_PLAYER_TEXT_DRAWS / 3)
  23. #define INVALID_PLAYER_BAR_VALUE (Float:0xFFFFFFFF)
  24. #define INVALID_PLAYER_BAR_ID (PlayerBar:-1)
  25. #if PB_DEBUG == true
  26. #define pb_debug(%0); printf(%0);
  27. #else
  28. #define pb_debug(%0);
  29. #endif
  30. /*==============================================================================
  31. Setup
  32. ==============================================================================*/
  33. enum
  34. {
  35. BAR_DIRECTION_RIGHT,
  36. BAR_DIRECTION_LEFT,
  37. BAR_DIRECTION_UP,
  38. BAR_DIRECTION_DOWN
  39. }
  40. enum E_BAR_DATA
  41. {
  42. bool: pbar_show,
  43. Float: pbar_posX,
  44. Float: pbar_posY,
  45. Float: pbar_width,
  46. Float: pbar_height,
  47. pbar_colour,
  48. Float: pbar_maxValue,
  49. Float: pbar_progressValue,
  50. pbar_direction
  51. }
  52. enum E_BAR_TEXT_DRAW
  53. {
  54. PlayerText: pbar_back,
  55. PlayerText: pbar_fill,
  56. PlayerText: pbar_main
  57. }
  58. static
  59. pbar_Data[MAX_PLAYERS][MAX_PLAYER_BARS][E_BAR_DATA],
  60. pbar_TextDraw[MAX_PLAYERS][MAX_PLAYER_BARS][E_BAR_TEXT_DRAW];
  61. #if defined _Y_ITERATE_LOCAL_VERSION
  62. new Iterator:pbar_Index[MAX_PLAYERS]<MAX_PLAYER_BARS>;
  63. #else
  64. static bool:pbar_Valid[MAX_PLAYERS][MAX_PLAYER_BARS];
  65. #endif
  66. forward PlayerBar:CreatePlayerProgressBar(playerid, Float:x, Float:y, Float:width=55.5, Float:height=3.2, colour = 0xFF1C1CFF, Float:max=100.0, direction=BAR_DIRECTION_RIGHT);
  67. forward Float:GetPlayerProgressBarValue(playerid, PlayerBar:barid);
  68. /*==============================================================================
  69. Utils
  70. ==============================================================================*/
  71. stock Float:_bar_percent(Float:x, Float:widthorheight, Float:max, Float:value, direction)
  72. {
  73. new Float:result;
  74. switch(direction)
  75. {
  76. case BAR_DIRECTION_RIGHT:
  77. result = ((x - 3.0) + (((((x - 2.0) + widthorheight) - x) / max) * value));
  78. case BAR_DIRECTION_LEFT:
  79. result = ((x - 1.0) - (((((x + 2.0) - widthorheight) - x) / max) * -value)) - 4.0;
  80. case BAR_DIRECTION_UP:
  81. result = -((((((widthorheight / 10.0) - 0.45) * 1.02) / max) * value) + 0.55);
  82. case BAR_DIRECTION_DOWN:
  83. result = ((((((widthorheight / 10.0) - 0.45) * 1.02) / max) * value) - 0.55);
  84. }
  85. return result;
  86. }
  87. stock _bar_NewID(playerid)
  88. {
  89. #if defined _Y_ITERATE_LOCAL_VERSION
  90. return Iter_Free(pbar_Index[playerid]);
  91. #else
  92. new i;
  93. for(i = 0; i < MAX_PLAYER_BARS; i++)
  94. {
  95. if(!pbar_Valid[playerid][i])
  96. break;
  97. }
  98. return (i == MAX_PLAYER_BARS) ? -1 : i;
  99. #endif
  100. }
  101. /*==============================================================================
  102. Core
  103. ==============================================================================*/
  104. stock PlayerBar:CreatePlayerProgressBar(playerid, Float:x, Float:y, Float:width = 55.5, Float:height = 3.2, colour = 0xFF1C1CFF, Float:max = 100.0, direction = BAR_DIRECTION_RIGHT)
  105. {
  106. if(!IsPlayerConnected(playerid))
  107. return INVALID_PLAYER_BAR_ID;
  108. new barid = _bar_NewID(playerid);
  109. if(barid == -1)
  110. {
  111. print("[CreatePlayerProgressBar] ERROR: MAX_PLAYER_BARS limit reached.");
  112. return INVALID_PLAYER_BAR_ID;
  113. }
  114. pb_debug("[CreatePlayerProgressBar] Creating progress bar %d at %f,%f width:%f height:%f max:%f direction:%d", barid, x, y, width, height, max, direction);
  115. pbar_TextDraw[playerid][barid][pbar_back] = PlayerText:INVALID_TEXT_DRAW;
  116. pbar_TextDraw[playerid][barid][pbar_fill] = PlayerText:INVALID_TEXT_DRAW;
  117. pbar_TextDraw[playerid][barid][pbar_main] = PlayerText:INVALID_TEXT_DRAW;
  118. pbar_Data[playerid][barid][pbar_show] = false;
  119. pbar_Data[playerid][barid][pbar_posX] = x;
  120. pbar_Data[playerid][barid][pbar_posY] = y;
  121. pbar_Data[playerid][barid][pbar_width] = width;
  122. pbar_Data[playerid][barid][pbar_height] = height;
  123. pbar_Data[playerid][barid][pbar_colour] = colour;
  124. pbar_Data[playerid][barid][pbar_maxValue] = max;
  125. pbar_Data[playerid][barid][pbar_progressValue] = 0.0;
  126. pbar_Data[playerid][barid][pbar_direction] = direction;
  127. #if defined _Y_ITERATE_LOCAL_VERSION
  128. Iter_Add(pbar_Index[playerid], barid);
  129. #else
  130. pbar_Valid[playerid][barid] = true;
  131. #endif
  132. _RenderBar(playerid, barid);
  133. return PlayerBar:barid;
  134. }
  135. stock DestroyPlayerProgressBar(playerid, PlayerBar:barid)
  136. {
  137. if(!IsValidPlayerProgressBar(playerid, barid))
  138. return 0;
  139. PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][_:barid][pbar_back]);
  140. PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][_:barid][pbar_fill]);
  141. PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][_:barid][pbar_main]);
  142. #if defined _Y_ITERATE_LOCAL_VERSION
  143. Iter_Remove(pbar_Index[playerid], _:barid);
  144. #else
  145. pbar_Valid[playerid][_:barid] = false;
  146. #endif
  147. return 1;
  148. }
  149. stock ShowPlayerProgressBar(playerid, PlayerBar:barid)
  150. {
  151. if(!IsValidPlayerProgressBar(playerid, barid))
  152. return 0;
  153. pbar_Data[playerid][_:barid][pbar_show] = true;
  154. PlayerTextDrawShow(playerid, pbar_TextDraw[playerid][_:barid][pbar_back]);
  155. PlayerTextDrawShow(playerid, pbar_TextDraw[playerid][_:barid][pbar_fill]);
  156. PlayerTextDrawShow(playerid, pbar_TextDraw[playerid][_:barid][pbar_main]);
  157. return 1;
  158. }
  159. stock HidePlayerProgressBar(playerid, PlayerBar:barid)
  160. {
  161. if(!IsValidPlayerProgressBar(playerid, barid))
  162. return 0;
  163. pbar_Data[playerid][_:barid][pbar_show] = false;
  164. PlayerTextDrawHide(playerid, pbar_TextDraw[playerid][_:barid][pbar_back]);
  165. PlayerTextDrawHide(playerid, pbar_TextDraw[playerid][_:barid][pbar_fill]);
  166. PlayerTextDrawHide(playerid, pbar_TextDraw[playerid][_:barid][pbar_main]);
  167. return 1;
  168. }
  169. /*==============================================================================
  170. Hooks and Internal
  171. ==============================================================================*/
  172. _RenderBar(playerid, barid)
  173. {
  174. if(!IsPlayerConnected(playerid))
  175. return false;
  176. if(!IsValidPlayerProgressBar(playerid, PlayerBar:barid))
  177. return false;
  178. PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][barid][pbar_back]);
  179. PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][barid][pbar_fill]);
  180. PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][barid][pbar_main]);
  181. switch(pbar_Data[playerid][barid][pbar_direction])
  182. {
  183. case BAR_DIRECTION_RIGHT:
  184. {
  185. pbar_TextDraw[playerid][barid][pbar_back] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX], pbar_Data[playerid][barid][pbar_posY], "_");
  186. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1);
  187. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], pbar_Data[playerid][barid][pbar_posX] + pbar_Data[playerid][barid][pbar_width] - 4.0, 0.0);
  188. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1.0, pbar_Data[playerid][barid][pbar_height] / 10);
  189. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_back], 0x00000000 | (pbar_Data[playerid][barid][pbar_colour] & 0x000000FF));
  190. pbar_TextDraw[playerid][barid][pbar_fill] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] + 1.2, pbar_Data[playerid][barid][pbar_posY] + 2.15, "_");
  191. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1);
  192. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], pbar_Data[playerid][barid][pbar_posX] + pbar_Data[playerid][barid][pbar_width] - 5.5, 0.0);
  193. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1.0, pbar_Data[playerid][barid][pbar_height] / 10 - 0.35);
  194. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_fill], (pbar_Data[playerid][barid][pbar_colour] & 0xFFFFFF00) | (0x66 & ((pbar_Data[playerid][barid][pbar_colour] & 0x000000FF) / 2)));
  195. pbar_TextDraw[playerid][barid][pbar_main] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] + 1.2, pbar_Data[playerid][barid][pbar_posY] + 2.15, "_");
  196. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1);
  197. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_main], _bar_percent(pbar_Data[playerid][barid][pbar_posX], pbar_Data[playerid][barid][pbar_width], pbar_Data[playerid][barid][pbar_maxValue], pbar_Data[playerid][barid][pbar_progressValue], pbar_Data[playerid][barid][pbar_direction]), 0.0);
  198. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_main], 1.0, pbar_Data[playerid][barid][pbar_height] / 10 - 0.35);
  199. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_main], pbar_Data[playerid][barid][pbar_colour]);
  200. }
  201. case BAR_DIRECTION_LEFT:
  202. {
  203. pbar_TextDraw[playerid][barid][pbar_back] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX], pbar_Data[playerid][barid][pbar_posY], "_");
  204. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1);
  205. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 4.0, 0.0);
  206. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1.0, pbar_Data[playerid][barid][pbar_height] / 10);
  207. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_back], 0x00000000 | (pbar_Data[playerid][barid][pbar_colour] & 0x000000FF));
  208. pbar_TextDraw[playerid][barid][pbar_fill] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] - 1.2, pbar_Data[playerid][barid][pbar_posY] + 2.15, "_");
  209. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1);
  210. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 2.5, 0.0);
  211. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1.0, pbar_Data[playerid][barid][pbar_height] / 10 - 0.35);
  212. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_fill], (pbar_Data[playerid][barid][pbar_colour] & 0xFFFFFF00) | (0x66 & ((pbar_Data[playerid][barid][pbar_colour] & 0x000000FF) / 2)));
  213. pbar_TextDraw[playerid][barid][pbar_main] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] - 1.2, pbar_Data[playerid][barid][pbar_posY] + 2.15, "_");
  214. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1);
  215. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_main], _bar_percent(pbar_Data[playerid][barid][pbar_posX], pbar_Data[playerid][barid][pbar_width], pbar_Data[playerid][barid][pbar_maxValue], pbar_Data[playerid][barid][pbar_progressValue], pbar_Data[playerid][barid][pbar_direction]), 0.0);
  216. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_main], 1.0, pbar_Data[playerid][barid][pbar_height] / 10 - 0.35);
  217. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_main], pbar_Data[playerid][barid][pbar_colour]);
  218. }
  219. case BAR_DIRECTION_UP:
  220. {
  221. pbar_TextDraw[playerid][barid][pbar_back] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX], pbar_Data[playerid][barid][pbar_posY], "_");
  222. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1);
  223. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 4.0, 0.0);
  224. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1.0, -((pbar_Data[playerid][barid][pbar_height] / 10) * 1.02) -0.35);
  225. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_back], 0x00000000 | (pbar_Data[playerid][barid][pbar_colour] & 0x000000FF));
  226. pbar_TextDraw[playerid][barid][pbar_fill] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] - 1.2, pbar_Data[playerid][barid][pbar_posY] - 1.0, "_");
  227. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1);
  228. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 2.5, 0.0);
  229. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1.0, -(pbar_Data[playerid][barid][pbar_height] / 10.0) * 1.02);
  230. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_fill], (pbar_Data[playerid][barid][pbar_colour] & 0xFFFFFF00) | (0x66 & ((pbar_Data[playerid][barid][pbar_colour] & 0x000000FF) / 2)));
  231. pbar_TextDraw[playerid][barid][pbar_main] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] - 1.2, pbar_Data[playerid][barid][pbar_posY] - 1.0, "_");
  232. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_main], 1);
  233. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_main], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 2.5, 0.0);
  234. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_main], 1.0, _bar_percent(pbar_Data[playerid][_:barid][pbar_posX], pbar_Data[playerid][_:barid][pbar_height], pbar_Data[playerid][_:barid][pbar_maxValue], pbar_Data[playerid][barid][pbar_progressValue], pbar_Data[playerid][barid][pbar_direction]));
  235. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_main], pbar_Data[playerid][barid][pbar_colour]);
  236. }
  237. case BAR_DIRECTION_DOWN:
  238. {
  239. pbar_TextDraw[playerid][barid][pbar_back] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX], pbar_Data[playerid][barid][pbar_posY], "_");
  240. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1);
  241. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 4.0, 0.0);
  242. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1.0, ((pbar_Data[playerid][barid][pbar_height] / 10)) -0.35);
  243. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_back], 0x00000000 | (pbar_Data[playerid][barid][pbar_colour] & 0x000000FF));
  244. pbar_TextDraw[playerid][barid][pbar_fill] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] - 1.2, pbar_Data[playerid][barid][pbar_posY] + 1.0, "_");
  245. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1);
  246. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 2.5, 0.0);
  247. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1.0, (pbar_Data[playerid][barid][pbar_height] / 10.0) - 0.55);
  248. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_fill], (pbar_Data[playerid][barid][pbar_colour] & 0xFFFFFF00) | (0x66 & ((pbar_Data[playerid][barid][pbar_colour] & 0x000000FF) / 2)));
  249. pbar_TextDraw[playerid][barid][pbar_main] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] - 1.2, pbar_Data[playerid][barid][pbar_posY] + 1.0, "_");
  250. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_main], 1);
  251. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_main], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 2.5, 0.0);
  252. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_main], 1.0, _bar_percent(pbar_Data[playerid][_:barid][pbar_posX], pbar_Data[playerid][_:barid][pbar_height], pbar_Data[playerid][_:barid][pbar_maxValue], pbar_Data[playerid][barid][pbar_progressValue], pbar_Data[playerid][barid][pbar_direction]));
  253. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_main], pbar_Data[playerid][barid][pbar_colour]);
  254. }
  255. }
  256. if(pbar_Data[playerid][barid][pbar_show])
  257. ShowPlayerProgressBar(playerid, PlayerBar:barid);
  258. return true;
  259. }
  260. #if defined _Y_ITERATE_LOCAL_VERSION
  261. #if defined FILTERSCRIPT
  262. public OnFilterScriptInit()
  263. {
  264. Iter_Init(pbar_Index);
  265. #if defined ppb_OnFilterScriptInit
  266. return ppb_OnFilterScriptInit();
  267. #else
  268. return 1;
  269. #endif
  270. }
  271. #if defined _ALS_OnFilterScriptInit
  272. #undef OnFilterScriptInit
  273. #else
  274. #define _ALS_OnFilterScriptInit
  275. #endif
  276. #define OnFilterScriptInit ppb_OnFilterScriptInit
  277. #if defined ppb_OnFilterScriptInit
  278. forward ppb_OnFilterScriptInit();
  279. #endif
  280. #else
  281. public OnGameModeInit()
  282. {
  283. Iter_Init(pbar_Index);
  284. #if defined ppb_OnGameModeInit
  285. return ppb_OnGameModeInit();
  286. #else
  287. return 1;
  288. #endif
  289. }
  290. #if defined _ALS_OnGameModeInit
  291. #undef OnGameModeInit
  292. #else
  293. #define _ALS_OnGameModeInit
  294. #endif
  295. #define OnGameModeInit ppb_OnGameModeInit
  296. #if defined ppb_OnGameModeInit
  297. forward ppb_OnGameModeInit();
  298. #endif
  299. #endif
  300. #endif
  301. public OnPlayerDisconnect(playerid, reason)
  302. {
  303. #if defined _Y_ITERATE_LOCAL_VERSION
  304. Iter_Clear(pbar_Index[playerid]);
  305. #else
  306. for(new i; i < MAX_PLAYER_BARS; i++)
  307. pbar_Valid[playerid][_:i] = false;
  308. #endif
  309. #if defined ppb_OnPlayerDisconnect
  310. return ppb_OnPlayerDisconnect(playerid, reason);
  311. #else
  312. return 1;
  313. #endif
  314. }
  315. #if defined _ALS_OnPlayerDisconnect
  316. #undef OnPlayerDisconnect
  317. #else
  318. #define _ALS_OnPlayerDisconnect
  319. #endif
  320. #define OnPlayerDisconnect ppb_OnPlayerDisconnect
  321. #if defined ppb_OnPlayerDisconnect
  322. forward ppb_OnPlayerDisconnect(playerid, reason);
  323. #endif
  324. #if defined FILTERSCRIPT
  325. public OnFilterScriptExit()
  326. {
  327. for(new i = 0; i < MAX_PLAYERS; i++)
  328. {
  329. if(IsPlayerConnected(i))
  330. DestroyAllPlayerProgressBars(i);
  331. }
  332. #if defined ppb_OnFilterScriptExit
  333. return ppb_OnFilterScriptExit();
  334. #else
  335. return 1;
  336. #endif
  337. }
  338. #if defined _ALS_OnFilterScriptExit
  339. #undef OnFilterScriptExit
  340. #else
  341. #define _ALS_OnFilterScriptExit
  342. #endif
  343. #define OnFilterScriptExit ppb_OnFilterScriptExit
  344. #if defined ppb_OnFilterScriptExit
  345. forward ppb_OnFilterScriptExit();
  346. #endif
  347. #else
  348. public OnGameModeExit()
  349. {
  350. for(new i = 0; i < MAX_PLAYERS; i++)
  351. {
  352. if(IsPlayerConnected(i))
  353. DestroyAllPlayerProgressBars(i);
  354. }
  355. #if defined ppb_OnGameModeExit
  356. return ppb_OnGameModeExit();
  357. #else
  358. return 1;
  359. #endif
  360. }
  361. #if defined _ALS_OnGameModeExit
  362. #undef OnGameModeExit
  363. #else
  364. #define _ALS_OnGameModeExit
  365. #endif
  366. #define OnGameModeExit ppb_OnGameModeExit
  367. #if defined ppb_OnGameModeExit
  368. forward ppb_OnGameModeExit();
  369. #endif
  370. #endif
  371. stock DestroyAllPlayerProgressBars(playerid)
  372. {
  373. for(new i = 0; i < MAX_PLAYER_BARS; i++)
  374. DestroyPlayerProgressBar(playerid, PlayerBar:i);
  375. return 1;
  376. }
  377. /*==============================================================================
  378. Interface
  379. ==============================================================================*/
  380. stock IsValidPlayerProgressBar(playerid, PlayerBar:barid)
  381. {
  382. #if defined _Y_ITERATE_LOCAL_VERSION
  383. return Iter_Contains(pbar_Index[playerid], _:barid);
  384. #else
  385. if(!(PlayerBar:0 <= barid < PlayerBar:MAX_PLAYER_BARS))
  386. return false;
  387. return pbar_Valid[playerid][_:barid];
  388. #endif
  389. }
  390. // pbar_posX
  391. // pbar_posY
  392. stock GetPlayerProgressBarPos(playerid, PlayerBar:barid, &Float:x, &Float:y)
  393. {
  394. if(!IsValidPlayerProgressBar(playerid, barid))
  395. return 0;
  396. x = pbar_Data[playerid][_:barid][pbar_posX];
  397. y = pbar_Data[playerid][_:barid][pbar_posY];
  398. return 1;
  399. }
  400. stock SetPlayerProgressBarPos(playerid, PlayerBar:barid, Float:x, Float:y)
  401. {
  402. if(!IsValidPlayerProgressBar(playerid, barid))
  403. return false;
  404. pbar_Data[playerid][_:barid][pbar_posX] = x;
  405. pbar_Data[playerid][_:barid][pbar_posY] = y;
  406. _RenderBar(playerid, _:barid);
  407. return true;
  408. }
  409. // pbar_width
  410. stock Float:GetPlayerProgressBarWidth(playerid, PlayerBar:barid)
  411. {
  412. if(!IsValidPlayerProgressBar(playerid, barid))
  413. return INVALID_PLAYER_BAR_VALUE;
  414. return pbar_Data[playerid][_:barid][pbar_width];
  415. }
  416. stock SetPlayerProgressBarWidth(playerid, PlayerBar:barid, Float:width)
  417. {
  418. if(!IsValidPlayerProgressBar(playerid, barid))
  419. return 0;
  420. pbar_Data[playerid][_:barid][pbar_width] = width;
  421. _RenderBar(playerid, _:barid);
  422. return 1;
  423. }
  424. // pbar_height
  425. stock Float:GetPlayerProgressBarHeight(playerid, PlayerBar:barid)
  426. {
  427. if(!IsValidPlayerProgressBar(playerid, barid))
  428. return INVALID_PLAYER_BAR_VALUE;
  429. return pbar_Data[playerid][_:barid][pbar_height];
  430. }
  431. stock SetPlayerProgressBarHeight(playerid, PlayerBar:barid, Float:height)
  432. {
  433. if(!IsValidPlayerProgressBar(playerid, barid))
  434. return 0;
  435. pbar_Data[playerid][_:barid][pbar_height] = height;
  436. _RenderBar(playerid, _:barid);
  437. return 1;
  438. }
  439. // pbar_colour
  440. stock GetPlayerProgressBarColour(playerid, PlayerBar:barid)
  441. {
  442. if(!IsValidPlayerProgressBar(playerid, barid))
  443. return 0;
  444. return pbar_Data[playerid][_:barid][pbar_colour];
  445. }
  446. stock SetPlayerProgressBarColour(playerid, PlayerBar:barid, colour)
  447. {
  448. if(!IsValidPlayerProgressBar(playerid, barid))
  449. return 0;
  450. pbar_Data[playerid][_:barid][pbar_colour] = colour;
  451. PlayerTextDrawBoxColor(playerid, pbar_TextDraw[playerid][_:barid][pbar_back], 0x00000000 | (colour & 0x000000FF));
  452. PlayerTextDrawBoxColor(playerid, pbar_TextDraw[playerid][_:barid][pbar_fill], (colour & 0xFFFFFF00) | (0x66 & ((colour & 0x000000FF) / 2)));
  453. PlayerTextDrawBoxColor(playerid, pbar_TextDraw[playerid][_:barid][pbar_main], colour);
  454. return 1;
  455. }
  456. // pbar_maxValue
  457. stock Float:GetPlayerProgressBarMaxValue(playerid, PlayerBar:barid)
  458. {
  459. if(!IsValidPlayerProgressBar(playerid, barid))
  460. return INVALID_PLAYER_BAR_VALUE;
  461. return pbar_Data[playerid][_:barid][pbar_maxValue];
  462. }
  463. stock SetPlayerProgressBarMaxValue(playerid, PlayerBar:barid, Float:max)
  464. {
  465. if(!IsValidPlayerProgressBar(playerid, barid))
  466. return 0;
  467. pbar_Data[playerid][_:barid][pbar_maxValue] = max;
  468. SetPlayerProgressBarValue(playerid, barid, pbar_Data[playerid][_:barid][pbar_progressValue]);
  469. return 1;
  470. }
  471. // pbar_progressValue
  472. stock SetPlayerProgressBarValue(playerid, PlayerBar:barid, Float:value)
  473. {
  474. if(!IsValidPlayerProgressBar(playerid, barid))
  475. return 0;
  476. value = (value < 0.0) ? (0.0) : (value > pbar_Data[playerid][_:barid][pbar_maxValue]) ? (pbar_Data[playerid][_:barid][pbar_maxValue]) : (value);
  477. PlayerTextDrawUseBox(playerid, pbar_TextDraw[playerid][_:barid][pbar_main], value > 0.0);
  478. pbar_Data[playerid][_:barid][pbar_progressValue] = value;
  479. switch(pbar_Data[playerid][_:barid][pbar_direction])
  480. {
  481. case BAR_DIRECTION_RIGHT, BAR_DIRECTION_LEFT:
  482. {
  483. PlayerTextDrawTextSize(playerid, pbar_TextDraw[playerid][_:barid][pbar_main],
  484. _bar_percent(
  485. pbar_Data[playerid][_:barid][pbar_posX],
  486. pbar_Data[playerid][_:barid][pbar_width],
  487. pbar_Data[playerid][_:barid][pbar_maxValue],
  488. value,
  489. pbar_Data[playerid][_:barid][pbar_direction]), 0.0);
  490. }
  491. case BAR_DIRECTION_UP, BAR_DIRECTION_DOWN:
  492. {
  493. PlayerTextDrawLetterSize(playerid, pbar_TextDraw[playerid][_:barid][pbar_main], 1.0,
  494. _bar_percent(
  495. pbar_Data[playerid][_:barid][pbar_posX],
  496. pbar_Data[playerid][_:barid][pbar_height],
  497. pbar_Data[playerid][_:barid][pbar_maxValue],
  498. value,
  499. pbar_Data[playerid][_:barid][pbar_direction]));
  500. }
  501. }
  502. if(pbar_Data[playerid][_:barid][pbar_show])
  503. ShowPlayerProgressBar(playerid, barid);
  504. return 1;
  505. }
  506. stock Float:GetPlayerProgressBarValue(playerid, PlayerBar:barid)
  507. {
  508. if(!IsValidPlayerProgressBar(playerid, barid))
  509. return INVALID_PLAYER_BAR_VALUE;
  510. return pbar_Data[playerid][_:barid][pbar_progressValue];
  511. }
  512. // pbar_direction
  513. stock GetPlayerProgressBarDirection(playerid, PlayerBar:barid)
  514. {
  515. if(!IsValidPlayerProgressBar(playerid, barid))
  516. return 0;
  517. return pbar_Data[playerid][_:barid][pbar_direction];
  518. }
  519. stock SetPlayerProgressBarDirection(playerid, PlayerBar:barid, direction)
  520. {
  521. if(!IsValidPlayerProgressBar(playerid, barid))
  522. return 0;
  523. pbar_Data[playerid][_:barid][pbar_direction] = direction;
  524. _RenderBar(playerid, _:barid);
  525. return 1;
  526. }