Ejemplo n.º 1
0
        private void ShowLevelInfo(CachedLevelData level)
        {
            LevelInfo.Visible = true;

            Task.Run(() =>
            {
                lock (Length)
                {
                    if (level.AudioDuration is null)
                    {
                        Length.Text = "0:00 – ";
                        level.LoadAudioDuration();
                    }
                    Length.Text = UIUtil.GetDurationString(level.AudioDuration ?? TimeSpan.Zero) + " – ";
                }
            });

            Title.Text       = level.Info.Title;
            Artist.Text      = level.Info.Artist;
            Subtitle.Text    = UIUtil.GetSubtitle(level.Info);
            Difficulty.Text  = UIUtil.GetDifficultyString(level.Info.Difficulty);
            Creator.Text     = level.Info.Designer;
            HeartImg.Visible = level.Info.HasHeart;

            ShowLocalScores(level);

            if (scores is null || scores.Count == 0)
            {
                HeartImg.Renderable = HeartOutlineIcon;
            }
Ejemplo n.º 2
0
        private void StartSongPreview(CachedLevelData level)
        {
            var player    = AudioPlayer.Instance;
            var audioFile = level.Mp3Path;

            if (player.CurrentFile == audioFile)
            {
                RestartSongPreview(level);
                return;
            }

            if (File.Exists(level.Mp3Path))
            {
                Task.Run(() =>
                {
                    lock (player)
                    {
                        player.Stop();
                        player.Load(level.Mp3Path, false, false);
                        var previewPoint = (int)(player.TotalTime.TotalMilliseconds
                                                 * (level.Info.AudioPreviewPoint / 100f));
                        player.JumpTo(previewPoint);
                        player.BeginFadeIn(FadeInTime);
                        player.Play();
                    }
                });
            }
            else
            {
                //errorMsg.Text = "Audio file is missing.";
                Play.Enabled = false;
            }
        }
Ejemplo n.º 3
0
        private void RestartSongPreview(CachedLevelData level)
        {
            var player = AudioPlayer.Instance;

            lock (player)
            {
                // Preview already playing or user abandoned level early
                if (player.PositionPercent < 1)
                {
                    if (!player.IsPlaying)
                    {
                        player.PlaybackSpeed = 1;
                        player.BeginFadeIn(FadeInTime);
                        try
                        {
                            player.Play();
                        }
                        catch (ObjectDisposedException odex)
                        {
                            // TODO: prevent this exception
                            // which happens when exiting the level before audio finished loading
                            logger.Warn(odex);
                        }
                    }
                }
                // returned to level select after level ended
                else
                {
                    player.PlaybackSpeed = 1;
                    var previewPoint = (int)(player.TotalTime.TotalMilliseconds
                                             * (level.Info.AudioPreviewPoint / 100f));
                    player.JumpTo(previewPoint);
                    player.BeginFadeIn(FadeInTime);
                    player.Play();
                }
            }
        }
Ejemplo n.º 4
0
        public LevelBoxLevel(CachedLevelData level) : this()
        {
            var gridRow = 0;

            var heartAndTitle = new HorizontalStackPanel();

            heartAndTitle.GridRow = gridRow++;
            heartAndTitle.Proportions.Add(new Proportion(ProportionType.Fill));
            Widgets.Add(heartAndTitle);

            var title = new Label
            {
                AutoEllipsisMethod  = AutoEllipsisMethod.Character,
                Margin              = new Thickness(0, 0, 10, 0),
                HorizontalAlignment = HorizontalAlignment.Left,
                Font = Fonts.OrkneyWithFallback.GetFont(24),
                Text = level.Info.Title,
            };

            heartAndTitle.Widgets.Add(title);

            if (level.Info.HasHeart)
            {
                var heart = new Image();
                UIUtil.SetHeart(heart, 18);
                heart.Renderable = level.HeartGotten
                    ? LevelSelect.HeartIcon
                    : LevelSelect.HeartOutlineIcon;
                heartAndTitle.Widgets.Add(heart);
            }


            var artistAndScore = new HorizontalStackPanel();

            artistAndScore.Proportions.Add(new Proportion(ProportionType.Fill));
            artistAndScore.GridRow = gridRow++;
            Widgets.Add(artistAndScore);

            var artist = new Label
            {
                AutoEllipsisMethod = AutoEllipsisMethod.Character,
                Font = Fonts.OrkneyWithFallback.GetFont(20),
                Text = level.Info.Artist,
            };

            artistAndScore.Widgets.Add(artist);

            if (level.BestScore.HasValue)
            {
                var score = new Label
                {
                    Font = Fonts.OrkneyWithFallback.GetFont(20),
                    Text = $"{level.BestScore:0%}",
                };
                artistAndScore.Widgets.Add(score);
            }


            var diffAndSubtitle = new HorizontalStackPanel
            {
                GridRow = gridRow++,
                Spacing = 10
            };

            Widgets.Add(diffAndSubtitle);

            var diff = new Label
            {
                Text = UIUtil.GetDifficultyString(level.Info.Difficulty),
                Font = Fonts.DejaVuSans.GetFont(20),
                VerticalAlignment = VerticalAlignment.Center
            };

            diffAndSubtitle.Widgets.Add(diff);

            var subtitle = new Label
            {
                VerticalAlignment = VerticalAlignment.Center
            };

            diffAndSubtitle.Widgets.Add(subtitle);
        }
Ejemplo n.º 5
0
 private void SetDisplayedLevel(CachedLevelData level)
 {
     Play.Enabled = true;
     StartSongPreview(level);
     ShowLevelInfo(level);
 }
Ejemplo n.º 6
0
 private void LevelBox_LevelSelected(object sender, CachedLevelData e)
 {
     Mod.ApplyLevelSettings(ref activeMod, e.Settings);
     SetDisplayedLevel(e);
 }