WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Tooltip hook stopped working in latest patch? (https://www.wowinterface.com/forums/showthread.php?t=59247)

Yocote 10-06-22 09:19 AM

Tooltip hook stopped working in latest patch?
 
Is anyone aware of any changes in how tooltip hooking works in yesterday's DragonFlight patch (2022-10-04, patch 45969)? One of my addons that adds a few lines to item tooltips has unexpecetdly stopped working (it worked in earlier dragonflight beta patches). Has there been a change? Or alternatively, can anyone show a minimalistic example of addon code that adds a line to an item tooltip?

Fizzlemizz 10-06-22 10:07 AM

Tooltips have been reworked with C_TooltipInfo but, from what I've read so far, if your tooltip uses "GameTooltipTemplate" instead of "SharedTooltipTemplate" you should be (mostly) OK... for the time being.

The info hasn't been added to WowPedia yet which is understandable being new and all.

Yocote 10-06-22 10:50 AM

Thanks for the info! I am not creating my own tooltip though, but adding extra lines to the system "GameTooltip" (and a few related ones), using code similar to this to hook in my code:

Lua Code:
  1. local tooltips = {
  2.   GameTooltip,
  3.   ItemRefTooltip,
  4.   ShoppingTooltip1,
  5.   ShoppingTooltip2,
  6. }
  7.  
  8. function events:PLAYER_LOGIN()
  9.   for i=1,#tooltips do
  10.     tooltips[i]:HookScript("OnTooltipSetItem", function(tt)
  11.       MyTooltipAddon:ProcessTip(tt)
  12.     end)
  13.   end
  14. end

What I observe is that my "MyTooltipAddon:ProcessTip" method is no longer being called at all since this patch. The hooking code in the PLAYER_LOGIN event handler is called, and no errors are raised there, but the hooks are just never called, as if HookScript silently no longer does anything anymore.

Gello 10-06-22 11:27 AM

I've found OnTooltipSetItem is not being called for GameTooltip as I'd expect. GameTooltip's SetCurrencyToken continues to work as expected. Unfortunately I've not had time to look into this more beyond acknowledging that was a problem. Looks like you use that too.

Xrystal 10-06-22 11:34 AM

As per Gello's response... 10.0 PTR has OnTooltipSetItem exists but on 10.0 Beta it doesn't in the ItemRef.xml file.

Fizzlemizz 10-06-22 11:38 AM

Presumably the PTR will get the Beta code at some stage before launch, but as it's new there maybe more things to come to match the differences between the two for at least a period before full deprecation.

Xrystal 10-06-22 11:45 AM

Yeah, there are definitely things in flux .. Container file also has differences between PTR and Beta. So I have had to withhold any changes there as I can't fully test it yet. The Container changes are kicking up errors with nUI but not pointing to which line in nUI is causing the problem. So could be a regular error rather than an addon error .. or .. similar to the options and editmode changes, they just don't like addons interfering with frames they want to work with :chuckle:

Yocote 10-06-22 11:47 AM

Quote:

Originally Posted by Gello (Post 341184)
I've found OnTooltipSetItem is not being called for GameTooltip as I'd expect. GameTooltip's SetCurrencyToken continues to work as expected. Unfortunately I've not had time to look into this more beyond acknowledging that was a problem. Looks like you use that too.

Looking at Interface/FrameXML/GameTooltip.xml in https://github.com/Gethe/wow-ui-sour...eb0ac4e2343e35 , it seems that <OnTooltipSetItem> indeed was removed from the <Scripts> section of GameTooltip in this latest patch. Now I wonder if that means that the main tooltip no longer can be hooked in any way ...

Fizzlemizz 10-06-22 11:55 AM

It means there's more to "unpack" from the latest changes and possibly more changes to come... must be getting close to launch ;)

Xrystal 10-06-22 01:29 PM

Quote:

Originally Posted by Fizzlemizz (Post 341189)
It means there's more to "unpack" from the latest changes and possibly more changes to come... must be getting close to launch ;)

Somethings happening or something is horribly wrong .. PTR Servers are still down ( I checked Over 20 hours ago ). And the update for Retail is in a loop.

Edit: Well the update finally kicked in just now. But PTR servers are still down.

Rilgamon 10-09-22 10:07 AM

Lua Code:
  1. local function ResetItem2(tooltip)
  2.     print("ResetItem")
  3. end
  4.  
  5. local function SetItem2(tooltip)
  6.     local tooltipData = tooltip:GetTooltipData()
  7.     if(tooltipData and tooltipData.id and tooltipData.type == 0) then -- type -> 0 = item, 1 = spell
  8.         print("SetItem", tooltipData.type, tooltipData.id)
  9.         tooltip:AddLine('Test')
  10.         GameTooltip_CalculatePadding(tooltip)
  11.     end
  12. end
  13.  
  14. hooksecurefunc(GameTooltip, "Show",SetItem2)
  15. hooksecurefunc(GameTooltip, "Hide",ResetItem2)
  16. --GameTooltip:HookScript("OnShow", SetItem2)
  17. --GameTooltip:HookScript("OnHide", ResetItem2)

I'm looking into this, too because of my items addon. I can change the tooltip and add a line. With hooksecure my function is called multiple times a second and the line is added 1-3 times for a tooltip (3 times when I hover over one of the bags in the bagbar, 2 times mostly for items). With HookScript its called only once but the tooltip is changed back after my line shows up for a split second. Not so promising ;) I really hope someone has a good guide how this is meant to work in the future :)

Fizzlemizz 10-09-22 01:04 PM

Docs have been updated.

sirpucna 10-27-22 03:16 AM

is the pre patch using a old version of wow compared to the beta?
Retail Pre-Patch: 46313
Current Beta: 46259

Seems many of the old Tooltip handlers are still used whereas the new ones suggested for beta dont work
So just ended up doing this:
Code:

if TooltipDataProcessor then
        TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Unit, TooltipSetUnit)
