class Gc_SbarKeys {
	
	// kd: Basic data
	protected int							key_colors;
	protected Array <class <Inventory> >	card_key;
	protected Array <TextureId>				card_sprite;
	protected TextureId						no_sprite;
	
	// What gets actually drawn
	protected Array <TextureId>				shown_sprite;
	protected int							offset_x;
	
	// kd: No virtual; we know the object beforehand.
	void Init (int offset_per_key = 15) {
		no_sprite	= TexMan.CheckForTexture("tnt1a0", TexMan.type_any);
		offset_x	= offset_per_key;
		key_colors	= 0;
		card_key.		clear();
		shown_sprite.	clear();
		card_sprite.	clear();
	}
	
	void Copy (Gc_SbarKeys source) {
		card_key.		copy(source.card_key);
		card_sprite.	copy(source.card_sprite);
		shown_sprite.	copy(source.shown_sprite);
		key_colors	= source.key_colors;
		no_sprite	= source.no_sprite;
		offset_x	= source.offset_x;
	}
	
	void AddKey (class <Inventory> card_inv, String card_sprite_name) {
		card_key.		push(card_inv);
		card_sprite.	push(0);
		shown_sprite.	push(0);
		key_colors = card_key.size();
		
		int i = key_colors - 1;
		card_sprite [i] = TexMan.CheckForTexture(card_sprite_name, TexMan.type_any);
	}
	
	void FromInventory (Actor mo) {
		for(int i = 0; i < key_colors; i++) {
			bool has_card	= 0 < mo.CountInv(card_key [i]);
			
			if(has_card) {
				shown_sprite [i] = card_sprite [i];
			}
			
			else {
				shown_sprite [i] = no_sprite;
			}
		}
	}
	
	ui void DrawBottom (Gc_StatusBar bar, int x, int y, double scale = 1) {
		for(int i = 0; i < key_colors; i++) {
			bar.DrawTexture(
				shown_sprite [i], (x, y),
				bar.DI_FORCESCALE | bar.DI_ITEM_LEFT_TOP | bar.DI_SCREEN_BOTTOM,
				scale: scale * (1, 1));
			x += offset_x;
		}
	}
}

/*	kd:
	
	Doom has three pairs of two keys, which have their own sprites that can
	occupy the same space. In GC, you will get a unique sprite if you have both
	keys of the same colour.
	
	*/

class Gc_SbarDoomKeys : Gc_SbarKeys {
	
	// kd: Basic data
	protected Array <class <Inventory> >	skull_key;
	protected Array <TextureId>				skull_sprite;
	protected Array <TextureId>				double_sprite;
	
	void Init (int offset_per_key = 15) {
		super.Init(offset_per_key);
		skull_key.		clear();
		skull_sprite.	clear();
		double_sprite.	clear();
	}
	
	void AddKeyPair (
	class <Inventory>	card_inv,
	class <Inventory>	skull_inv,
	String	card_sprite_name,
	String	skull_sprite_name,
	String	double_sprite_name) {
		AddKey(card_inv, card_sprite_name);
		
		skull_key.	push(skull_inv);
		
		// gzd </3 TextureId arrays
		skull_sprite.	push(0);
		double_sprite.	push(0);
		
		int i = key_colors - 1;
		
		skull_sprite	[i] = TexMan.CheckForTexture(
			skull_sprite_name, TexMan.type_any);
		double_sprite	[i] = TexMan.CheckForTexture(
			double_sprite_name, TexMan.type_any);
		shown_sprite	[i] = no_sprite;
	}
	
	// kd: Technically, none of these branches are necessary. Changing this
	// would make keys more annoying to code, though.
	void FromInventory (Actor mo) {
		for(int i = 0; i < key_colors; i++) {
			bool has_card	= 0 < mo.CountInv(card_key [i]);
			bool has_skull	= 0 < mo.CountInv(skull_key [i]);
			
			if(has_card && has_skull) {
				shown_sprite [i] = double_sprite [i];
			}
			
			else if(has_skull) {
				shown_sprite [i] = skull_sprite [i];
			}
			
			else if(has_card) {
				shown_sprite [i] = card_sprite [i];
			}
			
			else {
				shown_sprite [i] = no_sprite;
			}
		}
	}
}