#TouhouDanmakufu[Stage]
#ScriptVersion[2]
#Title[Hell's Famous Sisters (Configuration)]
#Text[Configuration Menu.

Hold USER key = set all
options to true.

Hold SHIFT+USER key = set all
options to false.]
#Player[.\_PlayerA.txt, .\_PlayerB.txt]

script_stage_main {
	let config = GetCurrentScriptDirectory ~ "config.png";
	let now = -1;
	let endis = [false, false, false];
	let go = 0;
	@Initialize {
		SetCommonData("Being Koishi", true);
		CreateCommonDataArea("Config");
		LoadCommonDataEx("Config", GetCurrentScriptDirectory ~ "config.dat");
		endis = [[1, 0][GetCommonDataDefaultEx("Config", "Background", true)], [1, 0][GetCommonDataDefaultEx("Config", "Custom Sidebar", true)], [1, 0][GetCommonDataDefaultEx("Config", "Boss Effects", true)]];
		SetClearFrameEffectEnable(false);
		LoadGraphic(config);
		Start;
	}
	@Finalize {
		DeleteGraphic(config);
	}
	@MainLoop {
		yield;
	}
	task Start {
		yield;
		if(GetKeyState(VK_USER)==KEY_HOLD) {
			if(GetKeyState(VK_SLOWMOVE)==KEY_HOLD) {
				SetCommonDataEx("Config", "Background", false);
				SetCommonDataEx("Config", "Custom Sidebar", false);
				SetCommonDataEx("Config", "Boss Effects", false);
			} else {
				SetCommonDataEx("Config", "Background", true);
				SetCommonDataEx("Config", "Custom Sidebar", true);
				SetCommonDataEx("Config", "Boss Effects", true);
			}
			SaveCommonDataEx("Config", GetCurrentScriptDirectory ~ "config.dat");
			RaiseError("Settings have been saved", "Overused All-stars");
		} else {
			ForbidShot(true); ForbidBomb(true);
			BG;
			ascent(i in 0..3) { Title(i); ascent(j in 0..2) { EnableDisable(i, j); } }
			End;
			EndBG;
			loop(60) { yield; }
			now = 0;
			Stitches;
		}
	}
	task Stitches {
		while(go == 0) {
			if(GetKeyState(VK_DOWN) == KEY_PUSH) {
				PlaySE(GetCurrentScriptDirectory ~ "se_menuselect.wav");
				now++; while(now > 3) { now-=4; }
			}
			if(GetKeyState(VK_UP) == KEY_PUSH) {
				PlaySE(GetCurrentScriptDirectory ~ "se_menuselect.wav");
				now--; while(now < 0) { now+=4; }
			}
			if(now != 3 && (GetKeyState(VK_LEFT) == KEY_PUSH || GetKeyState(VK_RIGHT) == KEY_PUSH)) {
				PlaySE(GetCurrentScriptDirectory ~ "se_menuselect.wav");
				endis[now] = endis[now]+1; while(endis[now] > 1) { endis[now]=endis[now]-2; }
			}
			if(now == 3 && GetKeyState(VK_SHOT) == KEY_PUSH) {
				PlaySE(GetCurrentScriptDirectory ~ "se_menuok.wav");
				go = 1;
			}
			yield;
		}
		SetCommonDataEx("Config", "Background", [true, false][endis[0]]);
		SetCommonDataEx("Config", "Custom Sidebar", [true, false][endis[1]]);
		SetCommonDataEx("Config", "Boss Effects", [true, false][endis[2]]);
		SaveCommonDataEx("Config", GetCurrentScriptDirectory ~ "config.dat");
	}
	task BG {
		let obj_1 = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(obj_1, 0, 0);
		ObjEffect_SetPrimitiveType(obj_1, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetLayer(obj_1, 8);
		ObjEffect_SetTexture(obj_1, config);
		ObjEffect_CreateVertex(obj_1, 4);
			ObjEffect_SetVertexUV(obj_1, 0, 0, 480);
			ObjEffect_SetVertexUV(obj_1, 1, 640, 480);
			ObjEffect_SetVertexUV(obj_1, 2, 640, 512);
			ObjEffect_SetVertexUV(obj_1, 3, 0, 512);
			ObjEffect_SetVertexXY(obj_1, 0, 0, 0);
			ObjEffect_SetVertexXY(obj_1, 1, 640, 0);
			ObjEffect_SetVertexXY(obj_1, 2, 640, 480);
			ObjEffect_SetVertexXY(obj_1, 3, 0, 480);
		let obj = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(obj, 0, 0);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetLayer(obj, 8);
		ObjEffect_SetTexture(obj, config);
		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);
		descent(i in 0..60) { ascent(j in 0..4) { ObjEffect_SetVertexColor(obj, j, 255*cos(i*90/60), 255, 255, 255); } yield; }
	}
	task EndBG {
		let obj_1 = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(obj_1, 0, 0);
		ObjEffect_SetPrimitiveType(obj_1, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetLayer(obj_1, 8);
		ObjEffect_SetTexture(obj_1, config);
		ObjEffect_CreateVertex(obj_1, 4);
			ObjEffect_SetVertexUV(obj_1, 0, 0, 480);
			ObjEffect_SetVertexUV(obj_1, 1, 640, 480);
			ObjEffect_SetVertexUV(obj_1, 2, 640, 512);
			ObjEffect_SetVertexUV(obj_1, 3, 0, 512);
			ObjEffect_SetVertexXY(obj_1, 0, 0, 0);
			ObjEffect_SetVertexXY(obj_1, 1, 640, 0);
			ObjEffect_SetVertexXY(obj_1, 2, 640, 480);
			ObjEffect_SetVertexXY(obj_1, 3, 0, 480);
		ascent(j in 0..4) { ObjEffect_SetVertexColor(obj_1, j, 0, 255, 255, 255); }
		while(go==0){yield}
		descent(i in 0..60) { ascent(j in 0..4) { ObjEffect_SetVertexColor(obj_1, j, 255*cos(i*90/60), 255, 255, 255); } yield; }
		RaiseError("Settings have been saved", "Overused All-stars");
	}
	task Title(let which) {
		let obj = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(obj, 0, 192+which*64);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetLayer(obj, 8);
		ObjEffect_SetTexture(obj, config);
		ObjEffect_CreateVertex(obj, 4);
			ObjEffect_SetVertexUV(obj, 0, 640, 0+64*which);
			ObjEffect_SetVertexUV(obj, 1, 640+384, 0+64*which);
			ObjEffect_SetVertexUV(obj, 2, 640+384, 64+64*which);
			ObjEffect_SetVertexUV(obj, 3, 640, 64+64*which);
			ObjEffect_SetVertexXY(obj, 0, 0, 0);
			ObjEffect_SetVertexXY(obj, 1, 384, 0);
			ObjEffect_SetVertexXY(obj, 2, 384, 64);
			ObjEffect_SetVertexXY(obj, 3, 0, 64);
			ObjEffect_SetScale(obj, 3/4, 3/4);
		task Trans {
			loop {
				ascent(j in 0..4) { ObjEffect_SetVertexColor(obj, j, [155, 255][now == which], 255, 255, 255); }
				yield;
			}
		} Trans;
		descent(i in 0..60) {
			Obj_SetX(obj, 12-384*(1-cos(i*90/60)));
			ascent(j in 0..4) { ObjEffect_SetVertexColor(obj, j, 155*cos(i*90/60), 255, 255, 255); }
		yield; }
	}
	task EnableDisable(let which, let which2) {
		let obj = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(obj, 0, 192+which*64+8);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetLayer(obj, 8);
		ObjEffect_SetTexture(obj, config);
		ObjEffect_CreateVertex(obj, 4);
			ObjEffect_SetVertexUV(obj, 0, 640+192*which2, 0+64*3);
			ObjEffect_SetVertexUV(obj, 1, 640+192+192*which2, 0+64*3);
			ObjEffect_SetVertexUV(obj, 2, 640+192+192*which2, 64+64*3);
			ObjEffect_SetVertexUV(obj, 3, 640+192*which2, 64+64*3);
			ObjEffect_SetVertexXY(obj, 0, 0, 0);
			ObjEffect_SetVertexXY(obj, 1, 192, 0);
			ObjEffect_SetVertexXY(obj, 2, 192, 64);
			ObjEffect_SetVertexXY(obj, 3, 0, 64);
			ObjEffect_SetScale(obj, 1/2, 1/2);
		task Trans {
			loop {
				ascent(j in 0..4) { ObjEffect_SetVertexColor(obj, j, [155, 255][endis[which] == which2], 255, 255, 255); }
				yield;
			}
		} Trans;
		descent(i in 0..60) {
			Obj_SetX(obj, 320+8+128*which2+384*(1-cos(i*90/60)));
			ascent(j in 0..4) { ObjEffect_SetVertexColor(obj, j, 155*cos(i*90/60), 255, 255, 255); }
		yield; }
	}
	task End {
		let obj = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(obj, 0, 192+3*64);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetLayer(obj, 8);
		ObjEffect_SetTexture(obj, config);
		ObjEffect_CreateVertex(obj, 4);
			ObjEffect_SetVertexUV(obj, 0, 640, 0+64*4);
			ObjEffect_SetVertexUV(obj, 1, 640+384, 0+64*4);
			ObjEffect_SetVertexUV(obj, 2, 640+384, 64+64*4);
			ObjEffect_SetVertexUV(obj, 3, 640, 64+64*4);
			ObjEffect_SetVertexXY(obj, 0, -384, 0);
			ObjEffect_SetVertexXY(obj, 1, 0, 0);
			ObjEffect_SetVertexXY(obj, 2, 0, 64);
			ObjEffect_SetVertexXY(obj, 3, -384, 64);
			ObjEffect_SetScale(obj, 3/4, 3/4);
		task Trans {
			loop {
				ascent(j in 0..4) { ObjEffect_SetVertexColor(obj, j, [155, 255][now == 3], 255, 255, 255); }
				yield;
			}
		} Trans;
		descent(i in 0..60) {
			Obj_SetX(obj, 640-12+384*(1-cos(i*90/60)));
			ascent(j in 0..4) { ObjEffect_SetVertexColor(obj, j, 155*cos(i*90/60), 255, 255, 255); }
		yield; }
	}
}