
require( "scripts/style" );

kButtonSpacing = 100;
kButtonY = 350;
kButtonX = 650;

WelcomeFont = {
  "fonts/chocolatebox.mvec",
  58,
  WhiteColor
};

PlayerNameFont = {
  "fonts/agilohandwriting.mvec",
  48,
  Color(153,102,204,255)
};

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",
	
	Bitmap
	{
		name="backgroundimage",
		image="images/main/mainbg",
		x=0, y=0,
		
		MainMenu
		{
			x=0,
			y=0,
			w=1024,
			h=768,
			
			Bitmap
			{
				image="images/main/welcome_bg", x=280, y=506
			};
			Text
			{
				font = WelcomeFont,
				name = "welcome",
				x=298,y=520,w=300,h=58,
				flags = kHAlignCenter + kVAlignCenter,
				label = "welcome"
			};
			Text
			{
				font = PlayerNameFont,
				name = "playername",
				x=346,y=580,w=206,h=50,
				flags = kHAlignCenter + kVAlignCenter
			};
			Bitmap
			{
				image="images/main/menu_bg", x=630, y=470
			};

			SetStyle( ClickToChangePlayerStyle ),
			MenuButton
			{
				x=370,y=625, w=235,h=22,
				name="changeplayer",
				MenuButtonLabel("changeplayer", nil, nil, 17, nil, nil, true),
				type = kPush,
				command=
					function()
						DoModal("scripts/chooseplayer.lua");
					end
			},

			SetStyle( MenuButtonStyle ),
			MenuButton
			{
				x=kButtonX,
				y=kButtonY + (kButtonSpacing * 1),
				w=260, h=50,
				name="debugmode",
				MenuButtonLabel("debugmode", nil, nil, nil, 94),
				type = kPush,
				sound = "audio/sfx/click_play1.ogg";
				command=
					function()
						if (CheckUsers()) then
							-- Tell TSettings what game mode we're entering
							SetCurrentGameMode(0);
							SendGameMessage("enabledebug");
							SetState( kGameMode, "samplegame" );
						end
					end
			},
		
--[[
			MenuButton
			{
				x=kButtonX,
				y=kButtonY + (kButtonSpacing * 1),
				name="gamemode2",
				MenuButtonLabel("gamemode1"),
				type = kPush,
				sound = "audio/sfx/click_play1.ogg",
				command=
					function()
						-- Set up the number of rows and columns
						if (CheckUsers()) then
							-- Tell TSettings what game mode we're entering
							SetCurrentGameMode(1);
							-- Switch to the appropriate screen
							SendGameMessage("disabledebug");
							SwapToModal("scripts/cutscene.lua");
							SetState( kGameMode, "samplegame" );
						end
					end
			},
--]]
			MenuButton
			{
				x=kButtonX,
				y=kButtonY + (kButtonSpacing * 2),
				w=260, h=50,
				name="options",
				MenuButtonLabel("options", nil, nil, nil, 80),
				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
	--		},
			
			--[[ Jean requested to hide medals button for BETA since not yet implemented
			MenuButton
			{
				x=kButtonX,
				y=kButtonY + (kButtonSpacing * 3),
				--w=260, h=50,
				name="medals",
				MenuButtonLabel("medals", nil, nil, nil, 90),
				type = kPush,
				command=
					function()
						SwapToModal("scripts/medals.lua");
					end
			},
			--]]
			

			MenuButton
			{
				x=kButtonX,
				y=kButtonY + (kButtonSpacing * 4),
				--w=260, h=50,
				name="quit",
				MenuButtonLabel("quit", nil, nil, nil, 110),
				type = kPush,
				command=
					function()
						result = DisplayDialog {
							"scripts/yesno.lua",
							body ="quitconfirm",
							title = "quittitle"
						};
						if (result=='yes') then
							PostMessage( CreateNamedMessage( kQuitNow, "Quit" ) );
						end
					end
			},
			
		-- match 3 levels
			MenuButton
			{
				x=310,
				y=kButtonY + (kButtonSpacing * 3) + 52,
				w=260, h=50,
				name="match3",
				MenuButtonLabel("main_btn_match3levels", nil, nil, nil, 36, 7),
				type = kPush,
				command=
					function()
						SwapToModal("scripts/match3menu.lua");
					end
			}
		}	
	}
}