From 640be621ac4e178f1e1b6f24283e13719e7f7ef6 Mon Sep 17 00:00:00 2001 From: TocoToucan Date: Sat, 7 Apr 2018 13:29:46 +0300 Subject: [PATCH 1/5] Handle multiple song previews playing in different beatmap categories on profile --- .../Beatmaps/PaginatedBeatmapContainer.cs | 4 ++++ .../Profile/Sections/BeatmapsSection.cs | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/osu.Game/Overlays/Profile/Sections/Beatmaps/PaginatedBeatmapContainer.cs b/osu.Game/Overlays/Profile/Sections/Beatmaps/PaginatedBeatmapContainer.cs index da070d1cc2..637985e3cd 100644 --- a/osu.Game/Overlays/Profile/Sections/Beatmaps/PaginatedBeatmapContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/Beatmaps/PaginatedBeatmapContainer.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using OpenTK; using osu.Framework.Configuration; using osu.Framework.Graphics; @@ -19,6 +20,8 @@ namespace osu.Game.Overlays.Profile.Sections.Beatmaps private DirectPanel currentlyPlaying; + public event Action BeatmapAdded; + public PaginatedBeatmapContainer(BeatmapSetType type, Bindable user, string header, string missing = "None... yet.") : base(user, header, missing) { @@ -63,6 +66,7 @@ namespace osu.Game.Overlays.Profile.Sections.Beatmaps currentlyPlaying = panel; }; + BeatmapAdded?.Invoke(panel); } }; diff --git a/osu.Game/Overlays/Profile/Sections/BeatmapsSection.cs b/osu.Game/Overlays/Profile/Sections/BeatmapsSection.cs index 760054716f..928ac677a4 100644 --- a/osu.Game/Overlays/Profile/Sections/BeatmapsSection.cs +++ b/osu.Game/Overlays/Profile/Sections/BeatmapsSection.cs @@ -1,7 +1,9 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System.Linq; using osu.Game.Online.API.Requests; +using osu.Game.Overlays.Direct; using osu.Game.Overlays.Profile.Sections.Beatmaps; namespace osu.Game.Overlays.Profile.Sections @@ -12,6 +14,8 @@ namespace osu.Game.Overlays.Profile.Sections public override string Identifier => "beatmaps"; + private DirectPanel currentlyPlaying; + public BeatmapsSection() { Children = new[] @@ -21,6 +25,19 @@ namespace osu.Game.Overlays.Profile.Sections new PaginatedBeatmapContainer(BeatmapSetType.Unranked, User, "Pending Beatmaps"), new PaginatedBeatmapContainer(BeatmapSetType.Graveyard, User, "Graveyarded Beatmaps"), }; + + foreach (var beatmapContainer in Children.OfType()) + { + beatmapContainer.BeatmapAdded += panel => panel.PreviewPlaying.ValueChanged += isPlaying => + { + if (!isPlaying) return; + + if (currentlyPlaying != null && currentlyPlaying != panel) + currentlyPlaying.PreviewPlaying.Value = false; + + currentlyPlaying = panel; + }; + } } } } From 6cdfaffcf7c6da6beda62118397af17dcf243e44 Mon Sep 17 00:00:00 2001 From: TocoToucan Date: Wed, 11 Apr 2018 16:19:21 +0300 Subject: [PATCH 2/5] PaginatedBeatmapContainer.BeganPlayingPreview --- .../Beatmaps/PaginatedBeatmapContainer.cs | 12 +++++++++--- .../Overlays/Profile/Sections/BeatmapsSection.cs | 15 +++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/osu.Game/Overlays/Profile/Sections/Beatmaps/PaginatedBeatmapContainer.cs b/osu.Game/Overlays/Profile/Sections/Beatmaps/PaginatedBeatmapContainer.cs index 637985e3cd..6e22d51958 100644 --- a/osu.Game/Overlays/Profile/Sections/Beatmaps/PaginatedBeatmapContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/Beatmaps/PaginatedBeatmapContainer.cs @@ -20,7 +20,7 @@ namespace osu.Game.Overlays.Profile.Sections.Beatmaps private DirectPanel currentlyPlaying; - public event Action BeatmapAdded; + public event Action BeganPlayingPreview; public PaginatedBeatmapContainer(BeatmapSetType type, Bindable user, string header, string missing = "None... yet.") : base(user, header, missing) @@ -61,16 +61,22 @@ namespace osu.Game.Overlays.Profile.Sections.Beatmaps { if (!isPlaying) return; + BeganPlayingPreview?.Invoke(this); if (currentlyPlaying != null && currentlyPlaying != panel) - currentlyPlaying.PreviewPlaying.Value = false; + StopPlayingPreview(); currentlyPlaying = panel; }; - BeatmapAdded?.Invoke(panel); } }; Api.Queue(req); } + + public void StopPlayingPreview() + { + if (currentlyPlaying != null) + currentlyPlaying.PreviewPlaying.Value = false; + } } } diff --git a/osu.Game/Overlays/Profile/Sections/BeatmapsSection.cs b/osu.Game/Overlays/Profile/Sections/BeatmapsSection.cs index 928ac677a4..f1f2421237 100644 --- a/osu.Game/Overlays/Profile/Sections/BeatmapsSection.cs +++ b/osu.Game/Overlays/Profile/Sections/BeatmapsSection.cs @@ -26,16 +26,15 @@ namespace osu.Game.Overlays.Profile.Sections new PaginatedBeatmapContainer(BeatmapSetType.Graveyard, User, "Graveyarded Beatmaps"), }; - foreach (var beatmapContainer in Children.OfType()) + foreach (var paginatedBeatmapContainer in Children.OfType()) { - beatmapContainer.BeatmapAdded += panel => panel.PreviewPlaying.ValueChanged += isPlaying => + paginatedBeatmapContainer.BeganPlayingPreview += (BeatmapContainer) => { - if (!isPlaying) return; - - if (currentlyPlaying != null && currentlyPlaying != panel) - currentlyPlaying.PreviewPlaying.Value = false; - - currentlyPlaying = panel; + foreach (var bc in Children.OfType()) + { + if (bc != BeatmapContainer) + bc.StopPlayingPreview(); + } }; } } From 6a8f568f66b9e8bc14f2ce892f6c31110ecf96ff Mon Sep 17 00:00:00 2001 From: TocoToucan Date: Wed, 11 Apr 2018 16:32:58 +0300 Subject: [PATCH 3/5] BeatmapContainer -> beatmapContainer --- osu.Game/Overlays/Profile/Sections/BeatmapsSection.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/Profile/Sections/BeatmapsSection.cs b/osu.Game/Overlays/Profile/Sections/BeatmapsSection.cs index f1f2421237..a0d37ffe71 100644 --- a/osu.Game/Overlays/Profile/Sections/BeatmapsSection.cs +++ b/osu.Game/Overlays/Profile/Sections/BeatmapsSection.cs @@ -28,11 +28,11 @@ namespace osu.Game.Overlays.Profile.Sections foreach (var paginatedBeatmapContainer in Children.OfType()) { - paginatedBeatmapContainer.BeganPlayingPreview += (BeatmapContainer) => + paginatedBeatmapContainer.BeganPlayingPreview += beatmapContainer => { foreach (var bc in Children.OfType()) { - if (bc != BeatmapContainer) + if (bc != beatmapContainer) bc.StopPlayingPreview(); } }; From 069d48ac14a29ac0bf20647a5cafe815500697f7 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 15 Apr 2018 15:29:00 +0900 Subject: [PATCH 4/5] Remove unused variable --- osu.Game/Overlays/Profile/Sections/BeatmapsSection.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/osu.Game/Overlays/Profile/Sections/BeatmapsSection.cs b/osu.Game/Overlays/Profile/Sections/BeatmapsSection.cs index ae3c10228b..78a3bd7468 100644 --- a/osu.Game/Overlays/Profile/Sections/BeatmapsSection.cs +++ b/osu.Game/Overlays/Profile/Sections/BeatmapsSection.cs @@ -3,7 +3,6 @@ using System.Linq; using osu.Game.Online.API.Requests; -using osu.Game.Overlays.Direct; using osu.Game.Overlays.Profile.Sections.Beatmaps; namespace osu.Game.Overlays.Profile.Sections @@ -14,8 +13,6 @@ namespace osu.Game.Overlays.Profile.Sections public override string Identifier => "beatmaps"; - private DirectPanel currentlyPlaying; - public BeatmapsSection() { Children = new[] From fd54ae3c87eab25df96bb90990ff1f8dead1d6df Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 15 Apr 2018 16:12:42 +0900 Subject: [PATCH 5/5] Simplify logic --- osu.Game/Overlays/Direct/PlayButton.cs | 3 ++- .../Beatmaps/PaginatedBeatmapContainer.cs | 17 +++++++++-------- .../Profile/Sections/BeatmapsSection.cs | 7 ++----- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/osu.Game/Overlays/Direct/PlayButton.cs b/osu.Game/Overlays/Direct/PlayButton.cs index 9f36d5acb7..44e24d8157 100644 --- a/osu.Game/Overlays/Direct/PlayButton.cs +++ b/osu.Game/Overlays/Direct/PlayButton.cs @@ -173,8 +173,9 @@ namespace osu.Game.Overlays.Direct if (trackLoader != d) return; Preview = d?.Preview; - Playing.TriggerChange(); + updatePreviewTrack(Playing); loading = false; + Add(trackLoader); }); } diff --git a/osu.Game/Overlays/Profile/Sections/Beatmaps/PaginatedBeatmapContainer.cs b/osu.Game/Overlays/Profile/Sections/Beatmaps/PaginatedBeatmapContainer.cs index 31433e64b3..3fec9d8697 100644 --- a/osu.Game/Overlays/Profile/Sections/Beatmaps/PaginatedBeatmapContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/Beatmaps/PaginatedBeatmapContainer.cs @@ -59,13 +59,13 @@ namespace osu.Game.Overlays.Profile.Sections.Beatmaps panel.PreviewPlaying.ValueChanged += isPlaying => { - if (!isPlaying) return; + StopPlayingPreview(); - BeganPlayingPreview?.Invoke(this); - if (currentlyPlaying != null && currentlyPlaying != panel) - StopPlayingPreview(); - - currentlyPlaying = panel; + if (isPlaying) + { + BeganPlayingPreview?.Invoke(this); + currentlyPlaying = panel; + } }; } }; @@ -75,8 +75,9 @@ namespace osu.Game.Overlays.Profile.Sections.Beatmaps public void StopPlayingPreview() { - if (currentlyPlaying != null) - currentlyPlaying.PreviewPlaying.Value = false; + if (currentlyPlaying == null) return; + currentlyPlaying.PreviewPlaying.Value = false; + currentlyPlaying = null; } } } diff --git a/osu.Game/Overlays/Profile/Sections/BeatmapsSection.cs b/osu.Game/Overlays/Profile/Sections/BeatmapsSection.cs index 78a3bd7468..92abd20f93 100644 --- a/osu.Game/Overlays/Profile/Sections/BeatmapsSection.cs +++ b/osu.Game/Overlays/Profile/Sections/BeatmapsSection.cs @@ -25,13 +25,10 @@ namespace osu.Game.Overlays.Profile.Sections foreach (var paginatedBeatmapContainer in Children.OfType()) { - paginatedBeatmapContainer.BeganPlayingPreview += beatmapContainer => + paginatedBeatmapContainer.BeganPlayingPreview += _ => { foreach (var bc in Children.OfType()) - { - if (bc != beatmapContainer) - bc.StopPlayingPreview(); - } + bc.StopPlayingPreview(); }; } }