//一時停止中スクリプト

let PhotoSensitive;

@Initialize
{
	PhotoSensitive = GetCommonData("PhotoSensitive", true);
	SetAutoDeleteObject(true);
	TWhiteOut();
	TBackground();
	TMenu();
}

@MainLoop
{
	yield;
}

@Finalize
{
}

task TWhiteOut{
	//分割設定
	if(PhotoSensitive){return;}
	let obj = ObjPrim_Create(OBJ_SPRITE_2D); //2D頂点ブジェクト生成
	Obj_SetRenderPriorityI(obj, 99); //描画優先度を設定
	ObjRender_SetPosition(obj, 0,0,0);
	ObjSprite2D_SetDestRect(obj, 0,0,640,480);
	ObjSprite2D_SetSourceRect(obj, 0,0,640,480);
	descent(i in 0 .. 30){
		ObjRender_SetAlpha(obj, 255*i/30);
		yield;
	}
	Obj_Delete(obj);
}

task TBackground{
	let target = GetTransitionRenderTargetName();
	let obj = ObjPrim_Create(OBJ_SPRITE_2D); //2D頂点ブジェクト生成
	Obj_SetRenderPriorityI(obj, 90); //描画優先度を設定
	ObjPrim_SetTexture(obj, target); //テクスチャを設定
	ObjRender_SetPosition(obj, 0,0,0);
	ObjSprite2D_SetDestRect(obj, 0,0,640,480);
	ObjSprite2D_SetSourceRect(obj, 0,0,640,480);
	
	let PhotoNum = GetCommonData("Package_Developing_Count", 0);
	let RTName = "PhotoNo." ~ itoa(PhotoNum);
	let img = GetCurrentScriptDirectory() ~ "./../../snapshot/" ~ GetCommonData(RTName ~ "_Img", RTName) ~ ".bmp";
	let Rect = GetCommonData("FinderPos", [0,0,0,0,0,0,0,0]);
	let CenterX= (Rect[0]+Rect[4])/2;
	let CenterY= (Rect[3]+Rect[7])/2;
	let objPhoto = ObjPrim_Create(OBJ_PRIMITIVE_2D);	//2D頂点ブジェクト生成
	Obj_SetRenderPriorityI(objPhoto, 91);				//描画優先度を設定
	if(!PhotoSensitive){
		ObjPrim_SetTexture(objPhoto, img);				//テクスチャを設定
	}
	ObjPrim_SetPrimitiveType(objPhoto, PRIMITIVE_TRIANGLELIST);
	ObjRender_SetPosition(objPhoto, CenterX, CenterY,0);
	ObjPrim_SetVertexCount(objPhoto, 6);
	ObjPrim_SetVertexUVT(objPhoto, 0, Rect[0], Rect[1]);
	ObjPrim_SetVertexUVT(objPhoto, 1, Rect[2], Rect[3]);
	ObjPrim_SetVertexUVT(objPhoto, 2, Rect[4], Rect[5]);
	ObjPrim_SetVertexUVT(objPhoto, 3, Rect[0], Rect[1]);
	ObjPrim_SetVertexUVT(objPhoto, 4, Rect[6], Rect[7]);
	ObjPrim_SetVertexUVT(objPhoto, 5, Rect[4], Rect[5]);
	ObjPrim_SetVertexPosition(objPhoto, 0, Rect[0]-CenterX, Rect[1]-CenterY, 0);
	ObjPrim_SetVertexPosition(objPhoto, 1, Rect[2]-CenterX, Rect[3]-CenterY, 0);
	ObjPrim_SetVertexPosition(objPhoto, 2, Rect[4]-CenterX, Rect[5]-CenterY, 0);
	ObjPrim_SetVertexPosition(objPhoto, 3, Rect[0]-CenterX, Rect[1]-CenterY, 0);
	ObjPrim_SetVertexPosition(objPhoto, 4, Rect[6]-CenterX, Rect[7]-CenterY, 0);
	ObjPrim_SetVertexPosition(objPhoto, 5, Rect[4]-CenterX, Rect[5]-CenterY, 0);
	if(!PhotoSensitive){
		ObjShader_SetShaderF(objPhoto, GetModuleDirectory~"script/TRIFocuser/fx/HLSL_DisableAlpha.fx");
		ObjShader_SetTechnique(objPhoto, "TecDisableAlpha");
		loop(15){yield;}
	}
	if(GetCommonData("ShootSuccess", false)){
		let time = 30;
		let photoX = GetCenterX()+(GetCenterX()-GetClipMinX+64)*(2*trunc(PhotoNum/5)-1);
		let photoY = GetScreenMaxY*(2*(4-(PhotoNum%5))+1)/10;
		ascent(i in 1 .. time+1){
			ObjRender_SetAngleZ(objPhoto, 720*sin(90*i/time));
			ObjRender_SetPosition(objPhoto, CenterX+(photoX-CenterX)*sin(90*i/time), CenterY+(photoY-CenterY)*sin(90*i/time), 0);
			ObjRender_SetScaleXYZ(objPhoto, 1.0-0.6*sin(90*i/time), 1.0-0.6*sin(90*i/time), 1);
			yield;
		}
	}else{
		let time = 30;
		let photoX = GetCenterX()+(GetCenterX()-GetClipMinX+64)*(2*trunc(PhotoNum/5)-1);
		let photoY = GetScreenMaxY*(2*(PhotoNum%5)+1)/10;
		ascent(i in 1 .. time+1){
			ObjRender_SetAngleZ(objPhoto, 360*sin(90*i/time));
			ObjRender_SetPosition(objPhoto, CenterX, CenterY+120*(1-cos(90*i/time)), 0);
			ObjRender_SetScaleXYZ(objPhoto, 1.0-0.6*sin(90*i/time), 1.0-0.6*sin(90*i/time), 1);
			ObjRender_SetAlpha(objPhoto, 255*(1-i/time));
			yield;
		}
	}
}

