/*	kd:
	
	This is a single bar that counts some state, which could be your health,
	armour, or inventory. This doesn't belong in the ammo bar handling, btw.
	
	Typically, if it's some value measured from 0 to whatever, like the above,
	you can add a function here to calculate for that instead, or something.
	I dunno. I find this more convenient than inheritance.
	
	Going full OOP was a regrettable decision. At least I managed to make the
	draw functions relatively fast by caching everything.
	
	*/

/*	kd:
	
	
	
	This is a simple scrolling clip overlay that assumes the sprite you're using
	can fill the clipped area (like, for example, the status bar meters).
	
	*/

class Gc_SbarObject {
	// kd: For sbarinfo.
	protected int						align_flags;
	protected int						item_flags;
	
	enum align {
		left = 0
	,	right
	,	top
	,	bottom
	,	center
	}
	
	void SetScreenAlignment (
	align	hor = left,
	align	ver = top) {
		align_flags = 0;
		
		switch(hor) {
		default:
		case left:
			align_flags |= StatusBar.DI_SCREEN_LEFT;
			break;
		case right:
			align_flags |= StatusBar.DI_SCREEN_RIGHT;
			break;
		case center:
			align_flags |= StatusBar.DI_SCREEN_HCENTER;
			break;
		}
		
		switch(ver) {
		default:
		case top:
			align_flags |= StatusBar.DI_SCREEN_TOP;
			break;
		case bottom:
			align_flags |= StatusBar.DI_SCREEN_BOTTOM;
			break;
		case center:
			align_flags |= StatusBar.DI_SCREEN_VCENTER;
			break;
		}
	}
	
	protected int SetItemAlignment (
	align	hor = left,
	align	ver = top) {
		int flags = 0;
		
		switch(hor) {
		default:
		case left:
			flags |= StatusBar.DI_ITEM_LEFT;
			break;
		case right:
			flags |= StatusBar.DI_ITEM_RIGHT;
			break;
		case center:
			flags |= StatusBar.DI_ITEM_HCENTER;
			break;
		}
		
		switch(ver) {
		default:
		case top:
			flags |= StatusBar.DI_ITEM_TOP;
			break;
		case bottom:
			flags |= StatusBar.DI_ITEM_BOTTOM;
			break;
		case center:
			flags |= StatusBar.DI_ITEM_VCENTER;
			break;
		}
		
		return flags;
	}
	
	protected int SetTextAlignment (
	align	hor = left,
	align	ver = top) {
		int flags = 0;
		
		switch(hor) {
		default:
		case left:
			flags |= StatusBar.DI_TEXT_ALIGN_LEFT | StatusBar.DI_ITEM_LEFT;
			break;
		case right:
			flags |= StatusBar.DI_TEXT_ALIGN_RIGHT | StatusBar.DI_ITEM_RIGHT;
			break;
		case center:
			flags |= StatusBar.DI_TEXT_ALIGN_CENTER | StatusBar.DI_ITEM_HCENTER;
			break;
		}
		
		switch(ver) {
		default:
		case top:
			flags |= StatusBar.DI_ITEM_TOP;
			break;
		case bottom:
			flags |= StatusBar.DI_ITEM_BOTTOM;
			break;
		case center:
			flags |= StatusBar.DI_ITEM_VCENTER;
			break;
		}
		
		return flags;
	}
	
	void SetSelfAlignment (
	align hor		= left,
	align ver		= top) {
		item_flags = SetItemAlignment(hor, ver);
	}
	
	int AlignFlags () const {
		return align_flags | item_flags;
	}
}

class Gc_ClipOverlay : Gc_SbarObject ui {
	protected TextureId					sprite;
	protected int						sprite_width;
	protected int						sprite_height;
	
	protected double					step_size;
	protected double					offset;
	protected double					dir_offset;
	
