Example #1
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.Sound.SetMusicLooped(!Game.Settings.Sound.Repeat);
            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($"{minutes:D2}:{seconds:D2} / {totalMinutes:D2}:{totalSeconds:D2}");
            };

            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(); }
            }
            ;
        }
Example #2
0
 public void StopMusic()
 {
     playlist.Stop();
 }
Example #3
0
        public MusicPlayerLogic(Widget widget, Ruleset modRules, 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 minutes      = (int)Game.Sound.MusicSeekPosition / 60;
                var seconds      = (int)Game.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 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 installButton = widget.GetOrNull <ButtonWidget>("INSTALL_BUTTON");

            if (installButton != null)
            {
                installButton.IsDisabled = () => world.Type != WorldType.Shellmap;
                var args = new[] { "installMusic={0}".F(Game.ModData.Manifest.Mod.Id) };
                installButton.OnClick = () =>
                                        Game.RunAfterTick(() => Game.InitializeMod("modchooser", 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 (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(); }
            }
            ;
        }
Example #4
0
        public SoundPlayerLogic(Widget widget, ModData modData, World world, Action onExit)
        {
            this.world = world;

            var panel = widget;

            var notifications = world.Map.Rules.Notifications;
            var voices        = world.Map.Rules.Voices;

            sounds             = new Dictionary <string, SoundPlayType>();
            voiceSounds        = new Dictionary <string, string[]>();
            notificationSounds = new Dictionary <string, string[]>();
            foreach (var notification in notifications)
            {
                foreach (var n in notification.Value.Notifications)
                {
                    if (notification.Key == "speech")
                    {
                        foreach (var prefix in notification.Value.Prefixes)
                        {
                            string key = n.Key + " - " + prefix.Value[0];
                            if (!sounds.ContainsKey(key))
                            {
                                sounds.Add(key, SoundPlayType.Notification_Speech);
                            }
                            if (!notificationSounds.ContainsKey(key))
                            {
                                string[] newValues = new string[n.Value.Length];
                                for (int i = 0; i < newValues.Length; i++)
                                {
                                    newValues[i] = prefix.Key;
                                }
                                notificationSounds.Add(key, newValues);
                            }
                        }
                    }
                    //else if(notification.Key=="sounds")
                    //{
                    //    sounds.Add(n.Key, SoundPlayType.Notification_Sounds);
                    //    notificationSounds.Add(n.Key, n.Value);
                    //}
                }
            }
            //foreach (var voice in voices)
            //{
            //    foreach (var v in voice.Value.Voices)
            //    {
            //        sounds.Add(string.Format("{0} - {1}", voice.Key, v.Key), SoundPlayType.Voice);
            //        voiceSounds.Add(string.Format("{0} - {1}", voice.Key, v.Key), v.Value);
            //    }
            //}
            soundIndex = 0;

            soundList     = panel.Get <ScrollPanelWidget>("SOUND_LIST");
            itemTemplate  = soundList.Get <ScrollItemWidget>("SOUND_TEMPLATE");
            soundPlaylist = world.WorldActor.Trait <MusicPlaylist>();

            BuildSoundTable();

            Func <bool> noMusic = () => !soundPlaylist.IsMusicAvailable || soundPlaylist.CurrentSongIsBackground;

            if (soundPlaylist.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 = () => sounds.Count == 0;
            playButton.IsVisible  = () => !Game.Sound.MusicPlaying;

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

            pauseButton.OnClick    = Game.Sound.PauseMusic;
            pauseButton.IsDisabled = () => sounds.Count == 0;
            pauseButton.IsVisible  = () => Game.Sound.MusicPlaying;

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

            stopButton.IsDisabled = () => sounds.Count == 0;
            stopButton.OnClick    = () => { soundPlaylist.Stop(); };

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

            nextButton.IsDisabled = () => sounds.Count == 0;
            nextButton.OnClick    = () => {
                KeyValuePair <string, string[]> sound;
                if (currentSoundAvaliable = GetSound(soundIndex++, out sound))
                {
                    currentSound = sound;
                    Play();
                }
            };

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

            prevButton.OnClick = () => {
                KeyValuePair <string, string[]> sound;
                if (currentSoundAvaliable = GetSound(soundIndex--, out sound))
                {
                    currentSound = sound;
                    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 = () => soundPlaylist.CurrentSongIsBackground;

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

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

            panel.Get <LabelWidget>("TIME_LABEL").GetText = () =>
            {
                if (!currentSoundAvaliable)
                {
                    return("");
                }

                return(string.Empty);
                //var seek = Game.Sound.MusicSeekPosition;
                //var minutes = (int)seek / 60;
                //var seconds = (int)seek % 60;
                //var totalMinutes = currentSound.Length / 60;
                //var totalSeconds = currentSound.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 = () => currentSoundAvaliable ? currentSound.Key : "No sound playing";
            }

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

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

            var soundWatcher = widget.GetOrNull <LogicTickerWidget>("SOUND_WATCHER");

            if (soundWatcher != null)
            {
                soundWatcher.OnTick = () =>
                {
                    //if (currentSoundAvaliable)
                    //	currentSound = new KeyValuePair<string, SoundInfo>();
                    //
                    //if (Game.Sound.CurrentMusic == null || currentSound == Game.Sound. || soundPlaylist.CurrentSongIsBackground)
                    //	return;
                    //
                    //currentSound = Game.Sound.CurrentMusic;
                };
            }

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

            if (backButton != null)
            {
                backButton.OnClick = () => { Game.Settings.Save(); Ui.CloseWindow(); onExit(); }
            }
            ;
        }