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);
            };
        }
Exemple #2
0
        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);
            });
        }
Exemple #3
0
        public MusicPlayerLogic(Widget widget, ModData modData, World world, Action onExit)
        {
            var panel = widget;

            musicList     = panel.Get <ScrollPanelWidget>("MUSIC_LIST");
            itemTemplate  = musicList.Get <ScrollItemWidget>("MUSIC_TEMPLATE");
            musicPlaylist = world.WorldActor.Trait <MusicPlaylist>();

            BuildMusicTable();

            Func <bool> noMusic = () => !musicPlaylist.IsMusicAvailable || musicPlaylist.CurrentSongIsBackground || currentSong == null;

            panel.Get("NO_MUSIC_LABEL").IsVisible = () => !musicPlaylist.IsMusicAvailable;

            if (musicPlaylist.IsMusicAvailable)
            {
                panel.Get <LabelWidget>("MUTE_LABEL").GetText = () =>
                {
                    if (Game.Settings.Sound.Mute)
                    {
                        return("Audio has been muted in settings.");
                    }

                    return("");
                };
            }

            var playButton = panel.Get <ButtonWidget>("BUTTON_PLAY");

            playButton.OnClick    = Play;
            playButton.IsDisabled = noMusic;
            playButton.IsVisible  = () => !Game.Sound.MusicPlaying;

            var pauseButton = panel.Get <ButtonWidget>("BUTTON_PAUSE");

            pauseButton.OnClick    = Game.Sound.PauseMusic;
            pauseButton.IsDisabled = noMusic;
            pauseButton.IsVisible  = () => Game.Sound.MusicPlaying;

            var stopButton = panel.Get <ButtonWidget>("BUTTON_STOP");

            stopButton.OnClick    = () => { musicPlaylist.Stop(); };
            stopButton.IsDisabled = noMusic;

            var nextButton = panel.Get <ButtonWidget>("BUTTON_NEXT");

            nextButton.OnClick    = () => { currentSong = musicPlaylist.GetNextSong(); Play(); };
            nextButton.IsDisabled = noMusic;

            var prevButton = panel.Get <ButtonWidget>("BUTTON_PREV");

            prevButton.OnClick    = () => { currentSong = musicPlaylist.GetPrevSong(); Play(); };
            prevButton.IsDisabled = noMusic;

            var shuffleCheckbox = panel.Get <CheckboxWidget>("SHUFFLE");

            shuffleCheckbox.IsChecked  = () => Game.Settings.Sound.Shuffle;
            shuffleCheckbox.OnClick    = () => Game.Settings.Sound.Shuffle ^= true;
            shuffleCheckbox.IsDisabled = () => musicPlaylist.CurrentSongIsBackground;

            var repeatCheckbox = panel.Get <CheckboxWidget>("REPEAT");

            repeatCheckbox.IsChecked  = () => Game.Settings.Sound.Repeat;
            repeatCheckbox.OnClick    = () => Game.Settings.Sound.Repeat ^= true;
            repeatCheckbox.IsDisabled = () => musicPlaylist.CurrentSongIsBackground;

            panel.Get <LabelWidget>("TIME_LABEL").GetText = () =>
            {
                if (currentSong == null || musicPlaylist.CurrentSongIsBackground)
                {
                    return("");
                }

                var seek         = Game.Sound.MusicSeekPosition;
                var minutes      = (int)seek / 60;
                var seconds      = (int)seek % 60;
                var totalMinutes = currentSong.Length / 60;
                var totalSeconds = currentSong.Length % 60;

                return("{0:D2}:{1:D2} / {2:D2}:{3:D2}".F(minutes, seconds, totalMinutes, totalSeconds));
            };

            var musicTitle = panel.GetOrNull <LabelWidget>("TITLE_LABEL");

            if (musicTitle != null)
            {
                musicTitle.GetText = () => currentSong != null ? currentSong.Title : "No song playing";
            }

            var musicSlider = panel.Get <SliderWidget>("MUSIC_SLIDER");

            musicSlider.OnChange += x => Game.Sound.MusicVolume = x;
            musicSlider.Value     = Game.Sound.MusicVolume;

            var songWatcher = widget.GetOrNull <LogicTickerWidget>("SONG_WATCHER");

            if (songWatcher != null)
            {
                songWatcher.OnTick = () =>
                {
                    if (musicPlaylist.CurrentSongIsBackground && currentSong != null)
                    {
                        currentSong = null;
                    }

                    if (Game.Sound.CurrentMusic == null || currentSong == Game.Sound.CurrentMusic || musicPlaylist.CurrentSongIsBackground)
                    {
                        return;
                    }

                    currentSong = Game.Sound.CurrentMusic;
                };
            }

            var backButton = panel.GetOrNull <ButtonWidget>("BACK_BUTTON");

            if (backButton != null)
            {
                backButton.OnClick = () => { Game.Settings.Save(); Ui.CloseWindow(); onExit(); }
            }
            ;
        }
