
require( "scripts/style.lua" );

kButtonSpacing = 31;
kButtonY = 550;
kButtonX = 438;

function CheckUsers()
	if (GetNumUsers() == 0) then
		gEnterNameValue = "";
		name = DoModal("scripts/entername.lua");
		if (not(name == nil)) then
			CreateProfile(name);
			SetActiveProfile(name);
			refreshInfo();
			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="gui/mainmenu/mainmenu.jpg",			
			
			FaderWindow
			{
				name="menulogo",
				wait=500,
				duration=4000,
				fit=true,
				image="gui/mainmenu/logo.png",
			},
			
			FaderWindow
			{
				name="menutitle",
				wait=2000,
				duration=4000,
				fit=true,
				image="gui/mainmenu/title.png",
			},			
			
			MovingImage
			{
				x=0,y=0,w=kMax,h=kMax,
				image="gui/mainmenu/drape1",
				imgx = 400;
				imgy = 591;
				minforcex= -1,
				maxforcex= 3,
				minforcey = -1,
				maxforcey =  3,
				maxdistx = 10,
				maxdisty = 15,
			},
			
			MovingImage
			{
				x=0,y=0,w=kMax,h=kMax,
				image="gui/mainmenu/drape2",
				imgx = 214;
				imgy = 655;
				minforcex=-1,
				maxforcex=1,
				minforcey=-1,
				maxforcey=1,
				maxdistx = 15,
				maxdisty = 15,
			},
			
			MovingImage
			{
				x=0,y=0,w=kMax,h=kMax,
				image="gui/mainmenu/drape3",
				imgx = 181;
				imgy = 642;
				minforcex=-1,
				maxforcex=1,
				minforcey=-1,
				maxforcey=1,
				maxdistx = 15,
				maxdisty = 15,
				gravityFactor = 0.8,
			},
			
			FaderWindow
			{
				name="menubuttons",
				wait=5000,
				duration=1000,
				fit = true,				
				
				Button
				{
					--fit = true,
					x = 26, y = 610,

					SelectLayer(1),
					Bitmap
					{
						x = 0, y = 120;
						image = "gui/mainmenu/selected.png",
					},
					SelectLayer(2),
					Bitmap
					{
						x = 0, y = 120;
						image = "gui/mainmenu/selected.png",
					},
					SelectLayer(kAllLayers),
					
					Bitmap
					{
						name = "activeProfileLogo",
						x = 54, y = 30,
					},
					
					Text
					{
						x = 20, y = 0,
						name = "activeProfileName",
						w = 200,
					},
					
					Text
					{
						label="menu_yourprofile",
						type=kPush,
						x=20,y=120,w=200,h=40,
						flags = kHAlignCenter,
						font = MenuButtonFont,
					},
					
					command = function()
									DisplayDialog{"scripts/profilewindow.lua"};
								end
				},
				
				SetStyle( MenuButtonStyle ),

				Button
				{
					x=kButtonX - 44,
					y=kButtonY + 3,
					name="menucarreer",
					label="menu_carreermode",
					type = kPush,
					command=
						function()
							CheckUsers();
							-- DisplaySplash("cutscenes/teste1.swf", "splash/playfirst_logo",4000);
							-- Tell TSettings what game mode we're entering
							SetCurrentGameMode(0);
							-- Switch to the appropriate screen
							SwapToModal("scripts/carreer.lua");
							SetState( kGameMode, "carreer" );
						end
				},

				SetStyle( MenuButtonStyle ),
				Button
				{
					name = "menufree",
					x=kButtonX - 44 ,y=kButtonY + kButtonSpacing + 3,w=155,h=40,
					label="menu_freemode",
					flags = kHAlignCenter,
					command=
						function()
							CheckUsers();
							local play = "yes";
							if(HasPlayed() == false)then
								play = DisplayDialog{'scripts/yesno.lua',yeslabel = 'play', nolabel = 'cancel', title = 'free_mode_confirm_title', body = 'free_mode_confirm_body'};
							end
							
							if(play == "yes")then
								SetCurrentGameMode(1);				
								SwapToModal("scripts/carreer.lua");
								SetState( kGameMode, "carreer" );
							end
						end
				},
				
				SetStyle( MenuButtonStyle ),
				Button
				{
					name = "menuOptions",
					label="options",
					type = kPush,
					x=kButtonX - 44 ,y=kButtonY + (kButtonSpacing * 2) + 3,w=155,h=40,
					flags = kHAlignCenter,
					label = "menu_options",
					command= function()
								DisplayDialog{"scripts/customoptions.lua"};
							end
				},
				
				SetStyle( MenuButtonStyle ),
				Button
				{
					name = "menuHighScores",
					label="menu_ranking",
					type = kPush,
					x=kButtonX - 44 ,y=kButtonY + (kButtonSpacing * 3) + 3,w=155,h=40,
					flags = kHAlignCenter,
					label = "menu_ranking",
					command= function()
								DisplayDialog{"scripts/ranking.lua"};
							end
				},
				
				SetStyle( MenuButtonStyle ),
				Button
				{
					name = "menuCredits",
					label="menu_credits",
					type = kPush,
					x=720 ,y=730,w=155,h=40,
					flags = kHAlignCenter,
					command= function()
								EnableWindow("menutitle",false);
								EnableWindow("menulogo",false);
								EnableWindow("menubuttons",false);
								DisplayDialog{"scripts/creditswindow.lua"};
								EnableWindow("menutitle",true);
								EnableWindow("menulogo",true);
								EnableWindow("menubuttons",true);
								reEnableFaders();
					         end
				},
			
				SetStyle( MenuButtonStyle ),		
				Button
				{
					x=kButtonX - 44,
					y=kButtonY + (kButtonSpacing * 5),
					name="quit",
					label="menu_quit",
					type = kPush,
					command=
						function()
							result = DisplayDialog {
								"scripts/yesno.lua",
								body ="quitconfirm",
								title = "quittitle"
							};
							if (result=='yes') then
								PostMessage( CreateNamedMessage( kQuitNow, "Quit" ) );
							end
						end
				},
			},
			
			MovingImage
			{
				x=0,y=0,w=kMax,h=kMax,
				image="gui/mainmenu/caustics1",
				imgx = 976;
				imgy = 736;
				minforcex=-0.1,
				maxforcex=0.1,
				minforcey=-0.1,
				maxforcey=0.1,
				minrot=-0.002,
				maxrot=0.002,
				maxdistx = 5,
				maxdisty = 5,
				gravityFactor = 0.8,
			},
			MovingImage
			{
				x=0,y=0,w=kMax,h=kMax,
				image="gui/mainmenu/caustics2",
				imgx = 984;
				imgy = 746;
				minforcex=-0.1,
				maxforcex=0.1,
				minforcey=-0.1,
				maxforcey=0.1,
				minrot=-0.002,
				maxrot=0.002,
				maxdistx = 5,
				maxdisty = 5,
				gravityFactor = 0.8,
			},
			MovingImage
			{
				x=0,y=0,w=kMax,h=kMax,
				image="gui/mainmenu/caustics3",
				imgx = 970;
				imgy = 739;
				minforcex=-0.1,
				maxforcex=0.1,
				minforcey=-0.1,
				maxforcey=0.1,
				minrot=-0.002,
				maxrot=0.002,
				maxdistx = 5,
				maxdisty = 5,
				gravityFactor = 0.8,
			},
			MovingImage
			{
				x=0,y=0,w=kMax,h=kMax,
				image="gui/mainmenu/caustics4",
				imgx = 988;
				imgy = 755;
				minforcex=-0.1,
				maxforcex=0.1,
				minforcey=-0.1,
				maxforcey=0.1,
				minrot=-0.002,
				maxrot=0.002,
				maxdistx = 5,
				maxdisty = 5,
				gravityFactor = 0.8,
			},
			MovingImage
			{
				x=0,y=0,w=kMax,h=kMax,
				image="gui/mainmenu/highlights1",
				imgx = 779;
				imgy = 450;
				minforcex=-0.1,
				maxforcex=0.1,
				minforcey=-0.1,
				maxforcey=0.1,
				minrot=-0.002,
				maxrot=0.002,
				maxdistx = 5,
				maxdisty = 5,
				gravityFactor = 0.8,
			},
			MovingImage
			{
				x=0,y=0,w=kMax,h=kMax,
				image="gui/mainmenu/highlights2",
				imgx = 787;
				imgy = 478;
				minforcex=-0.1,
				maxforcex=0.1,
				minforcey=-0.1,
				maxforcey=0.1,
				minrot=-0.002,
				maxrot=0.002,
				maxdistx = 5,
				maxdisty = 5,
				gravityFactor = 0.8,
			},
			MovingImage
			{
				x=0,y=0,w=kMax,h=kMax,
				image="gui/mainmenu/highlights3",
				imgx = 778;
				imgy = 490;
				minforcex=-0.1,
				maxforcex=0.1,
				minforcey=-0.1,
				maxforcey=0.1,
				minrot=-0.002,
				maxrot=0.002,
				maxdistx = 5,
				maxdisty = 5,
				gravityFactor = 0.8,
			},
			MovingImage
			{
				x=0,y=0,w=kMax,h=kMax,
				image="gui/mainmenu/highlights4",
				imgx = 801;
				imgy = 513;
				minforcex=-0.1,
				maxforcex=0.1,
				minforcey=-0.1,
				maxforcey=0.1,
				minrot=-0.002,
				maxrot=0.002,
				maxdistx = 5,
				maxdisty = 5,
				gravityFactor = 0.8,
			},
		},
	},
}
refreshInfo();
