progress2.inc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. /*==============================================================================
  2. Progress Bar 2.0.3
  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. Float: pbar_posX,
  43. Float: pbar_posY,
  44. Float: pbar_width,
  45. Float: pbar_height,
  46. pbar_colour,
  47. Float: pbar_maxValue,
  48. Float: pbar_progressValue,
  49. pbar_direction
  50. }
  51. enum E_BAR_TEXT_DRAW
  52. {
  53. PlayerText: pbar_back,
  54. PlayerText: pbar_fill,
  55. PlayerText: pbar_main
  56. }
  57. static
  58. pbar_Data[MAX_PLAYERS][MAX_PLAYER_BARS][E_BAR_DATA],
  59. pbar_TextDraw[MAX_PLAYERS][MAX_PLAYER_BARS][E_BAR_TEXT_DRAW];
  60. #if defined _Y_ITERATE_LOCAL_VERSION
  61. new Iterator:pbar_Index[MAX_PLAYERS]<MAX_PLAYER_BARS>;
  62. #else
  63. static bool:pbar_Valid[MAX_PLAYERS][MAX_PLAYER_BARS];
  64. #endif
  65. 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);
  66. forward Float:GetPlayerProgressBarValue(playerid, PlayerBar:barid);
  67. /*==============================================================================
  68. Utils
  69. ==============================================================================*/
  70. stock Float:pb_percent(Float:x, Float:widthorheight, Float:max, Float:value, direction)
  71. {
  72. new Float:result;
  73. switch(direction)
  74. {
  75. case BAR_DIRECTION_RIGHT:
  76. result = ((x - 3.0) + (((((x - 2.0) + widthorheight) - x) / max) * value));
  77. case BAR_DIRECTION_LEFT:
  78. result = ((x - 1.0) - (((((x + 2.0) - widthorheight) - x) / max) * -value)) - 4.0;
  79. case BAR_DIRECTION_UP:
  80. result = -((((((widthorheight / 10.0) - 0.45) * 1.02) / max) * value) + 0.55);
  81. case BAR_DIRECTION_DOWN:
  82. result = ((((((widthorheight / 10.0) - 0.45) * 1.02) / max) * value) - 0.55);
  83. }
  84. return result;
  85. }
  86. stock _bar_NewID(playerid)
  87. {
  88. #if defined _Y_ITERATE_LOCAL_VERSION
  89. return Iter_Free(pbar_Index[playerid]);
  90. #else
  91. new i;
  92. for(i = 0; i < MAX_PLAYER_BARS; i++)
  93. {
  94. if(!pbar_Valid[playerid][i])
  95. break;
  96. }
  97. return (i == MAX_PLAYER_BARS) ? -1 : i;
  98. #endif
  99. }
  100. /*==============================================================================
  101. Core
  102. ==============================================================================*/
  103. 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)
  104. {
  105. if(!IsPlayerConnected(playerid))
  106. return INVALID_PLAYER_BAR_ID;
  107. new barid = _bar_NewID(playerid);
  108. if(barid == -1)
  109. {
  110. print("[CreatePlayerProgressBar] ERROR: MAX_PLAYER_BARS limit reached.");
  111. return INVALID_PLAYER_BAR_ID;
  112. }
  113. 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);
  114. pbar_TextDraw[playerid][barid][pbar_back] = PlayerText:INVALID_TEXT_DRAW;
  115. pbar_TextDraw[playerid][barid][pbar_fill] = PlayerText:INVALID_TEXT_DRAW;
  116. pbar_TextDraw[playerid][barid][pbar_main] = PlayerText:INVALID_TEXT_DRAW;
  117. pbar_Data[playerid][barid][pbar_posX] = x;
  118. pbar_Data[playerid][barid][pbar_posY] = y;
  119. pbar_Data[playerid][barid][pbar_width] = width;
  120. pbar_Data[playerid][barid][pbar_height] = height;
  121. pbar_Data[playerid][barid][pbar_colour] = colour;
  122. pbar_Data[playerid][barid][pbar_maxValue] = max;
  123. pbar_Data[playerid][barid][pbar_progressValue] = 0.0;
  124. pbar_Data[playerid][barid][pbar_direction] = direction;
  125. #if defined _Y_ITERATE_LOCAL_VERSION
  126. Iter_Add(pbar_Index[playerid], barid);
  127. #else
  128. pbar_Valid[playerid][barid] = true;
  129. #endif
  130. _RenderBar(playerid, barid);
  131. return PlayerBar:barid;
  132. }
  133. stock DestroyPlayerProgressBar(playerid, PlayerBar:barid)
  134. {
  135. if(!IsValidPlayerProgressBar(playerid, barid))
  136. return 0;
  137. PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][_:barid][pbar_back]);
  138. PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][_:barid][pbar_fill]);
  139. PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][_:barid][pbar_main]);
  140. #if defined _Y_ITERATE_LOCAL_VERSION
  141. Iter_Remove(pbar_Index[playerid], _:barid);
  142. #else
  143. pbar_Valid[playerid][_:barid] = false;
  144. #endif
  145. return 1;
  146. }
  147. stock ShowPlayerProgressBar(playerid, PlayerBar:barid)
  148. {
  149. if(!IsValidPlayerProgressBar(playerid, barid))
  150. return 0;
  151. PlayerTextDrawShow(playerid, pbar_TextDraw[playerid][_:barid][pbar_back]);
  152. PlayerTextDrawShow(playerid, pbar_TextDraw[playerid][_:barid][pbar_fill]);
  153. PlayerTextDrawShow(playerid, pbar_TextDraw[playerid][_:barid][pbar_main]);
  154. return 1;
  155. }
  156. stock HidePlayerProgressBar(playerid, PlayerBar:barid)
  157. {
  158. if(!IsValidPlayerProgressBar(playerid, barid))
  159. return 0;
  160. PlayerTextDrawHide(playerid, pbar_TextDraw[playerid][_:barid][pbar_back]);
  161. PlayerTextDrawHide(playerid, pbar_TextDraw[playerid][_:barid][pbar_fill]);
  162. PlayerTextDrawHide(playerid, pbar_TextDraw[playerid][_:barid][pbar_main]);
  163. return 1;
  164. }
  165. /*==============================================================================
  166. Hooks and Internal
  167. ==============================================================================*/
  168. _RenderBar(playerid, barid, update = false)
  169. {
  170. if(!IsPlayerConnected(playerid))
  171. return false;
  172. if(!IsValidPlayerProgressBar(playerid, PlayerBar:barid))
  173. return false;
  174. PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][barid][pbar_back]);
  175. PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][barid][pbar_fill]);
  176. PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][barid][pbar_main]);
  177. switch(pbar_Data[playerid][barid][pbar_direction])
  178. {
  179. case BAR_DIRECTION_RIGHT:
  180. {
  181. pbar_TextDraw[playerid][barid][pbar_back] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX], pbar_Data[playerid][barid][pbar_posY], "_");
  182. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1);
  183. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], pbar_Data[playerid][barid][pbar_posX] + pbar_Data[playerid][barid][pbar_width] - 4.0, 0.0);
  184. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1.0, pbar_Data[playerid][barid][pbar_height] / 10);
  185. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_back], 0x00000000 | (pbar_Data[playerid][barid][pbar_colour] & 0x000000FF));
  186. pbar_TextDraw[playerid][barid][pbar_fill] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] + 1.2, pbar_Data[playerid][barid][pbar_posY] + 2.15, "_");
  187. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1);
  188. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], pbar_Data[playerid][barid][pbar_posX] + pbar_Data[playerid][barid][pbar_width] - 5.5, 0.0);
  189. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1.0, pbar_Data[playerid][barid][pbar_height] / 10 - 0.35);
  190. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_fill], (pbar_Data[playerid][barid][pbar_colour] & 0xFFFFFF00) | (0x66 & ((pbar_Data[playerid][barid][pbar_colour] & 0x000000FF) / 2)));
  191. pbar_TextDraw[playerid][barid][pbar_main] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] + 1.2, pbar_Data[playerid][barid][pbar_posY] + 2.15, "_");
  192. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1);
  193. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_main], pb_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);
  194. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_main], 1.0, pbar_Data[playerid][barid][pbar_height] / 10 - 0.35);
  195. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_main], pbar_Data[playerid][barid][pbar_colour]);
  196. }
  197. case BAR_DIRECTION_LEFT:
  198. {
  199. pbar_TextDraw[playerid][barid][pbar_back] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX], pbar_Data[playerid][barid][pbar_posY], "_");
  200. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1);
  201. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 4.0, 0.0);
  202. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1.0, pbar_Data[playerid][barid][pbar_height] / 10);
  203. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_back], 0x00000000 | (pbar_Data[playerid][barid][pbar_colour] & 0x000000FF));
  204. pbar_TextDraw[playerid][barid][pbar_fill] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] - 1.2, pbar_Data[playerid][barid][pbar_posY] + 2.15, "_");
  205. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1);
  206. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 2.5, 0.0);
  207. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1.0, pbar_Data[playerid][barid][pbar_height] / 10 - 0.35);
  208. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_fill], (pbar_Data[playerid][barid][pbar_colour] & 0xFFFFFF00) | (0x66 & ((pbar_Data[playerid][barid][pbar_colour] & 0x000000FF) / 2)));
  209. pbar_TextDraw[playerid][barid][pbar_main] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] - 1.2, pbar_Data[playerid][barid][pbar_posY] + 2.15, "_");
  210. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1);
  211. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_main], pb_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);
  212. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_main], 1.0, pbar_Data[playerid][barid][pbar_height] / 10 - 0.35);
  213. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_main], pbar_Data[playerid][barid][pbar_colour]);
  214. }
  215. case BAR_DIRECTION_UP:
  216. {
  217. pbar_TextDraw[playerid][barid][pbar_back] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX], pbar_Data[playerid][barid][pbar_posY], "_");
  218. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1);
  219. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 4.0, 0.0);
  220. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1.0, -((pbar_Data[playerid][barid][pbar_height] / 10) * 1.02) -0.35);
  221. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_back], 0x00000000 | (pbar_Data[playerid][barid][pbar_colour] & 0x000000FF));
  222. pbar_TextDraw[playerid][barid][pbar_fill] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] - 1.2, pbar_Data[playerid][barid][pbar_posY] - 1.0, "_");
  223. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1);
  224. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 2.5, 0.0);
  225. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1.0, -(pbar_Data[playerid][barid][pbar_height] / 10.0) * 1.02);
  226. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_fill], (pbar_Data[playerid][barid][pbar_colour] & 0xFFFFFF00) | (0x66 & ((pbar_Data[playerid][barid][pbar_colour] & 0x000000FF) / 2)));
  227. pbar_TextDraw[playerid][barid][pbar_main] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] - 1.2, pbar_Data[playerid][barid][pbar_posY] - 1.0, "_");
  228. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_main], 1);
  229. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_main], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 2.5, 0.0);
  230. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_main], 1.0, pb_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]));
  231. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_main], pbar_Data[playerid][barid][pbar_colour]);
  232. }
  233. case BAR_DIRECTION_DOWN:
  234. {
  235. pbar_TextDraw[playerid][barid][pbar_back] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX], pbar_Data[playerid][barid][pbar_posY], "_");
  236. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1);
  237. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 4.0, 0.0);
  238. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1.0, ((pbar_Data[playerid][barid][pbar_height] / 10)) -0.35);
  239. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_back], 0x00000000 | (pbar_Data[playerid][barid][pbar_colour] & 0x000000FF));
  240. pbar_TextDraw[playerid][barid][pbar_fill] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] - 1.2, pbar_Data[playerid][barid][pbar_posY] + 1.0, "_");
  241. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1);
  242. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 2.5, 0.0);
  243. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1.0, (pbar_Data[playerid][barid][pbar_height] / 10.0) - 0.55);
  244. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_fill], (pbar_Data[playerid][barid][pbar_colour] & 0xFFFFFF00) | (0x66 & ((pbar_Data[playerid][barid][pbar_colour] & 0x000000FF) / 2)));
  245. pbar_TextDraw[playerid][barid][pbar_main] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] - 1.2, pbar_Data[playerid][barid][pbar_posY] + 1.0, "_");
  246. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_main], 1);
  247. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_main], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 2.5, 0.0);
  248. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_main], 1.0, pb_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]));
  249. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_main], pbar_Data[playerid][barid][pbar_colour]);
  250. }
  251. }
  252. if(update)
  253. ShowPlayerProgressBar(playerid, PlayerBar:barid);
  254. return true;
  255. }
  256. #if defined _Y_ITERATE_LOCAL_VERSION
  257. #if defined FILTERSCRIPT
  258. public OnFilterScriptInit()
  259. {
  260. Iter_Init(pbar_Index);
  261. #if defined ppb_OnFilterScriptInit
  262. return ppb_OnFilterScriptInit();
  263. #else
  264. return 1;
  265. #endif
  266. }
  267. #if defined _ALS_OnFilterScriptInit
  268. #undef OnFilterScriptInit
  269. #else
  270. #define _ALS_OnFilterScriptInit
  271. #endif
  272. #define OnFilterScriptInit ppb_OnFilterScriptInit
  273. #if defined ppb_OnFilterScriptInit
  274. forward ppb_OnFilterScriptInit();
  275. #endif
  276. #else
  277. public OnGameModeInit()
  278. {
  279. Iter_Init(pbar_Index);
  280. #if defined ppb_OnGameModeInit
  281. return ppb_OnGameModeInit();
  282. #else
  283. return 1;
  284. #endif
  285. }
  286. #if defined _ALS_OnGameModeInit
  287. #undef OnGameModeInit
  288. #else
  289. #define _ALS_OnGameModeInit
  290. #endif
  291. #define OnGameModeInit ppb_OnGameModeInit
  292. #if defined ppb_OnGameModeInit
  293. forward ppb_OnGameModeInit();
  294. #endif
  295. #endif
  296. #endif
  297. public OnPlayerDisconnect(playerid, reason)
  298. {
  299. #if defined _Y_ITERATE_LOCAL_VERSION
  300. Iter_Clear(pbar_Index[playerid]);
  301. #else
  302. for(new i; i < MAX_PLAYER_BARS; i++)
  303. pbar_Valid[playerid][_:i] = false;
  304. #endif
  305. #if defined ppb_OnPlayerDisconnect
  306. return ppb_OnPlayerDisconnect(playerid, reason);
  307. #else
  308. return 1;
  309. #endif
  310. }
  311. #if defined _ALS_OnPlayerDisconnect
  312. #undef OnPlayerDisconnect
  313. #else
  314. #define _ALS_OnPlayerDisconnect
  315. #endif
  316. #define OnPlayerDisconnect ppb_OnPlayerDisconnect
  317. #if defined ppb_OnPlayerDisconnect
  318. forward ppb_OnPlayerDisconnect(playerid, reason);
  319. #endif
  320. /*==============================================================================
  321. Interface
  322. ==============================================================================*/
  323. stock IsValidPlayerProgressBar(playerid, PlayerBar:barid)
  324. {
  325. #if defined _Y_ITERATE_LOCAL_VERSION
  326. return Iter_Contains(pbar_Index[playerid], _:barid);
  327. #else
  328. if(!(PlayerBar:0 <= barid < PlayerBar:MAX_PLAYER_BARS))
  329. return false;
  330. return pbar_Valid[playerid][_:barid];
  331. #endif
  332. }
  333. // pbar_posX
  334. // pbar_posY
  335. stock GetPlayerProgressBarPos(playerid, PlayerBar:barid, &Float:x, &Float:y)
  336. {
  337. if(!IsValidPlayerProgressBar(playerid, barid))
  338. return 0;
  339. x = pbar_Data[playerid][_:barid][pbar_posX];
  340. y = pbar_Data[playerid][_:barid][pbar_posY];
  341. return 1;
  342. }
  343. stock SetPlayerProgressBarPos(playerid, PlayerBar:barid, Float:x, Float:y)
  344. {
  345. if(!IsValidPlayerProgressBar(playerid, barid))
  346. return false;
  347. pbar_Data[playerid][_:barid][pbar_posX] = x;
  348. pbar_Data[playerid][_:barid][pbar_posY] = y;
  349. _RenderBar(playerid, _:barid, true);
  350. return true;
  351. }
  352. // pbar_width
  353. stock Float:GetPlayerProgressBarWidth(playerid, PlayerBar:barid)
  354. {
  355. if(!IsValidPlayerProgressBar(playerid, barid))
  356. return INVALID_PLAYER_BAR_VALUE;
  357. return pbar_Data[playerid][_:barid][pbar_width];
  358. }
  359. stock SetPlayerProgressBarWidth(playerid, PlayerBar:barid, Float:width)
  360. {
  361. if(!IsValidPlayerProgressBar(playerid, barid))
  362. return 0;
  363. pbar_Data[playerid][_:barid][pbar_width] = width;
  364. _RenderBar(playerid, _:barid, true);
  365. return 1;
  366. }
  367. // pbar_height
  368. stock Float:GetPlayerProgressBarHeight(playerid, PlayerBar:barid)
  369. {
  370. if(!IsValidPlayerProgressBar(playerid, barid))
  371. return INVALID_PLAYER_BAR_VALUE;
  372. return pbar_Data[playerid][_:barid][pbar_height];
  373. }
  374. stock SetPlayerProgressBarHeight(playerid, PlayerBar:barid, Float:height)
  375. {
  376. if(!IsValidPlayerProgressBar(playerid, barid))
  377. return 0;
  378. pbar_Data[playerid][_:barid][pbar_height] = height;
  379. _RenderBar(playerid, _:barid, true);
  380. return 1;
  381. }
  382. // pbar_colour
  383. stock GetPlayerProgressBarColour(playerid, PlayerBar:barid)
  384. {
  385. if(!IsValidPlayerProgressBar(playerid, barid))
  386. return 0;
  387. return pbar_Data[playerid][_:barid][pbar_colour];
  388. }
  389. stock SetPlayerProgressBarColour(playerid, PlayerBar:barid, colour)
  390. {
  391. if(!IsValidPlayerProgressBar(playerid, barid))
  392. return 0;
  393. pbar_Data[playerid][_:barid][pbar_colour] = colour;
  394. PlayerTextDrawBoxColor(playerid, pbar_TextDraw[playerid][_:barid][pbar_back], 0x00000000 | (colour & 0x000000FF));
  395. PlayerTextDrawBoxColor(playerid, pbar_TextDraw[playerid][_:barid][pbar_fill], (colour & 0xFFFFFF00) | (0x66 & ((colour & 0x000000FF) / 2)));
  396. PlayerTextDrawBoxColor(playerid, pbar_TextDraw[playerid][_:barid][pbar_main], colour);
  397. return 1;
  398. }
  399. // pbar_maxValue
  400. stock Float:GetPlayerProgressBarMaxValue(playerid, PlayerBar:barid)
  401. {
  402. if(!IsValidPlayerProgressBar(playerid, barid))
  403. return INVALID_PLAYER_BAR_VALUE;
  404. return pbar_Data[playerid][_:barid][pbar_maxValue];
  405. }
  406. stock SetPlayerProgressBarMaxValue(playerid, PlayerBar:barid, Float:max)
  407. {
  408. if(!IsValidPlayerProgressBar(playerid, barid))
  409. return 0;
  410. pbar_Data[playerid][_:barid][pbar_maxValue] = max;
  411. SetPlayerProgressBarValue(playerid, barid, pbar_Data[playerid][_:barid][pbar_progressValue]);
  412. return 1;
  413. }
  414. // pbar_progressValue
  415. stock SetPlayerProgressBarValue(playerid, PlayerBar:barid, Float:value)
  416. {
  417. if(!IsValidPlayerProgressBar(playerid, barid))
  418. return 0;
  419. value = (value < 0.0) ? (0.0) : (value > pbar_Data[playerid][_:barid][pbar_maxValue]) ? (pbar_Data[playerid][_:barid][pbar_maxValue]) : (value);
  420. PlayerTextDrawUseBox(playerid, pbar_TextDraw[playerid][_:barid][pbar_main], value > 0.0);
  421. pbar_Data[playerid][_:barid][pbar_progressValue] = value;
  422. switch(pbar_Data[playerid][_:barid][pbar_direction])
  423. {
  424. case BAR_DIRECTION_RIGHT, BAR_DIRECTION_LEFT:
  425. {
  426. PlayerTextDrawTextSize(playerid, pbar_TextDraw[playerid][_:barid][pbar_main],
  427. pb_percent(
  428. pbar_Data[playerid][_:barid][pbar_posX],
  429. pbar_Data[playerid][_:barid][pbar_width],
  430. pbar_Data[playerid][_:barid][pbar_maxValue],
  431. value,
  432. pbar_Data[playerid][_:barid][pbar_direction]), 0.0);
  433. }
  434. case BAR_DIRECTION_UP, BAR_DIRECTION_DOWN:
  435. {
  436. PlayerTextDrawLetterSize(playerid, pbar_TextDraw[playerid][_:barid][pbar_main], 1.0,
  437. pb_percent(
  438. pbar_Data[playerid][_:barid][pbar_posX],
  439. pbar_Data[playerid][_:barid][pbar_height],
  440. pbar_Data[playerid][_:barid][pbar_maxValue],
  441. value,
  442. pbar_Data[playerid][_:barid][pbar_direction]));
  443. }
  444. }
  445. ShowPlayerProgressBar(playerid, barid);
  446. return 1;
  447. }
  448. stock Float:GetPlayerProgressBarValue(playerid, PlayerBar:barid)
  449. {
  450. if(!IsValidPlayerProgressBar(playerid, barid))
  451. return INVALID_PLAYER_BAR_VALUE;
  452. return pbar_Data[playerid][_:barid][pbar_progressValue];
  453. }
  454. // pbar_direction
  455. stock GetPlayerProgressBarDirection(playerid, PlayerBar:barid)
  456. {
  457. if(!IsValidPlayerProgressBar(playerid, barid))
  458. return 0;
  459. return pbar_Data[playerid][_:barid][pbar_direction];
  460. }
  461. stock SetPlayerProgressBarDirection(playerid, PlayerBar:barid, direction)
  462. {
  463. if(!IsValidPlayerProgressBar(playerid, barid))
  464. return 0;
  465. pbar_Data[playerid][_:barid][pbar_direction] = direction;
  466. _RenderBar(playerid, _:barid, true);
  467. return 1;
  468. }