Unhardcode music control hotkeys.

This commit is contained in:
Paul Chote
2017-07-23 17:51:07 +00:00
committed by reaperrr
parent 8d4ffee32a
commit 9a5b5d9b6f
10 changed files with 65 additions and 15 deletions

View File

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

View File

@@ -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<string, MiniYaml> logicArgs)
{
musicPlaylist = world.WorldActor.Trait<MusicPlaylist>();
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<LogicKeyListenerWidget>("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();
}

View File

@@ -610,10 +610,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
var hotkeys = new Dictionary<string, string>()
{
{ "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);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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