require "StandardMouseButton"
require "CDialog"

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

function HelpDialog:Create(  )
	
	-- The main screen container
	local instance = root.dialogs[ self.name ];
	instance:SetPosition( 139, 99 )
	CDialog:Attach( instance )
	
	-- get the buttons
	local prevButton = instance.prevButton
	local nextButton = instance.nextButton
	local quitButton = instance.quitButton
	
	local frameNum = 0
	
	
	-- The main init function
	function instance:Init( )
		instance.helpFrames:SetFrame( frameNum );
	
		-- init all button functionality
		StandardMouseButton( prevButton );
		prevButton:Init( )
		StandardMouseButton( nextButton );
		nextButton:Init( )
		StandardMouseButton( quitButton );
		quitButton:Init( )	
	
		self:UpdateButtonState()	
	end
	
	function instance:OnUpdate( )
	--log( "update "..tostring( instance.inGame ) )
		if( instance.inGame ~= nil and instance.inGame == true ) then
			--log( "ingame" )
			instance:SetPosition( 208, 99 )	
		end
		
		self:OnUpdateDialog()
	end
	
	-- lua is being a bitch and wouldnt allow me to reference frameNum properly like self.frameNume so I had to do it the bad way...
	function instance:UpdateButtonState()
		self.prevButton:SetVisible( (frameNum > 0) )
		self.prevButton:SetInputEnabled( (frameNum > 0) )
		
		self.nextButton:SetVisible( (frameNum < 7) )
		self.nextButton:SetInputEnabled( (frameNum < 7) )
	end
	
	-- prevButton brings up the profile swither dialog..?
	function prevButton:Init( )
		function prevButton:Pressed( )
			if ( frameNum > 0 ) then
				frameNum = frameNum - 1
				instance.helpFrames:SetFrame( frameNum );
			end		
			
			instance:UpdateButtonState()
		end
	end

	-- nextButton brings up the options dialog
	function nextButton:Init( )
		function nextButton:Pressed( )
			if ( frameNum < 7 ) then
				frameNum = frameNum + 1
				instance.helpFrames:SetFrame( frameNum );
			end
			
			instance:UpdateButtonState()
		end
	end
	
	-- continue button just closes the menu
	function quitButton:Init( )
		function quitButton:Pressed( )
			instance:CloseAndSave( )
		end
	end
end

HelpDialog:Create( )
