diff --git a/Core/Tooltip.lua b/Core/Tooltip.lua index 03b3db0..a4b33dc 100644 --- a/Core/Tooltip.lua +++ b/Core/Tooltip.lua @@ -331,65 +331,35 @@ function Tooltip:Initialize() -- Hook SetBagItem local oldSetBagItem = GameTooltip.SetBagItem - local oldSetInventoryItem = GameTooltip.SetInventoryItem - local oldSetHyperlink = GameTooltip.SetHyperlink function GameTooltip:SetBagItem(bag, slot) return WithDeferredMoney(self, function() - local bankFrame = getglobal("BankFrame") - - if bag == -1 and bankFrame and bankFrame:IsVisible() then - local invSlot = BankButtonIDToInvSlotID(slot) - if invSlot then - -- Use the inventory item method for bank main bag - local ret = oldSetInventoryItem(self, "player", invSlot) - local link = GetInventoryItemLink("player", invSlot) - if link then - Tooltip:AddInventoryInfo(self, link) - end - return ret - end - else - -- Bank is closed or readonly mode - try to get cached link - if bag == -1 or (bag >=5 and bag <=10) then - -- Get cached link from database for main bank bag - local playerName = addon.Modules.DB:GetPlayerFullName() - local bankData = addon.Modules.DB:GetCharacterBank(playerName) - if bankData and bankData[bag] and bankData[bag].slots and bankData[bag].slots[slot] then - local itemData = bankData[bag].slots[slot] - if itemData.link and string.find(itemData.link, "|H") then - -- Extract hyperlink from full colored string: |cFFFFFFFF|Hitem:...|h[Name]|h|r - -- SetHyperlink needs just the item:... part - local _, _, hyperlink = string.find(itemData.link, "|H(.+)|h") - if hyperlink then - local ret = oldSetHyperlink(self, hyperlink) - Tooltip:AddInventoryInfo(self, itemData.link) - return ret - end - end - end - -- No cached data found - return nil - else - -- Regular bags and bank bags (not main bag) - use normal SetBagItem - local ret = oldSetBagItem(self, bag, slot) - local link = GetContainerItemLink(bag, slot) - if link then - Tooltip:AddInventoryInfo(self, link) - end - return ret - end + local ret = oldSetBagItem(self, bag, slot) + local link = GetContainerItemLink(bag, slot) + if link then + Tooltip:AddInventoryInfo(self, link) end + return ret end) end - -- Hook SetHyperlink for chat links - local oldSetHyperlink = GameTooltip.SetHyperlink + -- Hook SetHyperlink for hyperlinks from chat and cached links + local oldSetHyperlink = GameTooltip.SetHyperlink function GameTooltip:SetHyperlink(link) return WithDeferredMoney(self, function() - local ret = oldSetHyperlink(self, link) - if link and strfind(link, "item:") then - Tooltip:AddInventoryInfo(self, link) + local _, _, inner = string.find(link or "", "|H(.+)|h") + local forwarded = link + local itemLinkForCounts = link + if inner then + forwarded = inner + if strfind(inner, "^item:") then + itemLinkForCounts = inner + end end + local ret = oldSetHyperlink(self, forwarded) + if itemLinkForCounts and strfind(itemLinkForCounts, "item:") then + Tooltip:AddInventoryInfo(self, itemLinkForCounts) + end + return ret end) end diff --git a/UI/ItemButton.lua b/UI/ItemButton.lua index 3229455..51da5e5 100644 --- a/UI/ItemButton.lua +++ b/UI/ItemButton.lua @@ -604,15 +604,22 @@ function Guda_ItemButton_OnEnter(self) end -- Early return for empty slots (no tooltip needed) - if not self.hasItem then + if not self.hasItem or not self.itemData then return end - GameTooltip:SetOwner(self, "ANCHOR_RIGHT") + GameTooltip:SetOwner(UIParent, "ANCHOR_NONE") + -- important position of tooltip + GameTooltip:SetPoint("BOTTOMRIGHT", self, "TOPLEFT", 10, 0) - -- For other characters or read-only mode, use cached item link if self.otherChar or self.isReadOnly then - GameTooltip:SetBagItem(self.bagID, self.slotID) + GameTooltip.GudaViewedCharacter = self.otherChar + if self.itemData and self.itemData.link then + GameTooltip:SetHyperlink(self.itemData.link) + else + GameTooltip:Hide() + return + end -- Special handling for bank main bag when bank might be closed elseif self.isBank and self.bagID == -1 then local bankFrame = getglobal("BankFrame") @@ -627,7 +634,6 @@ function Guda_ItemButton_OnEnter(self) -- For live mode: use SetBagItem for all bags GameTooltip:SetBagItem(self.bagID, self.slotID) end - GameTooltip:Show() -- Handle merchant sell cursor (same approach as BagShui) if MerchantFrame:IsShown() and not self.isBank and not self.otherChar and self.hasItem then @@ -640,6 +646,10 @@ end -- OnLeave handler function Guda_ItemButton_OnLeave(self) + -- Clear any viewed character hint on the tooltip when leaving + if GameTooltip and GameTooltip.GudaViewedCharacter then + GameTooltip.GudaViewedCharacter = nil + end GameTooltip:Hide() ResetCursor()