-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBindsWhen.lua
executable file
·377 lines (323 loc) · 11.1 KB
/
BindsWhen.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
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
--[[--------------------------------------------------------------------
Binds When?
Shows BoA/BoE text on bag items.
Copyright (c) 2015-2017 Phanx <[email protected]>. All rights reserved.
Maintained by Akkorian <[email protected]>
https://github.com/phanx-wow/BindsWhen
https://www.curseforge.com/wow/addons/bindswhen
https://www.wowinterface.com/downloads/info23465-BindsWhen.html
----------------------------------------------------------------------]]
-- Text to show for each binding type
local BoA = "|cffe6cc80BoA|r" -- heirloom item color
local BoE = "|cff1eff00BoE|r" -- uncommon item color
local BoP = false -- not displayed
------------------------------------------------------------------------
-- Map tooltip text to display text
local textForBind = {
[ITEM_ACCOUNTBOUND] = BoA,
[ITEM_BNETACCOUNTBOUND] = BoA,
[ITEM_BIND_TO_ACCOUNT] = BoA,
[ITEM_BIND_TO_BNETACCOUNT] = BoA,
[ITEM_BIND_ON_EQUIP] = BoE,
[ITEM_BIND_ON_USE] = BoE,
[ITEM_SOULBOUND] = BoP,
[ITEM_BIND_ON_PICKUP] = BoP,
}
------------------------------------------------------------------------
-- Which binding types can change during gameplay (BoE)
local temporary = {
[BoE] = true,
}
------------------------------------------------------------------------
-- Tooltip for scanning for Binds on X text
local scanTip = CreateFrame("GameTooltip", "BindsWhenScanTooltip")
for i = 1, 5 do
local L = scanTip:CreateFontString(nil, "OVERLAY", "GameFontNormal")
scanTip:AddFontStrings(L, scanTip:CreateFontString(nil, "OVERLAY", "GameFontNormal"))
scanTip[i] = L
end
------------------------------------------------------------------------
-- Keep a cache of which items are BoA or BoE
local textForItem = {}
local function GetBindText(arg1, arg2)
local link, setTooltip, onlyBoA
if arg1 == "player" then
link = GetInventoryItemLink(arg1, arg2)
setTooltip = scanTip.SetInventoryItem
elseif arg2 then
link = GetContainerItemLink(arg1, arg2)
setTooltip = scanTip.SetBagItem
else
link = arg1
setTooltip = scanTip.SetHyperlink
onlyBoA = true
end
if not link then
return
end
local item = onlyBoA and link or (arg1 .. arg2 .. link)
local text = textForItem[item]
if text then
return text
end
scanTip:SetOwner(WorldFrame, "ANCHOR_NONE")
setTooltip(scanTip, arg1, arg2)
for i = 1, 5 do
local bind = scanTip[i]:GetText()
if bind and strmatch(bind, USE_COLON) then -- ignore recipes
break
end
local text = bind and textForBind[bind]
if text then
if onlyBoA and text ~= BoA then -- don't save BoE text for non-recipe hyperlinks, eg. Bagnon cached items
return
end
textForItem[item] = text
return text
end
end
textForItem[item] = false
end
------------------------------------------------------------------------
-- Clear cached BoE items when confirming to bind something
local function ClearTempCache()
for id, text in pairs(textForItem) do
if temporary[text] then
textForItem[id] = nil
end
end
end
hooksecurefunc("BindEnchant", ClearTempCache)
hooksecurefunc("ConfirmBindOnUse", ClearTempCache)
------------------------------------------------------------------------
-- Add text string to an item button
local function SetItemButtonBindType(button, text)
local bindsOnText = button.bindsOnText
if not text and not bindsOnText then return end
if not text then
return bindsOnText:SetText("")
end
if not bindsOnText then
-- see ItemButtonTemplate.Count @ ItemButtonTemplate.xml#13
bindsOnText = button:CreateFontString(nil, "ARTWORK", "GameFontNormalOutline")
bindsOnText:SetPoint("BOTTOMRIGHT", -5, 2)
button.bindsOnText = bindsOnText
end
bindsOnText:SetText(text)
end
------------------------------------------------------------------------
-- Update default bag and bank frames
hooksecurefunc("ContainerFrame_Update", function(frame)
local bag = frame:GetID()
local name = frame:GetName()
for i = 1, frame.size do
local button = _G[name.."Item"..i]
local slot = button:GetID()
local text = not button.Count:IsShown() and GetBindText(bag, slot)
SetItemButtonBindType(button, text)
end
end)
hooksecurefunc("BankFrameItemButton_Update", function(button)
local bag = button.isBag and -4 or button:GetParent():GetID()
local slot = button:GetID()
local text = not button.Count:IsShown() and GetBindText("player", button:GetInventorySlot())
SetItemButtonBindType(button, text)
end)
------------------------------------------------------------------------
-- Addon support
local addons = {}
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", function(f, e, name)
for i = #addons, 1, -1 do
if not addons[i](name) then
tremove(addons, i)
end
end
if #addons == 0 then
f:UnregisterAllEvents()
f:SetScript("OnEvent", nil)
f, addons = nil, nil
else
f:RegisterEvent("ADDON_LOADED")
end
end)
------------------------------------------------------------------------
-- AdiBags
-- https://www.wowace.com/addons/adibags/
tinsert(addons, function(name)
local AdiBags = LibStub and LibStub("AceAddon-3.0", true) and LibStub("AceAddon-3.0"):GetAddon("AdiBags", true)
if not AdiBags then return true end
local ItemButton = AdiBags:GetClass("ItemButton")
hooksecurefunc(ItemButton.prototype, "Update", function(self)
local text
if self.inventorySlot then
text = not self.Count:IsShown() and GetBindText("player", self.inventorySlot)
else
text = not self.Count:IsShown() and GetBindText(self.bag, self.slot)
end
SetItemButtonBindType(self, text)
end)
end)
------------------------------------------------------------------------
-- Backpack
-- https://www.curseforge.com/wow/addons/backpack
-- https://wowinterface.com/downloads/info16997
tinsert(addons, function()
if not Backpack then return true end
Backpack:On("PostUpdateSlot", function(button)
local count = button.itemCount
local text = (not count or count < 2) and GetBindText(button.bagID, button.slotID)
SetItemButtonBindType(button, text)
end)
end)
------------------------------------------------------------------------
-- Bagnon
-- https://wow.curseforge.com/addons/bagnon/
-- https://wow.curseforge.com/addons/combuctor/
local function UpdateBagnonItemSlot(self)
local bag = self.bag
if type(bag) ~= "number" then return end
local text
local link = self.hasItem
if link and not self.Count:IsShown() then
if self:IsCached() then
if type(link) == "string" then
if strfind(link, "battlepet:") then
-- Caged battle pets don't bind and don't stack
text = BoE
else
text = GetBindText(link)
end
end
else
local slot = self:GetID()
local getInvSlot = bag == BANK_CONTAINER and BankButtonIDToInvSlotID or bag == REAGENTBANK_CONTAINER and ReagentBankButtonIDToInvSlotID
if getInvSlot then
text = GetBindText("player", getInvSlot(slot))
else
text = GetBindText(bag, slot)
end
end
end
SetItemButtonBindType(self, text)
end
tinsert(addons, function()
local addon = Bagnon or Combuctor
if not addon then return true end
local CreateItemSlot = addon.ItemSlot.Create
function addon.ItemSlot:Create()
local button = CreateItemSlot(self)
hooksecurefunc(button, "Update", UpdateBagnonItemSlot)
return button
end
end)
------------------------------------------------------------------------
-- cargBags
-- https://www.wowinterface.com/downloads/info22329-cargBagsNivayaRealUIstandalone.html
tinsert(addons, function(name)
local cargBags = _G[name and GetAddOnMetadata(name, "X-cargBags") or "cargBags"]
if not cargBags and not name then
for i = 1, GetNumAddOns() do
local global = GetAddOnMetadata(i, "X-cargBags")
if global then
cargBags = _G[global]
break
end
end
end
if not cargBags then return true end
local function UpdateItemButton(self, item)
local text
if item and not self.Count:IsShown() then
if not self.bindsOnText then
local bindsOnText = self:CreateFontString(nil, "ARTWORK")
bindsOnText:SetPoint("BOTTOMRIGHT", self.BottomString)
bindsOnText:SetFont(self.BottomString:GetFont())
self.bindsOnText = bindsOnText
end
text = GetBindText(item.bagID, item.slotID)
if text and self.BottomString:IsShown() then
self.BottomString:SetText("")
end
end
SetItemButtonBindType(self, text)
end
local hooked = {}
local Implementation = cargBags.classes.Implementation
hooksecurefunc(Implementation, "UpdateSlot", function(self, bagID, slotID)
local button = self:GetButton(bagID, slotID)
if button and button.Update and not hooked[button] then
hooksecurefunc(button, "Update", UpdateItemButton)
hooked[button] = true
button:Update(button:GetItemInfo())
end
end)
end)
------------------------------------------------------------------------
-- DerpyStuffing
-- https://www.wowinterface.com/downloads/info22500-DerpyStuffingAuroraOneBags.html
tinsert(addons, function()
if not Stuffing then return true end
hooksecurefunc(Stuffing, "SlotUpdate", function(self, b)
local button = b.frame
if not button.bindsOnText then
local bindsOnText = button:CreateFontString(nil, "ARTWORK")
bindsOnText:SetPoint("TOPRIGHT", button.Count)
bindsOnText:SetFont(button.Count:GetFont())
button.bindsOnText = bindsOnText
end
local bag = b.bag
local slot = b.slot
--print("SlotUpdate", bag, slot)
local text = not button.Count:IsShown() and GetBindText(bag, slot)
SetItemButtonBindType(button, text)
end)
end)
------------------------------------------------------------------------
-- Inventorian
-- https://wow.curseforge.com/addons/inventorian/
tinsert(addons, function(name)
local Inventorian = LibStub and LibStub("AceAddon-3.0", true) and LibStub("AceAddon-3.0"):GetAddon("Inventorian", true)
if not Inventorian then return end
hooksecurefunc(Inventorian.Item.prototype, "Update", function(button)
local text = not button.Count:IsShown() and GetBindText(button.bag, button.slot)
SetItemButtonBindType(button, text)
end)
end)
------------------------------------------------------------------------
-- LiteBag
-- https://wow.curseforge.com/addons/litebag/
tinsert(addons, function(name)
if not LiteBagItemButton_Update then return true end
hooksecurefunc("LiteBagItemButton_Update", function(button)
local slot = button:GetID()
local bag = button:GetParent():GetID()
local text = not button.Count:IsShown() and GetBindText(bag, slot)
SetItemButtonBindType(button, text)
end)
end)
------------------------------------------------------------------------
-- ElvUI
-- http://www.tukui.org/dl.php
tinsert(addons, function()
if not ElvUI then return true end
local Bags = LibStub("AceAddon-3.0"):GetAddon("ElvUI"):GetModule("Bags")
hooksecurefunc(Bags, "UpdateSlot", function(self, bag, slot)
local button = self.Bags[bag][slot]
local text = not button.Count:IsShown() and GetBindText(bag, slot)
SetItemButtonBindType(button, text)
end)
end)
------------------------------------------------------------------------
-- TukUI
-- http://www.tukui.org/dl.php
tinsert(addons, function()
if not Tukui then return true end
hooksecurefunc(Tukui[2].Inventory.Bags, "SlotUpdate", function(self, bag, button)
local slot = button:GetID()
local _, count = GetContainerItemInfo(bag, slot)
local text = (not count or count < 2) and GetBindText(bag, slot)
SetItemButtonBindType(button, text)
end)
end)