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 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 StopMusicKey = new Hotkey(Keycode.AUDIOSTOP, Modifiers.None);
|
||||||
public Hotkey PreviousTrack = new Hotkey(Keycode.AUDIOPREV, Modifiers.None);
|
public Hotkey PauseMusicKey = new Hotkey(Keycode.AUDIOPLAY, Modifiers.None);
|
||||||
public Hotkey StopMusic = new Hotkey(Keycode.AUDIOSTOP, Modifiers.None);
|
public Hotkey PrevMusicKey = new Hotkey(Keycode.AUDIOPREV, Modifiers.None);
|
||||||
public Hotkey PauseMusic = new Hotkey(Keycode.AUDIOPLAY, 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>[] ProductionKeys = GetKeys(24, "Production");
|
||||||
static readonly Func<KeySettings, Hotkey>[] SupportPowerKeys = GetKeys(6, "SupportPower");
|
static readonly Func<KeySettings, Hotkey>[] SupportPowerKeys = GetKeys(6, "SupportPower");
|
||||||
|
|||||||
@@ -9,23 +9,45 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.GameRules;
|
using OpenRA.GameRules;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Mods.Common.Lint;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
|
namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
|
||||||
{
|
{
|
||||||
|
[ChromeLogicArgsHotkeys("StopMusicKey", "PauseMusicKey", "PrevMusicKey", "NextMusicKey")]
|
||||||
public class MusicControllerLogic : ChromeLogic
|
public class MusicControllerLogic : ChromeLogic
|
||||||
{
|
{
|
||||||
MusicPlaylist musicPlaylist;
|
readonly MusicPlaylist musicPlaylist;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[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>();
|
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");
|
var keyhandler = widget.Get<LogicKeyListenerWidget>("MUSICCONTROLLER_KEYHANDLER");
|
||||||
keyhandler.OnKeyPress = e =>
|
keyhandler.OnKeyPress = e =>
|
||||||
{
|
{
|
||||||
@@ -33,13 +55,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
|
|||||||
{
|
{
|
||||||
var key = Hotkey.FromKeyInput(e);
|
var key = Hotkey.FromKeyInput(e);
|
||||||
|
|
||||||
if (key == Game.Settings.Keys.NextTrack)
|
if (key == nextKey.GetValue())
|
||||||
musicPlaylist.Play(musicPlaylist.GetNextSong());
|
musicPlaylist.Play(musicPlaylist.GetNextSong());
|
||||||
else if (key == Game.Settings.Keys.PreviousTrack)
|
else if (key == prevKey.GetValue())
|
||||||
musicPlaylist.Play(musicPlaylist.GetPrevSong());
|
musicPlaylist.Play(musicPlaylist.GetPrevSong());
|
||||||
else if (key == Game.Settings.Keys.StopMusic)
|
else if (key == stopKey.GetValue())
|
||||||
StopMusic();
|
StopMusic();
|
||||||
else if (key == Game.Settings.Keys.PauseMusic)
|
else if (key == pauseKey.GetValue())
|
||||||
PauseOrResumeMusic();
|
PauseOrResumeMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -610,10 +610,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
{
|
{
|
||||||
var hotkeys = new Dictionary<string, string>()
|
var hotkeys = new Dictionary<string, string>()
|
||||||
{
|
{
|
||||||
{ "NextTrack", "Next" },
|
{ "StopMusicKey", "Stop" },
|
||||||
{ "PreviousTrack", "Previous" },
|
{ "PauseMusicKey", "Pause or Resume" },
|
||||||
{ "StopMusic", "Stop" },
|
{ "PrevMusicKey", "Previous" },
|
||||||
{ "PauseMusic", "Pause or Resume" }
|
{ "NextMusicKey", "Next" }
|
||||||
};
|
};
|
||||||
|
|
||||||
var header = ScrollItemWidget.Setup(hotkeyHeader, returnTrue, doNothing);
|
var header = ScrollItemWidget.Setup(hotkeyHeader, returnTrue, doNothing);
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ Container@NEW_MAP_BG:
|
|||||||
Children:
|
Children:
|
||||||
Container@MUSICBUTTONS:
|
Container@MUSICBUTTONS:
|
||||||
Logic: MusicControllerLogic
|
Logic: MusicControllerLogic
|
||||||
|
StopMusicKey: StopMusic
|
||||||
|
PauseMusicKey: PauseMusic
|
||||||
|
PrevMusicKey: PrevMusic
|
||||||
|
NextMusicKey: NextMusic
|
||||||
Children:
|
Children:
|
||||||
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
|
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
|
||||||
Label@TITLE:
|
Label@TITLE:
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ Container@INGAME_ROOT:
|
|||||||
Children:
|
Children:
|
||||||
Container@MUSICBUTTONS:
|
Container@MUSICBUTTONS:
|
||||||
Logic: MusicControllerLogic
|
Logic: MusicControllerLogic
|
||||||
|
StopMusicKey: StopMusic
|
||||||
|
PauseMusicKey: PauseMusic
|
||||||
|
PrevMusicKey: PrevMusic
|
||||||
|
NextMusicKey: NextMusic
|
||||||
Children:
|
Children:
|
||||||
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
|
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
|
||||||
Container@WORLD_ROOT:
|
Container@WORLD_ROOT:
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ Container@MENU_BACKGROUND:
|
|||||||
Children:
|
Children:
|
||||||
Container@MUSICBUTTONS:
|
Container@MUSICBUTTONS:
|
||||||
Logic: MusicControllerLogic
|
Logic: MusicControllerLogic
|
||||||
|
StopMusicKey: StopMusic
|
||||||
|
PauseMusicKey: PauseMusic
|
||||||
|
PrevMusicKey: PrevMusic
|
||||||
|
NextMusicKey: NextMusic
|
||||||
Children:
|
Children:
|
||||||
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
|
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
|
||||||
Container@SHELLMAP_DECORATIONS:
|
Container@SHELLMAP_DECORATIONS:
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ Background@NEW_MAP_BG:
|
|||||||
Children:
|
Children:
|
||||||
Container@MUSICBUTTONS:
|
Container@MUSICBUTTONS:
|
||||||
Logic: MusicControllerLogic
|
Logic: MusicControllerLogic
|
||||||
|
StopMusicKey: StopMusic
|
||||||
|
PauseMusicKey: PauseMusic
|
||||||
|
PrevMusicKey: PrevMusic
|
||||||
|
NextMusicKey: NextMusic
|
||||||
Children:
|
Children:
|
||||||
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
|
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
|
||||||
Label@LABEL_TITLE:
|
Label@LABEL_TITLE:
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ Container@INGAME_ROOT:
|
|||||||
Children:
|
Children:
|
||||||
Container@MUSICBUTTONS:
|
Container@MUSICBUTTONS:
|
||||||
Logic: MusicControllerLogic
|
Logic: MusicControllerLogic
|
||||||
|
StopMusicKey: StopMusic
|
||||||
|
PauseMusicKey: PauseMusic
|
||||||
|
PrevMusicKey: PrevMusic
|
||||||
|
NextMusicKey: NextMusic
|
||||||
Children:
|
Children:
|
||||||
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
|
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
|
||||||
Container@WORLD_ROOT:
|
Container@WORLD_ROOT:
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ Container@MAINMENU:
|
|||||||
Children:
|
Children:
|
||||||
Container@MUSICBUTTONS:
|
Container@MUSICBUTTONS:
|
||||||
Logic: MusicControllerLogic
|
Logic: MusicControllerLogic
|
||||||
|
StopMusicKey: StopMusic
|
||||||
|
PauseMusicKey: PauseMusic
|
||||||
|
PrevMusicKey: PrevMusic
|
||||||
|
NextMusicKey: NextMusic
|
||||||
Children:
|
Children:
|
||||||
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
|
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
|
||||||
Background@BORDER:
|
Background@BORDER:
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ Container@MAINMENU:
|
|||||||
Children:
|
Children:
|
||||||
Container@MUSICBUTTONS:
|
Container@MUSICBUTTONS:
|
||||||
Logic: MusicControllerLogic
|
Logic: MusicControllerLogic
|
||||||
|
StopMusicKey: StopMusic
|
||||||
|
PauseMusicKey: PauseMusic
|
||||||
|
PrevMusicKey: PrevMusic
|
||||||
|
NextMusicKey: NextMusic
|
||||||
Children:
|
Children:
|
||||||
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
|
LogicKeyListener@MUSICCONTROLLER_KEYHANDLER:
|
||||||
Label@VERSION_LABEL:
|
Label@VERSION_LABEL:
|
||||||
|
|||||||
Reference in New Issue
Block a user