//---------------------------------------------------------------------------------------------
//
//	Chromatic Wing Mod
//	
//	Score (FEVER) relate
//
//---------------------------------------------------------------------------------------------


//---------------------------------------------------------------------------------------------
// Declare variable
//---------------------------------------------------------------------------------------------

// Fever System Relate
	let UIOE_FeverImage = GetCurrentScriptDirectory~"./img/fever.png";
	let UIOE_Fever;

	let UIOE_FeversizeY;
	let UIOE_FeversizeY1;
	let UIOE_FeversizeY2;
	let UIOE_count2 = 1;

	let n_temp;


	let UIOE_GMImage = GetCurrentScriptDirectory~"./img/GameMode.png";
	let UIOE_GameMode;
	let UIOE_GMdraw = 0;







//---------------------------------------------------------------------------------------------
// Sub function to be call later.
//---------------------------------------------------------------------------------------------

// For update each frame.

	sub SFU_fever
	{
	n_temp = floor(GetCommonDataDefault("CD_Feverscore",0) / 10000);

	SetCommonData("CD_FeverMultiply", n_temp);
	if (GetCommonDataDefault("CD_FeverMultiply",1) < 1)	{	SetCommonData("CD_FeverMultiply", 1);	}
	if (GetCommonDataDefault("CD_Feverscore",0) <= 0) { SetCommonData("CD_Feverscore", 0); }

	// Cast Super Natural Border when fever MAX
	if (GetCommonDataDefault("CD_Feverscore",0) >= 100000) 
		{
		SuperNaturalBorder(300);
		SetCommonData("CD_Feverscore", 60000);
		}

	SetCommonData("CD_FeverMultiplyUse", GetCommonDataDefault("CD_FeverMultiply",1));
	if (GetCommonDataDefault("CD_FeverMultiplyUse",1) > 5)	{	SetCommonData("CD_FeverMultiplyUse", 5);	}
	if (GetCommonDataDefault("CD_FeverMultiplyUse",1) < 1)	{	SetCommonData("CD_FeverMultiplyUse", 1);	}

	// Fever Score will drop by 10000 every 5 sec. (60*33 = 1980 *5)
	if ((GetCommonDataDefault("ng_feverdecrease",1) == 1) && (GetCommonDataDefault("CD_Feverscore",0) > 0))	{	SetCommonData("CD_Feverscore", GetCommonDataDefault("CD_Feverscore",0) - 33);	}


	// But if shooting enemy, it will increase a bit slowly - so you can get multi border during fight with boss or enemy
	// But yeah, fuck up because you can't use GetHisCount in stage again. Go to enemy file FUCK!
//	if (GetHitCount >= 1)	{	SetCommonData("CD_Feverscore", GetCommonDataDefault("CD_Feverscore",0) + 133);	}


	// Counter for 1 frame at mainloop then, draw or update
	UIOE_count2--;
	if (UIOE_count2 == 0)	
		{
		SFUUI_feverdraw;
		}
	else if (UIOE_count2 < 0)	
		{
		FU_feverupdate(GetCommonDataDefault("CD_FeverMultiply",1));
		}


	// draw gamemode after select gamemode
	if ((GetCommonDataDefault("CD_gamemode",0) > 0) && (UIOE_GMdraw == 0))
		{
		SFUUI_GMdraw;
		UIOE_GMdraw++;
		}
	else if ((GetCommonDataDefault("CD_gamemode",0) > 0) && (UIOE_GMdraw >= 1))
		{
		SFUUI_GMupdate;
		if (UIOE_GMdraw < 51)	{	UIOE_GMdraw++;	}
		}



	}




//---------------------------------------------------------------------------------------------
// Sub function drawing
//---------------------------------------------------------------------------------------------


// Draw Fever
	sub SFUUI_feverdraw 
	{
	UIOE_Fever = Obj_Create(OBJ_EFFECT);
	UIOE_FeversizeY = 16;
	ObjEffect_SetTexture(UIOE_Fever, UIOE_FeverImage);
	ObjEffect_SetLayer(UIOE_Fever, 8);
	ObjEffect_SetPrimitiveType(UIOE_Fever, PRIMITIVE_TRIANGLEFAN);
	ObjEffect_CreateVertex(UIOE_Fever, 4);
	ObjEffect_SetVertexXY(UIOE_Fever, 0, GetClipMaxX+20, GetClipMinY+265);
	ObjEffect_SetVertexXY(UIOE_Fever, 1, GetClipMaxX+93, GetClipMinY+265);
	ObjEffect_SetVertexXY(UIOE_Fever, 2, GetClipMaxX+93, GetClipMinY+282);
	ObjEffect_SetVertexXY(UIOE_Fever, 3, GetClipMaxX+20, GetClipMinY+282);
	ObjEffect_SetVertexUV(UIOE_Fever, 0, 0, 0);
	ObjEffect_SetVertexUV(UIOE_Fever, 1, 73, 0);
	ObjEffect_SetVertexUV(UIOE_Fever, 2, 73, 17);
	ObjEffect_SetVertexUV(UIOE_Fever, 3, 0, 17);
	}

