Skip to content

Commit

Permalink
Fastview Bugfix (#697)
Browse files Browse the repository at this point in the history
* Fixed a few bugs with the bank in fast view mode.
  • Loading branch information
Cidan authored Sep 13, 2024
1 parent fde068c commit 9b3b317
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 23 deletions.
16 changes: 14 additions & 2 deletions data/refresh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function refresh:StartUpdate(ctx)
local updateBank = false
local sortBackpack = false
local wipeAndRefreshAll = false
ctx:Set('wipe', false)
for _, event in pairs(self.UpdateQueue) do
if event.ctx:GetBool("wipe") then
-- Prevent full wipes from happening in combat.
Expand All @@ -106,6 +107,8 @@ function refresh:StartUpdate(ctx)
updateBank = true
elseif event.eventName == 'WIPE_AND_REFRESH_ALL' then
wipeAndRefreshAll = true
elseif event.eventName == 'BAG_UPDATE_ONLY' then
updateBackpack = true
elseif const.BANK_BAGS[event.args[1]] then
updateBank = true
elseif const.REAGENTBANK_BAGS[event.args[1]] then
Expand Down Expand Up @@ -139,7 +142,11 @@ function refresh:StartUpdate(ctx)
if addon.atWarbank and addon.Bags.Bank.bankTab < const.BANK_TAB.ACCOUNT_BANK_1 then
addon.Bags.Bank.bankTab = const.BANK_TAB.ACCOUNT_BANK_1
end
if updateBackpack then
table.insert(refresh.UpdateQueue, {eventName = 'BAG_UPDATE_ONLY', args = {const.BAG_KIND.BACKPACK}, ctx = ctx:Copy()})
end
items:RefreshBank(ctx:Copy())
return
end

if updateBackpack then
Expand Down Expand Up @@ -249,15 +256,20 @@ function refresh:OnEnable()
self:StartUpdate(ctx)
end)

events:RegisterMessage('bags/Draw/Bank/Done', function(ctx)
self.isUpdateRunning = false
if next(self.UpdateQueue) ~= nil then
self:StartUpdate(ctx)
end
end)

-- Register for when bags are done drawing.
events:RegisterMessage('bags/Draw/Backpack/Done', function(ctx)
-- If there are more updates in the queue, start the next one with a new context.
self.isUpdateRunning = false
self.backpackRedrawPending = false
if next(self.UpdateQueue) ~= nil then
self:StartUpdate(ctx)
else
ctx:Cancel()
end
end)

Expand Down
2 changes: 1 addition & 1 deletion frames/bag.lua
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ end
function bagFrame.bagProto:Draw(ctx, slotInfo, callback)
local viewList = self.views[database:GetBagView(self.kind)]
local updateView = viewList[1] == self.currentView and viewList[2] or viewList[1]
local previousView = self.currentView
local previousView = updateView == viewList[1] and viewList[2] or viewList[1]

