From 9a5b5d9b6f03e7881090abb7795181b4ea9fc043 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 23 Jul 2017 17:51:07 +0000 Subject: [PATCH] Unhardcode music control hotkeys. --- OpenRA.Game/Settings.cs | 8 ++--- .../Logic/Ingame/MusicControllerLogic.cs | 36 +++++++++++++++---- .../Widgets/Logic/SettingsLogic.cs | 8 ++--- mods/cnc/chrome/editor.yaml | 4 +++ mods/cnc/chrome/ingame.yaml | 4 +++ mods/cnc/chrome/mainmenu.yaml | 4 +++ mods/common/chrome/editor.yaml | 4 +++ mods/common/chrome/ingame.yaml | 4 +++ mods/common/chrome/mainmenu.yaml | 4 +++ mods/d2k/chrome/mainmenu.yaml | 4 +++ 10 files changed, 65 insertions(+), 15 deletions(-) diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index 4dc9a15a1d..d243049743 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -292,10 +292,10 @@ namespace OpenRA public Hotkey ReplaySpeedFastKey = new Hotkey(Keycode.F7, Modifiers.None); public Hotkey ReplaySpeedMaxKey = new Hotkey(Keycode.F8, Modifiers.None); - public Hotkey NextTrack = new Hotkey(Keycode.AUDIONEXT, Modifiers.None); - public Hotkey PreviousTrack = new Hotkey(Keycode.AUDIOPREV, Modifiers.None); - public Hotkey StopMusic = new Hotkey(Keycode.AUDIOSTOP, Modifiers.None); - public Hotkey PauseMusic = new Hotkey(Keycode.AUDIOPLAY, Modifiers.None); + public Hotkey StopMusicKey = new Hotkey(Keycode.AUDIOSTOP, Modifiers.None); + public Hotkey PauseMusicKey = new Hotkey(Keycode.AUDIOPLAY, Modifiers.None); + public Hotkey PrevMusicKey = new Hotkey(Keycode.AUDIOPREV, Modifiers.None); + public Hotkey NextMusicKey = new Hotkey(Keycode.AUDIONEXT, Modifiers.None); static readonly Func[] ProductionKeys = GetKeys(24, "Production"); static readonly Func[] SupportPowerKeys = GetKeys(6, "SupportPower"); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/MusicControllerLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/MusicControllerLogic.cs index 9a7a9f464e..cd850e40da 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/MusicControllerLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/MusicControllerLogic.cs @@ -9,23 +9,45 @@ */ #endregion +using System.Collections.Generic; using System.Linq; using OpenRA.GameRules; using OpenRA.Graphics; +using OpenRA.Mods.Common.Lint; using OpenRA.Mods.Common.Traits; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets.Logic.Ingame { + [ChromeLogicArgsHotkeys("StopMusicKey", "PauseMusicKey", "PrevMusicKey", "NextMusicKey")] public class MusicControllerLogic : ChromeLogic - { - MusicPlaylist musicPlaylist; + { + readonly MusicPlaylist musicPlaylist; [ObjectCreator.UseCtor] - public MusicControllerLogic(Widget widget, World world, WorldRenderer worldRenderer) + public MusicControllerLogic(Widget widget, World world, Dictionary logicArgs) { musicPlaylist = world.WorldActor.Trait(); + var ks = Game.Settings.Keys; + MiniYaml yaml; + + var stopKey = new NamedHotkey(); + if (logicArgs.TryGetValue("StopMusicKey", out yaml)) + stopKey = new NamedHotkey(yaml.Value, ks); + + var pauseKey = new NamedHotkey(); + if (logicArgs.TryGetValue("PauseMusicKey", out yaml)) + pauseKey = new NamedHotkey(yaml.Value, ks); + + var prevKey = new NamedHotkey(); + if (logicArgs.TryGetValue("PrevMusicKey", out yaml)) + prevKey = new NamedHotkey(yaml.Value, ks); + + var nextKey = new NamedHotkey(); + if (logicArgs.TryGetValue("NextMusicKey", out yaml)) + nextKey = new NamedHotkey(yaml.Value, ks); + var keyhandler = widget.Get("MUSICCONTROLLER_KEYHANDLER"); keyhandler.OnKeyPress = e => { @@ -33,13 +55,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame { var key = Hotkey.FromKeyInput(e); - if (key == Game.Settings.Keys.NextTrack) + if (key == nextKey.GetValue()) musicPlaylist.Play(musicPlaylist.GetNextSong()); - else if (key == Game.Settings.Keys.PreviousTrack) + else if (key == prevKey.GetValue()) musicPlaylist.Play(musicPlaylist.GetPrevSong()); - else if (key == Game.Settings.Keys.StopMusic) + else if (key == stopKey.GetValue()) StopMusic(); - else if (key == Game.Settings.Keys.PauseMusic) + else if (key == pauseKey.GetValue()) PauseOrResumeMusic(); } diff --git a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs index 0a4d114847..7bacac9441 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs @@ -610,10 +610,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic { var hotkeys = new Dictionary() { - { "NextTrack", "Next" }, - { "PreviousTrack", "Previous" }, - { "StopMusic", "Stop" }, - { "PauseMusic", "Pause or Resume" } + { "StopMusicKey", "Stop" }, + { "PauseMusicKey", "Pause or Resume" }, + { "PrevMusicKey", "Previous" }, + { "NextMusicKey", "Next" } }; var header = ScrollItemWidget.Setup(hotkeyHeader, returnTrue, doNothing); diff --git a/mods/cnc/chrome/editor.yaml b/mods/cnc/chrome/editor.yaml index 9709fa58cf..2e22df6c1e 100644 --- a/mods/cnc/chrome/editor.yaml +++ b/mods/cnc/chrome/editor.yaml @@ -7,6 +7,10 @@ Container@NEW_MAP_BG: Children: Container@MUSICBUTTONS: Logic: MusicControllerLogic + StopMusicKey: StopMusic + PauseMusicKey: PauseMusic + PrevMusicKey: PrevMusic + NextMusicKey: NextMusic Children: LogicKeyListener@MUSICCONTROLLER_KEYHANDLER: Label@TITLE: diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index 91582160a5..cd484acf63 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -3,6 +3,10 @@ Container@INGAME_ROOT: Children: Container@MUSICBUTTONS: Logic: MusicControllerLogic + StopMusicKey: StopMusic + PauseMusicKey: PauseMusic + PrevMusicKey: PrevMusic + NextMusicKey: NextMusic Children: LogicKeyListener@MUSICCONTROLLER_KEYHANDLER: Container@WORLD_ROOT: diff --git a/mods/cnc/chrome/mainmenu.yaml b/mods/cnc/chrome/mainmenu.yaml index 447aa2c676..864c2f0329 100644 --- a/mods/cnc/chrome/mainmenu.yaml +++ b/mods/cnc/chrome/mainmenu.yaml @@ -5,6 +5,10 @@ Container@MENU_BACKGROUND: Children: Container@MUSICBUTTONS: Logic: MusicControllerLogic + StopMusicKey: StopMusic + PauseMusicKey: PauseMusic + PrevMusicKey: PrevMusic + NextMusicKey: NextMusic Children: LogicKeyListener@MUSICCONTROLLER_KEYHANDLER: Container@SHELLMAP_DECORATIONS: diff --git a/mods/common/chrome/editor.yaml b/mods/common/chrome/editor.yaml index b209839d19..e221aca548 100644 --- a/mods/common/chrome/editor.yaml +++ b/mods/common/chrome/editor.yaml @@ -7,6 +7,10 @@ Background@NEW_MAP_BG: Children: Container@MUSICBUTTONS: Logic: MusicControllerLogic + StopMusicKey: StopMusic + PauseMusicKey: PauseMusic + PrevMusicKey: PrevMusic + NextMusicKey: NextMusic Children: LogicKeyListener@MUSICCONTROLLER_KEYHANDLER: Label@LABEL_TITLE: diff --git a/mods/common/chrome/ingame.yaml b/mods/common/chrome/ingame.yaml index 6f1ef76998..41e3309c37 100644 --- a/mods/common/chrome/ingame.yaml +++ b/mods/common/chrome/ingame.yaml @@ -3,6 +3,10 @@ Container@INGAME_ROOT: Children: Container@MUSICBUTTONS: Logic: MusicControllerLogic + StopMusicKey: StopMusic + PauseMusicKey: PauseMusic + PrevMusicKey: PrevMusic + NextMusicKey: NextMusic Children: LogicKeyListener@MUSICCONTROLLER_KEYHANDLER: Container@WORLD_ROOT: diff --git a/mods/common/chrome/mainmenu.yaml b/mods/common/chrome/mainmenu.yaml index bb496e53aa..1fdc23af25 100644 --- a/mods/common/chrome/mainmenu.yaml +++ b/mods/common/chrome/mainmenu.yaml @@ -3,6 +3,10 @@ Container@MAINMENU: Children: Container@MUSICBUTTONS: Logic: MusicControllerLogic + StopMusicKey: StopMusic + PauseMusicKey: PauseMusic + PrevMusicKey: PrevMusic + NextMusicKey: NextMusic Children: LogicKeyListener@MUSICCONTROLLER_KEYHANDLER: Background@BORDER: diff --git a/mods/d2k/chrome/mainmenu.yaml b/mods/d2k/chrome/mainmenu.yaml index f1ff3c6bc8..c122d02d91 100644 --- a/mods/d2k/chrome/mainmenu.yaml +++ b/mods/d2k/chrome/mainmenu.yaml @@ -3,6 +3,10 @@ Container@MAINMENU: Children: Container@MUSICBUTTONS: Logic: MusicControllerLogic + StopMusicKey: StopMusic + PauseMusicKey: PauseMusic + PrevMusicKey: PrevMusic + NextMusicKey: NextMusic Children: LogicKeyListener@MUSICCONTROLLER_KEYHANDLER: Label@VERSION_LABEL: