InstallFont(GetMainStgScriptDirectory ~ "font/MonoSpatial.ttf");
AddVirtualKey(VK_USER1,KEY_Z,KEY_INVALID);

function ObjDialog_ImageCreate( posx, charname){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let path = GetMainStgScriptDirectory ~ "img/cutin/" ~ charname;
	let posy = 240+60;
	ObjRender_SetScaleXYZ(obj,0.85,0.85,0);
	Obj_SetValue(obj,"Pose","_00");
	randomnameforarandomtask(obj);
	return obj;

	task randomnameforarandomtask(obj){
		let pos = 1;
		if(Obj_GetValueD(obj,"IfBack",true)){pos = 1;}
		else{pos = 0;}
		while(!Obj_IsDeleted(obj)){
			let path2 = path ~ Obj_GetValueD(obj,"Pose","_00") ~ ".png";
			ObjPrim_SetTexture(obj, path2);
			ObjSprite2D_SetSourceRect(obj, 0, 0, GetTextureWidth(path2), GetTextureHeight(path2)); 
			ObjSprite2D_SetDestCenter(obj);
			if(Obj_GetValueD(obj,"IfBack",false)){
				ObjRender_SetColor(obj,100,100,100);
				Obj_SetRenderPriority(obj,0.94);
				pos = min(pos+1/8,1);
			}
			else{
				ObjRender_SetColor(obj,255,255,255);
				Obj_SetRenderPriority(obj,0.95);
				pos = max(pos-1/8,0);
			}
			ObjRender_SetPosition(obj,posx+50*(posx-320)/absolute(posx-320)*pos,posy+80*pos,0);
			yield;
		}
	}

	task ObjRender_AddPatternA1(obj,x2,y2,t){
		let x = ObjRender_GetX(obj);
		let y = ObjRender_GetY(obj);
		let r = GetDis(x,y,x2,y2);
		let ang = GetAngA3(x,y,x2,y2);
		ascent(a in 1..t+1){
			ObjRender_SetPosition(obj,x+r*cos(-90+a/t*90)*cos(ang),y+r*cos(-90+a/t*90)*sin(ang),0);
			yield;
		}
	}
}

function ObjDialog_SetCharPos(obj,a,b){
	Obj_SetValue(obj,"Pose",a);
	Obj_SetValue(obj,"IfBack",b);
	return;
}

function ObjDialog_BoxCreate(){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let path = GetMainStgScriptDirectory ~ "img/dialog/talk_board.png";
	ObjPrim_SetTexture(obj,path);
	ObjSprite2D_SetSourceRect(obj, 0, 0, GetTextureWidth(path), GetTextureHeight(path)); 
	ObjSprite2D_SetDestCenter(obj);
	Obj_SetRenderPriority(obj,0.96);
	ObjRender_SetPosition(obj,320,480-48,0);
	ObjRender_SetAlpha(obj,150);
	randomnameforarandomtask(obj);
	return obj;

	task randomnameforarandomtask(obj){
		ascent(a in 1..21){
			ObjRender_SetAngleX(obj,90-a*90/20);
			yield;
		}
	}
}

task ObjDialog_BoxDelete(obj){
	descent(a in 1..21){
		ObjRender_SetAngleY(obj,90-a*90/20);
		yield;
	}
	Obj_Delete(obj);
}

task ObjDialog_TextCreate(text,conType,time){
	let objText = ObjText_Create();
	ObjText_SetText(objText, text);
	ObjText_SetFontSize(objText, 15);
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 200, 200, 200);
	Obj_SetRenderPriority(objText, 0.97);
	ObjText_SetFontType(objText, "MonoSpatial");
	ObjRender_SetPosition(objText, 320-390/2+15, 480-68, 0);

	loop(time){
		yield;
		if(conType != "Timed" && GetVirtualKeyState(VK_USER1)==KEY_PUSH){
			Obj_Delete(objText);
			return;
		}
	}
	Obj_Delete(objText);
}