/*!

*/
#if defined DIALOG_INCLUDED___
  #endinput
#endif
#define DIALOG_INCLUDED___

#include <all.inc>

stock obj:CreateLabelMessage(string[], obj:parent = 0) {

	new obj:label = CreateLabel(parent);
	SetPos(label, 0.0, 0.0, 1.0);
	SetColor(label, 1.0, 1.0, 1.0, 1.0);
	SetOptionS(label, TAG("UTF8"), string);
	SetOptionI(label, TAG("FSIZ"), 18);

	return label;
}

/*
*/
stock GameMenuDialog() {

	//黒い背景
	new obj:bg = CreatePlane(Disp2D());
	SetColor(bg, 0.0, 0.0, 0.0, 0.0);
	SetPos(bg, 320.0, 224.0, 1.0);
	SetLocalScale(bg, 640.0, 448.0, 1.0);
	SetZOrder(bg, ZSORT_TOP_MOST);
	SetZOffset(bg, 1.0);

	AnimColor(bg, 0.0, 0.0, 0.0, 0.5, 100.0);
	wait(100);

	//ダイアログベース
	new obj:dlg = CreatePlane(bg);
	SetPos(dlg, 0.0, -32.0, 0.0);
	SetLocalScale(dlg, 320.0, 148.0, 1.0);
	SetColor(dlg, 0.6, 0.3, 0.0, 0.6);
	SetZOrder(dlg, ZSORT_TOP_MOST);
	SetZOffset(dlg, 2.0);
	SetOptionI(dlg, TAG("FDEG"), 65535);

	//上部バー
	new obj:caption_base = CreatePlane(dlg);
	SetPos(caption_base, 0.0, -48.0, 0.0);
	SetLocalScale(caption_base, 300.0, 20.0, 1.0);
	SetColor(caption_base, 0.0, 0.3, 0.6, 0.2);
	SetZOrder(caption_base, ZSORT_TOP_MOST);
	SetZOffset(caption_base, 3.0);
	SetOptionI(caption_base, TAG("FDEG"), 65535);
	SetOptionI(caption_base, TAG("ALPH"), ALPHA_BLEND_AMPLIFY);

	//渡された文字列の作成
	new label_color[4];
//	MakeCol4( label_color, { 255,255,255,255, 255,255,255,255,
//							 255,192,176,228, 255,192,176,228 } );
	MakeCol4( label_color, { 255,255,255,255, 255,255,255,255,
							 176,192,255,228, 176,192,255,228 } );

	//キャプション
	new obj:dlg_caption = CreateLabelMessage("PAUSE", caption_base);
	SetColor(dlg_caption, 1.0, 1.0, 1.0, 1.0);
	SetPos(dlg_caption, 0.0, 8.0, 0.0);
	SetOptionI(dlg_caption, TAG("HALN"), ALIGN_CENTER);
	SetZOrder(dlg_caption, ZSORT_TOP_MOST);
	SetZOffset(dlg_caption, 10.0);

	new menu_message[3][] = {
		"ゲーム再開",
		"次の面",
		"タイトルに戻る"
	};

	new max_select = 3;
	new obj:label[3];
	new float:selector_y[3];
	for (new i = 0;i < max_select; ++i) {
		label[i] = CreateLabelMessage(menu_message[i], caption_base);
		selector_y[i] = 20.0 + i * 30.0 + 18.0 - 8.0;

		SetPos(label[i], 0.0, selector_y[i] + 10.0, 0.0);

		SetOptionI(label[i], TAG("HALN"), ALIGN_CENTER);
		SetScale(label[i], 1.0, 1.2, 1.0);
		SetZOrder(label[i], ZSORT_TOP_MOST);
		SetZOffset(label[i], 10.0);
		SetOptionP(label[i], TAG("COL4"), label_color);
		SetOptionI(label[i], TAG("FSIZ"), 20);
	}

	new obj:selector = CreatePlane(caption_base);
	SetLocalScale(selector, 48.0, 28.0, 1.0);
	SetPos(selector, 0.0, selector_y[0], 0.0);
	SetColor(selector, 0.6, 0.3, 0.0, 0.4);
	SetScale(selector, 5.0, 1.0, 0.1);
	SetZOrder(selector, ZSORT_TOP_MOST);
	SetZOffset(selector, 5.0);
	SetOptionI(selector, TAG("FDEG"), 8192);
	SetOptionI(selector, TAG("ALPH"), ALPHA_BLEND_ADD);

	new obj:selector2 = CreatePlane(selector);
	SetLocalScale(selector2, 34.0, 32.0, 1.0);
	SetPos(selector2, 0.0, 0.0, 0.0);
	SetColor(selector2, 0.6, 0.3, 0.0, 0.2);
	SetScale(selector2, 1.0, 0.9, 1.0);
	SetZOrder(selector2, ZSORT_TOP_MOST);
	SetZOffset(selector2, 5.0);
	SetOptionI(selector2, TAG("FDEG"), 16384);
	SetOptionI(selector2, TAG("ALPH"), ALPHA_BLEND_ADD);

	new select_index = 0;			//選択している文字列の数

	//スタート条件
	new bool:start_enabled = true;

	new pad;
	for (;;) {
		//タイトル表示
		PadState(_, pad);
		if (pad & ePADRright) {
			SEPlay(SE_OK_ACTION);
			break;
		}
		if (pad & ePADRdown) {
			SEPlay(SE_CANCEL_ACTION);
			select_index = -1;
			break;
		}
		if (pad & ePADLup) {
			SEPlay(SE_CURSOR_MOVE);
			AnimScale(selector, 0.0, 1.0, 1.0, 50.0);
			AnimColor(selector2, 0.0, 0.0, 0.0, 0.0, 50.0);

			select_index--;

			if ((!start_enabled) && (select_index == 2)) {
				select_index = 0;
			}

			if (select_index < 0) {
				select_index = max_select - 1;
			}
			wait(50);
			SetPos(selector, 0.0, selector_y[select_index], 0.0);
			AnimScale(selector, 5.0, 1.0, 1.0, 50.0);
			AnimColor(selector2, 0.6, 0.3, 0.0, 1.0, 50.0);
			wait(50);

			AnimColor(selector2, 0.6, 0.3, 0.0, 0.0, 400.0);

		}
		if (pad & ePADLdown) {
			SEPlay(SE_CURSOR_MOVE);
			AnimScale(selector, 0.0, 1.0, 1.0, 50.0);
			AnimColor(selector2, 0.0, 0.0, 0.0, 0.0, 50.0);

			select_index++;
			if ((!start_enabled) && (select_index == 1)) {
				select_index = 3;
			}
			if (select_index > (max_select - 1)) {
				select_index = 0;
			}
			wait(50);
			SetPos(selector, 0.0, selector_y[select_index], 0.0);
			AnimScale(selector, 5.0, 1.0, 1.0, 50.0);
			AnimColor(selector2, 0.6, 0.3, 0.0, 1.0, 50.0);

			wait(50);

			AnimColor(selector2, 0.6, 0.3, 0.0, 0.0, 400.0);

		}
		sleep;
	}

	wait(100);

	AnimColor(bg, 0.0, 0.0, 0.0, 0.0, 100.0);
	wait(100);

	SafeDestroyObject(bg);
	ArrayDestroyObject(label);
	SafeDestroyObject(selector);
	SafeDestroyObject(selector2);

	return select_index;

}

