2019-01-24 08:43:03 +00:00
|
|
|
|
// 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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2022-01-21 16:18:21 +00:00
|
|
|
|
using System;
|
2017-05-01 06:03:11 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2017-05-01 06:03:11 +00:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-04-02 05:51:28 +00:00
|
|
|
|
using osu.Framework.Graphics.Effects;
|
2017-06-21 10:23:38 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-05-01 06:03:11 +00:00
|
|
|
|
using osu.Game.Beatmaps;
|
2022-01-21 16:18:21 +00:00
|
|
|
|
using osu.Game.Database;
|
2017-05-01 06:03:11 +00:00
|
|
|
|
using osu.Game.Graphics;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2022-01-21 16:18:21 +00:00
|
|
|
|
using Realms;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-05-01 06:03:11 +00:00
|
|
|
|
namespace osu.Game.Overlays.Music
|
|
|
|
|
{
|
2019-10-14 23:40:53 +00:00
|
|
|
|
public class PlaylistOverlay : VisibilityContainer
|
2017-05-01 06:03:11 +00:00
|
|
|
|
{
|
|
|
|
|
private const float transition_duration = 600;
|
|
|
|
|
private const float playlist_height = 510;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-01-26 06:12:01 +00:00
|
|
|
|
public IBindableList<Live<BeatmapSetInfo>> BeatmapSets => beatmapSets;
|
2020-01-30 10:00:59 +00:00
|
|
|
|
|
2022-01-26 06:12:01 +00:00
|
|
|
|
private readonly BindableList<Live<BeatmapSetInfo>> beatmapSets = new BindableList<Live<BeatmapSetInfo>>();
|
2020-01-28 08:59:14 +00:00
|
|
|
|
|
2018-06-06 11:19:30 +00:00
|
|
|
|
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
|
2020-02-14 13:14:00 +00:00
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private BeatmapManager beatmaps { get; set; }
|
2018-05-23 08:37:39 +00:00
|
|
|
|
|
2022-01-21 16:18:21 +00:00
|
|
|
|
[Resolved]
|
2022-01-21 19:27:07 +00:00
|
|
|
|
private RealmAccess realm { get; set; }
|
2022-01-21 16:18:21 +00:00
|
|
|
|
|
|
|
|
|
private IDisposable beatmapSubscription;
|
|
|
|
|
|
2018-05-14 08:41:35 +00:00
|
|
|
|
private FilterControl filter;
|
2020-01-30 10:21:24 +00:00
|
|
|
|
private Playlist list;
|
2020-01-29 03:17:03 +00:00
|
|
|
|
|
2017-05-01 06:03:11 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
2020-02-14 13:14:00 +00:00
|
|
|
|
private void load(OsuColour colours, Bindable<WorkingBeatmap> beatmap)
|
2017-05-01 06:03:11 +00:00
|
|
|
|
{
|
2018-06-06 11:19:30 +00:00
|
|
|
|
this.beatmap.BindTo(beatmap);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-05-01 06:03:11 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
CornerRadius = 5,
|
|
|
|
|
Masking = true,
|
2017-06-12 03:48:47 +00:00
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
2017-05-01 06:03:11 +00:00
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
|
Colour = Color4.Black.Opacity(40),
|
|
|
|
|
Radius = 5,
|
|
|
|
|
},
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
Colour = colours.Gray3,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
2020-01-30 10:21:24 +00:00
|
|
|
|
list = new Playlist
|
2017-05-01 06:03:11 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Padding = new MarginPadding { Top = 95, Bottom = 10, Right = 10 },
|
2020-01-29 03:17:03 +00:00
|
|
|
|
RequestSelection = itemSelected
|
2017-05-01 06:03:11 +00:00
|
|
|
|
},
|
|
|
|
|
filter = new FilterControl
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2020-09-11 07:46:11 +00:00
|
|
|
|
FilterChanged = criteria => list.Filter(criteria),
|
2017-05-01 06:03:11 +00:00
|
|
|
|
Padding = new MarginPadding(10),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-06-24 12:25:23 +00:00
|
|
|
|
filter.Search.OnCommit += (_, _) =>
|
2017-07-18 08:24:09 +00:00
|
|
|
|
{
|
2022-02-09 01:16:43 +00:00
|
|
|
|
list.FirstVisibleSet?.PerformRead(set =>
|
2020-08-05 13:32:44 +00:00
|
|
|
|
{
|
2022-01-26 03:19:05 +00:00
|
|
|
|
BeatmapInfo toSelect = set.Beatmaps.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (toSelect != null)
|
|
|
|
|
{
|
|
|
|
|
beatmap.Value = beatmaps.GetWorkingBeatmap(toSelect);
|
|
|
|
|
beatmap.Value.Track.Restart();
|
|
|
|
|
}
|
|
|
|
|
});
|
2017-05-05 04:59:24 +00:00
|
|
|
|
};
|
2020-02-17 07:59:35 +00:00
|
|
|
|
}
|
2020-01-29 03:17:03 +00:00
|
|
|
|
|
2020-02-17 07:59:35 +00:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2022-01-21 16:18:21 +00:00
|
|
|
|
// tests might bind externally, in which case we don't want to involve realm.
|
|
|
|
|
if (beatmapSets.Count == 0)
|
2022-01-26 02:53:50 +00:00
|
|
|
|
beatmapSubscription = realm.RegisterForNotifications(r => r.All<BeatmapSetInfo>().Where(s => !s.DeletePending), beatmapsChanged);
|
2022-01-21 16:18:21 +00:00
|
|
|
|
|
2020-02-17 07:59:35 +00:00
|
|
|
|
list.Items.BindTo(beatmapSets);
|
2022-01-26 03:19:05 +00:00
|
|
|
|
beatmap.BindValueChanged(working => list.SelectedSet.Value = working.NewValue.BeatmapSetInfo.ToLive(realm), true);
|
2017-05-01 06:03:11 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-01-21 16:18:21 +00:00
|
|
|
|
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.
|
2022-01-26 10:04:18 +00:00
|
|
|
|
beatmapSets.AddRange(sender.Select(b => b.ToLive(realm)));
|
2022-01-21 16:18:21 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (int i in changes.InsertedIndices)
|
2022-01-26 03:19:05 +00:00
|
|
|
|
beatmapSets.Insert(i, sender[i].ToLive(realm));
|
2022-01-21 16:18:21 +00:00
|
|
|
|
|
|
|
|
|
foreach (int i in changes.DeletedIndices.OrderByDescending(i => i))
|
|
|
|
|
beatmapSets.RemoveAt(i);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-01 06:03:11 +00:00
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
filter.Search.HoldFocus = true;
|
2019-01-25 10:20:08 +00:00
|
|
|
|
Schedule(() => filter.Search.TakeFocus());
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-07-22 18:50:25 +00:00
|
|
|
|
this.ResizeTo(new Vector2(1, playlist_height), transition_duration, Easing.OutQuint);
|
|
|
|
|
this.FadeIn(transition_duration, Easing.OutQuint);
|
2017-05-01 06:03:11 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-05-01 06:03:11 +00:00
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
|
|
|
|
filter.Search.HoldFocus = false;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-07-22 18:50:25 +00:00
|
|
|
|
this.ResizeTo(new Vector2(1, 0), transition_duration, Easing.OutQuint);
|
2017-07-14 16:18:12 +00:00
|
|
|
|
this.FadeOut(transition_duration);
|
2017-05-01 06:03:11 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-01-26 06:12:01 +00:00
|
|
|
|
private void itemSelected(Live<BeatmapSetInfo> beatmapSet)
|
2017-05-01 06:03:11 +00:00
|
|
|
|
{
|
2022-01-26 03:19:05 +00:00
|
|
|
|
beatmapSet.PerformRead(set =>
|
2017-05-01 06:03:11 +00:00
|
|
|
|
{
|
2022-01-26 03:19:05 +00:00
|
|
|
|
if (set.Equals((beatmap.Value?.BeatmapSetInfo)))
|
|
|
|
|
{
|
|
|
|
|
beatmap.Value?.Track.Seek(0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-01-26 03:19:05 +00:00
|
|
|
|
beatmap.Value = beatmaps.GetWorkingBeatmap(set.Beatmaps.First());
|
|
|
|
|
beatmap.Value.Track.Restart();
|
|
|
|
|
});
|
2018-04-09 03:45:44 +00:00
|
|
|
|
}
|
2022-01-21 16:18:21 +00:00
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
beatmapSubscription?.Dispose();
|
|
|
|
|
}
|
2017-05-01 06:03:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|