Thread Tools Display Modes
06/06/15, 11:10 PM   #1
Kraeius
 
Kraeius's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 25
Item Tooltip

Hi guys,

I need help with item tooltip alteration. Aim is simple, get itemLink on mouse-hover, process it somewhere, get data etc, then show requested new data at bottom of original tooltip.

Lets say, I mouse-over an item, get it's itemLink, processing it to get itemName, then I show in at the bottom line of original tooltip after a divider.

Can any of you throw an example?

Thanks
  Reply With Quote
06/07/15, 01:26 AM   #2
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 578
Originally Posted by Kraeius View Post
Lets say, I mouse-over an item, get it's itemLink, processing it to get itemName, then I show in at the bottom line of original tooltip after a divider.

Can any of you throw an example?

Thanks
CritPercent from Garkin is a small tooltip-addon covering nearly all tooltips and therefore a good template.
Harven's Trait and Style from Harven and merlight does a bit more with the tooltip. (Adding header rows)
And Votan's Achievements Overview shows how to add custom controls.

Adding a divider is:
Lua Code:
  1. ZO_Tooltip_AddDivider(anyTooltipControl)

Is this what you are looking for?
  Reply With Quote
06/07/15, 02:19 AM   #3
Kraeius
 
Kraeius's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 25
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.

I didn't check Ach. Overview though, gonna look it now. Thanks Votan.
  Reply With Quote
06/07/15, 03:29 AM   #4
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 578
Originally Posted by Kraeius View Post
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:
  1. local function TooltipHook(tooltipControl, method, linkFunc)
  2.       local origMethod = tooltipControl[method] -- backup the original
  3.      
  4.       tooltipControl[method] = function(self, ...)
  5.         local itemLink = linkFunc(...) -- Convert the given parameters to an itemLink
  6.         -- pre hook stuff
  7.         origMethod(self, ...) -- call the original
  8.         -- post hook stuff
  9.         ZO_Tooltip_AddDivider(tooltipControl)
  10.         local name = GetItemLinkName(itemLink)
  11. -- 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
  12.         tooltipControl:AddLine(zo_strformat(SI_TOOLTIP_ITEM_NAME, name), "ZoFontWinH4", 0.5, 1, 0.5, CENTER, MODIFY_TEXT_TYPE_NONE, TEXT_ALIGN_CENTER, true)
  13.       end
  14.     end
Now hook (hopefully) all these Set-functions relevant for your addon:
Lua Code:
  1. local function ReturnItemLink(itemLink)
  2.       return itemLink
  3.     end
  4.      
  5.     local function OnAddOnLoaded(eventCode, addonName)
  6.       if addonName:find("^ZO_") then return end
  7.       EVENT_MANAGER:UnregisterForEvent("BetterGlyphTooltip", eventCode)
  8.      -- Tooltip control, function to hook, converter function
  9.       TooltipHook(ItemTooltip, "SetBagItem", GetItemLink)
  10.       TooltipHook(ItemTooltip, "SetTradeItem", GetTradeItemLink)
  11.       TooltipHook(ItemTooltip, "SetBuybackItem", GetBuybackItemLink)
  12.       TooltipHook(ItemTooltip, "SetStoreItem", GetStoreItemLink)
  13.       TooltipHook(ItemTooltip, "SetAttachedMailItem", GetAttachedItemLink)
  14.       TooltipHook(ItemTooltip, "SetLootItem", GetLootItemLink)
  15.       TooltipHook(ItemTooltip, "SetTradingHouseItem", GetTradingHouseSearchResultItemLink)
  16.       TooltipHook(ItemTooltip, "SetTradingHouseListing", GetTradingHouseListingItemLink)
  17.       TooltipHook(ItemTooltip, "SetLink", ReturnItemLink)
  18.      
  19.       TooltipHook(PopupTooltip, "SetLink", ReturnItemLink)
  20.      
  21.       TooltipHook(ZO_EnchantingTopLevelTooltip, "SetPendingEnchantingItem", GetEnchantingResultingItemLink)
  22.     end
  23.     EVENT_MANAGER:RegisterForEvent("BetterGlyphTooltip", EVENT_ADD_ON_LOADED, OnAddOnLoaded)
  Reply With Quote
06/07/15, 06:13 AM   #5
Kraeius
 
Kraeius's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 25
That's just what I need, thank you so much Votan
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Item Tooltip


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