Skip to content

Commit

Permalink
Fixed a bug where showing all empty slots would result in slots being…
Browse files Browse the repository at this point in the history
… out of order at times.
  • Loading branch information
Cidan committed Sep 4, 2024
1 parent 977a8ed commit bbd91ff
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions data/items.lua
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,8 @@ function items:LoadItems(ctx, kind, dataCache, equipmentCache, callback)
currentItem.itemInfo.category = self:GetCategory(ctx, currentItem)
search:UpdateCategoryIndex(currentItem, oldCategory)
end

slotInfo:SortEmptySlots()
--end, function(ectx)
for _, addedItem in pairs(slotInfo.addedItems) do
for _, removedItem in pairs(slotInfo.removedItems) do
Expand Down
14 changes: 14 additions & 0 deletions data/slots.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ local stacks = addon:GetModule('Stacks')
---@field addedItems table<string, ItemData> A list of items that were added since the last refresh.
---@field removedItems table<string, ItemData> A list of items that were removed since the last refresh.
---@field updatedItems table<string, ItemData> A list of items that were updated since the last refresh.
---@field emptySlotsSorted ItemData[] A sorted list of empty slots by bag and then slot.
---@field stacks Stack A stack object to manage item stacks.
local SlotInfo = {}

Expand All @@ -45,6 +46,7 @@ function items:NewSlotInfo()
addedItems = {},
removedItems = {},
updatedItems = {},
emptySlotsSorted = {},
deferDelete = false,
stacks = stacks:Create()
}, {__index = SlotInfo})
Expand Down Expand Up @@ -90,9 +92,19 @@ function SlotInfo:StoreIfEmptySlot(name, item)
self.emptySlotByBagAndSlot[item.bagid] = self.emptySlotByBagAndSlot[item.bagid] or {}
self.emptySlotByBagAndSlot[item.bagid][item.slotid] = item
self.freeSlotKeys[name] = item.slotkey
table.insert(self.emptySlotsSorted, item)
end
end

function SlotInfo:SortEmptySlots()
table.sort(self.emptySlotsSorted, function(a, b)
if a.bagid == b.bagid then
return a.slotid < b.slotid
end
return a.bagid < b.bagid
end)
end

---@param bagid number
---@param slotid number
---@return ItemData
Expand Down Expand Up @@ -132,6 +144,7 @@ function SlotInfo:Update(ctx, newItems)
self.updatedItems = {}
self.emptySlotByBagAndSlot = {}
self.dirtyItems = {}
self.emptySlotsSorted = {}
self.deferDelete = false
end

Expand All @@ -147,6 +160,7 @@ function SlotInfo:Wipe()
self.addedItems = {}
self.removedItems = {}
self.updatedItems = {}
self.emptySlotsSorted = {}
self.deferDelete = false
self.stacks:Clear()
end
10 changes: 4 additions & 6 deletions views/gridview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,10 @@ local function GridView(view, ctx, bag, slotInfo, callback)
if database:GetShowAllFreeSpace(bag.kind) then
freeSlotsSection:SetMaxCellWidth(sizeInfo.itemsPerRow * sizeInfo.columnCount)
freeSlotsSection:WipeOnlyContents()
for bagid, data in pairs(slotInfo.emptySlotByBagAndSlot) do
for slotid, item in pairs(data) do
local itemButton = view:GetOrCreateItemButton(ctx, item.slotkey)
itemButton:SetFreeSlots(ctx, bagid, slotid, 1, true)
freeSlotsSection:AddCell(item.slotkey, itemButton)
end
for _, item in ipairs(slotInfo.emptySlotsSorted) do
local itemButton = view:GetOrCreateItemButton(ctx, item.slotkey)
itemButton:SetFreeSlots(ctx, item.bagid, item.slotid, 1, true)
freeSlotsSection:AddCell(item.slotkey, itemButton)
end
freeSlotsSection:Draw(bag.kind, database:GetBagView(bag.kind), true, true)
else
Expand Down

0 comments on commit bbd91ff

Please sign in to comment.