Originally Posted by Kraeius
I already checked many, in the end I could get itemLink of item that I'm hovering. Modifying tooltip is still troubling.
I prefer to understand what I'm doing. Exact code example of what I've asked would be more helpful.
|
Yes, of course:
There are some functions, defined in build-in code, which are used to setup the layout of a tooltip, e.g. :SetLink(itemLink) or :SetBagItem(bagId, slotIndex)
By hooking them, your code will be executed whenever someone (build-in or addon) shows a tooltip.
Garkin's code does it in a very compact, elegant way (not suprising
)
Lua Code:
local function TooltipHook(tooltipControl, method, linkFunc)
local origMethod = tooltipControl[method] -- backup the original
tooltipControl[method] = function(self, ...)
local itemLink = linkFunc(...) -- Convert the given parameters to an itemLink
-- pre hook stuff
origMethod(self, ...) -- call the original
-- post hook stuff
ZO_Tooltip_AddDivider(tooltipControl)
local name = GetItemLinkName(itemLink)
-- text, font, r, g, b, control-alignment, text modifier, text-alignment, use full width <- otherwise text alignment other than TEXT_ALIGN_LEFT has no visual effect
tooltipControl:AddLine(zo_strformat(SI_TOOLTIP_ITEM_NAME, name), "ZoFontWinH4", 0.5, 1, 0.5, CENTER, MODIFY_TEXT_TYPE_NONE, TEXT_ALIGN_CENTER, true)
end
end
Now hook (hopefully) all these Set-functions relevant for your addon:
Lua Code:
local function ReturnItemLink(itemLink)
return itemLink
end
local function OnAddOnLoaded(eventCode, addonName)
if addonName:find("^ZO_") then return end
EVENT_MANAGER:UnregisterForEvent("BetterGlyphTooltip", eventCode)
-- Tooltip control, function to hook, converter function
TooltipHook(ItemTooltip, "SetBagItem", GetItemLink)
TooltipHook(ItemTooltip, "SetTradeItem", GetTradeItemLink)
TooltipHook(ItemTooltip, "SetBuybackItem", GetBuybackItemLink)
TooltipHook(ItemTooltip, "SetStoreItem", GetStoreItemLink)
TooltipHook(ItemTooltip, "SetAttachedMailItem", GetAttachedItemLink)
TooltipHook(ItemTooltip, "SetLootItem", GetLootItemLink)
TooltipHook(ItemTooltip, "SetTradingHouseItem", GetTradingHouseSearchResultItemLink)
TooltipHook(ItemTooltip, "SetTradingHouseListing", GetTradingHouseListingItemLink)
TooltipHook(ItemTooltip, "SetLink", ReturnItemLink)
TooltipHook(PopupTooltip, "SetLink", ReturnItemLink)
TooltipHook(ZO_EnchantingTopLevelTooltip, "SetPendingEnchantingItem", GetEnchantingResultingItemLink)
end
EVENT_MANAGER:RegisterForEvent("BetterGlyphTooltip", EVENT_ADD_ON_LOADED, OnAddOnLoaded)