-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
MicroMenu.lua
314 lines (267 loc) · 8.19 KB
/
MicroMenu.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
--[[
Copyright (c) 2009-2017, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com >
All rights reserved.
]]
local _, Bartender4 = ...
local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4")
-- register module
local MicroMenuMod = Bartender4:NewModule("MicroMenu", "AceHook-3.0", "AceEvent-3.0")
-- fetch upvalues
local Bar = Bartender4.Bar.prototype
local ButtonBar = Bartender4.ButtonBar.prototype
local pairs, setmetatable, table_insert = pairs, setmetatable, table.insert
local WoWClassic = (WOW_PROJECT_ID ~= WOW_PROJECT_MAINLINE)
local WoWClassicEra = (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC)
local WoW11 = select(4, GetBuildInfo()) >= 110000
-- GLOBALS: CharacterMicroButton, SpellbookMicroButton, TalentMicroButton, AchievementMicroButton, QuestLogMicroButton, GuildMicroButton
-- GLOBALS: LFDMicroButton, CollectionsMicroButton, EJMicroButton, MainMenuMicroButton
-- GLOBALS: HasVehicleActionBar, UnitVehicleSkin, HasOverrideActionBar, GetOverrideBarSkin
local BT_MICRO_BUTTONS
if WoWClassic then
BT_MICRO_BUTTONS = CopyTable(MICRO_BUTTONS)
elseif WoW11 then
BT_MICRO_BUTTONS = {
"CharacterMicroButton",
"ProfessionMicroButton",
"PlayerSpellsMicroButton",
"AchievementMicroButton",
"QuestLogMicroButton",
"GuildMicroButton",
"LFDMicroButton",
"CollectionsMicroButton",
"EJMicroButton",
"StoreMicroButton",
"MainMenuMicroButton",
}
else
BT_MICRO_BUTTONS = {
"CharacterMicroButton",
"SpellbookMicroButton",
"TalentMicroButton",
"AchievementMicroButton",
"QuestLogMicroButton",
"GuildMicroButton",
"LFDMicroButton",
"CollectionsMicroButton",
"EJMicroButton",
"StoreMicroButton",
"MainMenuMicroButton",
}
end
-- create prototype information
local MicroMenuBar = setmetatable({}, {__index = ButtonBar})
local defaults = { profile = Bartender4.Util:Merge({
enabled = true,
vertical = false,
visibility = {
possess = false,
},
padding = WoWClassicEra and -3 or (WoWClassic and -4 or 1),
position = {
scale = WoWClassic and 0.8 or 1.0,
},
}, Bartender4.ButtonBar.defaults) }
function MicroMenuMod:OnInitialize()
self.db = Bartender4.db:RegisterNamespace("MicroMenu", defaults)
self:SetEnabledState(self.db.profile.enabled)
end
function MicroMenuMod:OnEnable()
if not self.bar then
self.bar = setmetatable(Bartender4.ButtonBar:Create("MicroMenu", self.db.profile, L["Micro Menu"], true), {__index = MicroMenuBar})
local buttons = {}
-- remove the LFG button on classic era
if WoWClassicEra then
tDeleteItem(BT_MICRO_BUTTONS, "LFGMicroButton")
end
for i=1, #BT_MICRO_BUTTONS do
local button = _G[BT_MICRO_BUTTONS[i]]
if button then
table_insert(buttons, button)
end
end
self.bar.buttons = buttons
-- check if its owned by the UI on initial load
if MicroMenu then
self.ownedByUI = (MicroMenu:GetParent() ~= UIParent)
if not self.ownedByUI then
for i,v in pairs(buttons) do
v:SetParent(self.bar)
end
end
elseif self.bar.buttons[1]:GetParent() ~= MainMenuBarArtFrame then
self.ownedByUI = true
end
MicroMenuMod.button_count = #buttons
self.bar.anchors = {}
for i,v in pairs(buttons) do
self.bar.anchors[i] = { v:GetPoint() } -- Save orig button anchors.
v:SetFrameLevel(self.bar:GetFrameLevel() + 1)
v.ClearSetPoint = self.bar.ClearSetPoint
end
end
self:SecureHook("UpdateMicroButtons", "MicroMenuBarShow")
if UpdateMicroButtonsParent then
self:SecureHook("UpdateMicroButtonsParent")
UpdateMicroButtonsParent(self.bar)
end
if MicroMenu then
self:SecureHook(MicroMenu, "SetParent", "MicroMenuSetParent")
end
self:SecureHook("ActionBarController_UpdateAll")
if C_PetBattles then
self:RegisterEvent("PET_BATTLE_CLOSE")
end
self.bar:Enable()
self:ToggleOptions()
self:ApplyConfig()
self:MicroMenuBarShow()
end
function MicroMenuMod:ApplyConfig()
self.bar:ApplyConfig(self.db.profile)
end
function MicroMenuMod:RestoreMicroButtonParent()
if UpdateMicroButtonsParent then
UpdateMicroButtonsParent(self.bar)
end
if MicroMenu then
MicroMenu:SetParent(UIParent)
end
end
function MicroMenuMod:PET_BATTLE_CLOSE()
self:RestoreMicroButtonParent()
self:MicroMenuBarShow()
end
function MicroMenuMod:ActionBarController_UpdateAll()
if self.ownedByUI and ActionBarController_GetCurrentActionBarState() == LE_ACTIONBAR_STATE_MAIN and not (C_PetBattles and C_PetBattles.IsInBattle()) then
self:RestoreMicroButtonParent()
self:MicroMenuBarShow()
end
end
function MicroMenuMod:MicroMenuSetParent(_, parent)
if parent == UIParent then
for i,v in pairs(self.bar.buttons) do
v:SetParent(self.bar)
end
self.ownedByUI = false
self:MicroMenuBarShow()
return
end
for i,v in pairs(self.bar.buttons) do
v:SetParent(MicroMenu)
end
self.ownedByUI = true
MicroMenu.oldGridSettings = nil -- reset grid settings so that layout always runs
end
function MicroMenuMod:UpdateMicroButtonsParent(parent)
-- our own parent, ignore
if parent == self.bar then
self.ownedByUI = false
return
end
-- any other parent then MainMenuBarArtFrame means its taken over by the Override bar or the PetBattleFrame
if parent and ((Bartender4.db.profile.blizzardVehicle and parent == OverrideActionBar) or parent == (PetBattleFrame and PetBattleFrame.BottomFrame.MicroButtonFrame)) then
self.ownedByUI = true
self:BlizzardBarShow()
return
end
self.ownedByUI = false
self:MicroMenuBarShow()
end
function MicroMenuMod:MicroMenuBarShow()
-- Only "fix" button anchors if another frame that uses the MicroButtonBar isn't active.
if not self.ownedByUI then
if UpdateMicroButtonsParent then
UpdateMicroButtonsParent(self.bar)
end
self.bar:UpdateButtonLayout()
end
end
function MicroMenuMod:BlizzardBarShow()
-- Only reset button positions not set in MoveMicroButtons()
for i,v in pairs(self.bar.buttons) do
if v ~= CharacterMicroButton and v ~= LFDMicroButton then
v:ClearSetPoint(unpack(self.bar.anchors[i]))
end
end
end
if WoWClassic then
MicroMenuBar.button_width = 29
MicroMenuBar.button_height = 58
MicroMenuBar.vpad_offset = -20
else
MicroMenuBar.button_width = 32
MicroMenuBar.button_height = 40
MicroMenuBar.vpad_offset = 0
MicroMenuBar.hpad_offset = WoW11 and -8 or 0
end
function MicroMenuBar:ApplyConfig(config)
ButtonBar.ApplyConfig(self, config)
if not self.config.position.x then
self:ClearSetPoint("CENTER", -105, 30)
self:SavePosition()
end
self:UpdateButtonLayout()
end
if HelpMicroButton and StoreMicroButton then
function MicroMenuBar:UpdateButtonLayout()
ButtonBar.UpdateButtonLayout(self)
-- If the StoreButton is hidden we want to replace it with the Help button
if not StoreMicroButton:IsShown() then
HelpMicroButton:Show()
HelpMicroButton:ClearAllPoints()
HelpMicroButton:SetAllPoints(StoreMicroButton)
else
HelpMicroButton:Hide()
HelpMicroButton:ClearAllPoints()
end
end
end
if not WoWClassic and QueueStatusButton then
local QueueStatusMod = Bartender4:NewModule("QueueStatusButtonBar", "AceHook-3.0")
-- create prototype information
local QueueStatusBar = setmetatable({}, {__index = Bar})
local queuedefaults = { profile = Bartender4.Util:Merge({
enabled = true,
visibility = {
possess = false,
},
position = {
x = -315,
y = 150,
point = "BOTTOMRIGHT",
},
}, Bartender4.Bar.defaults) }
function QueueStatusMod:OnInitialize()
self.db = Bartender4.db:RegisterNamespace("QueueStatus", queuedefaults)
self:SetEnabledState(self.db.profile.enabled)
end
function QueueStatusMod:OnEnable()
if not self.bar then
self.bar = setmetatable(Bartender4.Bar:Create("QueueStatus", self.db.profile, L["Queue Status"], 1), {__index = QueueStatusBar})
self.bar:SetSize(45, 45)
self.bar.content = QueueStatusButton
self.bar.content:SetParent(self.bar)
end
self:SecureHook(QueueStatusButton, "UpdatePosition", "UpdateLayout")
self.bar:Enable()
self:ToggleOptions()
self:ApplyConfig()
end
function QueueStatusMod:ApplyConfig()
self.bar:ApplyConfig(self.db.profile)
end
function QueueStatusMod:UpdateLayout()
self.bar:PerformLayout()
end
function QueueStatusBar:ApplyConfig(config)
Bar.ApplyConfig(self, config)
self:PerformLayout()
end
QueueStatusBar.width = 45
QueueStatusBar.height = 45
function QueueStatusBar:PerformLayout()
local bar = self.content
bar:ClearAllPoints()
bar:SetPoint("TOPLEFT", self, "TOPLEFT", 0, 0)
end
end