fix: tooltip
This commit is contained in:
@@ -319,6 +319,59 @@ function DB:GetCharacterMailbox(fullName)
|
|||||||
return char and char.mailbox or {}
|
return char and char.mailbox or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Find an item ID and link by name in any character's data
|
||||||
|
function DB:FindItemByName(name)
|
||||||
|
if not name or name == "" or not Guda_DB or not Guda_DB.characters then return nil, nil end
|
||||||
|
|
||||||
|
for fullName, char in pairs(Guda_DB.characters) do
|
||||||
|
-- Check bags
|
||||||
|
if char.bags then
|
||||||
|
for bagID, bagData in pairs(char.bags) do
|
||||||
|
if type(bagData) == "table" and bagData.slots then
|
||||||
|
for slotID, item in pairs(bagData.slots) do
|
||||||
|
if item and item.name == name and item.link then
|
||||||
|
local itemID = addon.Modules.Utils:ExtractItemID(item.link)
|
||||||
|
if itemID then return itemID, item.link end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- Check bank
|
||||||
|
if char.bank then
|
||||||
|
for bagID, bagData in pairs(char.bank) do
|
||||||
|
if type(bagData) == "table" and bagData.slots then
|
||||||
|
for slotID, item in pairs(bagData.slots) do
|
||||||
|
if item and item.name == name and item.link then
|
||||||
|
local itemID = addon.Modules.Utils:ExtractItemID(item.link)
|
||||||
|
if itemID then return itemID, item.link end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- Check equipped
|
||||||
|
if char.equipped then
|
||||||
|
for slot, item in pairs(char.equipped) do
|
||||||
|
if item and item.name == name and item.link then
|
||||||
|
local itemID = addon.Modules.Utils:ExtractItemID(item.link)
|
||||||
|
if itemID then return itemID, item.link end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- Check mailbox
|
||||||
|
if char.mailbox then
|
||||||
|
for _, mail in ipairs(char.mailbox) do
|
||||||
|
if mail.item and mail.item.name == name and mail.item.link then
|
||||||
|
local itemID = addon.Modules.Utils:ExtractItemID(mail.item.link)
|
||||||
|
if itemID then return itemID, mail.item.link end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil, nil
|
||||||
|
end
|
||||||
|
|
||||||
-- Get character's equipped items
|
-- Get character's equipped items
|
||||||
function DB:GetCharacterEquipped(fullName)
|
function DB:GetCharacterEquipped(fullName)
|
||||||
local char = Guda_DB.characters[fullName]
|
local char = Guda_DB.characters[fullName]
|
||||||
|
|||||||
+10
-1
@@ -7,7 +7,10 @@ addon.Modules.Tooltip = Tooltip
|
|||||||
-- Helper function to get item ID from link (Lua 5.0 compatible)
|
-- Helper function to get item ID from link (Lua 5.0 compatible)
|
||||||
local function GetItemIDFromLink(link)
|
local function GetItemIDFromLink(link)
|
||||||
if not link then return nil end
|
if not link then return nil end
|
||||||
local _, _, itemID = strfind(link, "item:(%d+):?")
|
if type(link) == "number" then return link end
|
||||||
|
|
||||||
|
-- Try to find itemID in a standard link or a raw item:ID string
|
||||||
|
local _, _, itemID = string.find(link, "item:(%d+)")
|
||||||
return itemID and tonumber(itemID) or nil
|
return itemID and tonumber(itemID) or nil
|
||||||
end
|
end
|
||||||
local function CountCurrentCharacterItems(itemID)
|
local function CountCurrentCharacterItems(itemID)
|
||||||
@@ -277,6 +280,12 @@ function Tooltip:AddInventoryInfo(tooltip, link)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Guard against double-adding for the same item on the same tooltip
|
||||||
|
if tooltip.GudaInventoryAdded == itemID then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
tooltip.GudaInventoryAdded = itemID
|
||||||
|
|
||||||
local totalBags = 0
|
local totalBags = 0
|
||||||
local totalBank = 0
|
local totalBank = 0
|
||||||
local totalMail = 0
|
local totalMail = 0
|
||||||
|
|||||||
+8
-3
@@ -103,15 +103,20 @@ scanTooltip:SetOwner(WorldFrame, "ANCHOR_NONE")
|
|||||||
function Utils:GetInboxItemLink(index, itemIndex)
|
function Utils:GetInboxItemLink(index, itemIndex)
|
||||||
-- Try global function first (if it exists on this server/version)
|
-- Try global function first (if it exists on this server/version)
|
||||||
if GetInboxItemLink then
|
if GetInboxItemLink then
|
||||||
local link = GetInboxItemLink(index)
|
-- Turtle WoW might support (index, itemIndex) for multiple attachments
|
||||||
|
local link = GetInboxItemLink(index, itemIndex or 1)
|
||||||
|
if link then return link end
|
||||||
|
|
||||||
|
-- Fallback to single argument if that failed
|
||||||
|
link = GetInboxItemLink(index)
|
||||||
if link then return link end
|
if link then return link end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- In 1.12.1, GameTooltip:GetHyperlink() does not exist.
|
-- In 1.12.1, GameTooltip:GetHyperlink() does not exist.
|
||||||
-- Let's try to use GetItemInfo(name) as the primary way.
|
-- Let's try to use GetItemInfo(name) as the primary way.
|
||||||
local name = GetInboxItem(index, itemIndex)
|
local name, texture, count, quality = GetInboxItem(index, itemIndex or 1)
|
||||||
if name then
|
if name then
|
||||||
local _, link = GetItemInfo(name)
|
local itemName, link = GetItemInfo(name)
|
||||||
if link then
|
if link then
|
||||||
return link
|
return link
|
||||||
end
|
end
|
||||||
|
|||||||
+30
-28
@@ -36,11 +36,32 @@ function MailboxScanner:ScanMailItemRows(index)
|
|||||||
local rows = {}
|
local rows = {}
|
||||||
|
|
||||||
if hasItem then
|
if hasItem then
|
||||||
local itemIndex = 1
|
-- Turtle WoW supports up to 12 attachments per mail
|
||||||
-- GetInboxItem(index, itemIndex) returns: name, texture, count, quality, canUse
|
for itemIndex = 1, 12 do
|
||||||
local name, texture, count, quality, canUse = GetInboxItem(index, itemIndex)
|
-- GetInboxItem(index, itemIndex) returns: name, texture, count, quality, canUse
|
||||||
if name then
|
local name, texture, count, quality, canUse = GetInboxItem(index, itemIndex)
|
||||||
|
if not name then break end
|
||||||
|
|
||||||
local itemLink = addon.Modules.Utils:GetInboxItemLink(index, itemIndex)
|
local itemLink = addon.Modules.Utils:GetInboxItemLink(index, itemIndex)
|
||||||
|
local itemID = itemLink and addon.Modules.Utils:ExtractItemID(itemLink)
|
||||||
|
|
||||||
|
-- Fallback 1: If link/itemID is missing, try GetItemInfo(name) which might be cached now
|
||||||
|
if not itemID or not itemLink then
|
||||||
|
local _, link = GetItemInfo(name)
|
||||||
|
if link then
|
||||||
|
itemLink = link
|
||||||
|
itemID = addon.Modules.Utils:ExtractItemID(link)
|
||||||
|
addon:Debug("Recovered link from GetItemInfo for %s", name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Fallback 2: If still missing, try to recover from existing database (any character)
|
||||||
|
if not itemID or not itemLink then
|
||||||
|
itemID, itemLink = addon.Modules.DB:FindItemByName(name)
|
||||||
|
if itemID then
|
||||||
|
addon:Debug("Recovered link from DB for %s", name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local itemData = {
|
local itemData = {
|
||||||
link = itemLink,
|
link = itemLink,
|
||||||
@@ -48,34 +69,15 @@ function MailboxScanner:ScanMailItemRows(index)
|
|||||||
count = count or 1,
|
count = count or 1,
|
||||||
quality = quality or 0,
|
quality = quality or 0,
|
||||||
name = name,
|
name = name,
|
||||||
itemID = addon.Modules.Utils:ExtractItemID(itemLink),
|
itemID = itemID,
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Fallback: If link/itemID is missing, try to recover from existing database
|
-- Ensure we have a link if we have an itemID
|
||||||
if not itemData.itemID or not itemData.link then
|
if itemData.itemID and not itemData.link then
|
||||||
local existingMailbox = addon.Modules.DB:GetCharacterMailbox(addon.Modules.DB:GetPlayerFullName())
|
itemData.link = "item:" .. itemData.itemID .. ":0:0:0"
|
||||||
for _, oldMail in ipairs(existingMailbox) do
|
|
||||||
-- Match by sender, subject and item name
|
|
||||||
if oldMail.sender == sender and oldMail.subject == subject and oldMail.item and oldMail.item.name == name then
|
|
||||||
if not itemData.link and oldMail.item.link then
|
|
||||||
itemData.link = oldMail.item.link
|
|
||||||
addon:Debug("Recovered link from database for %s", name)
|
|
||||||
end
|
|
||||||
if not itemData.itemID and oldMail.item.itemID then
|
|
||||||
itemData.itemID = oldMail.item.itemID
|
|
||||||
addon:Debug("Recovered itemID from database for %s", name)
|
|
||||||
end
|
|
||||||
if itemData.link and itemData.itemID then break end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- If we still don't have itemID but have a link (or vice versa), fix it
|
-- If we have a link, try to get more detailed info from cache
|
||||||
if itemData.link and not itemData.itemID then
|
|
||||||
itemData.itemID = addon.Modules.Utils:ExtractItemID(itemData.link)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- If we have a link, try to get more detailed info
|
|
||||||
if itemData.link then
|
if itemData.link then
|
||||||
local itemName, link, itemQuality, iLevel, itemCategory, itemType, itemStackCount, itemSubType, itemTexture, itemEquipLoc, itemSellPrice = addon.Modules.Utils:GetItemInfo(itemData.link)
|
local itemName, link, itemQuality, iLevel, itemCategory, itemType, itemStackCount, itemSubType, itemTexture, itemEquipLoc, itemSellPrice = addon.Modules.Utils:GetItemInfo(itemData.link)
|
||||||
if itemName then
|
if itemName then
|
||||||
|
|||||||
+14
-1
@@ -1004,6 +1004,7 @@ function Guda_ItemButton_OnEnter(self)
|
|||||||
|
|
||||||
-- Add mailbox metadata if available
|
-- Add mailbox metadata if available
|
||||||
local mailData = self.mailData
|
local mailData = self.mailData
|
||||||
|
|
||||||
if mailData then
|
if mailData then
|
||||||
-- If we already added a line (for money/generic), or SetHyperlink/SetInboxItem added lines,
|
-- If we already added a line (for money/generic), or SetHyperlink/SetInboxItem added lines,
|
||||||
-- we might want a separator if we're adding sender info.
|
-- we might want a separator if we're adding sender info.
|
||||||
@@ -1028,6 +1029,17 @@ function Guda_ItemButton_OnEnter(self)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Add Inventory counts for mailbox items at the very bottom
|
||||||
|
if addon.Modules.Tooltip and addon.Modules.Tooltip.AddInventoryInfo then
|
||||||
|
local link = self.itemData and (self.itemData.link or (self.itemData.itemID and ("item:" .. self.itemData.itemID .. ":0:0:0")))
|
||||||
|
if not link and self.mailIndex and isMailboxOpen then
|
||||||
|
link = addon.Modules.Utils:GetInboxItemLink(self.mailIndex, self.mailItemIndex or 1)
|
||||||
|
end
|
||||||
|
if link then
|
||||||
|
addon.Modules.Tooltip:AddInventoryInfo(GameTooltip, link)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
GameTooltip:Show()
|
GameTooltip:Show()
|
||||||
return
|
return
|
||||||
elseif self.otherChar or self.isReadOnly then
|
elseif self.otherChar or self.isReadOnly then
|
||||||
@@ -1098,8 +1110,9 @@ end
|
|||||||
-- OnLeave handler
|
-- OnLeave handler
|
||||||
function Guda_ItemButton_OnLeave(self)
|
function Guda_ItemButton_OnLeave(self)
|
||||||
-- Clear any viewed character hint on the tooltip when leaving
|
-- Clear any viewed character hint on the tooltip when leaving
|
||||||
if GameTooltip and GameTooltip.GudaViewedCharacter then
|
if GameTooltip then
|
||||||
GameTooltip.GudaViewedCharacter = nil
|
GameTooltip.GudaViewedCharacter = nil
|
||||||
|
GameTooltip.GudaInventoryAdded = nil
|
||||||
end
|
end
|
||||||
GameTooltip:Hide()
|
GameTooltip:Hide()
|
||||||
ResetCursor()
|
ResetCursor()
|
||||||
|
|||||||
Reference in New Issue
Block a user