
.namespace InventorySlot

FLAG_MOUSER_PRESSED = 1
FLAG_MOUSEL_PRESSED = 2

function OnEnable()
	g_GameVariables = GameVariables
	g_Conditions = Conditions
	g_FlagsFunctions = FlagsFunctions
end


function OnWbpMouseLDown(x,y,buttonPressed)
	OPLog.Log("click sur "..self.Name)
	--local res =ObjectManager.PickObject(self.Name)
	
	Cursor.SetObjectDragged(InventoryManager.GetCurrentObject())
	--sans doute à faire d'une maniére un peu plus propre
	if res then
		self.Enabled = false
	end
end

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


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


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


--[[function Take()
	if self.PrivateTake ~= nil then
		self.PrivateTake()
	else
		OPLog.Log( "L'objet "..self.Name.." se fait cliquer dessus" )
		Cursor.SetObjectDragged( self )
		InventoryBag.Active()
	end
end]]


function CanClickOn()
	local res = self.Flags_Visible and IsEqualVariables("CurrentGamePhase","SearchSite")
	res = res and self.Inactive ~= true
	
	if self.PrivateCanClickOn ~= nil then
		res = res and self.PrivateCanClickOn()
	end
	
	return res
end

function OnDisable()

end

--attention c'est appelé à chaque frame ?
function SetCursor()
	if self.CanClickOn() then
		OPUnitFactory.GetUnit("Cursor","Cursor").ChangeCursor(CURSOR_OBJECT)
		return true
	end
	
	return false
end
