
require( "scripts/style.lua" );

kButtonSpacing = 45;
kButtonY = 293;
kButtonX = 0;

PlayerNameFont = {
  standardFont,
  24,
  WhiteColor
};

VersionFont = {
  standardFont,
  14,
  WhiteColor
};

function CheckUsers()
	if (GetNumUsers() == 0) then
		gEnterNameValue = "";
		name = DoModal("scripts/entername.lua");
		if (not(name == nil)) then
			CreateNewUser(name);
			return true ;
		end
		return false ;
	else
		return true;
	end
end

function QuitGame()
	CloseWindow();
end

MakeDialog
{
	-- Name the modal dialog
	name="mainmenu",
	MainMenu
	{
		fit=true;
		Bitmap
		{
			name="backgroundimage",
			image="mainmenu/main_menu",

			Text
			{
				font = PlayerNameFont,
				name = "welcome",
				x=250,y=550,w=300,h=50,
				flags = kHAlignCenter + kVAlignCenter,
				label = "welcome"
			};

			Text
			{
				font = VersionFont,
				flags=kHAlignRight + kVAlignCenter,
				x=600,y=560,
				w=180;h=40;
--				label="#"..GetString("version",GetConfig(kGameVersion)) ;
				label="#Version 1 . 0";
			};

--			SetStyle( MenuButtonStyle ),
--			MenuButton
--			{
--				x=kButtonX,
--				y=kButtonY,
--				name="gamemode1",
--				MenuButtonLabel("gamemode1"),
--				type = kPush,
--				command=
--					function()
--						if (CheckUsers()) then
--							-- Tell TSettings what game mode we're entering
--							SetCurrentGameMode(0);
--							-- Switch to the appropriate screen
--							SwapToModal("scripts/twodemos.lua");
--							SetState( kGameMode, "twodemos" );
--						end
--					end
--			},

			SetStyle( PlayButtonStyle ),
			MenuButton
			{
				start_game=0,
				x=522,
				y=169,
				name="gamemode2",
--				MenuButtonLabel("gamemode2"),
				type = kPush,
				command=
					function()
						-- Set up the number of rows and columns
						gRows=5; gColumns=5;
						if (CheckUsers()) then
							if (GetCurrentGameState() > 0) then
								start_game=DoModal("scripts/playgame.lua");
								--result=DisplayDialog {"scripts/yesno.lua", body="continuegame", title="continuegametitle"};
								--if (result == 'yes') then
								--	SetCurrentGameMode(GetCurrentGameMode());
								--else
								--	SetCurrentLevel(0);
								--	SetHintCounter(3);
								--end
							end
							if (GetCurrentGameState() == 0) then
								result=DisplayDialog {"scripts/yesnomode.lua", body="gamemode", title="gamemodetitle"};
								-- Tell TSettings what game mode we're entering
								if (result == 'yes') then
									SetCurrentGameMode(0);
								else
									SetCurrentGameMode(1);
								end
								start_game=1;
							end
							if (start_game == 2) then
								result=DisplayDialog {"scripts/yesnomode.lua", body="gamemode", title="gamemodetitle"};
								-- Tell TSettings what game mode we're entering
								if (result == 'yes') then
									SetCurrentGameMode(0);
								else
									SetCurrentGameMode(1);
								end
								ResetAll();
								start_game=1;
							end
							-- Switch to the appropriate screen
							if (start_game == 1) then
								SwapToModal("scripts/game.lua");
								SetState( kGameMode, "Dillinger" );
							end
						end
					end
			},

			SetStyle( OptionButtonStyle ),
			MenuButton
			{
				x=522,
				y=329,
				name="options",
--				MenuButtonLabel("options"),
				type = kPush,
				command=
					function()
						DoModal("scripts/options.lua");
					end
			},

--			MenuButton
--			{
--				x=kButtonX,
--				y=kButtonY + (kButtonSpacing * 3),
--				name="highscores",
--				MenuButtonLabel("highscores"),
--				type = kPush,
--				command=
--					function()
--						SwapToModal("scripts/hiscore.lua");
--					end
--			},
			
--			MenuButton
--			{
--				x=kButtonX,
--				y=kButtonY + (kButtonSpacing * 4),
--				name="medals",
--				MenuButtonLabel("medals"),
--				type = kPush,
--				command=
--					function()
--						SwapToModal("scripts/medals.lua");
--					end
--			},

			SetStyle( QuitButtonStyle ),
			MenuButton
			{
				x=522,
				y=409,
				name="quit",
--				MenuButtonLabel("quit"),
				type = kPush,
				command=
					function()
						result = DisplayDialog {
							"scripts/yesnoquit.lua",
							body ="quitconfirm",
							title = "quittitle"
						};
						if (result=='yes') then
							PostMessage( CreateNamedMessage( kQuitNow, "Quit" ) );
						end
					end
			},

			SetStyle( PlayerButtonStyle ),
			MenuButton
			{
				x=522,
				y=249,
				name="changeplayer",
--				label="changeplayer",
				type = kPush,
				command=
					function()
						DoModal("scripts/chooseplayer.lua");
					end
			},
			
--			SetStyle( InfamyButtonStyle ),
--			MenuButton
--			{
--				x=522,
--				y=364,
--				name="wallofinfamy",
--				type = kPush,
--				command=
--					function()
--						DoModal("scripts/wallofinfamy.lua");
--					end
--			},
			
--			SetStyle(PlayerButtonStyle),
--			Button
--			{
--				x=610,
--				y=480,
--				name="changeplayer",
--				label="changeplayer",
--				type = kPush,
--				command=
--					function()
--						DoModal("scripts/chooseplayer.lua");
--					end
--			},
--			Button
--			{
--				x=610,
--				y=520,
--				name="help",
--				label="help",
--				type = kPush,
--				command=
--					function()
--						DoModal("scripts/help.lua");
--					end
--			},
		},
	}
}