//@STATE=嶌惉拞
//@DESCRIPTION ---------------------------------------------------------------
// AuthorImpl.h: AuthorImpl 僋儔僗偺幚憰
//	惢嶌幰昞帵僔乕儞
//	棜楌丗
// $Log: SceneAuthor.cpp,v $
// Revision 1.1  2001/10/28 21:40:37  fujiwara
// DLL偵暘妱
//
// Revision 1.5  2001/07/09 20:30:09  fujiwara
// 椺奜張棟偺慻傒崬傒
//
// Revision 1.4  2001/07/01 21:30:34  fujiwara
// 儊儌儕儕乕僋僠僃僢僋尒捈偟
//
// Revision 1.3  2001/07/01 01:03:44  fujiwara
// const 偺尒捈偟
// 攝抲僄僨傿僞偼搑拞宱夁
//
// Revision 1.2  2001/05/12 00:49:09  fujiwara
// 俠倁俽傪摫擖偟丄儘僌昞帵傪捛壛
//
//	2001/01/29 儊儌儕乕儕乕僋専弌梡儔僀僽儔儕偺捛壛 
//@DESCRIPTION_END -----------------------------------------------------------
//@AUTHOR=S.F.
// Copyright (C) 2000 Satoshi Fujiwara. All Rights Reserved.
///////////////////////////////////////////////////////////////////////////////
#pragma warning( disable : 4786 )	//STL偺寈崘奜偟
// 儊儌儕乕儕乕僋専弌梡
#include "sfdebug.h"

#include <stack>
#include <list>
#include <vector>

#include "exception.h"
#include "system.h"
#include "sound.h"
#include "console.h"
#include "obj.h"
#include "Obj2D.h"
#include "Obj3D.h"
#include "ObjRectangle.h"
#include "ObjQuadrangle.h"
#include "input.h"
#include "Scene.h"
#include "Fade.h"
#include "main.h"
#include "AbstractScene.h"
#include "s2001.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#include "AuthorImpl.h"

//////////////////////////////////////////////////////////////////////
// 峔抸/徚柵
//////////////////////////////////////////////////////////////////////
using namespace sf::application::scene;

const int AuthorImpl::PERIOD = 1000 / sf::system::TIMER_INTERVAL * 4; 

sf::system::console::sprite::Info spinfo =
{ "media\\Author.png",0.0f,0.0f,0.0f,0.0f,0xff000000,sf::system::console::sprite::SPRITE2D};

// 僐儞僗僩儔僋僞 -------------------------------------------------------------
AuthorImpl::AuthorImpl() : AbstractScene()
{
	mTimer = PERIOD;
	//mMessage = pParam->message();
	mState = INITIALIZE;
	mpSprite = NULL;

}// AuthorImpl()

// 僨僗僩儔僋僞 ---------------------------------------------------------------
AuthorImpl::~AuthorImpl()
{
	// 僗僾儔僀僩偺嶍彍
	delete mpSprite;
}// ~AuthorImpl()


// 僔乕儞偺摦嶌傪婰弎偡傞 -----------------------------------------------------
void AuthorImpl::move(void)
{
	Fade* pfade;
	Scene *ps;
	switch (mState)
	{
	// 弶婜壔 ---------
	case INITIALIZE:

		mpSound->load(0,"author.sgt");
		mpSound->load(1,"select.sgt");

		mpSprite = mpConsole->createSprite(&spinfo);

		// 嶌幰價僢僩儅僢僾偺僙僢僩傾僢僾
		mAuthorObj.color(0xffffffff);
		mAuthorObj.x(system::console::viewport::X + system::console::viewport::WIDTH / 2.0f);
		mAuthorObj.y(system::console::viewport::Y + 200.0f);
		//AuthorObj.scalingX(1.0f);
		//AuthorObj.scalingY(1.0f);
		mAuthorObj.z(0.0f);
		mAuthorObj.visibility(true);
		mAuthorObj.sprite(mpSprite);

		// 僼僃乕僪僀儞愝掕	
		ps = sf::application::scene::createScene(FADE);
		ps->addListener(this);
		pfade = dynamic_cast<Fade *>(ps);
		
		pfade->startColor(0xff000000);
		pfade->endColor(0x00000000);
		pfade->speed(0.05f);
		pfade->fadeType(Fade::FADE_IN);
		pfade->fadeVolumeFlag(true);

		mState = START;
		sleep();
		break;
	// BGM 傪柭傜偡 -----------------------------
	case START:
		mpSound->play(0,1,true,true);
		mState = MAIN;
		break;
	// 儊僀儞 -----------------------------------
	case MAIN:
		mTimer --;
		
		if(mpInput->exit(true)){
			exitKeyPressed(this);
			return;
		}

		if(!mTimer || mpInput->start(true)){
			
			
			Scene *pscene = createScene(FADE);
			pscene->addListener(this);
			Fade *pfade = dynamic_cast<Fade *>(pscene);
			
			pfade->startColor(0x00000000);
			pfade->endColor(0xff000000);
			pfade->speed(-0.05f);
			pfade->fadeVolumeFlag(true);
			pfade->fadeType(Fade::FADE_OUT);

			mState = END;
			sleep();
		}
		break;
	case END:
    ;
	}
	//TestSprite.rotation(2.0f * 3.14159f / 75.0f * (mTimer % 75));
	//mpConsole->print(0,system::console::viewport::X,0.0f,0.0f,1.0f,0xffffffff,"%s",mMessage.c_str());
}// move

//AuthorImpl Scene 偺廔椆 ---------------------------------------------------------
void AuthorImpl::endOfScene(Scene *pScene)
{

	switch(mState){
	case END:
		callSceneEvent(&Listener::endOfScene);
	
		mpSound->stop();
		createScene(TITLE);
		
		delete this;
		return;

	case START:
		active();
		break;
	}

} //endOfScene()

// exitKey偑墴偝傟偨 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
void AuthorImpl::exitKeyPressed(Scene *pScene)
{
	callSceneEvent(&Listener::endOfScene);
	delete this;
}// exitKeyPressed