forked from MuffinManKen/AutoBar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoBarOptions.lua
More file actions
2702 lines (2436 loc) · 70.7 KB
/
AutoBarOptions.lua
File metadata and controls
2702 lines (2436 loc) · 70.7 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
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--
-- AutoBarOptions
-- Copyright 2007+ Toadkiller of Proudmoore.
--
-- Configuration Options for AutoBar
-- http://muffinmangames.com
--
-- Custom Category:
-- AutoBarDB2.custom_categories[customCategoryIndex]
-- A separate list of Categories that is global to all players
-- Users add custom Categories to list.
-- Custom Categories can have specific items and spells dragged into their list.
-- Custom Categories can also be set to PT3 Sets, one regular Set & one priority Set
-- A priority Set item has priority over a regular Set item with the same value.
-- All common settings available to a built in Category are also available to a Custom category
-- CustomButton:
-- A separate list of Buttons that is global to all players
-- Button:
-- AutoBar.db.<account|class|char>.buttonList[buttonIndex]
-- Some Buttons like custom Buttons can have their Categories chosen from the Categories list
-- AutoBar.db.char.buttons[buttonName]
-- Contains the defaults for Button settings & changes to the settings are stored here.
-- Enable / Disable state is recorded here
-- Only one buttonName per button found in a Bar
-- barKey
-- defaultButtonIndex (#, "*" for at end, "~" for do not place, "buttonName" to insert after a button).
-- place: true. Placement sets it to false.
-- Buttons are placed in their barKey at defaultButtonIndex on initialize.
-- deleted: false. Can be deleted by deleting from a Bar.
-- Deleted Buttons can be added back to a Bar
-- Plugin & Custom Buttons are added here & must have non-clashing names
-- GLOBALS: IsShiftKeyDown, IsControlKeyDown, IsAltKeyDown, GameTooltip, InCombatLockdown, GetItemInfo, GetMacroInfo
local _, AB = ...
local types = AB.types ---@class ABTypes
local code = AB.code ---@class ABCode
local AutoBar = AutoBar
local _ABGData = AutoBarGlobalDataObject
local L = AutoBarGlobalDataObject.locale
local LDB = LibStub("LibDataBroker-1.1", true)
local ldbIcon = LibStub("LibDBIcon-1.0", true)
local AceCfgReg = LibStub("AceConfigRegistry-3.0")
local AceCfgDlg = LibStub("AceConfigDialog-3.0")
local AceCfgCmd = LibStub("AceConfigCmd-3.0")
local dewdrop = nil
local hintString = "|cffffffff%s:|r %s"
local hintText = {
"AutoBar",
hintString:format(L["Left-Click"], L["Options GUI"]),
hintString:format(L["Alt-Click"], L["Key Bindings"]),
hintString:format(L["Ctrl-Click"], L["Move the Buttons"]),
hintString:format(L["Shift-Click"], L["Move the Bars"]),
}
local function LDBOnClick(_clickedFrame, button)
if (button == "LeftButton") then
if (dewdrop and dewdrop:GetOpenedParent()) then
dewdrop:Close()
end
if (IsShiftKeyDown()) then
AutoBar:MoveBarModeToggle()
elseif (IsControlKeyDown()) then
AutoBar:MoveButtonsModeToggle()
elseif (IsAltKeyDown()) then
AB.LibKeyBound:Toggle()
elseif(AceCfgDlg.OpenFrames["AutoBar"]) then
AceCfgDlg:Close("AutoBar")
else
AutoBar:CreateOptionsAce3()
AceCfgDlg:Open("AutoBar")
end
elseif (button == "RightButton") then
InterfaceOptionsFrame_OpenToCategory("AutoBar")
InterfaceOptionsFrame_OpenToCategory("AutoBar")
end
end
function AutoBar:InitializeOptions()
self:CreateOptionsAce3()
if (LDB) then
local ldbAutoBar = LibStub("LibDataBroker-1.1"):NewDataObject("AutoBar", {
type = "launcher",
icon = "Interface\\Icons\\INV_Ingot_Eternium",
tocname = "AutoBar",
label = "AutoBar",
OnClick = LDBOnClick,
OnTooltipShow = function(tooltip)
if (dewdrop and dewdrop:GetOpenedParent()) then
GameTooltip:Hide()
end
if (tooltip and tooltip.AddLine) then
for _i, text in ipairs(hintText) do
tooltip:AddLine(text)
end
end
end,
})
if (ldbIcon) then
ldbIcon:Register("AutoBar", ldbAutoBar, AutoBarDB2.ldb_icon)
self.optionsMain.args.main.args.ldbIcon = {
type = "toggle",
order = 199,
width = 1.2,
name = L["Show Minimap Icon"],
desc = L["Show Minimap Icon"],
get = function() return not AutoBarDB2.ldb_icon.hide end,
set = function(_info, value)
value = not value
AutoBarDB2.ldb_icon.hide = value
if (value) then
ldbIcon:Hide("AutoBar")
else
ldbIcon:Show("AutoBar")
end
end,
}
end
end
end
function AutoBar:OpenOptions()
AutoBar:RefreshButtonDBList()
AutoBar:RefreshBarDBLists()
AutoBar:RemoveDuplicateButtons()
AutoBar:RefreshUnplacedButtonList()
AutoBar:CreateOptionsAce3()
AceCfgReg:NotifyChange("AutoBar")
AceCfgDlg:Open("AutoBar")
end
function AutoBarChanged()
AB.UpdateObjects()
AceCfgReg:NotifyChange("AutoBar")
end
-- local function ButtonCategoriesChanged()
-- AutoBar:CreateCustomCategoryOptions(AutoBar.optionsMain.args.categories.args)
-- AB.UpdateCategories()
-- end
function AutoBar:ButtonsChanged()
AutoBar:RefreshButtonDBList()
AutoBar:RemoveDuplicateButtons()
AutoBar:RefreshUnplacedButtonList()
AutoBar:CreateButtonOptions(AutoBar.optionsMain.args.buttons.args)
AB.UpdateCategories()
AceCfgReg:NotifyChange("AutoBar")
end
function AutoBar:BarButtonChanged()
AutoBar:RefreshButtonDBList()
AutoBar:RemoveDuplicateButtons()
AutoBar:RefreshBarDBLists()
AutoBar:RefreshUnplacedButtonList()
AB.UpdateCategories()
AutoBar:CreateOptionsAce3()
AceCfgReg:NotifyChange("AutoBar")
end
function AutoBar:BarsChanged()
AutoBar:RefreshButtonDBList()
AutoBar:RefreshBarDBLists()
AutoBar:RemoveDuplicateButtons()
AutoBar:RefreshUnplacedButtonList()
AutoBar:CreateOptionsAce3()
AB.UpdateCategories()
AceCfgReg:NotifyChange("AutoBar")
end
function AutoBar:CategoriesChanged()
AutoBar:CreateCustomCategoryOptions(AutoBar.optionsMain.args.categories.args)
AB.UpdateCategories()
AceCfgReg:NotifyChange("AutoBar")
end
local function CopyTable(source, target)
for k, _v in pairs(source) do
if (type(k) == "table") then
target[k] = {}
CopyTable(source[k], target[k])
else
target[k] = source[k]
end
end
end
local shareValidateList = {
["1"] = L["None"], -- char
["2"] = L["Class"],
["3"] = L["Account"],
}
local SHARED_NONE = "1"
local SHARED_CLASS = "2"
local SHARED_ACCOUNT = "3"
function AutoBar:GetSharedBarDB(barKey, sharedVar)
local charDB = AutoBar.char.barList[barKey]
local classDB = AutoBar.class.barList[barKey]
local accountDB = AutoBarDB2.account.barList[barKey]
local debug = false --barKey == "AutoBarClassBarBasic"
if (debug) then code.log_warning("AutoBar:GetSharedBarDB(", barKey, ", ", sharedVar, ")"); end
if (debug) then code.log_warning("charDB", charDB, " classDB", classDB, " accountDB", accountDB); end
-- Char specific db overides all others
if (charDB and charDB[sharedVar]) then
if (charDB[sharedVar] == SHARED_NONE) then
return charDB
elseif (charDB[sharedVar] == SHARED_CLASS and classDB) then
return classDB
elseif (charDB[sharedVar] == SHARED_ACCOUNT and accountDB) then
return accountDB
end
end
-- Class db overides account
if (classDB and classDB[sharedVar]) then
if (classDB[sharedVar] == SHARED_NONE and charDB) then
return charDB
elseif (classDB[sharedVar] == SHARED_CLASS) then
return classDB
elseif (classDB[sharedVar] == SHARED_ACCOUNT and accountDB) then
return accountDB
end
end
if (debug) then code.log_warning("accountDB", accountDB, " sharedVar", accountDB[sharedVar]); end
-- Default to account
if (accountDB and accountDB[sharedVar]) then
if (accountDB[sharedVar] == SHARED_NONE and charDB) then
return charDB
elseif (accountDB[sharedVar] == SHARED_CLASS and classDB) then
return classDB
elseif (accountDB[sharedVar] == SHARED_ACCOUNT) then
return accountDB
end
end
-- No specific setting so use the widest scope available
if (accountDB) then
if (debug) then code.log_warning("using accountDB"); end
if (debug) then code.log_warning(code.Dump(accountDB, 1)); end
return accountDB
elseif (classDB) then
return classDB
elseif (charDB) then
return charDB
else
assert(accountDB and classDB and charDB, "AutoBar:GetSharedBarDB nil accountDB, classDB, charDB")
end
end
function AutoBar:GetSharedBarDBValue(barKey, sharedVar)
-- Char specific db overides all others
local charDB = AutoBar.char.barList[barKey]
if (charDB and charDB[sharedVar]) then
return charDB[sharedVar]
end
-- Class db overides account
local classDB = AutoBar.class.barList[barKey]
if (classDB and classDB[sharedVar]) then
return classDB[sharedVar]
end
-- Default to account
local accountDB = AutoBarDB2.account.barList[barKey]
if (accountDB and accountDB[sharedVar]) then
return accountDB[sharedVar]
end
-- No specific setting so use the widest scope available
if (accountDB) then
return SHARED_ACCOUNT
elseif (classDB) then
return SHARED_CLASS
elseif (charDB) then
return SHARED_NONE
else
assert(accountDB and classDB and charDB, "AutoBar:GetSharedBarDBValue nil accountDB, classDB, charDB")
end
end
--/dump AutoBar:GetSharedBarDBValue("AutoBarClassBarHunter", "sharedLayout")
--/dump AutoBar:GetSharedBarDB("AutoBarClassBarHunter", "sharedLayout")
--/dump AutoBar.char.barList["AutoBarClassBarHunter"]
--/dump AutoBar:GetSharedBarDBValue("AutoBarClassBarHunter", "sharedButtons")
--/dump AutoBar:GetSharedBarDB("AutoBarClassBarHunter", "sharedButtons")
function AutoBar:SetSharedBarDB(barKey, sharedVar, value)
local charDB, classDB, accountDB
if (value == SHARED_NONE) then
charDB = AutoBar.char.barList[barKey]
if (not charDB) then
local sourceDB = AutoBar:GetSharedBarDB(barKey, sharedVar)
charDB = {}
AutoBar.char.barList[barKey] = charDB
CopyTable(sourceDB, charDB)
end
charDB[sharedVar] = value
elseif (value == SHARED_CLASS) then
classDB = AutoBar.class.barList[barKey]
if (not classDB) then
local sourceDB = AutoBar:GetSharedBarDB(barKey, sharedVar)
classDB = {}
AutoBar.class.barList[barKey] = classDB
CopyTable(sourceDB, classDB)
end
classDB[sharedVar] = value
charDB = AutoBar.char.barList[barKey]
if (charDB) then
charDB[sharedVar] = nil
end
elseif (value == SHARED_ACCOUNT) then
accountDB = AutoBarDB2.account.barList[barKey]
if (accountDB) then
charDB = AutoBar.char.barList[barKey]
if (charDB) then
charDB[sharedVar] = nil
end
classDB = AutoBar.class.barList[barKey]
if (classDB) then
classDB[sharedVar] = nil
end
accountDB[sharedVar] = nil
else
-- Disallow promotion to account.
end
end
end
function AutoBar:GetButtonDB(buttonKey)
-- assert(buttonKey, "nil buttonKey")
local db, accountDB
-- Char specific db overides all others
db = AutoBar.char.buttonList[buttonKey]
if (db) then
if (db.shared and db.shared == SHARED_NONE) then
return db
elseif (db.shared and db.shared == SHARED_CLASS) then
return AutoBar.class.buttonList[buttonKey]
elseif (not db.shared or db.shared == SHARED_ACCOUNT) then
return AutoBarDB2.account.buttonList[buttonKey]
end
end
-- Class db overides account
db = AutoBar.class.buttonList[buttonKey]
if (db) then
if (db.shared and db.shared == SHARED_CLASS) then
return db
elseif (not db.shared or db.shared == SHARED_ACCOUNT) then
accountDB = AutoBarDB2.account.buttonList[buttonKey]
if (accountDB) then
return accountDB
else
return db
end
end
end
accountDB = AutoBarDB2.account.buttonList[buttonKey]
if (accountDB) then
return accountDB
end
return db
end
function AutoBar:GetSharedButtonDBValue(buttonKey)
-- Char specific db overides all others
local charDB = AutoBar.char.buttonList[buttonKey]
if (charDB and charDB.shared) then
return charDB.shared
end
-- Class db overides account
local classDB = AutoBar.class.buttonList[buttonKey]
if (classDB and classDB.shared) then
return classDB.shared
end
-- Default to account
local accountDB = AutoBarDB2.account.buttonList[buttonKey]
if (accountDB and accountDB.shared) then
return accountDB.shared
end
-- No specific setting so use the widest scope available
if (accountDB) then
return SHARED_ACCOUNT
elseif (classDB) then
return SHARED_CLASS
elseif (charDB) then
return SHARED_NONE
else
assert(accountDB and classDB and charDB, "AutoBar:GetSharedButtonDBValue nil accountDB, classDB, charDB")
end
end
function AutoBar:SetSharedButtonDB(buttonKey, value)
local charDB, classDB, accountDB
if (value == SHARED_NONE) then
charDB = AutoBar.char.buttonList[buttonKey]
if (not charDB) then
local sourceDB = AutoBar:GetButtonDB(buttonKey)
charDB = {}
AutoBar.char.buttonList[buttonKey] = charDB
CopyTable(sourceDB, charDB)
end
charDB.shared = value
elseif (value == SHARED_CLASS) then
classDB = AutoBar.class.buttonList[buttonKey]
if (not classDB) then
local sourceDB = AutoBar:GetButtonDB(buttonKey)
classDB = {}
AutoBar.class.buttonList[buttonKey] = classDB
CopyTable(sourceDB, classDB)
end
classDB.shared = value
charDB = AutoBar.char.buttonList[buttonKey]
if (charDB) then
charDB.shared = nil
end
elseif (value == SHARED_ACCOUNT) then
accountDB = AutoBarDB2.account.buttonList[buttonKey]
if (not accountDB) then
local sourceDB = AutoBar:GetButtonDB(buttonKey)
accountDB = {}
AutoBarDB2.account.buttonList[buttonKey] = accountDB
CopyTable(sourceDB, accountDB)
end
charDB = AutoBar.char.buttonList[buttonKey]
if (charDB) then
charDB.shared = nil
end
classDB = AutoBar.class.buttonList[buttonKey]
if (classDB) then
classDB.shared = nil
end
end
end
function AutoBar:GetCategoriesItemDB(categoryKey, itemIndex)
local config = AutoBarDB2.custom_categories[categoryKey]
if (itemIndex) then
config = config.items[itemIndex]
end
return config
end
--[[
local function ResetBarList(barList)
for barKey, barDB in pairs(barList) do
if (not barDB.isCustomBar) then
barList[barKey] = nil
end
end
end
--]]
--[[
local function ResetBars()
ResetBarList(AutoBarDB2.account.barList)
for _classKey, classDB in pairs(AutoBarDB2.classes) do
ResetBarList(classDB.barList)
end
for _charKey, charDB in pairs(AutoBarDB2.chars) do
ResetBarList(charDB.barList)
end
AutoBar:InitializeDefaults()
AutoBar:RefreshBarDBLists()
for _barKey, bar in pairs(AutoBar.barList) do
bar:UpdateShared()
end
AutoBar:PopulateBars()
AutoBar:CreateOptionsAce3()
AB.UpdateCategories()
AceCfgReg:NotifyChange("AutoBar")
end
--]]
--[[
local function ResetButtons()
AutoBar:PopulateBars()
AutoBar:CreateOptionsAce3()
AB.UpdateCategories()
AceCfgReg:NotifyChange("AutoBar")
end
--]]
-- local function ResetAutoBar()
-- AutoBar:PopulateBars()
-- AutoBar:CreateOptionsAce3()
-- AB.UpdateCategories()
-- AceCfgReg:NotifyChange("AutoBar")
-- end
function AutoBar:OnProfileDisable()
end
function AutoBar:OnProfileEnable()
end
local function getCombatLockdown()
return InCombatLockdown()
end
local function getDocking(info)
local barKey = info.arg.barKey
local docking = AutoBar.barLayoutDBList[barKey].docking
if (not docking) then
docking = "NONE"
end
return docking
end
local function setDocking(info, value)
local barKey = info.arg.barKey
if (value == "NONE") then
value = nil
end
AutoBar.barLayoutDBList[barKey].docking = value
AutoBarChanged()
end
local function setFrameStrata(info, value)
local barKey = info.arg.barKey
AutoBar.barLayoutDBList[barKey].frameStrata = value
local bar = AutoBar.barList[barKey]
if (bar) then
bar.frame:SetFrameStrata(value)
end
AutoBarChanged()
end
local function getCustomBarName(info)
local barKey = info.arg.barKey
return AutoBar.barLayoutDBList[barKey].name
end
local function setCustomBarName(info, value)
value = code.GetValidatedName(value)
if (value and value ~= "") then
local barKey = info.arg.barKey
if (not Bar:NameExists(value)) then
local customBarDB = AutoBar.barLayoutDBList[barKey]
customBarDB.name = value
local bar = AutoBar.barList[barKey]
if (bar) then
bar:ChangeName(value)
end
Bar:Rename(barKey, value)
AutoBar:BarsChanged()
end
end
end
local function getCustomButtonName(info)
local buttonKey = info.arg.buttonKey
return AutoBar:GetButtonDB(buttonKey).name
end
local function setCustomButtonName(info, value)
value = code.GetValidatedName(value)
if (value and value ~= "") then
local buttonKey = info.arg.buttonKey
if (AutoBar.Class.Button:NameExists(value)) then
else
AutoBar.Class.Button:Rename(buttonKey, value)
AutoBar:BarButtonChanged()
end
end
end
local function setButtonArrangeOnUse(info, value)
local buttonKey = info.arg.buttonKey
AutoBar:GetButtonDB(buttonKey).arrangeOnUse = value
local buttonData = AutoBar.char.buttonDataList[buttonKey]
if (buttonData) then
buttonData.arrangeOnUse = nil
end
AutoBarChanged()
end
-- Cut the button at fromIndex out of fromBarKey
-- 1 <= fromIndex <= # fromButtonKeyList
-- Adjust the remaining buttons to fill the gap if any
-- Return the button, its DB & its Options
function AutoBar:ButtonCut(fromBarKey, fromIndex)
local fromButtonKeyList = AutoBar.barButtonsDBList[fromBarKey].buttonKeys
local nButtons = # fromButtonKeyList
assert(fromIndex > 0, "AutoBar:ButtonCut fromIndex < 1")
assert(fromIndex <= nButtons, "AutoBar:ButtonCut " .. tostring(fromBarKey) .. " fromIndex (" .. tostring(fromIndex) .. ") > nButtons (" .. tostring(nButtons) .. ")")
local buttonKey = fromButtonKeyList[fromIndex]
for index = fromIndex, nButtons, 1 do
fromButtonKeyList[index] = fromButtonKeyList[index + 1]
end
local bar = AutoBar.barList[fromBarKey]
local button
if (bar) then
button = bar.buttonList[fromIndex]
end
return buttonKey, button
end
-- Paste buttonKey, buttonOptions at toIndex of toBarKey
-- 1 <= toIndex <= # toButtonKeyList + 1
-- Adjust the remaining buttons to fill the gap if any
function AutoBar:ButtonPaste(buttonDB, fromBarKey, toBarKey, toIndex, button)
local toButtonKeyList = AutoBar.barButtonsDBList[toBarKey].buttonKeys
local nButtons = # toButtonKeyList
assert(toIndex > 0, "AutoBar:ButtonPaste toIndex < 1")
assert(toIndex <= nButtons + 1, "AutoBar:ButtonPaste toIndex > nButtons + 1")
assert(buttonDB, "AutoBar:ButtonPaste buttonDB nil")
local multiBarPaste = fromBarKey ~= toBarKey
-- Avoid duplication
local duplicate
if (multiBarPaste) then
local targetButtonKey = buttonDB.buttonKey
for buttonKeyIndex, buttonKey in pairs(toButtonKeyList) do
if (targetButtonKey == buttonKey) then
duplicate = true
break
end
end
end
if (not duplicate) then
-- Make room
if (toIndex <= nButtons) then
for index = nButtons + 1, toIndex + 1, -1 do
toButtonKeyList[index] = toButtonKeyList[index - 1]
end
end
-- Paste it
toButtonKeyList[toIndex] = buttonDB.buttonKey
end
-- Handle reparenting for multiBarPaste of the actual button
if (multiBarPaste) then
buttonDB.barKey = toBarKey
local parentBar = AutoBar.barList[toBarKey]
if (button) then
button:Refresh(parentBar, buttonDB)
button.parentBar.frame:SetAttribute("addchild", button.frame)
end
end
end
-- This supports moving without the lame condition where you cannot move to a particular end
-- Button is cut from fromIndex of fromBarKey and inserted at toIndex of toBarKey
-- For toIndex <= toButtonKeyList existing buttons are shuffled up to make room
-- For toIndex > toButtonKeyList button is inserted at end
function AutoBar:ButtonMove(fromBarKey, fromIndex, toBarKey, toIndex)
local fromButtonKeyList = AutoBar.barButtonsDBList[fromBarKey].buttonKeys
local toButtonKeyList = AutoBar.barButtonsDBList[toBarKey].buttonKeys
local nButtons = # toButtonKeyList
local multiBarMove = fromBarKey ~= toBarKey
-- Wrangle the indexes
if (toIndex < 1) then
toIndex = 1
end
if (toIndex > nButtons) then
if (multiBarMove) then
-- Special case move to end across multiple bars
toIndex = nButtons + 1
else
toIndex = nButtons
end
end
if (not multiBarMove) then
if (toIndex > fromIndex) then
-- Adjust offset due to cut from earlier in the list
-- toIndex = toIndex - 1
elseif (toIndex == fromIndex) then
return
end
end
-- Cut & Paste
local buttonKey, button = AutoBar:ButtonCut(fromBarKey, fromIndex)
local buttonDB = AutoBar:GetButtonDB(buttonKey)
AutoBar:ButtonPaste(buttonDB, fromBarKey, toBarKey, toIndex, button)
end
local function BarNew()
local newBarName, barKey = AB.Bar:GetNewName(L["Custom"])
AutoBarDB2.account.barList[barKey] = {
name = newBarName,
desc = newBarName,
enabled = true,
rows = 1,
columns = 16,
alignButtons = "3",
alpha = 1,
docking = nil,
dockShiftX = 0,
dockShiftY = 0,
fadeOut = false,
frameStrata = "LOW",
hide = false,
padding = 0,
popupDirection = "1",
scale = 1,
showOnModifier = nil,
posX = 300,
posY = 360,
allowed_class = "*",
isCustomBar = true,
buttonKeys = {},
}
AutoBar:BarsChanged()
--DevTools_Dump(AutoBarDB2.account.barList)
end
--/Dump AutoBarDB2.account.barList
--/dump AutoBarDB2.account.barList["AutoBarCustomBar1"]
--/Script AutoBarDB2.account.barList["AutoBarCustomBar1"] = nil
local function BarButtonDelete(barKey, buttonKey, buttonIndex)
local buttonKey, button = AutoBar:ButtonCut(barKey, buttonIndex)
-- Move to disabled cache
if (AutoBar.buttonList[buttonKey]) then
AutoBar.buttonListDisabled[buttonKey] = AutoBar.buttonList[buttonKey]
AutoBar.buttonList[buttonKey] = nil
end
if (button) then
button.frame:Hide()
end
end
local function BarDelete(info)
local barKey = info.arg.barKey
local bar = AutoBar.barList[barKey]
if (bar) then
for buttonKey, button in pairs(bar.buttonList) do
if (AutoBar.buttonList[buttonKey]) then
AutoBar.buttonListDisabled[buttonKey] = AutoBar.buttonList[buttonKey]
AutoBar.buttonList[buttonKey] = nil
end
button.frame:Hide()
end
end
AutoBar.barList[barKey] = nil
AutoBarDB2.account.barList[barKey] = nil
for _, classDB in pairs(AutoBarDB2.classes) do
classDB.barList[barKey] = nil
end
for _, charDB in pairs(AutoBarDB2.chars) do
charDB.barList[barKey] = nil
end
AutoBar.optionsMain.args.bars.args[barKey] = nil
AutoBar:BarsChanged()
end
local function CustomButtonReset()
AutoBar.Class.Button:OptionsReset()
AutoBar:ButtonsChanged()
end
local MAXBARBUTTONS = 64
local function BarButtonNew(info)
local barKey = info.arg.barKey
local buttonKeys = AutoBar.barButtonsDBList[barKey].buttonKeys
local buttonIndex = # buttonKeys + 1
if (buttonIndex <= MAXBARBUTTONS) then
local newButtonName, customButtonKey = AutoBar.Class.Button:GetNewName(L["Custom"])
AutoBarDB2.account.buttonList[customButtonKey] = {
name = newButtonName,
buttonKey = customButtonKey,
buttonClass = "AutoBarButtonCustom",
barKey = barKey,
hasCustomCategories = true,
enabled = true,
}
AutoBarDB2.account.buttonList[customButtonKey][1] = "Misc.Hearth"
buttonKeys[buttonIndex] = customButtonKey
end
AutoBar:BarButtonChanged()
end
local function ButtonDelete(info)
local barKey, buttonKey, buttonIndex = info.arg.barKey, info.arg.buttonKey, info.arg.buttonIndex
local barButtonsDBList = AutoBar.barButtonsDBList
for barKey, barDB in pairs(barButtonsDBList) do
for barButtonIndex, barButtonKey in pairs(barDB.buttonKeys) do
if (barButtonKey == buttonKey) then
BarButtonDelete(barKey, buttonKey, barButtonIndex)
end
end
end
AutoBar.Class.Button:Delete(buttonKey)
AutoBarSearch:Reset()
AutoBar:BarButtonChanged()
end
-- /dump AutoBar.buttonDBList
-- /dump AutoBar.buttonDBList["AutoBarCustomButton4"]
-- /script AutoBarDB2.account.buttonList["AutoBarCustomButton4"] = nil
-- /script AutoBarDB2.account.buttonList["AutoBarCustomButton4"] = nil
local function ButtonRemove(info, oldBarKey, buttonKey)
if (info) then
oldBarKey, buttonKey = info.arg.barKey, info.arg.buttonKey
end
-- Search for its bar & cut it out
local barButtonsDBList = AutoBar.barButtonsDBList
for barKey, barDB in pairs(barButtonsDBList) do
for barButtonIndex, barButtonKey in pairs(barDB.buttonKeys) do
if (barButtonKey == buttonKey) then
BarButtonDelete(barKey, buttonKey, barButtonIndex)
end
end
end
-- Update its Bar location
local buttonDB = AutoBar.buttonDBList[buttonKey]
buttonDB.barKey = nil
AutoBar:BarButtonChanged()
end
local function ButtonNew()
local newButtonName, customButtonKey = AutoBar.Class.Button:GetNewName(L["Custom"])
AutoBarDB2.account.buttonList[customButtonKey] = {
name = newButtonName,
buttonKey = customButtonKey,
buttonClass = "AutoBarButtonCustom",
hasCustomCategories = true,
enabled = true,
}
AutoBarDB2.account.buttonList[customButtonKey][1] = "Misc.Hearth"
AutoBar:ButtonsChanged()
--DevTools_Dump(AutoBarDB2.account.buttonList)
end
local function getAddButtonName(info)
return nil
end
local function setAddButtonName(info, value)
local barKey = info.arg.barKey
local buttonKey = value
local buttonDB = AutoBar.buttonDBList[buttonKey]
if (buttonDB.barKey) then
ButtonRemove(nil, buttonDB.barKey, buttonKey)
end
local buttonKeys = AutoBar.barButtonsDBList[barKey].buttonKeys
buttonKeys[# buttonKeys + 1] = value
AutoBar:BarButtonChanged()
end
--[[
local function BarReset()
Bar:OptionsReset()
AutoBar:BarsChanged()
end
--]]
local function CategoryReset()
AutoBarDB2.custom_categories = {}
AutoBar:CategoriesChanged()
end
function AutoBar:CategoryNew()
local newCategoryName, categoryKey = AB.GetNewCustomCategoryName(L["Custom"], 1)
local customCategories = AutoBarDB2.custom_categories
customCategories[categoryKey] = {
name = newCategoryName,
desc = newCategoryName,
categoryKey = categoryKey,
items = {},
}
AutoBarCategoryList[categoryKey] = AB.CustomCategory:new(AutoBarDB2.custom_categories[categoryKey])
AutoBar:CategoriesChanged()
return categoryKey
end
local function CategoryDelete(info)
local categoryKey = info.arg.categoryKey
local categoriesListDB = AutoBarDB2.custom_categories
--print("CategoryDelete", categoryKey, categoriesListDB[categoryKey])
categoriesListDB[categoryKey] = nil
AutoBarCategoryList[categoryKey] = nil
AutoBar.optionsMain.args.categories.args[categoryKey] = nil
-- ToDo: remove category references from all Buttons.
AutoBar:CategoriesChanged()
end
--DevTools_Dump(categoriesListDB)
-- /dump AutoBarDB2.custom_categories
local function CategoryItemNew(info)
local categoryKey = info.arg.categoryKey
local itemsListDB = AutoBarDB2.custom_categories[categoryKey].items
local itemIndex = # itemsListDB + 1
itemsListDB[itemIndex] = {}
AutoBar:CategoriesChanged()
end
local otherMacroNames = {}
local function GetNewMacroName(itemsListDB)
for key in pairs(otherMacroNames) do
otherMacroNames[key] = nil
end
for itemIndex, itemsDB in pairs(itemsListDB) do
if (itemsDB.itemType == "macroCustom") then
otherMacroNames[itemsDB.itemId] = true
end
end
local baseName = L["Custom"]
local newName
local key_seed = 0
while true do
newName = baseName .. key_seed
key_seed = key_seed + 1
if (not otherMacroNames[newName]) then
break
end
end
return newName
end
local function CategoryMacroNew(info)
local categoryKey = info.arg.categoryKey
local itemsListDB = AutoBarDB2.custom_categories[categoryKey].items
local itemIndex = # itemsListDB + 1
local name = GetNewMacroName(itemsListDB)
local macroCustom = {
itemType = "macroCustom",
itemId = name,