Exemple #4
0
        public MusicPlayerLogic(Widget widget, Ruleset modRules, World world, Action onExit)
        {
            var panel = widget.Get("MUSIC_PANEL");

            musicList     = panel.Get <ScrollPanelWidget>("MUSIC_LIST");
            itemTemplate  = musicList.Get <ScrollItemWidget>("MUSIC_TEMPLATE");
            musicPlaylist = world.WorldActor.Trait <MusicPlaylist>();

            BuildMusicTable();

            Func <bool> noMusic = () => !musicPlaylist.IsMusicAvailable || musicPlaylist.CurrentSongIsBackground || currentSong == null;

            panel.Get("NO_MUSIC_LABEL").IsVisible = () => !musicPlaylist.IsMusicAvailable;

            var playButton = panel.Get <ButtonWidget>("BUTTON_PLAY");

            playButton.OnClick    = Play;
            playButton.IsDisabled = noMusic;
            playButton.IsVisible  = () => !Sound.MusicPlaying;

            var pauseButton = panel.Get <ButtonWidget>("BUTTON_PAUSE");

            pauseButton.OnClick    = Sound.PauseMusic;
            pauseButton.IsDisabled = noMusic;
            pauseButton.IsVisible  = () => Sound.MusicPlaying;

            var stopButton = panel.Get <ButtonWidget>("BUTTON_STOP");

            stopButton.OnClick    = () => { musicPlaylist.Stop(); };
            stopButton.IsDisabled = noMusic;

            var nextButton = panel.Get <ButtonWidget>("BUTTON_NEXT");

            nextButton.OnClick    = () => { currentSong = musicPlaylist.GetNextSong(); Play(); };
            nextButton.IsDisabled = noMusic;

            var prevButton = panel.Get <ButtonWidget>("BUTTON_PREV");

            prevButton.OnClick    = () => { currentSong = musicPlaylist.GetPrevSong(); Play(); };
            prevButton.IsDisabled = noMusic;

            var shuffleCheckbox = panel.Get <CheckboxWidget>("SHUFFLE");

            shuffleCheckbox.IsChecked  = () => Game.Settings.Sound.Shuffle;
            shuffleCheckbox.OnClick    = () => Game.Settings.Sound.Shuffle ^= true;
            shuffleCheckbox.IsDisabled = () => musicPlaylist.CurrentSongIsBackground;

            var repeatCheckbox = panel.Get <CheckboxWidget>("REPEAT");

            repeatCheckbox.IsChecked  = () => Game.Settings.Sound.Repeat;
            repeatCheckbox.OnClick    = () => Game.Settings.Sound.Repeat ^= true;
            repeatCheckbox.IsDisabled = () => musicPlaylist.CurrentSongIsBackground;

            panel.Get <LabelWidget>("TIME_LABEL").GetText = () =>
            {
                if (currentSong == null || musicPlaylist.CurrentSongIsBackground)
                {
                    return("");
                }

                var minutes      = (int)Sound.MusicSeekPosition / 60;
                var seconds      = (int)Sound.MusicSeekPosition % 60;
                var totalMinutes = currentSong.Length / 60;
                var totalSeconds = currentSong.Length % 60;

                return("{0:D2}:{1:D2} / {2:D2}:{3:D2}".F(minutes, seconds, totalMinutes, totalSeconds));
            };

            var musicSlider = panel.Get <SliderWidget>("MUSIC_SLIDER");

            musicSlider.OnChange += x => Sound.MusicVolume = x;
            musicSlider.Value     = Sound.MusicVolume;

            var installButton = widget.GetOrNull <ButtonWidget>("INSTALL_BUTTON");

            if (installButton != null)
            {
                installButton.IsDisabled = () => world == null || world.Type != WorldType.Shellmap;
                var args = new string[] { "Install.Music=true" };
                installButton.OnClick = () =>
                                        Game.RunAfterTick(() =>
                                                          Game.InitializeMod(Game.Settings.Game.Mod, new Arguments(args)));

                var installData = Game.ModData.Manifest.Get <ContentInstaller>();
                installButton.IsVisible = () => modRules.InstalledMusic.ToArray().Length <= installData.ShippedSoundtracks;
            }

            var songWatcher = widget.GetOrNull <LogicTickerWidget>("SONG_WATCHER");

            if (songWatcher != null)
            {
                songWatcher.OnTick = () =>
                {
                    if (musicPlaylist.CurrentSongIsBackground && currentSong != null)
                    {
                        currentSong = null;
                    }

                    if (Sound.CurrentMusic == null || currentSong == Sound.CurrentMusic || musicPlaylist.CurrentSongIsBackground)
                    {
                        return;
                    }

                    currentSong = Sound.CurrentMusic;
                };
            }

            panel.Get <ButtonWidget>("BACK_BUTTON").OnClick = () => { Game.Settings.Save(); Ui.CloseWindow(); onExit(); };
        }
Exemple #5
0
        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);
            });
        }