fix: Added isUnusable detection with caching

This commit is contained in:
Salikh Gurgenidze
2026-01-24 12:36:48 +04:00
parent 06db5f15fa
commit 52af32daaa
12 changed files with 198 additions and 258 deletions
+2 -14
View File
@@ -1849,20 +1849,8 @@ function Guda_BagFrame_MergeStacks()
ProcessNextMove()
end
-- Simple timer helper
function Guda_ScheduleTimer(delay, callback)
local frame = CreateFrame("Frame")
frame.elapsed = 0
frame.delay = delay
frame.callback = callback
frame:SetScript("OnUpdate", function()
this.elapsed = this.elapsed + arg1
if this.elapsed >= this.delay then
this:SetScript("OnUpdate", nil)
this.callback()
end
end)
end
-- NOTE: Guda_ScheduleTimer is defined in Core/Utils.lua (loaded earlier)
-- to ensure it's available for all modules that need timers
-- Hook bag container buttons to open Guda Bag View
local function HookBagContainers()
+19 -31
View File
@@ -1611,40 +1611,28 @@ function BankFrame:Initialize()
-- Update when bank is opened
addon.Modules.Events:OnBankOpen(function()
-- Delay showing custom bank to let TransmogUI finish processing
local frame = CreateFrame("Frame")
local elapsed = 0
frame:SetScript("OnUpdate", function()
elapsed = elapsed + arg1
if elapsed >= 0.2 then
frame:SetScript("OnUpdate", nil)
-- Delay showing custom bank to let TransmogUI finish processing (uses pooled timer)
Guda_ScheduleTimer(0.2, function()
-- Show current character's bank in interactive mode
currentViewChar = nil
-- Show current character's bank in interactive mode
currentViewChar = nil
-- Do not auto-hide BagFrame when opening BankFrame
-- Users may want both frames visible simultaneously; layout issues, if any,
-- should be addressed via positioning rather than auto-hiding.
-- Do not auto-hide BagFrame when opening BankFrame
-- Previously, we hid BagFrame to prevent button overlap:
-- local bagFrame = getglobal("Guda_BagFrame")
-- if bagFrame and bagFrame:IsShown() then
-- bagFrame:Hide()
-- end
-- Users may want both frames visible simultaneously; layout issues, if any,
-- should be addressed via positioning rather than auto-hiding.
-- Show and update custom bank frame
local customBankFrame = getglobal("Guda_BankFrame")
if customBankFrame then
customBankFrame:Show()
end
-- Force disable pfUI banks if enabled (pfUI uses pfBank for its bank frame)
if pfUI and pfUI.bag and pfUI.bag.left and pfUI.bag.left.Hide then
pfUI.bag.left:Hide()
end
addon.Modules.BankFrame:EnsureBagButtonsInitialized()
addon.Modules.BankFrame:Update()
-- Show and update custom bank frame
local customBankFrame = getglobal("Guda_BankFrame")
if customBankFrame then
customBankFrame:Show()
end
-- Force disable pfUI banks if enabled (pfUI uses pfBank for its bank frame)
if pfUI and pfUI.bag and pfUI.bag.left and pfUI.bag.left.Hide then
pfUI.bag.left:Hide()
end
addon.Modules.BankFrame:EnsureBagButtonsInitialized()
addon.Modules.BankFrame:Update()
end)
end, "BankFrameUI")
+9 -86
View File
@@ -110,91 +110,10 @@ local function Guda_GetUnusableColor()
return 0.9, 0.2, 0.2, 1.0
end
-- Build durability match pattern based on the client template
local durabilityPattern
if DURABILITY_TEMPLATE then
-- e.g. "Durability %d / %d" -> "Durability (.+)"
durabilityPattern = string.gsub(DURABILITY_TEMPLATE, "%%[^%s]+", "(.+)")
end
-- Tiny helper to compare font color to Blizzard's RED_FONT_COLOR
local function IsRedColor(r, g, b)
if not r or not g or not b or not RED_FONT_COLOR then return false end
local dr = math.abs(r - RED_FONT_COLOR.r)
local dg = math.abs(g - RED_FONT_COLOR.g)
local db = math.abs(b - RED_FONT_COLOR.b)
return (dr < 0.08 and dg < 0.08 and db < 0.08)
end
-- Scan tooltip for red text that is NOT a durability line
-- Uses shared tooltip from Utils module
local function IsItemUnusable(bagID, slotID, isBank)
bagID = tonumber(bagID)
slotID = tonumber(slotID)
if not bagID or not slotID then return false end
-- Get shared tooltip from Utils
local scanTooltip, tooltipName = addon.Modules.Utils:GetScanTooltip()
-- Some clients require SetOwner before every SetBagItem/SetInventoryItem to populate lines
if scanTooltip.SetOwner then
scanTooltip:SetOwner(UIParent or WorldFrame, "ANCHOR_NONE")
end
scanTooltip:ClearLines()
if isBank and bagID == -1 then
-- Bank frame item buttons map slots 1.. to inventory slots 40.. (39 + slot)
if scanTooltip.SetInventoryItem then
scanTooltip:SetInventoryItem("player", 39 + slotID)
else
-- Fallback to bag scan if API missing
scanTooltip:SetBagItem(bagID, slotID)
end
else
scanTooltip:SetBagItem(bagID, slotID)
end
if scanTooltip.Show then scanTooltip:Show() end
local num = scanTooltip:NumLines() or 0
for i = 1, num do
-- Scan LEFT column
local left = getglobal(tooltipName .. "TextLeft" .. i)
if left and left:IsShown() then
local text = left:GetText()
local r, g, b = left:GetTextColor()
-- Be tolerant with red detection in case client colors differ slightly
local isRed = IsRedColor(r, g, b) or (r and g and b and r > 0.85 and g < 0.3 and b < 0.3)
if text and isRed then
-- Ignore red durability (broken) lines
if durabilityPattern and string.find(text, durabilityPattern, 1) then
-- skip durability
else
if scanTooltip.Hide then scanTooltip:Hide() end
return true
end
end
end
-- Scan RIGHT column as well (required level etc can appear here on some clients)
local right = getglobal(tooltipName .. "TextRight" .. i)
if right and right:IsShown() then
local text = right:GetText()
local r, g, b = right:GetTextColor()
local isRed = IsRedColor(r, g, b) or (r and g and b and r > 0.85 and g < 0.3 and b < 0.3)
if text and isRed then
if durabilityPattern and string.find(text, durabilityPattern, 1) then
-- skip durability
else
if scanTooltip.Hide then scanTooltip:Hide() end
return true
end
end
end
end
return false
end
-- NOTE: IsItemUnusable detection is now handled by ItemDetection:IsUnusable()
-- which uses cached tooltip scanning to avoid duplicate scans per item.
-- The old IsItemUnusable, IsRedColor, and durabilityPattern have been removed
-- to prevent redundant tooltip scanning - all detection is now centralized.
-- Apply/remove red tint on item texture for unusable items
local function Guda_ItemButton_UpdateUsableTint(self)
@@ -225,7 +144,11 @@ local function Guda_ItemButton_UpdateUsableTint(self)
return
end
local unusable = IsItemUnusable(self.bagID, self.slotID, self.isBank)
-- Use cached detection from ItemDetection module (avoids duplicate tooltip scans)
local unusable = false
if self.itemData and addon.Modules.ItemDetection then
unusable = addon.Modules.ItemDetection:IsUnusable(self.itemData, self.bagID, self.slotID)
end
-- Ensure overlay exists (created in OnLoad, but be defensive)
if not self.unusableOverlay then
+4 -10
View File
@@ -649,16 +649,10 @@ function QuestItemBar:Initialize()
addon.Modules.Events:Register("BAG_UPDATE", function()
if bagUpdatePending then return end
bagUpdatePending = true
-- Debounce: wait 0.15 seconds before updating to batch rapid events
local debounceFrame = CreateFrame("Frame")
debounceFrame.elapsed = 0
debounceFrame:SetScript("OnUpdate", function()
this.elapsed = this.elapsed + arg1
if this.elapsed >= 0.15 then
this:SetScript("OnUpdate", nil)
bagUpdatePending = false
QuestItemBar:Update()
end
-- Debounce: wait 0.15 seconds before updating (uses pooled timer)
Guda_ScheduleTimer(0.15, function()
bagUpdatePending = false
QuestItemBar:Update()
end)
end, "QuestItemBar")
+4 -10
View File
@@ -312,16 +312,10 @@ function TrackedItemBar:Initialize()
addon.Modules.Events:Register("BAG_UPDATE", function()
if bagUpdatePending then return end
bagUpdatePending = true
-- Debounce: wait 0.15 seconds before updating to batch rapid events
local debounceFrame = CreateFrame("Frame")
debounceFrame.elapsed = 0
debounceFrame:SetScript("OnUpdate", function()
this.elapsed = this.elapsed + arg1
if this.elapsed >= 0.15 then
this:SetScript("OnUpdate", nil)
bagUpdatePending = false
TrackedItemBar:Update()
end
-- Debounce: wait 0.15 seconds before updating (uses pooled timer)
Guda_ScheduleTimer(0.15, function()
bagUpdatePending = false
TrackedItemBar:Update()
end)
end, "TrackedItemBar")