task StartSTGFrame {
	if(GetCommonDataDefaultEx("Config", "Custom Sidebar", true)) {
		SetDefaultStatusVisible(false);
		SetRateScoreSystemEnable(false);
		SetClearFrameEffectEnable(false);
		yield;
		CreateFrame;
		while(!chosediff) { yield; }
		TDifficulty(diffsel);
		ascent(i in 0..4) { InfoTitle(i, [52, 88, 106, 138][i]); }
		ascent(i in 0..2) { CreateNumber(i); }
		ascent(i in 0..2) { CreateLifeIndic(i); }
	} else {
		SetDefaultStatusVisible(true);
		SetRateScoreSystemEnable(true);
		SetClearFrameEffectEnable(true);
	}
}

task CreateFrame {
	let obj = Obj_Create(OBJ_EFFECT);
	Obj_SetPosition(obj, 0, 0);
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjEffect_SetLayer(obj, 8);
	ObjEffect_SetTexture(obj, stgframe);
	ObjEffect_CreateVertex(obj, 4);
	ObjEffect_SetVertexUV(obj, 0, 0, 0);
	ObjEffect_SetVertexUV(obj, 1, 640, 0);
	ObjEffect_SetVertexUV(obj, 2, 640, 480);
	ObjEffect_SetVertexUV(obj, 3, 0, 480);
	ObjEffect_SetVertexXY(obj, 0, 0, 0);
	ObjEffect_SetVertexXY(obj, 1, 640, 0);
	ObjEffect_SetVertexXY(obj, 2, 640, 480);
	ObjEffect_SetVertexXY(obj, 3, 0, 480);
}

function IntString(let number) { let str = ToString(number); let str2 = ""; let i = 0; while (str[i] != '.') { str2 = str2 ~ [str[i]]; i++; } return str2; }

function CharToNum(let number, let place) {
	alternative(IntString(number)[place])
	case('0') { return 0; } case('1') { return 1; } case('2') { return 2; } case('3') { return 3; } case('4') { return 4; }
	case('5') { return 5; } case('6') { return 6; } case('7') { return 7; } case('8') { return 8; } case('9') { return 9; }
	others { RaiseError("CharToNum is getting an invalid digit", "CharToNum error"); }
}

task CreateNumber(let arg) {
	function GetNumberValue {
		alternative(arg)
		case(0) { return GetScore; }
		case(1) { return GetGraze; }
		others { return 0; }
	}
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLELIST);
	ObjEffect_SetLayer(obj, 8);
	ObjEffect_SetTexture(obj, numbers);
	ObjEffect_CreateVertex(obj, 4);
	loop {
		let tempnum = length(IntString(GetNumberValue));
		ObjEffect_ResizeVertexCount(obj, 12*tempnum);
		Obj_SetPosition(obj, 616-12*tempnum, [44, 132][arg]);
		ascent(i in 0..tempnum) {
			let tempnum2 = CharToNum(GetNumberValue, i)*16;
			ObjEffect_SetVertexUV(obj, i*6+0, 0+tempnum2, 0);
			ObjEffect_SetVertexUV(obj, i*6+1, 16+tempnum2, 0);
			ObjEffect_SetVertexUV(obj, i*6+2, 16+tempnum2, 16);
			ObjEffect_SetVertexUV(obj, i*6+3, 0+tempnum2, 0);
			ObjEffect_SetVertexUV(obj, i*6+4, 16+tempnum2, 16);
			ObjEffect_SetVertexUV(obj, i*6+5, 0+tempnum2, 16);
			ObjEffect_SetVertexXY(obj, i*6+0, 0+12*i, 0);
			ObjEffect_SetVertexXY(obj, i*6+1, 16+12*i, 0);
			ObjEffect_SetVertexXY(obj, i*6+2, 16+12*i, 16);
			ObjEffect_SetVertexXY(obj, i*6+3, 0+12*i, 0);
			ObjEffect_SetVertexXY(obj, i*6+4, 16+12*i, 16);
			ObjEffect_SetVertexXY(obj, i*6+5, 0+12*i, 16);
			ObjEffect_SetVertexUV(obj, i*6+0, 0+tempnum2, 0);
			ObjEffect_SetVertexUV(obj, i*6+1, 16+tempnum2, 0);
			ObjEffect_SetVertexUV(obj, i*6+2, 16+tempnum2, 16);
			ObjEffect_SetVertexUV(obj, i*6+3, 0+tempnum2, 0);
			ObjEffect_SetVertexUV(obj, i*6+4, 16+tempnum2, 16);
			ObjEffect_SetVertexUV(obj, i*6+5, 0+tempnum2, 16);
			ObjEffect_SetVertexXY(obj, i*6+0, 0+12*i, 0);
			ObjEffect_SetVertexXY(obj, i*6+1, 16+12*i, 0);
			ObjEffect_SetVertexXY(obj, i*6+2, 16+12*i, 16);
			ObjEffect_SetVertexXY(obj, i*6+3, 0+12*i, 0);
			ObjEffect_SetVertexXY(obj, i*6+4, 16+12*i, 16);
			ObjEffect_SetVertexXY(obj, i*6+5, 0+12*i, 16);
		}
		yield;
	}
}

