Thread Tools Display Modes
10-15-22, 10:28 AM   #21
Ledii
A Deviate Faerie Dragon
 
Ledii's Avatar
Join Date: Apr 2013
Posts: 10
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.
__________________
Take it as it comes...
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Updating tooltip while tooltip is still active.


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off