require( "scripts/style.lua" );

kButtonSpacing = 45;
kButtonY = 75;
kButtonXFromCenter = 5;

geoX = 587;

CopyFont = {
	standardFont,
	21,
	Color(255,255,255,250)
};

CopyFontS = {
	standardFont,
	21,
	Color(0,0,0,200)
};

MetricsMode(0);
MenuBallsUpdate(1);

SetSoundMuteForPause(0);

MakeDialog
{
	
	MainMenu
	{
		w = 800,
		h = 600,
		
		Bitmap
		{ 
			name="backgroundimage",
			image="Game/UI/MainMenu/MainMenuScreen",	


			MenuBalls
			{
				w = 800,
				h = 600,
			},	
				

			Button -- Editor Mode
			{
				x=400,
				y=20,
				font = StandardButtonFont,
				graphics = StandardButtonGraphics,
				name="edtiormode",
				label="edtiormode",
				type = kPush,
				command=
					function()
						SetCurrentGameMode(0);
						SetEditor(1);
						--PopModal();
						SwapToModal("scripts/game.lua");
					end
			},
			
			Button -- Page Editor
			{
				x=400,
				y=60,
				font = StandardButtonFont,
				graphics = StandardButtonGraphics,
				name="pagemode",
				label="pagemode",
				type = kPush,
				command=
					function()
						SetCurrentGameMode(0);
						SetEditor(0);						
						--PopModal();
						SwapToModal("scripts/page.lua");
					end
			},

			Button -- Story Mode
			{
				x=geoX,
				y= kButtonY + (kButtonSpacing * 0),
				font = StandardButtonFont,
				graphics = StandardButtonGraphics,
				name="gamemode1",
				label="gamemode1",
				type = kPush,
				command=
					function()
						rungame = true
						MenuBallsUpdate(0);
						SetCurrentGameMode(0);
						SetEditor(0);
					
						if (GetNumUsers() == 0) then
							rungame = false
							gEnterNameValue = "";
							name = DoModal("scripts/entername.lua");
							if (not(name == nil)) then
								CreateNewUser(name);
								rungame = true
							end
						end
						
						if (rungame == true) then
						
							-- Is there a save game available ?
							ret = LoadGameState();
							if (not(ret == 0)) then
							
								-- Do we want to run it
								DebugOut( "Going To Call Continue Dialog" );
								result = DoModal("scripts/continue.lua")
								
								if (result=='yes') then
									-- Starting from map screen ?
									if (GetGameStateType() == 1) then							
										--PopModal()
										SwapToModal("scripts/storymap.lua");
										return
										
									end
									-- Starting from game ?
									if (GetGameStateType() == 2) then
										--PopModal()
										SwapToModal("scripts/game.lua");							
										return
										
									end	
								else
									if (result == 'cancel') then
										MenuBallsUpdate(1);
										return
									else
										if (result == 'newgame') then
											StartNewGame()
										end
									end
								end								
							end
							
							-- First Time
							if (ComicAvailable(0) == 1) then
								DoModal("scripts/comic.lua");								
							end
							
							--PopModal();
							SwapToModal("scripts/storymap.lua");
				
							return
							
						end
					
					MenuBallsUpdate(1);	
					end
			},
			
			Button -- Arcade Mode
			{
				x=geoX,
				y= kButtonY + (kButtonSpacing * 1),
				font = StandardButtonFont,
				graphics = StandardButtonGraphics,
				name="arcademode",
				label="arcademode",
				type = kPush,
				command=
					function()
					
						
						SetEditor(0);

						if (GetNumUsers() == 0) then
							gEnterNameValue = "";
							name = DoModal("scripts/entername.lua");
							if (not(name == nil)) then
								CreateNewUser(name);
								MenuBallsUpdate(0);
								if (ArcadeMode() == 1) then
									SetCurrentGameMode(1+GetArcadeDiff());
									SwapToModal("scripts/game.lua");
								end
								SetWelcomeName();
								MenuBallsUpdate(1);
							end
						else
							MenuBallsUpdate(0);
							if (ArcadeMode() == 1) then
								SetCurrentGameMode(1+GetArcadeDiff());
								SwapToModal("scripts/game.lua");
							end
							MenuBallsUpdate(1);
						end
					end
			},
			
			Button -- Arcade Mode
			{
				x=geoX,
				y= kButtonY + (kButtonSpacing * 2),
				font = StandardButtonFont,
				graphics = StandardButtonGraphics,
				name="moregames",
				label="moregames",
				type = kPush,
				command=
					function()
						DoModal("xsell/xsell.lua");
					end
			},
			
			Button
			{
				x=geoX,
				y= kButtonY + (kButtonSpacing * 3),
				font = StandardButtonFont,
				graphics = StandardButtonGraphics,
				name="options",
				label="options",
				type = kPush,
				command=
					function()
						MenuBallsUpdate(0);
						DoModal("scripts/options.lua");
						MetricsMode(0);
						MenuBallsUpdate(1);
					end
			},
			
			Button
			{
				x=geoX,
				y= kButtonY + (kButtonSpacing * 4),
				font = StandardButtonFont,
				graphics = StandardButtonGraphics,
				name="highscores",
				label="highscores",
				type = kPush,
				command=
					function()
						MenuBallsUpdate(0);
						--PopModal();
						DoModal("scripts/hiscore.lua");
						MetricsMode(0);
						MenuBallsUpdate(1);
					end
			},

			Button
			{
				x=geoX,
				y=kButtonY + (kButtonSpacing * 5),
				font = StandardButtonFont,
				graphics = StandardButtonGraphics,
				name="help",
				label="help",
				type = kPush,
				command=
					function()
						MenuBallsUpdate(0);
						--PopModal();
						DoModal("scripts/instructions.lua");
						MetricsMode(0);
						MenuBallsUpdate(1);
					end
			},
						
			Button
			{
				x=geoX,
				y=kButtonY + (kButtonSpacing * 6),
				font = StandardButtonFont,
				graphics = StandardButtonGraphics,
				name="quit",
				label="quit",
				type = kPush,
				command=
					function()
						MenuBallsUpdate(0);
						result = DisplayDialog { 
							"scripts/yesno.lua", 
							body ="quitconfirm",
							title = "quittitle" 
						};
						if (result=='yes') then
							PostMessage( CreateNamedMessage( kQuitNow, "Quit" ) );
						end
						MenuBallsUpdate(1);
					end
			},
			
			Text
			{
				font = StandardButtonFont,
				name = "welcome",
				x=geoX-30,y=423,w=200,h=50,
				flags = kHAlignCenter + kVAlignCenter,
				label = "welcome"
			};
			
			Button
			{
				x=geoX,
				y=494,
				font = StandardButtonFont,
				graphics = StandardButtonGraphics,
				name="changeplayer",
				label="changeplayer",
				type = kPush,
				command=
					function()
						MenuBallsUpdate(0);
						DoModal("scripts/chooseplayer.lua");
						MenuBallsUpdate(1);						
					end
			},
			

			Button{
				graphics = CheckboxButtonGraphics,
				name="cheatbutton",
				type = kToggle,
				x=geoX-5,
				y=40,
				w=350,
				Text
				{
					font = StandardButtonFont,
					name = "cheat",
					x=50,
					y=18,
					w=kMax,
					h=kMax,
					flags = kHAlignLeft + kVAlignTop,
					label="cheat",
				};
				command=
				function()
					ToggleCheat();
				end
				
			};	
			


				

			Text
			{
				font = CopyFontS,
				name = "copyright",
				x=11,y=565,w=790+2,h=30+5,
				flags = kHAlignLeft + kVAlignCenter,
				label = "copyright"
			};
			
			Text
			{
				font = CopyFont,
				name = "copyright",
				x=9,y=565,w=790,h=30,
				flags = kHAlignLeft + kVAlignCenter,
				label = "copyright"
			};
							
								
		},
			
	}
}

function ArcadeMode () 

	DebugOut( "Arcade Dialog" );
	result = DoModal("scripts/arcade.lua")
	
	if (result=='easy') then
		ArcadeDiff(0);
		return 1;
	else
		if (result=='medium') then
			ArcadeDiff(1);
			return 1;
		else
			if (result=='hard') then
				ArcadeDiff(2);
				return 1;
			end
		end
	end
	
	return 0;
end