fix: refresh live item charges in bags and bank
This commit is contained in:
@@ -4213,6 +4213,24 @@ function Guda_BagFrame_ClearBagButtonHighlight()
|
||||
end
|
||||
end
|
||||
|
||||
-- Refresh only known charge-bearing items in one changed bag.
|
||||
-- Normal stacks remain on the cached negative path and incur no tooltip scan.
|
||||
function BagFrame:RefreshKnownChargeOverlays(bagID)
|
||||
local detection = addon.Modules.ItemDetection
|
||||
if not detection or not detection.IsKnownChargeItem or not Guda_ItemButton_UpdateCharges then return end
|
||||
|
||||
detection:InvalidateCharges(bagID)
|
||||
local buttons = slotToButton[bagID]
|
||||
if not buttons then return end
|
||||
|
||||
for _, button in pairs(buttons) do
|
||||
if button and button.hasItem and button:IsShown()
|
||||
and detection:IsKnownChargeItem(button.itemData) then
|
||||
Guda_ItemButton_UpdateCharges(button)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Initialize
|
||||
function BagFrame:Initialize()
|
||||
-- Hook default bag functions (with slight delay to ensure UI is loaded)
|
||||
@@ -4321,6 +4339,10 @@ function BagFrame:Initialize()
|
||||
local viewType = addon.Modules.DB:GetSetting("bagViewType") or "single"
|
||||
addon:DebugCategory("BAG_UPDATE (BagFrame): bagID=%d, viewType=%s", bagID, viewType)
|
||||
|
||||
-- A charge use can fire BAG_UPDATE without changing item link or stack count.
|
||||
-- Refresh only already-known charge overlays before the incremental diff path.
|
||||
BagFrame:RefreshKnownChargeOverlays(bagID)
|
||||
|
||||
-- Check if sorting is in progress - use full redraw with throttle
|
||||
local isSorting = addon.Modules.SortEngine and addon.Modules.SortEngine.sortingInProgress
|
||||
|
||||
|
||||
+39
-3
@@ -2123,6 +2123,32 @@ function BankFrame:ShowBlizzardBank()
|
||||
ShowUIPanel(blizzardBankFrame)
|
||||
end
|
||||
|
||||
-- Refresh charge overlays without rebuilding bank item buttons.
|
||||
function BankFrame:RefreshKnownChargeOverlays(bagID, slotID)
|
||||
local detection = addon.Modules.ItemDetection
|
||||
if not detection or not detection.IsKnownChargeItem or not Guda_ItemButton_UpdateCharges then return end
|
||||
|
||||
detection:InvalidateCharges(bagID, slotID)
|
||||
local buttons = bankSlotToButton[bagID]
|
||||
if not buttons then return end
|
||||
|
||||
if slotID then
|
||||
local button = buttons[slotID] or buttons[tonumber(slotID)]
|
||||
if button and button.hasItem and button:IsShown()
|
||||
and detection:IsKnownChargeItem(button.itemData) then
|
||||
Guda_ItemButton_UpdateCharges(button)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
for _, button in pairs(buttons) do
|
||||
if button and button.hasItem and button:IsShown()
|
||||
and detection:IsKnownChargeItem(button.itemData) then
|
||||
Guda_ItemButton_UpdateCharges(button)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Initialize
|
||||
function BankFrame:Initialize()
|
||||
self:HideBlizzardBank()
|
||||
@@ -2312,6 +2338,10 @@ function BankFrame:Initialize()
|
||||
|
||||
-- Try single-slot update if not sorting
|
||||
if not isSorting then
|
||||
-- Refresh instance-only charge data for this exact main-bank slot.
|
||||
if addon.Modules.ItemDetection and addon.Modules.ItemDetection.InvalidateCharges then
|
||||
addon.Modules.ItemDetection:InvalidateCharges(-1, arg1)
|
||||
end
|
||||
-- Invalidate bag scanner cache for fresh slot data
|
||||
addon.Modules.BankScanner:InvalidateBag(-1)
|
||||
-- Try single-slot update
|
||||
@@ -2415,6 +2445,10 @@ function BankFrame:Initialize()
|
||||
elseif event == "BAG_UPDATE" and arg1 then
|
||||
-- Check if this is a bank bag (5-10)
|
||||
if arg1 >= 5 and arg1 <= 10 then
|
||||
-- BAG_UPDATE does not expose the changed slot. Refresh only
|
||||
-- previously proven charge-bearing items in this bank bag.
|
||||
BankFrame:RefreshKnownChargeOverlays(arg1)
|
||||
|
||||
-- Debug: count items in this bank bag via raw API
|
||||
local rawItemCount = 0
|
||||
local numSlots = GetContainerNumSlots(arg1) or 0
|
||||
@@ -2453,9 +2487,11 @@ function BankFrame:Initialize()
|
||||
return
|
||||
end
|
||||
elseif event == "PLAYERBANKBAGSLOTS_CHANGED" then
|
||||
-- Bank container slot changed (bag added/removed)
|
||||
-- Clear bag scanner cache since structure changed
|
||||
-- NOTE: Don't clear ItemDetection cache - item properties don't change
|
||||
-- Bank container slot changed (bag added/removed). Slot identities may
|
||||
-- be remapped, so discard charge slot state as well.
|
||||
if addon.Modules.ItemDetection and addon.Modules.ItemDetection.InvalidateCharges then
|
||||
addon.Modules.ItemDetection:InvalidateCharges(nil)
|
||||
end
|
||||
addon.Modules.BankScanner:ClearCache()
|
||||
end
|
||||
|
||||
|
||||
+22
-13
@@ -1779,6 +1779,24 @@ end
|
||||
--=====================================================
|
||||
|
||||
-- Set item data
|
||||
function Guda_ItemButton_UpdateCharges(button)
|
||||
if not button then return end
|
||||
local chargesText = getglobal(button:GetName().."_Charges")
|
||||
if not chargesText then return end
|
||||
|
||||
local charges = nil
|
||||
if button.hasItem and button.itemData and addon.Modules.ItemDetection then
|
||||
charges = addon.Modules.ItemDetection:GetCharges(button.itemData, button.bagID, button.slotID)
|
||||
end
|
||||
|
||||
if charges and charges > 0 then
|
||||
chargesText:SetText("x" .. charges)
|
||||
chargesText:Show()
|
||||
else
|
||||
chargesText:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
function Guda_ItemButton_SetItem(self, bagID, slotID, itemData, isBank, otherCharName, matchesFilter, isReadOnly)
|
||||
-- Proactively convert to number to avoid comparisons with strings in downstream functions
|
||||
bagID = tonumber(bagID)
|
||||
@@ -2265,19 +2283,10 @@ function Guda_ItemButton_SetItem(self, bagID, slotID, itemData, isBank, otherCha
|
||||
end
|
||||
end
|
||||
|
||||
-- Show/hide charges text (e.g. "x5" for Wizard Oil)
|
||||
if chargesText then
|
||||
local charges = nil
|
||||
if itemData and addon.Modules.ItemDetection then
|
||||
charges = addon.Modules.ItemDetection:GetCharges(itemData, bagID, slotID)
|
||||
end
|
||||
if charges and charges > 0 then
|
||||
chargesText:SetText("x" .. charges)
|
||||
chargesText:Show()
|
||||
else
|
||||
chargesText:Hide()
|
||||
end
|
||||
end
|
||||
-- Show/hide charges text (e.g. "x5" for Wizard Oil).
|
||||
-- Kept as a standalone refresh so charge-only BAG_UPDATE events do not
|
||||
-- need to rebuild the complete item button.
|
||||
Guda_ItemButton_UpdateCharges(self)
|
||||
|
||||
-- Handle tracking toggle on click
|
||||
-- Note: Tracking toggle is now handled in the main OnClick script above to avoid conflicts
|
||||
|
||||
Reference in New Issue
Block a user