	protected void Load (String sprite_name) {
		sprite = Gc_Sprite.Load(sprite_name);
		
		if(sprite.IsValid()) {
			vector2 size	= TexMan.GetScaledSize(sprite);
			sprite_width	= size.x;
			sprite_height	= size.y;
		}
		
		else {
			sprite_width	= 0;
			sprite_height	= 0;
		}
		
		SetScreenAlignment();
		SetSelfAlignment();
	}
	
	TextureId OverlaySprite () const {
		return sprite;
	}
	
	double RenderOffset (double t) const {
		return dir_offset + offset + t * step_size;
	}
	
	double SpriteWidth () const {
		return sprite_width;
	}
	
	double SpriteHeight () const {
		return sprite_height;
	}
}

class Gc_HorClipOverlay : Gc_ClipOverlay {
	Gc_HorClipOverlay Create (String sprite_name) {
		Gc_HorClipOverlay overlay = new("Gc_HorClipOverlay");
		
		if(overlay) {
			overlay.Load(sprite_name);
		}
		
		return overlay;
	}
	
	void SetScrollSpeed (double step = 1) {
		step_size = step;
		dir_offset = 0 < step ? -sprite_width : 0;
	}
	
	void Scroll () {
		offset += step_size;
		
		if(sprite_width <= offset) {
			offset -= sprite_width;
		}
		
		else if(offset <= -sprite_width) {
			offset += sprite_width;
		}
	}
}

class Gc_VerClipOverlay : Gc_ClipOverlay {
	Gc_VerClipOverlay Create (String sprite_name) {
		Gc_VerClipOverlay overlay = new("Gc_VerClipOverlay");
		
		if(overlay) {
			overlay.Load(sprite_name);
		}
		
		return overlay;
	}
	
	void SetScrollSpeed (double step = 1) {
		step_size = step;
		dir_offset = 0 < step ? -sprite_height : 0;
	}
	
	void Scroll () {
		offset += step_size;
		
		if(sprite_height <= offset) {
			offset -= sprite_height;
		}
		
		else if(offset <= -sprite_height) {
			offset += sprite_height;
		}
	}
}

class Gc_SbarMeterEx : Gc_SbarObject ui {
	protected FadeTickF					amount_t;
	protected TextureId					sprite;
	protected TextureId					bg_sprite;
	protected int						sprite_width;
	protected int						sprite_height;
	protected int						fill_tics;
	
	protected vector2					offset_to_top_left;
	
	protected double					amount_shown;
	protected double					max_amount_shown;
	
	protected String					amount_str;
	protected String					max_amount_str;
	
	// Offsets for the text strings by themselves:
	protected int						amount_align_flags;
	protected int						max_amount_align_flags;
	
	// And the actual relative position of the text strings on the bar:
	protected vector2					amount_offs;
	protected vector2					max_amount_offs;
	
	void Load (
	String	sprite_name,
	String	bg_sprite_name	= "") {
		LoadSprite(sprite_name, bg_sprite_name);
		
		// Timing:
		amount_shown		= 0;
		max_amount_shown	= 0;
		SetFillTics();
	}
	
	void LoadSprite (
	String	sprite_name,
	String	bg_sprite_name	= "") {
		if(GcString.IsEmpty(bg_sprite_name)) {
			bg_sprite = Gc_Sprite.Empty();
		}
		
		else {
			bg_sprite = Gc_Sprite.Load(bg_sprite_name);
		}
		
		sprite			= Gc_Sprite.Load(sprite_name);
		vector2 size	= TexMan.GetScaledSize(sprite);
		
		sprite_width	= size.x;
		sprite_height	= size.y;
		
		SetTextAlignment();
		SetTextPosition();
		SetSelfAlignment();
	}
	
	int AmountAlignFlags () const {
		return amount_align_flags;
	}
	
	int MaxAmountAlignFlags () const {
		return max_amount_align_flags;
	}
	
	vector2 AmountOffset () const {
		return amount_offs;
	}
	
	vector2 MaxAmountOffset () const {
		return max_amount_offs;
	}
	
	String AmountString () const {
		return amount_str;
	}
	
	String MaxAmountString () const {
		return max_amount_str;
	}
	
