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); }; }
public void PlayMusic(string track = null, LuaFunction func = null) { if (!playlist.IsMusicAvailable) { return; } var musicInfo = !string.IsNullOrEmpty(track) ? GetMusicTrack(track) : playlist.GetNextSong(); if (func != null) { var f = (LuaFunction)func.CopyReference(); Action onComplete = () => { try { using (f) f.Call().Dispose(); } catch (LuaException e) { Context.FatalError(e.Message); } }; playlist.Play(musicInfo, onComplete); } else { playlist.Play(musicInfo); } }
public MusicHotkeyLogic(Widget widget, ModData modData, World world, Dictionary <string, MiniYaml> logicArgs) { musicPlaylist = world.WorldActor.Trait <MusicPlaylist>(); MiniYaml yaml; var stopKey = new HotkeyReference(); if (logicArgs.TryGetValue("StopMusicKey", out yaml)) { stopKey = modData.Hotkeys[yaml.Value]; } var pauseKey = new HotkeyReference(); if (logicArgs.TryGetValue("PauseMusicKey", out yaml)) { pauseKey = modData.Hotkeys[yaml.Value]; } var prevKey = new HotkeyReference(); if (logicArgs.TryGetValue("PrevMusicKey", out yaml)) { prevKey = modData.Hotkeys[yaml.Value]; } var nextKey = new HotkeyReference(); if (logicArgs.TryGetValue("NextMusicKey", out yaml)) { nextKey = modData.Hotkeys[yaml.Value]; } var keyhandler = widget.Get <LogicKeyListenerWidget>("GLOBAL_KEYHANDLER"); keyhandler.AddHandler(e => { if (e.Event == KeyInputEvent.Down) { if (nextKey.IsActivatedBy(e)) { musicPlaylist.Play(musicPlaylist.GetNextSong()); } else if (prevKey.IsActivatedBy(e)) { musicPlaylist.Play(musicPlaylist.GetPrevSong()); } else if (stopKey.IsActivatedBy(e)) { StopMusic(); } else if (pauseKey.IsActivatedBy(e)) { 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 Play() { if (currentSong == null) { return; } musicList.ScrollToItem(currentSong.Filename); musicPlaylist.Play(currentSong); }
public MusicHotkeyLogic(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>("GLOBAL_KEYHANDLER"); keyhandler.AddHandler(e => { if (e.Event == KeyInputEvent.Down) { var key = Hotkey.FromKeyInput(e); if (key == nextKey.GetValue()) { musicPlaylist.Play(musicPlaylist.GetNextSong()); } else if (key == prevKey.GetValue()) { musicPlaylist.Play(musicPlaylist.GetPrevSong()); } else if (key == stopKey.GetValue()) { StopMusic(); } else if (key == pauseKey.GetValue()) { PauseOrResumeMusic(); } } return(false); }); }