#include "./funclib.txt"

function CutIn(let id, let type, let name, let color, let img, let x1, let y1, let x2, let y2)
{
	let width = x2 - x1; 
	let height = y2 - y1;
	let txtx = GetStgFrameWidth+16;
	let cty = GetStgFrameHeight+16+height;
	let dcty = cty - ( GetStgFrameHeight - height );
	let deca = 0;
	let decx = 0;

	InstallFont(gcsd~"font/verdana.ttf");

	let dec = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(dec, gcsd~"declare.png");
	ObjSprite2D_SetSourceRect(dec, 0, 0, 3600, 1200);
	ObjSprite2D_SetDestRect(dec, 0, 0, 3600, 1200);
	ObjRender_SetPosition(dec, -128, -16, 0);
	ObjRender_SetAlpha(dec, 0);
	ObjRender_SetAngleZ(dec, -10);

	let ct = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(ct, img);
	ObjSprite2D_SetSourceRect(ct, x1, y1, x2, y2);
	ObjSprite2D_SetDestRect(ct, 0, 0, width, height);
	ObjRender_SetPosition(ct, GetStgFrameWidth-(width), cty, 0);
	//ObjRender_SetPosition(ct, 0, 0, 0);

	let txt = ObjText_Create;
	ObjText_SetText(txt, name);
	ObjText_SetFontType(txt, "Verdana");
	ObjText_SetFontSize(txt, 20);
	alternative(color)
	case("RED")
	{
		ObjText_SetFontColorTop(txt, 255, 150, 150);
		ObjText_SetFontColorBottom(txt, 255, 200, 200);
		ObjText_SetFontBorderColor(txt, 255, 0, 0);
	}
	case("BLUE")
	{
		ObjText_SetFontColorTop(txt, 150, 150, 255);
		ObjText_SetFontColorBottom(txt, 200, 200, 255);
		ObjText_SetFontBorderColor(txt, 0, 0, 255);
	}
	case("GREEN")
	{
		ObjText_SetFontColorTop(txt, 150, 255, 150);
		ObjText_SetFontColorBottom(txt, 200, 255, 200);
		ObjText_SetFontBorderColor(txt, 0, 200, 0);
	}
	case("YELLOW")
	{
		ObjText_SetFontColorTop(txt, 255, 255, 150);
		ObjText_SetFontColorBottom(txt, 255, 255, 200);
		ObjText_SetFontBorderColor(txt, 150, 150, 0);
	}
	case("AQUA")
	{
		ObjText_SetFontColorTop(txt, 150, 255, 255);
		ObjText_SetFontColorBottom(txt, 200, 255, 255);
		ObjText_SetFontBorderColor(txt, 0, 200, 200);
	}
	case("PURPLE")
	{
		ObjText_SetFontColorTop(txt, 255, 150, 255);
		ObjText_SetFontColorBottom(txt, 255, 200, 255);
		ObjText_SetFontBorderColor(txt, 255, 0, 255);
	}
	ObjText_SetHorizontalAlignment(txt, ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(txt, GetStgFrameWidth);
	ObjText_SetFontBorderType(txt, BORDER_FULL);
	ObjText_SetFontBorderWidth(txt, 1);
	ObjRender_SetPosition(txt, txtx, 24, 0);

	let objScene = GetEnemyBossSceneObjectID();
	let bonus = ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE);
	let btxt = ObjText_Create;
	ObjText_SetText(btxt, "Bonus: " ~ IntToString(bonus) ~ " ");
	ObjText_SetFontType(btxt, "Verdana");
	ObjText_SetFontSize(btxt, 16);
	ObjText_SetFontColorTop(btxt, 255, 255, 255); ObjText_SetFontColorBottom(btxt, 255, 255, 255);
	ObjText_SetHorizontalAlignment(btxt, ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(btxt, GetStgFrameWidth);
	ObjText_SetFontBorderType(btxt, BORDER_FULL);
	ObjText_SetFontBorderWidth(btxt, 1);
	ObjText_SetFontBorderColor(btxt, 100, 100, 100);
	ObjRender_SetPosition(btxt, txtx, 42, 0);
	SpellB;

	if(type == 0)
	{
		StartSpell;
		Checker;
		CutinType0;
	}

	task CutinType0
	{
		ObjMove_SetDestAtFrame(ct, GetStgFrameWidth-width, -height, 180);
		
		loop(30)
		{
			txtx -= ((GetStgFrameWidth+16) / 30);
			cty -= (dcty / 45);
			deca+=(100/45);
			decx+=2;
			ObjRender_SetX(txt, txtx);
			ObjRender_SetX(btxt, txtx);
			ObjRender_SetY(ct, cty);
			ObjRender_SetAlpha(dec, deca);
			ObjSprite2D_SetSourceRect(dec, -decx, 0, 3600-decx, 1200);
			yield;
		}

		loop(15)
		{
			cty -= (dcty / 45);
			deca+=(100/45);
			decx+=2;
			ObjRender_SetAlpha(dec, deca);
			ObjRender_SetY(ct, cty);
			ObjSprite2D_SetSourceRect(dec, -decx, 0, 3600-decx, 1200);
			yield;
		}

		loop(45)
		{
			decx+=2;
			ObjSprite2D_SetSourceRect(dec, -decx, 0, 3600-decx, 1200);
			yield;
		}

		let cta = 255; let scale = 1;
		loop(30)
		{
			decx+=2;
			deca-=(100/30);
			cta -= 255/30;
			scale+=0.015;
			ObjRender_SetAlpha(ct, cta);
			ObjSprite2D_SetDestRect(ct, 0, 0, width*scale, height*scale);
			ObjRender_SetAlpha(dec, deca);
			ObjSprite2D_SetSourceRect(dec, -decx, 0, 3600-decx, 1200);
			yield;
		}
		Obj_Delete(ct);Obj_Delete(dec);
	}

	task SpellB
	{
		let ftimer = ObjEnemyBossScene_GetInfo(objScene, INFO_ORGTIMERF);
		let timer = ObjEnemyBossScene_GetInfo(objScene, INFO_TIMERF);
		let sc = timer/ftimer;
		let fail = false;

		loop
		{
			timer = ObjEnemyBossScene_GetInfo(objScene, INFO_TIMERF);
			sc = timer/ftimer;
			if(!fail){ObjText_SetText(btxt, "Bonus: " ~ IntToString(bonus*sc) ~ " ");}
			else{ObjText_SetText(btxt, "Bonus: Failed ");}
			loop(2){yield;}
			if((ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT)>0)||(ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT)>0)){fail = true;}
		}
	}

	task Checker
	{
		while(!Obj_IsDeleted(id)){yield;}
		Obj_Delete(txt); Obj_Delete(btxt);
	}
}


