1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-08 06:19:38 +08:00
osu-lazer/osu.Game/Overlays/Music/Playlist.cs

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

66 lines
2.3 KiB
C#
Raw Normal View History

2020-01-30 18:21:24 +08: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.
2022-06-17 15:37:17 +08:00
#nullable disable
2020-01-30 18:21:24 +08:00
using System;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
using osu.Game.Database;
2020-01-30 18:21:24 +08:00
using osu.Game.Graphics.Containers;
using osuTK;
namespace osu.Game.Overlays.Music
{
2022-01-26 14:12:01 +08:00
public class Playlist : OsuRearrangeableListContainer<Live<BeatmapSetInfo>>
2020-01-30 18:21:24 +08:00
{
2022-01-26 14:12:01 +08:00
public Action<Live<BeatmapSetInfo>> RequestSelection;
2020-01-30 18:21:24 +08:00
2022-01-26 14:12:01 +08:00
public readonly Bindable<Live<BeatmapSetInfo>> SelectedSet = new Bindable<Live<BeatmapSetInfo>>();
2020-01-30 18:21:24 +08:00
public new MarginPadding Padding
{
get => base.Padding;
set => base.Padding = value;
}
public void Filter(FilterCriteria criteria)
{
2022-01-26 14:12:01 +08:00
var items = (SearchContainer<RearrangeableListItem<Live<BeatmapSetInfo>>>)ListContainer;
string[] currentCollectionHashes = criteria.Collection?.PerformRead(c => c.BeatmapMD5Hashes.ToArray());
foreach (var item in items.OfType<PlaylistItem>())
{
if (currentCollectionHashes == null)
item.InSelectedCollection = true;
else
{
item.InSelectedCollection = item.Model.Value.Beatmaps.Select(b => b.MD5Hash)
.Any(currentCollectionHashes.Contains);
}
}
items.SearchTerm = criteria.SearchText;
}
2020-01-30 18:21:24 +08:00
2022-01-26 14:12:01 +08:00
public Live<BeatmapSetInfo> FirstVisibleSet => Items.FirstOrDefault(i => ((PlaylistItem)ItemMap[i]).MatchingFilter);
2020-01-30 18:21:24 +08:00
2022-01-26 14:12:01 +08:00
protected override OsuRearrangeableListItem<Live<BeatmapSetInfo>> CreateOsuDrawable(Live<BeatmapSetInfo> item) => new PlaylistItem(item)
2020-01-30 18:21:24 +08:00
{
SelectedSet = { BindTarget = SelectedSet },
RequestSelection = set => RequestSelection?.Invoke(set)
};
2022-01-26 14:12:01 +08:00
protected override FillFlowContainer<RearrangeableListItem<Live<BeatmapSetInfo>>> CreateListFillFlowContainer() => new SearchContainer<RearrangeableListItem<Live<BeatmapSetInfo>>>
2020-01-30 18:21:24 +08:00
{
Spacing = new Vector2(0, 3),
LayoutDuration = 200,
LayoutEasing = Easing.OutQuint,
};
}
}