/*	kd:
	
	This might be cool.
	
	*/

struct Gc_Shop_CursorAnim {
	private TextureId				sprite_cursor;
	private vector2					window_resolution;
	private vector2					outside_pos;
	
	private FadeTick				slide_t;
	
	void OnOpen (vector2 resolution, PlayerInfo player_info, Gc_Rng rng) {
		// kd: Might change, so...
		sprite_cursor		= Gc_MenuPreference.Cursor(player_info);
		window_resolution	= resolution;
		
		// kd: Come in from somewhere just outside the window. Then bring on
		// the animation.
		SetRandomOutsidePos(rng);
		slide_t.To(0, from: 15);
	}
	
	void OnClose (Gc_Rng rng) {
		SetRandomOutsidePos(rng);
		slide_t.To(15, from: 0);
	}
	
	private void SetRandomOutsidePos (Gc_Rng rng) {
		if(rng.Binary() < 1) {
			outside_pos.x = window_resolution.x * rng.Unit();
			outside_pos.y = window_resolution.y * rng.Binary();
		}
		
		else {
			outside_pos.x = window_resolution.x * rng.Binary();
			outside_pos.y = window_resolution.y * rng.Unit();
		}
	}
	
	void NextState () {
		slide_t.Next();
	}
	
	ui void DrawNoSlide (
	Gc_Shop_UiHandling	ui_handling,
	double				t = 1) const {
		InternDraw(ui_handling.mouse_input.DrawPos());
	}
	
	ui void Draw (
	Gc_Shop_UiHandling	ui_handling,
	double				t = 1) const {
		let pos = ui_handling.mouse_input.DrawPos(t);
		
		// kd: This way, the cursor can leave and enter. It's kinda cute.
		let anim_f	= slide_t.RenderStandardDelta(15, t);
		anim_f		= 1 - Gc_Interpol.trerpfast_unit(1 - anim_f);
		
		pos += anim_f * (outside_pos - pos);
		
		InternDraw(pos);
	}
	
	private ui void InternDraw (vector2 pos) const {
		let shadow_pos = pos + 4 * (1, 1);
		
		Screen.DrawTexture(
			sprite_cursor,
			true,
			shadow_pos.x,
			shadow_pos.y,
			DTA_VIRTUALWIDTHF,	window_resolution.x,
			DTA_VIRTUALHEIGHTF,	window_resolution.y,
			DTA_KEEPRATIO,		true,
			DTA_TOPOFFSET,		0,
			DTA_LEFTOFFSET,		0,
			DTA_FILLCOLOR,		0,
			DTA_ALPHA,			0.3);
		
		Screen.DrawTexture(
			sprite_cursor,
			true,
			pos.x,
			pos.y,
			DTA_VIRTUALWIDTHF,	window_resolution.x,
			DTA_VIRTUALHEIGHTF,	window_resolution.y,
			DTA_KEEPRATIO,		true,
			DTA_TOPOFFSET,		0,
			DTA_LEFTOFFSET,		0);
	}
}