//プレイヤー＆難易度の配列
let ShowPlayers = [ "Sunny", "Luna", "Star" ];
let ShowDifficults = [ "Easy", "Normal", "Panic" ];
let ShowPlayerShowNames = [ "サニーミルク", "ルナチャイルド", "スターサファイア" ];
let ShowDifficultShowNames = [ "Easy", "Normal", "Panic" ];

//現在表示しているプレイヤー＆難易度インデックス
let ShowPlayerIndex = 0;
let ShowDifficultIndex = 0;

//現在表示しているプレイヤー＆難易度
let ShowPlayer = ShowPlayers[ ShowPlayerIndex ];
let ShowDifficult = ShowDifficults[ ShowDifficultIndex ];

//リザルト表示設定
//  0:リザルトではない
//  1:スコア一覧
//  2:スペカ履歴
let ResultMode = 0;

//スペカ履歴の現在ページ数
let SpellResultPage = 0;
//スペカ履歴の最大ページ数
let SpellResultMaxPage = 2;
//未挑戦のスペカ名
let UnSeenSpellName = "？？？？？？？？？？？？？？？？？？";

/**
 * リザルト画面の文字描画
 */
function ResultDraw(){
	//描画位置決め用
	let x = 0;
	let y = 0;
	//数値取得用
	let no = 0;
	//文字取得用
	let str = "";
	
	//プレイヤー表示
	DrawText( "プレイヤー："                        ,  60, 40, 16, 255 );
	DrawText( ShowPlayerShowNames[ ShowPlayerIndex ], 160, 40, 16, 255 );
	
	//難易度表示
	DrawText( "難易度　　："                              ,  60, 60, 16, 255 );
	DrawText( ShowDifficultShowNames[ ShowDifficultIndex ], 160, 60, 16, 255 );
	
	if( ResultMode == 1 ){
		//スコア一覧
		
		//データを入れるための変数
		let score = "";
		let ns_hiscore = ShowPlayer ~ "HiScore" ~ ShowDifficult;
		let ns_playNum = ShowPlayer ~ "PlayNum" ~ ShowDifficult;
		let ns_ctClearNum = ShowPlayer ~ "ClearNum";
		let ns_ncClearNum = ShowPlayer ~ "NoContinueClearNum";
		let hiscore1 = 0;
		let hiscore2 = 0;
		let hiscore3 = 0;
		
		//ハイスコア
		DrawText( "ハイスコア", 180, 90, 16, 255 );
		
		ascent( i in 0..5 ){
			y = 120 + i * 20;
			no = (i + 1);
			str = IntToString( no );
			
			hiscore1 = GetCommonDataDefaultEx( "OFT_Save", ns_hiscore ~ str ~ "_1", 0 );
			hiscore2 = GetCommonDataDefaultEx( "OFT_Save", ns_hiscore ~ str ~ "_2", 0 );
			hiscore3 = GetCommonDataDefaultEx( "OFT_Save", ns_hiscore ~ str ~ "_3", 0 );
			score = LPad( SetComma( ScoreToString( hiscore1, hiscore2, hiscore3 ), 4, ",", "back" ), 26, " " );
			
			DrawText( str  ,  80, y, 16, 255 );
			DrawText( score, 110, y, 16, 255 );
		}
		
		//プレイデータ
		DrawText( "プレイデータ", 170, 230, 16, 255 );
		
		//ステージプレイ回数
		let playNum_1  = GetCommonDataDefaultEx( "OFT_Save", ns_playNum ~ "1", 0 );
		let playNum_2  = GetCommonDataDefaultEx( "OFT_Save", ns_playNum ~ "2", 0 );
		let playNum_3  = GetCommonDataDefaultEx( "OFT_Save", ns_playNum ~ "3", 0 );
		let playNum_EX = GetCommonDataDefaultEx( "OFT_Save", ns_playNum ~ "4", 0 );
		
		let clearNum_CT = GetCommonDataDefaultEx( "OFT_Save", ns_ctClearNum, 0 );
		let clearNum_NC = GetCommonDataDefaultEx( "OFT_Save", ns_ncClearNum, 0 );
		
		//ステージ
		DrawText( "プレイ回数",                               60, 250, 16, 255 );
		DrawText( "1",                                        60, 270, 16, 255 );
		DrawText( LPad( IntToString( playNum_1 ), 5, " " ),  100, 270, 16, 255 );
		DrawText( "2",                                        60, 290, 16, 255 );
		DrawText( LPad( IntToString( playNum_2 ), 5, " " ),  100, 290, 16, 255 );
		DrawText( "3",                                        60, 310, 16, 255 );
		DrawText( LPad( IntToString( playNum_3 ), 5, " " ),  100, 310, 16, 255 );
		DrawText( "EX",                                       60, 330, 16, 255 );
		DrawText( LPad( IntToString( playNum_EX ), 5, " " ), 100, 330, 16, 255 );
		
		//クリア回数
		DrawText( "クリア回数",                               200, 250, 16, 255 );
		DrawText( LPad( IntToString( clearNum_CT ), 5, " " ), 200, 270, 16, 255 );
		DrawText( "ノーコンティニュー",                       200, 290, 16, 255 );
		DrawText( "クリア回数",                               200, 310, 16, 255 );
		DrawText( LPad( IntToString( clearNum_NC ), 5, " " ), 200, 330, 16, 255 );
		
		//その他データ
		DrawText( "その他データ", 164, 360, 16, 255 );
		
		//プレイ時間
		DrawText( "プレイ時間"                             , 120, 390, 16, 255 );
		DrawText( LPad( IntToString( PlayTime_H ), 3, "0" ), 220, 390, 16, 255 );
		DrawText( ":"                                      , 250, 390, 16, 255 );
		DrawText( LPad( IntToString( PlayTime_M ), 2, "0" ), 260, 390, 16, 255 );
		DrawText( ":"                                      , 280, 390, 16, 255 );
		DrawText( LPad( IntToString( PlayTime_S ), 2, "0" ), 290, 390, 16, 255 );
		
		//説明
		DrawText( "上下キーで難易度の選択、左右キーでキャラクターの選択",     40, 420, 12, 255 );
		DrawText( "ショットキーでスペカ履歴へ移動、ボムキーでメニューへ戻る", 40, 440, 12, 255 );
	}else if( ResultMode == 2 ){
		//スペカ履歴
		
		//データを入れるための変数
		let spellCP = [ 0, 0 ];
		let spellC = 0;
		let spellP = 0;
		let spellName = "";
		
		//ページ数
		DrawText( IntToString( SpellResultPage + 1 ), 360, 80, 16, 255 );
		DrawText( "/"                               , 380, 80, 16, 255 );
		DrawText( IntToString( SpellResultMaxPage ) , 400, 80, 16, 255 );
		
		//スペルカード履歴
		DrawText( "スペルカード履歴", 180, 90, 16, 255 );
		
		//スペカ履歴
		ascent( i in 0..10 ){
			y = 140 + i * 20;
			no = (i + 1) + SpellResultPage * 10;
			str = IntToString( no );
			spellCP = GetSpellData( ShowPlayer, ShowDifficult, str );
			spellC = spellCP[ 0 ];
			spellP = spellCP[ 1 ];
			if( spellP == 0 ){
				spellName = UnSeenSpellName;
			}else{
				spellName = GetSpellName( ShowPlayer, ShowDifficult, str );
			}
			
			//取得したスペルには☆印
			if( spellC > 0 ){
				DrawText( "☆"                         ,  40, y, 12, 255 );
			}
			DrawText( "No."                                ,  60, y, 12, 255 );
			DrawText( LPad( str, 2, "0" )                  ,  80, y, 12, 255 );
			DrawText( spellName                            , 104, y, 12, 255 );
			DrawText( LPad( IntToString( spellC ), 3, "0" ), 347, y, 12, 255 );
			DrawText( "/"                                  , 372, y, 12, 255 );
			DrawText( LPad( IntToString( spellP ), 3, "0" ), 384, y, 12, 255 );
		}
		
		//説明
		DrawText( "上下キーで難易度の選択、左右キーでキャラクターの選択", 40, 420, 12, 255 );
		DrawText( "ショットキーでページ送り、ボムキーでメニューへ戻る",   40, 440, 12, 255 );
	}
}

