2017-05-01 14:03:11 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-05-01 14:09:14 +08:00
|
|
|
|
using System.Linq;
|
2017-05-01 14:03:11 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Database;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Music
|
|
|
|
|
{
|
|
|
|
|
internal class PlaylistList : Container
|
|
|
|
|
{
|
|
|
|
|
private readonly FillFlowContainer<PlaylistItem> items;
|
|
|
|
|
|
|
|
|
|
public IEnumerable<BeatmapSetInfo> BeatmapSets
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-05-01 14:09:14 +08:00
|
|
|
|
items.Children = value.Select(item => new PlaylistItem(item) { OnSelect = itemSelected }).ToList();
|
2017-05-01 14:03:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 12:59:24 +08:00
|
|
|
|
public BeatmapSetInfo FirstVisibleSet => items.Children.FirstOrDefault(i => i.MatchingCurrentFilter)?.BeatmapSetInfo;
|
|
|
|
|
|
2017-05-01 14:09:14 +08:00
|
|
|
|
private void itemSelected(BeatmapSetInfo b)
|
|
|
|
|
{
|
|
|
|
|
OnSelect?.Invoke(b);
|
|
|
|
|
}
|
2017-05-01 14:03:11 +08:00
|
|
|
|
|
2017-05-01 14:09:14 +08:00
|
|
|
|
public Action<BeatmapSetInfo> OnSelect;
|
|
|
|
|
|
2017-05-02 09:45:55 +08:00
|
|
|
|
private readonly SearchContainer search;
|
|
|
|
|
|
|
|
|
|
public void Filter(string searchTerm) => search.SearchTerm = searchTerm;
|
|
|
|
|
|
2017-05-01 14:09:14 +08:00
|
|
|
|
public BeatmapSetInfo SelectedItem
|
2017-05-01 14:03:11 +08:00
|
|
|
|
{
|
2017-05-01 14:09:14 +08:00
|
|
|
|
get { return items.Children.FirstOrDefault(i => i.Selected)?.BeatmapSetInfo; }
|
2017-05-01 14:03:11 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
foreach (PlaylistItem s in items.Children)
|
2017-05-01 14:09:14 +08:00
|
|
|
|
s.Selected = s.BeatmapSetInfo.ID == value?.ID;
|
2017-05-01 14:03:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PlaylistList()
|
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new ScrollContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-05-02 09:45:55 +08:00
|
|
|
|
search = new SearchContainer
|
2017-05-01 14:03:11 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2017-05-02 09:45:55 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
items = new ItemSearchContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-01 14:03:11 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-05-02 09:45:55 +08:00
|
|
|
|
|
|
|
|
|
private class ItemSearchContainer : FillFlowContainer<PlaylistItem>, IHasFilterableChildren
|
|
|
|
|
{
|
|
|
|
|
public string[] FilterTerms => new string[] { };
|
2017-05-02 15:26:11 +08:00
|
|
|
|
public bool MatchingCurrentFilter
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-05-02 15:49:27 +08:00
|
|
|
|
if (value)
|
|
|
|
|
InvalidateLayout();
|
2017-05-02 15:26:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-02 09:45:55 +08:00
|
|
|
|
|
|
|
|
|
public IEnumerable<IFilterable> FilterableChildren => Children;
|
|
|
|
|
|
|
|
|
|
public ItemSearchContainer()
|
|
|
|
|
{
|
|
|
|
|
LayoutDuration = 200;
|
|
|
|
|
LayoutEasing = EasingTypes.OutQuint;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-01 14:03:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|