require "scripts/style"

gIntroPlayed = false;

kButtonSpacing = 47;
kButtonY = -10;
kButtonX = 590;
zButtonY = 20;
zButtonX = 900;

function CheckUsers()
	if (GetNumUsers() == 0) then
		gEnterNameValue = "";
		name = DoModal("scripts/entername.lua");
		if (not(name == nil)) then
			CreateNewUser(name);
			SetWelcomeName();
			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",
			Text
			{
				font = StandardButtonFontThree,
				name = "welcome",
				x=310,y=720,w=kMax-172,h=52,
				flags = kVAlignCenter,
				label = "welcome"
			};
			
			SetStyle( MenuButtonStyle ),
-- NEW GAME
			MenuButton
			{
				graphics=NewGameGraphics,
				x=kButtonX,
				y=kButtonY + (kButtonSpacing * 1),
				name="gamemode1",
				type = kPush,
				command=
					function()
						if (CheckUsers()) then
							-- Tell TSettings what game mode we're entering
							SetCurrentGameMode(1);
							-- Switch to the appropriate screen
                        if (gIntroPlayed == true) then
							SwapToModal("scripts/worldMap.lua");
                        else
							StopMenuMusic();
                            SwapToModal("scripts/intro.lua");
                        end
							SetState( kGameMode, "samplegame" );
						end
					end
			},
            
			MenuButton
			{
				graphics=ExitGraphics,
				x=kButtonX,
				y=kButtonY + (kButtonSpacing * 5),
				name="quit",
                cancel=true,
				type = kPush,
				command=
					function()
						local quitconfirm,error = loadfile('scripts/quitverify.lua');
						if error then
							DebugOut(error)
						else
							quitconfirm();
						end
					end
			},
			
			MenuButton
			{
				graphics=CreditsGraphics,
				x=kButtonX,
				y=kButtonY + (kButtonSpacing * 4),
				name="credits",
				type = kPush,
				command=
					function()
						DoModal("scripts/credits.lua");
					end
			},
			
			MenuButton
			{
				graphics=NewProfGraphics,
				x=kButtonX,
				y=kButtonY + (kButtonSpacing * 2),
				name="changeplayer",
				label="changeplayer",
				type = kPush,
				command=
					function()
						if (CheckUsers()) then
                            DoModal("scripts/chooseplayer.lua");
						end
					end				
			},

			MenuButton
			{
				graphics=OptionsGraphics,
				x=kButtonX,
				y=kButtonY + (kButtonSpacing * 3),
				name="menuoptions",
				label="menuoptions",
				type = kPush,
				command=
					function()
						-- Pop up an options screen
						DoModal("scripts/options.lua");
					end
			},

		
		},
	},
}