/*task TBackground
{
	//分割設定
	let target = GetTransitionRenderTargetName();
	let obj = ObjPrim_Create(OBJ_SPRITE_2D); //2D頂点ブジェクト生成
	Obj_SetRenderPriorityI(obj, 90); //描画優先度を設定
	ObjPrim_SetTexture(obj, target); //テクスチャを設定
	ObjRender_SetPosition(obj, 0,0,0);
	ObjSprite2D_SetDestRect(obj, 0,0,640,480);
	ObjSprite2D_SetSourceRect(obj, 0,0,640,480);
	
	let Rect = GetCommonData("FinderPos", [0,0,0,0,0,0,0,0]);
	let CenterX= (Rect[0]+Rect[4])/2;
	let CenterY= (Rect[3]+Rect[7])/2;
	let PhotoNum = GetCommonData("Package_Developing_Count", 0);
	let objPhoto = ObjPrim_Create(OBJ_PRIMITIVE_2D); //2D頂点ブジェクト生成
	Obj_SetRenderPriorityI(objPhoto, 91); //描画優先度を設定
	ObjPrim_SetTexture(objPhoto, target); //テクスチャを設定
	ObjPrim_SetPrimitiveType(objPhoto, PRIMITIVE_TRIANGLELIST);
	ObjRender_SetPosition(objPhoto, CenterX, CenterY,0);
	ObjSprite2D_SetDestRect(objPhoto, 0,0,640,480);
	ObjSprite2D_SetSourceRect(objPhoto, 0,0,640,480);
	ObjPrim_SetVertexCount(objPhoto, 6);
	ObjPrim_SetVertexUVT(objPhoto, 0, Rect[0], Rect[1]);
	ObjPrim_SetVertexUVT(objPhoto, 1, Rect[2], Rect[3]);
	ObjPrim_SetVertexUVT(objPhoto, 2, Rect[4], Rect[5]);
	ObjPrim_SetVertexUVT(objPhoto, 3, Rect[0], Rect[1]);
	ObjPrim_SetVertexUVT(objPhoto, 4, Rect[6], Rect[7]);
	ObjPrim_SetVertexUVT(objPhoto, 5, Rect[4], Rect[5]);
	ObjPrim_SetVertexPosition(objPhoto, 0, Rect[0]-CenterX, Rect[1]-CenterY, 0);
	ObjPrim_SetVertexPosition(objPhoto, 1, Rect[2]-CenterX, Rect[3]-CenterY, 0);
	ObjPrim_SetVertexPosition(objPhoto, 2, Rect[4]-CenterX, Rect[5]-CenterY, 0);
	ObjPrim_SetVertexPosition(objPhoto, 3, Rect[0]-CenterX, Rect[1]-CenterY, 0);
	ObjPrim_SetVertexPosition(objPhoto, 4, Rect[6]-CenterX, Rect[7]-CenterY, 0);
	ObjPrim_SetVertexPosition(objPhoto, 5, Rect[4]-CenterX, Rect[5]-CenterY, 0);
	loop(15){yield;}
	if(GetCommonData("ShootSuccess", false)){
		let time = 30;
		let photoX = GetCenterX()+(GetCenterX()-GetClipMinX+64)*(2*trunc(PhotoNum/5)-1);
		let photoY = GetScreenMaxY*(2*(4-(PhotoNum%5))+1)/10;
		ascent(i in 1 .. time+1){
			ObjRender_SetAngleZ(objPhoto, 720*sin(90*i/time));
			ObjRender_SetPosition(objPhoto, CenterX+(photoX-CenterX)*sin(90*i/time), CenterY+(photoY-CenterY)*sin(90*i/time), 0);
			ObjRender_SetScaleXYZ(objPhoto, 1.0-0.6*sin(90*i/time), 1.0-0.6*sin(90*i/time), 1);
			yield;
		}
	}else{
		let time = 30;
		let photoX = GetCenterX()+(GetCenterX()-GetClipMinX+64)*(2*trunc(PhotoNum/5)-1);
		let photoY = GetScreenMaxY*(2*(PhotoNum%5)+1)/10;
		ascent(i in 1 .. time+1){
			ObjRender_SetAngleZ(objPhoto, 360*sin(90*i/time));
			ObjRender_SetPosition(objPhoto, CenterX, CenterY+120*(1-cos(90*i/time)), 0);
			ObjRender_SetScaleXYZ(objPhoto, 1.0-0.6*sin(90*i/time), 1.0-0.6*sin(90*i/time), 1);
			ObjRender_SetAlpha(objPhoto, 255*(1-i/time));
			yield;
		}
	}
}*/

task TMenu
{
	if(!PhotoSensitive){
		loop(45){
			yield;
		}
	}else{
		loop(30){
			yield;
		}
	}
	CloseScript(GetOwnScriptID());
}


function GetCenterX(){
	return (GetCommonData("STGFrame_L", 128)+GetCommonData("STGFrame_R", 512))/2;
}
function GetCenterY(){
	return (GetCommonData("STGFrame_U", 16)+GetCommonData("STGFrame_D", 464))/2;
}
function GetClipMinX(){
	return GetCommonData("STGFrame_L", 128);
}
function GetClipMinY(){
	return GetCommonData("STGFrame_U", 16);
}
function GetClipMaxX(){
	return GetCommonData("STGFrame_R", 512);
}
function GetClipMaxY(){
	return GetCommonData("STGFrame_D", 464);
}


function GetScreenCenterX(){
	return GetStgFrameWidth()/2;
}
function GetScreenCenterY(){
	return GetStgFrameHeight()/2;
}
function GetScreenMinX(){
	return 0;
}
function GetScreenMinY(){
	return 0;
}
function GetScreenMaxX(){
	return  GetStgFrameWidth();
}
function GetScreenMaxY(){
	return GetStgFrameHeight();
}