task InfoTitle(arg, y) {
	let obj = Obj_Create(OBJ_EFFECT);
	Obj_SetPosition(obj, 0, 0);
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjEffect_SetLayer(obj, 8);
	ObjEffect_SetTexture(obj, numbers);
	ObjEffect_CreateVertex(obj, 4);
	Obj_SetPosition(obj, GetClipMaxX+64, y);
	ObjEffect_SetScale(obj, 7/8, 7/8);
	ObjEffect_SetVertexUV(obj, 0, 128, 32+arg*24);
	ObjEffect_SetVertexUV(obj, 1, 256, 32+arg*24);
	ObjEffect_SetVertexUV(obj, 2, 256, 32+arg*24+23);
	ObjEffect_SetVertexUV(obj, 3, 128, 32+arg*24+23);
	ObjEffect_SetVertexXY(obj, 0, -64, -12);
	ObjEffect_SetVertexXY(obj, 1, 64, -12);
	ObjEffect_SetVertexXY(obj, 2, 64, 12);
	ObjEffect_SetVertexXY(obj, 3, -64, 12);
}

task CreateLifeIndic(let arg) {
	function GetNumberValue {
		alternative(arg)
		case(0) { return GetPlayerLife-1; }
		case(1) { return GetPlayerBomb; }
		others { return 0; }
	}
	let obj = Obj_Create(OBJ_EFFECT);
	Obj_SetPosition(obj, 508, 80+18*arg);
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLELIST);
	ObjEffect_SetLayer(obj, 8);
	ObjEffect_SetTexture(obj, numbers);
	ObjEffect_CreateVertex(obj, 6*8);
	loop {
		ascent(i in 0..8) {
			let arg2 = [1, 0][GetNumberValue > i];
			ObjEffect_SetVertexUV(obj, i*6+0, 176+16*arg2, 0);
			ObjEffect_SetVertexUV(obj, i*6+1, 176+16+16*arg2, 0);
			ObjEffect_SetVertexUV(obj, i*6+2, 176+16+16*arg2, 16);
			ObjEffect_SetVertexUV(obj, i*6+3, 176+16*arg2, 0);
			ObjEffect_SetVertexUV(obj, i*6+4, 176+16+16*arg2, 16);
			ObjEffect_SetVertexUV(obj, i*6+5, 176+16*arg2, 16);
			ObjEffect_SetVertexXY(obj, i*6+0, 0+16*i, 0);
			ObjEffect_SetVertexXY(obj, i*6+1, 16+16*i, 0);
			ObjEffect_SetVertexXY(obj, i*6+2, 16+16*i, 16);
			ObjEffect_SetVertexXY(obj, i*6+3, 0+16*i, 0);
			ObjEffect_SetVertexXY(obj, i*6+4, 16+16*i, 16);
			ObjEffect_SetVertexXY(obj, i*6+5, 0+16*i, 16);
		}
		yield;
	}
}

task TDifficulty(diff) {
	yield;
	let obj = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(obj, GetCenterX, GetClipMinY+10);
		ObjEffect_SetTexture(obj, numbers);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetLayer(obj, 8);
		ObjEffect_SetVertexUV(obj, 0, 0, 64+diff*16);
			ObjEffect_SetVertexUV(obj, 1, 128, 64+diff*16);
			ObjEffect_SetVertexUV(obj, 2, 128, 64+diff*16+16);
			ObjEffect_SetVertexUV(obj, 3, 0, 64+diff*16+16);
		ObjEffect_SetVertexXY(obj, 0, -64, -8);
			ObjEffect_SetVertexXY(obj, 1, 64, -8);
			ObjEffect_SetVertexXY(obj, 2, 64, 8);
			ObjEffect_SetVertexXY(obj, 3, -64, 8);
	ascent(i in 0..15) { ObjEffect_SetScale(obj, 1, (i+1)/15); yield; }
	ascent(i in 0..45/3) {
		ascent(j in 0..4) { ObjEffect_SetVertexColor(obj, j, 255, 175+80*sin((i%2)*90), 175+80*sin((i%2)*90), 175+80*sin((i%2)*90)); }
		loop(3) { yield; }
	}
	ascent(j in 0..4) { ObjEffect_SetVertexColor(obj, j, 255, 255, 255, 255); }
	loop(20) { yield; }
	descent(i in 0..20) {
		ascent(j in 0..4) { ObjEffect_SetVertexColor(obj, j, 255*(i/20), 255, 255, 255); }
		yield;
	}
	Obj_SetPosition(obj, GetClipMaxX+112+4, GetClipMinY+10);
	ascent(i in 0..20) {
		ascent(j in 0..4) { ObjEffect_SetVertexColor(obj, j, 255*((i+1)/20), 255, 255, 255); }
		yield;
	}
}

