class 'HintAnimationLogicBase' (Node)
-------------------------------------------------------------------------------

function HintAnimationLogicBase:__init(controls_panel)
	Node.__init(self, controls_panel:getMainEntity(), 'HintAnimationLogicBase', 3)
	self.controls_panel	= controls_panel
	self.game_scene		= controls_panel.game_scene
	
	if self.CreateLoaderTable then
		local table_resource = self:CreateLoaderTable()
		LoadScene(self.main_entity, table_resource)
	end

	self.hintButton = self:getEntityNamed('bttn_hint')
	self.skipButton = self:getEntityNamed('bttn_skip')

	self:setupButtons()
	self:setupFillDuration()
	self:setupModeHandlers()

	self.mode = EPanelMode.NONE
	self.fill_time = 0
	self.fill_percentage = 0
	self.is_hint_fill = false
	self.is_skip_fill = false
	self.bbt_id = 0	

	local function onUpdate(entity, dt)
		self:onUpdate(dt)
	end
	self:getMainEntity().onUpdate:add(onUpdate)
end
-------------------------------------------------------------------------------

function HintAnimationLogicBase:setupButtons()
	self.hintButton.onPress:add( bind(self.onHintButtonClick, self) )
	self.skipButton.onPress:add( bind(self.onSkipButtonClick, self) )

	self.hintButton:setSendEventsToParent(true)
	self.skipButton:setSendEventsToParent(true)

	self.hintButton:setSFXTrackOnPress( getCommonSoundEntity('ButtonClick') )
	self.skipButton:setSFXTrackOnPress( getCommonSoundEntity('ButtonClick') )
end
-------------------------------------------------------------------------------

function HintAnimationLogicBase:setupFillDuration()
	if not HasGameState('HintFillPercentage') then
		SetGameState('HintFillPercentage', '0')
	end

	self.quest_hint_fill_duration =
    {
    	[EPlayMode.CASUAL]		= EPlayModeDefaultParameters[EPlayMode.CASUAL	].hintRechargeTime,
    	[EPlayMode.ADVANCED]	= EPlayModeDefaultParameters[EPlayMode.ADVANCED	].hintRechargeTime,
    	[EPlayMode.HARD]		= EPlayModeDefaultParameters[EPlayMode.HARD		].hintRechargeTime,
    	[EPlayMode.CUSTOM]		= getPlayModeParameters().hintRechargeTime
	}

	self.mg_hint_fill_duration =
    {
    	[EPlayMode.CASUAL]		= EPlayModeDefaultParameters[EPlayMode.CASUAL	].skipRechargeTime,
    	[EPlayMode.ADVANCED]	= EPlayModeDefaultParameters[EPlayMode.ADVANCED	].skipRechargeTime,
    	[EPlayMode.HARD]		= EPlayModeDefaultParameters[EPlayMode.HARD		].skipRechargeTime,
    	[EPlayMode.CUSTOM]		= getPlayModeParameters().skipRechargeTime
	}

	if isDebugMode() or isCheatMode() then
		local speed_factor = 1/5
		for i, v in pairs(self.quest_hint_fill_duration) do
			v = v*speed_factor
		end
       	for i, v in pairs(self.mg_hint_fill_duration) do
			v = v*speed_factor
		end
	end

	self.fill_duration =
	{
		[EPanelMode.NONE] 			= self.quest_hint_fill_duration,
		[EPanelMode.QUEST] 			= self.quest_hint_fill_duration,
		[EPanelMode.HIDDENOBJECT] 	= self.quest_hint_fill_duration,
		[EPanelMode.COMICS] 		= self.quest_hint_fill_duration,
		[EPanelMode.MINIGAME] 		= self.mg_hint_fill_duration,
		[EPanelMode.CLEAN] 			= self.quest_hint_fill_duration,
		[EPanelMode.HIDDENPICTURE] 	= self.quest_hint_fill_duration,
		[EPanelMode.CUTSCENE] 		= self.quest_hint_fill_duration,
	}

end
-------------------------------------------------------------------------------

function HintAnimationLogicBase:setupModeHandlers()
	self.change_mode_handlers =
	{
		[EPanelMode.NONE] 			= function() self:activateHint() end,
		[EPanelMode.QUEST] 			= function() self:activateHint() end,
		[EPanelMode.MINIGAME] 		= function() self:activateSkip() end,
		[EPanelMode.HIDDENOBJECT] 	= function() self:activateHint() end,
		[EPanelMode.COMICS] 		= function() self:activateHint() end,
		[EPanelMode.CLEAN] 			= function() self:activateHint() end,
		[EPanelMode.HIDDENPICTURE] 	= function() self:activateHint() end,
		[EPanelMode.CUTSCENE] 		= function() self:activateHint() end,
	}
end
-------------------------------------------------------------------------------