/*
*/
stock RetryDialog() {

	//黒い背景
	new obj:bg = CreatePlane(Disp2D());
	SetColor(bg, 0.0, 0.0, 0.0, 0.0);
	SetPos(bg, 320.0, 224.0, 1.0);
	SetLocalScale(bg, 640.0, 448.0, 1.0);
	SetZOrder(bg, ZSORT_TOP_MOST);
	SetZOffset(bg, 1.0);

	AnimColor(bg, 0.0, 0.0, 0.0, 0.5, 100.0);
	wait(100);

	//ダイアログベース
	new obj:dlg = CreatePlane(bg);
	SetPos(dlg, 0.0, -32.0, 0.0);
	SetLocalScale(dlg, 320.0, 148.0, 1.0);
	SetColor(dlg, 0.6, 0.3, 0.0, 0.6);
	SetZOrder(dlg, ZSORT_TOP_MOST);
	SetZOffset(dlg, 2.0);
	SetOptionI(dlg, TAG("FDEG"), 65535);

	//上部バー
	new obj:caption_base = CreatePlane(dlg);
	SetPos(caption_base, 0.0, -48.0, 0.0);
	SetLocalScale(caption_base, 300.0, 20.0, 1.0);
	SetColor(caption_base, 0.0, 0.3, 0.6, 0.2);
	SetZOrder(caption_base, ZSORT_TOP_MOST);
	SetZOffset(caption_base, 3.0);
	SetOptionI(caption_base, TAG("FDEG"), 65535);
	SetOptionI(caption_base, TAG("ALPH"), ALPHA_BLEND_AMPLIFY);

	//渡された文字列の作成
	new label_color[4];
//	MakeCol4( label_color, { 255,255,255,255, 255,255,255,255,
//							 255,192,176,228, 255,192,176,228 } );
	MakeCol4( label_color, { 255,255,255,255, 255,255,255,255,
							 176,192,255,228, 176,192,255,228 } );

	//キャプション
	new obj:dlg_caption = CreateLabelMessage("RETRY?", caption_base);
	SetColor(dlg_caption, 1.0, 1.0, 1.0, 1.0);
	SetPos(dlg_caption, 0.0, 8.0, 0.0);
	SetOptionI(dlg_caption, TAG("HALN"), ALIGN_CENTER);
	SetZOrder(dlg_caption, ZSORT_TOP_MOST);
	SetZOffset(dlg_caption, 10.0);

	new menu_message[3][] = {
		"もう一度",
		"次の面",
		"タイトルに戻る"
	};

	new max_select = 3;
	new obj:label[3];
	new float:selector_y[3];
	for (new i = 0;i < max_select; ++i) {
		label[i] = CreateLabelMessage(menu_message[i], caption_base);
		selector_y[i] = 20.0 + i * 30.0 + 18.0 - 8.0;

		SetPos(label[i], 0.0, selector_y[i] + 10.0, 0.0);

		SetOptionI(label[i], TAG("HALN"), ALIGN_CENTER);
		SetScale(label[i], 1.0, 1.2, 1.0);
		SetZOrder(label[i], ZSORT_TOP_MOST);
		SetZOffset(label[i], 10.0);
		SetOptionP(label[i], TAG("COL4"), label_color);
		SetOptionI(label[i], TAG("FSIZ"), 20);
	}

	new obj:selector = CreatePlane(caption_base);
	SetLocalScale(selector, 48.0, 28.0, 1.0);
	SetPos(selector, 0.0, selector_y[0], 0.0);
	SetColor(selector, 0.6, 0.3, 0.0, 0.4);
	SetScale(selector, 5.0, 1.0, 0.1);
	SetZOrder(selector, ZSORT_TOP_MOST);
	SetZOffset(selector, 5.0);
	SetOptionI(selector, TAG("FDEG"), 8192);
	SetOptionI(selector, TAG("ALPH"), ALPHA_BLEND_ADD);

	new obj:selector2 = CreatePlane(selector);
	SetLocalScale(selector2, 34.0, 32.0, 1.0);
	SetPos(selector2, 0.0, 0.0, 0.0);
	SetColor(selector2, 0.6, 0.3, 0.0, 0.2);
	SetScale(selector2, 1.0, 0.9, 1.0);
	SetZOrder(selector2, ZSORT_TOP_MOST);
	SetZOffset(selector2, 5.0);
	SetOptionI(selector2, TAG("FDEG"), 16384);
	SetOptionI(selector2, TAG("ALPH"), ALPHA_BLEND_ADD);

	new select_index = 0;			//選択している文字列の数

	//スタート条件
	new bool:start_enabled = true;

	new pad;
	for (;;) {
		//タイトル表示
		PadState(_, pad);
		if (pad & ePADRright) {
			SEPlay(SE_OK_ACTION);

			break;
		}
		if (pad & ePADLup) {
			SEPlay(SE_CURSOR_MOVE);
			AnimScale(selector, 0.0, 1.0, 1.0, 50.0);
			AnimColor(selector2, 0.0, 0.0, 0.0, 0.0, 50.0);

			select_index--;

			if ((!start_enabled) && (select_index == 2)) {
				select_index = 0;
			}

			if (select_index < 0) {
				select_index = max_select - 1;
			}
			wait(50);
			SetPos(selector, 0.0, selector_y[select_index], 0.0);
			AnimScale(selector, 5.0, 1.0, 1.0, 50.0);
			AnimColor(selector2, 0.6, 0.3, 0.0, 1.0, 50.0);
			wait(50);

			AnimColor(selector2, 0.6, 0.3, 0.0, 0.0, 400.0);

		}
		if (pad & ePADLdown) {
			SEPlay(SE_CURSOR_MOVE);
			AnimScale(selector, 0.0, 1.0, 1.0, 50.0);
			AnimColor(selector2, 0.0, 0.0, 0.0, 0.0, 50.0);

			select_index++;
			if ((!start_enabled) && (select_index == 1)) {
				select_index = 3;
			}
			if (select_index > (max_select - 1)) {
				select_index = 0;
			}
			wait(50);
			SetPos(selector, 0.0, selector_y[select_index], 0.0);
			AnimScale(selector, 5.0, 1.0, 1.0, 50.0);
			AnimColor(selector2, 0.6, 0.3, 0.0, 1.0, 50.0);

			wait(50);

			AnimColor(selector2, 0.6, 0.3, 0.0, 0.0, 400.0);

		}
		sleep;
	}

	wait(100);

	AnimColor(bg, 0.0, 0.0, 0.0, 0.0, 100.0);
	wait(100);

	SafeDestroyObject(bg);
	ArrayDestroyObject(label);
	SafeDestroyObject(selector);
	SafeDestroyObject(selector2);

	return select_index;

}
