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:
local nUI_ButtonCache = {};
TooltipDataProcessor.AddTooltipPostCall(TooltipDataProcessor.AllTypes, function(self)
local owner = self:GetOwner();
if nUI_ButtonCache[owner] then
local key1, key2 = GetBindingKey(("CLICK %s:LeftButton"):format( owner:GetName() ));
if key1 then self:AddLine(("%s 1: |cFF00FFFF%s|r"):format( nUI_L["Key Binding"], GetBindingText( key1, "KEY_" )), 1, 1, 1 ); end
if key2 then self:AddLine(("%s 1: |cFF00FFFF%s|r"):format( nUI_L["Key Binding"], GetBindingText( key2, "KEY_" )), 1, 1, 1 ); end
if not (key1 or key2) then self:AddLine( nUI_L["No key bindings found"], 1, 1, 1 ); end
self:AddLine( nUI_L["<ctrl-alt-right click> to change bindings"], 0, 1, 1 );
end
end);
for _, bar in pairs( nUI_ButtonBars.Bars ) do
for _, row in pairs( bar.Buttons ) do
for _, button in pairs( row ) do
nUI_ButtonCache[button] = true;
button:SetScript( "OnEnter", function()
if nUI_Options.combat_tooltips or not InCombatLockdown() then
button:SetTooltip()
-- Old Code used to be here
GameTooltip:Show();
end
end);
end
end
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.