From e4aab9486d7603d154f74a309bbf2bd6f17103c2 Mon Sep 17 00:00:00 2001 From: zznty <94796179+zznty@users.noreply.github.com> Date: Wed, 29 Nov 2023 00:02:47 +0700 Subject: [PATCH] allow jumping to specific artist in player control --- MusicX/Controls/PlayerControl.xaml | 3 -- MusicX/Controls/PlayerControl.xaml.cs | 55 +++++++++++++++++---------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/MusicX/Controls/PlayerControl.xaml b/MusicX/Controls/PlayerControl.xaml index 6ed11bef..6158dd83 100644 --- a/MusicX/Controls/PlayerControl.xaml +++ b/MusicX/Controls/PlayerControl.xaml @@ -303,9 +303,6 @@ diff --git a/MusicX/Controls/PlayerControl.xaml.cs b/MusicX/Controls/PlayerControl.xaml.cs index bb0c0035..b16a33e4 100644 --- a/MusicX/Controls/PlayerControl.xaml.cs +++ b/MusicX/Controls/PlayerControl.xaml.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; +using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; @@ -136,21 +137,38 @@ private async void PlayerService_TrackChangedEvent(object? sender, EventArgs e) } TrackTitle.Text = playerService.CurrentTrack.Title; - string s = string.Empty; + + if (ArtistName.Inlines.Count > 0) + ArtistName.Inlines.Clear(); + if (playerService.CurrentTrack!.MainArtists.Any()) { - foreach (var trackArtist in playerService.CurrentTrack.MainArtists) + ArtistName.Inlines.AddRange(playerService.CurrentTrack.MainArtists.Select(b => { - s += trackArtist.Name + ", "; - } - - var artists = s.Remove(s.Length - 2); - - ArtistName.Text = artists; + var run = new Run(b.Name + ", ") + { + Tag = b + }; + + run.MouseEnter += ArtistName_MouseEnter; + run.MouseLeave += ArtistName_MouseLeave; + run.MouseLeftButtonUp += ArtistName_MouseLeftButtonUp; + + return run; + })); + + var lastInline = (Run)ArtistName.Inlines.LastInline; + lastInline.Text = lastInline.Text[..^2]; } else { - ArtistName.Text = playerService.CurrentTrack.GetArtistsString(); + var run = new Run(playerService.CurrentTrack.GetArtistsString()); + + run.MouseEnter += ArtistName_MouseEnter; + run.MouseLeave += ArtistName_MouseLeave; + run.MouseLeftButtonUp += ArtistName_MouseLeftButtonUp; + + ArtistName.Inlines.Add(run); } @@ -297,22 +315,17 @@ private async void PrevButton_Click(object sender, RoutedEventArgs e) private void ArtistName_MouseEnter(object sender, MouseEventArgs e) { - //if (playerService.CurrentTrack.MainArtists == null) return; - ArtistName.TextDecorations.Add(TextDecorations.Underline); - this.Cursor = Cursors.Hand; - + ((Run)sender).TextDecorations.Add(TextDecorations.Underline); + this.Cursor = Cursors.Hand; } private void ArtistName_MouseLeave(object sender, MouseEventArgs e) { - //if (playerService.CurrentTrack.MainArtists == null) return; - foreach (var dec in TextDecorations.Underline) { - ArtistName.TextDecorations.Remove(dec); + ((Run)sender).TextDecorations.Remove(dec); } this.Cursor = Cursors.Arrow; - } private async Task SaveVolume() @@ -331,13 +344,13 @@ private async Task SaveVolume() await configService.SetConfig(conf); } - private async void ArtistName_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + private async void ArtistName_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { try { var navigationService = StaticService.Container.GetRequiredService(); - if (playerService.CurrentTrack?.MainArtists.First().Id is {Type: ArtistIdType.Vk} artistId) + if (((Run)sender).Tag is TrackArtist { Id: { Type: ArtistIdType.Vk } artistId }) { navigationService.OpenSection(artistId.Id, SectionType.Artist); } @@ -395,13 +408,13 @@ private async void LikeTrack_Click(object sender, RoutedEventArgs e) LikeIcon.Filled = true; snackbarService.Show("Добавлено в вашу библиотеку", - $"Трек {ArtistName.Text} - {TrackTitle.Text} теперь находится в Вашей музыке!", ControlAppearance.Success); + $"Трек {playerService.CurrentTrack.GetArtistsString()} - {playerService.CurrentTrack.Title} теперь находится в Вашей музыке!", ControlAppearance.Success); return; } LikeIcon.Filled = false; snackbarService.Show("Удалено из вашей библиотеки", - $"Трек {ArtistName.Text} - {TrackTitle.Text} теперь удален из вашей музыки", ControlAppearance.Success); + $"Трек {playerService.CurrentTrack.GetArtistsString()} - {playerService.CurrentTrack.Title} теперь удален из вашей музыки", ControlAppearance.Success); } catch(Exception ex) {