require "scripts/style"
--------------------------------------
-- 					Init
--------------------------------------
local kButtonSpacing = 50;			-- Put our buttons 60 pixels apart
local kButtonY = kCenter - 150;	-- Three buttons means center 60 pixels above the center

-- When this dialog is popped up, we're entering pause state, so
-- let's just notify TGameState now.
SetState( kPause, true );

--------------------------------------
-- 				Controls
--------------------------------------

btnRetryLevel =
	Button
	{
		name = "retrybutton",
		x = kCenter,
		y = kButtonY,
		ButtonLabel("retry",28,22,2),
		command =
			function()
				SetWindowVisible("dialogshadow",false);
				result = DisplayDialog 
				{
					"scripts/popups/popupyesno.lua",
					body = "retrygameconfirm",
					title = "#"
				};
				if (result == 'yes') 
				then						
					SetState("EndState", 3);
					if (resetObjects)
					then
						resetObjects();
					end
					--[[if (cleanUpgrades)
					then
						cleanUpgrades();
					end]]
					doTransition("goGame");						                 
				end
				SetWindowVisible("dialogshadow",true);
			end
	};

btnMetamap = 
	Button
	{
		name = "metamapbutton",
		x = kCenter,
		y = kButtonY + (kButtonSpacing * 1),
		ButtonLabel("metamap",28,21,2),
		command =
			function()
				SetWindowVisible("dialogshadow",false);
				result = DisplayDialog 
				{
					"scripts/popups/popupyesno.lua",
					body = "gotometamapconfirm",
					title = "#"
				};
				if (result == 'yes') 
				then						
					SetState("EndState", 3);		
					if (resetObjects)
					then
						resetObjects();
					end
					doTransition("goMetaMap");						                 
				end
				SetWindowVisible("dialogshadow",true);
			end
	};

btnOptions = 
	Button	
	{
		name = "optionsbutton",
		x = kCenter,
		y = kButtonY + (kButtonSpacing * 2),
		ButtonLabel("options",28,16,2),
		command =
			function()
				-- Pop up an options screen
				SetWindowVisible("dialogshadow",false);
				DoModal("scripts/popups/popupoptions.lua");
				SetWindowVisible("dialogshadow",true);
			end
	};

btnMainMenu = 
	Button	
	{
		name = "maimenubutton",
		x = kCenter,
		y = kButtonY + (kButtonSpacing * 3),
		ButtonLabel("mainmenu",28,23,2),
		command =
			function()
				SetWindowVisible("dialogshadow",false);
				result = DisplayDialog 
				{
					"scripts/popups/popupyesno.lua",
					body = "mainmenuconfirm",
					title = "#"
				};
				if (result == 'yes') 
				then						
					SetState("EndState", 3);		
					if (resetObjects)
					then
						resetObjects();
					end
					doTransition("goMainMenu");						                 
				end
				SetWindowVisible("dialogshadow",true);
			end
	};



btnResume = 
	Button	
	{
		name = "resumebutton",
		x = kCenter,
		y = kButtonY + (kButtonSpacing * 5),
		ButtonLabel("resume",28,20,2),
		close = true,	-- Just close this window
		cancel = true,
		command =
			function()
				PauseAnimations(false);
				closeModal();
			end;
	};

btnQuit = 
	Button
	{
		name = "quitbutton",
		x = kCenter,
		y = kButtonY + (kButtonSpacing * 6),
		ButtonLabel("quit",28,16,2),
		command=
				function()
					SetWindowVisible("dialogshadow",false);
					result = DisplayDialog 
					{
						"scripts/popups/popupyesno.lua",
						body = "quitconfirm",
						title = "#"--quittitle"
					};
					if (result == 'yes') 
					then						
						SetState("EndState", 3);
						SetState( kPause, false );							
						PostMessage( CreateNamedMessage( kQuitNow, "Quit" ) );									
					end
					SetWindowVisible("dialogshadow",true);	
				end		
	};

--------------------------------------
-- 				Main Dialog
--------------------------------------
MakeDialog
{
	-- Name the modal dialog
	name = "pausemenu",
	Bitmap
	{
		name = "dialogshadow",
		image = "backgrounds/dialogs/backgroundalpha",
	},

	Bitmap
	{
		image = "backgrounds/popups/popuppause",
		x = kCenter,
		y = kCenter,

		SetStyle(ButtonStyle),
		btnRetryLevel,
		btnMetamap,
		btnOptions,
		btnMainMenu,
		--btnHelp,
		btnResume,
		btnQuit
	},
}