fix: harden charge cache and quest bar snapshot path
This commit is contained in:
@@ -115,7 +115,16 @@ local function PrepareTooltip(bagID, slotID, itemLink)
|
||||
|
||||
if bagID and slotID 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
|
||||
local ok = pcall(tooltip.SetBagItem, tooltip, bagID, slotID)
|
||||
if not ok then
|
||||
@@ -447,8 +456,9 @@ end
|
||||
|
||||
function ItemDetection:InvalidateCharges(bagID, slotID)
|
||||
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 = {}
|
||||
chargeCapableLinks = {}
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
@@ -1784,6 +1784,13 @@ function Guda_ItemButton_UpdateCharges(button)
|
||||
local chargesText = getglobal(button:GetName().."_Charges")
|
||||
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
|
||||
if button.hasItem and button.itemData and addon.Modules.ItemDetection then
|
||||
charges = addon.Modules.ItemDetection:GetCharges(button.itemData, button.bagID, button.slotID)
|
||||
|
||||
+41
-15
@@ -96,23 +96,49 @@ end
|
||||
|
||||
-- Scan bags for quest items (optimized: single tooltip scan per item)
|
||||
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
|
||||
local numSlots = GetContainerNumSlots(bagID)
|
||||
for slotID = 1, numSlots do
|
||||
local texture, count = GetContainerItemInfo(bagID, slotID)
|
||||
if texture then
|
||||
-- Single combined check instead of two separate tooltip scans
|
||||
local isQuest, isStarter, isUsable = self:CheckQuestItemUsable(bagID, slotID)
|
||||
if isQuest and isUsable and not isStarter then
|
||||
table.insert(questItems, {
|
||||
bagID = bagID,
|
||||
slotID = slotID,
|
||||
texture = texture,
|
||||
count = count
|
||||
})
|
||||
local bag = bagData[bagID]
|
||||
if bag and bag.slots then
|
||||
local numSlots = bag.numSlots or 0
|
||||
for slotID = 1, numSlots do
|
||||
local itemData = bag.slots[slotID]
|
||||
if itemData then
|
||||
local isQuest, isStarter, isUsable = false, false, false
|
||||
|
||||
if detection then
|
||||
local props = detection:GetItemProperties(itemData, bagID, slotID)
|
||||
if props then
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user