//--------------------
//^Cg
//--------------------

let m_Title_IsTitle = false;
let m_Title_TitleColorRate = 1;

let m_Title_IsContinueEnable = false;

let m_Title_TitleDispCounter = 0;
let m_Title_TitleDispStep = 0;
let m_Title_TitleDispSelection = 0;

//^Cgis̃C[`
task main_Title_MainRoutine()
{
	let cleared_stage = GetCommonDataDefaultEx("INVADER_SAVE", "Game.ClearedStage", 1);
	let movable = false;
	func_Stage_SetStatus(_STAGE_TITLE);
	m_Title_IsTitle = true;

	ForbidShot(true);
	ForbidBomb(true);

	loop
	{
		if(REMY_Stick_Push(_KEY_SHOT))
		{
			PlaySE(se_Cursor);
			if(m_Title_TitleDispStep == 0){ m_Title_TitleDispStep = 1; }
			else if(m_Title_TitleDispStep == 1 )
			{
				 if(m_Title_TitleDispSelection == 0){ break; }
				 if(m_Title_TitleDispSelection == 1){ wait_Title_ManualMain(); }
				 if(m_Title_TitleDispSelection == 2){ func_Score_LoadContinueData(); break; }
			}
		}
		if(m_Title_TitleDispStep == 1){
			if(REMY_Stick_GetY() == 0){ movable = true; }
			else if(movable){
				PlaySE(se_BgmBoss00);
				movable = false; 
				//ReBj[\ȂQ܂ŁB
				m_Title_TitleDispSelection = REMY_Math_Limit(m_Title_TitleDispSelection + REMY_Stick_GetY(), 0, [1, 2][m_Title_IsContinueEnable], true);
			}
		}

		m_Title_TitleDispCounter ++;
		yield;
	}

	SetPlayerX(GetCenterX());
	SetPlayerY(GetCenterY());

	ascent(i in 1..61)
	{
		m_Title_TitleColorRate = 1 - (i / 60);
		yield;
	}

	m_Title_IsTitle = false;
	ForbidShot(false);
	func_Stage_SetStatus(_STAGE_LOADING);


}//end function


//CXgJ[h̕\
function wait_Title_ManualMain()
{
	let old_card_id = 1;
	let current_card_id = 1;
	let changed = true;
	let quit = false;
	let ignore_time = 23;

	func_LoadInstruction();

	InstCard(1);
	InstCard(2);
	InstCard(3);

	loop{

		if(ignore_time > 0){ ignore_time--; }
		else
		{
			if(REMY_Stick_Push(_KEY_SHOT)){ current_card_id ++; }
			else { current_card_id += REMY_Stick_GetPushX(); }
		}

		if(current_card_id != old_card_id)
		{
			changed = true; 
			old_card_id = current_card_id; 
			PlaySE(se_BgmBoss00);
			ignore_time = 22;
		}
		else
		{
			changed = false;
		}

		yield;
		if(current_card_id >= 4 || current_card_id <= 0){ break; }
	}
	changed = false; 
	quit = true;
	loop(22){yield; }
	func_DeleteInstruction();
	return;

	//--------------

	task InstCard(let id)
	{
		let moving = false;
		let x_list = [GetCenterX() - 384, GetCenterX(), GetCenterX() + 384];
		let current_x = x_list[2];

		let obj = REMY_Effect_CreateObject([img_Inst01, img_Inst01, img_Inst02, img_Inst03][id], 4, 7);
		REMY_Effect_SetVertexSquare(obj, [0,0,384,448], [0, 0], [255, 255, 255, 255]);
		Obj_SetPosition(obj, current_x, GetCenterY());
		ObjEffect_SetRenderState(obj, ALPHA);
		ObjEffect_SetScale(obj, 1.0, 1.0);

		loop
		{
			if(changed){
				let movetopos = REMY_Math_Sign(id - current_card_id);
				move(x_list[1 + movetopos]);
			}
			yield;
			if(quit){ break; }
		}
		while(moving){ yield; }
		Obj_Delete(obj);

		//----------
		task move(let move_to)
		{
			if(moving){ return; }
			moving = true;
			ascent(i in 1..21){
				let x = current_x + (move_to - current_x) * (sin(90 * i/20));
				Obj_SetPosition(obj, x, GetCenterY());
				yield;
			}
			Obj_SetPosition(obj, move_to, GetCenterY());
			moving = false;
			current_x = move_to;
		}

	}//end task


}//end function



//
function draw_Title_GameTitle()
{
	if(!m_Title_IsTitle){ return; }

	let col = 255 * m_Title_TitleColorRate;
	SetTexture(img_Title);
	SetGraphicRect(496, 48, 512, 64);
	SetGraphicScale(30, 30);
	SetRenderState(SUBTRACT);
	SetColor(col,col, col);
	DrawGraphic(GetCenterX(), GetCenterY());

	SetRenderState(ALPHA);
	SetAlpha(col);
	SetGraphicScale(1, 1);
	SetColor(255,255,255);
	SetGraphicRect(0, 0, 384, 64);
	DrawGraphic(GetCenterX(), 160);


	if(m_Title_TitleDispStep == 0)
	{
		let light = ((m_Title_TitleDispCounter % 60) > 30);
		SetRenderState(ALPHA);
		SetAlpha(col * [0, 1][light]);
		SetGraphicScale(1, 1);
		SetColor(255,255,255);
		SetGraphicRect(384, 32, 512, 48);
		DrawGraphic(GetCenterX(), 360);

	}
	else if(m_Title_TitleDispStep == 1)
	{
		let light = ((m_Title_TitleDispCounter % 40) > 20);
		SetRenderState(ALPHA);
		SetGraphicScale(1, 1);
		SetColor(255,255,255);
		
		local{
			SetAlpha(col * [1, 0][light && (m_Title_TitleDispSelection == 0)]);
			SetGraphicRect(384, 0, 464, 16);
			DrawGraphic(GetCenterX(), 300);
		}
		local{
			SetAlpha(col * [1, 0][light && (m_Title_TitleDispSelection == 1)]);
			SetGraphicRect(384, 16, 480, 32);
			DrawGraphic(GetCenterX(), 330);
		}
		if(m_Title_IsContinueEnable)
		{
			SetColor(255,255,0);
			SetAlpha(col * [1, 0][light && (m_Title_TitleDispSelection == 2)]);
			SetGraphicRect(384, 48, 496, 64);
			DrawGraphic(GetCenterX(), 360);
		}

	}

	SetTexture(img_System);
	SetRenderState(ALPHA);
	SetAlpha(col);
	SetGraphicScale(1, 1);
	SetColor(255,255,255);
	SetGraphicRect(16,16,128,48);
	DrawGraphic(GetCenterX(), 220);

}//end function



function func_SetContinueEnable(let val)
{
	m_Title_IsContinueEnable = val;
}//
