Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom playlist music order was ignored. Queue music by filter and collection. #30343

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
17 changes: 17 additions & 0 deletions osu.Game/Overlays/Music/Playlist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,6 +23,9 @@ public partial class Playlist : OsuRearrangeableListContainer<Live<BeatmapSetInf

private FilterCriteria currentCriteria = new FilterCriteria();

[Resolved]
private MusicController musicController { get; set; } = null!;

public new MarginPadding Padding
{
get => base.Padding;
Expand All @@ -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<BeatmapSetInfo>? FirstVisibleSet => Items.FirstOrDefault(i => ((PlaylistItem)ItemMap[i]).MatchingFilter);
public IEnumerable<Live<BeatmapSetInfo>> AllVisibleSets => Items.Where(i => ((PlaylistItem)ItemMap[i]).MatchingFilter);

protected override OsuRearrangeableListItem<Live<BeatmapSetInfo>> CreateOsuDrawable(Live<BeatmapSetInfo> item) =>
new PlaylistItem(item)
Expand Down
5 changes: 5 additions & 0 deletions osu.Game/Overlays/Music/PlaylistOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,19 @@ private void beatmapsChanged(IRealmCollection<BeatmapSetInfo> 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()
Expand Down
15 changes: 11 additions & 4 deletions osu.Game/Overlays/MusicController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public partial class MusicController : CompositeDrawable
[Resolved]
private IBindable<IReadOnlyList<Mod>> mods { get; set; } = null!;

public readonly BindableList<Live<BeatmapSetInfo>> Playlist = new BindableList<Live<BeatmapSetInfo>>();

public DrawableTrack CurrentTrack { get; private set; } = new DrawableTrack(new TrackVirtual(1000));

[Resolved]
Expand Down Expand Up @@ -275,7 +277,6 @@ private PreviousTrackResult prev(bool allowProtectedTracks)
/// </summary>
/// <param name="onSuccess">Invoked when the operation has been performed successfully.</param>
/// <param name="allowProtectedTracks">Whether to include <see cref="BeatmapSetInfo.Protected"/> beatmap sets when navigating.</param>
/// <returns>A <see cref="ScheduledDelegate"/> of the operation.</returns>
public void NextTrack(Action? onSuccess = null, bool allowProtectedTracks = false) => Schedule(() =>
{
bool res = next(allowProtectedTracks);
Expand Down Expand Up @@ -459,9 +460,15 @@ private void restartTrack()

private TrackChangeDirection? queuedDirection;

private IEnumerable<Live<BeatmapSetInfo>> getBeatmapSets() => realm.Realm.All<BeatmapSetInfo>().Where(s => !s.DeletePending)
.AsEnumerable()
.Select(s => new RealmLive<BeatmapSetInfo>(s, realm));
private IEnumerable<Live<BeatmapSetInfo>> getBeatmapSets()
{
return Playlist.IsDefault
? realm.Realm.All<BeatmapSetInfo>()
.Where(s => !s.DeletePending)
.AsEnumerable()
.Select(s => new RealmLive<BeatmapSetInfo>(s, realm))
: Playlist.Where(s => !s.Value.DeletePending);
}

private void changeBeatmap(WorkingBeatmap newWorking)
{
Expand Down
Loading