module vs.scene.gameclear;



private import std.math;
private import gedo.gui.label;
private import gedo.gui.cursor;
private import gedo.gui.component;
private import gedo.audio.sound;
private import gedo.audio.music;
private import gedo.video.ggl;
private import gedo.video.rect;
private import gedo.video.color;
private import gedo.video.texture;
private import gedo.video.staticmesh;
private import gedo.input.joystick;
private import gedo.system.scene;
private import vs.scene.action;
private import vs.action.field;
private import vs.scene.characterselect;



private const float[2] CANVAS_SIZE = [640, 480];



alias Scene delegate() OnQuit;



public class GameClear : Scene
{
public:
	this(OnQuit dg)
	{
		_onQuit = dg;

		_bg     = Texture("$LIB/gameclear/bg.png", false);
		_credit = Texture("$LIB/gameclear/credit.png", false);
		_thank  = Texture("$LIB/gameclear/thank.png", false);

		_bgm = new Music("$LIB/gameclear/bgm.txt");
		_bgm.play();

		_time = 0;
	}


	override void update()
	{
		const auto SCENE_END_TIME = 60*20;

		if(_time >= SCENE_END_TIME)
		{
			_nextScene = _onQuit();
		}
		else
		{
			if(_time >= 60 && Joysticks().detectPressed())
			{
				_time = SCENE_END_TIME;
			}
			else
			{
				++_time;
			}
		}
	}


	override void draw()
	{
		const auto SPEED = 1.0;

		GGL_enableDepthBuffer(0);

		GGL_enableAlphaBlend(1);

		GGL_enter2DMode(CANVAS_SIZE[0], CANVAS_SIZE[1]);

		auto y = -0.5 * (CANVAS_SIZE[1] + _credit.height) + _time * SPEED;
		if(y > CANVAS_SIZE[1])
		{
			y = CANVAS_SIZE[1];
		}
		_bg.draw();

		GGL_translate(0.0, y, 0.0);
		_credit.draw();

		GGL_translate(0.0, -CANVAS_SIZE[1], 0.0);
		_thank.draw();
	}


private:
	Texture _bg;
	Texture _credit;
	Texture _thank;
	OnQuit  _onQuit;
	Music   _bgm;
	int     _time;
}
