feat: tooltip position and framelevel

This commit is contained in:
Salikh Gurgenidze
2025-11-22 04:07:42 +04:00
parent 0354c9a1fc
commit 2b0011599d
2 changed files with 35 additions and 55 deletions
+20 -50
View File
@@ -331,65 +331,35 @@ function Tooltip:Initialize()
-- Hook SetBagItem -- Hook SetBagItem
local oldSetBagItem = GameTooltip.SetBagItem local oldSetBagItem = GameTooltip.SetBagItem
local oldSetInventoryItem = GameTooltip.SetInventoryItem
local oldSetHyperlink = GameTooltip.SetHyperlink
function GameTooltip:SetBagItem(bag, slot) function GameTooltip:SetBagItem(bag, slot)
return WithDeferredMoney(self, function() return WithDeferredMoney(self, function()
local bankFrame = getglobal("BankFrame") local ret = oldSetBagItem(self, bag, slot)
local link = GetContainerItemLink(bag, slot)
if bag == -1 and bankFrame and bankFrame:IsVisible() then if link then
local invSlot = BankButtonIDToInvSlotID(slot) Tooltip:AddInventoryInfo(self, link)
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
end end
return ret
end) end)
end end
-- Hook SetHyperlink for chat links -- Hook SetHyperlink for hyperlinks from chat and cached links
local oldSetHyperlink = GameTooltip.SetHyperlink local oldSetHyperlink = GameTooltip.SetHyperlink
function GameTooltip:SetHyperlink(link) function GameTooltip:SetHyperlink(link)
return WithDeferredMoney(self, function() return WithDeferredMoney(self, function()
local ret = oldSetHyperlink(self, link) local _, _, inner = string.find(link or "", "|H(.+)|h")
if link and strfind(link, "item:") then local forwarded = link
Tooltip:AddInventoryInfo(self, link) local itemLinkForCounts = link
if inner then
forwarded = inner
if strfind(inner, "^item:") then
itemLinkForCounts = inner
end
end end
local ret = oldSetHyperlink(self, forwarded)
if itemLinkForCounts and strfind(itemLinkForCounts, "item:") then
Tooltip:AddInventoryInfo(self, itemLinkForCounts)
end
return ret return ret
end) end)
end end
+15 -5
View File
@@ -604,15 +604,22 @@ function Guda_ItemButton_OnEnter(self)
end end
-- Early return for empty slots (no tooltip needed) -- Early return for empty slots (no tooltip needed)
if not self.hasItem then if not self.hasItem or not self.itemData then
return return
end 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 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 -- Special handling for bank main bag when bank might be closed
elseif self.isBank and self.bagID == -1 then elseif self.isBank and self.bagID == -1 then
local bankFrame = getglobal("BankFrame") local bankFrame = getglobal("BankFrame")
@@ -627,7 +634,6 @@ function Guda_ItemButton_OnEnter(self)
-- For live mode: use SetBagItem for all bags -- For live mode: use SetBagItem for all bags
GameTooltip:SetBagItem(self.bagID, self.slotID) GameTooltip:SetBagItem(self.bagID, self.slotID)
end end
GameTooltip:Show() GameTooltip:Show()
-- Handle merchant sell cursor (same approach as BagShui) -- Handle merchant sell cursor (same approach as BagShui)
if MerchantFrame:IsShown() and not self.isBank and not self.otherChar and self.hasItem then if MerchantFrame:IsShown() and not self.isBank and not self.otherChar and self.hasItem then
@@ -640,6 +646,10 @@ 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
if GameTooltip and GameTooltip.GudaViewedCharacter then
GameTooltip.GudaViewedCharacter = nil
end
GameTooltip:Hide() GameTooltip:Hide()
ResetCursor() ResetCursor()