//@STATE=作成中
//@DESCRIPTION ---------------------------------------------------------------
// TitleImpl.cpp: TitleImpl クラスのインプリメンテーション
// $Log: TitleImpl.cpp,v $
// Revision 1.1  2001/10/28 21:40:37  fujiwara
// DLLに分割
//
// Revision 1.5  2001/07/09 20:30:10  fujiwara
// 例外処理の組み込み
//
// Revision 1.4  2001/07/01 21:30:34  fujiwara
// メモリリークチェック見直し
//
// Revision 1.3  2001/07/01 01:03:45  fujiwara
// const の見直し
// 配置エディタは途中経過
//
// Revision 1.2  2001/05/12 00:48:42  fujiwara
// ＣＶＳを導入し、ログ表示を追加
//
//@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 "exception.h"
#include "system.h"
#include "sound.h"
#include "console.h"
#include "Obj.h"
#include "Obj2D.h"
#include "Obj3D.h"
#include "Obj3DL.h"
#include "ObjRectangle.h"
#include "ObjQuadrangle.h"
#include "input.h"
#include "Scene.h"
#include "s2001.h"
#include "main.h"
#include "AbstractScene.h"
#include "Fade.h"

#include "TitleImpl.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// 構築/消滅
//////////////////////////////////////////////////////////////////////
using namespace sf::application::scene;
using namespace sf::system;
const int TitleImpl::PERIOD	= 1000 / TIMER_INTERVAL * 10;//(10 Sec)

//const console::sprite::Info TitleImpl::SPRITE_INFO =
//	{ "media\\test.x",0.0f,0.0f,0.0f,0.0f,0xff000000,console::sprite::MESH};

const console::sprite::Info TitleImpl::SPRITE_INFO_TITLE =
	{ "media\\title.png",0.0f,0.0f,0.0f,0.0f,0xff000000,console::sprite::SPRITE3D};

// コンストラクタ -------------------------------------------------------------
TitleImpl::TitleImpl() : AbstractScene()
{
	mTimer = 0;
	mState = INITIALIZE;
	//mpSpriteMyShip = 
	mpSpriteTitle = NULL;

}// TitleImpl::TitleImpl()

//デストラクタ ----------------------------------------------------------------
TitleImpl::~TitleImpl()
{
//	delete mpSpriteMyShip;
	delete mpSpriteTitle;

}// TitleImpl::~TitleImpl()

// フレーム処理 ---------------------------------------------------------------
void TitleImpl::move(void)
{

	switch(mState)
	{
	case INITIALIZE:
		initialize();
		return;
	// メイン -------------------------------------
	case MAIN:
		main();
		return;
	case END:
    ;
	}
}// TitleImpl::move()

//TitleImpl Scene の終了 ---------------------------------------------------------
void TitleImpl::endOfScene(Scene * const pScene)
{
	callSceneEvent(&Listener::endOfScene);
	delete this;
} //endOfScene()

// exit key が押された！ ------------------------------------------------------
void TitleImpl::exitKeyPressed(Scene * const pScene)
{
	callSceneEvent(&Listener::exitKeyPressed);
	delete this;
} //endOfScene()

// 初期化 ----------------------------------------------------------------------
void TitleImpl::initialize()
{

	mpSound->load(0,"select.sgt");
	
//	if(NULL == (mpSpriteMyShip = mpConsole->createSprite(&SPRITE_INFO)) )
//	{
//		mpSystem->outputError("TitleImpl.move():Bitmap File Load Error");
//		return false;
//	}

	mpSpriteTitle = mpConsole->createSprite(&SPRITE_INFO_TITLE);

	mState = MAIN;
	
	// タイトルビットマップのセットアップ
/* mTitleObj.color(0xffffffff);
	mTitleObj.specular(0xff000000);

	mTitleObj.x(system::console::viewport::X + system::console::viewport::WIDTH / 2.0f);
	mTitleObj.y(system::console::viewport::Y + 300.0f);

	mTitleObj.z(0.5f);
	mTitleObj.sprite(mpSpriteMyShip);
	mTitleObj.visibility(true);
*/
	// タイトルビットマップのセットアップ
	mTitleObj1.color(0xffffffff);
	mTitleObj1.specular(0xff000000);

	mTitleObj1.x(system::console::viewport::X + system::console::viewport::WIDTH / 2.0f);
	mTitleObj1.y(system::console::viewport::Y + 100.0f);

	mTitleObj1.z(0.0f);
	mTitleObj1.sprite(mpSpriteTitle);
	mTitleObj1.visibility(true);
	
	// フェードイン設定	
	Fade *pfade = dynamic_cast<Fade*>(scene::createScene(FADE));
	pfade->startColor(0xff000000);
	pfade->endColor(0x00000000);
	pfade->speed(0.02f);
	pfade->fadeType(Fade::FADE_IN);
	pfade->fadeVolumeFlag(true);
	
	mState = MAIN;
	mSoundID = 	sf::system::instance()->sound()->load("title.wav");
	sf::system::instance()->sound()->play(mSoundID,0,false,false);

}// initialize();

// シーンのメイン ------------------------------------------------------------
void TitleImpl::main()
{
	mTimer ++;
	float r = PI * 2.0f / 1024.0f * (float)(mTimer & 0x3ff);
//	mTitleObj.angleX(r);
//	mTitleObj.angleY(r);

	mTitleObj1.angleX(r);

	// スタート画面の表示 
	if(mTimer & 0x10)
	{
		mpConsole->print(
			0,
			system::console::viewport::X + system::console::viewport::WIDTH / 2 - 144.0f,
			system::console::viewport::Y + 300.0f,
			0.0f,1.0f,0xffffffff,"Start Game: A Button Or Space Key");
		mpConsole->print(
			0,
			system::console::viewport::X + system::console::viewport::WIDTH / 2 - 135.0f,
			system::console::viewport::Y + 310.0f,
			0.0f,1.0f,0xffffffff,"Exit Game: ESC Key");

	} else {
		mpConsole->print(
			0,
			system::console::viewport::X + system::console::viewport::WIDTH / 2 - 144.0f,
			system::console::viewport::Y + 300.0f,
			0.0f,1.0f,0x80ffffff,"Start Game: A Button Or Space Key");

		mpConsole->print(
			0,
			system::console::viewport::X + system::console::viewport::WIDTH / 2 - 135.0f,
			system::console::viewport::Y + 310.0f,
			0.0f,1.0f,0x80ffffff,"Exit Game: ESC Key");

	}

	// ＥＸＩＴキーが押されたか？
	if(mpInput->exit(true)) {
		exitKeyPressed(this);
		return;
	}

	// スターとキーが押されたか？
	if(mpInput->start(true)){
		mpSound->play(0,1,true,true);
		endOfScene(this);
		scene::createScene(GAME);
	}

}// main() 


