Skip to content

Instantly share code, notes, and snippets.

@cschomburg
Created September 12, 2010 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cschomburg/576500 to your computer and use it in GitHub Desktop.
Save cschomburg/576500 to your computer and use it in GitHub Desktop.
-- Multiple item-buttons per bagSlot
-- Untested and probably inefficient
function Implementation:UpdateSlot(event, bagID, slotID)
-- Existing code here - maybe also exclusive filtering
-- Cycle through containers which should be non-exclusive
for id, container in pairs(self.contByID) do
-- Find the button for the slot in the container, if any.
-- could be faster to have a separate table with bag/slot-IDs as keys
local button
for i, btn in pairs(container.buttons) do
if(btn.bagID == bagID and btn.slotID == slotID) then
button = btn
break
end
end
-- Check if the item can go into the container
if(container.filters:Check(item)) then
if(not button) then -- Create a new button when necessary
button = self.buttonClass:New(bagID, slotID)
container:AddButton(button)
end
button:Update()
elseif(button) then -- Didn't fit into container? Remove existing button
container:RemoveButton(button)
button:Free()
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment