diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index d8efb14788..d536a61513 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -127,6 +127,7 @@ namespace OpenRA public string Device = null; public bool CashTicks = true; + public bool Mute = false; } public class PlayerSettings @@ -204,6 +205,7 @@ namespace OpenRA public Hotkey DevReloadChromeKey = new Hotkey(Keycode.C, Modifiers.Ctrl | Modifiers.Shift); public Hotkey HideUserInterfaceKey = new Hotkey(Keycode.H, Modifiers.Ctrl | Modifiers.Shift); public Hotkey TakeScreenshotKey = new Hotkey(Keycode.P, Modifiers.Ctrl); + public Hotkey ToggleMuteKey = new Hotkey(Keycode.M, Modifiers.None); public Hotkey Production01Key = new Hotkey(Keycode.F1, Modifiers.None); public Hotkey Production02Key = new Hotkey(Keycode.F2, Modifiers.None); diff --git a/OpenRA.Game/Sound/Sound.cs b/OpenRA.Game/Sound/Sound.cs index 97ccc6db43..7f49409871 100644 --- a/OpenRA.Game/Sound/Sound.cs +++ b/OpenRA.Game/Sound/Sound.cs @@ -114,6 +114,16 @@ namespace OpenRA soundEngine.StopAllSounds(); } + public void MuteAudio() + { + soundEngine.Volume = 0f; + } + + public void UnmuteAudio() + { + soundEngine.Volume = 1f; + } + public ISound Play(string name) { return Play(null, name, true, WPos.Zero, 1f); } public ISound Play(string name, WPos pos) { return Play(null, name, false, pos, 1f); } public ISound Play(string name, float volumeModifier) { return Play(null, name, true, WPos.Zero, volumeModifier); } diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs index e958e0b5bc..b2bfeb835f 100644 --- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs @@ -302,6 +302,8 @@ namespace OpenRA.Widgets return CycleStatusBars(); else if (key == Game.Settings.Keys.TogglePixelDoubleKey) return TogglePixelDouble(); + else if (key == Game.Settings.Keys.ToggleMuteKey) + return ToggleMute(); } return false; @@ -360,5 +362,23 @@ namespace OpenRA.Widgets worldRenderer.Viewport.Zoom = Game.Settings.Graphics.PixelDouble ? 2 : 1; return true; } + + bool ToggleMute() + { + Game.Settings.Sound.Mute ^= true; + + if (Game.Settings.Sound.Mute) + { + Game.Sound.MuteAudio(); + Game.Debug("Audio muted"); + } + else + { + Game.Sound.UnmuteAudio(); + Game.Debug("Audio unmuted"); + } + + return true; + } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/MusicPlayerLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MusicPlayerLogic.cs index b85f0ad82d..522c60845b 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MusicPlayerLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MusicPlayerLogic.cs @@ -38,6 +38,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic Func noMusic = () => !musicPlaylist.IsMusicAvailable || musicPlaylist.CurrentSongIsBackground || currentSong == null; panel.Get("NO_MUSIC_LABEL").IsVisible = () => !musicPlaylist.IsMusicAvailable; + if (musicPlaylist.IsMusicAvailable) + { + panel.Get("MUTE_LABEL").GetText = () => + { + if (Game.Settings.Sound.Mute) + return "Audio has been muted in settings."; + + return ""; + }; + } + var playButton = panel.Get("BUTTON_PLAY"); playButton.OnClick = Play; playButton.IsDisabled = noMusic; diff --git a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs index 25cbde9528..60e95ed2c5 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs @@ -305,15 +305,30 @@ namespace OpenRA.Mods.Common.Widgets.Logic var ss = Game.Settings.Sound; BindCheckboxPref(panel, "CASH_TICKS", ss, "CashTicks"); + BindCheckboxPref(panel, "MUTE_SOUND", ss, "Mute"); BindSliderPref(panel, "SOUND_VOLUME", ss, "SoundVolume"); BindSliderPref(panel, "MUSIC_VOLUME", ss, "MusicVolume"); BindSliderPref(panel, "VIDEO_VOLUME", ss, "VideoVolume"); - // Update volume immediately - panel.Get("SOUND_VOLUME").OnChange += x => Game.Sound.SoundVolume = x; - panel.Get("MUSIC_VOLUME").OnChange += x => Game.Sound.MusicVolume = x; - panel.Get("VIDEO_VOLUME").OnChange += x => Game.Sound.VideoVolume = x; + var muteCheckbox = panel.Get("MUTE_SOUND"); + var muteCheckboxOnClick = muteCheckbox.OnClick; + muteCheckbox.OnClick = () => + { + muteCheckboxOnClick(); + + if (ss.Mute) + Game.Sound.MuteAudio(); + else + Game.Sound.UnmuteAudio(); + }; + + if (!ss.Mute) + { + panel.Get("SOUND_VOLUME").OnChange += x => Game.Sound.SoundVolume = x; + panel.Get("MUSIC_VOLUME").OnChange += x => Game.Sound.MusicVolume = x; + panel.Get("VIDEO_VOLUME").OnChange += x => Game.Sound.VideoVolume = x; + } var devices = Game.Sound.AvailableDevices(); soundDevice = devices.FirstOrDefault(d => d.Engine == ss.Engine && d.Device == ss.Device) ?? devices.First(); @@ -339,6 +354,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ss.MusicVolume = dss.MusicVolume; ss.VideoVolume = dss.VideoVolume; ss.CashTicks = dss.CashTicks; + ss.Mute = dss.Mute; ss.Device = dss.Device; ss.Engine = dss.Engine; @@ -348,6 +364,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic Game.Sound.MusicVolume = ss.MusicVolume; panel.Get("VIDEO_VOLUME").Value = ss.VideoVolume; Game.Sound.VideoVolume = ss.VideoVolume; + Game.Sound.UnmuteAudio(); soundDevice = Game.Sound.AvailableDevices().First(); }; } @@ -414,6 +431,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { "CycleStatusBarsKey", "Cycle status bars display" }, { "TogglePixelDoubleKey", "Toggle pixel doubling" }, + { "ToggleMuteKey", "Toggle audio mute" }, { "MapScrollUp", "Map scroll up" }, { "MapScrollDown", "Map scroll down" }, diff --git a/OpenRA.Platforms.Default/OpenAlSoundEngine.cs b/OpenRA.Platforms.Default/OpenAlSoundEngine.cs index 91cc787e43..914e507879 100644 --- a/OpenRA.Platforms.Default/OpenAlSoundEngine.cs +++ b/OpenRA.Platforms.Default/OpenAlSoundEngine.cs @@ -212,6 +212,9 @@ namespace OpenRA.Platforms.Default if (!TryGetSourceFromPool(out source)) return null; + if (Game.Settings.Sound.Mute) + Game.Sound.MuteAudio(); + var slot = sourcePool[source]; slot.Pos = pos; slot.FrameStarted = currFrame; diff --git a/mods/cnc/chrome/lobby-music.yaml b/mods/cnc/chrome/lobby-music.yaml index 73a3f53987..ad9397a0ae 100644 --- a/mods/cnc/chrome/lobby-music.yaml +++ b/mods/cnc/chrome/lobby-music.yaml @@ -31,6 +31,12 @@ Container@LOBBY_MUSIC_BIN: Width: 308 Height: PARENT_BOTTOM Children: + Label@MUTE_LABEL: + X: 25 + Y: 10 + Width: 300 + Height: 20 + Font: Small Label@TITLE_LABEL: Y: 45 Width: PARENT_RIGHT diff --git a/mods/cnc/chrome/music.yaml b/mods/cnc/chrome/music.yaml index 8e8c1dbe59..a4cefd6d5d 100644 --- a/mods/cnc/chrome/music.yaml +++ b/mods/cnc/chrome/music.yaml @@ -176,6 +176,12 @@ Container@MUSIC_PANEL: Width: 140 Height: 35 Text: Install Music + Label@MUTE_LABEL: + X: 165 + Y: 399 + Width: 300 + Height: 20 + Font: Small Container@INSTALL_MUSIC_PANEL: Logic: InstallMusicLogic diff --git a/mods/cnc/chrome/settings.yaml b/mods/cnc/chrome/settings.yaml index c1f867fdf0..c6747644cd 100644 --- a/mods/cnc/chrome/settings.yaml +++ b/mods/cnc/chrome/settings.yaml @@ -269,6 +269,13 @@ Container@SETTINGS_PANEL: Height: 20 Font: Regular Text: Cash Ticks + Checkbox@MUTE_SOUND: + X: 15 + Y: 70 + Width: 200 + Height: 20 + Font: Regular + Text: Mute Sound Label@MUSIC_LABEL: X: PARENT_RIGHT - WIDTH - 270 Y: 67 diff --git a/mods/ra/chrome/lobby-music.yaml b/mods/ra/chrome/lobby-music.yaml index c1a4a2f2bf..bb8fa3172a 100644 --- a/mods/ra/chrome/lobby-music.yaml +++ b/mods/ra/chrome/lobby-music.yaml @@ -31,6 +31,12 @@ Container@LOBBY_MUSIC_BIN: Width: 268 Height: PARENT_BOTTOM Children: + Label@MUTE_LABEL: + X: 25 + Y: 10 + Width: 300 + Height: 20 + Font: Small Label@TITLE_LABEL: Y: 45 Width: PARENT_RIGHT diff --git a/mods/ra/chrome/musicplayer.yaml b/mods/ra/chrome/musicplayer.yaml index 474b41b11b..04a29cd8cc 100644 --- a/mods/ra/chrome/musicplayer.yaml +++ b/mods/ra/chrome/musicplayer.yaml @@ -165,6 +165,12 @@ Background@MUSIC_PANEL: Text: Close Font: Bold Key: escape + Label@MUTE_LABEL: + X: 25 + Y: PARENT_BOTTOM - 45 + Width: 300 + Height: 20 + Font: Small Background@INSTALL_MUSIC_PANEL: Logic: InstallMusicLogic diff --git a/mods/ra/chrome/settings.yaml b/mods/ra/chrome/settings.yaml index 91a804e930..f495390ac9 100644 --- a/mods/ra/chrome/settings.yaml +++ b/mods/ra/chrome/settings.yaml @@ -277,6 +277,13 @@ Background@SETTINGS_PANEL: Height: 20 Font: Regular Text: Cash Ticks + Checkbox@MUTE_SOUND: + X: 15 + Y: 70 + Width: 200 + Height: 20 + Font: Regular + Text: Mute Sound Label@MUSIC_LABEL: X: PARENT_RIGHT - WIDTH - 270 Y: 67