This repository was archived by the owner on Apr 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimerBars_Options.lua
More file actions
1625 lines (1446 loc) · 59.6 KB
/
TimerBars_Options.lua
File metadata and controls
1625 lines (1446 loc) · 59.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
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
local trace = print
TIMERBARS.MAXBARSPACING = 24;
TIMERBARS.MAXBARPADDING = 12;
local GetActiveTalentGroup = _G.GetActiveSpecGroup
local LSM = LibStub("LibSharedMedia-3.0", true);
local textureList = LSM:List("statusbar");
local fontList = LSM:List("font");
local TimerBars_OldProfile = nil;
local TimerBars_OldSettings = nil;
TimerBarsOptions = {}
TimerBarsRMB = {}
function TimerBars.FindProfileByName(profName)
local key
for k,t in pairs(TimerBars_Profiles) do
if t.name == profName then
return k
end
end
end
function TimerBars.SlashCommand(cmd)
local args = {}
for arg in cmd:gmatch("(%S+)") do
table.insert(args, arg)
end
cmd = args[1]
table.remove(args,1)
if not cmd then
TimerBars.LockToggle();
elseif ( cmd == TIMERBARS.CMD_RESET ) then
TimerBars.Reset();
elseif ( cmd == TIMERBARS.CMD_SHOW ) then
TimerBars.Show(true);
elseif ( cmd == TIMERBARS.CMD_HIDE ) then
TimerBars.Show(false);
elseif ( cmd == TIMERBARS.CMD_PROFILE ) then
if args[1] then
local profileName = table.concat(args, " ")
local key = TimerBars.FindProfileByName( profileName )
if key then
TimerBars.ChangeProfile(key)
TimerBarsOptions.UIPanel_Profile_Update()
else
print("Could not find a profile named '",profileName,"'");
end
else
local spec = GetActiveTalentGroup()
local profile = TimerBars.CharSettings.Specs[spec]
print("Current TimerBars profile is \""..profile.."\"") -- LOCME!
end
else
print("Unknown TimerBars command",cmd)
end
end
function TimerBars.LockToggle(bLock)
if nil == bLock then
if TimerBars.CharSettings["Locked"] then
bLock = false;
else
bLock = true;
end
end
TimerBars.Show(true);
if TimerBars.CharSettings["Locked"] ~= bLock then
TimerBars.CharSettings["Locked"] = bLock;
TimerBars.last_cast = {};
TimerBars.Update();
end
end
-- -----------------------------
-- INTERFACE OPTIONS PANEL: MAIN
-- -----------------------------
function TimerBarsOptions.UIPanel_OnLoad(self)
local panelName = self:GetName();
local numberbarsLabel = _G[panelName.."NumberbarsLabel"];
local fixedDurationLabel = _G[panelName.."FixedDurationLabel"];
_G[panelName.."Version"]:SetText(TIMERBARS.VERSION);
_G[panelName.."SubText1"]:SetText(TIMERBARS.UIPANEL_SUBTEXT1);
numberbarsLabel:SetText(TIMERBARS.UIPANEL_NUMBERBARS);
numberbarsLabel:SetWidth(50);
fixedDurationLabel:SetText(TIMERBARS.UIPANEL_FIXEDDURATION);
fixedDurationLabel:SetWidth(50);
end
function TimerBarsOptions.UIPanel_OnShow()
TimerBars_OldProfile =TimerBars.ProfileSettings;
TimerBars_OldSettings = CopyTable(TimerBars.ProfileSettings);
TimerBarsOptions.UIPanel_Update();
end
function TimerBarsOptions.UIPanel_Update()
local panelName = "InterfaceOptionsTimerBarsPanel";
if not _G[panelName]:IsVisible() then return end
local settings = TimerBars.ProfileSettings;
for groupID = 1, settings.nGroups do
TimerBarsOptions.GroupEnableButton_Update(groupID);
TimerBarsOptions.NumberbarsWidget_Update(groupID);
_G[panelName.."Group"..groupID.."FixedDurationBox"]:SetText(settings.Groups[groupID]["FixedDuration"] or "");
end
end
function TimerBarsOptions.GroupEnableButton_Update(groupID)
local button = _G["InterfaceOptionsTimerBarsPanelGroup"..groupID.."EnableButton"];
button:SetChecked(TimerBars.ProfileSettings.Groups[groupID]["Enabled"]);
end
function TimerBarsOptions.GroupEnableButton_OnClick(self)
local groupID = self:GetParent():GetID();
if ( self:GetChecked() ) then
if groupID > TimerBars.ProfileSettings.nGroups then
TimerBars.ProfileSettings.nGroups = groupID
end
TimerBars.ProfileSettings.Groups[groupID]["Enabled"] = true;
else
TimerBars.ProfileSettings.Groups[groupID]["Enabled"] = false;
end
TimerBars.Update();
end
function TimerBarsOptions.NumberbarsWidget_Update(groupID)
local widgetName = "InterfaceOptionsTimerBarsPanelGroup"..groupID.."NumberbarsWidget";
local text = _G[widgetName.."Text"];
local leftButton = _G[widgetName.."LeftButton"];
local rightButton = _G[widgetName.."RightButton"];
local numberBars = TimerBars.ProfileSettings.Groups[groupID]["NumberBars"];
text:SetText(numberBars);
leftButton:Enable();
rightButton:Enable();
if ( numberBars == 1 ) then
leftButton:Disable();
elseif ( numberBars == TIMERBARS.MAXBARS ) then
rightButton:Disable();
end
end
function TimerBarsOptions.NumberbarsButton_OnClick(self, increment)
local groupID = self:GetParent():GetParent():GetID();
local oldNumber = TimerBars.ProfileSettings.Groups[groupID]["NumberBars"];
if ( oldNumber == 1 ) and ( increment < 0 ) then
return;
elseif ( oldNumber == TIMERBARS.MAXBARS ) and ( increment > 0 ) then
return;
end
TimerBars.ProfileSettings.Groups[groupID]["NumberBars"] = oldNumber + increment;
TimerBars.Group_Update(groupID);
TimerBarsOptions.NumberbarsWidget_Update(groupID);
end
function TimerBarsOptions.FixedDurationEditBox_OnTextChanged(self)
local enteredText = self:GetText();
if enteredText == "" then
TimerBars.ProfileSettings.Groups[self:GetParent():GetID()]["FixedDuration"] = nil;
else
TimerBars.ProfileSettings.Groups[self:GetParent():GetID()]["FixedDuration"] = enteredText;
end
TimerBars.Update();
end
function TimerBarsOptions.Cancel()
-- Can't copy the table here since ProfileSettings needs to point to the right place in
-- TimerBars_Globals.Profiles or in TimerBars_CharSettings.Profiles
-- FIXME: This is only restoring a small fraction of the total settings.
TimerBars.RestoreTableFromCopy(TimerBars_OldProfile, TimerBars_OldSettings);
-- FIXME: Close context menu if it's open; it may be referring to bar that doesn't exist
TimerBars.Update();
end
-- -----------------------------------
-- INTERFACE OPTIONS PANEL: APPEARANCE
-- -----------------------------------
TimerBarsOptions.DefaultSelectedColor = { 0.1, 0.6, 0.8, 1 }
TimerBarsOptions.DefaultNormalColor = { 0.7, 0.7, 0.7, 0 }
function TimerBarsOptions.UIPanel_Appearance_OnLoad(self)
self.name = TIMERBARS.UIPANEL_APPEARANCE;
self.parent = "TimerBars"
self.default = TimerBars.ResetCharacter
self.cancel = TimerBarsOptions.Cancel
-- need different way to handle cancel? users might open appearance panel without opening main panel
InterfaceOptions_AddCategory(self)
local panelName = self:GetName()
_G[panelName.."Version"]:SetText(TIMERBARS.VERSION)
_G[panelName.."SubText1"]:SetText(TIMERBARS.UIPANEL_APPEARANCE_SUBTEXT1)
self.Textures.fnClick = TimerBarsOptions.OnClickTextureItem
self.Textures.configure = function(i, btn, label)
btn.Bg:SetTexture(TimerBars.LSM:Fetch("statusbar",label))
end
self.Textures.List.update = TimerBarsOptions.UpdateBarTextureDropDown
self.Textures.normal_color = { 0.7, 0.7, 0.7, 1 }
self.Fonts.fnClick = TimerBarsOptions.OnClickFontItem
self.Fonts.configure = function(i, btn, label)
local fontPath = TimerBars.LSM:Fetch("font",label)
btn.text:SetFont(fontPath, 12)
btn.Bg:SetTexture(TimerBars.LSM:Fetch("statusbar","Minimalist"))
end
self.Fonts.List.update = TimerBarsOptions.UpdateBarFontDropDown
_G[panelName.."TexturesTitle"]:SetText("Texture:") -- LOCME
_G[panelName.."FontsTitle"]:SetText("Font:") -- LOCME
end
function TimerBarsOptions.UIPanel_Appearance_OnShow(self)
TimerBarsOptions.UIPanel_Appearance_Update();
-- todo: Cache this? Update needs it to
local idxCurrent = 1
for i = 1, #textureList do
if TimerBars.ProfileSettings["BarTexture"] == textureList[i] then
idxCurrent = i
break;
end
end
local idxScroll = idxCurrent - 3
if idxScroll < 0 then
idxScroll = 0
end
self.Textures.List.scrollBar:SetValue(idxScroll * self.Textures.List.buttonHeight+0.1)
HybridScrollFrame_OnMouseWheel(self.Textures.List, 1, 0.1);
for i = 1, #fontList do
if TimerBars.ProfileSettings["BarFont"] == fontList[i] then
idxCurrent = i
break;
end
end
idxScroll = idxCurrent - 3
if idxScroll < 0 then
idxScroll = 0
end
self.Fonts.List.scrollBar:SetValue(idxScroll * self.Fonts.List.buttonHeight+0.1)
HybridScrollFrame_OnMouseWheel(self.Fonts.List, 1, 0.1);
end
function TimerBarsOptions.UIPanel_Appearance_Update()
local panelName = "InterfaceOptionsTimerBarsAppearancePanel";
local panel = _G[panelName]
if not panel or not panel:IsVisible() then return end
local settings = TimerBars.ProfileSettings;
local barSpacingSlider = _G[panelName.."BarSpacingSlider"];
local barPaddingSlider = _G[panelName.."BarPaddingSlider"];
local fontSizeSlider = _G[panelName.."FontSizeSlider"];
local fontOutlineSlider = _G[panelName.."FontOutlineSlider"];
-- Mimic the behavior of the context menu, and force the alpha to one in the swatch
local r,g,b = unpack(settings.BkgdColor);
_G[panelName.."BackgroundColorButtonNormalTexture"]:SetVertexColor(r,g,b,1);
barSpacingSlider:SetMinMaxValues(0, TIMERBARS.MAXBARSPACING);
barSpacingSlider:SetValue(settings.BarSpacing);
barSpacingSlider:SetValueStep(0.25);
barPaddingSlider:SetMinMaxValues(0, TIMERBARS.MAXBARPADDING);
barPaddingSlider:SetValue(settings.BarPadding);
barPaddingSlider:SetValueStep(0.25);
fontSizeSlider:SetMinMaxValues(5,20);
fontSizeSlider:SetValue(settings.FontSize);
fontSizeSlider:SetValueStep(0.5);
fontOutlineSlider:SetMinMaxValues(0,2);
fontOutlineSlider:SetValue(settings.FontOutline);
fontOutlineSlider:SetValueStep(1);
TimerBarsOptions.UpdateBarTextureDropDown(_G[panelName.."Textures"]);
TimerBarsOptions.UpdateBarFontDropDown(_G[panelName.."Fonts"]);
end
-- -----------------------------------
-- INTERFACE OPTIONS PANEL: PROFILE
-- -----------------------------------
function TimerBarsOptions.UIPanel_Profile_OnLoad(self)
self.name = TIMERBARS.UIPANEL_PROFILE;
self.parent = "TimerBars";
self.default = TimerBars.ResetCharacter;
---- self.cancel = TimerBars.Cancel;
---- need different way to handle cancel? users might open appearance panel without opening main panel
InterfaceOptions_AddCategory(self);
local panelName = self:GetName();
_G[panelName.."Version"]:SetText(TIMERBARS.VERSION);
_G[panelName.."SubText1"]:SetText(TIMERBARS.UIPANEL_PROFILES_SUBTEXT1);
self.Profiles.configure = function(i, btn, label)
btn.Bg:SetTexture(TimerBars.LSM:Fetch("statusbar","Minimalist"))
end
self.Profiles.List.update = TimerBarsOptions.UpdateProfileList
self.Profiles.fnClick = function(self)
local scrollPanel = self:GetParent():GetParent():GetParent()
scrollPanel.curSel = self.text:GetText()
TimerBarsOptions.UpdateProfileList()
end
end
function TimerBarsOptions.UIPanel_Profile_OnShow(self)
TimerBarsOptions.RebuildProfileList(self)
TimerBarsOptions.UIPanel_Profile_Update();
end
function TimerBarsOptions.UIPanel_Profile_Update()
local panelName = "InterfaceOptionsTimerBarsProfilePanel";
local title
-- FIXME: Use GetSpecializationInfoForClassID(UnitClass("player"), GetSpecialization()) instead of primary
_G[panelName.."ProfilesTitle"]:SetText(TIMERBARS.UIPANEL_CURRENTPRIMARY)
local self = _G[panelName]
if not self:IsVisible() then return end
TimerBarsOptions.UpdateProfileList()
end
function TimerBarsOptions.RebuildProfileList(profilePanel)
local scrollPanel = profilePanel.Profiles
local oldKey
if ( scrollPanel.curSel and scrollPanel.profileMap ) then
oldKey = scrollPanel.profileMap[scrollPanel.curSel].key
end
if not scrollPanel.profileNames then
scrollPanel.profileNames = { }
end
scrollPanel.profileMap = { }
local allNames = scrollPanel.profileNames
local allRefs = scrollPanel.profileMap
local n = 0
local subList = TimerBars_Profiles
if subList then
for profKey, rProfile in pairs(subList) do
n = n + 1
local profName
if TimerBars_Globals.Profiles[profKey] == rProfile then
profName = 'Account: '..rProfile.name -- FIXME Localization
else
profName = 'Character: '..rProfile.name -- Fixme: Character-Server:
end
allNames[n] = profName
allRefs[profName] = { ref = rProfile, global=true, key=profKey }
if ( profKey == oldKey ) then
scrollPanel.curSel = profName;
end
end
end
while n < #allNames do
table.remove(allNames)
end
table.sort(allNames, function(lhs,rhs) return string.upper(lhs)<string.upper(rhs) end )
TimerBarsOptions.UpdateProfileList()
end
function TimerBarsOptions.IsProfileNameAvailable(newName)
if not newName or newName == "" then
return false;
end
for k, profile in pairs(TimerBars_Profiles) do
if profile.name == newName then
return false;
end
end
return true;
end
function TimerBarsOptions.UpdateProfileList()
local panel = _G["InterfaceOptionsTimerBarsProfilePanel"]
local scrollPanel = panel.Profiles
if scrollPanel.profileNames then
local curProfile
for n,r in pairs(scrollPanel.profileMap) do
if r.ref == TimerBars.ProfileSettings then
curProfile = n
break;
end
end
if not scrollPanel.curSel or not scrollPanel.profileMap[scrollPanel.curSel] then
scrollPanel.curSel = curProfile
end
local curSel = scrollPanel.curSel
TimerBarsOptions.UpdateScrollPanel(scrollPanel, scrollPanel.profileNames, curSel, curProfile)
local optionsPanel = scrollPanel:GetParent()
if curSel == curProfile then
optionsPanel.SwitchToBtn:Disable()
else
optionsPanel.SwitchToBtn:Enable()
end
if curSel == curProfile then
optionsPanel.DeleteBtn:Disable()
else
optionsPanel.DeleteBtn:Enable()
end
local curEntry = optionsPanel.NewName:GetText()
if TimerBarsOptions.IsProfileNameAvailable(curEntry) then
optionsPanel.RenameBtn:Enable()
optionsPanel.CopyBtn:Enable()
else
optionsPanel.RenameBtn:Disable()
optionsPanel.CopyBtn:Disable()
end
local rSelectedProfile = scrollPanel.profileMap[curSel].ref;
local rSelectedKey = scrollPanel.profileMap[curSel].key;
if ( rSelectedProfile and rSelectedKey and TimerBars_Globals.Profiles[rSelectedKey] == rSelectedProfile ) then
optionsPanel.PrivateBtn:Show();
optionsPanel.PublicBtn:Hide();
else
optionsPanel.PrivateBtn:Hide();
optionsPanel.PublicBtn:Show();
end
end
end
function TimerBarsOptions.UIPanel_Profile_SwitchToSelected(panel)
local scrollPanel = panel.Profiles
local curSel = scrollPanel.curSel
if curSel then
TimerBars.ChangeProfile( scrollPanel.profileMap[curSel].key )
TimerBarsOptions.UpdateProfileList()
end
end
StaticPopupDialogs["TIMERBARS.CONFIRMDLG"] = {
button1 = YES,
button2 = NO,
timeout = 0,
hideOnEscape = 1,
OnShow = function(self)
self.oldStrata = self:GetFrameStrata()
self:SetFrameStrata("TOOLTIP")
end,
OnHide = function(self)
if self.oldStrata then
self:SetFrameStrata(self.oldStrata)
end
end
};
function TimerBarsOptions.UIPanel_Profile_DeleteSelected(panel)
local scrollPanel = panel.Profiles
local curSel = scrollPanel.curSel
if curSel then
local k = scrollPanel.profileMap[curSel].key
local dlgInfo = StaticPopupDialogs["TIMERBARS.CONFIRMDLG"]
dlgInfo.text = "Are you sure you want to delete the profile: ".. curSel .."?"
dlgInfo.OnAccept = function(self, data)
if TimerBars_Profiles[k] == TimerBars.ProfileSettings then
print("TimerBars: Won't delete the active profile!")
else
TimerBars_Profiles[k] = nil;
if TimerBars_Globals.Profiles[k] then
print("TimerBars: deleted account-wide profile", TimerBars_Globals.Profiles[k].name) -- LOCME
TimerBars_Globals.Profiles[k] = nil;
elseif TimerBars_CharSettings.Profiles[k] then
print("TimerBars: deleted character profile", TimerBars_CharSettings.Profiles[k].name) -- LOCME
TimerBars_CharSettings.Profiles[k] = nil;
end
TimerBarsOptions.RebuildProfileList(panel)
end
end
StaticPopup_Show("TIMERBARS.CONFIRMDLG");
end
end
function TimerBarsOptions.UIPanel_Profile_CopySelected(panel)
local scrollPanel = panel.Profiles
local curSel = scrollPanel.curSel
local edit = panel.NewName
local newName = edit:GetText()
edit:ClearFocus()
if scrollPanel.curSel and TimerBarsOptions.IsProfileNameAvailable(newName) then
local keyNew = TimerBars.CreateProfile(CopyTable(scrollPanel.profileMap[curSel].ref), nil, newName)
TimerBars.ChangeProfile(keyNew)
TimerBarsOptions.RebuildProfileList(panel)
edit:SetText("");
print("TimerBars: Copied",curSel,"to",newName,"and made it the active profile")
end
end
function TimerBarsOptions.UIPanel_Profile_RenameSelected(panel)
local scrollPanel = panel.Profiles
local edit = panel.NewName
local newName = edit:GetText()
edit:ClearFocus()
if scrollPanel.curSel and TimerBarsOptions.IsProfileNameAvailable(newName) then
local key = scrollPanel.profileMap[scrollPanel.curSel].key
print("TimerBars: Renaming profile",TimerBars_Profiles[key].name,"to",newName)
TimerBars_Profiles[key].name = newName;
edit:SetText("");
TimerBarsOptions.RebuildProfileList(panel)
end
end
function TimerBarsOptions.UIPanel_Profile_PublicizeSelected(panel)
local scrollPanel = panel.Profiles
if scrollPanel.curSel then
local ref = scrollPanel.profileMap[scrollPanel.curSel].ref
local key = scrollPanel.profileMap[scrollPanel.curSel].key
TimerBars_Globals.Profiles[key] = ref
TimerBars_CharSettings.Profiles[key] = nil
TimerBarsOptions.RebuildProfileList(panel)
end
end
function TimerBarsOptions.UIPanel_Profile_PrivatizeSelected(panel)
local scrollPanel = panel.Profiles
if scrollPanel.curSel then
local ref = scrollPanel.profileMap[scrollPanel.curSel].ref
local key = scrollPanel.profileMap[scrollPanel.curSel].key
TimerBars_Globals.Profiles[key] = nil
TimerBars_CharSettings.Profiles[key] = ref
TimerBarsOptions.RebuildProfileList(panel)
end
end
-----
function TimerBarsOptions.OnClickTextureItem(self)
TimerBars.ProfileSettings["BarTexture"] = self.text:GetText()
TimerBars.Update()
TimerBarsOptions.UIPanel_Appearance_Update()
end
function TimerBarsOptions.OnClickFontItem(self)
TimerBars.ProfileSettings["BarFont"] = self.text:GetText()
TimerBars.Update()
TimerBarsOptions.UIPanel_Appearance_Update()
end
function TimerBarsOptions.ChooseColor(variable)
info = UIDropDownMenu_CreateInfo();
info.r, info.g, info.b, info.opacity = unpack(TimerBars.ProfileSettings[variable]);
info.opacity = 1 - info.opacity;
info.hasOpacity = true;
info.opacityFunc = TimerBarsOptions.SetOpacity;
info.swatchFunc = TimerBarsOptions.SetColor;
info.cancelFunc = TimerBarsOptions.CancelColor;
info.extraInfo = variable;
-- Not sure if I should leave this state around or not. It seems like the
-- correct strata to have it at anyway, so I'm going to leave it there for now
ColorPickerFrame:SetFrameStrata("FULLSCREEN_DIALOG");
OpenColorPicker(info);
end
function TimerBarsOptions.SetColor()
local variable = ColorPickerFrame.extraInfo;
local r,g,b = ColorPickerFrame:GetColorRGB();
TimerBars.ProfileSettings[variable][1] = r;
TimerBars.ProfileSettings[variable][2] = g;
TimerBars.ProfileSettings[variable][3] = b;
TimerBars.Update();
TimerBarsOptions.UIPanel_Appearance_Update();
end
function TimerBarsOptions.SetOpacity()
local variable = ColorPickerFrame.extraInfo;
TimerBars.ProfileSettings[variable][4] = 1 - OpacitySliderFrame:GetValue();
TimerBars.Update();
TimerBarsOptions.UIPanel_Appearance_Update();
end
function TimerBarsOptions.CancelColor(previousValues)
if ( previousValues ) then
local variable = ColorPickerFrame.extraInfo;
TimerBars.ProfileSettings[variable] = {previousValues.r, previousValues.g, previousValues.b, previousValues.opacity};
TimerBars.Update();
TimerBarsOptions.UIPanel_Appearance_Update();
end
end
function TimerBarsOptions.UIPanel_Appearance_OnSizeChanged(self)
-- Despite my best efforts, the scroll bars insist on being outside the width of their
local mid = self:GetWidth()/2 --+ _G[self:GetName().."TexturesListScrollBar"]:GetWidth()
local textures = self.Textures
local leftTextures = textures:GetLeft()
if mid and mid > 0 and textures and leftTextures then
local ofs = leftTextures - self:GetLeft()
textures:SetWidth(mid - ofs)
end
end
function TimerBarsOptions.OnScrollFrameSized(self)
local old_value = self.scrollBar:GetValue();
local scrollFrame = self:GetParent();
HybridScrollFrame_CreateButtons(self, "TimerBarsScrollItemTemplate")
--scrollFrame.Update(scrollFrame)
local max_value = self.range or self:GetHeight()
self.scrollBar:SetValue(min(old_value, max_value));
-- Work around a bug in HybridScrollFrame; it can't scroll by whole items (wow 4.1)
--self.stepSize = self.buttons[1]:GetHeight()*.9
end
function TimerBarsOptions.UpdateScrollPanel(panel, list, selected, checked)
local Value = _G[panel:GetName().."Value"]
Value:SetText(checked)
local PanelList = panel.List
local buttons = PanelList.buttons
HybridScrollFrame_Update(PanelList, #(list) * buttons[1]:GetHeight() , PanelList:GetHeight())
local numButtons = #buttons;
local scrollOffset = HybridScrollFrame_GetOffset(PanelList);
local label;
for i = 1, numButtons do
local idx = i + scrollOffset
label = list[idx]
if ( label ) then
buttons[i]:Show();
buttons[i].text:SetText(label);
if ( label == checked ) then
buttons[i].Check:Show();
else
buttons[i].Check:Hide();
end
if ( label == selected ) then
local color = panel.selected_color
if not color then color = TimerBarsOptions.DefaultSelectedColor end
buttons[i].Bg:SetVertexColor(unpack(color));
else
local color = panel.normal_color
if not color then color = TimerBarsOptions.DefaultNormalColor end
buttons[i].Bg:SetVertexColor(unpack(color));
end
panel.configure(i, buttons[i], label)
else
buttons[i]:Hide();
end
end
end
--function TimerBarsOptions.OnScrollFrameScrolled(self)
--local scrollPanel = self:GetParent()
--local fn = scrollPanel.Update
--if fn then fn(scrollPanel) end
--end
--
function TimerBarsOptions.UpdateBarTextureDropDown()
local scrollPanel = _G["InterfaceOptionsTimerBarsAppearancePanelTextures"]
TimerBarsOptions.UpdateScrollPanel(scrollPanel, textureList, TimerBars.ProfileSettings.BarTexture, TimerBars.ProfileSettings.BarTexture)
end
function TimerBarsOptions.UpdateBarFontDropDown()
local scrollPanel = _G["InterfaceOptionsTimerBarsAppearancePanelFonts"]
TimerBarsOptions.UpdateScrollPanel(scrollPanel, fontList, nil, TimerBars.ProfileSettings.BarFont)
end
-- --------
-- BAR GUI
-- --------
TimerBarsRMB.CurrentBar = { groupID = 1, barID = 1 }; -- a dirty hack, i know.
StaticPopupDialogs["TIMERBARS.CHOOSENAME_DIALOG"] = {
text = TIMERBARS.CHOOSENAME_DIALOG,
button1 = ACCEPT,
button2 = CANCEL,
hasEditBox = 1,
editBoxWidth = 300,
maxLetters = 0,
OnAccept = function(self)
local text = self.editBox:GetText();
local variable = self.variable;
if ( nil ~= variable ) then
TimerBarsRMB.BarMenu_ChooseName(text, variable);
end
end,
EditBoxOnEnterPressed = function(self)
StaticPopupDialogs["TIMERBARS.CHOOSENAME_DIALOG"].OnAccept(self:GetParent())
self:GetParent():Hide();
end,
EditBoxOnEscapePressed = function(self)
self:GetParent():Hide();
end,
OnHide = function(self)
-- Removed for wow 3.3.5, it seems like there is a focu stack
-- now that obsoletes this anyway. If not, there isn't a
-- single ChatFrameEditBox anymore, there's ChatFrame1EditBox etc.
-- if ( ChatFrameEditBox:IsVisible() ) then
-- ChatFrameEditBox:SetFocus();
-- end
self.editBox:SetText("");
end,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
};
TimerBarsRMB.BarMenu_MoreOptions = {
{ VariableName = "Enabled", MenuText = TIMERBARS.BARMENU_ENABLE },
{ VariableName = "AuraName", MenuText = TIMERBARS.BARMENU_CHOOSENAME, Type = "Dialog", DialogText = "CHOOSENAME_DIALOG" },
{ VariableName = "BuffOrDebuff", MenuText = TIMERBARS.BARMENU_BUFFORDEBUFF, Type = "Submenu" },
{ VariableName = "Options", MenuText = "Settings", Type = "Submenu" },
{},
{ VariableName = "TimeFormat", MenuText = TIMERBARS.BARMENU_TIMEFORMAT, Type = "Submenu" },
{ VariableName = "Show", MenuText = TIMERBARS.BARMENU_SHOW, Type = "Submenu" },
{ VariableName = "VisualCastTime", MenuText = TIMERBARS.BARMENU_VISUALCASTTIME, Type = "Submenu" },
{ VariableName = "BlinkSettings", MenuText = "Blink Settings", Type = "Submenu" }, -- LOCME
{ VariableName = "BarColor", MenuText = TIMERBARS.BARMENU_BARCOLOR, Type = "Color" },
{},
{ VariableName = "ImportExport", MenuText = "Import/Export Bar Settings", Type = "Dialog", DialogText = "IMPORTEXPORT_DIALOG" },
}
TimerBarsRMB.BarMenu_SubMenus = {
-- the keys on this table need to match the settings variable names
BuffOrDebuff = {
{ Setting = "HELPFUL", MenuText = TIMERBARS.BARMENU_HELPFUL },
{ Setting = "HARMFUL", MenuText = TIMERBARS.BARMENU_HARMFUL },
{ Setting = "TOTEM", MenuText = TIMERBARS.BARMENU_TOTEM },
{ Setting = "CASTCD", MenuText = TIMERBARS.BARMENU_CASTCD },
{ Setting = "BUFFCD", MenuText = TIMERBARS.BARMENU_BUFFCD },
-- Now that Victory Rush adds a buff when you can use it, this confusing option is being removed.
-- The code that drives it remains so that any existing users' bars won't break.
-- { Setting = "USABLE", MenuText = TIMERBARS.BARMENU_USABLE },
{ Setting = "EQUIPSLOT", MenuText = TIMERBARS.BARMENU_EQUIPSLOT },
-- { Setting = "POWER", MenuText = TIMERBARS.BARMENU_POWER }
},
TimeFormat = {
{ Setting = "Fmt_SingleUnit", MenuText = TIMERBARS.FMT_SINGLEUNIT },
{ Setting = "Fmt_TwoUnits", MenuText = TIMERBARS.FMT_TWOUNITS },
{ Setting = "Fmt_Float", MenuText = TIMERBARS.FMT_FLOAT },
},
Unit = {
{ Setting = "player", MenuText = TIMERBARS.BARMENU_PLAYER },
{ Setting = "target", MenuText = TIMERBARS.BARMENU_TARGET },
{ Setting = "targettarget", MenuText = TIMERBARS.BARMENU_TARGETTARGET },
{ Setting = "focus", MenuText = TIMERBARS.BARMENU_FOCUS },
{ Setting = "pet", MenuText = TIMERBARS.BARMENU_PET },
{ Setting = "vehicle", MenuText = TIMERBARS.BARMENU_VEHICLE },
{ Setting = "lastraid", MenuText = TIMERBARS.BARMENU_LAST_RAID },
},
DebuffUnit = {
{ Setting = "player", MenuText = TIMERBARS.BARMENU_PLAYER },
{ Setting = "target", MenuText = TIMERBARS.BARMENU_TARGET },
{ Setting = "targettarget", MenuText = TIMERBARS.BARMENU_TARGETTARGET },
{ Setting = "focus", MenuText = TIMERBARS.BARMENU_FOCUS },
{ Setting = "pet", MenuText = TIMERBARS.BARMENU_PET },
{ Setting = "vehicle", MenuText = TIMERBARS.BARMENU_VEHICLE },
},
Opt_HELPFUL = {
{ VariableName = "Unit", MenuText = TIMERBARS.BARMENU_CHOOSEUNIT, Type = "Submenu" },
{ VariableName = "bDetectExtends", MenuText = "Track duration increases" }, -- LOCME
{ VariableName = "OnlyMine", MenuText = TIMERBARS.BARMENU_ONLYMINE },
{ VariableName = "show_all_stacks", MenuText = "Sum stacks from all casters" },
},
Opt_HARMFUL = {
{ VariableName = "DebuffUnit", MenuText = TIMERBARS.BARMENU_CHOOSEUNIT, Type = "Submenu" },
{ VariableName = "bDetectExtends", MenuText = "Track duration increases" }, -- LOCME
{ VariableName = "OnlyMine", MenuText = TIMERBARS.BARMENU_ONLYMINE },
{ VariableName = "show_all_stacks", MenuText = "Sum stacks from all casters" },
},
Opt_TOTEM = {},
Opt_CASTCD =
{
{ VariableName = "append_cd", MenuText = "Append \"CD\"" }, -- LOCME
{ VariableName = "show_charges", MenuText = "Show first and last charge CD" }, -- LOCME
},
Opt_EQUIPSLOT =
{
{ VariableName = "append_cd", MenuText = "Append \"CD\"" }, -- LOCME
},
-- Opt_POWER =
-- {
-- { VariableName = "Unit", MenuText = TIMERBARS.BARMENU_CHOOSEUNIT, Type = "Submenu" },
-- { VariableName = "power_sole", MenuText = "Only Show When Primary" }, -- LOCME
-- },
Opt_BUFFCD =
{
{ VariableName = "buffcd_duration", MenuText = "Cooldown duration...", Type = "Dialog", DialogText = "BUFFCD_DURATION_DIALOG", Numeric=true },
{ VariableName = "buffcd_reset_spells", MenuText = "Reset on buff...", Type = "Dialog", DialogText = "BUFFCD_RESET_DIALOG" },
{ VariableName = "append_cd", MenuText = "Append \"CD\"" }, -- LOCME
},
Opt_USABLE =
{
{ VariableName = "usable_duration", MenuText = "Usable duration...", Type = "Dialog", DialogText = "USABLE_DURATION_DIALOG", Numeric=true },
{ VariableName = "append_usable", MenuText = "Append \"Usable\"" }, -- LOCME
},
EquipmentSlotList =
{
{ Setting = "1", MenuText = TIMERBARS.ITEM_NAMES[1] },
{ Setting = "2", MenuText = TIMERBARS.ITEM_NAMES[2] },
{ Setting = "3", MenuText = TIMERBARS.ITEM_NAMES[3] },
{ Setting = "4", MenuText = TIMERBARS.ITEM_NAMES[4] },
{ Setting = "5", MenuText = TIMERBARS.ITEM_NAMES[5] },
{ Setting = "6", MenuText = TIMERBARS.ITEM_NAMES[6] },
{ Setting = "7", MenuText = TIMERBARS.ITEM_NAMES[7] },
{ Setting = "8", MenuText = TIMERBARS.ITEM_NAMES[8] },
{ Setting = "9", MenuText = TIMERBARS.ITEM_NAMES[9] },
{ Setting = "10", MenuText = TIMERBARS.ITEM_NAMES[10] },
{ Setting = "11", MenuText = TIMERBARS.ITEM_NAMES[11] },
{ Setting = "12", MenuText = TIMERBARS.ITEM_NAMES[12] },
{ Setting = "13", MenuText = TIMERBARS.ITEM_NAMES[13] },
{ Setting = "14", MenuText = TIMERBARS.ITEM_NAMES[14] },
{ Setting = "15", MenuText = TIMERBARS.ITEM_NAMES[15] },
{ Setting = "16", MenuText = TIMERBARS.ITEM_NAMES[16] },
{ Setting = "17", MenuText = TIMERBARS.ITEM_NAMES[17] },
{ Setting = "18", MenuText = TIMERBARS.ITEM_NAMES[18] },
{ Setting = "19", MenuText = TIMERBARS.ITEM_NAMES[19] },
},
VisualCastTime = {
{ VariableName = "vct_enabled", MenuText = TIMERBARS.BARMENU_VCT_ENABLE },
{ VariableName = "vct_color", MenuText = TIMERBARS.BARMENU_VCT_COLOR, Type = "Color" },
{ VariableName = "vct_spell", MenuText = TIMERBARS.BARMENU_VCT_SPELL, Type = "Dialog", DialogText = "CHOOSE_VCT_SPELL_DIALOG" },
{ VariableName = "vct_extra", MenuText = TIMERBARS.BARMENU_VCT_EXTRA, Type = "Dialog", DialogText = "CHOOSE_VCT_EXTRA_DIALOG", Numeric=true },
},
Show = {
{ VariableName = "show_icon", MenuText = TIMERBARS.BARMENU_SHOW_ICON },
{ VariableName = "show_text", MenuText = TIMERBARS.BARMENU_SHOW_TEXT },
{ VariableName = "show_count", MenuText = TIMERBARS.BARMENU_SHOW_COUNT },
{ VariableName = "show_time", MenuText = TIMERBARS.BARMENU_SHOW_TIME },
{ VariableName = "show_spark", MenuText = TIMERBARS.BARMENU_SHOW_SPARK },
{ VariableName = "show_mypip", MenuText = TIMERBARS.BARMENU_SHOW_MYPIP },
{ VariableName = "show_ttn1", MenuText = TIMERBARS.BARMENU_SHOW_TTN1 },
{ VariableName = "show_ttn2", MenuText = TIMERBARS.BARMENU_SHOW_TTN2 },
{ VariableName = "show_ttn3", MenuText = TIMERBARS.BARMENU_SHOW_TTN3 },
{ VariableName = "show_text_user", MenuText = TIMERBARS.BARMENU_SHOW_TEXT_USER, Type = "Dialog", DialogText = "CHOOSE_OVERRIDE_TEXT", Checked = function(settings) return "" ~= settings.show_text_user end },
},
BlinkSettings = {
{ VariableName = "blink_enabled", MenuText = TIMERBARS.BARMENU_VCT_ENABLE },
{ VariableName = "blink_label", MenuText = "Bar text while blinking...", Type = "Dialog", DialogText="CHOOSE_BLINK_TITLE_DIALOG" },
{ VariableName = "MissingBlink", MenuText = "Bar color when blinking...", Type = "Color" }, -- LOCME
{ VariableName = "blink_ooc", MenuText = "Blink out of combat" }, -- LOCME
{ VariableName = "blink_boss", MenuText = "Blink only for bosses" }, -- LOCME
},
};
TimerBarsRMB.VariableRedirects =
{
DebuffUnit = "Unit",
EquipmentSlotList = "AuraName",
}
function TimerBarsRMB.ShowMenu(bar)
TimerBarsRMB.CurrentBar["barID"] = bar:GetID();
TimerBarsRMB.CurrentBar["groupID"] = bar:GetParent():GetID();
if not TimerBarsRMB.DropDown then
TimerBarsRMB.DropDown = CreateFrame("Frame", "TimerBarsDropDown", nil, "TimerBars_DropDownTemplate")
end
-- There's no OpenDropDownMenu that forces it to show in the new place,
-- so we have to check if the first Toggle opened or closed it
ToggleDropDownMenu(1, nil, TimerBarsRMB.DropDown, "cursor", 0, 0);
if not DropDownList1:IsShown() then
ToggleDropDownMenu(1, nil, TimerBarsRMB.DropDown, "cursor", 0, 0);
end
end
function TimerBarsRMB.BarMenu_AddButton(barSettings, i_desc, i_parent)
info = UIDropDownMenu_CreateInfo();
local item_type = i_desc["Type"];
info.text = i_desc["MenuText"];
local varSettings
if ( nil ~= i_desc["Setting"]) then
item_type = "SetVar"
local v = TimerBarsRMB.VariableRedirects[i_parent] or i_parent
varSettings = barSettings[v]
else
info.value = i_desc["VariableName"];
varSettings = barSettings[info.value];
end
if ( not varSettings and (item_type == "Check" or item_type == "Color") ) then
print (string.format("TB: Could not find %s in", info.value), barSettings);
return
end
info.hasArrow = false;
local b = i_desc["Checked"]
if b then
if type(b) == "function" then
info.checked = b(barSettings)
else
info.checked = b
end
end
info.keepShownOnClick = true;
info.notCheckable = false; -- indent everything
info.hideUnCheck = true; -- but hide the empty checkbox/radio
if ( not item_type and not text and not info.value ) then
info.func = TimerBarsRMB.BarMenu_IgnoreToggle;
info.disabled = true;
elseif ( nil == item_type or item_type == "Check" ) then
info.func = TimerBarsRMB.BarMenu_ToggleSetting;
info.checked = (nil ~= varSettings and varSettings);
info.hideUnCheck = nil;
info.isNotRadio = true;
elseif ( item_type == "SetVar" ) then
info.func = TimerBarsRMB.BarMenu_ChooseSetting;
info.value = i_desc["Setting"];
info.checked = (varSettings == info.value);
info.hideUnCheck = nil;
info.keepShownOnClick = false;
elseif ( item_type == "Submenu" ) then
info.hasArrow = true;
info.isNotRadio = true;
info.func = TimerBarsRMB.BarMenu_IgnoreToggle;
elseif ( item_type == "Dialog" ) then
info.func = TimerBarsRMB.BarMenu_ShowNameDialog;
info.keepShownOnClick = false;
info.value = {variable = i_desc.VariableName, text = i_desc.DialogText, numeric = i_desc.Numeric };
elseif ( item_type == "Color" ) then
info.hasColorSwatch = 1;
info.hasOpacity = true;
info.r = varSettings.r;
info.g = varSettings.g;
info.b = varSettings.b;
info.opacity = 1 - varSettings.a;
info.swatchFunc = TimerBarsRMB.BarMenu_SetColor;
info.opacityFunc = TimerBarsRMB.BarMenu_SetOpacity;
info.cancelFunc = TimerBarsRMB.BarMenu_CancelColor;
info.func = UIDropDownMenuButton_OpenColorPicker;
info.keepShownOnClick = false;
end
UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
-- Code to get the button copied from UIDropDownMenu_AddButton
local level = UIDROPDOWNMENU_MENU_LEVEL;
local listFrame = _G["DropDownList"..level];
local index = listFrame and (listFrame.numButtons) or 1;
local listFrameName = listFrame:GetName();
local buttonName = listFrameName.."Button"..index;
if ( item_type == "Color" ) then
-- Sadly, extraInfo isn't a field propogated to the button
local button = _G[buttonName];
button.extraInfo = info.value;
end
if ( info.hideUnCheck ) then
local checkBG = _G[buttonName.."UnCheck"];
checkBG:Hide();
end
end
function TimerBarsRMB.BarMenu_Initialize()
local groupID = TimerBarsRMB.CurrentBar["groupID"];
local barID = TimerBarsRMB.CurrentBar["barID"];
local barSettings = TimerBars.ProfileSettings.Groups[groupID]["Bars"][barID];
if ( barSettings.MissingBlink.a == 0 ) then
barSettings.blink_enabled = false;
end
TimerBarsRMB.BarMenu_SubMenus.Options = TimerBarsRMB.BarMenu_SubMenus["Opt_"..barSettings.BuffOrDebuff];
if ( UIDROPDOWNMENU_MENU_LEVEL > 1 ) then
if ( UIDROPDOWNMENU_MENU_VALUE == "VisualCastTime" ) then
-- Create a summary title for the visual cast time submenu
local title = "";
if ( barSettings.vct_spell and "" ~= barSettings.vct_spell ) then
title = title .. barSettings.vct_spell;
end
local fExtra = tonumber(barSettings.vct_extra);
if ( fExtra and fExtra > 0 ) then
if ("" ~= title) then
title = title .. " + ";
end
title = title .. string.format("%0.1fs", fExtra);
end
if ( "" ~= title ) then
local info = UIDropDownMenu_CreateInfo();
info.text = title;
info.isTitle = true;
info.notCheckable = true; -- unindent
UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
end
end
local subMenus = TimerBarsRMB.BarMenu_SubMenus;
for index, value in ipairs(subMenus[UIDROPDOWNMENU_MENU_VALUE]) do
TimerBarsRMB.BarMenu_AddButton(barSettings, value, UIDROPDOWNMENU_MENU_VALUE);