mirror of
https://github.com/brues-code/pfUI.git
synced 2026-11-01 16:36:56 +00:00
Rebuild the unit tooltip when its unit retargets
pfUI's unit lines -- target, guild, colours, speed, unit id, the buff row -- were added once from OnShow, so the target line went stale while hovering, and any SetUnit on a shown tooltip wiped them. They now go on from OnTooltipSetUnit, every time a unit is set. While a unit tooltip is up it listens for UNIT_TARGET on the unit's GUID and re-sets the unit a frame later, through the token the tooltip was built from: "mouseover" stops naming the unit once the cursor leaves, so a fading tooltip is left to fade. Item and spell ids stay on OnShow.
This commit is contained in:
+49
-15
@@ -95,7 +95,16 @@ pfUI:RegisterModule("tooltip", function ()
|
||||
|
||||
pfUI.tooltip:SetAllPoints()
|
||||
pfUI.tooltip:SetScript("OnShow", function()
|
||||
pfUI.tooltip:Update()
|
||||
if C.tooltip.itemid == "1" and GameTooltip:HasItem() then
|
||||
local _, _, itemID = GameTooltip:GetItem()
|
||||
GameTooltip:AddLine(T["ItemID"] .. ": " .. itemID, .25,.5,1)
|
||||
GameTooltip:Show()
|
||||
elseif C.tooltip.spellid == "1" and GameTooltip:HasSpell() then
|
||||
local _, _, spellID = GameTooltip:GetSpell()
|
||||
GameTooltip:AddLine(T["SpellID"] .. ": " .. spellID, .25,.5,1)
|
||||
GameTooltip:Show()
|
||||
end
|
||||
|
||||
if GameTooltip:GetAnchorType() == "ANCHOR_NONE" then
|
||||
GameTooltip:ClearAllPoints()
|
||||
if C.tooltip.position == "bottom" then
|
||||
@@ -273,22 +282,47 @@ pfUI:RegisterModule("tooltip", function ()
|
||||
end
|
||||
end
|
||||
|
||||
function pfUI.tooltip:Update()
|
||||
-- A unit tooltip names the unit's target, so it rebuilds when that changes:
|
||||
-- UNIT_TARGET by the unit's GUID, which unit events fire with whatever token
|
||||
-- names the unit. SetUnit re-runs OnTooltipSetUnit and with it UpdateUnit.
|
||||
-- It goes through the token the tooltip was built from -- "mouseover" for a
|
||||
-- world unit stops naming it once the cursor leaves, so a fading tooltip is
|
||||
-- left to fade -- and waits a frame: the rebuild re-points this frame's
|
||||
-- registration, which the dispatch is still walking.
|
||||
local function Retarget()
|
||||
local _, unit = GameTooltip:GetUnit()
|
||||
local _, guid = GameTooltip:GetUnitGUID()
|
||||
if unit and GameTooltip:IsShown() and UnitGUID(unit) == guid then
|
||||
GameTooltip:SetUnit(unit)
|
||||
end
|
||||
end
|
||||
|
||||
pfUI.tooltip.retarget = CreateFrame("Frame")
|
||||
pfUI.tooltip.retarget:SetScript("OnEvent", function()
|
||||
RunNextFrame(Retarget)
|
||||
end)
|
||||
|
||||
-- pfUI's unit lines go on whenever a unit is set, not only when the tooltip
|
||||
-- shows, so a tooltip rebuilt while it is up keeps them
|
||||
GameTooltip:HookScript("OnTooltipSetUnit", function()
|
||||
pfUI.tooltip:UpdateUnit()
|
||||
end)
|
||||
|
||||
-- the buff row belongs to the unit it was built for
|
||||
GameTooltip:HookScript("OnTooltipCleared", function()
|
||||
pfUI.tooltip:UpdateBuffs("none")
|
||||
end)
|
||||
|
||||
GameTooltip:HookScript("OnHide", function()
|
||||
pfUI.tooltip:UpdateBuffs("none")
|
||||
pfUI.tooltip.retarget:UnregisterEvent("UNIT_TARGET")
|
||||
end)
|
||||
|
||||
function pfUI.tooltip:UpdateUnit()
|
||||
local unit = pfUI.tooltip:GetUnit()
|
||||
pfUI.tooltip:UpdateBuffs(unit)
|
||||
if unit == "none" then
|
||||
if C.tooltip.itemid == "1" and GameTooltip:HasItem() then
|
||||
local _, _, itemID = GameTooltip:GetItem()
|
||||
GameTooltip:AddLine(T["ItemID"] .. ": " .. itemID, .25,.5,1)
|
||||
GameTooltip:Show()
|
||||
elseif C.tooltip.spellid == "1" and GameTooltip:HasSpell() then
|
||||
local _, _, spellID = GameTooltip:GetSpell()
|
||||
GameTooltip:AddLine(T["SpellID"] .. ": " .. spellID, .25,.5,1)
|
||||
GameTooltip:Show()
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
if unit == "none" then return end
|
||||
pfUI.tooltip.retarget:RegisterUnitEvent("UNIT_TARGET", UnitGUID(unit))
|
||||
|
||||
local pvpname = UnitPVPName(unit)
|
||||
local name = UnitName(unit)
|
||||
|
||||
Reference in New Issue
Block a user