1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 03:07:26 +08:00
osu-lazer/osu.Game/Overlays/Music/PlaylistOverlay.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

168 lines
5.6 KiB
C#
Raw Normal View History

// 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 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
using System;
2017-05-01 14:03:11 +08:00
using System.Linq;
using osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2017-05-01 14:03:11 +08:00
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Extensions.EnumExtensions;
2017-05-01 14:03:11 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2019-04-02 13:51:28 +08:00
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
2017-05-01 14:03:11 +08:00
using osu.Game.Beatmaps;
using osu.Game.Database;
2017-05-01 14:03:11 +08:00
using osu.Game.Graphics;
2018-11-20 15:51:59 +08:00
using osuTK;
using osuTK.Graphics;
using Realms;
2018-04-13 17:19:50 +08:00
2017-05-01 14:03:11 +08:00
namespace osu.Game.Overlays.Music
{
public partial class PlaylistOverlay : VisibilityContainer
2017-05-01 14:03:11 +08:00
{
private const float transition_duration = 600;
public const float PLAYLIST_HEIGHT = 510;
2018-04-13 17:19:50 +08:00
2022-01-26 14:12:01 +08:00
private readonly BindableList<Live<BeatmapSetInfo>> beatmapSets = new BindableList<Live<BeatmapSetInfo>>();
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
2020-02-14 21:14:00 +08:00
[Resolved]
private BeatmapManager beatmaps { get; set; }
[Resolved]
private RealmAccess realm { get; set; }
private IDisposable beatmapSubscription;
private FilterControl filter;
2020-01-30 18:21:24 +08:00
private Playlist list;
2017-05-01 14:03:11 +08:00
[BackgroundDependencyLoader]
2020-02-14 21:14:00 +08:00
private void load(OsuColour colours, Bindable<WorkingBeatmap> beatmap)
2017-05-01 14:03:11 +08:00
{
this.beatmap.BindTo(beatmap);
2018-04-13 17:19:50 +08:00
2017-05-01 14:03:11 +08:00
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
CornerRadius = 5,
Masking = true,
2017-06-12 11:48:47 +08:00
EdgeEffect = new EdgeEffectParameters
2017-05-01 14:03:11 +08: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 18:21:24 +08:00
list = new Playlist
2017-05-01 14:03:11 +08:00
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = 95, Bottom = 10, Right = 10 },
RequestSelection = itemSelected
2017-05-01 14:03:11 +08:00
},
filter = new FilterControl
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
FilterChanged = criteria => list.Filter(criteria),
2017-05-01 14:03:11 +08:00
Padding = new MarginPadding(10),
},
},
},
};
2018-04-13 17:19:50 +08:00
2022-06-24 20:25:23 +08:00
filter.Search.OnCommit += (_, _) =>
2017-07-18 16:24:09 +08:00
{
list.FirstVisibleSet?.PerformRead(set =>
2020-08-05 21:32:44 +08:00
{
BeatmapInfo toSelect = set.Beatmaps.FirstOrDefault();
if (toSelect != null)
{
beatmap.Value = beatmaps.GetWorkingBeatmap(toSelect);
beatmap.Value.Track.Restart();
}
});
};
}
protected override void LoadComplete()
{
base.LoadComplete();
beatmapSubscription = realm.RegisterForNotifications(r => r.All<BeatmapSetInfo>().Where(s => !s.DeletePending), beatmapsChanged);
list.Items.BindTo(beatmapSets);
beatmap.BindValueChanged(working => list.SelectedSet.Value = working.NewValue.BeatmapSetInfo.ToLive(realm), true);
2017-05-01 14:03:11 +08:00
}
2018-04-13 17:19:50 +08:00
2023-07-06 12:37:42 +08:00
private void beatmapsChanged(IRealmCollection<BeatmapSetInfo> sender, ChangeSet changes)
{
if (changes == null)
{
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.OrderByDescending(i => i))
beatmapSets.RemoveAt(i);
}
2017-05-01 14:03:11 +08:00
protected override void PopIn()
{
filter.Search.HoldFocus = true;
Schedule(() => filter.Search.TakeFocus());
2018-04-13 17:19:50 +08:00
this.ResizeTo(new Vector2(1, RelativeSizeAxes.HasFlagFast(Axes.Y) ? 1f : PLAYLIST_HEIGHT), transition_duration, Easing.OutQuint);
2017-07-23 02:50:25 +08:00
this.FadeIn(transition_duration, Easing.OutQuint);
2017-05-01 14:03:11 +08:00
}
2018-04-13 17:19:50 +08:00
2017-05-01 14:03:11 +08:00
protected override void PopOut()
{
filter.Search.HoldFocus = false;
2018-04-13 17:19:50 +08:00
2017-07-23 02:50:25 +08:00
this.ResizeTo(new Vector2(1, 0), transition_duration, Easing.OutQuint);
this.FadeOut(transition_duration);
2017-05-01 14:03:11 +08:00
}
2018-04-13 17:19:50 +08:00
2022-01-26 14:12:01 +08:00
private void itemSelected(Live<BeatmapSetInfo> beatmapSet)
2017-05-01 14:03:11 +08:00
{
beatmapSet.PerformRead(set =>
2017-05-01 14:03:11 +08:00
{
if (set.Equals((beatmap.Value?.BeatmapSetInfo)))
{
beatmap.Value?.Track.Seek(0);
return;
}
2018-04-13 17:19:50 +08:00
beatmap.Value = beatmaps.GetWorkingBeatmap(set.Beatmaps.First());
beatmap.Value.Track.Restart();
});
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
beatmapSubscription?.Dispose();
}
2017-05-01 14:03:11 +08:00
}
}