WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Updating tooltip while tooltip is still active. (https://www.wowinterface.com/forums/showthread.php?t=44247)

Ledii 10-15-22 10:28 AM

General suggestions for handling tooltips
 
If you want your addon to work together with other addons which also modifies the tooltips,
you might need to be a little more sophisticated around how you modify your lines.
You will not always know which lines are yours. And clearing the entire tooltip will end up clearing more than you want too...

Here is the approach I ended up using:

Code:

local cachedUnit = nil

function OnTooltipSetUnit()
        --Figure out if we are reading data from mouseover or target
        local unit = "mouseover"
        if (not UnitExists(unit)) then
                unit = "target"
        end

        --Cache unit so that we can run it again later with the same unit
        cachedUnit = unit
        AppendCustomTooltipLines()
end

function AppendCustomTooltipLines()
        --Add custom lines here with custom color
        local r = 1
        local g = 1
        local b = 1
        GameTooltip:AddLine("Custom text here...", r, g, b)
end

function UpdateTooltip()
        if cachedUnit == nil then return end

        --Makes sure custom tooltip lines are cleared
        GameTooltip:SetUnit(cachedUnit)
end

GameTooltip:HookScript("OnTooltipSetUnit", OnTooltipSetUnit)

You may then call UpdateTooltip() wherever, when you know there is new data to apply.


All times are GMT -6. The time now is 03:39 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI