-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
utils.lua
64 lines (59 loc) · 1.95 KB
/
utils.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
local _, addon = ...
if addon:IsRetail() then
function addon:HookTooltip(callback)
TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Item, function(tooltip, data)
if not (tooltip and not tooltip:IsForbidden() and tooltip:GetOwner()) then
return
end
if tooltip ~= GameTooltip then
-- disqualify shopping tooltips
return
end
if data.guid then
local location = C_Item.GetItemLocation(data.guid)
if location and location:IsBagAndSlot() then
local bagID = location:GetBagAndSlot()
if bagID >= 0 and bagID <= 5 then -- limit to player bags
callback(tooltip, Item:CreateFromItemLocation(location))
end
end
elseif tooltip:GetOwner():GetName() == 'TradeRecipientItem7ItemButton' then
-- special handling for trade window
local _, itemLink = tooltip:GetItem()
if itemLink then
callback(tooltip, Item:CreateFromItemLink(itemLink))
end
end
end)
end
else
local function getBagAndSlotID(parent)
if parent then
local grandParent = parent:GetParent()
if grandParent then
local slotID = parent.GetID and parent:GetID()
local bagID = grandParent.GetID and grandParent:GetID()
if bagID and slotID and slotID >= 0 then
return bagID, slotID
end
end
end
end
function addon:HookTooltip(callback)
GameTooltip:HookScript('OnTooltipSetItem', function(tooltip)
if not (tooltip and not tooltip:IsForbidden() and tooltip:GetOwner()) then
return
end
local _, itemLink = tooltip:GetItem()
if itemLink then
local bagID, slotID = getBagAndSlotID(tooltip:GetOwner())
if bagID and slotID and bagID >= 0 and bagID <= 4 then -- limit to player bags
callback(tooltip, Item:CreateFromItemLocation(ItemLocation:CreateFromBagAndSlot(bagID, slotID)))
elseif tooltip:GetOwner():GetName() == 'TradeRecipientItem7ItemButton' then
-- special handling for trade window
callback(tooltip, Item:CreateFromItemLink(itemLink))
end
end
end)
end
end