task GetSpellCardBonusDraw(let arg) {
	let objG = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetPrimitiveType(objG, PRIMITIVE_TRIANGLEFAN);
	ObjEffect_SetLayer(objG, 6);
	ObjEffect_SetTexture(objG, numbers);
	ObjEffect_CreateVertex(objG, 4);
	Obj_SetPosition(objG, GetCenterX, GetCenterY-100);
		ObjEffect_SetVertexUV(objG, 0, 0, 128+0);
		ObjEffect_SetVertexUV(objG, 1, 256, 128+0);
		ObjEffect_SetVertexUV(objG, 2, 256, 128+32);
		ObjEffect_SetVertexUV(objG, 3, 0, 128+32);
		ObjEffect_SetVertexXY(objG, 0, -128, -16);
		ObjEffect_SetVertexXY(objG, 1, 128, -16);
		ObjEffect_SetVertexXY(objG, 2, 128, 16);
		ObjEffect_SetVertexXY(objG, 3, -128, 16);
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLELIST);
	ObjEffect_SetLayer(obj, 6);
	ObjEffect_SetTexture(obj, numbers);
	ObjEffect_CreateVertex(obj, 4);
	let tempnum = length(IntString(arg));
	ObjEffect_ResizeVertexCount(obj, 6*tempnum);
	Obj_SetPosition(obj, GetCenterX-6*tempnum, GetCenterY-75);
	ascent(i in 0..tempnum) {
		let tempnum2 = CharToNum(arg, i)*16;
		ObjEffect_SetVertexUV(obj, i*6+0, 0+tempnum2, 0);
		ObjEffect_SetVertexUV(obj, i*6+1, 16+tempnum2, 0);
		ObjEffect_SetVertexUV(obj, i*6+2, 16+tempnum2, 16);
		ObjEffect_SetVertexUV(obj, i*6+3, 0+tempnum2, 0);
		ObjEffect_SetVertexUV(obj, i*6+4, 16+tempnum2, 16);
		ObjEffect_SetVertexUV(obj, i*6+5, 0+tempnum2, 16);
		ObjEffect_SetVertexXY(obj, i*6+0, 0+12*i, -8);
		ObjEffect_SetVertexXY(obj, i*6+1, 16+12*i, -8);
		ObjEffect_SetVertexXY(obj, i*6+2, 16+12*i, 8);
		ObjEffect_SetVertexXY(obj, i*6+3, 0+12*i, -8);
		ObjEffect_SetVertexXY(obj, i*6+4, 16+12*i, 8);
		ObjEffect_SetVertexXY(obj, i*6+5, 0+12*i, 8);
	}
	ascent(i in 0..15) {
		ObjEffect_SetScale(obj, 1, (i+1)/15);
		ObjEffect_SetScale(objG, 1, (i+1)/15);
		yield;
	}
	loop(90/4) {
		ascent(i in 0..tempnum*6) { ObjEffect_SetVertexColor(obj, i, 255, 155, 155, 155); }
		ascent(i in 0..4) { ObjEffect_SetVertexColor(objG, i, 255, 155, 155, 155); }
		loop(2) { yield; }
		ascent(i in 0..tempnum*6) { ObjEffect_SetVertexColor(obj, i, 255, 255, 255, 255); }
		ascent(i in 0..4) { ObjEffect_SetVertexColor(objG, i, 255, 255, 255, 255); }
		loop(2) { yield; }
	}
	descent(i in 0..15) {
		ObjEffect_SetScale(obj, 1, (i)/15);
		ObjEffect_SetScale(objG, 1, (i)/15);
		yield;
	}
	Obj_Delete(obj);
	Obj_Delete(objG);
}

task BonusFailedDraw {
	let objG = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetPrimitiveType(objG, PRIMITIVE_TRIANGLEFAN);
	ObjEffect_SetLayer(objG, 6);
	ObjEffect_SetTexture(objG, numbers);
	ObjEffect_CreateVertex(objG, 4);
	Obj_SetPosition(objG, GetCenterX, GetCenterY-100);
		ObjEffect_SetVertexUV(objG, 0, 0, 128+32);
		ObjEffect_SetVertexUV(objG, 1, 256, 128+32);
		ObjEffect_SetVertexUV(objG, 2, 256, 128+64);
		ObjEffect_SetVertexUV(objG, 3, 0, 128+64);
		ObjEffect_SetVertexXY(objG, 0, -128, -16);
		ObjEffect_SetVertexXY(objG, 1, 128, -16);
		ObjEffect_SetVertexXY(objG, 2, 128, 16);
		ObjEffect_SetVertexXY(objG, 3, -128, 16);
	ascent(i in 0..15) {
		ObjEffect_SetScale(objG, 1, (i+1)/15);
		yield;
	}
	loop(90/4) {
		ascent(i in 0..4) { ObjEffect_SetVertexColor(objG, i, 255, 155, 155, 155); }
		loop(2) { yield; }
		ascent(i in 0..4) { ObjEffect_SetVertexColor(objG, i, 255, 255, 255, 255); }
		loop(2) { yield; }
	}
	descent(i in 0..15) {
		ObjEffect_SetScale(objG, 1, (i)/15);
		yield;
	}
	Obj_Delete(objG);
}