vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | local L = AceLibrary("AceLocale-2.0"):new("VolumeFu") |
2 | local Crayon = AceLibrary("Crayon-2.0") |
||
3 | local Tablet = AceLibrary("Tablet-2.0") |
||
4 | |||
5 | VolumeFu = AceLibrary("AceAddon-2.0"):new("AceConsole-2.0", "AceDB-2.0", "FuBarPlugin-2.0") |
||
6 | |||
7 | VolumeFu.version = "2.0."..string.sub("$Revision: 9772 $", 12, -3) |
||
8 | VolumeFu.date = string.sub("$Date: 2006-09-01 19:38:36 -0400 (Fri, 01 Sep 2006) $", 8, 17) |
||
9 | VolumeFu.hasIcon = "Interface\\AddOns\\FuBar_VolumeFu\\icons\\off.tga" |
||
10 | VolumeFu.hasNoText = true |
||
11 | VolumeFu.defaultPosition = "RIGHT" |
||
12 | |||
13 | VolumeFu:RegisterDB("VolumeFuDB") |
||
14 | VolumeFu:RegisterDefaults("profile", { |
||
15 | quickfix = false, |
||
16 | mute = false, |
||
17 | master = tonumber(GetCVar("MasterVolume")), |
||
18 | }) |
||
19 | |||
20 | function VolumeFu:OnEnable() |
||
21 | self:SetIcon(self:GetVolumeIcon()) |
||
22 | end |
||
23 | |||
24 | function VolumeFu:OnClick() |
||
25 | if not self:IsMute() and not self:IsQuickFix() then |
||
26 | if arg1 == "LeftButton" and IsShiftKeyDown() then |
||
27 | self:ResetVolume() |
||
28 | end |
||
29 | end |
||
30 | end |
||
31 | |||
32 | function VolumeFu:OnDoubleClick() |
||
33 | self:ToggleMute() |
||
34 | self:SetIcon(self:GetVolumeIcon()) |
||
35 | end |
||
36 | |||
37 | function VolumeFu:OnTooltipUpdate() |
||
38 | local r, g, b = 1, 1, 0 |
||
39 | local category |
||
40 | |||
41 | if self:IsMute() then |
||
42 | category = Tablet:AddCategory( |
||
43 | "text", Crayon:Red(L["Muted"]), |
||
44 | "columns", 1, |
||
45 | "justify", "CENTER", |
||
46 | "showWithoutChildren", true |
||
47 | ) |
||
48 | end |
||
49 | |||
50 | category = Tablet:AddCategory( |
||
51 | "text", L["Levels"], |
||
52 | "columns", 2, |
||
53 | "child_textR", r, |
||
54 | "child_textG", g, |
||
55 | "child_textB", b |
||
56 | ) |
||
57 | |||
58 | self:AddTooltipLevel(category, L["Master"], self:GetMasterVolume()) |
||
59 | self:AddTooltipLevel(category, L["Sound"], self:GetSoundVolume()) |
||
60 | self:AddTooltipLevel(category, L["Music"], self:GetMusicVolume()) |
||
61 | self:AddTooltipLevel(category, L["Ambience"], self:GetAmbienceVolume()) |
||
62 | |||
63 | category = Tablet:AddCategory( |
||
64 | "text", L["Settings"], |
||
65 | "columns", 2, |
||
66 | "child_textR", r, |
||
67 | "child_textG", g, |
||
68 | "child_textB", b |
||
69 | ) |
||
70 | |||
71 | self:AddTooltipSetting(category, L["Ambience"], self:IsSetAmbience()) |
||
72 | self:AddTooltipSetting(category, L["Error Speech"], self:IsSetErrorSpeech()) |
||
73 | self:AddTooltipSetting(category, L["Music"], self:IsSetMusic()) |
||
74 | self:AddTooltipSetting(category, L["Sound at Character"], self:IsSetSoundAtCharacter()) |
||
75 | self:AddTooltipSetting(category, L["Emote Sounds"], self:IsSetEmoteSounds()) |
||
76 | self:AddTooltipSetting(category, L["Loop Music"], self:IsSetLoopMusic()) |
||
77 | |||
78 | if not self:IsMute() and self:IsQuickFix() then |
||
79 | self:ResetVolume() |
||
80 | end |
||
81 | |||
82 | if self:IsMute() then |
||
83 | Tablet:SetHint(L["MuteOn-hint"]) |
||
84 | else |
||
85 | if self:IsQuickFix() then |
||
86 | Tablet:SetHint(L["QuickFix-hint"].."\n"..L["MuteOff-hint"]) |
||
87 | else |
||
88 | Tablet:SetHint(L["RegularFix-hint"].."\n"..L["MuteOff-hint"]) |
||
89 | end |
||
90 | end |
||
91 | end |
||
92 | |||
93 | local options = { |
||
94 | handler = VolumeFu, |
||
95 | type = "group", |
||
96 | args = { |
||
97 | mute = { |
||
98 | type = "toggle", |
||
99 | order = 1.0, |
||
100 | name = L["Mute"], |
||
101 | desc = L["Mute sound"], |
||
102 | get = "IsMute", |
||
103 | set = "ToggleMute", |
||
104 | }, |
||
105 | quickfix = { |
||
106 | type = "toggle", |
||
107 | order = 1.1, |
||
108 | name = L["Quick Fix"], |
||
109 | desc = L["Always reset game volume on mouseover"], |
||
110 | get = "IsQuickFix", |
||
111 | set = "ToggleQuickFix", |
||
112 | }, |
||
113 | levels = { |
||
114 | type = "group", |
||
115 | order = 1.2, |
||
116 | name = L["Levels"], |
||
117 | desc = L["Set volume levels"], |
||
118 | disabled = function() return VolumeFu:IsMute() end, |
||
119 | args = { |
||
120 | master = { |
||
121 | type = "range", |
||
122 | order = 1.0, |
||
123 | name = L["Master"], |
||
124 | desc = L["Set the master volume"], |
||
125 | max = 1, |
||
126 | min = 0, |
||
127 | step = 0.01, |
||
128 | isPercent = true, |
||
129 | get = "GetMasterVolume", |
||
130 | set = "SetMasterVolume", |
||
131 | }, |
||
132 | sound = { |
||
133 | type = "range", |
||
134 | order = 1.1, |
||
135 | name = L["Sound"], |
||
136 | desc = L["Set the sound volume"], |
||
137 | max = 1, |
||
138 | min = 0, |
||
139 | step = 0.01, |
||
140 | isPercent = true, |
||
141 | get = "GetSoundVolume", |
||
142 | set = "SetSoundVolume", |
||
143 | }, |
||
144 | music = { |
||
145 | type = "range", |
||
146 | order = 1.2, |
||
147 | name = L["Music"], |
||
148 | desc = L["Set the music volume"], |
||
149 | max = 1, |
||
150 | min = 0, |
||
151 | step = 0.01, |
||
152 | isPercent = true, |
||
153 | get = "GetMusicVolume", |
||
154 | set = "SetMusicVolume", |
||
155 | }, |
||
156 | ambience = { |
||
157 | type = "range", |
||
158 | order = 1.3, |
||
159 | name = L["Ambience"], |
||
160 | desc = L["Set the ambience volume"], |
||
161 | max = 1, |
||
162 | min = 0, |
||
163 | step = 0.01, |
||
164 | isPercent = true, |
||
165 | get = "GetAmbienceVolume", |
||
166 | set = "SetAmbienceVolume", |
||
167 | }, |
||
168 | }, |
||
169 | }, |
||
170 | settings = { |
||
171 | type = "group", |
||
172 | order = 1.2, |
||
173 | name = L["Settings"], |
||
174 | desc = L["Change volume settings"], |
||
175 | disabled = function() return VolumeFu:IsMute() end, |
||
176 | args = { |
||
177 | soundeffects = { |
||
178 | type = "toggle", |
||
179 | order = 1.0, |
||
180 | name = L["Sound Effects"], |
||
181 | desc = L["Toggle master sound effects"], |
||
182 | get = "IsSetMasterSoundEffects", |
||
183 | set = "ToggleMasterSoundEffects", |
||
184 | }, |
||
185 | ambience = { |
||
186 | type = "toggle", |
||
187 | order = 1.1, |
||
188 | name = L["Ambience"], |
||
189 | desc = L["Toggle ambient noise"], |
||
190 | get = "IsSetAmbience", |
||
191 | set = "ToggleAmbience", |
||
192 | }, |
||
193 | errorspeech = { |
||
194 | type = "toggle", |
||
195 | order = 1.2, |
||
196 | name = L["Error Speech"], |
||
197 | desc = L["Toggle error speech"], |
||
198 | get = "IsSetErrorSpeech", |
||
199 | set = "ToggleErrorSpeech", |
||
200 | }, |
||
201 | music = { |
||
202 | type = "toggle", |
||
203 | order = 1.3, |
||
204 | name = L["Music"], |
||
205 | desc = L["Toggle music"], |
||
206 | get = "IsSetMusic", |
||
207 | set = "ToggleMusic", |
||
208 | }, |
||
209 | soundatcharacter = { |
||
210 | type = "toggle", |
||
211 | order = 1.4, |
||
212 | name = L["Sound at Character"], |
||
213 | desc = L["Toggle sound at character"], |
||
214 | get = "IsSetSoundAtCharacter", |
||
215 | set = "ToggleSoundAtCharacter", |
||
216 | }, |
||
217 | emotesounds = { |
||
218 | type = "toggle", |
||
219 | order = 1.5, |
||
220 | name = L["Emote Sounds"], |
||
221 | desc = L["Toggle emote sounds"], |
||
222 | get = "IsSetEmoteSounds", |
||
223 | set = "ToggleEmoteSounds", |
||
224 | }, |
||
225 | loopmusic = { |
||
226 | type = "toggle", |
||
227 | order = 1.6, |
||
228 | name = L["Loop Music"], |
||
229 | desc = L["Toggle loop music"], |
||
230 | get = "IsSetLoopMusic", |
||
231 | set = "ToggleLoopMusic", |
||
232 | }, |
||
233 | }, |
||
234 | }, |
||
235 | }, |
||
236 | } |
||
237 | |||
238 | VolumeFu:RegisterChatCommand({"/volumefu", "/volfu", "/vfu"}, options) |
||
239 | VolumeFu.OnMenuRequest = options |
||
240 | |||
241 | |||
242 | function VolumeFu:AddTooltipLevel(category, label, level) |
||
243 | local r, g, b = Crayon:GetThresholdColor(level) |
||
244 | category:AddLine( |
||
245 | "text", label, |
||
246 | "text2", format("%d%%", floor(100 * level + 0.5)), |
||
247 | "text2R", r, |
||
248 | "text2G", g, |
||
249 | "text2B", b |
||
250 | ) |
||
251 | end |
||
252 | |||
253 | local MAP_ONOFF = { [false] = "|cffff0000Off|r", [true] = "|cff00ff00On|r" } |
||
254 | function VolumeFu:AddTooltipSetting(category, label, value) |
||
255 | category:AddLine( |
||
256 | "text", label, |
||
257 | "text2", MAP_ONOFF[value] |
||
258 | ) |
||
259 | end |
||
260 | |||
261 | function VolumeFu:ResetVolume() |
||
262 | local volume = self:GetMasterVolume() |
||
263 | SetCVar("MasterVolume", 0) |
||
264 | SetCVar("MasterVolume", volume) |
||
265 | end |
||
266 | |||
267 | function VolumeFu:GetVolumeIcon() |
||
268 | local path = "Interface\\AddOns\\FuBar_VolumeFu\\icons\\" |
||
269 | local volume = self:GetMasterVolume() |
||
270 | if volume > 0.66 then |
||
271 | path = path.."high" |
||
272 | elseif volume > 0.33 then |
||
273 | path = path.."medium" |
||
274 | elseif volume > 0 then |
||
275 | path = path.."low" |
||
276 | else |
||
277 | path = path.."off" |
||
278 | end |
||
279 | if self:IsMute() then |
||
280 | path = path.."-mute" |
||
281 | end |
||
282 | return path..".tga" |
||
283 | end |
||
284 | |||
285 | function VolumeFu:IsQuickFix() |
||
286 | return self.db.profile.quickfix |
||
287 | end |
||
288 | |||
289 | function VolumeFu:ToggleQuickFix() |
||
290 | self.db.profile.quickfix = not self.db.profile.quickfix |
||
291 | self:Update() |
||
292 | return self.db.profile.quickfix |
||
293 | end |
||
294 | |||
295 | function VolumeFu:IsMute() |
||
296 | return self.db.profile.mute |
||
297 | end |
||
298 | |||
299 | function VolumeFu:ToggleMute() |
||
300 | self.db.profile.mute = not self.db.profile.mute |
||
301 | if self.db.profile.mute then |
||
302 | SetCVar("MasterVolume", 0) |
||
303 | else |
||
304 | SetCVar("MasterVolume", self.db.profile.master) |
||
305 | end |
||
306 | self:SetIcon(self:GetVolumeIcon()) |
||
307 | self:Update() |
||
308 | return self.db.profile.mute |
||
309 | end |
||
310 | |||
311 | function VolumeFu:GetMasterVolume() |
||
312 | return self.db.profile.master |
||
313 | end |
||
314 | |||
315 | function VolumeFu:SetMasterVolume(value) |
||
316 | self.db.profile.master = value |
||
317 | SetCVar("MasterVolume", value) |
||
318 | self:SetIcon(self:GetVolumeIcon()) |
||
319 | end |
||
320 | |||
321 | function VolumeFu:GetSoundVolume() |
||
322 | return tonumber(GetCVar("SoundVolume")) |
||
323 | end |
||
324 | |||
325 | function VolumeFu:SetSoundVolume(value) |
||
326 | SetCVar("SoundVolume", value) |
||
327 | self:SetIcon(self:GetVolumeIcon()) |
||
328 | end |
||
329 | |||
330 | function VolumeFu:GetMusicVolume() |
||
331 | return tonumber(GetCVar("MusicVolume")) |
||
332 | end |
||
333 | |||
334 | function VolumeFu:SetMusicVolume(value) |
||
335 | SetCVar("MusicVolume", value) |
||
336 | self:SetIcon(self:GetVolumeIcon()) |
||
337 | end |
||
338 | |||
339 | function VolumeFu:GetAmbienceVolume() |
||
340 | return tonumber(GetCVar("AmbienceVolume")) |
||
341 | end |
||
342 | |||
343 | function VolumeFu:SetAmbienceVolume(value) |
||
344 | SetCVar("AmbienceVolume", value) |
||
345 | self:SetIcon(self:GetVolumeIcon()) |
||
346 | end |
||
347 | |||
348 | function VolumeFu:IsSetMasterSoundEffects() |
||
349 | return GetCVar("MasterSoundEffects") == "1" |
||
350 | end |
||
351 | |||
352 | function VolumeFu:ToggleMasterSoundEffects() |
||
353 | SetCVar("MasterSoundEffects", GetCVar("MasterSoundEffects") == "1" and 0 or 1) |
||
354 | end |
||
355 | |||
356 | function VolumeFu:IsSetMusic() |
||
357 | return GetCVar("EnableMusic") == "1" |
||
358 | end |
||
359 | |||
360 | function VolumeFu:ToggleMusic() |
||
361 | SetCVar("EnableMusic", GetCVar("EnableMusic") == "1" and 0 or 1) |
||
362 | end |
||
363 | |||
364 | function VolumeFu:IsSetSoundAtCharacter() |
||
365 | return GetCVar("SoundListenerAtCharacter") == "1" |
||
366 | end |
||
367 | |||
368 | function VolumeFu:ToggleSoundAtCharacter() |
||
369 | SetCVar("SoundListenerAtCharacter", GetCVar("SoundListenerAtCharacter") == "1" and 0 or 1) |
||
370 | end |
||
371 | |||
372 | function VolumeFu:IsSetEmoteSounds() |
||
373 | return GetCVar("EmoteSounds") == "1" |
||
374 | end |
||
375 | |||
376 | function VolumeFu:ToggleEmoteSounds() |
||
377 | SetCVar("EmoteSounds", GetCVar("EmoteSounds") == "1" and 0 or 1) |
||
378 | end |
||
379 | |||
380 | function VolumeFu:IsSetLoopMusic() |
||
381 | return GetCVar("SoundZoneMusicNoDelay") == "1" |
||
382 | end |
||
383 | |||
384 | function VolumeFu:ToggleLoopMusic() |
||
385 | SetCVar("SoundZoneMusicNoDelay", GetCVar("SoundZoneMusicNoDelay") == "1" and 0 or 1) |
||
386 | end |
||
387 | |||
388 | function VolumeFu:IsSetAmbience() |
||
389 | return GetCVar("EnableAmbience") == "1" |
||
390 | end |
||
391 | |||
392 | function VolumeFu:ToggleAmbience() |
||
393 | SetCVar("EnableAmbience", GetCVar("EnableAmbience") == "1" and 0 or 1) |
||
394 | end |
||
395 | |||
396 | function VolumeFu:IsSetErrorSpeech() |
||
397 | return GetCVar("EnableErrorSpeech") == "1" |
||
398 | end |
||
399 | |||
400 | function VolumeFu:ToggleErrorSpeech() |
||
401 | SetCVar("EnableErrorSpeech", GetCVar("EnableErrorSpeech") == "1" and 0 or 1) |
||
402 | end |