Added MusicControllerLogic, now we can handle audio buttons anywhere in the game.
This commit is contained in:
@@ -284,6 +284,11 @@ namespace OpenRA
|
|||||||
public Hotkey ReplaySpeedFastKey = new Hotkey(Keycode.F7, Modifiers.None);
|
public Hotkey ReplaySpeedFastKey = new Hotkey(Keycode.F7, Modifiers.None);
|
||||||
public Hotkey ReplaySpeedMaxKey = new Hotkey(Keycode.F8, 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>[] ProductionKeys = GetKeys(24, "Production");
|
||||||
static readonly Func<KeySettings, Hotkey>[] SupportPowerKeys = GetKeys(6, "SupportPower");
|
static readonly Func<KeySettings, Hotkey>[] SupportPowerKeys = GetKeys(6, "SupportPower");
|
||||||
|
|
||||||
|
|||||||
@@ -541,6 +541,7 @@
|
|||||||
<Compile Include="UtilityCommands\ExtractLanguageStringsCommand.cs" />
|
<Compile Include="UtilityCommands\ExtractLanguageStringsCommand.cs" />
|
||||||
<Compile Include="UtilityCommands\ExtractLuaDocsCommand.cs" />
|
<Compile Include="UtilityCommands\ExtractLuaDocsCommand.cs" />
|
||||||
<Compile Include="UtilityCommands\ExtractTraitDocsCommand.cs" />
|
<Compile Include="UtilityCommands\ExtractTraitDocsCommand.cs" />
|
||||||
|
<Compile Include="Widgets\Logic\Ingame\MusicControllerLogic.cs" />
|
||||||
<Compile Include="WorldExtensions.cs" />
|
<Compile Include="WorldExtensions.cs" />
|
||||||
<Compile Include="UtilityCommands\GetMapHashCommand.cs" />
|
<Compile Include="UtilityCommands\GetMapHashCommand.cs" />
|
||||||
<Compile Include="UtilityCommands\Glob.cs" />
|
<Compile Include="UtilityCommands\Glob.cs" />
|
||||||
@@ -754,4 +755,4 @@ cd "$(SolutionDir)"</PostBuildEvent>
|
|||||||
<Target Name="AfterBuild">
|
<Target Name="AfterBuild">
|
||||||
</Target>
|
</Target>
|
||||||
-->
|
-->
|
||||||
</Project>
|
</Project>
|
||||||
@@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -560,6 +560,24 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
BindHotkeyPref(kv, ks, developerTemplate, hotkeyList);
|
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 () => { };
|
return () => { };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ Container@NEW_MAP_BG:
|
|||||||
Width: 300
|
Width: 300
|
||||||
Height: 125
|
Height: 125
|
||||||
Children:
|
Children:
|
||||||
|
Container@MUSICBUTTONS:
|
||||||
|
Logic: MusicControllerLogic
|
||||||
|
Children:
|
||||||
|
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
|
||||||
Label@TITLE:
|
Label@TITLE:
|
||||||
Text: New Map
|
Text: New Map
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
Container@INGAME_ROOT:
|
Container@INGAME_ROOT:
|
||||||
Logic: LoadIngamePlayerOrObserverUILogic
|
Logic: LoadIngamePlayerOrObserverUILogic
|
||||||
Children:
|
Children:
|
||||||
|
Container@MUSICBUTTONS:
|
||||||
|
Logic: MusicControllerLogic
|
||||||
|
Children:
|
||||||
|
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
|
||||||
Container@WORLD_ROOT:
|
Container@WORLD_ROOT:
|
||||||
Logic: LoadIngamePerfLogic
|
Logic: LoadIngamePerfLogic
|
||||||
Children:
|
Children:
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ Container@MENU_BACKGROUND:
|
|||||||
Height: WINDOW_BOTTOM
|
Height: WINDOW_BOTTOM
|
||||||
Logic: CncMainMenuLogic
|
Logic: CncMainMenuLogic
|
||||||
Children:
|
Children:
|
||||||
|
Container@MUSICBUTTONS:
|
||||||
|
Logic: MusicControllerLogic
|
||||||
|
Children:
|
||||||
|
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
|
||||||
Container@SHELLMAP_DECORATIONS:
|
Container@SHELLMAP_DECORATIONS:
|
||||||
Children:
|
Children:
|
||||||
Image@RETICLE:
|
Image@RETICLE:
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
Container@INGAME_ROOT:
|
Container@INGAME_ROOT:
|
||||||
Logic: LoadIngamePlayerOrObserverUILogic
|
Logic: LoadIngamePlayerOrObserverUILogic
|
||||||
Children:
|
Children:
|
||||||
|
Container@MUSICBUTTONS:
|
||||||
|
Logic: MusicControllerLogic
|
||||||
|
Children:
|
||||||
|
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
|
||||||
Container@WORLD_ROOT:
|
Container@WORLD_ROOT:
|
||||||
Logic: LoadIngamePerfLogic
|
Logic: LoadIngamePerfLogic
|
||||||
Children:
|
Children:
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
Container@MAINMENU:
|
Container@MAINMENU:
|
||||||
Logic: MainMenuLogic
|
Logic: MainMenuLogic
|
||||||
Children:
|
Children:
|
||||||
|
Container@MUSICBUTTONS:
|
||||||
|
Logic: MusicControllerLogic
|
||||||
|
Children:
|
||||||
|
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
|
||||||
Label@VERSION_LABEL:
|
Label@VERSION_LABEL:
|
||||||
X: WINDOW_RIGHT - 10
|
X: WINDOW_RIGHT - 10
|
||||||
Y: WINDOW_BOTTOM - 20
|
Y: WINDOW_BOTTOM - 20
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ Background@NEW_MAP_BG:
|
|||||||
Width: 300
|
Width: 300
|
||||||
Height: 185
|
Height: 185
|
||||||
Children:
|
Children:
|
||||||
|
Container@MUSICBUTTONS:
|
||||||
|
Logic: MusicControllerLogic
|
||||||
|
Children:
|
||||||
|
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
|
||||||
Label@LABEL_TITLE:
|
Label@LABEL_TITLE:
|
||||||
X: 0
|
X: 0
|
||||||
Y: 20
|
Y: 20
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
Container@INGAME_ROOT:
|
Container@INGAME_ROOT:
|
||||||
Logic: LoadIngamePlayerOrObserverUILogic
|
Logic: LoadIngamePlayerOrObserverUILogic
|
||||||
Children:
|
Children:
|
||||||
|
Container@MUSICBUTTONS:
|
||||||
|
Logic: MusicControllerLogic
|
||||||
|
Children:
|
||||||
|
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
|
||||||
Container@WORLD_ROOT:
|
Container@WORLD_ROOT:
|
||||||
Logic: LoadIngamePerfLogic
|
Logic: LoadIngamePerfLogic
|
||||||
Children:
|
Children:
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
Container@MAINMENU:
|
Container@MAINMENU:
|
||||||
Logic: MainMenuLogic
|
Logic: MainMenuLogic
|
||||||
Children:
|
Children:
|
||||||
|
Container@MUSICBUTTONS:
|
||||||
|
Logic: MusicControllerLogic
|
||||||
|
Children:
|
||||||
|
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
|
||||||
Background@BORDER:
|
Background@BORDER:
|
||||||
Background: mainmenu-border
|
Background: mainmenu-border
|
||||||
X: 0 - 15
|
X: 0 - 15
|
||||||
|
|||||||
Reference in New Issue
Block a user