mirror of
https://github.com/brues-code/pfUI.git
synced 2026-11-01 16:36:56 +00:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user