/
MicroMenu.lua
151 lines (128 loc) · 4.21 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
--[[
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 ButtonBar = Bartender4.ButtonBar.prototype
local pairs, setmetatable, table_insert = pairs, setmetatable, table.insert
local WoWClassic = select(4, GetBuildInfo()) < 20000
-- GLOBALS: CharacterMicroButton, SpellbookMicroButton, TalentMicroButton, AchievementMicroButton, QuestLogMicroButton, GuildMicroButton
-- GLOBALS: LFDMicroButton, CollectionsMicroButton, EJMicroButton, MainMenuMicroButton
-- GLOBALS: HasVehicleActionBar, UnitVehicleSkin, HasOverrideActionBar, GetOverrideBarSkin
local BT_MICRO_BUTTONS = WoWClassic and {
"CharacterMicroButton",
"SpellbookMicroButton",
"TalentMicroButton",
"QuestLogMicroButton",
"SocialsMicroButton",
"WorldMapMicroButton",
"MainMenuMicroButton",
"HelpMicroButton",
}
or
{
"CharacterMicroButton",
"SpellbookMicroButton",
"TalentMicroButton",
"AchievementMicroButton",
"QuestLogMicroButton",
"GuildMicroButton",
"LFDMicroButton",
"CollectionsMicroButton",
"EJMicroButton",
"StoreMicroButton",
"MainMenuMicroButton",
}
-- create prototype information
local MicroMenuBar = setmetatable({}, {__index = ButtonBar})
local defaults = { profile = Bartender4:Merge({
enabled = true,
vertical = false,
visibility = {
possess = false,
},
padding = -3,
position = {
scale = 0.8,
},
}, 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"]), {__index = MicroMenuBar})
local buttons = {}
for i=1, #BT_MICRO_BUTTONS do
table_insert(buttons, _G[BT_MICRO_BUTTONS[i]])
end
self.bar.buttons = buttons
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 OverrideActionBar then
self:SecureHookScript(OverrideActionBar, "OnShow", "BlizzardBarShow")
self:SecureHookScript(OverrideActionBar, "OnHide", "MicroMenuBarShow")
end
if PetBattleFrame then
self:SecureHookScript(PetBattleFrame.BottomFrame.MicroButtonFrame, "OnShow", "BlizzardBarShow")
self:SecureHookScript(PetBattleFrame.BottomFrame.MicroButtonFrame, "OnHide", "MicroMenuBarShow")
end
self.bar:Enable()
self:ToggleOptions()
self:ApplyConfig()
self:MicroMenuBarShow()
end
function MicroMenuMod:ApplyConfig()
self.bar:ApplyConfig(self.db.profile)
end
function MicroMenuMod:MicroMenuBarShow()
-- Only "fix" button anchors if another frame that uses the MicroButtonBar isn't active.
if not ((OverrideActionBar and OverrideActionBar:IsShown()) or (PetBattleFrame and PetBattleFrame:IsShown())) then
UpdateMicroButtonsParent(self.bar)
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
MicroMenuBar.button_width = 28
MicroMenuBar.button_height = 36
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