diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index a7bfc55d4f..43de252fa4 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -823,6 +823,7 @@ + diff --git a/OpenRA.Mods.Common/Widgets/Logic/MuteHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MuteHotkeyLogic.cs new file mode 100644 index 0000000000..b8cf1dce9f --- /dev/null +++ b/OpenRA.Mods.Common/Widgets/Logic/MuteHotkeyLogic.cs @@ -0,0 +1,44 @@ +#region Copyright & License Information +/* + * Copyright 2007-2017 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System.Collections.Generic; +using System.Drawing; +using OpenRA.Mods.Common.Lint; +using OpenRA.Widgets; + +namespace OpenRA.Mods.Common.Widgets.Logic +{ + [ChromeLogicArgsHotkeys("MuteAudioKey")] + public class MuteHotkeyLogic : SingleHotkeyBaseLogic + { + [ObjectCreator.UseCtor] + public MuteHotkeyLogic(Widget widget, Dictionary logicArgs) + : base(widget, "MuteAudioKey", "GLOBAL_KEYHANDLER", logicArgs) { } + + protected override bool OnHotkeyActivated(KeyInput e) + { + Game.Settings.Sound.Mute ^= true; + + if (Game.Settings.Sound.Mute) + { + Game.Sound.MuteAudio(); + Game.AddChatLine(Color.White, "Battlefield Control", "Audio muted"); + } + else + { + Game.Sound.UnmuteAudio(); + Game.AddChatLine(Color.White, "Battlefield Control", "Audio unmuted"); + } + + return true; + } + } +} diff --git a/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs index 71691fae1b..4c74f24425 100644 --- a/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs @@ -292,8 +292,6 @@ namespace OpenRA.Mods.Common.Widgets return CycleStatusBars(); else if (key == Game.Settings.Keys.TogglePixelDoubleKey) return TogglePixelDouble(); - else if (key == Game.Settings.Keys.ToggleMuteKey) - return ToggleMute(); else if (key == Game.Settings.Keys.TogglePlayerStanceColorsKey) return TogglePlayerStanceColors(); } @@ -364,24 +362,6 @@ namespace OpenRA.Mods.Common.Widgets return true; } - bool ToggleMute() - { - Game.Settings.Sound.Mute ^= true; - - if (Game.Settings.Sound.Mute) - { - Game.Sound.MuteAudio(); - Game.AddChatLine(Color.White, "Battlefield Control", "Audio muted"); - } - else - { - Game.Sound.UnmuteAudio(); - Game.AddChatLine(Color.White, "Battlefield Control", "Audio unmuted"); - } - - return true; - } - bool TogglePlayerStanceColors() { Game.Settings.Game.UsePlayerStanceColors ^= true; diff --git a/mods/cnc/chrome/editor.yaml b/mods/cnc/chrome/editor.yaml index 7643fd2fc8..949d963b6d 100644 --- a/mods/cnc/chrome/editor.yaml +++ b/mods/cnc/chrome/editor.yaml @@ -192,12 +192,13 @@ Container@EDITOR_ROOT: Logic: LoadMapEditorLogic Children: LogicKeyListener@GLOBAL_KEYHANDLER: - Logic: MusicHotkeyLogic, ScreenshotHotkeyLogic + Logic: MusicHotkeyLogic, ScreenshotHotkeyLogic, MuteHotkeyLogic StopMusicKey: StopMusic PauseMusicKey: PauseMusic PrevMusicKey: PrevMusic NextMusicKey: NextMusic TakeScreenshotKey: TakeScreenshot + MuteAudioKey: ToggleMute Container@WORLD_ROOT: Container@MENU_ROOT: TooltipContainer@TOOLTIP_CONTAINER: diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index 0936109ddb..f185bbd44f 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -2,12 +2,13 @@ Container@INGAME_ROOT: Logic: LoadIngamePlayerOrObserverUILogic Children: LogicKeyListener@GLOBAL_KEYHANDLER: - Logic: MusicHotkeyLogic, ScreenshotHotkeyLogic + Logic: MusicHotkeyLogic, ScreenshotHotkeyLogic, MuteHotkeyLogic StopMusicKey: StopMusic PauseMusicKey: PauseMusic PrevMusicKey: PrevMusic NextMusicKey: NextMusic TakeScreenshotKey: TakeScreenshot + MuteAudioKey: ToggleMute Container@WORLD_ROOT: Logic: LoadIngamePerfLogic Children: diff --git a/mods/cnc/chrome/mainmenu.yaml b/mods/cnc/chrome/mainmenu.yaml index ebc27d985a..8a471e5f8e 100644 --- a/mods/cnc/chrome/mainmenu.yaml +++ b/mods/cnc/chrome/mainmenu.yaml @@ -4,12 +4,13 @@ Container@MENU_BACKGROUND: Logic: MainMenuLogic Children: LogicKeyListener@GLOBAL_KEYHANDLER: - Logic: MusicHotkeyLogic, ScreenshotHotkeyLogic + Logic: MusicHotkeyLogic, ScreenshotHotkeyLogic, MuteHotkeyLogic StopMusicKey: StopMusic PauseMusicKey: PauseMusic PrevMusicKey: PrevMusic NextMusicKey: NextMusic TakeScreenshotKey: TakeScreenshot + MuteAudioKey: ToggleMute Container@SHELLMAP_DECORATIONS: Children: Image@NOD: diff --git a/mods/common/chrome/editor.yaml b/mods/common/chrome/editor.yaml index aeec45fb92..d8788c83c3 100644 --- a/mods/common/chrome/editor.yaml +++ b/mods/common/chrome/editor.yaml @@ -183,12 +183,13 @@ Container@EDITOR_ROOT: Logic: LoadMapEditorLogic Children: LogicKeyListener@GLOBAL_KEYHANDLER: - Logic: MusicHotkeyLogic, ScreenshotHotkeyLogic + Logic: MusicHotkeyLogic, ScreenshotHotkeyLogic, MuteHotkeyLogic StopMusicKey: StopMusic PauseMusicKey: PauseMusic PrevMusicKey: PrevMusic NextMusicKey: NextMusic TakeScreenshotKey: TakeScreenshot + MuteAudioKey: ToggleMute Container@WORLD_ROOT: Container@MENU_ROOT: TooltipContainer@TOOLTIP_CONTAINER: diff --git a/mods/common/chrome/ingame.yaml b/mods/common/chrome/ingame.yaml index 2df8e40c6b..eee5a75ee7 100644 --- a/mods/common/chrome/ingame.yaml +++ b/mods/common/chrome/ingame.yaml @@ -2,12 +2,13 @@ Container@INGAME_ROOT: Logic: LoadIngamePlayerOrObserverUILogic Children: LogicKeyListener@GLOBAL_KEYHANDLER: - Logic: MusicHotkeyLogic, ScreenshotHotkeyLogic + Logic: MusicHotkeyLogic, ScreenshotHotkeyLogic, MuteHotkeyLogic StopMusicKey: StopMusic PauseMusicKey: PauseMusic PrevMusicKey: PrevMusic NextMusicKey: NextMusic TakeScreenshotKey: TakeScreenshot + MuteAudioKey: ToggleMute Container@WORLD_ROOT: Logic: LoadIngamePerfLogic Children: diff --git a/mods/common/chrome/mainmenu.yaml b/mods/common/chrome/mainmenu.yaml index 42e9967d2a..0e6c992ce4 100644 --- a/mods/common/chrome/mainmenu.yaml +++ b/mods/common/chrome/mainmenu.yaml @@ -2,12 +2,13 @@ Container@MAINMENU: Logic: MainMenuLogic Children: LogicKeyListener@GLOBAL_KEYHANDLER: - Logic: MusicHotkeyLogic, ScreenshotHotkeyLogic + Logic: MusicHotkeyLogic, ScreenshotHotkeyLogic, MuteHotkeyLogic StopMusicKey: StopMusic PauseMusicKey: PauseMusic PrevMusicKey: PrevMusic NextMusicKey: NextMusic TakeScreenshotKey: TakeScreenshot + MuteAudioKey: ToggleMute Background@BORDER: Background: mainmenu-border X: 0 - 15 diff --git a/mods/d2k/chrome/mainmenu.yaml b/mods/d2k/chrome/mainmenu.yaml index 8829b3b73e..3d015b2b8a 100644 --- a/mods/d2k/chrome/mainmenu.yaml +++ b/mods/d2k/chrome/mainmenu.yaml @@ -2,12 +2,13 @@ Container@MAINMENU: Logic: MainMenuLogic Children: LogicKeyListener@GLOBAL_KEYHANDLER: - Logic: MusicHotkeyLogic, ScreenshotHotkeyLogic + Logic: MusicHotkeyLogic, ScreenshotHotkeyLogic, MuteHotkeyLogic StopMusicKey: StopMusic PauseMusicKey: PauseMusic PrevMusicKey: PrevMusic NextMusicKey: NextMusic TakeScreenshotKey: TakeScreenshot + MuteAudioKey: ToggleMute Label@VERSION_LABEL: X: WINDOW_RIGHT - 10 Y: WINDOW_BOTTOM - 20