let selectMode;
//TMenu();

task TBackground
{
	task TVertex(var index, var left, var top, var right, var bottom)
	{
		ObjPrim_SetVertexPosition(obj, index + 0, left, top, 0);
		ObjPrim_SetVertexPosition(obj, index + 1, left, bottom, 0);
		ObjPrim_SetVertexPosition(obj, index + 2, right, top, 0);
		ObjPrim_SetVertexPosition(obj, index + 3, right, top, 0);
		ObjPrim_SetVertexPosition(obj, index + 4, left, bottom, 0);
		ObjPrim_SetVertexPosition(obj, index + 5, right, bottom, 0);

		ObjPrim_SetVertexUVT(obj, index + 0, left, top);
		ObjPrim_SetVertexUVT(obj, index + 1, left, bottom);
		ObjPrim_SetVertexUVT(obj, index + 2, right, top);
		ObjPrim_SetVertexUVT(obj, index + 3, right, top);
		ObjPrim_SetVertexUVT(obj, index + 4, left, bottom);
		ObjPrim_SetVertexUVT(obj, index + 5, right, bottom);

		//STGシーン内のみアニメーション
		if(left >= 32 && right <= 416 && top >=16 && bottom <= 464)
		{
			let alpha = 255;
			while(alpha >= 128)
			{
				ObjPrim_SetVertexAlpha(obj, index + 0, alpha);
				ObjPrim_SetVertexAlpha(obj, index + 1, alpha/2);
				ObjPrim_SetVertexAlpha(obj, index + 2, alpha/2);
				ObjPrim_SetVertexAlpha(obj, index + 3, alpha/2);
				ObjPrim_SetVertexAlpha(obj, index + 4, alpha/2);
				ObjPrim_SetVertexAlpha(obj, index + 5, alpha);
				alpha -= 255 / frame;

				yield;
			}
		}
	}

	//分割設定
	let frame = 30;
	let countH = 20; //分割数
	let countV = 30; 
	let width = 640 / countH;
	let height = 480 / countV;
	let target = GetTransitionRenderTargetName();
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D); //2D頂点ブジェクト生成
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLELIST);
	ObjPrim_SetVertexCount(obj, countH * countV * 6);
	Obj_SetRenderPriorityI(obj, 0); //描画優先度を設定
	ObjPrim_SetTexture(obj, target); //テクスチャを設定

	ascent(ix in 0.. countH)
	{
		ascent(iy in 0.. countV)
		{
			let index = (ix + iy * countH) * 6;
			let left = ix * width;
			let right = left + width;
			let top = iy * height;
			let bottom = top + height;
			TVertex(index, left, top, right, bottom);
		}
	}

}

function TMenu
{
	SetAutoDeleteObject(true);
	selectMode = true;
	let objScene = GetEnemyBossSceneObjectID();
	let timer = ObjEnemyBossScene_GetInfo(objScene, INFO_TIMERF);

	let objTt2 = ObjText_Create();
	ObjText_SetText(objTt2, "Please try \"IDF 1 - The 1st Stage of WBaWC\"");
	ObjText_SetFontType(objTt2,"Cabin");
	ObjText_SetFontSize(objTt2, 18);
	ObjText_SetFontBold(objTt2, true);
	ObjText_SetFontColorTop(objTt2, 255, 255, 255);
	ObjText_SetFontColorBottom(objTt2, 255, 255, 255);
	ObjText_SetFontBorderType(objTt2, BORDER_FULL);
	ObjText_SetFontBorderColor(objTt2, 10, 10, 10);
	ObjText_SetFontBorderWidth(objTt2, 2);
	Obj_SetRenderPriorityI(objTt2, 50);
	ObjRender_SetX(objTt2, 24);
	ObjRender_SetY(objTt2, 180);

	let objTt3 = ObjText_Create();
	ObjText_SetText(objTt3, "before trying this");
	ObjText_SetFontType(objTt3,"Cabin");
	ObjText_SetFontSize(objTt3, 18);
	ObjText_SetFontBold(objTt3, true);
	ObjText_SetFontColorTop(objTt3, 255, 255, 255);
	ObjText_SetFontColorBottom(objTt3, 255, 255, 255);
	ObjText_SetFontBorderType(objTt3, BORDER_FULL);
	ObjText_SetFontBorderColor(objTt3, 10, 10, 10);
	ObjText_SetFontBorderWidth(objTt3, 2);
	Obj_SetRenderPriorityI(objTt3, 50);
	ObjRender_SetX(objTt3, 130);
	ObjRender_SetY(objTt3, 200);

	let objTt4 = ObjText_Create();
	ObjText_SetText(objTt4, "Press Z to continue");
	ObjText_SetFontType(objTt4,"Cabin");
	ObjText_SetFontSize(objTt4, 18);
	ObjText_SetFontBold(objTt4, true);
	ObjText_SetFontColorTop(objTt4, 255, 255, 255);
	ObjText_SetFontColorBottom(objTt4, 255, 255, 255);
	ObjText_SetFontBorderType(objTt4, BORDER_FULL);
	ObjText_SetFontBorderColor(objTt4, 10, 10, 10);
	ObjText_SetFontBorderWidth(objTt4, 2);
	Obj_SetRenderPriorityI(objTt4, 50);
	ObjRender_SetX(objTt4, 120);
	ObjRender_SetY(objTt4, 220);

	while(GetVirtualKeyState(VK_PAUSE) != KEY_FREE){yield;}

	loop
	{
		//決定
		if(GetVirtualKeyState(VK_OK) == KEY_PULL)
		{
			LoadSound(GetCurrentScriptDirectory ~ "system/se/cancel.wav");
			PlaySE(GetCurrentScriptDirectory ~ "system/se/cancel.wav");
			loop(8){ yield; }
			selectMode = false;
			Obj_Delete(objTt2);
			Obj_Delete(objTt3);
			Obj_Delete(objTt4);
			return;
		}
		else{ yield; }
	}
}