toribio

toribio

Dec 14th, 2009
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.62 KB | None | 0 0
  1. /**
  2.  *  Progress Bar 1.3.0.0
  3.  *  Copyright 2007-2010 Infernus' Group,
  4.  *  Flávio Toribio (flavio_toibio@hotmail.com)
  5.  */
  6.  
  7. #if defined _progress_included
  8.     #endinput
  9. #endif
  10.  
  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.  
  18. #tryinclude <foreach>
  19.  
  20. #define _progress_included
  21. #define _progress_version   0x1300
  22.  
  23. #define MAX_BARS                (MAX_TEXT_DRAWS / 3)
  24. #define INVALID_BAR_VALUE       (Float:0xFFFFFFFF)
  25. #define INVALID_BAR_ID          (Bar:-1)
  26. #define pb_percent(%1,%2,%3,%4) ((%1 - 6.0) + ((((%1 + 6.0 + %2 - 2.0) - %1) / %3) * %4))
  27. //pb_percent(x, width, max, value)
  28.  
  29. /* Pawno/Infernus Pawn Editor function list
  30. native Bar:CreateProgressBar(Float:x, Float:y, Float:width=55.5, Float:height=3.2, color, Float:max=100.0);
  31. native DestroyProgressBar(Bar:barid);
  32. native ShowProgressBarForPlayer(playerid, Bar:barid);
  33. native HideProgressBarForPlayer(playerid, Bar:barid);
  34. native ShowProgressBarForAll(Bar:barid);
  35. native HideProgressBarForAll(Bar:barid);
  36. native SetProgressBarValue(Bar:barid, Float:value);
  37. native Float:GetProgressBarValue(Bar:barid);
  38. native SetProgressBarMaxValue(Bar:barid, Float:max);
  39. native SetProgressBarColor(Bar:barid, color);
  40. native UpdateProgressBar(Bar:barid, playerid=INVALID_PLAYER_ID);
  41. */
  42.  
  43. forward Float:GetProgressBarValue(Bar:barid);
  44.  
  45. enum e_bar
  46. {
  47.     Float:pb_x,
  48.     Float:pb_y,
  49.     Float:pb_w,
  50.     Float:pb_h,
  51.     Float:pb_m,
  52.     Float:pb_v,
  53.     Text:pb_t1,
  54.     Text:pb_t2,
  55.     Text:pb_t3,
  56.     pb_color,
  57.     bool:pb_created
  58. }
  59.  
  60. static Bars[MAX_BARS][e_bar];
  61.  
  62. stock Bar:CreateProgressBar(Float:x, Float:y, Float:width=55.5, Float:height=3.2, color, Float:max=100.0)
  63. {
  64.     new
  65.         barid;
  66.  
  67.     for(barid = 0; barid < sizeof Bars; ++barid)
  68.         if(!Bars[barid][pb_created]) break;
  69.  
  70.     if(Bars[barid][pb_created] || barid == sizeof Bars)
  71.         return INVALID_BAR_ID;
  72.  
  73.     new Text:in_t = Bars[barid][pb_t1] = TextDrawCreate(x, y, "_");
  74.     TextDrawUseBox      (in_t, 1);
  75.     TextDrawTextSize    (in_t, x + width, 0.0);
  76.     TextDrawLetterSize  (in_t, 1.0, height / 10);
  77.     TextDrawBoxColor    (in_t, 0x00000000 | (color & 0x000000FF));
  78.  
  79.     in_t = Bars[barid][pb_t2] = TextDrawCreate(x + 1.2, y + 2.15, "_");
  80.     TextDrawUseBox      (in_t, 1);
  81.     TextDrawTextSize    (in_t, x + width - 2.0, 0.0);
  82.     TextDrawLetterSize  (in_t, 1.0, height / 10 - 0.35);
  83.     TextDrawBoxColor    (in_t, (color & 0xFFFFFF00) | (0x66 & ((color & 0x000000FF) / 2)));
  84.  
  85.     in_t = Bars[barid][pb_t3] = TextDrawCreate(x + 1.2, y + 2.15, "_");
  86.     TextDrawTextSize    (in_t, pb_percent(x, width, max, 1.0), 0.0);
  87.     TextDrawLetterSize  (in_t, 1.0, height / 10 - 0.35);
  88.     TextDrawBoxColor    (in_t, color);
  89.  
  90.     Bars[barid][pb_x] = x;
  91.     Bars[barid][pb_y] = y;
  92.     Bars[barid][pb_w] = width;
  93.     Bars[barid][pb_h] = height;
  94.     Bars[barid][pb_m] = max;
  95.     Bars[barid][pb_color] = color;
  96.     Bars[barid][pb_created] = true;
  97.     return Bar:barid;
  98. }
  99.  
  100. stock DestroyProgressBar(Bar:barid)
  101. {
  102.     if(barid != INVALID_BAR_ID && Bar:-1 < barid < Bar:MAX_BARS)
  103.     {
  104.         if(!Bars[_:barid][pb_created])
  105.             return 0;
  106.  
  107.         TextDrawDestroy(Bars[_:barid][pb_t1]);
  108.         TextDrawDestroy(Bars[_:barid][pb_t2]);
  109.         TextDrawDestroy(Bars[_:barid][pb_t3]);
  110.  
  111.         Bars[_:barid][pb_t1] = Text:0;      
  112.         Bars[_:barid][pb_t2] = Text:0;      
  113.         Bars[_:barid][pb_t3] = Text:0;
  114.         Bars[_:barid][pb_x] = 0.0;
  115.         Bars[_:barid][pb_y] = 0.0;
  116.         Bars[_:barid][pb_w] = 0.0;
  117.         Bars[_:barid][pb_h] = 0.0;
  118.         Bars[_:barid][pb_m] = 0.0;
  119.         Bars[_:barid][pb_v] = 0.0;
  120.         Bars[_:barid][pb_color] = 0;
  121.         Bars[_:barid][pb_created] = false;
  122.         return 1;
  123.     }
  124.     return 0;
  125. }
  126.  
  127. stock ShowProgressBarForPlayer(playerid, Bar:barid)
  128. {
  129.     if(IsPlayerConnected(playerid) && barid != INVALID_BAR_ID && Bar:-1 < barid < Bar:MAX_BARS)
  130.     {
  131.         if(!Bars[_:barid][pb_created])
  132.             return 0;
  133.  
  134.         TextDrawShowForPlayer(playerid, Bars[_:barid][pb_t1]);
  135.         TextDrawShowForPlayer(playerid, Bars[_:barid][pb_t2]);
  136.         TextDrawShowForPlayer(playerid, Bars[_:barid][pb_t3]);
  137.         return 1;
  138.     }
  139.     return 0;
  140. }
  141.  
  142. stock HideProgressBarForPlayer(playerid, Bar:barid)
  143. {
  144.     if(IsPlayerConnected(playerid) && barid != INVALID_BAR_ID && Bar:-1 < barid < Bar:MAX_BARS)
  145.     {
  146.         if(!Bars[_:barid][pb_created])
  147.             return 0;
  148.  
  149.         TextDrawHideForPlayer(playerid, Bars[_:barid][pb_t1]);
  150.         TextDrawHideForPlayer(playerid, Bars[_:barid][pb_t2]);
  151.         TextDrawHideForPlayer(playerid, Bars[_:barid][pb_t3]);
  152.         return 1;
  153.     }
  154.     return 0;
  155. }
  156.  
  157. stock SetProgressBarValue(Bar:barid, Float:value)
  158. {
  159.     if(barid == INVALID_BAR_ID || Bar:MAX_BARS < barid < Bar:-1)
  160.         return 0;
  161.  
  162.     if(Bars[_:barid][pb_created])
  163.     {
  164.         value =
  165.             (value < 0.0) ? (0.0) : (value > Bars[_:barid][pb_m]) ? (Bars[_:barid][pb_m]) : (value);
  166.  
  167.         TextDrawUseBox(Bars[_:barid][pb_t3], value > 0.0);
  168.  
  169.         Bars[_:barid][pb_v] = value;
  170.  
  171.         TextDrawTextSize(Bars[_:barid][pb_t3],
  172.             pb_percent(Bars[_:barid][pb_x], Bars[_:barid][pb_w], Bars[_:barid][pb_m], value), 0.0);
  173.  
  174.         return 1;
  175.     }
  176.     return 0;
  177. }
  178.  
  179. stock Float:GetProgressBarValue(Bar:barid)
  180. {
  181.     if(barid == INVALID_BAR_ID || Bar:MAX_BARS < barid < Bar:-1)
  182.         return INVALID_BAR_VALUE;
  183.  
  184.     if(Bars[_:barid][pb_created])
  185.         return Bars[_:barid][pb_v];
  186.  
  187.     return INVALID_BAR_VALUE;
  188. }
  189.  
  190. stock SetProgressBarMaxValue(Bar:barid, Float:max)
  191. {
  192.     if(barid == INVALID_BAR_ID || Bar:MAX_BARS < barid < Bar:-1)
  193.         return 0;
  194.  
  195.     if(Bars[_:barid][pb_created])
  196.     {
  197.         Bars[_:barid][pb_m] = max;
  198.         SetProgressBarValue(barid, Bars[_:barid][pb_v]);
  199.         return 1;
  200.     }
  201.     return 0;
  202. }
  203.  
  204. stock SetProgressBarColor(Bar:barid, color)
  205. {
  206.     if(barid == INVALID_BAR_ID || Bar:MAX_BARS < barid < Bar:-1)
  207.         return 0;
  208.  
  209.     if(Bars[_:barid][pb_created])
  210.     {  
  211.         Bars[_:barid][pb_color] = color;
  212.         TextDrawBoxColor(Bars[_:barid][pb_t1], 0x00000000 | (color & 0x000000FF));
  213.  
  214.         TextDrawBoxColor(Bars[_:barid][pb_t2],
  215.             (color & 0xFFFFFF00) | (0x66 & ((color & 0x000000FF) / 2)));
  216.  
  217.         TextDrawBoxColor(Bars[_:barid][pb_t3], color);
  218.         return 1;
  219.     }
  220.     return 0;
  221. }
  222.  
  223. stock ShowProgressBarForAll(Bar:barid)
  224. {
  225.     #if defined _foreach_included
  226.     foreach(Player, i)
  227.     #else
  228.     for(new i = 0; i < MAX_PLAYERS; ++i)
  229.         if(IsPlayerConnected(i))
  230.     #endif
  231.     #if defined IsPlayerNPC
  232.         if(!IsPlayerNPC(i))
  233.     #endif
  234.     {
  235.         ShowProgressBarForPlayer(i, barid);
  236.     }
  237.     return 1;
  238. }
  239.  
  240. stock HideProgressBarForAll(Bar:barid)
  241. {
  242.     #if defined _foreach_included
  243.     foreach(Player, i)
  244.     #else
  245.     for(new i = 0; i < MAX_PLAYERS; ++i)
  246.         if(IsPlayerConnected(i))
  247.     #endif
  248.     #if defined IsPlayerNPC
  249.         if(!IsPlayerNPC(i))
  250.     #endif
  251.     {
  252.         HideProgressBarForPlayer(i, barid);
  253.     }
  254.     return 1;
  255. }
  256.  
  257. stock UpdateProgressBar(Bar:barid, playerid=INVALID_PLAYER_ID)
  258. {
  259.     if(playerid == INVALID_PLAYER_ID)
  260.     {
  261.         return ShowProgressBarForAll(barid);
  262.     } else {
  263.         return ShowProgressBarForPlayer(playerid, barid);
  264.     }
  265. }
Add Comment
Please, Sign In to add comment