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;
|
2017-07-26 12:22:46 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2017-07-12 17:57:44 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2017-05-01 14:03:11 +08:00
|
|
|
|
|
|
|
|
|
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-30 15:33:26 +08:00
|
|
|
|
public BeatmapSetInfo FirstVisibleSet => items.Children.FirstOrDefault(i => i.MatchingFilter)?.BeatmapSetInfo;
|
2017-05-05 12:59:24 +08:00
|
|
|
|
|
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[]
|
|
|
|
|
{
|
2017-07-12 17:57:44 +08:00
|
|
|
|
new OsuScrollContainer
|
2017-05-01 14:03:11 +08:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
2017-07-22 15:26:47 +08:00
|
|
|
|
public void AddBeatmapSet(BeatmapSetInfo beatmapSet)
|
|
|
|
|
{
|
|
|
|
|
items.Add(new PlaylistItem(beatmapSet) { OnSelect = itemSelected });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveBeatmapSet(BeatmapSetInfo beatmapSet)
|
|
|
|
|
{
|
2017-07-28 11:47:23 +08:00
|
|
|
|
PlaylistItem itemToRemove = items.Children.FirstOrDefault(item => item.BeatmapSetInfo.ID == beatmapSet.ID);
|
2017-07-22 15:26:47 +08:00
|
|
|
|
if (itemToRemove != null) items.Remove(itemToRemove);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-02 09:45:55 +08:00
|
|
|
|
private class ItemSearchContainer : FillFlowContainer<PlaylistItem>, IHasFilterableChildren
|
|
|
|
|
{
|
|
|
|
|
public string[] FilterTerms => new string[] { };
|
2017-05-30 15:33:26 +08:00
|
|
|
|
public bool MatchingFilter
|
2017-05-02 15:26:11 +08:00
|
|
|
|
{
|
|
|
|
|
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;
|
2017-07-23 02:50:25 +08:00
|
|
|
|
LayoutEasing = Easing.OutQuint;
|
2017-05-02 09:45:55 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-01 14:03:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|