/**
 * リザルト画面専用のキーチェック処理
 */
function ResultKeyCheck(){
	//決定キー
	if( GetKeyState( VK_SHOT ) == KEY_PUSH ){
		if( ResultMode == 1 ){
			//スペカ履歴へ移動
			ResultMode = 2;
		}else if( ResultMode == 2 ){
			//ページ送り
			SpellResultPage += 1;
			
			//最終ページまで行ったらハイスコア画面へ戻る
			if( SpellResultPage >= SpellResultMaxPage ){
				SpellResultPage = 0;
				ResultMode = 1;
			}
		}
	}
	//上キー
	if( GetKeyState( VK_UP ) == KEY_PUSH ){
		ShowPlayerIndex -= 1;
		if( ShowPlayerIndex < 0 ){
			ShowPlayerIndex = 2;
		}
	}
	//下キー
	if( GetKeyState( VK_DOWN ) == KEY_PUSH ){
		ShowPlayerIndex += 1;
		if( ShowPlayerIndex > 2 ){
			ShowPlayerIndex = 0;
		}
	}
	//左キー
	if( GetKeyState( VK_LEFT ) == KEY_PUSH ){
		ShowDifficultIndex -= 1;
		if( ShowDifficultIndex < 0 ){
			ShowDifficultIndex = 2;
		}
	}
	//右キー
	if( GetKeyState( VK_RIGHT ) == KEY_PUSH ){
		ShowDifficultIndex += 1;
		if( ShowDifficultIndex > 2 ){
			ShowDifficultIndex = 0;
		}
	}
	
	ShowPlayer = ShowPlayers[ ShowPlayerIndex ];
	ShowDifficult = ShowDifficults[ ShowDifficultIndex ];
}