class 'StrategyGuideHomePageBase' (Node)

function StrategyGuideHomePageBase:__init(screen, name, order)
	Node.__init(self, screen:getMainEntity(), name, order)

	self.screen	 = screen
	self.buttons = {}

	self.buttonsColor			= Colorf(1,1,1,1)
	self.buttonsHighlightColor	= Colorf(0.5,0.5,0.5,1)
	self.buttonsFont			= 'Data/Fonts/Options.fnt'
	self.buttonsWidth			= 350

	self:createContent()

	self:getMainEntity():setOpacity(0)
	self:getMainEntity():setRespondable(false)
end
-------------------------------------------------------------------------------

function StrategyGuideHomePageBase:createContent()
	if self.CreateLoaderTable then
		local resourceTable = self:CreateLoaderTable()
		LoadScene(self:getMainEntity(), resourceTable)
	end
end
-------------------------------------------------------------------------------

function StrategyGuideHomePageBase:createTopicButton(text, index, pos, scale, align)
	local button = CreateButtonEntity('')
	local title	 = button:getOverlayTextEntity()

	title:setText			( text )
	title:setOrder			( 1 )
	title:setColor			( self.buttonsColor )
	title:setFont			( self.buttonsFont ) 
	title:setTextAlignment	( align or ETextHorizontalAlignmentLeft )

	button:attachTo			( self:getMainEntity() )
	button:setName			( 'button_'..#self.buttons )  
	button:setPosition		( pos )
	button:setOrder			( 1 )
	button:setScale			( scale or 1 )
	button:setActiveRectSize( self.buttonsWidth, title:getHeight() )
	button:setSFXTrackOnPress( getCommonSoundEntity('ButtonClick') )

	button.properties = {}
	button.properties.pageIndex = index

	button.onPress:add		( bind(self.onLinkButtonPress, self) )
	button.onFocusIn:add	( bind(self.onLinkButtonFocusIn, self) )
	button.onFocusOut:add	( bind(self.onLinkButtonFocusOut, self) )

	table.insert(self.buttons, button)
	return button
end
-------------------------------------------------------------------------------

function StrategyGuideHomePageBase:placeTopicButtons()
	local count		= #self.buttons
	local position	= Vector2f(512, 200)
	local offset	= Vector2f(0, 0)
	local deltaY	= 50
	local centerSpaceWidth = 20

	for i=1, count do
		local button = self.buttons[i]
		button:setPosition(position + offset)

		if i==1 or i > (count - 3) then
			button:getOverlayTextEntity():setTextAlignment( ETextHorizontalAlignmentCenter )
		end

		if i == 1 then
			offset.x = offset.x - (self.buttonsWidth + centerSpaceWidth)/2
			offset.y = offset.y + deltaY
		elseif i >= (count - 3) then
			offset.x = 0
			offset.y = offset.y + deltaY
		else
			local dir = math.pow(-1, i)
			offset.x = offset.x + (self.buttonsWidth + centerSpaceWidth) * dir
			offset.y = offset.y + i%2 * deltaY
		end
	end
end
-------------------------------------------------------------------------------

function StrategyGuideHomePageBase:placeTopicButtonsInDemo()
	local count		= #self.buttons
	local position	= Vector2f(512, 200)
	local offset	= Vector2f(0, 50)

	for i=1, count do
		local button = self.buttons[i]
		button:setPosition(position)
		button:getOverlayTextEntity():setTextAlignment( ETextHorizontalAlignmentCenter )

		position = position + offset
	end
end
-------------------------------------------------------------------------------

function StrategyGuideHomePageBase:onLinkButtonPress(button)
	button:setColor( self.buttonsColor )
	self.screen:showPage( button.properties.pageIndex )
end
-------------------------------------------------------------------------------

function StrategyGuideHomePageBase:onLinkButtonFocusIn(button)
	button:getOverlayTextEntity():setColor( self.buttonsHighlightColor )
end
-------------------------------------------------------------------------------

function StrategyGuideHomePageBase:onLinkButtonFocusOut(button)
	button:getOverlayTextEntity():setColor( self.buttonsColor )
end
-------------------------------------------------------------------------------

function StrategyGuideHomePageBase:show(time)
	self:getMainEntity():destroyEffectors()
	local eff = self:getMainEntity():ChangeOpacity(nil, 1, time)

	eff.onFinish:add(	function()
							self:getMainEntity():setRespondable(true)
						end)
end
-------------------------------------------------------------------------------

function StrategyGuideHomePageBase:hide(time)
	self:getMainEntity():destroyEffectors()
	self:getMainEntity():setRespondable(false)
	self:getMainEntity():ChangeOpacity(nil, 0, time)
end
-------------------------------------------------------------------------------