function HintAnimationLogicBase:activateHint()
	if getPlayModeParameters().hintEnabled then
		self.hintButton:show()
	else
		self.hintButton:hide()
	end
	self.skipButton:hide()

	local hint_fill_percentage = tonumber(GetGameState('HintFillPercentage'):get(0))

	self.fill_percentage = hint_fill_percentage
	self.fill_time	  = hint_fill_percentage / 100 * self:getFillDuration()
	self.is_hint_fill = (hint_fill_percentage < 100)
	self.is_skip_fill = false

	if self.is_hint_fill then
		self.hintButton:setRespondable(false)
	end

	if self.onActivateHint then
		self:onActivateHint(hint_fill_percentage)
	end
end
-------------------------------------------------------------------------------

function HintAnimationLogicBase:activateSkip()
	self.hintButton:hide()
	if getPlayModeParameters().skipEnabled then
		self.skipButton:show()
	else
		self.skipButton:hide()
	end
	self.skipButton:setRespondable(false)

	self.fill_time	  = 0
	self.fill_percentage = 0
	self.is_skip_fill = true
	self.is_hint_fill = false

	if self.onActivateSkip then
		self:onActivateSkip( 0 )
	end
end
-------------------------------------------------------------------------------

function HintAnimationLogicBase:onUpdate(dt)
	if self.is_hint_fill or self.is_skip_fill then

		if self.fill_time == 0 then
			self.fill_percentage = 0	
		end

		local fillDuration = self:getFillDuration()
		self.fill_percentage = math.min(self.fill_percentage + 100*dt/fillDuration, 100)
		self.fill_time	  = self.fill_percentage / 100 * fillDuration

		if self.is_hint_fill then
			SetGameState('HintFillPercentage', tostring(self.fill_percentage))

			if self.onHintFillUpdate then
				self:onHintFillUpdate(self.fill_percentage)
			end

			if self.fill_percentage == 100 then
				self:onHintFilled()
			end
		else -- self.is_skip_fill
			if self.onSkipFillUpdate then
				self:onSkipFillUpdate(self.fill_percentage)
			end

			if self.fill_percentage == 100 then
				self:onSkipFilled()
			end
		end

	end -- self.is_hint_fill or self.is_skip_fill

end
-------------------------------------------------------------------------------

function HintAnimationLogicBase:onHintButtonClick()
	local hinted = self.game_scene:getPlayField():getHint():hint()
	if hinted == HintResult.RESET then
		local scene_name = self.game_scene:getPlayField():getName()
		self.game_scene:getAchievmentsManager():handleEvent('on_hint_pressed', {['scene_name'] = scene_name})

		self.fill_time	  = 0
		self.fill_percentage = 100
		self.is_hint_fill = true

		self.hintButton:setRespondable( false )
		SetGameState('HintFillPercentage', '0')

		playCommonSound('Hint')
	elseif hinted == HintResult.NO_OBJECTS then
		self:showBBT()
	end
end
-------------------------------------------------------------------------------

function HintAnimationLogicBase:onSkipButtonClick()
	local level = self.game_scene:getPlayField()
	level:onDefaultSkipMiniGame()
end
-------------------------------------------------------------------------------

function HintAnimationLogicBase:fillHint()	
	SetGameState('HintFliesToPanel', 'false')
	self:onHintFilled()
end
-------------------------------------------------------------------------------

function HintAnimationLogicBase:onHintFilled()
	if getPlayModeParameters().hintEnabled then
		self.hintButton:setRespondable( true )
	end
	self.is_hint_fill = false
	SetGameState('HintFillPercentage', '100')
end
-------------------------------------------------------------------------------

function HintAnimationLogicBase:onSkipFilled()
	if getPlayModeParameters().skipEnabled then
		self.skipButton:setRespondable(true)
	end
	self.is_skip_fill = false	
end
-------------------------------------------------------------------------------

function HintAnimationLogicBase:setMode(mode)
	self.mode = mode
	self.change_mode_handlers[mode]()
end
-------------------------------------------------------------------------------

function HintAnimationLogicBase:getFillDuration()
	return self.fill_duration[self.mode][getPlayMode()]
end
-------------------------------------------------------------------------------

function HintAnimationLogicBase:onSceneStart()
end
-------------------------------------------------------------------------------

function HintAnimationLogicBase:showBBT()
	self.game_scene:getPlayField():showBlackBar('C_NOTHING_TO_DO_'..tostring(self.bbt_id % 4))
	self.bbt_id = self.bbt_id + 1
end

-------------------------------------------------------------------------------
function HintAnimationLogicBase:completeFilling()
	if self.is_hint_fill or self.is_skip_fill then
		self.fill_time = self:getFillDuration()
		self.fill_percentage = 100
	end
end

-------------------------------------------------------------------------------
-- function HintAnimationLogicBase:resetHintFillSpeed()
-- 	-- body
-- end
-------------------------------------------------------------------------------