-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuBar.lua
More file actions
175 lines (149 loc) · 4.92 KB
/
Copy pathMenuBar.lua
File metadata and controls
175 lines (149 loc) · 4.92 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
local _G = getfenv(0)
local ceil = math.ceil
local min = math.min
local max = math.max
local pairs = pairs
local ipairs = ipairs
local type = type
local InCombatLockdown = InCombatLockdown
local combatQueue = {}
local queueFrame = CreateFrame('Frame')
queueFrame:RegisterEvent('PLAYER_REGEN_ENABLED')
queueFrame:SetScript('OnEvent', function()
for key, func in pairs(combatQueue) do
local success, err = pcall(func)
if not success then
geterrorhandler()(err)
end
combatQueue[key] = nil
end
end)
local function Enqueue(key, func)
combatQueue[key] = func
end
local menuButtons = {}
do
local function LoadDynamicButtons()
menuButtons = {}
for name, obj in pairs(_G) do
if type(obj) == "table" and type(obj.GetObjectType) == "function" then
if obj:GetObjectType() == "Button" or obj:GetObjectType() == "CheckButton" then
if name:match('(%w+)MicroButton$') and name ~= 'FriendsMicroButton' and obj:IsVisible() then
table.insert(menuButtons, obj)
end
end
end
end
table.sort(menuButtons, function(a, b)
local aX = a:GetLeft() or 0
local bX = b:GetLeft() or 0
return aX < bX
end)
end
LoadDynamicButtons()
if TalentMicroButton then
TalentMicroButton:SetScript('OnEvent', function(self, event)
if (event == 'PLAYER_LEVEL_UP' or event == 'PLAYER_LOGIN') then
if UnitCharacterPoints('player') > 0 and not CharacterFrame:IsShown() then
SetButtonPulse(self, 60, 1)
end
elseif event == 'UPDATE_BINDINGS' then
self.tooltipText = MicroButtonTooltipText(TALENTS_BUTTON, 'TOGGLETALENTS')
end
end)
TalentMicroButton:UnregisterAllEvents()
TalentMicroButton:RegisterEvent('PLAYER_LEVEL_UP')
TalentMicroButton:RegisterEvent('PLAYER_LOGIN')
TalentMicroButton:RegisterEvent('UPDATE_BINDINGS')
end
if AchievementMicroButton then
AchievementMicroButton:UnregisterAllEvents()
end
end
local MenuBar = CleanBars:CreateClass('Frame', CleanBars.Frame)
CleanBars.MenuBar = MenuBar
function MenuBar:New()
local f = self.super.New(self, 'menu')
f:SetClampedToScreen(true)
f:LoadButtons()
f:Layout()
return f
end
function MenuBar:GetDefaults()
return {
point = 'BOTTOMRIGHT',
x = -244,
y = 0,
}
end
function MenuBar:NumButtons()
return #menuButtons
end
function MenuBar:AddButton(i)
if InCombatLockdown() then return end
local b = menuButtons[i]
if b then
b:SetParent(self.header)
b:Show()
self.buttons[i] = b
end
end
function MenuBar:RemoveButton(i)
if InCombatLockdown() then return end
local b = self.buttons[i]
if b then
b:SetParent(nil)
b:Hide()
self.buttons[i] = nil
end
end
local WIDTH_OFFSET = 2
function MenuBar:Layout()
if InCombatLockdown() then return end
if #self.buttons > 0 then
local cols = min(self:NumColumns(), #self.buttons)
local rows = ceil(#self.buttons / cols)
local pW, pH = self:GetPadding()
local spacing = self:GetSpacing()
local cellWidth = 28 - WIDTH_OFFSET
local cellHeight = 36
local visualHeightOffset = 22
for i, b in pairs(self.buttons) do
local col = (i - 1) % cols
local row = ceil(i / cols) - 1
b:ClearAllPoints()
local actualHeight = b:GetHeight() or 58
local topPadding = max(0, actualHeight - cellHeight)
local xPos = pW + (col * (cellWidth + spacing))
local yPos = -pH - (row * (cellHeight + spacing))
b:SetPoint('TOPLEFT', self.header, 'TOPLEFT', xPos, yPos + topPadding)
end
self:SetWidth(max((cellWidth * cols) + (spacing * (cols - 1)) + (pW * 2), 8))
self:SetHeight(max((cellHeight * rows) + (spacing * (rows - 1)) + (pH * 2), 8))
else
self:SetWidth(30)
self:SetHeight(30)
end
end
local protectedMethods = {
'SetNumButtons', 'SetColumns', 'SetSpacing', 'SetPadding',
'SetScale', 'SetShowStates',
'SetPage', 'UpdateStateDriver', 'RefreshActions', 'UpdateGrid',
'AddButton', 'RemoveButton', 'Layout'
}
for _, methodName in ipairs(protectedMethods) do
local originalMethod = MenuBar[methodName]
if originalMethod then
MenuBar[methodName] = function(self, ...)
if InCombatLockdown() then
local key = methodName .. "_" .. (self.id or "global")
local args = { ... }
Enqueue(key, function()
originalMethod(self, unpack(args))
end)
return
end
return originalMethod(self, ...)
end
end
end