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
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2018-05-14 08:41:35 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-01-28 08:59:14 +00:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Music
|
|
|
|
|
{
|
2020-01-28 08:59:14 +00:00
|
|
|
|
public class PlaylistList2 : BasicRearrangeableListContainer<PlaylistListItem>
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-01-28 08:59:14 +00:00
|
|
|
|
public readonly BindableList<BeatmapSetInfo> BeatmapSets = new BindableList<BeatmapSetInfo>();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
public new MarginPadding Padding
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
get => base.Padding;
|
|
|
|
|
set => base.Padding = value;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-28 08:59:14 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-01-28 08:59:14 +00:00
|
|
|
|
BeatmapSets.ItemsAdded += addBeatmapSets;
|
|
|
|
|
BeatmapSets.ItemsRemoved += removeBeatmapSets;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-28 08:59:14 +00:00
|
|
|
|
public void Filter(string searchTerm) => ((PlaylistListFlowContainer)ListContainer).SearchTerm = searchTerm;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-28 08:59:14 +00:00
|
|
|
|
public BeatmapSetInfo FirstVisibleSet => ListContainer.FlowingChildren.Cast<DrawablePlaylistListItem>().FirstOrDefault(i => i.MatchingFilter)?.Model.BeatmapSetInfo;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-28 08:59:14 +00:00
|
|
|
|
private void addBeatmapSets(IEnumerable<BeatmapSetInfo> sets) => Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in sets)
|
|
|
|
|
AddItem(new PlaylistListItem(item));
|
|
|
|
|
});
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-28 08:59:14 +00:00
|
|
|
|
private void removeBeatmapSets(IEnumerable<BeatmapSetInfo> sets) => Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in sets)
|
|
|
|
|
RemoveItem(ListContainer.Children.Select(d => d.Model).FirstOrDefault(m => m.BeatmapSetInfo == item));
|
|
|
|
|
});
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-28 08:59:14 +00:00
|
|
|
|
protected override BasicDrawableRearrangeableListItem CreateBasicItem(PlaylistListItem item) => new DrawablePlaylistListItem(item);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-28 08:59:14 +00:00
|
|
|
|
protected override FillFlowContainer<DrawableRearrangeableListItem> CreateListFillFlowContainer() => new PlaylistListFlowContainer
|
|
|
|
|
{
|
|
|
|
|
LayoutDuration = 200,
|
|
|
|
|
LayoutEasing = Easing.OutQuint
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-28 08:59:14 +00:00
|
|
|
|
public class PlaylistListFlowContainer : SearchContainer<RearrangeableListContainer<PlaylistListItem>.DrawableRearrangeableListItem>
|
|
|
|
|
{
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-28 08:59:14 +00:00
|
|
|
|
public class PlaylistListItem : IEquatable<PlaylistListItem>
|
|
|
|
|
{
|
|
|
|
|
public readonly BeatmapSetInfo BeatmapSetInfo;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-28 08:59:14 +00:00
|
|
|
|
public PlaylistListItem(BeatmapSetInfo beatmapSetInfo)
|
|
|
|
|
{
|
|
|
|
|
BeatmapSetInfo = beatmapSetInfo;
|
|
|
|
|
}
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2020-01-28 08:59:14 +00:00
|
|
|
|
public override string ToString() => BeatmapSetInfo.ToString();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-28 08:59:14 +00:00
|
|
|
|
public bool Equals(PlaylistListItem other) => BeatmapSetInfo.Equals(other?.BeatmapSetInfo);
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-28 08:59:14 +00:00
|
|
|
|
public class DrawablePlaylistListItem : BasicRearrangeableListContainer<PlaylistListItem>.BasicDrawableRearrangeableListItem, IFilterable
|
|
|
|
|
{
|
|
|
|
|
public DrawablePlaylistListItem(PlaylistListItem item)
|
|
|
|
|
: base(item)
|
|
|
|
|
{
|
|
|
|
|
FilterTerms = item.BeatmapSetInfo.Metadata.SearchableTerms;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-28 08:59:14 +00:00
|
|
|
|
public IEnumerable<string> FilterTerms { get; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-28 08:59:14 +00:00
|
|
|
|
private bool matching = true;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-28 08:59:14 +00:00
|
|
|
|
public bool MatchingFilter
|
|
|
|
|
{
|
|
|
|
|
get => matching;
|
|
|
|
|
set
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-01-28 08:59:14 +00:00
|
|
|
|
if (matching == value) return;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-28 08:59:14 +00:00
|
|
|
|
matching = value;
|
2019-03-28 15:29:07 +00:00
|
|
|
|
|
2020-01-28 08:59:14 +00:00
|
|
|
|
this.FadeTo(matching ? 1 : 0, 200);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-28 08:59:14 +00:00
|
|
|
|
|
|
|
|
|
public bool FilteringActive { get; set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|