require( "scripts/style" );
--------------------------------------
-- 					Init
--------------------------------------
local kButtonSpacing = 25;
local kButtonY = 480;
local kButtonX = 170;
-- Change Plyaer
local kWelcomeUserW = 294;
local kWelcomeUserH = 100;
local kWelcomeUserXOffset = 25;
local kWelcomeUserYOffset = 10;
local newUser = false;

gFromMetastructure = 0;
gNavigatingMetamap = 0;
gCurrentLevel = 1; -- Temp
gCurrentVenue = 1; -- Temp 
					
--------------------------------------
-- 					Functions
--------------------------------------
function CheckUsers()
	if (GetNumUsers() == 0) 
	then
		gEnterNameValue = "";
		name = DoModal("scripts/popups/popupentername.lua");
		if (not(name == nil)) 
		then
			CreateNewUser(name);
			newUser=true;
			return true ;
		end
		return false ;
	else
		return true;
	end
end

function QuitGame()
	CloseWindow();
end

--------------------------------------
-- 				Controls
--------------------------------------
txtWelcome = 
	ColorShadowColorText(294,
							100,
							kMax - kWelcomeUserW - kWelcomeUserXOffset,
							kMax - kWelcomeUserH - kWelcomeUserYOffset + 18, 
							kDefaultButtonFontSize - 12,
							"welcome", 
							Color(3,9,50,255), 
							Color(255,230,236,255),
							"welcome",
							kDefaultButtonFontShadowSize+1,
							kHAlignCenter + kVAlignCenter,
							defaultFont);	

btnPlay = 
	Button
	{
		name = "play",
		x = kButtonX,
		y = kButtonY,
		DefaultButtonLabel("play"),
		type = kPush,
		command =
			function()
				-- Set up the number of rows and columns
				gRows = 5; 
				gColumns = 5;
				if (CheckUsers()) 
				then
					doTransition("goMetaMap");
				end
			end
	};
	
	btnCredits = 
	Button
		{
			name = "credits",
			x = kButtonX,
			y = kButtonY + (kButtonSpacing * 2),
			default = true,
			cancel = true,
			DefaultButtonLabel("#Credits"),
			command =
				function()
					DoModal("scripts/dialogs/dialogcredits.lua");
				end
		};

btnOptions = 
	Button
	{
		name = "options",
		x = kButtonX,
		y = kButtonY + (kButtonSpacing * 4),
		DefaultButtonLabel("options"),
		type = kPush,
		command =
			function()
				DoModal("scripts/popups/popupoptions.lua");
			end
	};

btnQuit = 
	Button
	{
		name = "quit",
		x = kButtonX,
		y = kButtonY + (kButtonSpacing * 6),
		DefaultButtonLabel("quit"),
		type = kPush,
		command =
			function()
				result = DisplayDialog 
				{
					"scripts/popups/popupyesno.lua",
					body = "quitconfirm",
					title = "#"
				};
				if (result == 'yes') then
					PostMessage( CreateNamedMessage( kQuitNow, "Quit" ) );
				end
			end
	};

btnChangePlayer = 
	Button
	{
		name = "changeplayer",
		x = 758,
		y = 638,
		ButtonLabel("changeplayer",28,0,0),
		type = kPush,
		command =
			function()
				DoModal("scripts/popups/popupchooseplayer.lua");
			end
	};

bmpUsername = 
	Bitmap
	{
		name = "bmpUsername",
		image = "elements/mainmenu/eleusername",
		x = kMax - kWelcomeUserW - kWelcomeUserXOffset,
		y = kMax - kWelcomeUserH - kWelcomeUserYOffset, 
		
	};
--------------------------------------
-- 				Main Dialog
--------------------------------------
DoModal("scripts/dialogs/dialogload.lua");
MakeDialog
{
	-- Name the modal dialog
	name = "mainmenu",
	Bitmap
		{
			name = "backgroundimage",
			image = "backgrounds/dialogs/dialogmainmenu",
	MainMenu
	{
		fit = true;
		Bitmap
		{
			name = "backgroundimage",
			image = "backgrounds/dialogs/dialogmainmenu",

			SetStyle(ButtonStyle),
			btnPlay,
			btnOptions,
			btnCredits,
			btnQuit,
			--btnHelp,
			
			SetStyle(ChangePlayerButtonStyle),
			btnChangePlayer,
			-- Welcome
			bmpUsername,
			txtWelcome,
				
			-- Sound	
			createSound(),
		},
	},
	}
}