diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index 5e1109e49e..bf12668f18 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -284,6 +284,11 @@ 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); + static readonly Func[] ProductionKeys = GetKeys(24, "Production"); static readonly Func[] SupportPowerKeys = GetKeys(6, "SupportPower"); diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index c004e194d3..5425c97e9c 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -541,6 +541,7 @@ + @@ -754,4 +755,4 @@ cd "$(SolutionDir)" --> - + \ No newline at end of file diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/MusicControllerLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/MusicControllerLogic.cs new file mode 100644 index 0000000000..2d52435826 --- /dev/null +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/MusicControllerLogic.cs @@ -0,0 +1,70 @@ +#region Copyright & License Information +/* + * Copyright 2007-2016 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.Linq; +using OpenRA.GameRules; +using OpenRA.Graphics; +using OpenRA.Mods.Common.Traits; +using OpenRA.Widgets; + +namespace OpenRA.Mods.Common.Widgets.Logic.Ingame +{ + public class MusicControllerLogic : ChromeLogic + { + MusicPlaylist musicPlaylist; + + [ObjectCreator.UseCtor] + public MusicControllerLogic(Widget widget, World world, WorldRenderer worldRenderer) + { + musicPlaylist = world.WorldActor.Trait(); + + var keyhandler = widget.Get("MUSICCONTROLLER_KEYHANDLER"); + keyhandler.OnKeyPress = e => + { + if (e.Event == KeyInputEvent.Down) + { + var key = Hotkey.FromKeyInput(e); + + if (key == Game.Settings.Keys.NextTrack) + musicPlaylist.Play(musicPlaylist.GetNextSong()); + else if (key == Game.Settings.Keys.PreviousTrack) + musicPlaylist.Play(musicPlaylist.GetPrevSong()); + else if (key == Game.Settings.Keys.StopMusic) + StopMusic(); + else if (key == Game.Settings.Keys.PauseMusic) + PauseOrResumeMusic(); + } + + return false; + }; + } + + void PauseOrResumeMusic() + { + if (Game.Sound.MusicPlaying) + Game.Sound.PauseMusic(); + else if (Game.Sound.CurrentMusic != null) + Game.Sound.PlayMusic(); + else + { + musicPlaylist.Play(musicPlaylist.GetNextSong()); + } + } + + void StopMusic() + { + if (!musicPlaylist.CurrentSongIsBackground) + musicPlaylist.Stop(); + else + musicPlaylist.Play(musicPlaylist.GetNextSong()); + } + } +} diff --git a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs index b12b650657..fb9b5fef22 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs @@ -560,6 +560,24 @@ namespace OpenRA.Mods.Common.Widgets.Logic BindHotkeyPref(kv, ks, developerTemplate, hotkeyList); } + // Music + { + var hotkeys = new Dictionary() + { + { "NextTrack", "Next" }, + { "PreviousTrack", "Previous" }, + { "StopMusic", "Stop" }, + { "PauseMusic", "Pause or Resume" } + }; + + var header = ScrollItemWidget.Setup(hotkeyHeader, returnTrue, doNothing); + header.Get("LABEL").GetText = () => "Music commands"; + hotkeyList.AddChild(header); + + foreach (var kv in hotkeys) + BindHotkeyPref(kv, ks, developerTemplate, hotkeyList); + } + return () => { }; } diff --git a/mods/cnc/chrome/editor.yaml b/mods/cnc/chrome/editor.yaml index 4b4738fc74..f1d1860929 100644 --- a/mods/cnc/chrome/editor.yaml +++ b/mods/cnc/chrome/editor.yaml @@ -5,6 +5,10 @@ Container@NEW_MAP_BG: Width: 300 Height: 125 Children: + Container@MUSICBUTTONS: + Logic: MusicControllerLogic + Children: + LogicKeyListener@MUSICCONTROLLER_KEYHANDLER: Label@TITLE: Text: New Map Width: PARENT_RIGHT diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index e173cc7dfb..c3852451dd 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -1,6 +1,10 @@ Container@INGAME_ROOT: Logic: LoadIngamePlayerOrObserverUILogic Children: + Container@MUSICBUTTONS: + Logic: MusicControllerLogic + Children: + LogicKeyListener@MUSICCONTROLLER_KEYHANDLER: Container@WORLD_ROOT: Logic: LoadIngamePerfLogic Children: diff --git a/mods/cnc/chrome/mainmenu.yaml b/mods/cnc/chrome/mainmenu.yaml index 8595450618..93384c2d8d 100644 --- a/mods/cnc/chrome/mainmenu.yaml +++ b/mods/cnc/chrome/mainmenu.yaml @@ -3,6 +3,10 @@ Container@MENU_BACKGROUND: Height: WINDOW_BOTTOM Logic: CncMainMenuLogic Children: + Container@MUSICBUTTONS: + Logic: MusicControllerLogic + Children: + LogicKeyListener@MUSICCONTROLLER_KEYHANDLER: Container@SHELLMAP_DECORATIONS: Children: Image@RETICLE: diff --git a/mods/d2k/chrome/ingame.yaml b/mods/d2k/chrome/ingame.yaml index c21ab956ef..a21b9fe428 100644 --- a/mods/d2k/chrome/ingame.yaml +++ b/mods/d2k/chrome/ingame.yaml @@ -1,6 +1,10 @@ Container@INGAME_ROOT: Logic: LoadIngamePlayerOrObserverUILogic Children: + Container@MUSICBUTTONS: + Logic: MusicControllerLogic + Children: + LogicKeyListener@MUSICCONTROLLER_KEYHANDLER: Container@WORLD_ROOT: Logic: LoadIngamePerfLogic Children: diff --git a/mods/d2k/chrome/mainmenu.yaml b/mods/d2k/chrome/mainmenu.yaml index e1bd9fb749..6e86cae007 100644 --- a/mods/d2k/chrome/mainmenu.yaml +++ b/mods/d2k/chrome/mainmenu.yaml @@ -1,6 +1,10 @@ Container@MAINMENU: Logic: MainMenuLogic Children: + Container@MUSICBUTTONS: + Logic: MusicControllerLogic + Children: + LogicKeyListener@MUSICCONTROLLER_KEYHANDLER: Label@VERSION_LABEL: X: WINDOW_RIGHT - 10 Y: WINDOW_BOTTOM - 20 diff --git a/mods/ra/chrome/editor.yaml b/mods/ra/chrome/editor.yaml index 025f7a912e..5fc11872cc 100644 --- a/mods/ra/chrome/editor.yaml +++ b/mods/ra/chrome/editor.yaml @@ -5,6 +5,10 @@ Background@NEW_MAP_BG: Width: 300 Height: 185 Children: + Container@MUSICBUTTONS: + Logic: MusicControllerLogic + Children: + LogicKeyListener@MUSICCONTROLLER_KEYHANDLER: Label@LABEL_TITLE: X: 0 Y: 20 diff --git a/mods/ra/chrome/ingame.yaml b/mods/ra/chrome/ingame.yaml index c21ab956ef..a21b9fe428 100644 --- a/mods/ra/chrome/ingame.yaml +++ b/mods/ra/chrome/ingame.yaml @@ -1,6 +1,10 @@ Container@INGAME_ROOT: Logic: LoadIngamePlayerOrObserverUILogic Children: + Container@MUSICBUTTONS: + Logic: MusicControllerLogic + Children: + LogicKeyListener@MUSICCONTROLLER_KEYHANDLER: Container@WORLD_ROOT: Logic: LoadIngamePerfLogic Children: diff --git a/mods/ra/chrome/mainmenu.yaml b/mods/ra/chrome/mainmenu.yaml index 66ea1fcd87..157a0ec82f 100644 --- a/mods/ra/chrome/mainmenu.yaml +++ b/mods/ra/chrome/mainmenu.yaml @@ -1,6 +1,10 @@ Container@MAINMENU: Logic: MainMenuLogic Children: + Container@MUSICBUTTONS: + Logic: MusicControllerLogic + Children: + LogicKeyListener@MUSICCONTROLLER_KEYHANDLER: Background@BORDER: Background: mainmenu-border X: 0 - 15