	void CacheOffsetToTopLeft () {
		// Horizontal:
		if(item_flags & StatusBar.DI_ITEM_LEFT) {
			offset_to_top_left.x = 0;
		}
		
		// kd: Be VERY (!!!) careful about the order! DI_ITEM_HCENTER is
		// just 0, so that means, if the other two flags aren't set, HCENTER is
		// implicitly set!
		else if(item_flags & StatusBar.DI_ITEM_RIGHT) {
			offset_to_top_left.x = -sprite_width;
		}
		
		else {
			offset_to_top_left.x = -0.5 * sprite_width;
		}
		
		// Vertical:
		if(item_flags & StatusBar.DI_ITEM_TOP) {
			offset_to_top_left.y = 0;
		}
		
		// Similar here! DI_ITEM_BOTTOM is 0!
		else if(item_flags & StatusBar.DI_ITEM_VCENTER) {
			offset_to_top_left.y = -0.5 * sprite_height;
		}
		
		else {
			offset_to_top_left.y = -sprite_height;
		}
	}
	
	vector2 OffsetToTopLeft () const {
		return offset_to_top_left;
	}
	
	double LeftOffset () const {
		return offset_to_top_left.x;
	}
	
	double TopOffset () const {
		return offset_to_top_left.y;
	}
	
	void SetTextPosition (
	vector2	amount_pos		= (0, 0.5),
	vector2 max_amount_pos	= (1, 0.5)) {
		amount_offs.x		= sprite_width	* amount_pos.x;
		amount_offs.y 		= sprite_height	* amount_pos.y;
		max_amount_offs.x	= sprite_width	* max_amount_pos.x;
		max_amount_offs.y	= sprite_height	* max_amount_pos.y;
	}
	
	protected double VerticalOffset (align flag) const {
		switch(flag) {
		case center:
			return 0.5;
		case bottom:
			return 1;
		}
		
		return 0;
	}
	
	void AddTextAlignment (
	HudFont ffont,
	align amt_hor	= left,
	align amt_ver	= center,
	align mamt_hor	= right,
	align mamt_ver	= center) {
		amount_align_flags		= SetTextAlignment(amt_hor, amt_ver);
		max_amount_align_flags	= SetTextAlignment(mamt_hor, mamt_ver);
		
		// kd: Apparently gzd sucks at aligning text, too.
		double height = ffont.mfont.GetHeight();
		max_amount_offs.y	-= VerticalOffset(mamt_ver) * height;
		amount_offs.y		-= VerticalOffset(amt_ver) * height;
	}
	
	void CopySize (Gc_SbarMeterEx source) {
		sprite_width	= source.sprite_width;
		sprite_height	= source.sprite_height;
	}
	
	void SetFillTics (int tics = 1) {
		fill_tics = max(1, tics);
	}
	
	TextureId MeterSprite () const {
		return sprite;
	}
	
	TextureId BackSprite () const {
		return bg_sprite;
	}
	
	double ClippedWidth (double t = 1) const {
		return amount_t.RenderStandardDelta(100.0, t) * sprite_width;
	}
	
	double ClippedHeight (double t = 1) const {
		return amount_t.RenderStandardDelta(100.0, t) * sprite_height;
	}
	
	double ClippedWidthRev (double t = 1) const {
		return
			(1 - amount_t.RenderStandardDelta(100.0, t)) * sprite_width;
	}
	
	double ClippedHeightRev (double t = 1) const {
		return
			(1 - amount_t.RenderStandardDelta(100.0, t)) * sprite_height;
	}
	
	double SpriteWidth () const {
		return sprite_width;
	}
	
	double SpriteHeight () const {
		return sprite_height;
	}
	
	double RemainderX (double x) const {
		return clamp(sprite_width - x, 0, sprite_width);
	}
	
	double RemainderY (double y) const {
		return clamp(sprite_height - y, 0, sprite_height);
	}
	
	double MovingAmount (double t = 1) const {
		return 
			amount_shown +
			amount_t.RenderStandardDelta(fill_tics, t) *
			(max_amount_shown - amount_shown);
	}
	
