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

@@ -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();
}