-
-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathHooks.lua
More file actions
executable file
·397 lines (336 loc) · 14.8 KB
/
Hooks.lua
File metadata and controls
executable file
·397 lines (336 loc) · 14.8 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
if BattlePetToolTip_Show ~= nil then -- not Auctionator.Constants.IsClassic
hooksecurefunc (_G, "BattlePetToolTip_Show",
function(speciesID, ...)
Auctionator.Tooltip.AddPetTip(speciesID)
end
)
end
local TooltipHandlers = {}
-- This is called when mousing over an item in your bags
TooltipHandlers["SetBagItem"] = function(tip, bag, slot)
local itemLocation = ItemLocation:CreateFromBagAndSlot(bag, slot)
if C_Item.DoesItemExist(itemLocation) then
local itemLink = C_Item.GetItemLink(itemLocation);
local itemCount = C_Item.GetStackCount(itemLocation)
Auctionator.Tooltip.ShowTipWithPricing(tip, itemLink, itemCount)
end
end
-- This is called when mousing over an item in a merchant window (Buyback Pane)
TooltipHandlers["SetBuybackItem"] = function(tip, slotIndex)
local itemLink = GetBuybackItemLink(slotIndex)
local _, _, _, itemCount = GetBuybackItemInfo(slotIndex);
Auctionator.Tooltip.ShowTipWithPricing(tip, itemLink, itemCount)
end
local GetMerchantItemInfo = GetMerchantItemInfo or function(index)
local info = C_MerchantFrame.GetItemInfo(index);
if info then
return info.name, info.texture, info.price, info.stackCount, info.numAvailable, info.isPurchasable, info.isUsable, info.hasExtendedCost, info.currencyID, info.spellID;
end
end
-- This is called when mousing over an item in a merchant window (Merchant Pane)
TooltipHandlers["SetMerchantItem"] = function(tip, index)
local itemLink = GetMerchantItemLink(index)
local _, _, _, itemCount = GetMerchantItemInfo(index);
Auctionator.Tooltip.ShowTipWithPricing(tip, itemLink, itemCount)
end
-- This is called when mousing over an item in your bank, or a bag in your bag list
TooltipHandlers["SetInventoryItem"] = function(tip, unit, slot)
local itemLink = GetInventoryItemLink(unit, slot)
local itemCount = GetInventoryItemCount(unit, slot)
Auctionator.Tooltip.ShowTipWithPricing(tip, itemLink, itemCount ~= 0 and itemCount or 1)
end
-- This is called when mousing over an item in your guild bank
-- Guild banks don't keep track of pets inside them correctly, so showing the AH
-- price is difficult.
TooltipHandlers["SetGuildBankItem"] = function(tip, tab, slot)
local itemLink = GetGuildBankItemLink(tab, slot)
local _, itemCount = GetGuildBankItemInfo(tab, slot)
Auctionator.Tooltip.ShowTipWithPricing(tip, itemLink, itemCount)
end
if GameTooltip.SetRecipeReagentItem then -- Dragonflight onwards
-- Reagent in Dragonflight recipe tradeskill page, only for reagents without a
-- quality rating.
TooltipHandlers["SetRecipeReagentItem"] = function( tip, recipeID, slotID )
local recipeLevel
if ProfessionsFrame and ProfessionsFrame.CraftingPage:IsVisible() then
recipeLevel = ProfessionsFrame.CraftingPage.SchematicForm:GetCurrentRecipeLevel()
elseif ProfessionsFrame and ProfessionsFrame.OrdersPage:IsVisible() then
recipeLevel = ProfessionsFrame.OrdersPage.OrderView.OrderDetails.SchematicForm:GetCurrentRecipeLevel()
end
local schematic = C_TradeSkillUI.GetRecipeSchematic(recipeID, false, recipeLevel)
for _, reagentSlotSchematic in ipairs(schematic.reagentSlotSchematics) do
if reagentSlotSchematic.dataSlotIndex == slotID then
local itemCount = reagentSlotSchematic.quantityRequired
local _, itemLink = GetItemInfo(reagentSlotSchematic.reagents[1].itemID)
Auctionator.Tooltip.ShowTipWithPricing(tip, itemLink, itemCount)
break
end
end
end
end
if GameTooltip.SetRecipeResultItem then -- Dragonflight onwards
TooltipHandlers["SetRecipeResultItem"] = function(tip, recipeID, reagents, allocations, recipeLevel, qualityID)
local outputLink
-- Use GetRecipeOutputLink when Crafting page visible (same resolution as profit line for quality items)
if ProfessionsFrame and ProfessionsFrame.CraftingPage and ProfessionsFrame.CraftingPage:IsVisible() then
local schematicForm = ProfessionsFrame.CraftingPage.SchematicForm
outputLink = schematicForm and Auctionator.CraftingInfo.GetRecipeOutputLink(schematicForm, qualityID)
end
if not outputLink then
local rInfo = C_TradeSkillUI.GetRecipeInfo(recipeID, recipeLevel or 0)
if rInfo and rInfo.qualityItemIDs and #rInfo.qualityItemIDs > 0 and qualityID and qualityID >= 13 and qualityID <= 14 then
local outID = rInfo.qualityItemIDs[qualityID - 12]
if outID then outputLink = select(2, C_Item.GetItemInfo(outID)) end
end
end
if not outputLink then
local out = C_TradeSkillUI.GetRecipeOutputItemData(recipeID, reagents or {}, allocations, qualityID)
outputLink = out and out.hyperlink
end
if not outputLink and Auctionator.CraftingInfo and Auctionator.CraftingInfo.EnchantSpellsToItems and Auctionator.CraftingInfo.EnchantSpellsToItems[recipeID] then
local itemID = Auctionator.CraftingInfo.EnchantSpellsToItems[recipeID][1]
if itemID then outputLink = select(2, C_Item.GetItemInfo(itemID)) end
end
if outputLink then
local schematic = C_TradeSkillUI.GetRecipeSchematic(recipeID, false, recipeLevel or 0)
Auctionator.Tooltip.ShowTipWithPricing(tip, outputLink, schematic and schematic.quantityMin or 1)
end
end
end
if GameTooltip.SetItemByGUID then
TooltipHandlers["SetItemByGUID"] = function(tip, guid)
local itemLink = C_Item.GetItemLinkByGUID(guid)
if itemLink then
Auctionator.Tooltip.ShowTipWithPricing(tip, itemLink, 1)
end
end
end
if GameTooltip.SetTradeSkillItem then -- Classic
TooltipHandlers["SetTradeSkillItem"] = function(tip, recipeIndex, reagentIndex)
local itemLink, itemCount
if reagentIndex ~= nil then
itemLink = GetTradeSkillReagentItemLink(recipeIndex, reagentIndex)
itemCount = select(3, GetTradeSkillReagentInfo(recipeIndex, reagentIndex))
else
itemLink = GetTradeSkillItemLink(recipeIndex);
itemCount = GetTradeSkillNumMade(recipeIndex);
end
Auctionator.Tooltip.ShowTipWithPricing(tip, itemLink, itemCount)
end
end
if GameTooltip.SetCraftItem then -- TBC classic and earlier
TooltipHandlers["SetCraftItem"] = function(tip, recipeIndex, reagentIndex)
local itemLink, itemCount
if reagentIndex ~= nil then
itemLink = GetCraftReagentItemLink(recipeIndex, reagentIndex)
itemCount = select(3, GetCraftReagentInfo(recipeIndex, reagentIndex))
else
itemLink = GetCraftItemLink(recipeIndex);
itemCount = GetCraftNumMade(recipeIndex);
end
Auctionator.Tooltip.ShowTipWithPricing(tip, itemLink, itemCount)
end
end
-- This is called when mousing over an item in the loot window
TooltipHandlers["SetLootItem"] = function (tip, slot)
if LootSlotHasItem(slot) then
local itemLink, _, itemCount = GetLootSlotLink(slot);
Auctionator.Tooltip.ShowTipWithPricing(tip, itemLink, itemCount)
end
end
-- TODO Haven't tested this so making an educated guess:
-- This is called when mousing over an item in the loot roll window
TooltipHandlers["SetLootRollItem"] = function (tip, slot)
local itemLink = GetLootRollItemLink(slot)
local _, _, itemCount = GetLootRollItemInfo(slot)
Auctionator.Tooltip.ShowTipWithPricing(tip, itemLink, itemCount)
end
-- This is called when mousing over an item in a quest window
TooltipHandlers["SetQuestItem"] = function (tip, type, index)
local itemLink = GetQuestItemLink(type, index)
local _, _, itemCount = GetQuestItemInfo(type, index);
Auctionator.Tooltip.ShowTipWithPricing(tip, itemLink, itemCount)
end
-- This is called when mousing over an item in a quest description in your quest log
TooltipHandlers["SetQuestLogItem"] = function (tip, type, index)
local itemLink = GetQuestLogItemLink(type, index)
local itemCount, _;
if type == "choice" then
_, _, itemCount = GetQuestLogChoiceInfo(index);
else
_, _, itemCount = GetQuestLogRewardInfo(index)
end
Auctionator.Tooltip.ShowTipWithPricing(tip, itemLink, itemCount)
end
-- This is called when mousing over an item in the send mail window
TooltipHandlers["SetSendMailItem"] = function (tip, id)
local _, _, _, itemCount = GetSendMailItem(id)
local itemLink = GetSendMailItemLink(id);
Auctionator.Tooltip.ShowTipWithPricing(tip, itemLink, itemCount)
end
-- This occurs when:
-- 1. mousing over an item in the Open Mail frame
-- 2. mousing over an item in the Inbox frame
TooltipHandlers["SetInboxItem"] = function(tip, index, attachIndex)
if Auctionator.Config.Get(Auctionator.Config.Options.MAILBOX_TOOLTIPS) then
local attachmentIndex = attachIndex or 1
local itemLink = GetInboxItemLink(index, attachmentIndex)
local _, _, _, itemCount = GetInboxItem(index, attachmentIndex);
Auctionator.Tooltip.ShowTipWithPricing(tip, itemLink, itemCount)
end
end
-- This occurs when mousing over an item in the Inbox frame
hooksecurefunc("InboxFrameItem_OnEnter",
function(self)
local itemCount = select(8, GetInboxHeaderInfo(self.index))
local tooltipEnabled =
Auctionator.Config.Get(Auctionator.Config.Options.MAILBOX_TOOLTIPS) and (
Auctionator.Config.Get(Auctionator.Config.Options.VENDOR_TOOLTIPS) or
Auctionator.Config.Get(Auctionator.Config.Options.AUCTION_TOOLTIPS) or
Auctionator.Config.Get(Auctionator.Config.Options.ENCHANT_TOOLTIPS)
)
if tooltipEnabled and itemCount and itemCount > 1 then
local itemEntries = {}
local name, itemCount, itemLink, _
for attachmentIndex = 1, ATTACHMENTS_MAX_RECEIVE do
name, _, _, itemCount = GetInboxItem(self.index, attachmentIndex)
if name then
itemLink = GetInboxItemLink(self.index, attachmentIndex)
table.insert(itemEntries, {
link = itemLink,
count = itemCount,
name = name
})
end
end
Auctionator.Tooltip.ShowTipWithMultiplePricing(GameTooltip, itemEntries)
end
end
);
-- Occurs when mousing over items I'm trading
TooltipHandlers["SetTradePlayerItem"] = function (tip, id)
local itemLink = GetTradePlayerItemLink(id)
if itemLink ~= nil then
local _, _, itemCount = GetTradePlayerItemInfo(id);
Auctionator.Tooltip.ShowTipWithPricing(tip, itemLink, itemCount)
end
end
-- Occurs when mousing over items other player are trading
TooltipHandlers["SetTradeTargetItem"] = function (tip, id)
local itemLink = GetTradeTargetItemLink(id)
if itemLink ~= nil then
local _, _, itemCount = GetTradeTargetItemInfo(id)
Auctionator.Tooltip.ShowTipWithPricing(tip, itemLink, itemCount)
end
end
if GameTooltip.SetAuctionItem then
TooltipHandlers["SetAuctionItem"] = function(tip, viewType, index)
local itemCount = select(3, GetAuctionItemInfo(viewType, index))
local itemLink = GetAuctionItemLink(viewType, index)
Auctionator.Tooltip.ShowTipWithPricing(tip, itemLink, itemCount)
end
end
if GameTooltip.SetItemKey then
TooltipHandlers["SetItemKey"] = function(tip, itemID, itemLevel, itemSuffix)
local itemLink
if C_TooltipInfo then
local info = C_TooltipInfo and C_TooltipInfo.GetItemKey(itemID, itemLevel, itemSuffix)
if info == nil then
return
end
itemLink = info.hyperlink
else
itemLink = select(2, tip:GetItem())
end
if itemLink then
-- Necessary as for recipes the crafted item is returned info.hyperlink,
-- so we check we actually got the recipe item
if C_Item.GetItemInfoInstant(itemLink) ~= itemID then
itemLink = select(2, C_Item.GetItemInfo(itemID))
end
Auctionator.Tooltip.ShowTipWithPricingDBKey(
tip,
Auctionator.Utilities.DBKeyFromBrowseResult({itemKey = {itemID = itemID, itemLevel = itemLevel, itemSuffix = itemSuffix, battlePetSpeciesID = 0}}),
itemLink,
1
)
end
end
end
-- Occurs when mousing over items in the Refer-a-Friend frame, and a few other places
TooltipHandlers["SetItemByID"] = function (tip, itemID)
if not itemID then
return
end
local itemLink = select(2, C_Item.GetItemInfo(itemID))
Auctionator.Tooltip.ShowTipWithPricing(tip, itemLink, 1)
end
-- Occurs mainly with addons (Blizzard and otherwise)
TooltipHandlers["SetHyperlink"] = function (tip, itemLink)
Auctionator.Tooltip.ShowTipWithPricing(tip, itemLink, 1)
end
-- Magic to update the tooltip with the prices when it is cleared and still
-- retain stack size information
if TooltipDataProcessor and C_TooltipInfo then
local function ValidateTooltip(tooltip)
if tooltip == GameTooltip or tooltip == GameTooltipTooltip or tooltip == ItemRefTooltip or tooltip == GarrisonShipyardMapMissionTooltipTooltip then
return true
end
if tooltip:IsForbidden() then
return false
end
local name = tooltip:GetName() or ""
return name:match("^NotGameTooltip") or name:match("^RSMap") -- Standard protocol, or RareScanner
end
TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Item, function(tooltip, data)
if ValidateTooltip(tooltip) then
local info = tooltip.info or tooltip.processingInfo
if not info or not info.getterName or info.excludeLines then
return
end
local handler = TooltipHandlers[info.getterName:gsub("^Get", "Set")]
if handler ~= nil then
handler(tooltip, unpack(info.getterArgs))
end
end
end)
else
-- This occurs when clicking on an item link (i.e. in chat)
hooksecurefunc(ItemRefTooltip, "SetHyperlink", TooltipHandlers["SetHyperlink"])
for func, handler in pairs(TooltipHandlers) do
hooksecurefunc(GameTooltip, func, handler)
end
end
EventUtil.ContinueOnAddOnLoaded("Blizzard_ProfessionsTemplates", function()
local function QualityTooltip(slot, transaction, noInstruction)
local display = {}
local quantities = Professions.GetQuantitiesAllocated(transaction, slot:GetReagentSlotSchematic())
for index, reagentDetails in ipairs(slot:GetReagentSlotSchematic().reagents) do
table.insert(display, {
itemID = reagentDetails.itemID,
quality = C_TradeSkillUI.GetItemReagentQualityByItemInfo(reagentDetails.itemID),
itemCount = quantities[index],
})
end
table.sort(display, function(a, b)
return a.quality < b.quality
end)
Auctionator.Tooltip.AddReagentsAuctionTip(GameTooltip, display)
end
local function OptionalTooltip(item)
end
if Professions.SetupQualityReagentTooltip then
hooksecurefunc(Professions, "SetupQualityReagentTooltip", QualityTooltip)
hooksecurefunc(Professions, "AddCommonOptionalTooltipInfo", function(item)
Auctionator.Tooltip.AddReagentsAuctionTip(GameTooltip, {{itemID = item:GetItemID(), itemCount = 1}})
end)
elseif Professions.SetupReagentQualityPickerTooltip then
hooksecurefunc(Professions, "SetupReagentQualityPickerTooltip", QualityTooltip)
hooksecurefunc(Professions, "SetupOptionalReagentTooltip", function(slot, transaction)
local reagent = slot.Button:GetReagent()
if reagent and reagent.itemID then
Auctionator.Tooltip.AddReagentsAuctionTip(GameTooltip, {{itemID = reagent.itemID, itemCount = 1}})
end
end)
end
end)