-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompat.lua
More file actions
338 lines (311 loc) · 8.98 KB
/
Compat.lua
File metadata and controls
338 lines (311 loc) · 8.98 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
local addonName, Peddler = ...
-- Full bag addon compatibility & icon overlays restored
if not Peddler then Peddler = {} end
--------------------------------------------------
-- Local references
--------------------------------------------------
local GetContainerNumSlots = GetContainerNumSlots
local GetContainerItemLink = GetContainerItemLink
local GetItemInfo = GetItemInfo
local IsAddOnLoaded = IsAddOnLoaded
--------------------------------------------------
-- Icon helpers
--------------------------------------------------
local function EnsureSellTexture(btn)
if not btn or btn.coins then return end
local tex = btn:CreateTexture(nil,"OVERLAY")
tex:SetTexture("Interface\\AddOns\\Peddler\\coins")
local px,py=-3,1
if IconPlacement and IconPlacement:find("TOP") then py=-3 end
if IconPlacement and IconPlacement:find("LEFT") then px=1 end
tex:SetPoint(IconPlacement or "BOTTOMLEFT", px, py)
btn.coins = tex
end
local function EnsureDeleteTexture(btn)
if not btn or btn.coins_delete then return end
local tex = btn:CreateTexture(nil,"OVERLAY")
tex:SetTexture("Interface\\AddOns\\Peddler\\coins_delete")
local px,py=-3,1
if IconPlacement and IconPlacement:find("TOP") then py=-3 end
if IconPlacement and IconPlacement:find("LEFT") then px=1 end
tex:SetPoint(IconPlacement or "BOTTOMLEFT", px, py)
btn.coins_delete = tex
end
local function DisplayItemIcons(itemID, unique, btn)
if not btn then return end
if not unique then
if btn.coins then btn.coins:Hide() end
if btn.coins_delete then btn.coins_delete:Hide() end
return
end
if Peddler.itemIsToBeSold(itemID, unique) then
EnsureSellTexture(btn)
btn.coins:Show()
elseif btn.coins then
btn.coins:Hide()
end
if ItemsToDelete and ItemsToDelete[unique] and Peddler.ItemDelete.IsUnsellable(itemID) then
EnsureDeleteTexture(btn)
btn.coins_delete:Show()
elseif btn.coins_delete then
btn.coins_delete:Hide()
end
end
local function CheckItem(bag, slot, btn)
if not btn then return end
local link = GetContainerItemLink(bag, slot)
if not link then
DisplayItemIcons(nil, nil, btn)
return
end
local itemID, unique = Peddler.ParseItemLink(link)
if itemID then
DisplayItemIcons(itemID, unique, btn)
else
DisplayItemIcons(nil, nil, btn)
end
end
local function CheckButton(btn)
local bag, slot
if Peddler.GetButtonBagSlot then
bag, slot = Peddler.GetButtonBagSlot(btn)
end
if bag and slot then
CheckItem(bag, slot, btn)
end
end
--------------------------------------------------
-- Individual addon scanners (ported from original)
--------------------------------------------------
local function markBagginsBags()
local Baggins = _G.Baggins
if not (Baggins and Baggins.bagframes) then return end
for _, bag in ipairs(Baggins.bagframes) do
if bag.sections then
for _, section in ipairs(bag.sections) do
if section.items then
for _, btn in ipairs(section.items) do
local parent = btn:GetParent()
if parent then CheckItem(parent:GetID(), btn:GetID(), btn) end
end
end
end
end
end
end
local function markCombuctorBags()
for bag=0,4 do
for slot=1,36 do
local btn=_G["ContainerFrame"..(bag+1).."Item"..slot]
if btn then
CheckButton(btn)
end
end
end
end
local function markDragonUICombuctorBags()
local misses = 0
for itemID = 1, 512 do
local btn = _G["DragonUI_CombuctorItem"..itemID]
if btn then
misses = 0
CheckButton(btn)
else
misses = misses + 1
if misses >= 32 then
break
end
end
end
end
local function markOneBagBags()
for bag=0,4 do
local slots=GetContainerNumSlots(bag)
for slot=1,slots do
local btn=_G["OneBagFrameBag"..bag.."Item"..(slots-slot+1)]
if btn then
local p=btn:GetParent()
if p then CheckItem(p:GetID(), btn:GetID(), btn) end
end
end
end
end
local function markBaudBagBags()
for bag=0,4 do
local slots=GetContainerNumSlots(bag)
for slot=1,slots do
CheckItem(bag, slot, _G["BaudBagSubBag"..bag.."Item"..slot])
end
end
end
local function markAdiBagBags()
local total=0
for bag=0,4 do total=total+GetContainerNumSlots(bag) end
total=math.max(100,total+160)
for i=1,total do
local btn=_G["AdiBagsItemButton"..i]
if btn then
local _, b, s = strsplit('-', tostring(btn))
b=tonumber(b); s=tonumber(s)
if b and s then CheckItem(b,s,btn) end
end
end
end
local function markArkInventoryBags()
for bag=0,4 do
local slots=GetContainerNumSlots(bag)
for slot=1,slots do
CheckItem(bag, slot, _G["ARKINV_Frame1ScrollContainerBag"..(bag+1).."Item"..slot])
end
end
end
local function markfamBagsBags()
for bag=0,4 do
local slots=GetContainerNumSlots(bag)
for slot=1,slots do
CheckItem(bag, slot, _G["famBagsButton_"..bag.."_"..slot])
end
end
end
local function markCargBagsNivayaBags()
local total=0
for bag=0,4 do total=total+GetContainerNumSlots(bag) end
total=total*5
for i=1,total do
local btn=_G["NivayaSlot"..i]
if btn then
local p=btn:GetParent()
if p then CheckItem(p:GetID(), btn:GetID(), btn) end
end
end
end
local function markMonoBags()
local total=0
for bag=0,4 do total=total+GetContainerNumSlots(bag) end
for i=1,total do
local btn=_G["m_BagsSlot"..i]
if btn then
local p=btn:GetParent()
if p then CheckItem(p:GetID(), btn:GetID(), btn) end
end
end
end
local function markDerpyBags()
for bag=0,4 do
local slots=GetContainerNumSlots(bag)
for slot=1,slots do
CheckItem(bag, slot, _G["StuffingBag"..bag.."_"..slot])
end
end
end
local function markElvUIBags()
for bag=0,4 do
local slots=GetContainerNumSlots(bag)
for slot=1,slots do
CheckItem(bag, slot, _G["ElvUI_ContainerFrameBag"..bag.."Slot"..slot])
end
end
end
local function markInventorianBags()
for bag=0,NUM_CONTAINER_FRAMES do
for slot=1,36 do
local btn=_G["ContainerFrame"..(bag+1).."Item"..slot]
if btn then
local p=btn:GetParent()
if p then CheckItem(p:GetID(), btn:GetID(), btn) end
end
end
end
end
local function markLiteBagBags()
if not _G.LiteBagInventoryPanel or not LiteBagInventoryPanel.itemButtons then return end
for _, btn in pairs(LiteBagInventoryPanel.itemButtons) do
if btn then
local p=btn:GetParent()
if p then CheckItem(p:GetID(), btn:GetID(), btn) end
end
end
end
local function markLUIBags()
for bag=0,4 do
local slots=GetContainerNumSlots(bag)
for slot=1,slots do
CheckItem(bag, slot, _G["LUIBags_Item"..bag.."_"..slot])
end
end
end
local function markSortedItems()
for bag=0,4 do
local slots=GetContainerNumSlots(bag)
for slot=1,slots do
CheckItem(bag, slot, _G["SortedSlot_Bag"..bag.."Item"..slot.."FavoriteButton"])
end
end
end
local function markNormalBags()
for bag=0,4 do
local frame=_G["ContainerFrame"..(bag+1)]
if frame and frame:IsShown() then
local slots=GetContainerNumSlots(bag)
for slot=1,slots do
local btn=_G["ContainerFrame"..(bag+1).."Item"..(slots-slot+1)]
if btn then
local p=btn:GetParent()
if p then CheckItem(p:GetID(), btn:GetID(), btn) end
end
end
end
end
end
--------------------------------------------------
-- Public MarkWares (used by core OnUpdate driver)
--------------------------------------------------
function Peddler.MarkWares()
if IsAddOnLoaded("Baggins") then
markBagginsBags()
elseif _G.DragonUI_CombuctorFrame1 or _G.DragonUI_CombuctorItem1 then
markDragonUICombuctorBags()
elseif IsAddOnLoaded("Combuctor") or IsAddOnLoaded("Bagnon") then
markCombuctorBags()
elseif IsAddOnLoaded("OneBag3") then
markOneBagBags()
elseif IsAddOnLoaded("BaudBag") then
markBaudBagBags()
elseif IsAddOnLoaded("AdiBags") then
markAdiBagBags()
elseif IsAddOnLoaded("ArkInventory") then
markArkInventoryBags()
elseif IsAddOnLoaded("famBags") then
markfamBagsBags()
elseif IsAddOnLoaded("cargBags_Nivaya") then
markCargBagsNivayaBags()
elseif IsAddOnLoaded("m_Bags") then
markMonoBags()
elseif IsAddOnLoaded("DerpyStuffing") then
markDerpyBags()
elseif IsAddOnLoaded("Inventorian") then
markInventorianBags()
elseif IsAddOnLoaded("LiteBag") then
markLiteBagBags()
elseif IsAddOnLoaded("LUI") and _G["LUIBags_Item0_1"] then
markLUIBags()
elseif IsAddOnLoaded("Sorted") then
markSortedItems()
elseif IsAddOnLoaded("ElvUI") then
markElvUIBags()
else
markNormalBags()
end
end
--------------------------------------------------
-- Optional addon specific hook registration
--------------------------------------------------
function Peddler.CompatRegister()
if IsAddOnLoaded("Baggins") and _G.Baggins and _G.Baggins.RegisterSignal and not Peddler._bagginsRegistered then
Peddler._bagginsRegistered = true
_G.Baggins:RegisterSignal("Baggins_BagOpened", function()
-- Force one immediate re-mark on next OnUpdate cycle (core will drive)
if Peddler.MarkWares then Peddler.MarkWares() end
end, _G.Baggins)
end
end