-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
ActionBars.lua
388 lines (343 loc) · 9.41 KB
/
ActionBars.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
--[[
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")
local BT4ActionBars = Bartender4:NewModule("ActionBars", "AceEvent-3.0")
local select, ipairs, pairs, tostring, tonumber, min, setmetatable = select, ipairs, pairs, tostring, tonumber, min, setmetatable
local WoWClassic = (WOW_PROJECT_ID ~= WOW_PROJECT_MAINLINE)
local WoWWrath = (WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC)
local WoWCata = (WOW_PROJECT_ID == WOW_PROJECT_CATACLYSM_CLASSIC)
local WoW10 = select(4, GetBuildInfo()) >= 100000
local LAB10 = LibStub("LibActionButton-1.0")
local LSM = LibStub("LibSharedMedia-3.0")
local Masque = LibStub("Masque", true)
-- GLOBALS: UnitClass, InCombatLockdown, GetBindingKey, ClearOverrideBindings, SetOverrideBindingClick
local abdefaults = {
['**'] = Bartender4.Util:Merge({
enabled = true,
buttons = 12,
buttonOffset = 0,
hidemacrotext = false,
showgrid = false,
flyoutDirection = "UP",
elements = {
['**'] = {
font = "Arial Narrow",
fontSize = 13,
fontFlags = "OUTLINE",
fontColor = {1, 1, 1},
textAnchor = "CENTER",
textOffsetX = 0,
textOffsetY = 0,
textJustifyH = "CENTER",
},
hotkey = {
fontSize = WoW10 and 16 or 13,
fontColor = {0.9, 0.9, 0.9},
textAnchor = "TOPRIGHT",
textOffsetX = -2,
textOffsetY = -4,
textJustifyH = "RIGHT",
},
count = {
fontSize = WoW10 and 19 or 16,
textAnchor = "BOTTOMRIGHT",
textOffsetX = -2,
textOffsetY = 4,
textJustifyH = "RIGHT",
},
macro = {
font = "Friz Quadrata TT",
fontSize = WoW10 and 11 or 10,
textAnchor = "BOTTOM",
textOffsetX = 0,
textOffsetY = 2,
},
},
}, Bartender4.StateBar.defaults),
[1] = {
states = {
enabled = true,
possess = true,
actionbar = false,
stance = {
DRUID = { bear = 9, cat = 7, prowl = 8 },
ROGUE = (WoWWrath or WoWCata) and { stealth = 7, shadowdance = 8 } or { stealth = 7 },
WARRIOR = WoWClassic and { battle = 7, def = 8, berserker = 9 } or nil,
PRIEST = WoWClassic and { shadowform = 7 } or nil,
EVOKER = { soar = 7 },
},
},
visibility = {
vehicleui = false,
overridebar = false,
},
},
[7] = {
enabled = false,
},
[8] = {
enabled = false,
},
[9] = {
enabled = false,
},
[10] = {
enabled = false,
},
[13] = {
enabled = false,
},
[14] = {
enabled = false,
},
[15] = {
enabled = false,
},
}
local LIST_ACTIONBARS = WoW10 and { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 14, 15 } or { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
BT4ActionBars.LIST_ACTIONBARS = LIST_ACTIONBARS
local BINDING_MAPPINGS = {
[1] = "ACTIONBUTTON%d",
[3] = "MULTIACTIONBAR3BUTTON%d",
[4] = "MULTIACTIONBAR4BUTTON%d",
[5] = "MULTIACTIONBAR2BUTTON%d",
[6] = "MULTIACTIONBAR1BUTTON%d",
[13] = "MULTIACTIONBAR5BUTTON%d",
[14] = "MULTIACTIONBAR6BUTTON%d",
[15] = "MULTIACTIONBAR7BUTTON%d",
}
local defaults = {
profile = {
actionbars = abdefaults,
}
}
local ActionBar_MT = {__index = Bartender4.ActionBar}
-- export defaults for other modules
Bartender4.ActionBar.defaults = abdefaults['**']
function BT4ActionBars:OnInitialize()
self.db = Bartender4.db:RegisterNamespace("ActionBars", defaults)
end
-- setup the 10 actionbars
local first = true
function BT4ActionBars:OnEnable()
if first then
self.playerclass = select(2, UnitClass("player"))
self.actionbars = {}
for _, i in ipairs(LIST_ACTIONBARS) do
local config = self.db.profile.actionbars[i]
if config.enabled then
self.actionbars[i] = self:Create(i, config, BINDING_MAPPINGS[i])
else
self:CreateBarOption(i, self.disabledoptions)
end
end
first = nil
end
self:RegisterEvent("UPDATE_BINDINGS", "ReassignBindings")
self:ReassignBindings()
LSM.RegisterCallback(self, "LibSharedMedia_Registered", function(mtype, key)
if mtype == "font" then
for k, bar in pairs(self.actionbars) do
if bar.config.elements.hotkey.font == key or bar.config.elements.count.font == key or bar.config.elements.macro.font == key then
bar:UpdateButtonConfig()
end
end
end
end)
if Masque then
self.MasqueFlyoutGroup = Masque:Group("Bartender4", "Flyout")
for _, button in pairs(LAB10.FlyoutButtons) do
button:AddToMasque(self.MasqueFlyoutGroup)
end
LAB10:RegisterCallback("OnFlyoutButtonCreated", function(event, button) button:AddToMasque(self.MasqueFlyoutGroup) end)
end
end
function BT4ActionBars:SetupOptions()
if not self.options then
-- empty table to hold the bar options
self.options = {}
-- template for disabled bars
self.disabledoptions = {
general = {
type = "group",
name = L["General Settings"],
cmdInline = true,
order = 1,
args = {
enabled = {
type = "toggle",
name = L["Enabled"],
desc = L["Enable/Disable the bar."],
set = function(info, v) if v then BT4ActionBars:EnableBar(info[2]) end end,
get = function() return false end,
}
}
}
}
-- iterate over bars and create their option tables
for _, i in ipairs(LIST_ACTIONBARS) do
local config = self.db.profile.actionbars[i]
if config.enabled then
self:CreateBarOption(i)
else
self:CreateBarOption(i, self.disabledoptions)
end
end
end
end
-- Applys the config in the current profile to all active Bars
function BT4ActionBars:ApplyConfig()
for _, i in ipairs(LIST_ACTIONBARS) do
local config = self.db.profile.actionbars[i]
-- make sure the bar has its current config object if it exists already
if self.actionbars[i] then
self.actionbars[i].config = config
end
if config.enabled then
self:EnableBar(i)
else
self:DisableBar(i)
end
end
if LibStub("LibActionButton-1.0").flyoutHandler then
LibStub("LibActionButton-1.0").flyoutHandler.Background:SetShown(Bartender4.db.profile.flyoutBackground)
end
end
-- we do not allow to disable the actionbars module
function BT4ActionBars:ToggleModule()
return
end
function BT4ActionBars:UpdateButtons(force)
for i,v in ipairs(self.actionbars) do
for j,button in ipairs(v.buttons) do
button:UpdateAction(force)
end
end
end
local function MigrateKeybindBindings(target, ...)
local needSaving = false
for k=1, select('#', ...) do
local key = select(k, ...)
if key and key ~= "" then
SetBindingClick(key, target, "Keybind")
needSaving = true
end
end
return needSaving
end
local s_inReassignBindings = false
function BT4ActionBars:ReassignBindings()
if InCombatLockdown() or s_inReassignBindings then return end
s_inReassignBindings = true
if self.actionbars then
for id, mapping in pairs(BINDING_MAPPINGS) do
local frame = self.actionbars[id]
if frame then
ClearOverrideBindings(frame)
for i = 1,min(#frame.buttons, 12) do
local button, real_button = mapping:format(i), frame.buttons[i]:GetName()
for k=1, select('#', GetBindingKey(button)) do
local key = select(k, GetBindingKey(button))
if key and key ~= "" then
SetOverrideBindingClick(frame, false, key, real_button, "Keybind")
end
end
end
end
end
end
-- re-assign bindings from LeftButton to Keybind buttons
local needSaving = false
for i = 1,180 do
local button = ("BT4Button%d"):format(i)
local clickbutton = ("CLICK %s:LeftButton"):format(button)
if MigrateKeybindBindings(button, GetBindingKey(clickbutton)) then
needSaving = true
end
end
if needSaving then
SaveBindings(GetCurrentBindingSet())
end
s_inReassignBindings = false
end
BT4ActionBars.BLIZZARD_BAR_MAP = {
[6] = 2,
[5] = 3,
[3] = 4,
[4] = 5,
[13] = 6,
[14] = 7,
[15] = 8,
}
function BT4ActionBars:GetBarName(id)
if WoW10 then
local barID = tonumber(id)
if barID == 7 or barID == 8 or barID == 9 or barID == 10 then
return (L["Class Bar %d"]):format(barID - 6)
elseif self.BLIZZARD_BAR_MAP[barID] then
return (L["Bar %s"]):format(tostring(self.BLIZZARD_BAR_MAP[barID]))
elseif barID == 2 then
return L["Bonus Action Bar"]
end
end
return (L["Bar %s"]):format(id)
end
-- Creates a new bar object based on the id and the specified config
function BT4ActionBars:Create(id, config, bindingmapping)
id = tostring(id)
local bar = setmetatable(Bartender4.StateBar:Create(id, config, self:GetBarName(id)), ActionBar_MT)
bar.module = self
bar.bindingmapping = bindingmapping
bar:SetScript("OnEvent", bar.OnEvent)
if not WoWClassic or WoWCata then
bar:RegisterEvent("PLAYER_TALENT_UPDATE")
bar:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED")
end
bar:RegisterEvent("LEARNED_SPELL_IN_TAB")
bar:RegisterEvent("PLAYER_REGEN_ENABLED")
self:CreateBarOption(id)
bar:ApplyConfig()
return bar
end
function BT4ActionBars:DisableBar(id)
id = tonumber(id)
local bar = self.actionbars[id]
if not bar then return end
bar.config.enabled = false
bar:Disable()
self:CreateBarOption(id, self.disabledoptions)
end
function BT4ActionBars:EnableBar(id)
id = tonumber(id)
local bar = self.actionbars[id]
local config = self.db.profile.actionbars[id]
config.enabled = true
if not bar then
bar = self:Create(id, config, BINDING_MAPPINGS[id])
self.actionbars[id] = bar
else
bar.disabled = nil
self:CreateBarOption(id)
bar:ApplyConfig(config)
end
if not Bartender4.Locked then
bar:Unlock()
end
end
function BT4ActionBars:GetAll()
return pairs(self.actionbars)
end
function BT4ActionBars:ForAll(method, ...)
for _, bar in self:GetAll() do
local func = bar[method]
if func then
func(bar, ...)
end
end
end
function BT4ActionBars:ForAllButtons(...)
self:ForAll("ForAll", ...)
end