
require "scripts/style"

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

function Start()
	if (CheckUsers()) then
		savedLevel = GetCompletedLevelName();
		if( savedLevel == "" ) then
			StartGame( "find/gangway/gangway.lua");
		else
			StartGame( savedLevel );
		end
	end
end


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

function QuitGame()
	CloseWindow();
end

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

			Text
			{
				font = StandardButtonFont,
				name = "welcome",
				x=360,y=700,w=kMax,h=50,
				flags = kHAlignCenter + kVAlignCenter,
				label = "welcome"
			},
			
		MainMenu
		{
			x=0,
			y=0,
			w=1024,
			h=768,
			
			
			SetStyle( ButtonStyle ),
			
			Button
			{
				graphics = {	"buttons/mmoptions_up",
								"buttons/mmoptions_down",
								"buttons/mmoptions_over" };
				x=582,
				y=488,
				name="options",
				type = kPush,
				command=
					function()
						DoModal("scripts/options.lua");
					end
			},

			Button
			{
				graphics = {	"buttons/mmquit_up",
								"buttons/mmquit_down",
								"buttons/mmquit_over" };
				x=624,
				y=571,
				name="quit",
				type = kPush,
				command=
					function()
						result = DisplayDialog {
							"scripts/yesno.lua",
							body ="quitconfirm",
							title = "quittitle"
						};
						if (result=='yes') then
							PostMessage( CreateNamedMessage( kQuitNow, "Quit" ) );
						end
					end
			},
			
			Button
			{
				graphics = {	"buttons/mmplayer_up",
								"buttons/mmplayer_down",
								"buttons/mmplayer_over" };
				x=503,
				y=403,
				name="changeplayer",
				type = kPush,
				command=
					function()
						DoModal("scripts/chooseplayer.lua");
					end
			},

			Button
			{
				graphics = {	"buttons/mmnew_up",
								"buttons/mmnew_down",
								"buttons/mmnew_over" };
				name = "newGame",
				sound = "audio/sfx/scream",
				x = 551,
				y = 334,
				command = 
						function()
							Start()
						end
			},

			Button
			{
				graphics = {	"buttons/mmcont_up",
								"buttons/mmcont_down",
								"buttons/mmcont_over" };
				name = "continue",
				sound = "audio/sfx/scream",
				x = 583,
				y = 319,
				command = 
						function()
							Start()
						end
			}
		}
	}
}
