View Single Post
05-29-23, 06:46 AM   #20
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,330
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.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 05-29-23 at 07:34 AM.
  Reply With Quote