-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.lua
176 lines (150 loc) · 6.47 KB
/
core.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
-- Bears Audio Switcher - Database
-- Created by N6REJ character is Bearesquishy - dalaran please credit whenever.
-- Source on GitHub: https://n6rej.github.io
---
---@class ns
-- Create BearsSwitcher in wow
BearsSwitcher = LibStub("AceAddon-3.0"):NewAddon("BearsSwitcher", "AceEvent-3.0", "AceConsole-3.0")
-- Create local variable for profiles incase we need them.
local _G = _G
-- Locals
local AC = LibStub("AceConfig-3.0")
local ACD = LibStub("AceConfigDialog-3.0")
function BearsSwitcher:OnInitialize()
-- uses the "Default" profile instead of character-specific profiles
-- https://www.wowace.com/projects/ace3/pages/api/ace-db-3-0
self.db = LibStub("AceDB-3.0"):New("BearsSwitcherDB", self.defaults, true)
-- registers an options table and adds it to the Blizzard options window
-- https://www.wowace.com/projects/ace3/pages/api/ace-config-3-0
AC:RegisterOptionsTable("BearsSwitcher_Options", BearsSwitcher.options)
self.optionsFrame = ACD:AddToBlizOptions("BearsSwitcher_Options", "Bears Audio Switcher")
-- adds a child options table, in this case our profiles panel
local profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
AC:RegisterOptionsTable("BearsSwitcher_Profiles", profiles)
ACD:AddToBlizOptions("BearsSwitcher_Profiles", "Profiles", "Bears Audio Switcher")
-- https://www.wowace.com/projects/ace3/pages/api/ace-console-3-0
self:RegisterChatCommand("bs", "SlashCommand")
self:RegisterChatCommand("switcher", "SlashCommand")
-- We need to set some defaults to use if they've not set things up before.
local defaults = {
volumeUp = GetBindingText("NUMPADPLUS"),
volumeDown = GetBindingText("NUMPADMINUS"),
volumeSteps = 1,
toggle = GetBindingText("NUMPADMULTIPLY"),
music_toggle = GetBindingText("NUMPADDIVIDE"),
enableSound = true
}
for key, value in pairs(defaults) do
if BearsSwitcher.db.profile[key] == nil then
BearsSwitcher.db.profile[key] = value
end
end
-- Let them know the addon is working
print("|cff00FF00Bears Audio Switcher loaded. For options type /bs|r")
end
-- Let them use profiles
function BearsSwitcher:GetCharacterInfo()
-- stores character-specific data
self.db.char.level = UnitLevel("player")
end
function BearsSwitcher:SlashCommand(input, editbox)
if input == "enable" then
self:Enable()
self:Print("Enabled.")
elseif input == "disable" then
-- unregisters all events and calls BearsSwitcher:OnDisable() if you defined that
self:Disable()
self:Print("Disabled.")
else
ACD:Open("BearsSwitcher_Options")
end
end
-- VOLUME CONTROLS
local function AdjustMasterVolume(SOUND_MASTERVOLUME_STEP)
-- Set volume to 1-100
SOUND_MASTERVOLUME_STEP = SOUND_MASTERVOLUME_STEP / 100
-- Get current volume level from 1 - 100
local volume = tonumber(GetCVar("Sound_MasterVolume"))
if (volume) then
volume = volume + SOUND_MASTERVOLUME_STEP
if (volume >= 1.0) then
volume = 1.0
if BearsSwitcher.db.profile.enableSound == true then
-- Sound to let them know the volume is maxed
PlaySoundFile("Interface\\AddOns\\Bears_Audio_Switcher\\media\\100.ogg")
end
elseif (volume <= 0.0) then
volume = 0.0
end
SetCVar("Sound_MasterVolume", volume)
end
end
function VolumeUp()
AdjustMasterVolume(BearsSwitcher.db.profile.volumeSteps)
end
function VolumeDown()
AdjustMasterVolume(-BearsSwitcher.db.profile.volumeSteps)
end
-- Check for valid keypress
local f = CreateFrame("Button")
f:SetScript(
"OnKeyDown",
function(self, key)
if key == BearsSwitcher.db.profile.toggle then
-- Check for volume up or down
-- Which speaker is active?
local cVar = "Sound_OutputDriverIndex"
local switch = tonumber(GetCVar(cVar))
local current
local spkr1 = BearsSwitcher.db.profile.spkr1 - 1
local spkr2 = BearsSwitcher.db.profile.spkr2 - 1
-- print("spkr1=", BearsSwitcher.db.profile.spkr1)
-- print("spkr2=", BearsSwitcher.db.profile.spkr2)
-- print("switch is: ", switch)
if switch == spkr1 then
-- print("set spkr1 active")
SetCVar("Sound_OutputDriverIndex", tostring(spkr2))
else
-- print("set spkr2 active")
SetCVar("Sound_OutputDriverIndex", tostring(spkr1))
end
-- Make the device active.
Sound_GameSystem_RestartSoundSystem()
-- Find out current device so we can tell them what it is.
cVar = "Sound_OutputDriverIndex"
current = tonumber(GetCVar(cVar))
print(
"|cff00FF00Audio Devices changed:|r",
"|cffe3ff00",
Sound_GameSystem_GetOutputDriverNameByIndex(current),
"|r|cff00FF00 active|r"
)
elseif key == BearsSwitcher.db.profile.volumeUp then
VolumeUp()
-- Sound to let them know the button was pushed
local volume = tonumber(GetCVar("Sound_MasterVolume"))
if BearsSwitcher.db.profile.enableSound == true and volume < 1 then
PlaySoundFile("Interface\\AddOns\\Bears_Audio_Switcher\\media\\volumeUp.ogg")
end
elseif key == BearsSwitcher.db.profile.volumeDown then
VolumeDown()
-- Sound to let them know the button was pushed
local volume = tonumber(GetCVar("Sound_MasterVolume"))
if BearsSwitcher.db.profile.enableSound == true and volume >= .01 then
PlaySoundFile("Interface\\AddOns\\Bears_Audio_Switcher\\media\\volumeDown.ogg")
end
end
if key == BearsSwitcher.db.profile.music_toggle then
-- Check for current state of music toggle.
Sound_ToggleMusic()
end
-- ok, pass the key thru
if not InCombatLockdown() then
self:SetPropagateKeyboardInput(true)
end
end
)
-- Addon compartment usage
function BearsAudioSwitcher_OnAddonCompartmentClick(addonName, buttonName, editbox)
BearsSwitcher:SlashCommand("/bs", editbox)
end