	double RealAmount () const {
		return amount_shown;
	}
	
	double MaxAmount () const {
		return max_amount_shown;
	}
	
	protected void PrepareForDraw (
	int		amount,
	int		max_amount) {
		amount_t.ContinueTo(100.0 * amount / max_amount);
		amount_shown		= amount;
		max_amount_shown	= max_amount;
		amount_t.NextStep(100.0 / fill_tics);
	}
	
	protected void PrepareForDrawWithText (
	int		amount,
	int		max_amount,
	int		text_amount,
	int		text_max_amount) {
		amount_t.ContinueTo(100.0 * amount / max_amount);
		amount_shown		= text_amount;
		max_amount_shown	= text_max_amount;
		amount_t.NextStep(100.0 / fill_tics);
	}
	
	void CacheAmountInt (String suffix = "") {
		amount_str = String.Format("%i%s", amount_shown, suffix);
	}
	
	void CacheAmountDecimal (String suffix = "") {
		amount_str = String.Format("%01.1f%s", amount_shown, suffix);
	}
	
	void CacheMovingAmountInt (double t = 1, String suffix = "") {
		amount_str = String.Format("%i%s", MovingAmount(t), suffix);
	}
	
	void CacheMovingAmountDecimal (double t = 1, String suffix = "") {
		amount_str = String.Format("%01.1f%s", MovingAmount(t), suffix);
	}
	
	void CacheMaxAmountInt (String suffix = "") {
		max_amount_str = String.Format("%i%s", max_amount_shown, suffix);
	}
	
	void CacheMaxAmountDecimal (String suffix = "") {
		max_amount_str = String.Format("%01.1f%s", max_amount_shown, suffix);
	}
	
	void Force () {
		amount_t.ForceDone();
	}
}

class Gc_SbarHealthMeter : Gc_SbarMeterEx {
	Gc_SbarHealthMeter Create (
	String	sprite_name,
	String	bg_sprite_name	= "") {
		Gc_SbarHealthMeter meter = new("Gc_SbarHealthMeter");
		
		if(meter) {
			meter.Load(sprite_name, bg_sprite_name);
		}
		
		return meter;
	}
	
	void Next (PlayerPawn po) {
		PrepareForDraw(max(0, po.health), po.GetMaxHealth());
	}
}

class Gc_SbarInvMeter : Gc_SbarMeterEx {
	Gc_SbarInvMeter Create (
	String	sprite_name,
	String	bg_sprite_name	= "") {
		Gc_SbarInvMeter meter = new("Gc_SbarInvMeter");
		
		if(meter) {
			meter.Load(sprite_name, bg_sprite_name);
		}
		
		return meter;
	}
	
	void Next (class <Inventory> inv_class, PlayerPawn po) {
		let inv = po.FindInventory(inv_class);
		
		if(inv) {
			PrepareForDraw(inv.amount, inv.maxamount);
		}
		
		else {
			PrepareForDraw(0, 1);
		}
	}
	
	// kd: This fills the bar up the less you have of the inventory!
	// Used for Supermags (Johnson and Theta).
	void InversedNext (class <Inventory> inv_class, PlayerPawn po) {
		let inv = po.FindInventory(inv_class);
		
		if(inv) {
			PrepareForDraw(inv.maxamount - inv.amount, inv.maxamount);
		}
		
		else {
			PrepareForDraw(1, 1);
		}
	}
}

class Gc_SbarArmorMeter : Gc_SbarMeterEx {
	Gc_SbarArmorMeter Create (
	String	sprite_name,
	String	bg_sprite_name	= "") {
		Gc_SbarArmorMeter meter = new("Gc_SbarArmorMeter");
		
		if(meter) {
			meter.Load(sprite_name, bg_sprite_name);
		}
		
		return meter;
	}
	
