-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConfig.lua
More file actions
executable file
·864 lines (752 loc) · 35.6 KB
/
Config.lua
File metadata and controls
executable file
·864 lines (752 loc) · 35.6 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
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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
-- Config
-- user defined options and saved vars
-------------------------------------------------------------------------------
-- Module Loading
-------------------------------------------------------------------------------
---@type Ufo
local ADDON_NAME, Ufo = ...
Ufo.Wormhole()
local zebug = Zebug:new(Z_VOLUME_GLOBAL_OVERRIDE or Zebug.INFO)
---@type MouseClick
MouseClick = Ufo.MouseClick
---@class ConfigOption -- IntelliJ-EmmyLua annotation
---@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 doKeybindTheButtonsOnTheFlyout boolean when a UFO is open, are its buttons bound to number keys?
---@field enableBonusModifierKeys boolean Incorporate shift, control, etc when using keybindings
---@field doNotOverwriteExistingKeybindings boolean when enableBonusModifierKeys are enabled, do not create new key bindings that clobber pre-existing ones
---@field bonusModifierKeys table<ModifierKey,GermClickBehavior> maps shift/ctrl/etc to OPEN/PRIME/etc
---@field muteLogin boolean don't print out status messages on log in
---@field showLabels boolean display a UFO's name on the action bar button
---@field primaryButtonIs PrimaryButtonIs which button is considered "primary"
---@field flyoutMaxSize number how wide is a flyout allowed to be
---@field version number identifies the config data's format. determines when the config is (in)compatible with the addon code's version
Options = { }
---@class ConfigField
---@field name ConfigOption
ConfigField = {
name = {
muteLogin = "muteLogin",
showLabels = "showLabels",
doCloseOnClick = "doCloseOnClick",
usePlaceHolders = "usePlaceHolders",
clickers = "clickers",
keybindBehavior = "keybindBehavior",
doKeybindTheButtonsOnTheFlyout = "doKeybindTheButtonsOnTheFlyout",
enableBonusModifierKeys = "enableBonusModifierKeys",
doNotOverwriteExistingKeybindings = "doNotOverwriteExistingKeybindings",
bonusModifierKeys = "bonusModifierKeys",
muteLogin = "muteLogin",
primaryButtonIs = "primaryButtonIs",
flyoutMaxSize = "flyoutMaxSize",
version = "version",
}
}
---@class Config -- IntelliJ-EmmyLua annotation
---@field opts ConfigOption
---@field optDefaults ConfigOption
---@field field ConfigField
Config = { field = ConfigField }
-------------------------------------------------------------------------------
-- Enums
-------------------------------------------------------------------------------
---@class PrimaryButtonIs
PrimaryButtonIs = {
FIRST = "FIRST",
RECENT = "RECENT",
}
-------------------------------------------------------------------------------
-- Constants
-------------------------------------------------------------------------------
local KEY_MOD_NA = "KEY_MOD_NA"
-------------------------------------------------------------------------------
-- Data
-------------------------------------------------------------------------------
local keymodOptsOrder = 0
---@return ConfigOption
function Config:getOptionDefaults()
---@type ConfigOption
local defaults = {
doCloseOnClick = true,
usePlaceHolders = true,
muteLogin = false,
showLabels = false,
hideCooldownsWhen = 99999,
keybindBehavior = GermClickBehavior.OPEN,
enableBonusModifierKeys = false,
doKeybindTheButtonsOnTheFlyout = true,
primaryButtonIs = PrimaryButtonIs.FIRST,
flyoutMaxSize = 20,
clickers = {
flyouts = {
default = {
[MouseClick.ANY] = GermClickBehavior.OPEN,
[MouseClick.LEFT] = GermClickBehavior.OPEN,
[MouseClick.RIGHT] = GermClickBehavior.PRIME_BTN,
[MouseClick.MIDDLE] = GermClickBehavior.RANDOM_BTN,
[MouseClick.FOUR] = GermClickBehavior.CYCLE_ALL_BTNS,
[MouseClick.FIVE] = nil, -- REVERSE_CYCLE_ALL_BTNS,
}
}
},
bonusModifierKeys = {
[ModifierKey.SHIFT] = nil,
[ModifierKey.ALT] = nil,
[ModifierKey.CTRL] = nil,
[ModifierKey.META] = nil,
},
}
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 = 100,
type = 'description',
fontSize = "small",
name = L10N.cfg.SHORTCUT .. "\n\n" .. Ufo.myTitle .. L10N.cfg.UFO_LETS_YOU .. EOLx2
},
doCloseOnClick = {
order = 110,
name = L10N.cfg.AUTO_CLOSE_UFO,
desc = L10N.cfg.CLOSES_THE_UFO,
width = "medium",
type = "toggle",
set = function(optionsMenu, val)
opts.doCloseOnClick = val
UFO_DUM_DUM:setSecEnvAttribute("doCloseOnClick", val)
--GermCommander:forEachGerm(Germ.copyDoCloseOnClickConfigValToAttribute, "user-config-changed-doCloseOnClick") -- TODO: target just the clickers
end,
get = function()
return opts.doCloseOnClick
end,
},
doMute = {
order = 120,
name = L10N.cfg.MUTE_LOGIN_MESSAGES,
desc = L10N.cfg.DONT_PRINT,
width = "medium",
type = "toggle",
set = function(optionsMenu, val)
opts.muteLogin = val
end,
get = function()
return Config:get("muteLogin")
end,
},
showLabels = {
order = 130,
name = L10N.cfg.SHOW_LABELS, -- "Show Labels",
desc = L10N.cfg.ADD_A_LABEL, -- "Add a label to the action bar button displaying the UFO's name.",
width = "medium",
type = "toggle",
set = function(optionsMenu, val)
opts.showLabels = val
GermCommander:applyConfigForLabels("config_labels")
end,
get = function()
return Config:get("showLabels")
end,
},
spacer = {
order = 140,
type = 'description',
name = EOLx2
},
-------------------------------------------------------------------------------
-- Max Flyout Size
-------------------------------------------------------------------------------
maxFlyoutSizeDiv = {
order = 150,
name = "Maximum Flyout Length",
type = 'header',
},
maxFlyoutSizeGroup = {
order = 160,
name = "", -- L10N.cfg.THE_PRIMARY_BUTTON, -- 'The "Primary Button"',
type = "group",
inline = true,
args = {
maxSizeHelp = {
order = 10,
type = 'description',
name = L10N.cfg.MAX_LEN_HELP, -- "How many buttons can a flyout display on a single line before it splits itself into multiple lines? A value of 15 means 16 buttons would be displayed as 2 lines of 8."
},
chooseMaxSize = {
order = 20,
name = "", -- L10N.cfg.THE_PRIMARY_BUTTON_IS_THE, --'The "Primary" Button is the:',
desc = "Button count", -- L10N.cfg.WHICH_BUTTON_OF_THE_FLYOUT, --'Which button of the flyout should be considered its "Primary" button?',
width = "double",
type = "range",
min = 10,
max = MAX_FLYOUT_SIZE,
step = 1,
set = function(optionsMenu, val)
opts.flyoutMaxSize = val
zebug.info:name("opt:flyoutMaxSize()"):print("new val",val)
UFO_DUM_DUM:setSecEnvAttribute("FLYOUT_MAX_LEN", val)
end,
get = function()
return Config:get(Config.field.name.flyoutMaxSize)
end,
},
maxSizeFooter = {
order = 30,
type = 'description',
name = EOLx2,
},
},
},
-------------------------------------------------------------------------------
-- Define Primary
-------------------------------------------------------------------------------
primaryButtonIsDiv = {
order = 200,
name = L10N.cfg.THE_PRIMARY_BUTTON, -- 'The "Primary Button"',
type = 'header',
},
primaryButtonIsGroup = {
order = 210,
name = "",
type = "group",
inline = true,
args = {
helpPrim = {
order = 210,
type = 'description',
name = L10N.cfg.ONE_BUTTON_ON_THE_UFO_IS_PRIMARY .. EOLx2, -- One button on the UFO is "Primary," is shown on the actionbar, and can be clicked without necessarily opening the UFO. By default, the first button on the UFO is its primary. Alternatively, whenever you use a button it would become the new primary.
},
primaryButtonIsMenu = {
order = 220,
name = L10N.cfg.THE_PRIMARY_BUTTON_IS_THE, --'The "Primary" Button is the:',
desc = L10N.cfg.WHICH_BUTTON_OF_THE_FLYOUT, --'Which button of the flyout should be considered its "Primary" button?',
width = "double",
type = "select",
style = "dropdown",
values = {
[PrimaryButtonIs.FIRST] = L10N.cfg.FIRST_BUTTON, --"First Button, usually",
[PrimaryButtonIs.RECENT] = L10N.cfg.MOST_RECENTLY_USED, --"Most Recently Used",
},
sorting = {PrimaryButtonIs.FIRST, PrimaryButtonIs.RECENT},
set = function(optionsMenu, val)
opts.primaryButtonIs = val
zebug.info:name("opt:primaryButtonIs()"):print("new val",val)
GermCommander:applyConfigForPrimaryButtonIs("config_delta_prime")
end,
get = function()
return Config:get("primaryButtonIs")
end,
},
promoteViaShiftKey = {
order = 230,
-- hidden = function() return Config:get("primaryButtonIs") ~= PrimaryButtonIs.FIRST end,
type = 'description',
-- fontSize = "small",
name = EOL
.. L10N.cfg.ANY_BUTTON_CAN_BE_PROMOTED -- 'Also, any button can be promoted to "Primary" by holding a modifier key (shift, control, etc) while clicking the button.'
.. EOLx3
},
},
},
-------------------------------------------------------------------------------
-- Mouse Click opts
-------------------------------------------------------------------------------
mouseClickDiv = {
order = 300,
name =L10N.cfg.MOUSE_BUTTONS, --"Mouse Buttons",
type = 'header',
},
mouseClickHelp = {
order = 310,
type = 'description',
name = L10N.cfg.YOU_CAN_CHOOSE_A_DIFFERENT, -- You can choose a different action for each mouse button when it clicks on a UFO.
},
mouseClickGroup = {
order = 320,
name = " ",
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),
},
},
excluderHelpText = {
order = 330,
type = 'description',
fontSize = "small",
name = EOL .. L10N.cfg.TIP_IN_THE_CATALOG .. EOLx3, --Tip: In the catalog, open a UFO and right click a button to exclude it from the "random" and "cycle" actions.
},
-------------------------------------------------------------------------------
-- Keybinds
-------------------------------------------------------------------------------
keybindGroup = {
order = 400,
name = L10N.cfg.KEYBINDING_BEHAVIOR, --"Keybinding Behavior",
type = "group",
inline = true, -- set this to false to enable multiple configs, one per flyout.
args = {
mkeybindHelp = {
order = 10,
type = 'description',
name = L10N.cfg.UFOS_ON_THE_ACTION_BARS .. EOLx2, --UFOs on the action bars support keybindings. Buttons on UFOs can be configured to also have keybindings.
},
hotkeyWhenOpen = {
order = 20,
name = L10N.cfg.HOT_KEY_THE_BUTTONS_ON_A_UFO, --"Hot Key the Buttons on a UFO",
desc = L10N.cfg.WHILE_OPEN_ASSIGN_KEYS, --"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] = L10N.cfg.BIND_EACH_BUTTON, --"Bind each button to a number (Escape to close).",
[false] = L10N.cfg.AN_OPEN_UFO_WONT, --"An open UFO won't intercept key presses.",
},
set = function(_, doKeybindTheButtonsOnTheFlyout)
opts.doKeybindTheButtonsOnTheFlyout = doKeybindTheButtonsOnTheFlyout
GermCommander:applyConfigForBindTheButtons("Config-doKeybindTheButtonsOnTheFlyout")
end,
get = function()
return Config:get("doKeybindTheButtonsOnTheFlyout")
end,
},
keybindBehavior = {
order = 30,
name = L10N.cfg.ACTIONBAR_KEYBINDING, --"Actionbar Keybinding",
desc = L10N.cfg.A_UFO_ON_AN_ACTIONBAR_BUTTON_WILL_RESPOND, --"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:applyConfigForMainKeybind("Config-Main-Keybind")
end
end,
get = function()
return opts.keybindBehavior or Config.optDefaults.keybindBehavior
end,
},
-------------------------------------------------------------------------------
-- Keymods
-------------------------------------------------------------------------------
enableBonusModifierKeys = {
order = 500,
name = L10N.cfg.ENABLE_MODIFIER_KEYS_FOR_KEYBINDS, --"Enable Modifier Keys for Keybinds",
desc = L10N.cfg.INCORPORATE_SHIFT_ETC, --"Incorporate shift, control, etc when using keybindings.",
width = "double",
type = "toggle",
set = function(optionsMenu, val)
opts.enableBonusModifierKeys = val
GermCommander:applyConfigForBonusModifierKeys(Event:new("Config", "mod-ALL-the-mod-keys"))
end,
get = function()
return Config:get("enableBonusModifierKeys")
end,
},
keymodGroup = {
order = 510,
name = L10N.cfg.INCORPORATE_SHIFT_ETC, --"Modifier Keys for Keybindings",
type = "group",
inline = true, -- set this to false to enable multiple configs, one per flyout.
hidden = function() return not Config:get("enableBonusModifierKeys") end,
args = {
keymodHelp = {
order = 10,
type = 'description',
name = L10N.cfg.IN_ADDITION_TO_USING_THE_KEYBINDINGS, --In addition to using the keybindings configured in the standard WoW menus, UFO can bind extra key + modifier combinations. For example, if you have a UFO bound to the Z key, then you can add shift-Z or control-Z here.
},
shiftKey = includeKeyModOpts(ModifierKey.SHIFT),
ctrlKey = includeKeyModOpts(ModifierKey.CTRL),
altKey = includeKeyModOpts(ModifierKey.ALT),
cmdtKey = includeKeyModOpts(ModifierKey.META),
keymodOverwriteHelp = {
order = keymodOptsOrder + 10,
type = 'description',
name = L10N.cfg.MODIFIERS_ARE_ADDITIVE_IN_THE_ABOVE_EXAMPLE,
-- (Note: modifiers are additive. So, if a UFO's main keybind is CMD-X then its extra bindings will always include "CMD-X" plus the modifiers. Expect CMD-SHIFT-X (not SHIFT-X) and CMD-ALT-X (not ALT-X)
-- In the above example, there is a UFO on the Z key. What if there is also an action bound to Shift-Z (for example) already. How do you want UFO how to handle such a conflict?
},
doNotOverwriteExistingKeybindings = {
order = keymodOptsOrder + 20,
name = L10N.cfg.DO_NOT_OVERWRITE_EXISTING_KEYBINDINGS, --"Do Not Overwrite Existing Keybindings",
desc = L10N.cfg.LEAVE_EXISTING_KEYBINDINGS, --"Leave existing keybindings intact rather than overwrite them with new ones specific to a UFO",
width = "double",
type = "toggle",
set = function(optionsMenu, val)
opts.doNotOverwriteExistingKeybindings = val
GermCommander:applyConfigForBonusModifierKeys(Event:new("Config", "config-key-mods-clobber"))
end,
get = function()
return Config:get("doNotOverwriteExistingKeybindings")
end,
},
},
},
},
},
-------------------------------------------------------------------------------
-- Place Holder options
-------------------------------------------------------------------------------
placeHoldersHeader = {
order = 600,
name = L10N.cfg.PLACEHOLDER_MACROS_VS_EDIT_MODE_CONFIG, --"PlaceHolder Macros VS Edit Mode Config",
type = 'header',
},
helpTextForPlaceHolders = {
order = 610,
type = 'description',
name = L10N.cfg.EACH_UFO_PLACED,
-- 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 = 620,
name = L10N.cfg.CHOOSE_YOUR_WORKAROUND, --"Choose your workaround:",
desc = L10N.cfg.BECAUSE_UFOS_ARENT_SPELLS, --"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] = L10N.cfg.PLACEHOLDER_MACROS, --"Placeholder Macros",
[false] = L10N.cfg.EXTRA_UI_CONFIGURATION, --"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("config_delta_ph")
else
Config:deletePlaceholder()
end
end,
get = function()
return opts.usePlaceHolders
end,
},
-------------------------------------------------------------------------------
-- Snapshot
-------------------------------------------------------------------------------
snapshotHeader = {
order = 700,
name = L10N.cfg.SNAPSHOT,
type = 'header',
},
helpTextForSnapshot = {
order = 710,
type = 'description',
name = L10N.cfg.SNAPSHOT_HELP,
},
snapshotSave = {
order = 720,
name = L10N.cfg.SNAPSHOT_SAVE_BTN,
desc = L10N.SLASH_DESC_SNAPSHOT_SAVE,
--width = "full",
type = "execute",
func = DB.snapshotSave,
},
snapshotLoad = {
order = 730,
name = L10N.cfg.SNAPSHOT_LOAD_BTN,
desc = L10N.SLASH_DESC_SNAPSHOT_LOAD,
type = "execute",
func = DB.snapshotLoad,
hidden = DB.isNoSnapshot
},
},
}
return optionsMenu
end
-------------------------------------------------------------------------------
-- Mouse Button opt maker
-------------------------------------------------------------------------------
local mouseButtonOptsOrder = 0
local mouseButtonName = {
[MouseClick.ANY] = L10N.cfg.ALL_BUTTONS, --"All Buttons",
[MouseClick.LEFT] = L10N.cfg.LEFT, --"Left",
[MouseClick.RIGHT] = L10N.cfg.RIGHT, --"Right",
[MouseClick.MIDDLE] = L10N.cfg.MIDDLE, --"Middle",
[MouseClick.FOUR] = L10N.cfg.FOURTH, --"Fourth",
[MouseClick.FIVE] = L10N.cfg.FIFTH, --"Fifth",
[MouseClick.RESERVED_FOR_KEYBIND] = L10N.cfg.KEYBIND, --"Keybind",
}
---@param click MouseClick
function includeMouseButtonOpts(mouseClick)
local opts = Config.opts
mouseButtonOptsOrder = mouseButtonOptsOrder + 10
return {
order = mouseButtonOptsOrder,
name = mouseButtonName[mouseClick],
desc = L10N.cfg.ASSIGN_AN_ACTION_TO_THE .." ".. zebug.warn:colorize(mouseButtonName[mouseClick]) .." ".. L10N.cfg.MOUSE_BUTTON, -- "Assign an action to the ".. zebug.warn:colorize(mouseButtonName[mouseClick]) .." mouse button",
width = "double",
type = "select",
style = "dropdown",
values = includeGermClickBehaviors("include empty"),
sorting = includeGermClickBehaviorSorting("include empty"),
---@param behavior GermClickBehavior
set = function(zelf, behavior)
if behavior == KEY_MOD_NA then
behavior = nil
end
Config:setClickBehavior(nil, mouseClick, behavior)
zebug.info:name("opt:MouseButtonOpts()"):print("mouseClick",mouseClick, "new val", behavior)
GermCommander:updateClickerForAllActiveGerms(mouseClick, Event:new("Config", "bind-a-mouse-button"))
end,
---@return GermClickBehavior
get = function()
local val = Config:getGermClickBehavior(nil, mouseClick)
zebug.info:name("opt:MouseButtonOpts()"):print("mouseClick",mouseClick, "current val", val)
return val
end,
}
end
---@param click ModifierKey
function includeKeyModOpts(modifierKey, mk2)
local opts = Config.opts
keymodOptsOrder = keymodOptsOrder + 10
local l10nKey = modifierKey .. "_INIT_CAP"
return {
order = keymodOptsOrder,
name = L10N.cfg[l10nKey] or "NiL",
desc = L10N.cfg.ASSIGN_AN_ACTION_TO_THE_KEYBIND .." ".. zebug.warn:colorize(L10N[modifierKey] or "NiL") .." ".. L10N.cfg.MODIFIER, --"Assign an action to the keybind + ".. zebug.warn:colorize(L10N[modifierKey] or "NiL") .." modifier",
width = "double",
type = "select",
style = "dropdown",
values = includeGermClickBehaviors("include empty"),
sorting = includeGermClickBehaviorSorting("do it dummy"),
---@param behavior GermClickBehavior
set = function(zelf, behavior)
zebug.info:name("opt:KeyModOpts()"):print("modifierKey",modifierKey, "new val", behavior)
if behavior == KEY_MOD_NA then
behavior = nil
end
Config.opts.bonusModifierKeys[modifierKey] = behavior
GermCommander:applyConfigForBonusModifierKeys(modifierKey, behavior, Event:new("Config", "mod-the-mod-keys"))
end,
---@return GermClickBehavior
get = function()
return Config.opts.bonusModifierKeys[modifierKey]
end,
}
end
local INCLUDE_GERM_CLICK_BEHAVIORS
local INCLUDE_GERM_CLICK_BEHAVIORS_PLUS_NA
function includeGermClickBehaviors(includeNa)
if not INCLUDE_GERM_CLICK_BEHAVIORS then
INCLUDE_GERM_CLICK_BEHAVIORS = {
[GermClickBehavior.OPEN] = zebug.info:colorize(L10N.cfg.OPEN) .." ".. L10N.cfg.THE_FLYOUT,
[GermClickBehavior.PRIME_BTN] = L10N.cfg.TRIGGER_THE .." ".. zebug.info:colorize(L10N.cfg.PRIMARY) .." ".. L10N.cfg.BUTTON_OF_THE_FLYOUT, -- "Trigger the ".. zebug.info:colorize(L10N.cfg.PRIMARY) .." button of the flyout",
[GermClickBehavior.RANDOM_BTN] = L10N.cfg.TRIGGER_A .." ".. zebug.info:colorize(L10N.cfg.RANDOM) .." ".. L10N.cfg.BUTTON_OF_THE_FLYOUT, -- "Trigger a ".. zebug.info:colorize(L10N.cfg.RANDOM) .." button of the flyout",
[GermClickBehavior.CYCLE_ALL_BTNS] = zebug.info:colorize(L10N.cfg.CYCLE) .." ".. L10N.cfg.THROUGH_EACH_BUTTON_OF_THE_FLYOUT,
--[GermClickBehavior.REVERSE_CYCLE_ALL_BTNS] = zebug.info:colorize(L10N.cfg.CYCLE_BACKWARDS) .." ".. L10N.cfg.THROUGH_EACH_BUTTON_OF_THE_FLYOUT,
}
INCLUDE_GERM_CLICK_BEHAVIORS_PLUS_NA = deepcopy(INCLUDE_GERM_CLICK_BEHAVIORS)
INCLUDE_GERM_CLICK_BEHAVIORS_PLUS_NA[KEY_MOD_NA] = ""-- "Do not include in binding"
end
if includeNa then
return INCLUDE_GERM_CLICK_BEHAVIORS_PLUS_NA
else
return INCLUDE_GERM_CLICK_BEHAVIORS
end
end
function includeGermClickBehaviorSorting(includeNa)
if includeNa then
return {
KEY_MOD_NA,
GermClickBehavior.OPEN,
GermClickBehavior.PRIME_BTN,
GermClickBehavior.RANDOM_BTN,
GermClickBehavior.CYCLE_ALL_BTNS,
}
else
return {
--"default", -- will be useful if I implement each FlyoutId having its own config
-- KEY_MOD_NA,
GermClickBehavior.OPEN,
GermClickBehavior.PRIME_BTN,
GermClickBehavior.RANDOM_BTN,
GermClickBehavior.CYCLE_ALL_BTNS,
--GermClickBehavior.REVERSE_CYCLE_ALL_BTNS,
}
end
end
---@param flyoutId number aspirational param for when I allow users to give each UFO its own configs
---@param mouseClick MouseClick
---@return GermClickBehavior
function Config:getGermClickBehavior(flyoutId, mouseClick)
local clickOpts = Config.opts.clickers.flyouts[flyoutId] or Config.opts.clickers.flyouts.default
return clickOpts[mouseClick]
end
local isUsingRecent -- cleared during setClickBehavior() and recalculated by isAnyClickerUsingRecent()
function Config:setClickBehavior(flyoutId, mouseClick, behavior)
isUsingRecent = nil
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
---@param modifierKey ModifierKey
---@return GermClickBehavior
function Config:getKeyModBehavior(modifierKey)
return Config.modifierKey[modifierKey]
end
function Config:isPrimeDefinedAsRecent()
return Config:get("primaryButtonIs") == PrimaryButtonIs.RECENT
end
function Config:isPrimeDefinedAsFirst()
return Config:get("primaryButtonIs") == PrimaryButtonIs.FIRST
end
function Config:isAnyClickerUsingRecent(flyoutId)
local isPrimeDefinedAsRecent = Config:get("primaryButtonIs") == PrimaryButtonIs.RECENT
if not isPrimeDefinedAsRecent then
return false
end
if isUsingRecent == nil then
local clickOpts = Config.opts.clickers.flyouts[flyoutId] or Config.opts.clickers.flyouts.default
for k, v in pairs(MouseClick) do
if clickOpts[v] == GermClickBehavior.PRIME_BTN then isUsingRecent = true end
end
end
return isUsingRecent
end
function Config:getPrimeClickers(flyoutId)
local primeClickers
local clickOpts = Config.opts.clickers.flyouts[flyoutId] or Config.opts.clickers.flyouts.default
for k, v in pairs(MouseClick) do
if clickOpts[v] == GermClickBehavior.PRIME_BTN then
if primeClickers == nil then
primeClickers = {}
end
primeClickers[#primeClickers +1] = v
zebug.info:print("isUsingRecent v",v)
end
end
return primeClickers
end
function Config:initializeOptionsMenu()
initializeOptionsMenu()
Config.AceConfigDialog = LibStub("AceConfigDialog-3.0");
LibStub("AceConfig-3.0"):RegisterOptionsTable(ADDON_NAME, optionsMenu)
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(ADDON_NAME, Ufo.myTitle)
end
function Config:toggle()
local myName = ADDON_NAME
local acd = Config.AceConfigDialog
local frames = acd.OpenFrames
if frames[myName] == nil then
acd:Open(myName)
if frames[myName] then
frames[myName]:SetStatusText(Ufo.versionMsg)
end
else
acd:Close(myName)
end
end
function Config:get(key)
if not key then
error("NiL provided as config field name.")
end
if not Config.field.name[key] then
error("No such config field exists with a name of "..key)
end
if Config.opts[key] == nil then
return Config.optDefaults[key]
else
return Config.opts[key]
end
end
function Config:deletePlaceholder()
Ufo.deletedPlaceholder = "Config: DELETE PLACEHOLDER"
zebug.info:name("opt:usePlaceHolders()"):print("DELETE ",PLACEHOLDER_MACRO_NAME,"START")
DeleteMacro(Ufo.PLACEHOLDER_MACRO_NAME) -- here
-- they claim lua is single threaded. lets see i WoW's engine is synchronous
zebug.info:name("opt:usePlaceHolders()"):print("DELETE ",PLACEHOLDER_MACRO_NAME, "DONE")
Ufo.deletedPlaceholder = nil
end
Config.deletePlaceholder = Pacifier:wrap(Config.deletePlaceholder, L10N.DELETE_PLACEHOLDERS)
-------------------------------------------------------------------------------
-- Versioning and Migration
-------------------------------------------------------------------------------
local migrationFuncs = {}
function Config:getRequiredVersion()
local vString = C_AddOns.GetAddOnMetadata(ADDON_NAME, "X-Config-Version") or 0
return tonumber(vString)
end
function Config:getCurrentVersion()
if not self.opts.version then
self.opts.version = 1
end
return self.opts.version
end
function Config:migrateToCurrentVersion()
local v = self:getCurrentVersion()
local required = self:getRequiredVersion()
if v == required then
return
elseif v > required then
-- um, hello time traveler
return
else
-- v < required
-- fix incompatible data, etc.
for i = v+1, required do
local migrate = migrationFuncs[i]
if migrate then
msgUserOrNot(L10N.cfg.MIGRATING_CONFIG_FROM_VERSION, self.opts.version, L10N.cfg.TO, i)
migrate()
self.opts.version = i
end
end
self.opts.version = required
end
end
migrationFuncs[3] = function()
local x = Config.opts
local clickers = x.clickers.flyouts.default
local old = "FIRST_BTN"
local new = GermClickBehavior.PRIME_BTN
---@param behavior GermClickBehavior
---@param clicker MouseClick
for clicker, behavior in pairs(clickers) do
if behavior == old then
msgUserOrNot(L10N.cfg.FIXING_CLICKER,clicker, L10N.cfg.FROM,old, L10N.cfg.TO, new)
clickers[clicker] = new
end
end
if x.keybindBehavior == old then
msgUserOrNot(L10N.cfg.FIXING_KEYBINDBEHAVIOR_FROM, old, L10N.cfg.TO, new)
x.keybindBehavior = new
end
end