--[[ script de description de la classe AreaClic --]]

.namespace AreaClick

OPLua.Include("framework/inc/Cursor_datas.lua")



function OnEnable()
	self.GameVariables = GameVariables
	self.Conditions = Conditions
	self.FlagsFunctions = FlagsFunctions
	self.CurrentManager = GetCurrentManager()
end


function OnWbpMouseLDown()
	if self.CanClickOn() then
		self.AddFlag(AREA_CLICKED)
		
		if self.CurrentManager.OnAreaClick ~= nil then
			self.CurrentManager.OnAreaClick( self.Name )
		end
		
		if self.CurrentManager.OnUpdate ~= nil then
			self.CurrentManager.OnUpdate()
		end
		
		return true
	end
end


function CompareFlag( p_flag )
	return self.FlagsFunctions.CompareFlag( p_flag, nil, self.Name )
end


function AddFlag( p_flag )
	self.FlagsFunctions.AddFlag( p_flag, nil, self.Name )
end


function SubFlag( p_flag )
	self.FlagsFunctions.SubFlag( p_flag, nil, self.Name )
end


function OnUpdateAll()
	if self.CompareFlag(AREA_RESOLVED) then
		self.Flags_Visible = false
	end
	
	if self.CompareFlag(AREA_CLICKED) then
		self.Flags_Visible = false
	end
end


function SetCursor()
	if self.CanClickOn() then
		OPUnitFactory.GetUnit("Cursor","Cursor").ChangeCursor(CURSOR_AREA_HOTSPOT)
		return true
	end	
	return false
end


function CanClickOn()
	local res = self.Flags_Visible
	
	if self.PrivateCanClickOn ~= nil then
		res = res and self.PrivateCanClickOn()
	end	
	
	return res
end






