Merge pull request #11136 from SzabKel/musicButtons

Added music controlling hotkeys. Closes #3231
This commit is contained in:
Matthias Mailänder
2016-05-03 07:16:05 +02:00
12 changed files with 127 additions and 1 deletions

View File

@@ -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<KeySettings, Hotkey>[] ProductionKeys = GetKeys(24, "Production");
static readonly Func<KeySettings, Hotkey>[] SupportPowerKeys = GetKeys(6, "SupportPower");

View File

@@ -540,6 +540,7 @@
<Compile Include="UtilityCommands\ExtractLanguageStringsCommand.cs" />
<Compile Include="UtilityCommands\ExtractLuaDocsCommand.cs" />
<Compile Include="UtilityCommands\ExtractTraitDocsCommand.cs" />
<Compile Include="Widgets\Logic\Ingame\MusicControllerLogic.cs" />
<Compile Include="WorldExtensions.cs" />
<Compile Include="UtilityCommands\GetMapHashCommand.cs" />
<Compile Include="UtilityCommands\Glob.cs" />
@@ -754,4 +755,4 @@ cd "$(SolutionDir)"</PostBuildEvent>
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

View File

@@ -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<MusicPlaylist>();
var keyhandler = widget.Get<LogicKeyListenerWidget>("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());
}
}
}

View File

@@ -560,6 +560,24 @@ namespace OpenRA.Mods.Common.Widgets.Logic
BindHotkeyPref(kv, ks, developerTemplate, hotkeyList);
}
// Music
{
var hotkeys = new Dictionary<string, string>()
{
{ "NextTrack", "Next" },
{ "PreviousTrack", "Previous" },
{ "StopMusic", "Stop" },
{ "PauseMusic", "Pause or Resume" }
};
var header = ScrollItemWidget.Setup(hotkeyHeader, returnTrue, doNothing);
header.Get<LabelWidget>("LABEL").GetText = () => "Music commands";
hotkeyList.AddChild(header);
foreach (var kv in hotkeys)
BindHotkeyPref(kv, ks, developerTemplate, hotkeyList);
}
return () => { };
}

View File

@@ -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

View File

@@ -1,6 +1,10 @@
Container@INGAME_ROOT:
Logic: LoadIngamePlayerOrObserverUILogic
Children:
Container@MUSICBUTTONS:
Logic: MusicControllerLogic
Children:
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
Container@WORLD_ROOT:
Logic: LoadIngamePerfLogic
Children:

View File

@@ -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:

View File

@@ -1,6 +1,10 @@
Container@INGAME_ROOT:
Logic: LoadIngamePlayerOrObserverUILogic
Children:
Container@MUSICBUTTONS:
Logic: MusicControllerLogic
Children:
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
Container@WORLD_ROOT:
Logic: LoadIngamePerfLogic
Children:

View File

@@ -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

View File

@@ -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

View File

@@ -1,6 +1,10 @@
Container@INGAME_ROOT:
Logic: LoadIngamePlayerOrObserverUILogic
Children:
Container@MUSICBUTTONS:
Logic: MusicControllerLogic
Children:
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
Container@WORLD_ROOT:
Logic: LoadIngamePerfLogic
Children:

View File

@@ -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