
require( "scripts/style.lua" );

kButtonSpacing = 45;
kButtonX = 450;
kButtonY = 323;

--[[function CheckUsersWithoutCreation()
	if (GetNumUsers() == 0) then
		return false ;
	else
		return true;
	end
end]]

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="backgrounds/mainmenu",
				
			GameScreen
			{
				x=0,
				y=0,
				w=1024,
				h=768,									
			},			
			SetStyle( PlayButtonStyle ),
			
			MenuButton
			{
				x=412,
				y=616,
				--name="gamemode2",
				name = "PlayGameButton",
				MenuButtonLabel(""),
				type = kPush,
				command=
					function()
						-- Set up the number of rows and columns
						gRows=5; gColumns=5;
						if (CheckUsers()) then
							-- Tell TSettings what game mode we're entering
							SetCurrentGameMode(1);
							-- Switch to the appropriate screen
							SwapToModal("scripts/tearstone.lua");
							SetState( kGameMode, "tearstone" );
						end
					end
			},				
			Text
			{
				font = WhitePlayerText,
				name = "welcome",
				x=0,y=570,w=kMax,h=50,
				flags = kHAlignCenter + kVAlignCenter,
				label = "welcome"
			};
			--[[
			Text
			{
				font = ChangePlayerText,
				name = "click",
				x=409,y=650,w=kMax,h=50,
				--flags = kHAlignCenter + kVAlignCenter,
				label = "click"
			};		

			Text
			{
				font = ChangePlayerText,
				name = "changepl_text",
				x=513,y=650,w=kMax,h=50,
				--flags = kHAlignCenter + kVAlignCenter,
				label = "changepl_text"
			};				
              ]]            
			
			--[[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
			},

			MenuButton
			{
				x=kButtonX,
				y=kButtonY,
				name="gamemode2",
				MenuButtonLabel("gamemode2"),
				type = kPush,
				command=
					function()
						-- Set up the number of rows and columns
						gRows=5; gColumns=5;
						if (CheckUsers()) then
							-- Tell TSettings what game mode we're entering
							SetCurrentGameMode(1);
							-- Switch to the appropriate screen
							SwapToModal("scripts/tearstone.lua");
							SetState( kGameMode, "tearstone" );
						end
					end
			},

			MenuButton
			{
				x=kButtonX + 12,
				y=kButtonY + (kButtonSpacing * 1) + 5,
				name="options",
				MenuButtonLabel("options"),
				type = kPush,
				command=
					function()
						DoModal("scripts/options.lua");
					end
			},
			
			MenuButton
			{
				x=kButtonX + 13,
				y=kButtonY + (kButtonSpacing * 2) + 8,
				name="options",
				MenuButtonLabel("credits"),
				type = kPush,
				command=
					function()
						DoModal("scripts/credits.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
			},

			MenuButton
			{
				x=kButtonX + 30,
				y=kButtonY + (kButtonSpacing * 3) + 13,
				name="quit",
				MenuButtonLabel("quit"),
				type = kPush,
				command=
					function()
						result = DisplayDialog {
							"scripts/yesno.lua",
							body ="quitconfirm",
							title = "quittitle"
						};
						if (result=='yes') then
							PostMessage( CreateNamedMessage( kQuitNow, "Quit" ) );
						end
					end
			},

			SetStyle(ChangePlayerButtonStyle),
			Button
			{
				x=395,
				y=640,
				name="changeplayer",
				label="changeplayer",				
				type = kPush,
				command=
					function()
						DoModal("scripts/chooseplayer.lua");
					end
			},]]
			--[[Button
			{
				x=710,
				y=620,
				name="help",
				label="help",
				type = kPush,
				command=
					function()
						DoModal("scripts/help.lua");
					end
			},]]
		},
	}
}