-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConfig.lua
394 lines (381 loc) · 12 KB
/
Config.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
-- Retrieve addon folder name, and our local, private namespace.
---@type string
local addonName = ...
---@class addon
local addon = select(2, ...)
local L = addon.L
-- Lua API
-----------------------------------------------------------
-- Up-value any lua functions used here.
local math_abs = math.abs
local math_fmod = math.fmod
-- Your default settings.
-----------------------------------------------------------
-- Note that anything changed will be saved to disk when you reload the user
-- interface, or exit the game, and those saved changes will override your
-- defaults here.
-- * You should access saved settings by using `db[key]`
-- * Don't put frame handles or other widget references in here,
-- just strings, numbers, and booleans. Tables also work.
---@class db
addon.db = {
-- Put your default settings here
MainMenuBar = true,
MultiBarBottomLeft = true,
MultiBarBottomRight = true,
MultiBarRight = true,
MultiBarLeft = true,
MultiBar5 = true,
MultiBar6 = true,
MultiBar7 = true,
StanceBar = true,
PetActionBar = true,
LinkActionBars = false,
Skyriding = true,
FadeInDelay = 0,
FadeInDuration = 0.1,
FadeOutDelay = 1,
FadeOutDuration = 0.1,
AlphaMin = 0,
AlphaMax = 1,
MaxRefreshRate = 0.01,
FadeInAlphaStep = 0.1,
FadeOutAlphaStep = 0.1,
}
addon.settings = {
actionBarsProxy = {
{
name = L["Action Bar 1"],
tooltip = L["Toggle mouseover for the main action bar"],
variable = addon.shortName .. "_MainBar",
type = Settings.VarType.Boolean,
defaultValue = Settings.Default.True,
GetValue = function()
return addon.db.MainMenuBar
end,
SetValue = function(value)
addon.db.MainMenuBar = value
addon:ApplyOnBar(addon.bars["MainMenuBar"], "MainMenuBar")
end,
},
{
name = L["Action Bar 2"],
tooltip = L["Toggle mouseover for the bottom left action bar"],
variable = addon.shortName .. "_Bar2",
type = Settings.VarType.Boolean,
defaultValue = Settings.Default.True,
GetValue = function()
return addon.db.MultiBarBottomLeft
end,
SetValue = function(value)
addon.db.MultiBarBottomLeft = value
addon:ApplyOnBar(addon.bars["MultiBarBottomLeft"], "MultiBarBottomLeft")
end,
},
{
name = L["Action Bar 3"],
tooltip = L["Toggle mouseover for the bottom right action bar"],
variable = addon.shortName .. "_Bar3",
type = Settings.VarType.Boolean,
defaultValue = Settings.Default.True,
GetValue = function()
return addon.db.MultiBarBottomRight
end,
SetValue = function(value)
addon.db.MultiBarBottomRight = value
addon:ApplyOnBar(addon.bars["MultiBarBottomRight"], "MultiBarBottomRight")
end,
},
{
name = L["Action Bar 4"],
tooltip = L["Toggle mouseover for the right action bar"],
variable = addon.shortName .. "_Bar4",
type = Settings.VarType.Boolean,
defaultValue = Settings.Default.True,
GetValue = function()
return addon.db.MultiBarRight
end,
SetValue = function(value)
addon.db.MultiBarRight = value
addon:ApplyOnBar(addon.bars["MultiBarRight"], "MultiBarRight")
end,
},
{
name = L["Action Bar 5"],
tooltip = L["Toggle mouseover for the left action bar"],
variable = addon.shortName .. "_Bar5",
type = Settings.VarType.Boolean,
defaultValue = Settings.Default.True,
GetValue = function()
return addon.db.MultiBarLeft
end,
SetValue = function(value)
addon.db.MultiBarLeft = value
addon:ApplyOnBar(addon.bars["MultiBarLeft"], "MultiBarLeft")
end,
},
{
name = L["Action Bar 6"],
tooltip = L["Toggle mouseover for the action bar 6"],
variable = addon.shortName .. "_Bar6",
type = Settings.VarType.Boolean,
defaultValue = Settings.Default.True,
GetValue = function()
return addon.db.MultiBar5
end,
SetValue = function(value)
addon.db.MultiBar5 = value
addon:ApplyOnBar(addon.bars["MultiBar5"], "MultiBar5")
end,
},
{
name = L["Action Bar 7"],
tooltip = L["Toggle mouseover for the action bar 7"],
variable = addon.shortName .. "_Bar7",
type = Settings.VarType.Boolean,
defaultValue = Settings.Default.True,
GetValue = function()
return addon.db.MultiBar6
end,
SetValue = function(value)
addon.db.MultiBar6 = value
addon:ApplyOnBar(addon.bars["MultiBar6"], "MultiBar6")
end,
},
{
name = L["Action Bar 8"],
tooltip = L["Toggle mouseover for the action bar 8"],
variable = addon.shortName .. "_Bar8",
type = Settings.VarType.Boolean,
defaultValue = Settings.Default.True,
GetValue = function()
return addon.db.MultiBar7
end,
SetValue = function(value)
addon.db.MultiBar7 = value
addon:ApplyOnBar(addon.bars["MultiBar7"], "MultiBar7")
end,
},
{
name = L["Stance Bar"],
tooltip = L["Toggle mouseover for the stance bar"],
variable = addon.shortName .. "_StanceBar",
type = Settings.VarType.Boolean,
defaultValue = Settings.Default.True,
GetValue = function()
return addon.db.StanceBar
end,
SetValue = function(value)
addon.db.StanceBar = value
addon:ApplyOnBar(addon.bars["StanceBar"], "StanceBar")
end,
},
{
name = L["Pet Action Bar"],
tooltip = L["Toggle mouseover for the pet action bar"],
variable = addon.shortName .. "_PetBar",
type = Settings.VarType.Boolean,
defaultValue = Settings.Default.True,
GetValue = function()
return addon.db.PetActionBar
end,
SetValue = function(value)
addon.db.PetActionBar = value
addon:ApplyOnBar(addon.bars["PetActionBar"], "PetActionBar")
end,
},
},
actionBars = {
{
name = L["Link Action Bars"],
tooltip = L["Link all action bars to show/hide together"],
variable = addon.shortName .. "_Link",
variableKey = "LinkActionBars",
type = Settings.VarType.Boolean,
defaultValue = Settings.Default.False,
},
{
name = L["Show while Skyriding"],
tooltip = L["Show main action bar while skyriding. Requires a reload to take effect."],
variable = addon.shortName .. "_Skyriding",
variableKey = "Skyriding",
type = Settings.VarType.Boolean,
defaultValue = Settings.Default.True,
}
},
fadeSliders = {
{
name = L["Fade-in delay"],
tooltip = L["Delay before the action bar fades in"],
variable = addon.shortName .. "_FadeInDelay",
variableKey = "FadeInDelay",
variableTbl = addon.db,
type = Settings.VarType.Number,
defaultValue = 0,
minValue = 0,
maxValue = 2,
step = 0.1,
},
{
name = L["Fade-in duration"],
tooltip = L["Duration of the fade-in animation"],
variable = addon.shortName .. "_FadeInDuration",
variableKey = "FadeInDuration",
variableTbl = addon.db,
type = Settings.VarType.Number,
defaultValue = 0.1,
minValue = 0,
maxValue = 2,
step = 0.1,
},
{
name = L["Fade-out delay"],
tooltip = L["Delay before the action bar fades out"],
variable = addon.shortName .. "_FadeOutDelay",
variableKey = "FadeOutDelay",
variableTbl = addon.db,
type = Settings.VarType.Number,
defaultValue = 1,
minValue = 0,
maxValue = 2,
step = 0.1,
},
{
name = L["Fade-out duration"],
tooltip = L["Duration of the fade-out animation"],
variable = addon.shortName .. "_FadeOutDuration",
variableKey = "FadeOutDuration",
variableTbl = addon.db,
type = Settings.VarType.Number,
defaultValue = 0.1,
minValue = 0,
maxValue = 2,
step = 0.1,
},
},
alphaSliders = {
{
name = L["Fade-in transparency"],
tooltip = L["Transparency of the action bar when fully faded in"],
variable = addon.shortName .. "_AlphaMin",
variableKey = "AlphaMin",
variableTbl = addon.db,
type = Settings.VarType.Number,
defaultValue = 0,
minValue = 0,
maxValue = 1,
step = 0.01,
},
{
name = L["Fade-out transparency"],
tooltip = L["Transparency of the action bar when fully faded out"],
variable = addon.shortName .. "_AlphaMax",
variableKey = "AlphaMax",
variableTbl = addon.db,
type = Settings.VarType.Number,
defaultValue = 1,
minValue = 0,
maxValue = 1,
step = 0.01,
},
},
}
-- Addon API
-----------------------------------------------------------
--- Updates the existing DB when chaging option names.
--- Assume addon.db refences the saved variables table already.
function addon:MigrateDB()
if (addon.db["pet_bar_ignore"] ~= nil) then
addon.db.PetActionBar = addon.db.pet_bar_ignore
addon.db.pet_bar_ignore = nil
end
if addon.db["Dragonriding"] ~= nil then
addon.db.Skyriding = addon.db.Dragonriding
addon.db.Dragonriding = nil
end
end
--- Compute option values
function addon:ComputeValues()
local alphaRange = math_abs(self.db.AlphaMax - self.db.AlphaMin)
if (self.db.FadeInDuration == 0) then
addon.db.FadeInAlphaStep = 1
else
addon.db.FadeInAlphaStep = alphaRange / (self.db.FadeInDuration / self.db.MaxRefreshRate)
end
if (self.db.FadeOutDuration == 0) then
addon.db.FadeOutAlphaStep = 1
else
addon.db.FadeOutAlphaStep = alphaRange / (self.db.FadeOutDuration / self.db.MaxRefreshRate)
end
end
--- Round a value to the nearest percentile
---@param value any Sliders values
function addon:RoundToNearestPercentile(value)
local val = value * 100
local remain = math_fmod(val, 1)
if remain < 0.5 then
val = val - remain
elseif remain > 0.5 then
val = val + 1 - remain
end
return val / 100
end
--- Create the in-game addon option window
function addon:CreateConfigPanel()
local category, layout = Settings.RegisterVerticalLayoutCategory(addon.shortName)
addon.category = category:GetID()
local function FormatSeconds(value)
return string.format("%.1fs", value)
end
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer(L["Action Bars"])); -- weird way to say "Add a header to the list"
for _, s in ipairs(addon.settings.actionBarsProxy) do
local setting = Settings.RegisterProxySetting(
category, s.variable, s.type, s.name, s.defaultValue, s.GetValue, s.SetValue)
Settings.CreateCheckbox(category, setting, s.tooltip)
end
for _, s in ipairs(addon.settings.actionBars) do
-- the variable table must be the global saved variables table, the reference with addon.db does not work
local setting = Settings.RegisterAddOnSetting(
category, s.variable, s.variableKey, _G[addonName .. "_DB"], s.type, s.name, s.defaultValue)
Settings.CreateCheckbox(category, setting, s.tooltip)
end
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer(L["Fade Times"]));
for _, s in ipairs(addon.settings.fadeSliders) do
local GetValue = function() return addon.db[s.variableKey] end
local SetValue = function(value)
local roundValue = addon:RoundToNearestPercentile(value)
if roundValue == addon.db[s.variableKey] then return end
addon.db[s.variableKey] = value
addon:ComputeValues()
end
local setting = Settings.RegisterProxySetting(
category, s.variable, s.type, s.name, s.defaultValue, GetValue, SetValue)
local options = Settings.CreateSliderOptions(s.minValue, s.maxValue, s.step);
options:SetLabelFormatter(MinimalSliderWithSteppersMixin.Label.Right, FormatSeconds);
Settings.CreateSlider(category, setting, options, s.tooltip)
end
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer(L["Transparency"]));
for _, s in ipairs(addon.settings.alphaSliders) do
local GetValue = function() return addon.db[s.variableKey] end
local SetValue = function(value)
local roundValue = addon:RoundToNearestPercentile(value)
if roundValue == addon.db[s.variableKey] then return end
addon.db[s.variableKey] = value
addon:ComputeValues()
for _, bar_name in pairs(addon.bar_names) do
addon:ApplyOnBar(addon.bars[bar_name], bar_name)
end
end
local setting = Settings.RegisterProxySetting(
category, s.variable, s.type, s.name, s.defaultValue, GetValue, SetValue)
local options = Settings.CreateSliderOptions(s.minValue, s.maxValue, s.step);
options:SetLabelFormatter(MinimalSliderWithSteppersMixin.Label.Right, FormatPercentage);
Settings.CreateSlider(category, setting, options, s.tooltip)
end
Settings.RegisterAddOnCategory(category)
end
EventRegistry:RegisterFrameEventAndCallback("VARIABLES_LOADED", function()
-- we sometimes change the options, hence the need to migrate tables
addon:MigrateDB()
addon:CreateConfigPanel()
end)