From 07e315cd86ee39ef82764dda58e9a3009d436e2e Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat, 31 Oct 2026 03:05:56 -0500 Subject: [PATCH] Toggle the item comparison live with shift The comparison read IsShiftKeyDown() only when the tooltip was set, so pressing or releasing shift while hovering did nothing until the next hover. Each hooked tooltip now remembers the item it shows, dropped on OnTooltipCleared and OnHide, and MODIFIER_STATE_CHANGED shows or hides its comparison right away, as on retail. Merchant and auction comparisons show regardless of shift and never store a link, so shift leaves them up. --- modules/eqcompare.lua | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/modules/eqcompare.lua b/modules/eqcompare.lua index 8e9f82df..59843200 100644 --- a/modules/eqcompare.lua +++ b/modules/eqcompare.lua @@ -86,6 +86,12 @@ pfUI:RegisterModule("eqcompare", function () end end + local function HideCompareItem(self) + local shoppingTooltip1, shoppingTooltip2 = unpack(self.shoppingTooltips or { ShoppingTooltip1, ShoppingTooltip2 }) + shoppingTooltip1:Hide() + shoppingTooltip2:Hide() + end + local prevMerchant = ShoppingTooltip1.SetMerchantCompareItem local function SetMerchantCompareItem(self, index, compareItem) if compareItem == 1 then @@ -139,9 +145,18 @@ pfUI:RegisterModule("eqcompare", function () deferred = true end) + -- the item each hooked tooltip shows, for MODIFIER_STATE_CHANGED. Every Set* + -- clears the tooltip before it builds, so OnTooltipCleared drops the link + -- of the previous content before the hook stores the new one. + local links = {} + local function forget() + links[this] = nil + end + local function makeHook(getter) return function(tooltip, arg1, arg2, arg3) local link = getter(arg1, arg2, arg3) + links[tooltip] = link if not deferred then return ShowCompareItem(tooltip, link) end @@ -157,8 +172,29 @@ pfUI:RegisterModule("eqcompare", function () for setter, getter in pairs(TooltipHooks) do hooksecurefunc(tooltip, setter, makeHook(getter)) end + tooltip:HookScript("OnTooltipCleared", forget) + tooltip:HookScript("OnHide", forget) end + -- pressing or releasing shift over an item toggles its comparison at once. + -- Merchant and auction comparisons show regardless of shift and never set + -- a link, so they stay up. + pfUI.events:RegisterFrameEventAndCallback("MODIFIER_STATE_CHANGED", function(_, key) + if key ~= "LSHIFT" and key ~= "RSHIFT" then return end + + local shift = IsShiftKeyDown() + for tooltip, link in pairs(links) do + -- a hidden tooltip got its item from a scan, not a hover + if tooltip:IsShown() then + if shift then + ShowCompareItem(tooltip, link, shift) + elseif C.tooltip.compare.showalways ~= "1" or C_Item.IsEquippedItem(link) then + HideCompareItem(tooltip) + end + end + end + end) + HookTooltip(GameTooltip) pfUI.eqcompare.HookTooltip = HookTooltip