-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConfig.lua
executable file
·395 lines (354 loc) · 14.8 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
395
-- Config
-- user defined options and saved vars
-------------------------------------------------------------------------------
-- Module Loading
-------------------------------------------------------------------------------
---@type Ufo
local ADDON_NAME, Ufo = ...
Ufo.Wormhole()
local zebug = Zebug:new()
---@type MouseClick
MouseClick = Ufo.MouseClick
---@class Options -- IntelliJ-EmmyLua annotation
---@field supportCombat boolean placate Bliz security rules of "don't SetAnchor() during combat"
---@field doCloseOnClick boolean close the flyout after the user clicks one of its buttons
---@field usePlaceHolders boolean eliminate the need for "Always Show Buttons" in Bliz UI "Edit Mode" config option for action bars
---@field clickers table germ behavior for various mouse clicks
---@field keybindBehavior GermClickBehavior when a keybind is activated, it will perform this action
---@field flyoutButtonsWillBind boolean when a UFO is open, are its buttons bound to number keys?
---@field muteLogin boolean don't print out status messages on log in
Options = { }
---@class Config -- IntelliJ-EmmyLua annotation
---@field opts Options
---@field optDefaults Options
Config = { }
-------------------------------------------------------------------------------
-- Data
-------------------------------------------------------------------------------
---@return Options
function Config:getOptionDefaults()
---@type Options
local defaults = {
supportCombat = true,
doCloseOnClick = true,
usePlaceHolders = true,
muteLogin = false,
hideCooldownsWhen = 99999,
keybindBehavior = GermClickBehavior.OPEN,
flyoutButtonsWillBind = true,
clickers = {
flyouts = {
default = {
[MouseClick.ANY] = GermClickBehavior.OPEN,
[MouseClick.LEFT] = GermClickBehavior.OPEN,
[MouseClick.RIGHT] = GermClickBehavior.FIRST_BTN,
[MouseClick.MIDDLE] = GermClickBehavior.RANDOM_BTN,
[MouseClick.FOUR] = GermClickBehavior.CYCLE_ALL_BTNS,
[MouseClick.FIVE] = GermClickBehavior.OPEN, -- REVERSE_CYCLE_ALL_BTNS,
}
}
},
}
return defaults
end
-------------------------------------------------------------------------------
-- Configuration Options Menu UI
-------------------------------------------------------------------------------
function getOptTitle() return Ufo.myTitle end
local optionsMenu
local function initializeOptionsMenu()
if optionsMenu then
return optionsMenu
end
local opts = Config.opts
optionsMenu = {
name = getOptTitle,
type = "group",
args = {
-------------------------------------------------------------------------------
-- General Options
-------------------------------------------------------------------------------
helpText = {
order = 5,
type = 'description',
fontSize = "small",
name = "(Shortcut: Right-click the [UFO] button to open this config menu.)\n\n",
},
doCloseOnClick = {
order = 10,
name = "Auto-Close UFO",
desc = "Closes the UFO after clicking any of its buttons",
width = "medium",
type = "toggle",
set = function(optionsMenu, val)
opts.doCloseOnClick = val
GermCommander:updateAll()
end,
get = function()
return opts.doCloseOnClick
end,
},
doMute = {
order = 12,
name = "Mute Login Messages",
desc = "Don't print out Addon info during login.",
width = "medium",
type = "toggle",
set = function(optionsMenu, val)
opts.muteLogin = val
end,
get = function()
return opts.muteLogin
end,
},
hideCooldownsWhen = {
hidden = true, -- this is too nitty gritty
order = 20,
name = "Hide Long Cooldowns",
desc = "When configured with a '?' icon, a UFO on the action bar displays its first button including its cooldown. This option will hide the cooldown if it's longer than X seconds.",
width = "double",
type = "range",
min = 1,
max = 99999,
softMax = 9999,
step = 1,
set = function(optionsMenu, val)
opts.hideCooldownsWhen = val
GermCommander:throttledUpdateAll()
end,
get = function()
return opts.hideCooldownsWhen or 1
end,
},
-------------------------------------------------------------------------------
-- Keybinds
-------------------------------------------------------------------------------
keybindBehavior = {
order = 25,
name = "Keybind's Action",
desc = "A UFO on an actionbar button will respond to any keybinding you've given that button. Choose what the keybind does:",
width = "double",
type = "select",
style = "dropdown",
values = includeGermClickBehaviors(),
sorting = includeGermClickBehaviorSorting(),
set = function(_, behavior)
local isDiff = opts.keybindBehavior ~= behavior
opts.keybindBehavior = behavior
if isDiff then
GermCommander:updateAllKeybindBehavior()
end
end,
get = function()
return opts.keybindBehavior or Config.optDefaults.keybindBehavior
end,
},
hotkeyWhenOpen = {
order = 26,
name = "Hot Key the Buttons",
desc = "While open, assign keys 1 through 9 and 0 to the first 10 buttons on the UFO.",
width = "double",
type = "select",
style = "dropdown",
values = {
[true] = "Bind each button to a number (Escape to close).",
[false] = "An open UFO won't intercept key presses.",
},
set = function(_, flyoutButtonsWillBind)
opts.flyoutButtonsWillBind = flyoutButtonsWillBind
GermCommander:updateAllGermsWithButtonsWillBind()
end,
get = function()
return Config:get("flyoutButtonsWillBind")
end,
},
excluderHelpText = {
order = 28,
type = 'description',
fontSize = "small",
name = [[
Tip: In the catalog, open a UFO and right click a button to exclude it from the "random" and "cycle" actions.
]],
},
-------------------------------------------------------------------------------
-- Place Holder options
-------------------------------------------------------------------------------
placeHoldersHeader = {
order = 30,
name = "PlaceHolder Macros VS Edit Mode Config",
type = 'header',
},
helpTextForPlaceHolders = {
order = 40,
type = 'description',
name = [=[
Each UFO placed onto an action bar has a special macro (named "]=].. Ufo.PLACEHOLDER_MACRO_NAME ..[=[") to hold its place as a button and ensure the UI renders it.
You may disable placeholder macros, but, doing so will require extra UI configuration on your part: You must set the "Always Show Buttons" config option for action bars in Bliz UI "Edit Mode" (in Bartender4 the same option is called "Button Grid").
]=]
},
usePlaceHolders = {
order = 41,
name = "Choose your workaround:",
desc = "Because UFOs aren't spells or items, when they are placed into an action bar slot, the UI thinks that slot is empty and doesn't render the slot by default.",
width = "full",
type = "select",
style = "radio",
values = {
[true] = "Placeholder Macros",
[false] = "Extra UI Configuration" ,
},
sorting = {true,false},
set = function(optionsMenu, val)
opts.usePlaceHolders = val
zebug.info:name("opt:usePlaceHolders()"):print("new val",val)
if val then
GermCommander:ensureAllGermsHavePlaceholders()
else
DeleteMacro(Ufo.PLACEHOLDER_MACRO_NAME)
end
end,
get = function()
return opts.usePlaceHolders
end,
},
supportCombat = {
hidden = true,
name = "Support Combat",
desc = "Placate Bliz security rules of during combat at the cost of less efficient memory usage.",
width = "full",
type = "toggle",
set = function(info, val)
opts.supportCombat = val
end,
get = function()
return opts.supportCombat
end
},
-------------------------------------------------------------------------------
-- Mouse Click opts
-------------------------------------------------------------------------------
mouseClickGroupHeader = {
order = 100,
name = "Mouse Buttons",
type = 'header',
},
mouseClickGroupHelp = {
order = 110,
type = 'description',
name = [=[
You can choose a different action for each mouse button when it clicks on a UFO.
]=]
},
mouseClickGroup = {
order = 120,
name = "Mouse Buttons",
type = "group",
inline = true, -- set this to false to enable multiple configs, one per flyout.
args = {
leftBtn = includeMouseButtonOpts(MouseClick.LEFT),
middleBtn = includeMouseButtonOpts(MouseClick.MIDDLE),
rightBtn = includeMouseButtonOpts(MouseClick.RIGHT),
fourBtn = includeMouseButtonOpts(MouseClick.FOUR),
fiveBtn = includeMouseButtonOpts(MouseClick.FIVE),
},
},
},
}
return optionsMenu
end
-------------------------------------------------------------------------------
-- Mouse Button opt maker
-------------------------------------------------------------------------------
local mouseButtonOptsOrder = 0
local mouseButtonName = {
[MouseClick.ANY] = "All Buttons",
[MouseClick.LEFT] = "Left",
[MouseClick.RIGHT] = "Right",
[MouseClick.MIDDLE] = "Middle",
[MouseClick.FOUR] = "Fourth",
[MouseClick.FIVE] = "Fifth",
[MouseClick.SIX] = "Keybind",
}
---@param click MouseClick
function includeMouseButtonOpts(mouseClick)
local opts = Config.opts
mouseButtonOptsOrder = mouseButtonOptsOrder + 1
return {
order = mouseButtonOptsOrder,
name = mouseButtonName[mouseClick],
desc = "Assign an action to the ".. zebug.warn:colorize(mouseButtonName[mouseClick]) .." mouse button",
width = "double",
type = "select",
style = "dropdown",
values = includeGermClickBehaviors(),
sorting = includeGermClickBehaviorSorting(),
---@param behavior GermClickBehavior
set = function(zelf, behavior)
Config:setClickBehavior(nil, mouseClick, behavior)
zebug.info:name("opt:MouseButtonOpts()"):print("mouseClick",mouseClick, "new val", behavior)
GermCommander:updateClickHandlerForAllGerms(mouseClick)
end,
---@return GermClickBehavior
get = function()
local val = Config:getClickBehavior(nil, mouseClick)
zebug.info:name("opt:MouseButtonOpts()"):print("mouseClick",mouseClick, "current val", val)
return val
end,
}
end
function includeGermClickBehaviors()
local values = {
[GermClickBehavior.OPEN] = zebug.info:colorize("Open") .." the flyout",
[GermClickBehavior.FIRST_BTN] = "Trigger the ".. zebug.info:colorize("first") .." button of the flyout",
[GermClickBehavior.RANDOM_BTN] = "Trigger a ".. zebug.info:colorize("random") .." button of the flyout",
[GermClickBehavior.CYCLE_ALL_BTNS] = zebug.info:colorize("Cycle") .." through each button of the flyout",
--[GermClickBehavior.REVERSE_CYCLE_ALL_BTNS] = zebug.info:colorize("Cycle backwards") .." through each button of the flyout",
}
return values
end
function includeGermClickBehaviorSorting()
local sorting = {
--"default", -- will be useful if I implement each FlyoutId having its own config
GermClickBehavior.OPEN,
GermClickBehavior.FIRST_BTN,
GermClickBehavior.RANDOM_BTN,
GermClickBehavior.CYCLE_ALL_BTNS,
--GermClickBehavior.REVERSE_CYCLE_ALL_BTNS,
}
return sorting
end
---@param flyoutId string
---@param mouseClick MouseClick
---@return GermClickBehavior
function Config:getClickBehavior(flyoutId, mouseClick)
local clickOpts = Config.opts.clickers.flyouts[flyoutId] or Config.opts.clickers.flyouts.default
return clickOpts[mouseClick]
end
function Config:setClickBehavior(flyoutId, mouseClick, behavior)
if not flyoutId then
flyoutId = "default"
end
local clickOpts = Config.opts.clickers.flyouts[flyoutId]
if not clickOpts then
clickOpts = {}
Config.opts.clickers.flyouts[flyoutId] = clickOpts
end
if behavior == "default" then
behavior = nil
end
clickOpts[mouseClick] = behavior
end
function Config:initializeOptionsMenu()
initializeOptionsMenu()
--local db = LibStub("AceDB-3.0"):New(ADDON_NAME, defaults)
--options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(db)
LibStub("AceConfig-3.0"):RegisterOptionsTable(ADDON_NAME, optionsMenu)
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(ADDON_NAME, Ufo.myTitle)
end
function Config:get(key)
if Config.opts[key] == nil then
return Config.optDefaults[key]
else
return Config.opts[key]
end
end