fix: harden charge cache and quest bar snapshot path

This commit is contained in:
Dusk-92
2026-09-06 10:20:15 +02:00
parent 27eebd814e
commit e15eed943d
3 changed files with 60 additions and 17 deletions
+12 -2
View File
@@ -115,7 +115,16 @@ local function PrepareTooltip(bagID, slotID, itemLink)
if bagID and slotID then if bagID and slotID then
if bagID == -1 then if bagID == -1 then
if not SafeSetHyperlink(tooltip, itemLink) then return nil, nil end local ok = false
local bankOpen = addon.Modules.BankScanner
and addon.Modules.BankScanner.IsBankOpen
and addon.Modules.BankScanner:IsBankOpen()
if bankOpen and tooltip.SetInventoryItem then
ok = pcall(tooltip.SetInventoryItem, tooltip, "player", 39 + slotID)
end
if not ok then
if not SafeSetHyperlink(tooltip, itemLink) then return nil, nil end
end
else else
local ok = pcall(tooltip.SetBagItem, tooltip, bagID, slotID) local ok = pcall(tooltip.SetBagItem, tooltip, bagID, slotID)
if not ok then if not ok then
@@ -447,8 +456,9 @@ end
function ItemDetection:InvalidateCharges(bagID, slotID) function ItemDetection:InvalidateCharges(bagID, slotID)
if not bagID then if not bagID then
-- Per-slot values are live instance state, but whether an item link
-- has an explicit Charges line is stable for this UI session.
chargesCache = {} chargesCache = {}
chargeCapableLinks = {}
return return
end end
+7
View File
@@ -1784,6 +1784,13 @@ function Guda_ItemButton_UpdateCharges(button)
local chargesText = getglobal(button:GetName().."_Charges") local chargesText = getglobal(button:GetName().."_Charges")
if not chargesText then return end if not chargesText then return end
-- Saved banks / other-character views have no live item instance
-- behind the displayed slot. Never read the current player slot.
if button.isReadOnly or button.otherChar then
chargesText:Hide()
return
end
local charges = nil local charges = nil
if button.hasItem and button.itemData and addon.Modules.ItemDetection then if button.hasItem and button.itemData and addon.Modules.ItemDetection then
charges = addon.Modules.ItemDetection:GetCharges(button.itemData, button.bagID, button.slotID) charges = addon.Modules.ItemDetection:GetCharges(button.itemData, button.bagID, button.slotID)
+41 -15
View File
@@ -96,23 +96,49 @@ end
-- Scan bags for quest items (optimized: single tooltip scan per item) -- Scan bags for quest items (optimized: single tooltip scan per item)
function QuestItemBar:ScanForQuestItems() function QuestItemBar:ScanForQuestItems()
questItems = {} -- Reuse the existing table so repeated bag refreshes do not create
-- another questItems table for the Lua GC.
for i = table.getn(questItems), 1, -1 do
questItems[i] = nil
end
-- Scan backpack and 4 bags local scanner = addon.Modules.BagScanner
local bagData = scanner and scanner.GetBagData and scanner:GetBagData()
if not bagData then return end
local detection = addon.Modules.ItemDetection
-- Consume the exact snapshot already used by the bag UI. No
-- independent GetContainerNumSlots/GetContainerItemInfo pass.
for bagID = 0, 4 do for bagID = 0, 4 do
local numSlots = GetContainerNumSlots(bagID) local bag = bagData[bagID]
for slotID = 1, numSlots do if bag and bag.slots then
local texture, count = GetContainerItemInfo(bagID, slotID) local numSlots = bag.numSlots or 0
if texture then for slotID = 1, numSlots do
-- Single combined check instead of two separate tooltip scans local itemData = bag.slots[slotID]
local isQuest, isStarter, isUsable = self:CheckQuestItemUsable(bagID, slotID) if itemData then
if isQuest and isUsable and not isStarter then local isQuest, isStarter, isUsable = false, false, false
table.insert(questItems, {
bagID = bagID, if detection then
slotID = slotID, local props = detection:GetItemProperties(itemData, bagID, slotID)
texture = texture, if props then
count = count isQuest = props.isQuestItem and true or false
}) isStarter = props.isQuestStarter and true or false
isUsable = props.isQuestUsable and true or false
end
else
isQuest, isStarter, isUsable = self:CheckQuestItemUsable(bagID, slotID)
end
if isQuest and isUsable and not isStarter then
table.insert(questItems, {
bagID = bagID,
slotID = slotID,
texture = itemData.texture,
count = itemData.count or 1,
link = itemData.link,
})
end
end end
end end
end end