
require "scripts/style"

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

MMButtonFont = {
  standardFont,
  66,
  WhiteColor
};

MMButtonFont2 = {
  standardFont,
  46,
  WhiteColor
};

WelcomeFont = {
  standardFont,
  36,
  WhiteColor,
 -- flags=kVAlignCenter+kHAlignCenter
}

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;
		w=1024,
		h=768,
		title_filename="ui/main_menu/logos/english",
		copyright_filename="ui/main_menu/copyright/english",
		tagline_fadetime = 1000,
		title_fadetime = 2700,
		title_fireoff = 5000,
		uipanel_vertoffset=300,
		uipanel_movetime=700,
--		Bitmap
--		{
--			name="backgroundimage",
--			image="ui/main_menu/_back",

			Bitmap{ 
				name = "uiframe",
				image = "ui/main_menu/frame", 
				x = 0, y = 445 
			},

			Text
			{
				font = WelcomeFont,
				name = "welcome",
				x=0,y=724,w=1024,h=50,
				flags = kHAlignCenter + kVAlignCenter,
				label = "welcome"
			},

			SetStyle( ButtonStyle ),
--			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
--							LoadUserData();
--							SwapToModal("scripts/hogame.lua");
--							SetState( kGameMode, "hogame" );
--						end
--					end
--			},
			Button
			{
				name = "play_button",
				graphics = { "ui/main_menu/button_5","ui/main_menu/button_5_ac","ui/main_menu/button_5_ac" },
				font = MMButtonFont,
				--tx=00,tw=300,ty=10,
				--ty=5,
				x = 376,--386, 
				y = 646,--655,
				label = "gamemode1",
				command =
					function()
						if (CheckUsers()) then
							DisplaySplash("","backgrounds/loading",200);
							SetWindowVisible("loading",true);
							-- Tell TSettings what game mode we're entering
							SetCurrentGameMode(1);
							-- Switch to the appropriate screen
							LoadUserData();
							SwapToModal("scripts/hogame.lua");
							SetState( kGameMode, "hogame" );
						end
					end
			},

--			MenuButton
--			{
--				x=kButtonX,
--				y=kButtonY + (kButtonSpacing * 2),
--				name="options",
--				MenuButtonLabel("options"),
--				type = kPush,
--				command=
--					function()
--						DoModal("scripts/options.lua");
--					end
--			},
			Button
			{
				name = "options_button",
				graphics = { "ui/main_menu/button_4","ui/main_menu/button_4_ac","ui/main_menu/button_4_ac" },
				font = MMButtonFont2,
				--tx=00,tw=200,ty=10,
				--ty=5,
				x = 28,--39,
				y = 695,--702,
				label = "options",
				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
--			},

--			MenuButton
--			{
--				x=kButtonX,
--				y=kButtonY + (kButtonSpacing * 5),
--				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
--			},
			Button
			{
				name = "exit_button",
				graphics = { "ui/main_menu/button_1","ui/main_menu/button_1_ac","ui/main_menu/button_1_ac" },
				font = MMButtonFont2,
				--tx=00,tw=200,ty=10,
				--ty=5,
				x = 748,--759,
				y = 695,--702,
				label = "quit",
				command =
					--[[function()
						result = DisplayDialog {
							"scripts/yesno.lua",
							body ="quitconfirm",
							title = "quittitle"
						};
						if (result=='yes') then
							PostMessage( CreateNamedMessage( kQuitNow, "Quit" ) );
						end
					end]]
					function()
						local quitconfirm,error = loadfile('scripts/quitverify.lua');
						if error then
							DebugOut(error)
						else
							quitconfirm();
						end
					end
			},

			Button
			{
				name = "profiles_button",
				graphics = { "ui/main_menu/button_3","ui/main_menu/button_3_ac","ui/main_menu/button_3_ac" },
				font = MMButtonFont2,
				x = 28,--39,
				y = 625,--632,
				label = "changeplayer",
				command=
					function()
						DoModal("scripts/chooseplayer.lua");
					end
			},
			Button
			{
				name = "film_button",
				graphics = { "ui/main_menu/button_2","ui/main_menu/button_2_ac","ui/main_menu/button_2_ac" },
				font = MMButtonFont2,
				--tx=00,tw=200,ty=10,
				--ty=5,
				x = 748,--759,
				y = 625,--632,
				label = "about",
				command =
				function()
					DoModal('scripts/about.lua'); 
				end
			},
			Bitmap{
				name="loading",
				image="backgrounds/loading",
				x=kCenter,
				y=kCenter,
			},
--			SetStyle(LongButtonStyle),
--			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
--			},
--		},
	}
		
}
SetWindowVisible("loading",false);
SetCurrentGameMode(0);