diff --git a/osu.Game/Overlays/Music/Playlist.cs b/osu.Game/Overlays/Music/Playlist.cs index ab51ca7e1dec..3a82412e4b3a 100644 --- a/osu.Game/Overlays/Music/Playlist.cs +++ b/osu.Game/Overlays/Music/Playlist.cs @@ -2,7 +2,9 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Collections.Generic; using System.Linq; +using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -21,6 +23,9 @@ public partial class Playlist : OsuRearrangeableListContainer base.Padding; @@ -46,9 +51,21 @@ public void Filter(FilterCriteria criteria) items.SearchTerm = criteria.SearchText; currentCriteria = criteria; + + if (currentCriteria == criteria) + updateMusicControllerPlaylist(); + + items.FilterCompleted += updateMusicControllerPlaylist; + + void updateMusicControllerPlaylist() => Scheduler.AddOnce(() => + { + musicController.Playlist.Clear(); + musicController.Playlist.AddRange(AllVisibleSets); + }); } public Live? FirstVisibleSet => Items.FirstOrDefault(i => ((PlaylistItem)ItemMap[i]).MatchingFilter); + public IEnumerable> AllVisibleSets => Items.Where(i => ((PlaylistItem)ItemMap[i]).MatchingFilter); protected override OsuRearrangeableListItem> CreateOsuDrawable(Live item) => new PlaylistItem(item) diff --git a/osu.Game/Overlays/Music/PlaylistOverlay.cs b/osu.Game/Overlays/Music/PlaylistOverlay.cs index b49c794aa30b..eb1f2ff05a8c 100644 --- a/osu.Game/Overlays/Music/PlaylistOverlay.cs +++ b/osu.Game/Overlays/Music/PlaylistOverlay.cs @@ -115,14 +115,19 @@ private void beatmapsChanged(IRealmCollection sender, ChangeSet beatmapSets.Clear(); // must use AddRange to avoid RearrangeableList sort overhead per add op. beatmapSets.AddRange(sender.Select(b => b.ToLive(realm))); + return; } foreach (int i in changes.InsertedIndices) + { beatmapSets.Insert(i, sender[i].ToLive(realm)); + } foreach (int i in changes.DeletedIndices.OrderDescending()) + { beatmapSets.RemoveAt(i); + } } protected override void PopIn() diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 87920fdf551b..e8d3942ab3bb 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -60,6 +60,8 @@ public partial class MusicController : CompositeDrawable [Resolved] private IBindable> mods { get; set; } = null!; + public readonly BindableList> Playlist = new BindableList>(); + public DrawableTrack CurrentTrack { get; private set; } = new DrawableTrack(new TrackVirtual(1000)); [Resolved] @@ -275,7 +277,6 @@ private PreviousTrackResult prev(bool allowProtectedTracks) /// /// Invoked when the operation has been performed successfully. /// Whether to include beatmap sets when navigating. - /// A of the operation. public void NextTrack(Action? onSuccess = null, bool allowProtectedTracks = false) => Schedule(() => { bool res = next(allowProtectedTracks); @@ -459,9 +460,15 @@ private void restartTrack() private TrackChangeDirection? queuedDirection; - private IEnumerable> getBeatmapSets() => realm.Realm.All().Where(s => !s.DeletePending) - .AsEnumerable() - .Select(s => new RealmLive(s, realm)); + private IEnumerable> getBeatmapSets() + { + return Playlist.IsDefault + ? realm.Realm.All() + .Where(s => !s.DeletePending) + .AsEnumerable() + .Select(s => new RealmLive(s, realm)) + : Playlist.Where(s => !s.Value.DeletePending); + } private void changeBeatmap(WorkingBeatmap newWorking) {