... is a library that help addons that add or modify tooltip information.
The API is extremely simple :
TooltipHookLib:RegisterHook(key, func, name...)
_ key is a identifier unique to this particular hook (or nil).
_ func is either a function, or a table, that is seen as an object.
_ name is one or more methods or list of methods of a GameTooltip that you want to hook. see below for more details.
The return value is either key or, if key was nil, a unique value is created and returned.
Can be then used to remove the hook.
your callback function should have the form :
local my_callback(method, tooltip, <params>)
where method is the string of the method that triggered the callback, tooltip is a reference to the tooltip object that just called the method, and parameters are whatever parameters the method expects.
If your callback is an object, then it should have a method for each methods it hooks, like this :
function MyAddon:SetHyperlink(tooltip, link)
TooltipHookLib:RegisterHook(nil, MyAddon, "SetHyperlink")
Your function should not call tooltip:Show() if it add a line, but should return a true value, so that Show() will only be called once.
Any Set...() method of Tooltip can be hooked this way, even "SetAction", or "SetSpell".
There is a new virtual method "SetItemLink", that automatically handles all the different Set...() method that have an API to get the itemlink from. So if you do something like this :
Here is an updated version (drycoded). Change in this version are the following :
_ we use the new tooltip:GetItem() call if it's available instead of having specific hooks for each type of method. This reduce the complexity of the code drastically. This should also allow information to be added to a few new tooltips (SetAuctionCompareItem, SetBuybackItem, SetSendMailItem, for example, had previously no API to get an itemlink).
_ Added two new "virtual" methods "SetUnit*" and "SetSpell*" that will be called if the tooltip is for a valid unit or a valid spell. This is based on the new API tooltip:GetSpell() and tooltip:GetUnit().
_ Added a new API. RegisterTooltipException(tooltip), to allow some tooltip NOT to be hooked. This is useful for tooltips that are never shown, like Gratuity.