dofile ('Data/Scripts/Hint/HintComposition.lua')
dofile('Data/Scripts/Common/Hint/HintBase.lua')
-- dofile('Data/Scripts/Common/Hint/HintSimpleBase.lua')

class 'Hint' (HintBase)

local SCALE_COEF = 200
local ANGLE_COEF = 2.5

function Hint:__init(playfield)
	HintBase.__init(self, playfield)

	self.show_bbt_on_unvisited_zoom = false
end

function Hint:hint()
	local panel_area_take_ringing_phone_obj
	local panel_bttn_phone
	if current_scene and current_scene:getPanel() and current_scene:getPanel():getControlsPanel() then
		panel_area_take_ringing_phone_obj 	= current_scene:getPanel():getControlsPanel():getEntityNamed('area_take_ringing_phone')
		panel_bttn_phone 					= current_scene:getPanel():getControlsPanel():getEntityNamed('bttn_phone')
	end
	
	if panel_area_take_ringing_phone_obj and panel_area_take_ringing_phone_obj:isVisible() and panel_area_take_ringing_phone_obj:isRespondable() then
		local hint_animation = self:playHintAnimation(panel_area_take_ringing_phone_obj)
		hint_animation:attachTo(current_scene:getPanel():getControlsPanel():getMainEntity())
	    hint_animation:setOrder(current_scene:getPanel():getControlsPanel():getMaxOrder())
	    
	    self:setLastHintedObject(panel_area_take_ringing_phone_obj)
	    return self:returnHintResult(HintResult.KEEP, panel_area_take_ringing_phone_obj)
	elseif (self.playfield:hasNotebookHint()) then
		local hint_animation = self:playHintAnimation(panel_bttn_phone)
		hint_animation:attachTo(current_scene:getPanel():getControlsPanel():getMainEntity())
	    hint_animation:setOrder(current_scene:getPanel():getControlsPanel():getMaxOrder())
	    
	    self:setLastHintedObject(panel_bttn_phone)
	    return self:returnHintResult(HintResult.KEEP, panel_bttn_phone)
	else
		return HintBase.hint(self)
	end
end

----------------------------------------------------------------------------------
function Hint:createLinkZonePointer(target_object, cursor_name, angle)
	if not self.arrow then
		self.arrow = CreateSpriteEntity('Data/Textures/Screens/Tutorial/TutorialArrow.png')
	end
	
	local y_offset = cursor_name == 'CursorDown' and -100 or 0
	self.arrow:setName('arrow_to_'..target_object:getName())
	self.arrow:setColor(1, 1, 1, 1)
	self.arrow:setRespondable(false)
	self.arrow:attachTo(self.playfield:getMainEntity())
	self.arrow:setOrder(self.playfield:getMaxOrder())
	self.arrow:setHotSpot(185, 39)
	self.arrow:setScrXY(target_object:getScrX(), target_object:getScrY() + y_offset)
	self.arrow:setRotationDeg(angle)	
	self.arrow:setVisible(true)
end

function Hint:playHintAnimation( targetObject )
	if self:getAnimationDisabled() then
	  return
	end
	
	local hintPos = Vector2f( 981, 727 )
	local hintScrPos = self.playfield:getMainEntity():localToScreen( hintPos )	
	local targetObjPos = targetObject:getScrPosition()
	local pos = hintScrPos - targetObjPos
	local distance = math.sqrt( pos.x ^ 2 + pos.y ^ 2 ) 
	local hintScale = distance / ( WSCR_W - SCALE_COEF )
	local hintAngle = math.atan2( pos.y, pos.x ) + math.rad( ANGLE_COEF / hintScale )

	local hintAnimation = createCompositionHint(
		targetObjPos.x, targetObjPos.y, hintScrPos, hintScale, hintAngle )

	Helpers.attachInPlace( hintAnimation,self. playfield:getMainEntity() )
	hintAnimation:setOrder( self.playfield:getMaxOrder() )
	hintAnimation:setVisible( true )
	hintAnimation:setRespondable( false )
	hintAnimation:play()

	self.playfield:getTimer():add(
		function ()
			hintAnimation:destroy()
		end,
		hintAnimation:getDuration() )

	return hintAnimation
end