Class GHAGStatus : BaseStatusBar
{
	BoxObject rootscene;
	BoxObject battlehud;
	ImageObject battleborder;
	BoxObject weapons;
	
	meterobject healthbar_grn;
	meterobject healthbar_orn;
	meterobject healthbar_red;
	meterobject armorbar;
	meterobject angerbar;
	
	stringobject healthamount;
	stringobject armoramount;
	stringobject angeramount;
	stringobject angeramountEcho;
	stringobject ragedisplay;
	stringobject ragedisplayEcho;
	stringobject gunname;
	stringobject ammocount;
	
	Array<ImageObject> weapitems;
	ImageObject weapslot_zero;
	
	BoxObject keybox;
	imageobject keyslot_a;
	imageobject keyslot_b;
	imageobject keyslot_c;
	
	Font fnt_white;
	HUDFont pokefont;
	
	vector2 battlehudscale;
	vector2 scale;
	vector2 size;
	Vector2 ragepos;
	Vector2 angerpos;
	
	string wtfString;
	double userscale;
	
	int lastAngerValue;
	
	override void Init()
	{
		Super.Init();
		
		fnt_white = "PKMNWHITE";
		pokefont = HUDFont.Create(fnt_white);
		
		weapitems.clear();
		weapitems.reserve(3);
		
		battlehudscale = (0.75, 0.75);
		ragepos = (6, 18);
		angerpos = (140, 120);
		
		rootscene = BoxObject.create((0, 0), (1, 1), self);
		battlehud = BoxObject.create((0, 0), (1, 1));
		battleborder = ImageObject.create("BATTLHUD", (0, 0), battlehudscale);
		
		double bar_x = 81;
		
		healthbar_grn = MeterObject.create("HPBAR", (bar_x, 6));
		healthbar_grn.current = 350;
		healthbar_grn.max = 350;
		healthbar_orn = MeterObject.create("HPBARHLF", (bar_x, 6));
		healthbar_orn.visible = false;
		healthbar_orn.current = 350;
		healthbar_orn.max = 350;
		healthbar_red = MeterObject.create("ANGBAR", (bar_x, 6));
		healthbar_red.visible = false;
		healthbar_red.current = 350;
		healthbar_red.max = 350;
		
		healthamount = StringObject.create("", (140, 3), (0.55, 0.55));
		healthamount.ObjectFont = pokefont;
		
		armorbar = MeterObject.create("ARMBAR", (bar_x, 28));
		armorbar.current = 0;
		armorbar.max = 200;
		
		armoramount = StringObject.create("", (140, 35), (0.55, 0.55));
		armoramount.ObjectFont = pokefont;
		
		angerbar = MeterObject.create("ANGBAR", (bar_x, 91));
		angeramount = StringObject.create("", angerpos, (0.55, 0.55));
		angeramount.ObjectFont = pokefont;
		angeramountEcho = StringObject.create("", angerpos, (0.55, 0.55));
		angeramountEcho.ObjectFont = pokefont;
		angeramountEcho.visible = false;
		
		ragedisplay = StringObject.create("", ragepos, (1.75, 1.75));
		ragedisplay.ObjectFont = pokefont;
		ragedisplay.FontTranslation = Font.CR_DARKRED;
		ragedisplayEcho = StringObject.create("", ragepos, (1.75, 1.75));
		ragedisplayEcho.ObjectFont = pokefont;
		ragedisplayEcho.FontTranslation = Font.CR_DARKRED;
		ragedisplayEcho.visible = false;
		
		gunname = StringObject.create("", (15, -35), (0.75, 0.75));
		gunname.ObjectFont = pokefont;
		ammocount = StringObject.create("", (15, -18), (0.75, 0.75));
		ammocount.ObjectFont = pokefont;
		
		rootscene.addChild(battlehud);
		battlehud.addChild(battleborder);
		
		battleborder.addchild(healthbar_grn);
		battleborder.addchild(healthbar_orn);
		battleborder.addchild(healthbar_red);
		battleborder.addchild(armorbar);
		battleborder.addchild(angerbar);
		
		battlehud.addchild(healthamount);
		battlehud.addchild(armoramount);
		battlehud.addchild(angeramountEcho);
		battlehud.addchild(angeramount);
		
		battlehud.addChild(ragedisplayEcho);
		battlehud.addChild(ragedisplay);
		
		battlehud.addChild(gunname);
		battlehud.addChild(ammocount);
		
		weapons = BoxObject.Create();
		rootscene.addChild(weapons);
		
		keybox = BoxObject.create((-25, 0), (1.5, 1.5));
		weapons.addChild(keybox);
		keyslot_a = ImageObject.create("");
		keyslot_b = ImageObject.create("", (10, 0));
		keyslot_c = ImageObject.create("", (20, 0));
		keybox.addChild(keyslot_a);
		keybox.addChild(keyslot_b);
		keybox.addChild(keyslot_c);
	}
	
	void updateScale()
	{
		size = (Screen.getWidth(), Screen.getHeight());
		scale = getHUDScale();
		
		size.x /= scale.x;
		size.y /= scale.y;
		
		double hscale = CVar.GetCVar('hud_scale', CPlayer).GetFloat();
		userscale = hscale > 0. ? hscale : 1;
		userscale *= CVAR.GetCVar("ghaghudscale", CPlayer).GetFloat();
	}
	
	override void Tick()
	{
		Super.tick();
		
		if (gametic % 10 == 0) wtfString = wtf();
		
		updateScale();
		
		if (CPlayer.ReadyWeapon)
		{
			gunname.msg = CPlayer.ReadyWeapon.getTag();
			ammocount.msg = "";
			if (CPlayer.ReadyWeapon is "GHAGPsychoCutter")
			{
				ammocount.msg = CPlayer.mo.countInv('GHAGPsychoCutterOverlay') .. '/4 Lacerators';
			}
			else if (CPlayer.ReadyWeapon.Ammo1)
			{
				ammocount.msg = 'Ammo: ' .. CPlayer.ReadyWeapon.Ammo1.Amount .. '/' .. CPlayer.ReadyWeapon.Ammo1.MaxAmount;
			}
		}
		
		healthbar_grn.current = CPlayer.mo.health;
		healthbar_orn.current = CPlayer.mo.health;
		healthbar_red.current = CPlayer.mo.health;
		
		if (CPlayer.mo.health > 175)
		{
			healthbar_grn.visible = true;
			healthbar_orn.visible = false;
			healthbar_red.visible = false;
		}
		else if (CPlayer.mo.health <= 175 && CPlayer.mo.health > 70)
		{
			healthbar_grn.visible = false;
			healthbar_orn.visible = true;
			healthbar_red.visible = false;
		}
		else
		{
			healthbar_grn.visible = false;
			healthbar_orn.visible = false;
			healthbar_red.visible = true;
		}
		healthamount.msg = CPlayer.mo.health .. '/350 HP';
		
		armorbar.current = GetArmorAmount();
		armoramount.msg = GetArmorAmount() .. ' Armor';
		
		angerbar.current = Min(GHAGGardevoir(CPlayer.mo).rageValue, GHAGGardevoir(CPlayer.mo).rageConstant);
		angerbar.max = GHAGGardevoir(CPlayer.mo).rageConstant;
			
		string angy_percent = String.Format("%.1f", (Float(GHAGGardevoir(CPlayer.mo).RageValue) / 10));
		string angry_cap = String.format("%.1f", (Float(GHAGGardevoir(CPlayer.mo).RageConstant) / 10));
		
		if (GHAGGardevoir(CPlayer.mo).ragevalue <= GHAGGardevoir(CPlayer.mo).rageConstant)
		{
			angeramount.msg = angy_percent .. '/' .. angry_cap;
			ragedisplayEcho.visible = false;
			if (GHAGGardevoir(CPlayer.mo).ragevalue > lastAngerValue)
			{
				angeramountEcho.visible = true;
				angeramountEcho.msg = angy_percent .. '/' .. angry_cap;
				angeramountEcho.position = angerpos + (random(-5, 5), random(-5, 5));
			}
			else
			{
				if (gametic % 5 == 0) angeramountEcho.visible = false;
			}
			
		}
		else
		{
			angeramount.msg = wtfString;
			angeramountEcho.msg = wtfString;
			angeramountEcho.visible = true;
			angeramountEcho.position = angerpos + (random(-5, 5), random(-5, 5));
			ragedisplayEcho.msg = GetAngerString();
			ragedisplayEcho.visible = true;
			ragedisplayEcho.position = ragepos + (random(-10, 10), random(-10, 10));
		}
		
		lastAngerValue = GHAGGardevoir(CPlayer.mo).ragevalue;
		
		ragedisplay.msg = GetAngerString();
		
		weapitems.clear();
		weapitems.reserve(3);
		weapons.children.clear();
		weapons.addChild(keybox);
		
		int weaponcount = 0;
		for (int i = 0; i < 10; ++i)
		{
			for (int j = 0; j < CPlayer.weapons.SlotSize(i); ++j)
			{
				let gun = Weapon(CPlayer.mo.FindInventory(CPlayer.weapons.GetWeapon(i, j)));			
				ImageObject selected;
				ImageObject notSelected;
				ImageObject empty;
				
				if (gun)
				{
					if (!weapitems[weaponcount])
					{
						let selected = ImageObject.create("WEPACTIV", (0, 0), (1.5, 1.5));
						let notSelected = ImageObject.create("WEPINNAC", (0, 0), (1.5, 1.5));
						let empty = ImageObject.create("WEPEMPTY", (0, 0), (1.5, 1.5));
						
						weapons.addChild(selected);
						weapons.addChild(notSelected);
						weapons.addChild(empty);
						
						weapitems.insert(weaponcount, selected);
						weapitems.insert(weaponcount + 1, notSelected);
						weapitems.insert(weaponcount + 2, empty);
						
						weapitems.grow(3);
					}
				
					selected = weapitems[weaponcount];
					notSelected = weapitems[weaponcount + 1];
					empty = weapitems[weaponcount + 2];
				
					Vector2 pos = (8 * gun.slotNumber, -10 * j);
				
					selected.position = pos;
					notSelected.position = pos;
					empty.position = pos;
					
					if (CPlayer.ReadyWeapon == gun)
					{
						notSelected.visible = false;
						
						if (gun.ammo1)
						{
							if (gun.ammo1.amount == 0)
							{
								selected.visible = false;
								empty.visible = true;
							} 
							else
							{
								selected.visible = true;
								empty.visible = false;
							}
						} 
						else
						{
							selected.visible = true;
							empty.visible = false;
						}
						
					}
					else
					{
						selected.visible = false;
						
						if (gun.ammo1)
						{
							if (gun.ammo1.amount == 0)
							{
								notSelected.visible = false;
								empty.visible = true;
							} 
							else
							{
								notSelected.visible = true;
								empty.visible = false;
							}
						} 
						else
						{
							notSelected.visible = true;
							empty.visible = false;
						}
					}
					
					weaponcount += 3;
				}
			}
		}
		
		bool locks[6];
		for (int i = 0; i < 6; i++) {
			locks[i] = CPlayer.mo.CheckKeys(i + 1, false, true);
		}
		
		if (locks[1] || locks[4])
		{
			keyslot_a.visible = true;
			if (locks[1] && locks[4]) keyslot_a.texture = "STKEYS6";
			else if (locks[1]) keyslot_a.texture = "STKEYS0";
			else if (locks[4]) keyslot_a.texture = "STKEYS3";
		}
		else
		{
			keyslot_a.visible = false;
		}
		
		if (locks[2] || locks[5])
		{
			keyslot_b.visible = true;
			if (locks[2] && locks[5]) keyslot_b.texture = "STKEYS7";
			else if (locks[2]) keyslot_b.texture = "STKEYS1";
			else if (locks[5]) keyslot_b.texture = "STKEYS4";
		}
		else
		{
			keyslot_b.visible = false;
		}
		
		if (locks[0] || locks[3])
		{
			keyslot_c.visible = true;
			if (locks[0] && locks[3]) keyslot_c.texture = "STKEYS8";
			else if (locks[0]) keyslot_c.texture = "STKEYS2";
			else if (locks[3]) keyslot_c.texture = "STKEYS5";
		}
		else
		{
			keyslot_c.visible = false;
		}
		
	}

	override void Draw(int state, double tic) 
	{
		
		Super.Draw(state, tic);
		
		if (state == HUD_None) return;
		
		BeginHUD();
		
		updateScale();
		
		//console.printf('' .. size);
		battlehud.position = (10, (size.y / userscale) - 85);
		weapons.position = ((size.x / userscale) - 110, (size.y / userscale) - 15);
		
		battlehud.scale = (userscale, userscale);
		weapons.scale = (userscale, userscale);
	
		rootscene.draw();
	}
	
	string wtf()
	{
		string value = '';
		for (int i = 0; i < 10; ++i)
		{
			int rng = Random(1, 2);
			if (rng % 2 == 0) value = value .. '!';
			else value = value .. '?';
		}
		return value;
	}
	
	string GetAngerString()
	{
		let gardie = GHAGGardevoir(CPlayer.mo);
		if (!gardie) return "I'm so angry, I simply do not exist!";
		
		if (Gardie.RageValue < 0) return "Drained";
		if (Gardie.overTheEdge) {
			switch(GameInfo.GameType)
			{
				case 1:
					return "HELL HATH NO FURY";
				case 2:
					return "D'SPARIL TREMBLES";
				case 4:
					return "KORAX SHALL CRAWL";
				default:
					console.printf('' .. GameInfo.GameType);
					return "hurrrrrr";
			}
		}
		
		if (Gardie.RageValue > 1000) return "MURDEROUS";
		
		int anger = Min(Gardie.RageValue, 1000) / 100;
		switch (anger) {
			case 0:
				return "Calm";
			case 1:
				return "Annoyed";
			case 2:
				return "Bitter";
			case 3:
				return "Heated";
			case 4:
				return "Fuming";
			case 5:
				return "Hateful";
			case 6:
				return "Savage";
			case 7:
				return "Scornful";
			case 8:
				return "Livid";
			case 9:
			case 10:
				return "Seeing Red";
				
		}
		
		return "So hecking angery, that idk what to call this!";
	}
}