	void Next (PlayerPawn po, int molten_bonus = 0) {
		let player_armor	= BasicArmor(po.FindInventory("BasicArmor"));
		int amount			= 0;
		int max_amount		= 1;
		int text_amount		= 0;
		
		// Should always be there but you never know.
		if(player_armor) {
			// kd: The opposite of syntactical sugar.
			let armor_class	= (class <BasicArmorPickup>)(player_armor.armortype);
			
			if(armor_class) {
				let def_type	= GetDefaultByType(armor_class);;
				max_amount		= player_armor.actualsaveamount;
			}
			
			else {
				max_amount = player_armor.maxamount;
			}
			
			// or actualsaveamount or amount???
			amount = min(max_amount, player_armor.amount);
			text_amount = max(amount, player_armor.amount);
		}
		
		// kd: evil hardcoding 
		max_amount += po.CountInv("MoltenArmor") * molten_bonus;
		max_amount = max(1, max_amount);
		
		PrepareForDrawWithText(
			amount,
			max_amount,
			text_amount,
			max_amount);
	}
}

class Gc_SbarPowerupMeter : Gc_SbarMeterEx {
	Gc_SbarPowerupMeter Create (
	String	sprite_name,
	String	bg_sprite_name	= "") {
		Gc_SbarPowerupMeter meter = new("Gc_SbarPowerupMeter");
		
		if(meter) {
			meter.Load(sprite_name, bg_sprite_name);
		}
		
		return meter;
	}
	
	void Next (class <Powerup> power, PlayerPawn po) {
		int amount		= 0;
		int max_amount	= 1;
		
		let pow = Powerup(po.FindInventory(power));
		
		if(pow) {
			amount = pow.effecttics;
			max_amount = GetDefaultByType(power).effecttics;
		}
		
		PrepareForDrawWithText(
			amount, max_amount,
			amount, max_amount);
	}
	
	void InversedNext (class <Powerup> power, PlayerPawn po) {
		int amount		= 0;
		int max_amount	= 1;
		
		let pow = Powerup(po.FindInventory(power));
		
		if(pow) {
			amount = pow.effecttics;
			max_amount = GetDefaultByType(power).effecttics;
		}
		
		//console.printf("%i %i", amount, max_amount);
		
		PrepareForDrawWithText(
			max(max_amount - amount, 0), max_amount,
			amount / Thinker.ticrate, max_amount / Thinker.ticrate);
	}
}

class Gc_SbarAirMeter : Gc_SbarMeterEx {
	Gc_SbarAirMeter Create (
	String	sprite_name,
	String	bg_sprite_name	= "") {
		Gc_SbarAirMeter meter = new("Gc_SbarAirMeter");
		
		if(meter) {
			meter.Load(sprite_name, bg_sprite_name);
		}
		
		return meter;
	}
	
	void Next (PlayerInfo player) {
		int amount		= max(0, player.air_finished - level.time);;
		int max_amount	= 60 * Thinker.ticrate; // kd: Seems hardcoded...
		
		PrepareForDrawWithText(
			amount, max_amount,
			amount / Thinker.ticrate, 60);
	}
}

/*	kd:
	
	This code is retired. */

