require "StandardMouseButton"
require "CDialog"

-- reserve constructor
GameMenuDialog = 
{
	name = "GameMenuDialog"
}

function GameMenuDialog:Create(  )
	
	-- The main screen container
	local instance = root.dialogs[ self.name ];
	instance:SetPosition( 208, 99 )
	CDialog:Attach( instance )
	
	-- get the buttons
	local continueButton = instance.continueButton
	local helpbutton = instance.helpbutton
	local creditsbutton = instance.creditsbutton
	local optionsButton = instance.optionsButton
	local quitButton = instance.quitButton
	
	-- The main init function
	function instance:Init( )

		-- init all button functionality
		StandardMouseButton( continueButton )
		continueButton:Init( )	
		StandardMouseButton( optionsButton )
		optionsButton:Init( )	
		StandardMouseButton( helpbutton )
		helpbutton:Init( )
		StandardMouseButton( creditsbutton )
		creditsbutton:Init( )
		StandardMouseButton( quitButton )
		quitButton:Init( )
	end
	
	-- continue button just closes the menu
	function continueButton:Init( )
		function continueButton:Pressed( )
			instance:CloseAndSave( )
		end
	end
	
	-- optionsButton brings up the options dialog
	function optionsButton:Init( )
		function optionsButton:Pressed( )
			instance:ScreenEvent( "Options", "GameMenuDialog" )
		end
	end
	
	function helpbutton:Init( )
		function helpbutton:Pressed( )
			instance:ScreenEvent( "Help", "GameMenuDialog" )
		end
	end

	function creditsbutton:Init( )
		function creditsbutton:Pressed( )
			instance:ScreenEvent( "Credits", "GameMenuDialog" )
		end
	end
	
	-- quitButton closes the main menu and exits the game
	function quitButton:Init( )
		function quitButton:Pressed( )
			instance:ScreenEvent( "Confirm InGame Quit", "GameMenuDialog" )
		end
	end
		
	-- Handle keyboard input for the dialog
	function instance:CharDown( i_Key )
		log( "On Key Down" .. i_Key )
	end
	
	function instance:OnUpdate( )
		self:OnUpdateDialog()
	end
end

GameMenuDialog:Create( )