else
        GameTooltip:HookScript("OnTooltipSetUnit", TooltipSetUnit)
end


LudiusMaximus 11-30-22 08:54 AM

Is there still a way to do a pre-hook on what used to be OnTooltipSetItem?

I want to operate on the tooltip of items before any other addons added their lines to it.
Before 10.0.2 I executed this code (a few seconds after login, to make sure that all other addons have already registered):

Lua Code:
  1. local OtherScripts = GameTooltip:GetScript("OnTooltipSetItem")
  2. local function RunOtherScripts(self, ...)
  3.   if OtherScripts then
  4.     return OtherScripts(self, ...)
  5.   else
  6.     return
  7.   end
  8. end
  9.  
  10. GameTooltip:SetScript("OnTooltipSetItem", function(self, ...)
  11.  
  12.   -- Do my stuff with the untouched tooltip.
  13.  
  14.   -- Then let the other addons append their lines.
  15.   return RunOtherScripts(self, ...)
  16. end)


How could the same effect be achieved with the new TooltipDataProcessor?

LudiusMaximus 01-25-23 01:51 AM

Quote:

Originally Posted by LudiusMaximus (Post 341703)
Is there still a way to do a pre-hook on what used to be OnTooltipSetItem?

I just found out that there is also a `TooltipDataProcessor.AddTooltipPreCall`, which seems to let you do stuff to the tooltip before any other addons have done their modifications.

SDPhantom 01-25-23 07:32 PM

Other addons can also register with that function and there's no guarantee that your code would run first. Nor is there a way to force it without causing taint, which is more of an issue now that the new TooltipDataHandler is capable of handling secure code.

LudiusMaximus 01-26-23 02:21 AM

That's true. Thanks for pointing it out. :)
In fact, it seems that the registered functions are executed in the order they have been registered. So it is not possible to make sure you are first by waiting with the registration.


Lua Code:
  1. local startupFrame = CreateFrame("Frame")
  2. startupFrame:RegisterEvent("PLAYER_LOGIN")
  3. startupFrame:SetScript("OnEvent", function(self, event, ...)
  4.  
  5.   TooltipDataProcessor.AddTooltipPreCall(Enum.TooltipDataType.Item, function(self)
  6.     print("Registered first.")
  7.   end)
  8.  
  9.   C_Timer.After(3.0, function()
  10.     TooltipDataProcessor.AddTooltipPreCall(Enum.TooltipDataType.Item, function(self)
  11.       print("Registered after 3 seconds.")
  12.     end)
  13.   end)
  14.  
  15.   C_Timer.After(5.0, function()
  16.     TooltipDataProcessor.AddTooltipPreCall(Enum.TooltipDataType.Item, function(self)
  17.       print("Registered after 5 seconds.")
  18.     end)
  19.   end)
  20.  
  21. end)

Printed result is:
Registered first.
Registered after 3 seconds.
Registered after 5 seconds.

SDPhantom 01-26-23 10:01 AM

Quote:

Originally Posted by LudiusMaximus (Post 342067)
In fact, it seems that the registered functions are executed in the order they have been registered.

Indeed. The functions are registered by table.insert() and iterated with ipairs().

Xrystal 05-29-23 05:00 AM

I have a similar problem in nUI now that I have reinstated its action bars back to service.

nUI adds Keybinding info to the action button tooltip which of course no longer displays permanently due to the tooltip changes I presume.

Now, looking at your findings I tried to do something similar but it has gone belly up.

