//一時停止中スクリプト
let pause=true; let type=0;
@Initialize
{yield;
	SetAutoDeleteObject(true);

	EndMenu;
}

@MainLoop
{
	yield;
}

@Finalize
{
}

@Event
{

}

	
task EndMenu{
if (!IsReplay){
SetAreaCommonData("hiscore", GetCommonData("stage", "0"), max(GetAreaCommonData("hiscore", GetCommonData("stage", "0"), 0), GetScore));
SaveCommonDataAreaA2("hiscore", GetModuleDirectory~"script/LastBossCollection/data/score.dat");}
let PAUSE_TEXT=["Save replay", "Give up and retry", "Return to title"];
if (IsReplay){PAUSE_TEXT=["Restart", "Return to title", "Return to title"];}
let CONFIRM_TEXT=["Yes", "No"];
let menu_selected=0; let menu2=0;
let menu_select=0; let angle=0; let alpha=0;
	let tex=[ObjText_Create,ObjText_Create,ObjText_Create];
	let tex2=[ObjText_Create,ObjText_Create];
	let text=ObjText_Create;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"img/mainmenu.png");
	ObjRender_SetPosition(obj, 130, 300, 0);
	Obj_SetRenderPriorityI(obj, 98);
	ObjRender_SetScaleXYZ(obj, 0.75, 0.75, 0);
	ObjRender_SetAlpha(obj, 200);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 256, 256);
	ObjSprite2D_SetDestCenter(obj);

	
	ascent(i in 0..2){
	ObjText_SetFontType(tex2[i], "Copperplate Gothic Light");
	ObjText_SetText(tex2[i], CONFIRM_TEXT[i]);
	ObjText_SetFontBorderWidth(tex2[i], 3);
	ObjText_SetFontBorderType(tex2[i], BORDER_SHADOW);
	ObjText_SetFontBorderColor(tex2[i], 40, 40, 40);
	ObjText_SetFontSize(tex2[i], 32);
	ObjRender_SetPosition(tex2[i], 490, 285+i*45, 0);
	Obj_SetRenderPriorityI(tex2[i], 99);
	}
	ascent(i in 0..3){ObjText_SetFontType(tex[i], "Copperplate Gothic Light");
	ObjText_SetText(tex[i], PAUSE_TEXT[i]);
	ObjText_SetFontBorderWidth(tex[i], 3);
	ObjText_SetFontBorderType(tex[i], BORDER_SHADOW);
	ObjText_SetFontBorderColor(tex[i], 40, 40, 40);
	ObjText_SetFontSize(tex[i], 32);
	ObjRender_SetPosition(tex[i], 100+i*20, 240+i*45, 0);
	Obj_SetRenderPriorityI(tex[i], 99);
	}
	CheckKeys;
	while(!Obj_IsDeleted(tex[0])){
	ObjRender_SetAngleXYZ(obj, 0, 0, angle/8);
	angle+=8;
	alpha=200+55*cos(angle);
	
	ascent(i in 0..2){
	if (menu2==i){
	ObjText_SetFontColorTop(tex2[i], alpha, alpha, alpha);
	ObjText_SetFontColorBottom(tex2[i], 150, 150, 150);}
	else{ObjText_SetFontColorTop(tex2[i], 100, 100, 100); 
	ObjText_SetFontColorBottom(tex2[i], 100, 100, 100);}
	if (menu_selected==0){Obj_SetVisible(tex2[i], false);}
	else{Obj_SetVisible(tex2[i], true); }
	}
	
	ascent(i in 0..3){
	if (i==2&&IsReplay){Obj_SetVisible(tex[i], false);}
	if (menu_select==i&&menu_selected==0){
	ObjText_SetFontColorTop(tex[i], alpha, alpha, alpha);
	ObjText_SetFontColorBottom(tex[i], 150, 150, 150);}
	else{ObjText_SetFontColorTop(tex[i], 100, 100, 100); 
	ObjText_SetFontColorBottom(tex[i], 100, 100, 100);}}
	yield;}
	
	task CheckKeys{
	let t=0; 
	while(!Obj_IsDeleted(tex[0])){
	t++;
	if (t>30){
	if (menu_selected==0){
	if (GetVirtualKeyState(VK_DOWN)==KEY_PUSH){menu_select++; if (!IsReplay&&menu_select>2){menu_select=0;} if (IsReplay&&menu_select>1){menu_select=0;}}
	if (GetVirtualKeyState(VK_UP)==KEY_PUSH){menu_select--; if (menu_select<0){if (!IsReplay){menu_select=2;} else{menu_select=0;}}}
	if (GetVirtualKeyState(VK_SHOT)==KEY_PUSH){
	if (menu_select!=0){menu_selected=1;}
	else{
	if (!IsReplay){
	if (GetCommonData("gameover", true)==false){
	SetScriptResult(RESULT_SAVE_REPLAY);
	ClearInvalidRenderPriority;
	CloseScript(GetOwnScriptID());}
	else{yield;}}
	else{SetScriptResult(RESULT_RETRY);
	NotifyEventAll(EV_USER+11, 0);
	ClearInvalidRenderPriority;
	CloseScript(GetOwnScriptID());}
	}
	}
			}
			else{
			if (GetVirtualKeyState(VK_DOWN)==KEY_PUSH){menu2++; if (menu2>1){menu2=0;}}
			if (GetVirtualKeyState(VK_UP)==KEY_PUSH){menu2--; if (menu2<0){menu2=1;}}
			if (GetVirtualKeyState(VK_BOMB)==KEY_PUSH||(GetVirtualKeyState(VK_SHOT)==KEY_PUSH&&menu2==1)){yield; menu2=0; menu_selected=0;}
			if (GetVirtualKeyState(VK_SHOT)==KEY_PUSH&&menu2==0){
			if (!IsReplay){if (menu_select==1){SetScriptResult(RESULT_RETRY); CloseScript(GetOwnScriptID);}
			if (menu_select==2){SetScriptResult(RESULT_END); CloseScript(GetOwnScriptID);}}
			else{if (menu_select==0){SetScriptResult(RESULT_RETRY); CloseScript(GetOwnScriptID);}
			if (menu_select==1){SetScriptResult(RESULT_END); CloseScript(GetOwnScriptID);}}
			}
			}
	}
	yield;}
	ClearInvalidRenderPriority;
	}
}