Unhardcode music control hotkeys.
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user