| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387 |
- /*==============================================================================
- Progress Bar 2.1.4
- A SA:MP UI library for rendering progress bars used to visualise all
- manner of data from health to a countdown timer.
- Library originally written by Flávio Toribio: flavio_toribio@hotmail.com
- Now maintained by Southclaw in version 2+ with new features.
- ==============================================================================*/
- #if defined _progress2_included
- #endinput
- #endif
- #if !defined _samp_included
- #tryinclude <a_samp>
- #if !defined _samp_included
- #error could not locate a_samp.inc file, please check your server includes
- #endif
- #endif
- #if !defined PB_DEBUG
- #define PB_DEBUG (false)
- #endif
- #define _progress2_included
- #define _progress2_version 0x211
- #define MAX_PLAYER_BARS (MAX_PLAYER_TEXT_DRAWS / 3)
- #define INVALID_PLAYER_BAR_VALUE (Float:0xFFFFFFFF)
- #define INVALID_PLAYER_BAR_ID (PlayerBar:-1)
- #if PB_DEBUG == true
- #define pb_debug(%0); printf(%0);
- #else
- #define pb_debug(%0);
- #endif
- /*==============================================================================
- Setup
- ==============================================================================*/
- enum
- {
- BAR_DIRECTION_RIGHT,
- BAR_DIRECTION_LEFT,
- BAR_DIRECTION_UP,
- BAR_DIRECTION_DOWN
- }
- enum E_BAR_DATA
- {
- bool: pbar_show,
- Float: pbar_posX,
- Float: pbar_posY,
- Float: pbar_width,
- Float: pbar_height,
- pbar_colour,
- Float: pbar_maxValue,
- Float: pbar_progressValue,
- pbar_direction
- }
- enum E_BAR_TEXT_DRAW
- {
- PlayerText: pbar_back,
- PlayerText: pbar_fill,
- PlayerText: pbar_main
- }
- static
- pbar_Data[MAX_PLAYERS][MAX_PLAYER_BARS][E_BAR_DATA],
- pbar_TextDraw[MAX_PLAYERS][MAX_PLAYER_BARS][E_BAR_TEXT_DRAW];
- #if defined _Y_ITERATE_LOCAL_VERSION
- new Iterator:pbar_Index[MAX_PLAYERS]<MAX_PLAYER_BARS>;
- #else
- static bool:pbar_Valid[MAX_PLAYERS][MAX_PLAYER_BARS];
- #endif
- 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);
- forward Float:GetPlayerProgressBarValue(playerid, PlayerBar:barid);
- /*==============================================================================
- Utils
- ==============================================================================*/
- stock Float:_bar_percent(Float:x, Float:widthorheight, Float:max, Float:value, direction)
- {
- new Float:result;
- switch(direction)
- {
- case BAR_DIRECTION_RIGHT:
- result = ((x - 3.0) + (((((x - 2.0) + widthorheight) - x) / max) * value));
- case BAR_DIRECTION_LEFT:
- result = ((x - 1.0) - (((((x + 2.0) - widthorheight) - x) / max) * -value)) - 4.0;
- case BAR_DIRECTION_UP:
- result = -((((((widthorheight / 10.0) - 0.45) * 1.02) / max) * value) + 0.55);
- case BAR_DIRECTION_DOWN:
- result = ((((((widthorheight / 10.0) - 0.45) * 1.02) / max) * value) - 0.55);
- }
- return result;
- }
- stock _bar_NewID(playerid)
- {
- #if defined _Y_ITERATE_LOCAL_VERSION
- return Iter_Free(pbar_Index[playerid]);
- #else
- new i;
- for(i = 0; i < MAX_PLAYER_BARS; i++)
- {
- if(!pbar_Valid[playerid][i])
- break;
- }
- return (i == MAX_PLAYER_BARS) ? -1 : i;
- #endif
- }
- /*==============================================================================
- Core
- ==============================================================================*/
- 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)
- {
- if(!IsPlayerConnected(playerid))
- return INVALID_PLAYER_BAR_ID;
- new barid = _bar_NewID(playerid);
- if(barid == -1)
- {
- print("[CreatePlayerProgressBar] ERROR: MAX_PLAYER_BARS limit reached.");
- return INVALID_PLAYER_BAR_ID;
- }
- 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);
- pbar_TextDraw[playerid][barid][pbar_back] = PlayerText:INVALID_TEXT_DRAW;
- pbar_TextDraw[playerid][barid][pbar_fill] = PlayerText:INVALID_TEXT_DRAW;
- pbar_TextDraw[playerid][barid][pbar_main] = PlayerText:INVALID_TEXT_DRAW;
- pbar_Data[playerid][barid][pbar_show] = false;
- pbar_Data[playerid][barid][pbar_posX] = x;
- pbar_Data[playerid][barid][pbar_posY] = y;
- pbar_Data[playerid][barid][pbar_width] = width;
- pbar_Data[playerid][barid][pbar_height] = height;
- pbar_Data[playerid][barid][pbar_colour] = colour;
- pbar_Data[playerid][barid][pbar_maxValue] = max;
- pbar_Data[playerid][barid][pbar_progressValue] = 0.0;
- pbar_Data[playerid][barid][pbar_direction] = direction;
- #if defined _Y_ITERATE_LOCAL_VERSION
- Iter_Add(pbar_Index[playerid], barid);
- #else
- pbar_Valid[playerid][barid] = true;
- #endif
- _RenderBar(playerid, barid);
- return PlayerBar:barid;
- }
- stock DestroyPlayerProgressBar(playerid, PlayerBar:barid)
- {
- if(!IsValidPlayerProgressBar(playerid, barid))
- return 0;
- PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][_:barid][pbar_back]);
- PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][_:barid][pbar_fill]);
- PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][_:barid][pbar_main]);
- #if defined _Y_ITERATE_LOCAL_VERSION
- Iter_Remove(pbar_Index[playerid], _:barid);
- #else
- pbar_Valid[playerid][_:barid] = false;
- #endif
- return 1;
- }
- stock ShowPlayerProgressBar(playerid, PlayerBar:barid)
- {
- if(!IsValidPlayerProgressBar(playerid, barid))
- return 0;
- pbar_Data[playerid][_:barid][pbar_show] = true;
- PlayerTextDrawShow(playerid, pbar_TextDraw[playerid][_:barid][pbar_back]);
- PlayerTextDrawShow(playerid, pbar_TextDraw[playerid][_:barid][pbar_fill]);
- PlayerTextDrawShow(playerid, pbar_TextDraw[playerid][_:barid][pbar_main]);
- return 1;
- }
- stock HidePlayerProgressBar(playerid, PlayerBar:barid)
- {
- if(!IsValidPlayerProgressBar(playerid, barid))
- return 0;
- pbar_Data[playerid][_:barid][pbar_show] = false;
- PlayerTextDrawHide(playerid, pbar_TextDraw[playerid][_:barid][pbar_back]);
- PlayerTextDrawHide(playerid, pbar_TextDraw[playerid][_:barid][pbar_fill]);
- PlayerTextDrawHide(playerid, pbar_TextDraw[playerid][_:barid][pbar_main]);
- return 1;
- }
- /*==============================================================================
- Hooks and Internal
- ==============================================================================*/
- _RenderBar(playerid, barid)
- {
- if(!IsPlayerConnected(playerid))
- return false;
- if(!IsValidPlayerProgressBar(playerid, PlayerBar:barid))
- return false;
- PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][barid][pbar_back]);
- PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][barid][pbar_fill]);
- PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][barid][pbar_main]);
- switch(pbar_Data[playerid][barid][pbar_direction])
- {
- case BAR_DIRECTION_RIGHT:
- {
- pbar_TextDraw[playerid][barid][pbar_back] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX], pbar_Data[playerid][barid][pbar_posY], "_");
- PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1);
- PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], pbar_Data[playerid][barid][pbar_posX] + pbar_Data[playerid][barid][pbar_width] - 4.0, 0.0);
- PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1.0, pbar_Data[playerid][barid][pbar_height] / 10);
- PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_back], 0x00000000 | (pbar_Data[playerid][barid][pbar_colour] & 0x000000FF));
- pbar_TextDraw[playerid][barid][pbar_fill] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] + 1.2, pbar_Data[playerid][barid][pbar_posY] + 2.15, "_");
- PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1);
- PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], pbar_Data[playerid][barid][pbar_posX] + pbar_Data[playerid][barid][pbar_width] - 5.5, 0.0);
- PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1.0, pbar_Data[playerid][barid][pbar_height] / 10 - 0.35);
- PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_fill], (pbar_Data[playerid][barid][pbar_colour] & 0xFFFFFF00) | (0x66 & ((pbar_Data[playerid][barid][pbar_colour] & 0x000000FF) / 2)));
- pbar_TextDraw[playerid][barid][pbar_main] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] + 1.2, pbar_Data[playerid][barid][pbar_posY] + 2.15, "_");
- PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1);
- 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);
- PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_main], 1.0, pbar_Data[playerid][barid][pbar_height] / 10 - 0.35);
- PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_main], pbar_Data[playerid][barid][pbar_colour]);
- }
- case BAR_DIRECTION_LEFT:
- {
- pbar_TextDraw[playerid][barid][pbar_back] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX], pbar_Data[playerid][barid][pbar_posY], "_");
- PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1);
- PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 4.0, 0.0);
- PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1.0, pbar_Data[playerid][barid][pbar_height] / 10);
- PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_back], 0x00000000 | (pbar_Data[playerid][barid][pbar_colour] & 0x000000FF));
- pbar_TextDraw[playerid][barid][pbar_fill] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] - 1.2, pbar_Data[playerid][barid][pbar_posY] + 2.15, "_");
- PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1);
- PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 2.5, 0.0);
- PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1.0, pbar_Data[playerid][barid][pbar_height] / 10 - 0.35);
- PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_fill], (pbar_Data[playerid][barid][pbar_colour] & 0xFFFFFF00) | (0x66 & ((pbar_Data[playerid][barid][pbar_colour] & 0x000000FF) / 2)));
- pbar_TextDraw[playerid][barid][pbar_main] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] - 1.2, pbar_Data[playerid][barid][pbar_posY] + 2.15, "_");
- PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1);
- 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);
- PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_main], 1.0, pbar_Data[playerid][barid][pbar_height] / 10 - 0.35);
- PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_main], pbar_Data[playerid][barid][pbar_colour]);
- }
- case BAR_DIRECTION_UP:
- {
- pbar_TextDraw[playerid][barid][pbar_back] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX], pbar_Data[playerid][barid][pbar_posY], "_");
- PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1);
- PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 4.0, 0.0);
- PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1.0, -((pbar_Data[playerid][barid][pbar_height] / 10) * 1.02) -0.35);
- PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_back], 0x00000000 | (pbar_Data[playerid][barid][pbar_colour] & 0x000000FF));
- pbar_TextDraw[playerid][barid][pbar_fill] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] - 1.2, pbar_Data[playerid][barid][pbar_posY] - 1.0, "_");
- PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1);
- PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 2.5, 0.0);
- PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1.0, -(pbar_Data[playerid][barid][pbar_height] / 10.0) * 1.02);
- PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_fill], (pbar_Data[playerid][barid][pbar_colour] & 0xFFFFFF00) | (0x66 & ((pbar_Data[playerid][barid][pbar_colour] & 0x000000FF) / 2)));
- pbar_TextDraw[playerid][barid][pbar_main] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] - 1.2, pbar_Data[playerid][barid][pbar_posY] - 1.0, "_");
- PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_main], 1);
- PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_main], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 2.5, 0.0);
- 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]));
- PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_main], pbar_Data[playerid][barid][pbar_colour]);
- }
- case BAR_DIRECTION_DOWN:
- {
- pbar_TextDraw[playerid][barid][pbar_back] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX], pbar_Data[playerid][barid][pbar_posY], "_");
- PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1);
- PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 4.0, 0.0);
- PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_back], 1.0, ((pbar_Data[playerid][barid][pbar_height] / 10)) -0.35);
- PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_back], 0x00000000 | (pbar_Data[playerid][barid][pbar_colour] & 0x000000FF));
- pbar_TextDraw[playerid][barid][pbar_fill] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] - 1.2, pbar_Data[playerid][barid][pbar_posY] + 1.0, "_");
- PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1);
- PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 2.5, 0.0);
- PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_fill], 1.0, (pbar_Data[playerid][barid][pbar_height] / 10.0) - 0.55);
- PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_fill], (pbar_Data[playerid][barid][pbar_colour] & 0xFFFFFF00) | (0x66 & ((pbar_Data[playerid][barid][pbar_colour] & 0x000000FF) / 2)));
- pbar_TextDraw[playerid][barid][pbar_main] = CreatePlayerTextDraw(playerid, pbar_Data[playerid][barid][pbar_posX] - 1.2, pbar_Data[playerid][barid][pbar_posY] + 1.0, "_");
- PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_main], 1);
- PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_main], pbar_Data[playerid][barid][pbar_posX] - pbar_Data[playerid][barid][pbar_width] - 2.5, 0.0);
- 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]));
- PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_main], pbar_Data[playerid][barid][pbar_colour]);
- }
- }
- if(pbar_Data[playerid][barid][pbar_show])
- ShowPlayerProgressBar(playerid, PlayerBar:barid);
- return true;
- }
- #if defined _Y_ITERATE_LOCAL_VERSION
- #if defined FILTERSCRIPT
- public OnFilterScriptInit()
- {
- Iter_Init(pbar_Index);
- #if defined ppb_OnFilterScriptInit
- return ppb_OnFilterScriptInit();
- #else
- return 1;
- #endif
- }
- #if defined _ALS_OnFilterScriptInit
- #undef OnFilterScriptInit
- #else
- #define _ALS_OnFilterScriptInit
- #endif
-
- #define OnFilterScriptInit ppb_OnFilterScriptInit
- #if defined ppb_OnFilterScriptInit
- forward ppb_OnFilterScriptInit();
- #endif
- #else
- public OnGameModeInit()
- {
- Iter_Init(pbar_Index);
- #if defined ppb_OnGameModeInit
- return ppb_OnGameModeInit();
- #else
- return 1;
- #endif
- }
- #if defined _ALS_OnGameModeInit
- #undef OnGameModeInit
- #else
- #define _ALS_OnGameModeInit
- #endif
-
- #define OnGameModeInit ppb_OnGameModeInit
- #if defined ppb_OnGameModeInit
- forward ppb_OnGameModeInit();
- #endif
- #endif
- #endif
- public OnPlayerDisconnect(playerid, reason)
- {
- #if defined _Y_ITERATE_LOCAL_VERSION
- Iter_Clear(pbar_Index[playerid]);
- #else
- for(new i; i < MAX_PLAYER_BARS; i++)
- pbar_Valid[playerid][_:i] = false;
- #endif
- #if defined ppb_OnPlayerDisconnect
- return ppb_OnPlayerDisconnect(playerid, reason);
- #else
- return 1;
- #endif
- }
- #if defined _ALS_OnPlayerDisconnect
- #undef OnPlayerDisconnect
- #else
- #define _ALS_OnPlayerDisconnect
- #endif
-
- #define OnPlayerDisconnect ppb_OnPlayerDisconnect
- #if defined ppb_OnPlayerDisconnect
- forward ppb_OnPlayerDisconnect(playerid, reason);
- #endif
- #if defined FILTERSCRIPT
- public OnFilterScriptExit()
- {
- for(new i = 0; i < MAX_PLAYERS; i++)
- {
- if(IsPlayerConnected(i))
- DestroyAllPlayerProgressBars(i);
- }
- #if defined ppb_OnFilterScriptExit
- return ppb_OnFilterScriptExit();
- #else
- return 1;
- #endif
- }
- #if defined _ALS_OnFilterScriptExit
- #undef OnFilterScriptExit
- #else
- #define _ALS_OnFilterScriptExit
- #endif
- #define OnFilterScriptExit ppb_OnFilterScriptExit
- #if defined ppb_OnFilterScriptExit
- forward ppb_OnFilterScriptExit();
- #endif
- #else
- public OnGameModeExit()
- {
- for(new i = 0; i < MAX_PLAYERS; i++)
- {
- if(IsPlayerConnected(i))
- DestroyAllPlayerProgressBars(i);
- }
- #if defined ppb_OnGameModeExit
- return ppb_OnGameModeExit();
- #else
- return 1;
- #endif
- }
- #if defined _ALS_OnGameModeExit
- #undef OnGameModeExit
- #else
- #define _ALS_OnGameModeExit
- #endif
- #define OnGameModeExit ppb_OnGameModeExit
- #if defined ppb_OnGameModeExit
- forward ppb_OnGameModeExit();
- #endif
- #endif
- stock DestroyAllPlayerProgressBars(playerid)
- {
- for(new i = 0; i < MAX_PLAYER_BARS; i++)
- DestroyPlayerProgressBar(playerid, PlayerBar:i);
- return 1;
- }
- /*==============================================================================
- Interface
- ==============================================================================*/
- stock IsValidPlayerProgressBar(playerid, PlayerBar:barid)
- {
- #if defined _Y_ITERATE_LOCAL_VERSION
- return Iter_Contains(pbar_Index[playerid], _:barid);
- #else
- if(!(PlayerBar:0 <= barid < PlayerBar:MAX_PLAYER_BARS))
- return false;
- return pbar_Valid[playerid][_:barid];
- #endif
- }
- // pbar_posX
- // pbar_posY
- stock GetPlayerProgressBarPos(playerid, PlayerBar:barid, &Float:x, &Float:y)
- {
- if(!IsValidPlayerProgressBar(playerid, barid))
- return 0;
- x = pbar_Data[playerid][_:barid][pbar_posX];
- y = pbar_Data[playerid][_:barid][pbar_posY];
- return 1;
- }
- stock SetPlayerProgressBarPos(playerid, PlayerBar:barid, Float:x, Float:y)
- {
- if(!IsValidPlayerProgressBar(playerid, barid))
- return false;
- pbar_Data[playerid][_:barid][pbar_posX] = x;
- pbar_Data[playerid][_:barid][pbar_posY] = y;
- _RenderBar(playerid, _:barid);
- return true;
- }
- // pbar_width
- stock Float:GetPlayerProgressBarWidth(playerid, PlayerBar:barid)
- {
- if(!IsValidPlayerProgressBar(playerid, barid))
- return INVALID_PLAYER_BAR_VALUE;
- return pbar_Data[playerid][_:barid][pbar_width];
- }
- stock SetPlayerProgressBarWidth(playerid, PlayerBar:barid, Float:width)
- {
- if(!IsValidPlayerProgressBar(playerid, barid))
- return 0;
- pbar_Data[playerid][_:barid][pbar_width] = width;
- _RenderBar(playerid, _:barid);
- return 1;
- }
- // pbar_height
- stock Float:GetPlayerProgressBarHeight(playerid, PlayerBar:barid)
- {
- if(!IsValidPlayerProgressBar(playerid, barid))
- return INVALID_PLAYER_BAR_VALUE;
- return pbar_Data[playerid][_:barid][pbar_height];
- }
- stock SetPlayerProgressBarHeight(playerid, PlayerBar:barid, Float:height)
- {
- if(!IsValidPlayerProgressBar(playerid, barid))
- return 0;
- pbar_Data[playerid][_:barid][pbar_height] = height;
- _RenderBar(playerid, _:barid);
- return 1;
- }
- // pbar_colour
- stock GetPlayerProgressBarColour(playerid, PlayerBar:barid)
- {
- if(!IsValidPlayerProgressBar(playerid, barid))
- return 0;
- return pbar_Data[playerid][_:barid][pbar_colour];
- }
- stock SetPlayerProgressBarColour(playerid, PlayerBar:barid, colour)
- {
- if(!IsValidPlayerProgressBar(playerid, barid))
- return 0;
- pbar_Data[playerid][_:barid][pbar_colour] = colour;
- PlayerTextDrawBoxColor(playerid, pbar_TextDraw[playerid][_:barid][pbar_back], 0x00000000 | (colour & 0x000000FF));
- PlayerTextDrawBoxColor(playerid, pbar_TextDraw[playerid][_:barid][pbar_fill], (colour & 0xFFFFFF00) | (0x66 & ((colour & 0x000000FF) / 2)));
- PlayerTextDrawBoxColor(playerid, pbar_TextDraw[playerid][_:barid][pbar_main], colour);
- return 1;
- }
- // pbar_maxValue
- stock Float:GetPlayerProgressBarMaxValue(playerid, PlayerBar:barid)
- {
- if(!IsValidPlayerProgressBar(playerid, barid))
- return INVALID_PLAYER_BAR_VALUE;
- return pbar_Data[playerid][_:barid][pbar_maxValue];
- }
- stock SetPlayerProgressBarMaxValue(playerid, PlayerBar:barid, Float:max)
- {
- if(!IsValidPlayerProgressBar(playerid, barid))
- return 0;
- pbar_Data[playerid][_:barid][pbar_maxValue] = max;
- SetPlayerProgressBarValue(playerid, barid, pbar_Data[playerid][_:barid][pbar_progressValue]);
- return 1;
- }
- // pbar_progressValue
- stock SetPlayerProgressBarValue(playerid, PlayerBar:barid, Float:value)
- {
- if(!IsValidPlayerProgressBar(playerid, barid))
- return 0;
- value = (value < 0.0) ? (0.0) : (value > pbar_Data[playerid][_:barid][pbar_maxValue]) ? (pbar_Data[playerid][_:barid][pbar_maxValue]) : (value);
- PlayerTextDrawUseBox(playerid, pbar_TextDraw[playerid][_:barid][pbar_main], value > 0.0);
- pbar_Data[playerid][_:barid][pbar_progressValue] = value;
- switch(pbar_Data[playerid][_:barid][pbar_direction])
- {
- case BAR_DIRECTION_RIGHT, BAR_DIRECTION_LEFT:
- {
- 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],
- value,
- pbar_Data[playerid][_:barid][pbar_direction]), 0.0);
- }
- case BAR_DIRECTION_UP, BAR_DIRECTION_DOWN:
- {
- 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],
- value,
- pbar_Data[playerid][_:barid][pbar_direction]));
- }
- }
- if(pbar_Data[playerid][_:barid][pbar_show])
- ShowPlayerProgressBar(playerid, barid);
- return 1;
- }
- stock Float:GetPlayerProgressBarValue(playerid, PlayerBar:barid)
- {
- if(!IsValidPlayerProgressBar(playerid, barid))
- return INVALID_PLAYER_BAR_VALUE;
- return pbar_Data[playerid][_:barid][pbar_progressValue];
- }
- // pbar_direction
- stock GetPlayerProgressBarDirection(playerid, PlayerBar:barid)
- {
- if(!IsValidPlayerProgressBar(playerid, barid))
- return 0;
- return pbar_Data[playerid][_:barid][pbar_direction];
- }
- stock SetPlayerProgressBarDirection(playerid, PlayerBar:barid, direction)
- {
- if(!IsValidPlayerProgressBar(playerid, barid))
- return 0;
- pbar_Data[playerid][_:barid][pbar_direction] = direction;
- _RenderBar(playerid, _:barid);
- return 1;
- }
|