require "StandardMouseButton"
require "CDialog"

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

function MainMenuDialog:Create(  )
	
	-- The main screen container
	local instance = root.dialogs[ self.name ];
	instance:SetPosition( 139, 99 )
	CDialog:Attach( instance )
	
	-- get the buttons
	local continueButton = instance.continueButton
	local switchProfileButton = instance.switchProfileButton
	local optionsButton = instance.optionsButton
	local highScoresButton = instance.highScoresButton	
	local helpbutton = instance.helpbutton
	local creditsbutton = instance.creditsbutton
	local quitButton = instance.quitButton
	
	
	-- The main init function
	function instance:Init( )
	
		-- init all button functionality
		StandardMouseButton( continueButton );
		continueButton:Init( )	
		StandardMouseButton( switchProfileButton );
		switchProfileButton:Init( )	
		StandardMouseButton( optionsButton );
		optionsButton:Init( )	
		StandardMouseButton( highScoresButton );
		highScoresButton:Init( )	
		StandardMouseButton( quitButton );
		quitButton:Init( )	

		StandardMouseButton( helpbutton )
		helpbutton:Init( )
		StandardMouseButton( creditsbutton )
		creditsbutton:Init( )		
	end
	
	-- continue button just closes the menu
	function continueButton:Init( )
		function continueButton:Pressed( )
			instance:CloseAndSave( )
		end
	end
	
	-- switchProfileButton brings up the profile swither dialog..?
	function switchProfileButton:Init( )
		function switchProfileButton:Pressed( )
			instance:ScreenEvent( "Switch Profile", "MainMenuDialog" )
		end
	end

	-- optionsButton brings up the options dialog
	function optionsButton:Init( )
		function optionsButton:Pressed( )
			instance:ScreenEvent( "Options", "MainMenuDialog" )
		end
	end
	
	-- highScoresButton shows the high scores dialog
	function highScoresButton:Init( )
		function highScoresButton:Pressed( )
			instance:ScreenEvent( "High Scores", "MainMenuDialog" )
		end
	end
	
	function helpbutton:Init( )
		function helpbutton:Pressed( )
			instance:ScreenEvent( "Help", "MainMenuDialog" )
		end
	end

	function creditsbutton:Init( )
		function creditsbutton:Pressed( )
			instance:ScreenEvent( "Credits", "MainMenuDialog" )
		end
	end
	-- quitButton closes the main menu and exits the game
	function quitButton:Init( )
		function quitButton:Pressed( )
			instance:ScreenEvent( "Confirm Quit", "MainMenuDialog" )
		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

MainMenuDialog:Create( )
