mirror of
https://github.com/ppy/osu
synced 2024-12-14 02:46:27 +00:00
Reimplement subscription logic in PlaylistOverlay
directly
This commit is contained in:
parent
958cfde608
commit
8a4f3a7ce0
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
@ -10,9 +11,11 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Graphics.Effects;
|
using osu.Framework.Graphics.Effects;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Database;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
using Realms;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Music
|
namespace osu.Game.Overlays.Music
|
||||||
{
|
{
|
||||||
@ -30,6 +33,15 @@ namespace osu.Game.Overlays.Music
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private BeatmapManager beatmaps { get; set; }
|
private BeatmapManager beatmaps { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private RealmContextFactory realmFactory { get; set; }
|
||||||
|
|
||||||
|
private IDisposable beatmapSubscription;
|
||||||
|
|
||||||
|
private IQueryable<BeatmapSetInfo> availableBeatmaps => realmFactory.Context
|
||||||
|
.All<BeatmapSetInfo>()
|
||||||
|
.Where(s => !s.DeletePending);
|
||||||
|
|
||||||
private FilterControl filter;
|
private FilterControl filter;
|
||||||
private Playlist list;
|
private Playlist list;
|
||||||
|
|
||||||
@ -91,10 +103,31 @@ namespace osu.Game.Overlays.Music
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
|
// tests might bind externally, in which case we don't want to involve realm.
|
||||||
|
if (beatmapSets.Count == 0)
|
||||||
|
beatmapSubscription = realmFactory.RegisterForNotifications(realm => availableBeatmaps, beatmapsChanged);
|
||||||
|
|
||||||
list.Items.BindTo(beatmapSets);
|
list.Items.BindTo(beatmapSets);
|
||||||
beatmap.BindValueChanged(working => list.SelectedSet.Value = working.NewValue.BeatmapSetInfo, true);
|
beatmap.BindValueChanged(working => list.SelectedSet.Value = working.NewValue.BeatmapSetInfo, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void beatmapsChanged(IRealmCollection<BeatmapSetInfo> sender, ChangeSet changes, Exception error)
|
||||||
|
{
|
||||||
|
if (changes == null)
|
||||||
|
{
|
||||||
|
beatmapSets.Clear();
|
||||||
|
// must use AddRange to avoid RearrangeableList sort overhead per add op.
|
||||||
|
beatmapSets.AddRange(sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (int i in changes.InsertedIndices)
|
||||||
|
beatmapSets.Insert(i, sender[i]);
|
||||||
|
|
||||||
|
foreach (int i in changes.DeletedIndices.OrderByDescending(i => i))
|
||||||
|
beatmapSets.RemoveAt(i);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void PopIn()
|
protected override void PopIn()
|
||||||
{
|
{
|
||||||
filter.Search.HoldFocus = true;
|
filter.Search.HoldFocus = true;
|
||||||
@ -123,5 +156,11 @@ namespace osu.Game.Overlays.Music
|
|||||||
beatmap.Value = beatmaps.GetWorkingBeatmap(set.Beatmaps.First());
|
beatmap.Value = beatmaps.GetWorkingBeatmap(set.Beatmaps.First());
|
||||||
beatmap.Value.Track.Restart();
|
beatmap.Value.Track.Restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool isDisposing)
|
||||||
|
{
|
||||||
|
base.Dispose(isDisposing);
|
||||||
|
beatmapSubscription?.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user