-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathVolumizer.lua
executable file
·1012 lines (880 loc) · 27.3 KB
/
Volumizer.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
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
-------------------------------------------------------------------------------
-- Localized globals
-------------------------------------------------------------------------------
local math = _G.math
local string = _G.string
local table = _G.table
local tonumber = _G.tonumber
local tostring = _G.tostring
local pairs = _G.pairs
local CreateFrame = _G.CreateFrame
local GameTooltip = _G.GameTooltip
local UIParent = _G.UIParent
local def_col, def_bg_col = _G.TOOLTIP_DEFAULT_COLOR, _G.TOOLTIP_DEFAULT_BACKGROUND_COLOR
-------------------------------------------------------------------------------
-- Addon namespace
-------------------------------------------------------------------------------
local Volumizer = CreateFrame("Frame", "VolumizerPanel", UIParent, _G.BackdropTemplateMixin and "BackdropTemplate")
Volumizer:SetScript("OnEvent", function(self, event, ...)
return self[event] and self[event](self, event, ...)
end)
Volumizer:RegisterEvent("ADDON_LOADED")
local LDB = _G.LibStub:GetLibrary("LibDataBroker-1.1")
local DataObj
-------------------------------------------------------------------------------
-- Constants
-------------------------------------------------------------------------------
local DEFAULT_PRESET_VALUES = {
ambience = {
volume = 0.6,
enable = true
},
dialog = {
volume = 1.0,
enable = true
},
master = {
volume = 1.0,
enable = true
},
music = {
volume = 0.4,
enable = true
},
sfx = {
volume = 1.0,
enable = true
},
error = true,
emote = true,
pet = true,
petmusic = false,
reverb = false,
loop = false,
background = false,
listener = true,
}
local DB_VERSION = '20221106.01'
-- local category = Settings.GetCategory(AUDIO_LABEL); seems to be unused
local INITIAL_PRESETS = {
{
name = "Preset 1",
values = _G.CopyTable(DEFAULT_PRESET_VALUES),
},
{
name = "Preset 2",
values = _G.CopyTable(DEFAULT_PRESET_VALUES),
},
{
name = "Preset 3",
values = _G.CopyTable(DEFAULT_PRESET_VALUES),
},
{
name = "Preset 4",
values = _G.CopyTable(DEFAULT_PRESET_VALUES),
},
{
name = "Preset 5",
values = _G.CopyTable(DEFAULT_PRESET_VALUES),
},
}
local DEFAULT_PRESET = {
values = _G.CopyTable(DEFAULT_PRESET_VALUES)
}
local VOLUMES = {
ambience = {
SoundOption = {
text = _G.AMBIENCE_VOLUME,
minValue = 0,
maxValue = 1,
step = .05,
},
VolumeCVar = "Sound_AmbienceVolume",
Volume = _G.AudioOptionsSoundPanelAmbienceVolume,
EnableCVar = "Sound_EnableAmbience",
Enable = _G.AudioOptionsSoundPanelAmbientSounds,
Tooltip = _G.OPTION_TOOLTIP_ENABLE_AMBIENCE,
},
dialog = {
SoundOption = {
text = _G.DIALOG_VOLUME,
minValue = 0,
maxValue = 1,
step = .05,
},
VolumeCVar = "Sound_DialogVolume",
Volume = _G.AudioOptionsSoundPanelDialogVolume,
EnableCVar = "Sound_EnableDialog",
Enable = _G.AudioOptionsSoundPanelDialogSounds,
Tooltip = _G.OPTION_TOOLTIP_ENABLE_DIALOG,
},
master = {
SoundOption = {
text = _G.MASTER_VOLUME,
minValue = 0,
maxValue = 1,
step = .05,
},
VolumeCVar = "Sound_MasterVolume",
Volume = _G.AudioOptionsSoundPanelMasterVolume,
EnableCVar = "Sound_EnableAllSound",
Enable = _G.AudioOptionsSoundPanelEnableSound,
Tooltip = _G.OPTION_TOOLTIP_ENABLE_SOUND,
},
music = {
SoundOption = {
text = _G.MUSIC_VOLUME,
minValue = 0,
maxValue = 1,
step = .05,
},
VolumeCVar = "Sound_MusicVolume",
Volume = _G.AudioOptionsSoundPanelMusicVolume,
EnableCVar = "Sound_EnableMusic",
Enable = _G.AudioOptionsSoundPanelMusic,
Tooltip = _G.OPTION_TOOLTIP_ENABLE_MUSIC,
},
sfx = {
SoundOption = {
text = _G.FX_VOLUME,
minValue = 0,
maxValue = 1,
step = .05,
},
VolumeCVar = "Sound_SFXVolume",
Volume = _G.AudioOptionsSoundPanelSoundVolume,
EnableCVar = "Sound_EnableSFX",
Enable = _G.AudioOptionsSoundPanelSoundEffects,
Tooltip = _G.OPTION_TOOLTIP_ENABLE_SOUNDFX,
}
}
local TOGGLES = {
background = {
SoundOption = {
text = _G.ENABLE_BGSOUND,
},
EnableCVar = "Sound_EnableSoundWhenGameIsInBG",
Enable = _G.AudioOptionsSoundPanelSoundInBG,
Tooltip = _G.OPTION_TOOLTIP_ENABLE_BGSOUND,
},
emote = {
SoundOption = {
text = _G.ENABLE_EMOTE_SOUNDS,
},
EnableCVar = "Sound_EnableEmoteSounds",
Enable = _G.AudioOptionsSoundPanelEmoteSounds,
Tooltip = _G.OPTION_TOOLTIP_ENABLE_EMOTE_SOUNDS,
},
error = {
SoundOption = {
text = _G.ENABLE_ERROR_SPEECH,
},
EnableCVar = "Sound_EnableErrorSpeech",
Enable = _G.AudioOptionsSoundPanelErrorSpeech,
Tooltip = _G.OPTION_TOOLTIP_ENABLE_ERROR_SPEECH,
},
listener = {
SoundOption = {
text = _G.ENABLE_SOFTWARE_HRTF,
},
EnableCVar = "Sound_EnablePositionalLowPassFilter",
Enable = nil,
Tooltip = _G.OPTION_TOOLTIP_ENABLE_SOFTWARE_HRTF,
},
loop = {
SoundOption = {
text = _G.ENABLE_MUSIC_LOOPING,
},
EnableCVar = "Sound_ZoneMusicNoDelay",
Enable = _G.AudioOptionsSoundPanelLoopMusic,
Tooltip = _G.OPTION_TOOLTIP_ENABLE_MUSIC_LOOPING,
},
pet = {
SoundOption = {
text = _G.ENABLE_PET_SOUNDS,
},
EnableCVar = "Sound_EnablePetSounds",
Enable = _G.AudioOptionsSoundPanelPetSounds,
Tooltip = _G.OPTION_TOOLTIP_ENABLE_PET_SOUNDS,
},
petmusic = {
SoundOption = {
text = _G.ENABLE_PET_BATTLE_MUSIC,
},
EnableCVar = "Sound_EnablePetBattleMusic",
Enable = nil,
Tooltip = _G.OPTION_TOOLTIP_ENABLE_PET_BATTLE_MUSIC,
},
reverb = {
SoundOption = {
text = _G.ENABLE_REVERB,
},
EnableCVar = "Sound_EnableReverb",
Enable = nil,
Tooltip = _G.OPTION_TOOLTIP_ENABLE_REVERB,
},
}
local HorizontalSliderBG = {
bgFile = [[Interface\Buttons\UI-SliderBar-Background]],
edgeFile = [[Interface\Buttons\UI-SliderBar-Border]],
edgeSize = 8,
tile = true,
tileSize = 8,
insets = {
left = 3,
right = 3,
top = 6,
bottom = 6
}
}
local order_VOLUMES = { "master", "music", "ambience", "dialog" }
local order_TOGGLES = { "loop", "petmusic", "pet", "emote", "error", "background", "reverb", "listener" }
-------------------------------------------------------------------------------
-- Variables
-------------------------------------------------------------------------------
local user_presets
-------------------------------------------------------------------------------
-- Local functions
-------------------------------------------------------------------------------
local function HideTooltip()
GameTooltip:Hide()
end
local function ShowTooltip(self)
if not self.tooltip then
return
end
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
GameTooltip:SetText(self.tooltip, nil, nil, nil, nil, true)
end
local function MakeCheckButton(parent)
local check = CreateFrame("CheckButton", nil, parent)
check:SetWidth(15)
check:SetHeight(15)
check:SetNormalTexture([[Interface\Buttons\UI-CheckBox-Up]])
check:SetPushedTexture([[Interface\Buttons\UI-CheckBox-Down]])
check:SetHighlightTexture([[Interface\Buttons\UI-CheckBox-Highlight]])
check:SetDisabledCheckedTexture([[Interface\Buttons\UI-CheckBox-Check-Disabled]])
check:SetCheckedTexture([[Interface\Buttons\UI-CheckBox-Check]])
return check
end
local function MakeContainer(relative, dist)
local container = CreateFrame("Frame", nil, Volumizer)
container:SetWidth(155)
container:SetHeight(40)
container:SetPoint("TOP", relative, 0, (relative == Volumizer) and -22 or (relative and dist or -30))
return container
end
local MakeToggle, MakeControl
do
function MakeToggle(name, relative)
local ref = TOGGLES[name]
local container = MakeContainer(relative, -15)
local check = MakeCheckButton(container)
check:SetPoint("LEFT", container, "LEFT")
if ref.Enable then
check:SetChecked(ref.Enable:GetValue())
else
check:SetChecked((Settings.GetValue(ref.EnableCVar)))
end
check:SetHitRectInsets(-10, -150, 0, 0)
check:SetScript("OnClick", function(checkButton)
if ref.Enable then
ref.Enable:SetValue(check:GetChecked() and 1 or 0)
else
Settings.SetValue(ref.EnableCVar, check:GetChecked())
end
end)
check.tooltip = ref.Tooltip
check:SetScript("OnEnter", ShowTooltip)
check:SetScript("OnLeave", HideTooltip)
local text = check:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
text:SetPoint("LEFT", check, "RIGHT", 0, 3)
text:SetText(ref.SoundOption.text)
_G.hooksecurefunc("SetCVar", function(cvar, value)
if cvar == ref.EnableCVar then
check:SetChecked(value)
end
end)
return container
end
local function SetSliderLabel(slider, ref, value)
slider.text:SetFormattedText("%s %d%%", ref.SoundOption.text, value * 100)
end
function MakeControl(name, relative)
local ref = VOLUMES[name]
local container = MakeContainer(relative)
local check = MakeCheckButton(container)
check:SetPoint("LEFT", container, "LEFT")
if ref.Enable then
check:SetChecked(ref.Enable:GetValue())
check:SetScript("OnClick", function(checkButton)
ref.Enable:SetValue(check:GetChecked() and 1 or 0)
end)
else
check:SetChecked(Settings.GetValue(ref.EnableCVar))
check:SetScript("OnClick", function(checkButton)
Settings.SetValue(ref.EnableCVar, check:GetChecked())
end)
end
check.tooltip = ref.Tooltip
check:SetScript("OnEnter", ShowTooltip)
check:SetScript("OnLeave", HideTooltip)
local slider = CreateFrame("Slider", nil, container, _G.BackdropTemplateMixin and "BackdropTemplate")
slider:SetPoint("LEFT", check, "RIGHT", 0, 0)
slider:SetPoint("RIGHT")
slider:SetHeight(15)
slider:SetHitRectInsets(0, 0, -10, -10)
slider:SetOrientation("HORIZONTAL")
slider:SetThumbTexture([[Interface\Buttons\UI-SliderBar-Button-Horizontal]])
slider:SetBackdrop(HorizontalSliderBG)
slider:SetMinMaxValues(ref.SoundOption.minValue, ref.SoundOption.maxValue)
slider:SetValue(Settings.GetValue(ref.VolumeCVar) or 0)
slider:SetValueStep(0.05)
slider:EnableMouseWheel(true)
slider.text = slider:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
slider.text:SetPoint("BOTTOM", slider, "TOP", 0, 3)
SetSliderLabel(slider, ref, Settings.GetValue(ref.VolumeCVar) or 0)
slider:SetScript("OnValueChanged", function(self, value)
Settings.SetValue(ref.VolumeCVar, value)
SetSliderLabel(self, ref, value)
if ref == VOLUMES.master then
DataObj:UpdateText(value)
end
end)
slider:SetScript("OnMouseWheel", function(self, delta)
local currentValue = self:GetValue()
local minValue, maxValue = self:GetMinMaxValues()
local step = self:GetValueStep()
if delta > 0 then
self:SetValue(math.min(maxValue, currentValue + step))
elseif delta < 0 then
self:SetValue(math.max(minValue, currentValue - step))
end
end)
_G.hooksecurefunc("SetCVar", function(cvar, value)
if cvar == ref.VolumeCVar then
slider:SetValue(value)
elseif cvar == ref.EnableCVar then
check:SetChecked(value)
if ref == VOLUMES.master then
if value then
DataObj.icon = [[Interface\COMMON\VoiceChat-Speaker-Small]]
else
DataObj.icon = [[Interface\COMMON\VOICECHAT-MUTED]]
end
end
end
end)
return container
end
end
-------------------------------------------------------------------------------
-- Panel Backdrops
-------------------------------------------------------------------------------
local TooltipBackdrop = {
bgFile = [[Interface\Tooltips\UI-Tooltip-Background]],
edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]],
tile = true,
tileSize = 16,
edgeSize = 16,
insets = {
left = 5,
right = 5,
top = 5,
bottom = 5,
}
}
local PlainBackdrop = {
bgFile = [[Interface\Tooltips\UI-Tooltip-Background]],
tile = true,
tileSize = 16,
edgeSize = 16,
insets = {
left = 5,
right = 5,
top = 5,
bottom = 5,
}
}
-------------------------------------------------------------------------------
-- Main AddOn functions
-------------------------------------------------------------------------------
function Volumizer:ChangeBackdrop(backdrop)
self:SetBackdrop(backdrop)
self:SetBackdropBorderColor(def_col.r, def_col.g, def_col.b)
self:SetBackdropColor(def_bg_col.r, def_bg_col.g, def_bg_col.b)
end
local function __UsePreset(preset)
local ref = (preset < 1) and DEFAULT_PRESET or user_presets[preset]
if not ref then
_G.error("The preset '"..preset.."' does not exist.")
return
end
for category, data in pairs(VOLUMES) do
Settings.SetValue(data.VolumeCVar, tonumber(ref.values[category].volume))
local enable = ref.values[category].enable;
if (type(enable == "number")) then
if enable then
enable = true
else
enable = false
end
end
Settings.SetValue(data.EnableCVar, enable)
end
for category, data in pairs(TOGGLES) do
local enable = ref.values[category];
if (type(enable == "number")) then
if enable then
enable = true
else
enable = false
end
end
Settings.SetValue(data.EnableCVar, enable)
end
end
local function DropDownUsePreset(self, preset)
__UsePreset(preset)
-- Remove the check-mark from the menu entry.
_G[self:GetName().."Check"]:Hide()
end
local function DropDownSavePreset(self, preset)
local ref = user_presets[preset]
if not ref then
_G.error("The preset '"..preset.."' does not exist.")
return
end
for category, data in pairs(VOLUMES) do
ref.values[category].volume = Settings.GetValue(data.VolumeCVar)
ref.values[category].enable = Settings.GetValue(data.EnableCVar)
end
for category, data in pairs(TOGGLES) do
ref.values[category] = Settings.GetValue(data.EnableCVar)
end
user_presets[preset] = ref
end
local function DropDownDeletePreset(self, preset)
local ref = user_presets[preset]
if not ref then
_G.error("The preset '"..preset.."' does not exist.")
return
end
table.remove(user_presets, preset)
_G.CloseDropDownMenus(1)
end
local function RenamePreset_Popup(self, preset)
Volumizer.renaming = preset
_G.StaticPopup_Show("Volumizer_RenamePreset")
_G.CloseDropDownMenus(1)
end
local function DropDownAddPreset(self)
local preset = {
name = ("Preset %s"):format(_G.date("%b %d %H:%M:%S %Y", _G.GetTime())),
values = {},
}
for category, data in pairs(DEFAULT_PRESET_VALUES) do
if _G.type(data) == "table" then
preset.values[category] = {}
for label, value in pairs(data) do
preset.values[category][label] = value
end
else
preset.values[category] = data
end
end
table.insert(user_presets, preset)
RenamePreset_Popup(self, #user_presets)
end
do
local function GetAnchor(frame)
if not frame then
return "CENTER", UIParent, 0, 0
end
local x, y = frame:GetCenter()
if not x or not y then
return "TOPLEFT", "BOTTOMLEFT"
end
local hhalf = (x > UIParent:GetWidth() * 2 / 3) and "RIGHT" or (x < UIParent:GetWidth() / 3) and "LEFT" or ""
local vhalf = (y > UIParent:GetHeight() / 2) and "TOP" or "BOTTOM"
return vhalf .. hhalf, frame, (vhalf == "TOP" and "BOTTOM" or "TOP") .. hhalf
end
function Volumizer:Toggle(anchor, use_border)
if self:IsShown() then
self:Hide()
self.border:Hide()
else
self:ClearAllPoints()
self:SetPoint(GetAnchor(anchor))
self:Show()
if use_border then
self:ChangeBackdrop(PlainBackdrop)
self.border:Show()
else
self:ChangeBackdrop(TooltipBackdrop)
end
end
end
end -- do
-------------------------------------------------------------------------------
-- Event functions
-------------------------------------------------------------------------------
-- Make sure Blizzard_Settings was loaded
local loaded_Volumizer, loaded_Blizzard_Settings
function Volumizer:ADDON_LOADED(event, addon)
if addon == "Volumizer" then
user_presets = _G.VolumizerPresets
if not user_presets or _G.VolumizerDBVersion ~= DB_VERSION then
_G.VolumizerPresets = INITIAL_PRESETS
user_presets = _G.VolumizerPresets
_G.VolumizerDBVersion = DB_VERSION
print("Volumizer profile has been reset to default.")
end
loaded_Volumizer = true
if _G.IsAddOnLoaded('Blizzard_Settings') then
loaded_Blizzard_Settings = true
end
elseif addon == "Blizzard_Settings" then
loaded_Blizzard_Settings = true
end
if loaded_Volumizer and loaded_Blizzard_Settings then
if _G.IsLoggedIn() then
self:PLAYER_ENTERING_WORLD()
else
self:RegisterEvent("PLAYER_ENTERING_WORLD")
end
self:UnregisterEvent("ADDON_LOADED")
self.ADDON_LOADED = nil
end
end
function Volumizer:PLAYER_ENTERING_WORLD()
-----------------------------------------------------------------------
-- Main panel setup
-----------------------------------------------------------------------
self:SetFrameStrata("MEDIUM")
self:ChangeBackdrop(PlainBackdrop)
self:SetWidth(180)
self:SetHeight(305)
self:SetToplevel(true)
self:EnableMouse(true)
self:SetMovable(true)
self:SetClampedToScreen(true)
self:Hide()
-----------------------------------------------------------------------
-- Panel border setup
-----------------------------------------------------------------------
local border = CreateFrame("Frame", nil, self, _G.BackdropTemplateMixin and "BackdropTemplate")
self.border = border
border:SetFrameStrata("MEDIUM")
border:SetBackdrop({
edgeFile = [[Interface\DialogFrame\UI-DialogBox-Border]],
tile = true,
tileSize = 32,
edgeSize = 32,
insets = { left = 11, right = 12, top = 12, bottom = 11 }
})
border:SetBackdropBorderColor(def_col.r, def_col.g, def_col.b)
border:SetAllPoints(self)
border:Hide()
local titlebox = CreateFrame("Frame", nil, border)
titlebox:EnableMouse(true)
titlebox:SetMovable(true)
titlebox:RegisterForDrag("LeftButton")
titlebox:SetScript("OnDragStart", function()
Volumizer:StartMoving()
end)
titlebox:SetScript("OnDragStop", function()
Volumizer:StopMovingOrSizing()
end)
local titlebg = border:CreateTexture(nil, "ARTWORK")
titlebg:SetTexture([[Interface\DialogFrame\UI-DialogBox-Header]])
titlebg:SetPoint("CENTER", border, "TOP", 0, -17)
titlebg:SetWidth(230)
titlebg:SetHeight(56)
titlebox:SetAllPoints(titlebg)
local text = titlebox:CreateFontString(nil, "ARTWORK", "GameFontNormal")
text:SetPoint("TOP", titlebg, "TOP", 0, -11)
text:SetText("Volumizer")
-----------------------------------------------------------------------
-- Slider and Checkbox setup
-----------------------------------------------------------------------
local relative = self
do
local widget
for _, category in ipairs(order_VOLUMES) do
widget = MakeControl(category, relative)
relative = widget
end
relative = MakeContainer(relative, -10) -- Blank space in panel.
for _, category in ipairs(order_TOGGLES) do
widget = MakeToggle(category, relative)
relative = widget
end
end -- do-block
-----------------------------------------------------------------------
-- Hardware output controls
-----------------------------------------------------------------------
do
local cvar = "Sound_OutputDriverIndex"
local driver_index = Settings.GetValue(cvar)
local device_name = _G.Sound_GameSystem_GetOutputDriverNameByIndex(driver_index)
local output = CreateFrame("Frame", "Volumizer_OutputDropDown", self, "UIDropDownMenuTemplate")
output:SetPoint("TOPLEFT", relative, "BOTTOMLEFT", -5, 0)
local function output_OnClick(info)
local value = info.value
local dropdown = output
_G.UIDropDownMenu_SetSelectedValue(dropdown, value)
local prev_value = dropdown:GetValue()
dropdown:SetValue(value)
if prev_value ~= value then
_G.AudioOptionsFrame_AudioRestart()
end
end
function output:initialize()
local value = _G.UIDropDownMenu_GetSelectedValue(self)
local num = _G.Sound_GameSystem_GetNumOutputDrivers()
local info = _G.UIDropDownMenu_CreateInfo()
for index = 0, num - 1, 1 do
info.text = _G.Sound_GameSystem_GetOutputDriverNameByIndex(index)
info.value = index
info.checked = nil
if value and value == index then
_G.UIDropDownMenu_SetText(self, info.text)
info.checked = true
else
info.checked = nil
end
info.func = output_OnClick
_G.UIDropDownMenu_AddButton(info)
end
end
output.type = _G.CONTROLTYPE_DROPDOWN
output.cvar = cvar
output.value = driver_index
output.newValue = driver_index
_G.UIDropDownMenu_SetSelectedValue(output, driver_index)
_G.UIDropDownMenu_Initialize(output, output.initialize)
function output:SetValue(value)
self.value = value
Settings.SetValue(self.cvar, value)
end
function output:GetValue()
return Settings.GetValue(self.cvar)
end
function output:RefreshValue()
driver_index = Settings.GetValue(self.cvar)
self.value = driver_index
self.newValue = driver_index
_G.UIDropDownMenu_SetSelectedValue(self, driver_index)
_G.UIDropDownMenu_Initialize(self, self.initialize)
end
local text = output:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
text:SetPoint("BOTTOM", output, "TOP", 63, 3)
text:SetText(_G.GAME_SOUND_OUTPUT)
end -- do-block
-----------------------------------------------------------------------
-- Presets
-----------------------------------------------------------------------
do
local preset_menu = CreateFrame("Frame", nil, self)
preset_menu.displayMode = "MENU"
preset_menu.point = "TOPLEFT"
preset_menu.relativePoint = "RIGHT"
preset_menu.yOffset = 8
preset_menu.levelAdjust = 0
preset_menu.info = {}
function preset_menu.initialize(self, level)
if not level then
return
end
local info = preset_menu.info
table.wipe(info)
if level == 1 then
for index = 1, #user_presets do
info.text = user_presets[index].name
info.value = index
info.hasArrow = true
info.notCheckable = true
info.arg1 = index
info.func = DropDownUsePreset
_G.UIDropDownMenu_AddButton(info, level)
end
table.wipe(info) -- Blank space in menu.
info.disabled = true
info.notCheckable = 1
_G.UIDropDownMenu_AddButton(info, level)
info.disabled = nil
info.text = _G.ADD
info.func = DropDownAddPreset
info.arg1 = 0
info.colorCode = "|cffffff00"
info.notCheckable = 1
_G.UIDropDownMenu_AddButton(info, level)
info.text = _G.DEFAULTS
info.func = DropDownUsePreset
info.arg1 = 0
info.colorCode = "|cffffff00"
info.notCheckable = 1
_G.UIDropDownMenu_AddButton(info, level)
elseif level == 2 then
table.wipe(info)
info.arg1 = _G.UIDROPDOWNMENU_MENU_VALUE
info.notCheckable = 1
info.text = _G.SAVE
info.func = DropDownSavePreset
_G.UIDropDownMenu_AddButton(info, level)
info.text = _G.NAME
info.func = RenamePreset_Popup
_G.UIDropDownMenu_AddButton(info, level)
info.text = _G.DELETE
info.func = DropDownDeletePreset
_G.UIDropDownMenu_AddButton(info, level)
end
end
local preset_button = CreateFrame("Button", "Volumizer_PresetButton", self)
preset_button:SetWidth(20)
preset_button:SetHeight(20)
preset_button:SetPoint("RIGHT", self, "BOTTOMRIGHT", -8, 17)
preset_button:SetNormalTexture([[Interface\BUTTONS\UI-SpellbookIcon-NextPage-Up]])
preset_button:SetHighlightTexture([[Interface\BUTTONS\ButtonHilight-Round]])
preset_button:SetDisabledTexture([[Interface\BUTTONS\UI-SpellbookIcon-NextPage-Disabled]])
preset_button:SetPushedTexture([[Interface\BUTTONS\UI-SpellbookIcon-NextPage-Down]])
preset_button:SetScript("OnClick", function(self, button, down)
preset_menu.relativeTo = self
_G.ToggleDropDownMenu(1, nil, preset_menu, self:GetName(), 0, 0)
end)
preset_button:SetScript("OnHide", function()
if _G.UIDROPDOWNMENU_OPEN_MENU == preset_menu then
_G.CloseDropDownMenus()
end
end)
local text = preset_button:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
text:SetPoint("RIGHT", preset_button, "LEFT")
text:SetText("Presets")
end -- do-block
-----------------------------------------------------------------------
-- Static popup initialization
-----------------------------------------------------------------------
do
local function OnRenamePreset(self)
local edit_box = self:GetParent().editBox or self.editBox
local text = edit_box:GetText()
if text == "" then
text = nil
end
edit_box:SetText("")
user_presets[Volumizer.renaming].name = text
edit_box:GetParent():Hide()
end
StaticPopupDialogs["Volumizer_RenamePreset"] = {
text = _G.ERR_NAME_NO_NAME,
button1 = _G.ACCEPT,
button2 = _G.CANCEL,
OnShow = function(self)
self.button1:Disable()
self.button2:Enable()
self.editBox:SetFocus()
end,
OnAccept = OnRenamePreset,
EditBoxOnEnterPressed = OnRenamePreset,
EditBoxOnEscapePressed = function(self)
self:GetParent():Hide()
end,
EditBoxOnTextChanged = function(self)
local parent = self:GetParent()
if parent.editBox:GetText() ~= "" then
parent.button1:Enable()
else
parent.button1:Disable()
end
end,
timeout = 0,
hideOnEscape = 1,
exclusive = 1,
whileDead = 1,
hasEditBox = 1
}
end -- do-block
-----------------------------------------------------------------------
-- Frame interaction with keyboard/mouse
-----------------------------------------------------------------------
do
local old_x, old_y, click_time
_G.WorldFrame:HookScript("OnMouseDown", function(frame, ...)
old_x, old_y = _G.GetCursorPosition()
click_time = _G.GetTime()
end)
_G.WorldFrame:HookScript("OnMouseUp", function(frame, ...)
local x, y = _G.GetCursorPosition()
if not old_x or not old_y or not x or not y or not click_time then
self:Hide()
border:Hide()
return
end
if (math.abs(x - old_x) + math.abs(y - old_y)) <= 5 and _G.GetTime() - click_time < 1 then
self:Hide()
border:Hide()
end
end)
table.insert(_G.UISpecialFrames, "VolumizerPanel")
SLASH_Volumizer1 = "/volumizer"
SLASH_Volumizer2 = "/vol"
SlashCmdList["Volumizer"] = function(preset_name)
local can_toggle = true
preset_name = preset_name:lower()
if preset_name then
for index = 1, #user_presets do
if user_presets[index].name:lower() == preset_name then
can_toggle = false
__UsePreset(index)
break
end
end
end
if can_toggle then
Volumizer:Toggle(nil, true)
end
end
end -- do-block
-----------------------------------------------------------------------
-- LDB Icon initial display
-----------------------------------------------------------------------
DataObj = LDB:NewDataObject("Volumizer", {
type = "data source",
label = "Volumizer",
text = "0%",
icon = [[Interface\COMMON\VOICECHAT-SPEAKER]],
OnClick = function(display, button)
if button == "LeftButton" then
Settings.SetValue("Sound_EnableAllSound", not Settings.GetValue("Sound_EnableAllSound"))
elseif button == "RightButton" then
Volumizer:Toggle(display, false)
end
end,
OnTooltipShow = function(self)
self:AddLine(_G.KEY_BUTTON1 .. " - " .. _G.MUTE)
self:AddLine(_G.KEY_BUTTON2 .. " - " .. _G.CLICK_FOR_DETAILS)
end,
OnMouseWheel = function(self, delta)
local ref = VOLUMES.master
local current = Settings.GetValue(ref.VolumeCVar)
local step = 0.05
if delta > 0 then
Settings.SetValue(ref.VolumeCVar, math.min(ref.SoundOption.maxValue, current + step))
elseif delta < 0 then
Settings.SetValue(ref.VolumeCVar, math.max(ref.SoundOption.minValue, current - step))
end
end,
UpdateText = function(self, value)
self.text = ("%d%%"):format(value * 100)
end,