diff --git a/Core/ItemDetection.lua b/Core/ItemDetection.lua index d42fb0e..4d90cee 100644 --- a/Core/ItemDetection.lua +++ b/Core/ItemDetection.lua @@ -45,22 +45,13 @@ end --===================================================== -- Tooltip Scanning Helpers +-- Uses shared tooltip from Utils module --===================================================== --- Get or create the scanning tooltip -local scanTooltip = nil -local function GetScanTooltip() - if not scanTooltip then - scanTooltip = CreateFrame("GameTooltip", "GudaItemDetectionTooltip", nil, "GameTooltipTemplate") - scanTooltip:SetOwner(WorldFrame, "ANCHOR_NONE") - end - return scanTooltip -end - -- Scan tooltip and return all text lines local function ScanTooltipLines(bagID, slotID, itemLink) - local tooltip = GetScanTooltip() - local tooltipName = "GudaItemDetectionTooltip" + -- Use shared tooltip from Utils module + local tooltip, tooltipName = addon.Modules.Utils:GetScanTooltip() -- Ensure tooltip owner is set before each scan tooltip:SetOwner(WorldFrame, "ANCHOR_NONE") diff --git a/Core/Utils.lua b/Core/Utils.lua index 0fc3b52..522f4ff 100644 --- a/Core/Utils.lua +++ b/Core/Utils.lua @@ -415,9 +415,16 @@ function Utils:GetItemInfo(itemLink) return nil end --- Create a hidden tooltip for scanning -local scanTooltip = CreateFrame("GameTooltip", "GudaBagScanTooltip", nil, "GameTooltipTemplate") +-- Create a single shared tooltip for all scanning operations +-- This tooltip is used by: Utils, ItemDetection, SortEngine +local scanTooltip = CreateFrame("GameTooltip", "GudaScanTooltip", nil, "GameTooltipTemplate") scanTooltip:SetOwner(WorldFrame, "ANCHOR_NONE") +local SCAN_TOOLTIP_NAME = "GudaScanTooltip" + +-- Public getter for the shared scan tooltip (used by ItemDetection, SortEngine) +function Utils:GetScanTooltip() + return scanTooltip, SCAN_TOOLTIP_NAME +end -- Get item link from mailbox attachment (WoW 1.12.1 workaround) function Utils:GetInboxItemLink(index, itemIndex) @@ -627,7 +634,7 @@ function Utils:HasSpecialTooltipText(bagID, slotID, itemLink) -- Scan tooltip lines for yellow or green text for i = 2, numLines do -- Start from line 2 (skip item name on line 1) - local leftLine = getglobal("GudaBagScanTooltipTextLeft" .. i) + local leftLine = getglobal("GudaScanTooltipTextLeft" .. i) if leftLine and leftLine:IsShown() then local text = leftLine:GetText() local r, g, b = leftLine:GetTextColor() @@ -674,7 +681,7 @@ function Utils:HasSpecialTooltipText(bagID, slotID, itemLink) end -- Also check right side of tooltip - local rightLine = getglobal("GudaBagScanTooltipTextRight" .. i) + local rightLine = getglobal("GudaScanTooltipTextRight" .. i) if rightLine and rightLine:IsShown() then local text = rightLine:GetText() local r, g, b = rightLine:GetTextColor() @@ -799,11 +806,11 @@ function Utils:IsQuestItem(bagID, slotID, itemData, isOtherChar, isBank) local tooltip = GetScanTooltip() tooltip:ClearLines() tooltip:SetBagItem(bagID, slotID) - if IsPermanentEnchantItem(tooltip, "GudaBagScanTooltip") then + if IsPermanentEnchantItem(tooltip, "GudaScanTooltip") then return false, false -- Not a quest item, it's an enchant scroll end -- Also scan for quest starter text - local _, starterDetected = ScanTooltipForQuest(tooltip, "GudaBagScanTooltip") + local _, starterDetected = ScanTooltipForQuest(tooltip, "GudaScanTooltip") return true, starterDetected end return true, false @@ -825,7 +832,7 @@ function Utils:IsQuestItem(bagID, slotID, itemData, isOtherChar, isBank) tooltip:SetBagItem(bagID, slotID) end - isQuestItem, isQuestStarter = ScanTooltipForQuest(tooltip, "GudaBagScanTooltip") + isQuestItem, isQuestStarter = ScanTooltipForQuest(tooltip, "GudaScanTooltip") -- Filter out equipment that has quest-like text but isn't categorized as Quest if isQuestItem and isEquipment and not isQuestCategory then @@ -864,7 +871,7 @@ function Utils:IsItemGrayTooltip(bagID, slotID, itemLink) tooltip:ClearLines() tooltip:SetBagItem(bagID, slotID) - local line = getglobal("GudaBagScanTooltipTextLeft1") + local line = getglobal("GudaScanTooltipTextLeft1") if line then local text = line:GetText() if text then @@ -963,7 +970,7 @@ function Utils:GetSpecializedBagType(bagID) tooltip:SetInventoryItem("player", invSlot) for i = 1, tooltip:NumLines() do - local line = getglobal("GudaBagScanTooltipTextLeft" .. i) + local line = getglobal("GudaScanTooltipTextLeft" .. i) if line then local text = line:GetText() if text then @@ -1077,7 +1084,7 @@ function Utils:GetConsumableRestoreTag(bagID, slotID, itemLink) tooltip:SetBagItem(bagID, slotID) local tag = nil for i = 1, tooltip:NumLines() do - local line = getglobal("GudaBagScanTooltipTextLeft" .. i) + local line = getglobal("GudaScanTooltipTextLeft" .. i) if line then local text = line:GetText() if text then @@ -1199,7 +1206,7 @@ function Utils:IsBindOnEquip(bagID, slotID, itemLink) -- Check tooltip lines for "Binds when equipped" for i = 1, numLines do - local line = getglobal("GudaBagScanTooltipTextLeft" .. i) + local line = getglobal("GudaScanTooltipTextLeft" .. i) if line then local text = line:GetText() if text and string.find(string.lower(text), "binds when equipped") then @@ -1258,7 +1265,7 @@ function Utils:IsUniqueItem(bagID, slotID, itemLink) -- Check tooltip lines for "Unique" (but not "Unique-Equipped") for i = 1, numLines do - local line = getglobal("GudaBagScanTooltipTextLeft" .. i) + local line = getglobal("GudaScanTooltipTextLeft" .. i) if line then local text = line:GetText() if text then diff --git a/Sorting/SortEngine.lua b/Sorting/SortEngine.lua index a109938..31e15b0 100644 --- a/Sorting/SortEngine.lua +++ b/Sorting/SortEngine.lua @@ -127,12 +127,9 @@ local GEM_PATTERNS = { --=========================================================================== -- UTILITY FUNCTIONS +-- Uses shared tooltip from Utils module --=========================================================================== --- Tooltip for scanning item properties -local scanTooltip = CreateFrame("GameTooltip", "Guda_SortScanTooltip", nil, "GameTooltipTemplate") -scanTooltip:SetOwner(WorldFrame, "ANCHOR_NONE") - -- Property cache to prevent race conditions during rapid moves local propertyCache = {} @@ -166,13 +163,15 @@ local function GetItemProperties(bagID, slotID, itemLink) end if bagID and slotID then + -- Use shared tooltip from Utils module + local scanTooltip, tooltipName = addon.Modules.Utils:GetScanTooltip() scanTooltip:ClearLines() scanTooltip:SetBagItem(bagID, slotID) - + local numLines = scanTooltip:NumLines() if numLines and numLines > 0 then for i = 1, numLines do - local line = getglobal("Guda_SortScanTooltipTextLeft" .. i) + local line = getglobal(tooltipName .. "TextLeft" .. i) if line then local text = line:GetText() if text then diff --git a/UI/ItemButton.lua b/UI/ItemButton.lua index 1501ef7..dccf978 100644 --- a/UI/ItemButton.lua +++ b/UI/ItemButton.lua @@ -5,8 +5,7 @@ local addon = Guda local buttonPool = {} local nextButtonID = 1 -local scanTooltip = CreateFrame("GameTooltip", "Guda_QuestScanTooltip", nil, "GameTooltipTemplate") -scanTooltip:SetOwner(WorldFrame, "ANCHOR_NONE") +-- Use shared tooltip from Utils module (retrieved on-demand to ensure Utils is loaded) -- Helper function to check if an item is a quest item -- Uses centralized ItemDetection module @@ -115,11 +114,15 @@ local function IsRedColor(r, g, b) 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") @@ -143,7 +146,7 @@ local function IsItemUnusable(bagID, slotID, isBank) local num = scanTooltip:NumLines() or 0 for i = 1, num do -- Scan LEFT column - local left = getglobal("Guda_QuestScanTooltipTextLeft" .. i) + local left = getglobal(tooltipName .. "TextLeft" .. i) if left and left:IsShown() then local text = left:GetText() local r, g, b = left:GetTextColor() @@ -161,7 +164,7 @@ local function IsItemUnusable(bagID, slotID, isBank) end -- Scan RIGHT column as well (required level etc can appear here on some clients) - local right = getglobal("Guda_QuestScanTooltipTextRight" .. i) + local right = getglobal(tooltipName .. "TextRight" .. i) if right and right:IsShown() then local text = right:GetText() local r, g, b = right:GetTextColor() diff --git a/UI/QuestItemBar.lua b/UI/QuestItemBar.lua index 74f429b..152982c 100644 --- a/UI/QuestItemBar.lua +++ b/UI/QuestItemBar.lua @@ -227,7 +227,7 @@ function QuestItemBar:Update() if arg1 == "LeftButton" then if CursorHasItem() then -- Try to pin item on cursor - local tooltip = GetScanTooltip() + local tooltip = addon.Modules.Utils:GetScanTooltip() tooltip:SetOwner(WorldFrame, "ANCHOR_NONE") tooltip:SetCursorItem() local link = nil diff --git a/UI/TrackedItemBar.lua b/UI/TrackedItemBar.lua index a42416c..0244f19 100644 --- a/UI/TrackedItemBar.lua +++ b/UI/TrackedItemBar.lua @@ -11,16 +11,6 @@ end local buttons = {} local trackedItemsInfo = {} --- Create a hidden tooltip for scanning if needed (though we mostly use itemID) -local scanTooltip -local function GetScanTooltip() - if not scanTooltip then - scanTooltip = CreateFrame("GameTooltip", "Guda_TrackedBarScanTooltip", nil, "GameTooltipTemplate") - scanTooltip:SetOwner(WorldFrame, "ANCHOR_NONE") - end - return scanTooltip -end - -- Check if an item is a quest item by scanning tooltip local function IsQuestItem(bagID, slotID) if addon.Modules.Utils and addon.Modules.Utils.IsQuestItem then