-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMasqueBlizzInv.lua
497 lines (430 loc) · 16.1 KB
/
MasqueBlizzInv.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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
--
-- Masque Blizzard Inventory
-- Enables Masque to skin the built-in inventory UI
--
-- Copyright 2022 - 2024 SimGuy
--
-- Use of this source code is governed by an MIT-style
-- license that can be found in the LICENSE file or at
-- https://opensource.org/licenses/MIT.
--
local _, Shared = ...
-- From Locales/Locales.lua
-- Not used yet
--local L = Shared.Locale
-- From Metadata.lua
local Metadata = Shared.Metadata
local Groups = Metadata.Groups
local Callbacks = Metadata.OptionCallbacks
-- From Core.lua
local Core = Shared.Core
-- Push us into shared object
local Addon = {}
Shared.Addon = Addon
-- Handle events for buttons that get created dynamically by Blizzard
function Addon:HandleEvent(event, target)
local frame
-- Handle Classic Era Bank
if event == "BANKFRAME_OPENED" then
event = "PLAYER_INTERACTION_MANAGER_FRAME_SHOW"
target = 8
end
-- This handles Character Inspection
if event == "INSPECT_READY" and InspectPaperDollFrame then
frame = Groups.InspectPaperDollFrame
--print("skinning:", frame.Title, frame.Skinned)
if not frame.Skinned then
Core:Skin(frame.Buttons, frame.Group)
frame.Skinned = true
end
end
-- This handles Cataclysm Classic or later
if event == "PLAYER_INTERACTION_MANAGER_FRAME_SHOW" then
if target == 8 then -- Bank
frame = Groups.BankFrame
Addon:Options_BankFrame_Update()
elseif target == 10 then -- Guild Bank
frame = Groups.GuildBankFrame
Addon:Options_GuildBankFrame_Update()
elseif target == 26 then -- Void Storage
frame = Groups.VoidStorageFrame
Addon:Options_VoidStorageFrame_Update()
end
if not frame then
--print("unknown frame", target)
return
end
--print("skinning:", frame.Title, frame.Skinned)
if not frame.Skinned then
Core:Skin(frame.Buttons, frame.Group)
frame.Skinned = true
end
end
end
-- Retail Bags are mapped in this way:
-- * ContainerFrameCombinedBags is always the Combined Backpack
-- * ContainerFrame1 is always standard Backpack
-- * ContainerFrame2 - 5 are the Held Bags
-- * ContainerFrame6 is always Reagent Bag
-- * ContainerFrame7 - 13 are the Bank Bags
--
-- Held and Bank bags use whichever frame is next available and not
-- already showing when they are opened. This means that Bank Bag
-- 7 could use Frame7 if opened first, or Frame13 if opened after
-- all other bags, so each time a bag is opened we need to check if
-- all its buttons are skinned and skin the ones that are new.
--
-- If the Combined Backpack appears in 10.0, it just adds all the other
-- buttons to itself from their true parents, and sets its size to 0,
-- so we'll have to simulate skinning the bags one by one. In 11.0,
-- the Combined Backpack uses an itemButtonPool of its own.
--
-- However, if this is Classic then we just treat all bags the same
-- because the frames get reused arbitrarily depending on which opens
-- first.
function Addon:ContainerFrame_GenerateFrame(slots, target, parent)
-- Work on whichever frame Blizzard is giving us
if self and not parent then
parent = self
elseif not parent then
return
end
local frame = parent:GetName()
local frameitem = frame .. "Item"
local group
-- If this is the Combined Bag, simulate skinning the bags one by one
if frame == "ContainerFrameCombinedBags" and Core:CheckVersion({ nil, 110000 }) then
--print("bag combined:", frame, slots, target)
for i = 1, 5 do
-- Figure out the number of slots in each bag
local bagslots = C_Container.GetContainerNumSlots(i-1)
Addon:ContainerFrame_GenerateFrame(bagslots, i-1, _G["ContainerFrame"..i])
end
return
end
-- Skip processing if the bag has no slots
if slots == 0 and frame ~= "ContainerFrameCombinedBags" then return end
--print("bag update:", frame, slots, target)
-- Identify which group this bag belongs to by ID or name
if target >= 13 then -- We don't know about this bag
print("MBI Error: Unknown bag opened", frame, slots, target)
return
elseif Core:CheckVersion({ nil, 100000 }) then
group = Groups.ContainerFrameClassic
elseif target >= 6 then -- This is a bank bag
group = Groups.BankContainerFrames
elseif target >= 1 and target < 5 then -- This is a held (main) bag
group = Groups.ContainerFrames
else -- This frame matches its name (reagent, backpack, combined)
group = Groups[frame]
end
Core:Skin(group.Buttons, group.Group, frameitem, slots)
if group.ButtonPools then
Core:SkinButtonPool(group.ButtonPools, group.Group)
end
end
-- Skin the ReagentBank and AccountBank the first time the user opens them.
-- There's no event to capture and it doesn't exist on initial bank open.
function Addon:BankFrame_ShowPanel()
local rbframe = Groups.ReagentBankFrame
if BankFrame.activeTabIndex == 2 then
Addon:Options_ReagentBankFrame_Update()
if not rbframe.Skinned then
Core:Skin(rbframe.Buttons, rbframe.Group)
rbframe.Skinned = true
end
end
local abframe = Groups.AccountBankPanel
if BankFrame.activeTabIndex == 3 then
Addon:Options_AccountBankPanel_Update()
Core:SkinButtonPool(abframe.ButtonPools, abframe.Group)
end
end
-- Update the visibility of Bank elements based on settings
function Addon:Options_BankFrame_Update()
-- This only works on Retail due to frame design
if not Core:CheckVersion({ 100000, nil }) then return end
local show = not Core:GetOption('BankFrameHideSlots')
local frame = BankSlotsFrame
-- This is the texture map used for bank slot artwork
local texture = 590156
-- Find regions that use the texture and hide (or show) them
if frame then
for i = 1, select("#", frame:GetRegions()) do
local child = select(i, frame:GetRegions())
if type(child) == "table" and child.GetTexture and child:GetTexture() == texture then
child:SetShown(show)
end
end
end
end
-- Update the visibility of Reagent Bank elements based on settings
function Addon:Options_ReagentBankFrame_Update()
-- This only works on Retail due to frame design
if not Core:CheckVersion({ 100000, nil }) then return end
local show = not Core:GetOption('ReagentBankFrameHideSlots')
local frame = ReagentBankFrame
-- This is the texture map used for reagent bank slot artwork
local texture = 997675
-- Find regions that use the texture and hide (or show) them
if frame then
for i = 1, select("#", frame:GetRegions()) do
local child = select(i, frame:GetRegions())
if type(child) == "table" and child.GetTexture and child:GetTexture() == texture then
child:SetShown(show)
end
end
end
end
-- Update the visibility of Warband Bank elements based on settings
function Addon:Options_AccountBankPanel_Update()
-- This only works on Retail due to frame design
if not Core:CheckVersion({ 110000, nil }) then return end
local show = not Core:GetOption('AccountBankPanelHideSlots')
-- Find all the item buttons in the Warband Bank and hide (or show) them
for itemButton in AccountBankPanel.itemButtonPool:EnumerateActive() do
itemButton.Background:SetShown(show)
end
end
-- Update the visibility of Guild Bank elements based on settings
function Addon:Options_GuildBankFrame_Update()
-- This only works on Retail due to frame design
if not Core:CheckVersion({ 100000, nil }) then return end
local show = not Core:GetOption('GuildBankFrameHideSlots')
local showbg = not Core:GetOption('GuildBankFrameHideBackground')
local frame = GuildBankFrame
-- Find regions that use the texture and hide (or show) them
if frame then
for i = 1, 7 do
local column = frame['Column' .. i]
if column and column.Background then
column.Background:SetShown(show)
end
end
if frame.BlackBG then
frame.BlackBG:SetShown(showbg)
end
end
end
-- Update the visibility of Void Storage elements based on settings
function Addon:Options_VoidStorageFrame_Update()
-- This only works on Retail due to frame design
if not Core:CheckVersion({ 100000, nil }) then return end
local show = not Core:GetOption('VoidStorageFrameHideSlots')
local buttons = Groups.VoidStorageFrame.Buttons
-- Find regions that use the texture and hide (or show) them
for button, count in pairs(buttons) do
for i = 1, count do
local bg = _G[button .. i .. "Bg"]
if bg then
bg:SetShown(show)
end
end
end
end
-- Update the visibility of Equipment Flyout Frame background based on settings
function Addon:Options_EquipmentFlyout_Show()
-- This frame only exists on Retail
if not Core:CheckVersion({ 100000, nil }) then return end
local show = not Core:GetOption('EquipmentFlyoutFrameHideSlots')
local frame = EquipmentFlyoutFrameButtons
if not show then
local i = 1
while frame['bg' .. i] do
frame['bg' .. i]:Hide()
i = i + 1
end
end
end
-- Update the visibility of Mail elements based on settings
function Addon:Options_MailFrame_Update()
-- This only works on Retail due to frame design
if not Core:CheckVersion({ 100000, nil }) then return end
local showbg = not Core:GetOption('MailFrameHideInboxBackground')
local showinbox = not Core:GetOption('MailFrameHideInboxSlots')
local showsend = not Core:GetOption('MailFrameHideSendSlots')
-- Find regions that use the texture and hide (or show) them
for i = 1, INBOXITEMS_TO_DISPLAY do
-- There is slot artwork in the parent frame
local frame = _G['MailItem' .. i]
local texture = 136383
-- Find regions that use the texture and hide (or show) them
if frame then
for r = 1, select("#", frame:GetRegions()) do
local child = select(r, frame:GetRegions())
if type(child) == "table" and child.GetTexture and child:GetTexture() == texture then
child:SetShown(showbg)
end
end
end
-- The button's also got slot artwork
local slot = _G['MailItem' .. i .. 'ButtonSlot']
if slot then
slot:SetShown(showinbox)
end
end
for i = 1, Groups.MailFrame.Buttons.SendMailAttachment do
local frame = _G['SendMailAttachment' .. i]
local texture = 130862
-- Find regions that use the texture and hide (or show) them
if frame then
for r = 1, select("#", frame:GetRegions()) do
local child = select(r, frame:GetRegions())
if type(child) == "table" and child.GetTexture and child:GetTexture() == texture then
child:SetShown(showsend)
end
end
end
end
end
-- Fix some weird button behavior upon showing the icons in the Equipment Manager
function Addon:GearManagerDialog_Update()
local bar = Groups.GearManagerDialog
for i = 1, bar.Buttons.GearSetButton do
local button = _G['GearSetButton'..i]
if button.icon:GetTexture() ~= nil then
button.icon:SetAlpha(1)
button.icon:Show()
end
end
end
-- A shared function to handle dynamic flyout allocation
function Addon:HandleFlyout(group, bname, maxslots)
local activeSlots = 0
for slot = 1, maxslots + 1 do
if _G[bname .. slot] then
activeSlots = slot
end
end
-- Skin any extra buttons found
local numButtons = group.Buttons[bname]
if (numButtons < activeSlots) then
for i = numButtons + 1, activeSlots do
-- TODO: Update this to use Core:Skin()
local button = _G[bname .. i]
group.Group:AddButton(button, { Highlight = button.HighlightTexture }, "Item")
end
group.Buttons[bname] = activeSlots
end
end
-- Paper Doll Frame Item Flyout buttons are created as needed when a flyout is opened, so
-- check for any new buttons any time that happens
function Addon:PaperDollFrameItemFlyout_Show()
local group = Groups.PaperDollFrameItemFlyout
Addon:HandleFlyout(group, 'PaperDollFrameItemFlyoutButtons', PDFITEMFLYOUT_MAXITEMS)
end
-- Equipment Flyout buttons are created as needed when a flyout is opened, so
-- check for any new buttons any time that happens
function Addon:EquipmentFlyout_Show()
local group = Groups.EquipmentFlyoutFrame
Addon:HandleFlyout(group, 'EquipmentFlyoutFrameButton', EQUIPMENTFLYOUT_ITEMS_PER_PAGE)
Addon:Options_EquipmentFlyout_Show()
end
-- Locate the LootFrameItems when the LootFrame opens and skin them since
-- they are generated dynamically.
function Addon:LootFrame_Open()
local lfc = LootFrame.ScrollBox.ScrollTarget
local group = Groups.LootFrame
for i = 1, select("#", lfc:GetChildren()) do
local lfi = select(i, lfc:GetChildren())
-- Try not to add buttons that are already added
--
-- I'm not sure if the Frame created for the Loot button is used for
-- the whole life of the UI so if the frame changes, we'll
-- skin whatever replaced it.
if lfi and lfi.Item and lfi.Item:GetObjectType() == "Button" then
local name = lfi:GetDebugName()
if group.State.LootFrameItem[name] ~= lfi then
-- TODO: Update this to use Core:Skin()
group.Group:AddButton(lfi.Item, nil, "Item")
group.State.LootFrameItem[name] = lfi
end
end
end
end
-- When new items are being rendered upon opening the mailbox, sometimes
-- the backdrop frame ends up in front of the icon. Set the draw layer
-- to prevent that.
function Addon:InboxFrame_Update()
Addon:Options_MailFrame_Update()
for i=1, INBOXITEMS_TO_DISPLAY do
local icon = _G["MailItem"..i.."ButtonIcon"]
end
end
-- Blizzard sets the icon non-standardly for SendMailAttachment icons
-- so we have to set the icons for items when the frame updates.
function Addon:SendMailFrame_Update()
local frame = Groups.MailFrame
local button = "SendMailAttachment"
Addon:Options_MailFrame_Update()
for i=1, frame.Buttons[button] do
local icon = _G[button..i].icon
if HasSendMailItem(i) then
local _, _, itemTexture, _, _ = GetSendMailItem(i)
icon:SetTexture(itemTexture or "Interface\\Icons\\INV_Misc_QuestionMark")
else
icon:SetTexture(nil)
end
end
end
-- These are init steps specific to this addon
-- This should be run before Core:Init()
function Addon:Init()
-- All Bag types
hooksecurefunc("ContainerFrame_GenerateFrame",
Addon.ContainerFrame_GenerateFrame)
-- Inbox
hooksecurefunc("InboxFrame_Update",
Addon.InboxFrame_Update)
-- Send Mail
hooksecurefunc("SendMailFrame_Update",
Addon.SendMailFrame_Update)
-- Reagent Bank
if Core:CheckVersion({ 60000, nil }) then
hooksecurefunc("BankFrame_ShowPanel",
Addon.BankFrame_ShowPanel)
end
-- EquipmentFlyout
if Core:CheckVersion({ 40300, nil }) then
hooksecurefunc("EquipmentFlyout_Show",
Addon.EquipmentFlyout_Show)
end
-- LootFrame (Retail only)
if Core:CheckVersion({ 100000, nil }) then
hooksecurefunc(LootFrame, "Open",
Addon.LootFrame_Open)
end
Addon.Events = CreateFrame("Frame")
Addon.Events:RegisterEvent("INSPECT_READY")
if Core:CheckVersion({ nil, 30401 }) then
-- Bank (Classic Era)
Addon.Events:RegisterEvent("BANKFRAME_OPENED")
end
if Core:CheckVersion({ 30401, nil }) then
-- Bank, Guild Bank, and Void Storage
Addon.Events:RegisterEvent("PLAYER_INTERACTION_MANAGER_FRAME_SHOW")
end
Addon.Events:SetScript("OnEvent", Addon.HandleEvent)
if Core:CheckVersion({ 100000, nil }) then
-- Register Callbacks for various options here
Callbacks.BankFrameHideSlots = Addon.Options_BankFrame_Update
Callbacks.ReagentBankFrameHideSlots = Addon.Options_ReagentBankFrame_Update
Callbacks.GuildBankFrameHideSlots = Addon.Options_GuildBankFrame_Update
Callbacks.GuildBankFrameHideBackground = Addon.Options_GuildBankFrame_Update
Callbacks.VoidStorageFrameHideSlots = Addon.Options_VoidStorageFrame_Update
Callbacks.MailFrameHideInboxSlots = Addon.Options_MailFrame_Update
Callbacks.MailFrameHideInboxBackground = Addon.Options_MailFrame_Update
Callbacks.MailFrameHideSendSlots = Addon.Options_MailFrame_Update
Callbacks.EquipmentFlyoutFrameHideSlots = Addon.Options_EquipmentFlyout_Show
if Core:CheckVersion({ 110000, nil }) then
Callbacks.AccountBankPanelHideSlots = Addon.Options_AccountBankPanel_Update
else
Metadata.Options.args.AccountBankPanel = nil
end
else
-- Empty the whole options table because we don't support it on Classic
Metadata.Options = nil
end
end
Addon:Init()
Core:Init()