/* struct Gc_SbarMeter ui {
	// The bar itself:
	private FadeTick					amount_t;
	private TextureId					sprite;
	private int							amount;
	private int							max_amount;
	private int							sprite_width;
	private int							sprite_height;
	
	// The scrolling texture overlay:
	private TextureId					overlay_sprite;
	private int							overlay_width;
	private int							overlay_height;
	private double						overlay_offset;
	private int							overlay_count;
	private double						overlay_speed;
	
	void Load (String sprite_name) {
		sprite			= TexMan.CheckForTexture(sprite_name, TexMan.type_any);
		vector2 size	= TexMan.GetScaledSize(sprite);
		sprite_width	= size.x;
		sprite_height	= size.y;
	}
	
	void LoadWithOverlay (String sprite_name, String overlay_sprite_name) {
		Load(sprite_name);
		
		overlay_sprite	= TexMan.CheckForTexture(overlay_sprite_name, TexMan.type_any);
		vector2 size2	= TexMan.GetScaledSize(overlay_sprite);
		overlay_width	= size2.x;
		overlay_height	= size2.y;
		overlay_count	= 1 + sprite_width / overlay_width;
	}
	
	void Copy (Gc_SbarMeter source) {
		amount_t.Copy(source.amount_t);
		sprite			= source.sprite;
		amount			= source.amount;
		max_amount		= source.max_amount;
		sprite_width	= source.sprite_width;
		sprite_height	= source.sprite_height;
		overlay_sprite	= source.overlay_sprite;
		overlay_width	= source.overlay_width;
		overlay_height	= source.overlay_height;
		overlay_offset	= source.overlay_offset;
		overlay_count	= source.overlay_count;
		overlay_speed	= source.overlay_speed;
	}
	
	// kd: Call this after any of the below to prevent interpolation.
	void Force () {
		amount_t.Force(amount, max_amount);
	}
	
	void ScrollOverlayHor (double offset) {
		overlay_offset =
			(overlay_offset + offset) % overlay_width - overlay_width;
		overlay_speed = offset;
	}
	
	void ScrollOverlayVer (double offset) {
		overlay_offset =
			(overlay_offset + offset) % overlay_height - overlay_height;
		overlay_speed = offset;
	}
	
	void ToHealth (Gc_StatusBar bar, int speed = 1) {
		let mo = bar.cplayer.mo;
		amount = max(0, mo.health);
		max_amount = mo.GetMaxHealth();
		amount_t.ContinueTo(amount);
		amount_t.NextStep(speed);
	}
	
	void ToAir (Gc_StatusBar bar, int speed = 1) {
		amount = bar.GetAirTime();
		max_amount = 60 * Thinker.TICRATE;	// kd: Seems to be hardcoded!
		amount_t.ContinueTo(amount);
		amount_t.NextStep(speed);
	}
	
	void ToArmor (Gc_StatusBar bar, int speed = 1) {
		ToInventory(bar, "BasicArmor", speed);
	}
	
	void ToInventory (Gc_StatusBar bar, class <Inventory> inv, int speed = 1) {
		[amount, max_amount] = bar.GetAmount(inv);
		amount_t.ContinueTo(amount);
		amount_t.NextStep(speed);
	}
	
	void ToInventoryRev (Gc_StatusBar bar, class <Inventory> inv, int speed = 1) {
		[amount, max_amount] = bar.GetAmount(inv);
		amount = max_amount - amount;
		
		amount_t.ContinueTo(amount);
		amount_t.NextStep(speed);
	}
	
	void ToPowerupDuration (Gc_StatusBar bar, class <Powerup> inv, int speed = 1) {
		let mo_inv = Powerup(bar.cplayer.mo.FindInventory(inv));
		
		if(mo_inv) {
			amount = mo_inv.effecttics;
		}
		
		else {
			amount = 0;
		}
		
		max_amount = GetDefaultByType(inv).effecttics;
		
		amount_t.ContinueTo(amount);
		amount_t.NextStep(speed);
	}
	
	void ClampBelow (Gc_SbarMeter other) {
		int other_tics = other.amount_t.Now();
		
		if(amount_t.Now() < other_tics) {
			amount_t.Force(other_tics, max_amount);
		}
	}
	
	void CopyDimensions (Gc_SbarMeter source) {
		sprite_width = source.sprite_width;
		sprite_height = source.sprite_height;
	}
	
	private double ClippedWidth (double t) const {
		return
			sprite_width *
			clamp(amount_t.RenderStandardDelta(max(1, max_amount), t), 0, 1);
	}
	
	private double ClippedHeight (double t) const {
		return
			sprite_height *
			clamp(amount_t.RenderStandardDelta(max(1, max_amount), t), 0, 1);
	}
	
	void DrawBottomVer (
	Gc_StatusBar bar,
	int x, int y,
	double t, double alpha = 1) const {
		bar.DrawRightBarBottom(sprite, x, y, sprite_width, ClippedHeight(t), alpha);
	}
	
	void DrawBottomVerRev (
	Gc_StatusBar bar,
	int x, int y,
	double t, double alpha = 1) const {
		double clip_height = ClippedHeight(t);
		double clip_y = y + sprite_height - clip_height;
		
		bar.SetClipRect(x, clip_y, sprite_width, clip_height);
		bar.DrawTexture(sprite, (x, y), bar.DI_ITEM_LEFT_TOP | bar.DI_SCREEN_BOTTOM, alpha);
	}
	
	void DrawBottom (
	Gc_StatusBar bar,
	int x, int y,
	double t, double alpha = 1) const {
		bar.DrawRightBarBottom(sprite, x, y, ClippedWidth(t), sprite_height, alpha);
	}
	
	void DrawBottomRev (
	Gc_StatusBar bar,
	int x, int y,
	double t, double alpha = 1) const {
		double clip_width = ClippedWidth(t);
		double clip_x = x + sprite_width - clip_width;
		
		bar.SetClipRect(clip_x, y, clip_width, sprite_height);
		bar.DrawTexture(sprite, (x, y), bar.DI_ITEM_LEFT_TOP | bar.DI_SCREEN_BOTTOM, alpha);
	}
	
	void DrawBottomRight (
	Gc_StatusBar bar,
	int x, int y,
	double t, double alpha = 1) const {
		bar.DrawRightBarBottomRight(sprite, x, y, ClippedWidth(t), sprite_height, alpha);
	}
	
	void Dim (
	Gc_StatusBar bar,
	Color fill_Color,
	int x, int y, double t) const {
		bar.Fill(fill_color, x, y, ClippedWidth(t), sprite_height);
	}
	
	void DrawBottomFilled (
	Gc_StatusBar bar,
	int x, int y,
	double alpha = 1) const {
		bar.DrawRightBarBottom(sprite, x, y, sprite_width, sprite_height, alpha);
	}
	
	void DrawBottomHorOverlay (
	Gc_StatusBar bar,
	double x,
	double y,
	double t,
	double alpha = 1,
	double overlay_alpha = 1) const {
		bar.DrawRightBarBottom(
			sprite, x, y, ClippedWidth(t), sprite_height, alpha);
		
		x = overlay_offset - overlay_width + (1 - t) * overlay_speed;
		for(int i = 0; i <= overlay_count; i++) {
			x += overlay_width;
			bar.DrawTexture(
				overlay_sprite,
				(x, y),
				bar.DI_ITEM_LEFT_TOP | bar.DI_SCREEN_BOTTOM,
				overlay_alpha);
		}
	}
	
	void DrawBottomVerOverlay (
	Gc_StatusBar bar,
	double x,
	double y,
	double t,
	double alpha = 1,
	double overlay_alpha = 1) const {
		bar.DrawRightBarBottom(
			sprite, x, y, ClippedWidth(t), sprite_height, alpha);
		
		y = y + 3 * overlay_height + overlay_offset + t * overlay_speed;
		for(int i = 0; i <= overlay_count; i++) {
			bar.DrawTexture(
				overlay_sprite,
				(x, y),
				bar.DI_ITEM_LEFT_BOTTOM | bar.DI_SCREEN_BOTTOM,
				overlay_alpha);
			y -= overlay_height;
		}
	}
	
	void DimBottom (Gc_StatusBar bar, Color fill_Color, int x, int y, double t) const {
		bar.Fill(
			fill_color,
			x, y,
			ClippedWidth(t), sprite_height,
			bar.DI_SCREEN_LEFT_BOTTOM);
	}
	
	void DrawAmountBottom (
	Gc_StatusBar bar, HudFont ffont,
	int x, int y, int color = Font.cr_untranslated, double alpha = 1) const {
		bar.DrawRightNum(amount, x + sprite_width - 1, y, ffont, color, alpha);
	}
	
	void DrawAmountBottomLeft (
	Gc_StatusBar bar, HudFont ffont,
	int x, int y, int color = Font.cr_untranslated, double alpha = 1) const {
		bar.DrawLeftNum(amount, x + 1, y, ffont, color, alpha);
	}
} */