--if self.currentView and self.currentView:GetBagView() ~= updateView:GetBagView() then
-- self.currentView:Wipe(ctx)
Expand Down
12 changes: 6 additions & 6 deletions views/bagview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ end
---@param ctx Context
---@param view View
local function WipeSections(ctx, view)
debug:StartProfile('Bag View Sections Wipe')
debug:StartProfile('Bag View Sections Wipe %d', view.kind)
for _, section in pairs(view.sections) do
async:RawBatch(ctx, 10, section:GetCellList(), function(bctx, cell)
cell:Release(bctx)
Expand All @@ -57,7 +57,7 @@ local function WipeSections(ctx, view)
end
wipe(view.sections)
wipe(view.itemsByBagAndSlot)
debug:EndProfile('Bag View Sections Wipe')
debug:EndProfile('Bag View Sections Wipe %d', view.kind)
end

---@param bagid number
Expand Down Expand Up @@ -159,10 +159,10 @@ local function BagView(view, ctx, bag, slotInfo, callback)
async:Chain(ctx, nil,
function(ectx)
if ectx:GetBool('wipe') then
debug:StartProfile('Wipe Loop')
debug:StartProfile('Wipe Loop %d', bag.kind)
view:Wipe(ectx)
WipeSections(ectx, view)
debug:EndProfile('Wipe Loop')
debug:EndProfile('Wipe Loop %d', bag.kind)
end
end,
function(ectx)
Expand Down Expand Up @@ -218,13 +218,13 @@ local function BagView(view, ctx, bag, slotInfo, callback)
view.content:Sort(function(a, b)
return sort.SortSectionsAlphabetically(view.kind, a, b)
end)
debug:StartProfile('Content Draw Stage')
debug:StartProfile('Content Draw Stage %d', bag.kind)
local w, h = view.content:Draw({
cells = view.content.cells,
maxWidthPerRow = ((37 + 4) * sizeInfo.itemsPerRow) + 16,
columns = sizeInfo.columnCount,
})
debug:EndProfile('Content Draw Stage')
debug:EndProfile('Content Draw Stage %d', bag.kind)
-- Reposition the content frame if the recent items section is empty.
if w < 160 then
w = 160
Expand Down
28 changes: 14 additions & 14 deletions views/gridview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ local debug = addon:GetModule('Debug')
---@param ctx Context
local function Wipe(view, ctx)
debug:Log("Wipe", "Grid View Wipe")
debug:StartProfile('Grid View Content Wipe')
debug:StartProfile('Grid View Content Wipe %d', view.kind)
view.content:Wipe()
debug:EndProfile('Grid View Content Wipe')
debug:EndProfile('Grid View Content Wipe %d', view.kind)
if view.freeSlot ~= nil then
view.freeSlot:Release(ctx)
view.freeSlot = nil
Expand All @@ -58,7 +58,7 @@ end
---@param ctx Context
---@param view View
local function WipeSections(ctx, view)
debug:StartProfile('Grid View Sections Wipe')
debug:StartProfile('Grid View Sections Wipe %d', view.kind)
for _, section in pairs(view.sections) do
async:RawBatch(ctx, 10, section:GetCellList(), function(bctx, cell)
cell:Release(bctx)
Expand All @@ -67,7 +67,7 @@ local function WipeSections(ctx, view)
end
wipe(view.sections)
wipe(view.itemsByBagAndSlot)
debug:EndProfile('Grid View Sections Wipe')
debug:EndProfile('Grid View Sections Wipe %d', view.kind)
end

-- ClearButton clears a button and makes it empty while preserving the slot,
Expand Down Expand Up @@ -257,14 +257,14 @@ local function GridView(view, ctx, bag, slotInfo, callback)
async:Chain(ctx, nil,
function(ectx)
if ectx:GetBool('wipe') then
debug:StartProfile('Wipe Loop')
debug:StartProfile('Wipe Loop %d', bag.kind)
view:Wipe(ectx)
WipeSections(ectx, view)
debug:EndProfile('Wipe Loop')
debug:EndProfile('Wipe Loop %d', bag.kind)
end
end,
function(ectx)
debug:StartProfile('Removed Loop')
debug:StartProfile('Removed Loop %d', bag.kind)
async:RawBatch(ectx, 15, removed, function(bctx, item)
local stackInfo = slotInfo.stacks:GetStackInfo(item.itemHash)
if not stackInfo then
Expand All @@ -279,10 +279,10 @@ local function GridView(view, ctx, bag, slotInfo, callback)
UpdateButton(bctx, view, stackInfo.rootItem)
end
end)
debug:EndProfile('Removed Loop')
debug:EndProfile('Removed Loop %d', bag.kind)
end,
function(ectx)
debug:StartProfile('Added Loop')
debug:StartProfile('Added Loop %d', bag.kind)
async:RawBatch(ectx, 15, added, function(bctx, item)
local stackInfo = slotInfo.stacks:GetStackInfo(item.itemHash)
---- Check stacking options
Expand All @@ -298,10 +298,10 @@ local function GridView(view, ctx, bag, slotInfo, callback)
ReconcileStack(bctx, view, stackInfo)
end
end)
debug:EndProfile('Added Loop')
debug:EndProfile('Added Loop %d', bag.kind)
end,
function(ectx)
debug:StartProfile('Changed Loop')
debug:StartProfile('Changed Loop %d', bag.kind)
async:RawBatch(ectx, 15, changed, function(bctx, item)
local stackInfo = slotInfo.stacks:GetStackInfo(item.itemHash)
if not stackInfo then
Expand All @@ -326,10 +326,10 @@ local function GridView(view, ctx, bag, slotInfo, callback)
end
end
end)
debug:EndProfile('Changed Loop')
debug:EndProfile('Changed Loop %d', bag.kind)
end,
function(ectx)
debug:StartProfile('Everything Else')
debug:StartProfile('Everything Else %d', bag.kind)
-- Special handling for Recent Items -- add it to the dirty sections if
-- it has no items visible.
local recentItemsSection = view:GetSection(L:G("Recent Items"))
Expand Down Expand Up @@ -460,7 +460,7 @@ local function GridView(view, ctx, bag, slotInfo, callback)
bag.frame:SetHeight(bagHeight)
UpdateViewSize(view)
view.itemCount = slotInfo.totalItems
debug:EndProfile('Everything Else')
debug:EndProfile('Everything Else %d', bag.kind)
end, callback)

end
Expand Down

0 comments on commit 9b3b317

Please sign in to comment.