/*
Player Status Bar with Icons v 1.36
Author: Dart_Rogue
Mod: Epoch
https://github.com/DarthRogue/Status_Bar

Transfered to Altis Life + add   SBUserhy
*/
#include <macro.h>
waitUntil {!(isNull (findDisplay 46))};
disableSerialization;
waitUntil{life_session_completed};

/*_rscLayer = "osefStatusBar" call BIS_fnc_rscLayer;
_rscLayer cutRsc["osefStatusBar","PLAIN"];
*/
4 cutRsc ["osefStatusBar","PLAIN"];

//systemChat format["Willkommen auf dem Server", _rscLayer];

[] spawn {
    sleep 2;
        _counter = 360;
        _timeSinceLastUpdate = 0;
        _colourDefault  = parseText "#ADADAD"; //set your default colour here
		_colour100 		= parseText "#33FF00";
		_colour90 		= parseText "#33FF00";
		_colour80 		= parseText "#33FF00";
		_colour70 		= parseText "#33FF00";
		_colour60 		= parseText "#66FF00";
		_colour50 		= parseText "#CCFF00";
		_colour40 		= parseText "#FFFF00";
		_colour30 		= parseText "#FFFF00";
		_colour20 		= parseText "#CC0000";
		_colour10 		= parseText "#CC0000";
		_colour0 		= parseText "#CC0000";
		_colourDead 	= parseText "#000000";
        _colourUpTimeHUD  = parseText "#CCCCCC";

while {true} do 
	{
		sleep 1;
		//moved the creation of the status bar inside the loop and create it if it is null,
		//this is to handle instance where the status bar is disappearing 
		if (displayNull isEqualTo(uiNamespace getvariable "osefStatusBar")) then {		
			disableSerialization;
			cutRsc ["osefStatusBar","PLAIN"];
			_ui = uiNamespace getVariable "osefStatusBar";			
		};
        //initialize variables and set values
        //neu
        _CivplayHUD = civilian countSide playableUnits;							//1
        _WestplayHUD = west countSide playableUnits;							//2
        _IndepplayHUD = independent countSide playableUnits;					//3
		_EastplayHUD = east countSide playableUnits;
        _hunger = round(life_hunger);											//8
        _thirst = round(life_thirst);											//9
        _damage = round ((1 - (damage player)) * 100);							//10
        _UpTimeHUD = [serverTime,"HH:MM:SS"] call BIS_fnc_secondsToString;		//13
		//_TimeHUD = round("05:58:00"-(_UpTimeHUD)); 
		_barcash = [CASH] call life_fnc_numberText;						//14
		_bankcash = [BANK] call life_fnc_numberText;					//15
		_battery = round(life_battery); 										//16
        //neu ende
		_toxPercent = round(life_thirst);
		_energy = round(life_thirst);
		_energyPercent =  floor((_energy / 2500 ) * 100);
		_players = (count playableUnits);
        //Colour coding
		//Hunger
		_colourHunger = _colourDefault;
		switch true do {
			case(_hunger >= 100) : {_colourHunger = _colour70;};
			case((_hunger >= 90) && (_hunger < 100)) :  {_colourHunger =  _colour70;};
			case((_hunger >= 80) && (_hunger < 90)) :  {_colourHunger =  _colour70;};
			case((_hunger >= 70) && (_hunger < 80)) :  {_colourHunger =  _colour70;};
			case((_hunger >= 60) && (_hunger < 70)) :  {_colourHunger =  _colour60;};
			case((_hunger >= 50) && (_hunger < 60)) :  {_colourHunger =  _colour50;};
			case((_hunger >= 40) && (_hunger < 50)) :  {_colourHunger =  _colour40;};
			case((_hunger >= 30) && (_hunger < 40)) :  {_colourHunger =  _colour30;};
			case((_hunger >= 20) && (_hunger < 30)) :  {_colourHunger =  _colour20;};
			case((_hunger >= 10) && (_hunger < 20)) :  {_colourHunger =  _colour10;};
			case((_hunger >= 1) && (_hunger < 10)) :  {_colourHunger =  _colour0;};
			case(_hunger < 1) : {_colourHunger =  _colourDead;};
		};
		//Thirst
		_colourThirst = _colourDefault;		
		switch true do{
			case(_thirst >= 100) : {_colourThirst = _colour70;};
			case((_thirst >= 90) && (_thirst < 100)) :  {_colourThirst =  _colour70;};
			case((_thirst >= 80) && (_thirst < 90)) :  {_colourThirst =  _colour70;};
			case((_thirst >= 70) && (_thirst < 80)) :  {_colourThirst =  _colour70;};
			case((_thirst >= 60) && (_thirst < 70)) :  {_colourThirst =  _colour60;};
			case((_thirst >= 50) && (_thirst < 60)) :  {_colourThirst =  _colour50;};
			case((_thirst >= 40) && (_thirst < 50)) :  {_colourThirst =  _colour40;};
			case((_thirst >= 30) && (_thirst < 40)) :  {_colourThirst =  _colour30;};
			case((_thirst >= 20) && (_thirst < 30)) :  {_colourThirst =  _colour20;};
			case((_thirst >= 10) && (_thirst < 20)) :  {_colourThirst =  _colour10;};
			case((_thirst >= 1) && (_thirst < 10)) :  {_colourThirst =  _colour0;};
			case(_thirst < 1) : {_colourThirst =  _colourDead;};
		};
        //Damage
		_colourDamage = _colourDefault;
		switch true do {
			case(_damage >= 100) : {_colourDamage = _colour70;};
			case((_damage >= 90) && (_damage < 100)) : {_colourDamage =  _colour70;};
			case((_damage >= 80) && (_damage < 90)) : {_colourDamage =  _colour70;};
			case((_damage >= 70) && (_damage < 80)) : {_colourDamage =  _colour70;};
			case((_damage >= 60) && (_damage < 70)) : {_colourDamage =  _colour60;};
			case((_damage >= 50) && (_damage < 60)) : {_colourDamage =  _colour50;};
			case((_damage >= 40) && (_damage < 50)) : {_colourDamage =  _colour40;};
			case((_damage >= 30) && (_damage < 40)) : {_colourDamage =  _colour30;};
			case((_damage >= 20) && (_damage < 30)) : {_colourDamage =  _colour20;};
			case((_damage >= 10) && (_damage < 20)) : {_colourDamage =  _colour10;};
			case((_damage >= 1) && (_damage < 10)) : {_colourDamage =  _colour0;};
			case(_damage < 1) : {_colourDamage =  _colourDead;};
		};

    ((uiNamespace getVariable "osefStatusBar")displayCtrl 555556)ctrlSetStructuredText parseText 
            format["<t shadow='1' shadowColor='#000000'>
			<img size='1.6' shadowColor='#000000' image='icons\Statusbar\players.paa' color='#CC0000'/>%1
			<img size='1.6' shadowColor='#000000' image='icons\Statusbar\civ.paa' />%2 
			<img size='1.6' shadowColor='#000000' image='icons\Statusbar\polizei.paa' />%3 
			<img size='1.6' shadowColor='#000000' image='icons\Statusbar\drk.paa' />%4 
			<img size='1.6' shadowColor='#000000' image='icons\Statusbar\adac.paa'/>%5
			<img size='1.6' shadowColor='#000000' image='icons\Statusbar\food.paa' />%6 
			<img size='1.6' shadowColor='#000000' image='icons\Statusbar\thirst.paa' />%7 
			<img size='1.6' shadowColor='#000000' image='icons\Statusbar\life.paa' color='%9'/>%8 
			<img size='1.6' shadowColor='#000000' image='icons\Statusbar\battery.paa' />%10
			<img size='1.6' shadowColor='#000000' image='icons\Statusbar\money.paa' />%11 
			<img size='1.6' shadowColor='#000000' image='icons\Statusbar\bank.paa' />%12 
			<img size='1.6'  shadowColor='#000000' image='icons\Statusbar\restart.paa' color='%14'/>%13
			</t>",_players,_CivplayHUD,_WestplayHUD,_IndepplayHUD,_EastplayHUD,_hunger, _thirst, _damage, _colourDamage, _battery, _barcash, _bankcash, _UpTimeHUD, _colourUpTimeHUD];

	}; 
};