function CutIn2(let id, let type, let name, let name2, let color, let color2, let img, let x1, let y1, let x2, let y2, let val)
{
	let ch = gcsd~"sfx/se_ch00.wav";
	LoadSound(ch);

	let width = x2 - x1; 
	let height = y2 - y1;
	let txtx = GetStgFrameWidth+16;
	let cty = GetStgFrameHeight+16+height;
	let dcty = cty - ( GetStgFrameHeight - height );
	let deca = 0;
	let decx = 0;

	InstallFont(gcsd~"font/verdana.ttf");

	let dec = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(dec, gcsd~"declare.png");
	ObjSprite2D_SetSourceRect(dec, 0, 0, 3600, 1200);
	ObjSprite2D_SetDestRect(dec, 0, 0, 3600, 1200);
	ObjRender_SetPosition(dec, -128, -16, 0);
	ObjRender_SetAlpha(dec, 0);
	ObjRender_SetAngleZ(dec, -10);

	let ct = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(ct, img);
	ObjSprite2D_SetSourceRect(ct, x1, y1, x2, y2);
	ObjSprite2D_SetDestRect(ct, 0, 0, width, height);
	ObjRender_SetPosition(ct, GetStgFrameWidth-(width), cty, 0);
	//ObjRender_SetPosition(ct, 0, 0, 0);

	let txt = ObjText_Create;
	ObjText_SetText(txt, name);
	ObjText_SetFontType(txt, "Verdana");
	ObjText_SetFontSize(txt, 20);
	alternative(color)
	case("RED")
	{
		ObjText_SetFontColorTop(txt, 255, 150, 150);
		ObjText_SetFontColorBottom(txt, 255, 200, 200);
		ObjText_SetFontBorderColor(txt, 255, 0, 0);
	}
	case("BLUE")
	{
		ObjText_SetFontColorTop(txt, 150, 150, 255);
		ObjText_SetFontColorBottom(txt, 200, 200, 255);
		ObjText_SetFontBorderColor(txt, 0, 0, 255);
	}
	case("GREEN")
	{
		ObjText_SetFontColorTop(txt, 150, 255, 150);
		ObjText_SetFontColorBottom(txt, 200, 255, 200);
		ObjText_SetFontBorderColor(txt, 0, 200, 0);
	}
	case("YELLOW")
	{
		ObjText_SetFontColorTop(txt, 255, 255, 150);
		ObjText_SetFontColorBottom(txt, 255, 255, 200);
		ObjText_SetFontBorderColor(txt, 150, 150, 0);
	}
	case("AQUA")
	{
		ObjText_SetFontColorTop(txt, 150, 255, 255);
		ObjText_SetFontColorBottom(txt, 200, 255, 255);
		ObjText_SetFontBorderColor(txt, 0, 200, 200);
	}
	case("PURPLE")
	{
		ObjText_SetFontColorTop(txt, 255, 150, 255);
		ObjText_SetFontColorBottom(txt, 255, 200, 255);
		ObjText_SetFontBorderColor(txt, 255, 0, 255);
	}
	ObjText_SetHorizontalAlignment(txt, ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(txt, GetStgFrameWidth);
	ObjText_SetFontBorderType(txt, BORDER_FULL);
	ObjText_SetFontBorderWidth(txt, 1);
	ObjRender_SetPosition(txt, txtx, 24, 0);

	let objScene = GetEnemyBossSceneObjectID();
	let bonus = ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE);
	let btxt = ObjText_Create;
	ObjText_SetText(btxt, "Bonus: " ~ IntToString(bonus) ~ " ");
	ObjText_SetFontType(btxt, "Verdana");
	ObjText_SetFontSize(btxt, 16);
	ObjText_SetFontColorTop(btxt, 255, 255, 255); ObjText_SetFontColorBottom(btxt, 255, 255, 255);
	ObjText_SetHorizontalAlignment(btxt, ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(btxt, GetStgFrameWidth);
	ObjText_SetFontBorderType(btxt, BORDER_FULL);
	ObjText_SetFontBorderWidth(btxt, 1);
	ObjText_SetFontBorderColor(btxt, 100, 100, 100);
	ObjRender_SetPosition(btxt, txtx, 42, 0);
	SpellB;

	if(type == 0)
	{
		StartSpell;
		Checker;
		CutinType0;
		ValCheck;
	}

	task CutinType0
	{
		ObjMove_SetDestAtFrame(ct, GetStgFrameWidth-width, -height, 180);
		
		loop(30)
		{
			txtx -= ((GetStgFrameWidth+16) / 30);
			cty -= (dcty / 45);
			deca+=(100/45);
			decx+=2;
			ObjRender_SetX(txt, txtx);
			ObjRender_SetX(btxt, txtx);
			ObjRender_SetY(ct, cty);
			ObjRender_SetAlpha(dec, deca);
			ObjSprite2D_SetSourceRect(dec, -decx, 0, 3600-decx, 1200);
			yield;
		}

		loop(15)
		{
			cty -= (dcty / 45);
			deca+=(100/45);
			decx+=2;
			ObjRender_SetAlpha(dec, deca);
			ObjRender_SetY(ct, cty);
			ObjSprite2D_SetSourceRect(dec, -decx, 0, 3600-decx, 1200);
			yield;
		}

		loop(45)
		{
			decx+=2;
			ObjSprite2D_SetSourceRect(dec, -decx, 0, 3600-decx, 1200);
			yield;
		}

		let cta = 255; let scale = 1;
		loop(30)
		{
			decx+=2;
			deca-=(100/30);
			cta -= 255/30;
			scale+=0.015;
			ObjRender_SetAlpha(ct, cta);
			ObjSprite2D_SetDestRect(ct, 0, 0, width*scale, height*scale);
			ObjRender_SetAlpha(dec, deca);
			ObjSprite2D_SetSourceRect(dec, -decx, 0, 3600-decx, 1200);
			yield;
		}
		Obj_Delete(ct);Obj_Delete(dec);
	}

	task SpellB
	{
		let ftimer = ObjEnemyBossScene_GetInfo(objScene, INFO_ORGTIMERF);
		let timer = ObjEnemyBossScene_GetInfo(objScene, INFO_TIMERF);
		let sc = timer/ftimer;
		let fail = false;

		loop
		{
			timer = ObjEnemyBossScene_GetInfo(objScene, INFO_TIMERF);
			sc = timer/ftimer;
			if(!fail)
			{
				if(ftimer<1000000)
				{
					ObjText_SetText(btxt, "Bonus: " ~ IntToString(bonus*sc) ~ " ");
				}
				
				else
				{
					ObjText_SetText(btxt, "Bonus: " ~ IntToString(bonus) ~ " ");
				}
			}
			else{ObjText_SetText(btxt, "Bonus: Failed ");}
			loop(2){yield;}
			if((ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT)>0)||(ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT)>0))
			{
				fail = true;
			}
		}
	}

	task Checker
	{
		while(!Obj_IsDeleted(id)){yield;}
		Obj_Delete(txt); Obj_Delete(btxt);
	}

	task ValCheck
	{
		loop(120){yield;}
		while(GetLife(id)>=val){yield;}
		Changer;
	}

	task Changer
	{
		PlaySE(ch);
		let ta = 255;
		loop(60){ta-=(255/60);ObjRender_SetAlpha(txt, ta);yield;}
		ObjText_SetText(txt, name2);
		alternative(color2)
		case("RED")
		{
			ObjText_SetFontColorTop(txt, 255, 150, 150);
			ObjText_SetFontColorBottom(txt, 255, 200, 200);
			ObjText_SetFontBorderColor(txt, 255, 0, 0);
		}
		case("BLUE")
		{
			ObjText_SetFontColorTop(txt, 150, 150, 255);
			ObjText_SetFontColorBottom(txt, 200, 200, 255);
			ObjText_SetFontBorderColor(txt, 0, 0, 255);
		}
		case("GREEN")
		{
			ObjText_SetFontColorTop(txt, 150, 255, 150);
			ObjText_SetFontColorBottom(txt, 200, 255, 200);
			ObjText_SetFontBorderColor(txt, 0, 200, 0);
		}
		case("YELLOW")
		{
			ObjText_SetFontColorTop(txt, 255, 255, 150);
			ObjText_SetFontColorBottom(txt, 255, 255, 200);
			ObjText_SetFontBorderColor(txt, 150, 150, 0);
		}
		case("AQUA")
		{
			ObjText_SetFontColorTop(txt, 150, 255, 255);
			ObjText_SetFontColorBottom(txt, 200, 255, 255);
			ObjText_SetFontBorderColor(txt, 0, 200, 200);
		}
		case("PURPLE")
		{
			ObjText_SetFontColorTop(txt, 255, 150, 255);
			ObjText_SetFontColorBottom(txt, 255, 200, 255);
			ObjText_SetFontBorderColor(txt, 255, 0, 255);
		}
		loop(60){ta+=(255/60);ObjRender_SetAlpha(txt, ta);yield;}
	}
}