// Update Fever
	function FU_feverupdate(fdata)
	{
	alternative(fdata)
//		case(0)	{	UIOE_FeversizeY1 = 0;	UIOE_FeversizeY2 = 1;	}
		case(1)	{	UIOE_FeversizeY1 = 0;	UIOE_FeversizeY2 = 1;	}
		case(2)	{	UIOE_FeversizeY1 = 1;	UIOE_FeversizeY2 = 2;	}
		case(3)	{	UIOE_FeversizeY1 = 2;	UIOE_FeversizeY2 = 3;	}
		case(4)	{	UIOE_FeversizeY1 = 3;	UIOE_FeversizeY2 = 4;	}
		case(5)	{	UIOE_FeversizeY1 = 4;	UIOE_FeversizeY2 = 5;	}
		case(6)	{	UIOE_FeversizeY1 = 5;	UIOE_FeversizeY2 = 6;	}
		case(7)	{	UIOE_FeversizeY1 = 6;	UIOE_FeversizeY2 = 7;	}
		case(8)	{	UIOE_FeversizeY1 = 7;	UIOE_FeversizeY2 = 8;	}
		case(9)	{	UIOE_FeversizeY1 = 8;	UIOE_FeversizeY2 = 9;	}

		ObjEffect_SetVertexUV(UIOE_Fever, 0, 0, UIOE_FeversizeY*UIOE_FeversizeY1);
		ObjEffect_SetVertexUV(UIOE_Fever, 1, 73, UIOE_FeversizeY*UIOE_FeversizeY1);
		ObjEffect_SetVertexUV(UIOE_Fever, 2, 73, (UIOE_FeversizeY*UIOE_FeversizeY2)+1);
		ObjEffect_SetVertexUV(UIOE_Fever, 3, 0, (UIOE_FeversizeY*UIOE_FeversizeY2)+1);
	}



// Draw gamemode
	sub SFUUI_GMdraw 
	{
	UIOE_GameMode = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(UIOE_GameMode, UIOE_GMImage);
	ObjEffect_SetLayer(UIOE_GameMode, 8);
	ObjEffect_SetPrimitiveType(UIOE_GameMode, PRIMITIVE_TRIANGLEFAN);
	ObjEffect_CreateVertex(UIOE_GameMode, 4);
	ObjEffect_SetVertexXY(UIOE_GameMode, 0, GetClipMaxX+82.5, GetClipMinY-2.5);
	ObjEffect_SetVertexXY(UIOE_GameMode, 1, GetClipMaxX+157.5, GetClipMinY-2.5);
	ObjEffect_SetVertexXY(UIOE_GameMode, 2, GetClipMaxX+157.5, GetClipMinY+22.5);
	ObjEffect_SetVertexXY(UIOE_GameMode, 3, GetClipMaxX+82.5, GetClipMinY+22.5);

	if (GetCommonData("CD_gamemode") == 2)
		{
		ObjEffect_SetVertexUV(UIOE_GameMode, 0, 0, 26);
		ObjEffect_SetVertexUV(UIOE_GameMode, 1, 75, 26);
		ObjEffect_SetVertexUV(UIOE_GameMode, 2, 75, 50);
		ObjEffect_SetVertexUV(UIOE_GameMode, 3, 0, 50);
		}
	else
		{
		ObjEffect_SetVertexUV(UIOE_GameMode, 0, 0, 26);
		ObjEffect_SetVertexUV(UIOE_GameMode, 1, 75, 26);
		ObjEffect_SetVertexUV(UIOE_GameMode, 2, 75, 50);
		ObjEffect_SetVertexUV(UIOE_GameMode, 3, 0, 50);
		}

	ObjEffect_SetVertexColor(UIOE_GameMode, 0, 0, 255, 255, 255);
	ObjEffect_SetVertexColor(UIOE_GameMode, 1, 0, 255, 255, 255);
	ObjEffect_SetVertexColor(UIOE_GameMode, 2, 0, 255, 255, 255);
	ObjEffect_SetVertexColor(UIOE_GameMode, 3, 0, 255, 255, 255);
	}

// continue drawing
	sub SFUUI_GMupdate
	{
	if (GetCommonData("CD_gamemode") == 2)
		{
		ObjEffect_SetVertexUV(UIOE_GameMode, 0, 0, 26);
		ObjEffect_SetVertexUV(UIOE_GameMode, 1, 75, 26);
		ObjEffect_SetVertexUV(UIOE_GameMode, 2, 75, 50);
		ObjEffect_SetVertexUV(UIOE_GameMode, 3, 0, 50);
		}
	else
		{
		ObjEffect_SetVertexUV(UIOE_GameMode, 0, 0, 1);
		ObjEffect_SetVertexUV(UIOE_GameMode, 1, 75, 1);
		ObjEffect_SetVertexUV(UIOE_GameMode, 2, 75, 25);
		ObjEffect_SetVertexUV(UIOE_GameMode, 3, 0, 25);
		}
	ObjEffect_SetVertexColor(UIOE_GameMode, 0, UIOE_GMdraw*5, 255, 255, 255);
	ObjEffect_SetVertexColor(UIOE_GameMode, 1, UIOE_GMdraw*5, 255, 255, 255);
	ObjEffect_SetVertexColor(UIOE_GameMode, 2, UIOE_GMdraw*5, 255, 255, 255);
	ObjEffect_SetVertexColor(UIOE_GameMode, 3, UIOE_GMdraw*5, 255, 255, 255);
	}