In PLAYER_LOGIN I have the following block of code - amongst other code
Lua Code:
  1. for i in pairs( nUI_ButtonBars.Bars ) do
  2.     local bar = nUI_ButtonBars.Bars[i];
  3.     for row in pairs( bar.Buttons ) do
  4.         for col in pairs( bar.Buttons[row] ) do
  5.             local button      = bar.Buttons[row][col];
  6.             local key1, key2  = GetBindingKey( "CLICK "..button:GetName()..":LeftButton" );
  7.  
  8.             TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Spell, function(self)
  9.                 if key1 then GameTooltip:AddLine( nUI_L["Key Binding"].." 1: |cFF00FFFF"..GetBindingText( key1, "KEY_" ).."|r", 1, 1, 1 ); end
  10.                 if key2 then GameTooltip:AddLine( nUI_L["Key Binding"].." 2: |cFF00FFFF"..GetBindingText( key2, "KEY_" ).."|r", 1, 1, 1 ); end                                  
  11.                 if not key1 and not key2 then GameTooltip:AddLine( nUI_L["No key bindings found"], 1, 1, 1 ); end
  12.                  GameTooltip:AddLine( nUI_L["<ctrl-alt-right click> to change bindings"], 0, 1, 1 );                                        
  13.             end)
  14.  
  15.             button:SetScript( "OnEnter", function()
  16.                 if nUI_Options.combat_tooltips or not InCombatLockdown() then
  17.                     button:SetTooltip()
  18.                     -- Old Code used to be here
  19.                     GameTooltip:Show();
  20.                 end
  21.             end );
  22.         end
  23.     end
  24. end
All but the TooltipDataProcessor open and close lines were already in the code, but initially inside the OnEnterScript.

It worked fine before Dragonflight but now inside OnEnter it briefly shows but then disappears, and outside OnEnter it shows a ton of lines running down the screen. Instead of the 1-4 I am expecting per button.

Anyone have any ideas on how I would get it working like before ?

Thanks in advance.


edit:
I also tried creating my own tooltip as follows:
local tooltip = CreateFrame("GameTooltip",nil,button,"GameTooltipTemplate")
And using this instead of GameTooltip but no difference.

SDPhantom 05-29-23 06:46 AM

The problem with registering with TooltipDataProcessor.AddTooltipPostCall() is it's a global register. This means it'll call the function every time anything wishes to display a spell's tooltip. Not just the individual button you're working with.

For example, someone mouseovers a spell in their spellbook and every instance of that function for every button you've created will run sequentially for that single tooltip.



I wouldn't suggest this approach as it would impact performance if everyone would start doing it this way, but here's an attempt to fix your code example.
Lua Code:
  1. local nUI_ButtonCache = {};
  2.  
  3. TooltipDataProcessor.AddTooltipPostCall(TooltipDataProcessor.AllTypes, function(self)
  4.     local owner = self:GetOwner();
  5.     if nUI_ButtonCache[owner] then
  6.         local key1, key2 = GetBindingKey(("CLICK %s:LeftButton"):format( owner:GetName() ));
  7.         if key1 then self:AddLine(("%s 1: |cFF00FFFF%s|r"):format( nUI_L["Key Binding"], GetBindingText( key1, "KEY_" )), 1, 1, 1 ); end
  8.         if key2 then self:AddLine(("%s 1: |cFF00FFFF%s|r"):format( nUI_L["Key Binding"], GetBindingText( key2, "KEY_" )), 1, 1, 1 ); end
  9.         if not (key1 or key2) then self:AddLine( nUI_L["No key bindings found"], 1, 1, 1 ); end
  10.         self:AddLine( nUI_L["<ctrl-alt-right click> to change bindings"], 0, 1, 1 );
  11.     end
  12. end);
  13.  
  14. for _, bar in pairs( nUI_ButtonBars.Bars ) do
  15.     for _, row in pairs( bar.Buttons ) do
  16.         for _, button in pairs( row ) do
  17.             nUI_ButtonCache[button] = true;
  18.             button:SetScript( "OnEnter", function()
  19.                 if nUI_Options.combat_tooltips or not InCombatLockdown() then
  20.                     button:SetTooltip()
  21.                     -- Old Code used to be here
  22.                     GameTooltip:Show();
  23.                 end
  24.             end);
  25.         end
  26.     end
  27. end

As noted earlier, TooltipDataProcessor.AddTooltipPostCall() is a global register, so I reduced its handler to a single function. I registered it with the TooltipDataProcessor.AllTypes enum, which is a special flag that tells the processor to call the handler for every tooltip type. The handler is called with the tooltip being processed and its associated raw data table. We can query its owner with :GetOwner() and check if it's one of our buttons. If it is, we can proceed with posting its keybind info.


All times are GMT -6. The time now is 11:48 AM.

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