1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 18:47:27 +08:00
osu-lazer/osu.Game/Overlays/Music/PlaylistList.cs

96 lines
3.0 KiB
C#
Raw Normal View History

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-30 15:33:26 +08:00
public BeatmapSetInfo FirstVisibleSet => items.Children.FirstOrDefault(i => i.MatchingFilter)?.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;
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[]
{
search = new SearchContainer
2017-05-01 14:03:11 +08:00
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
items = new ItemSearchContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
},
}
}
2017-05-01 14:03:11 +08:00
},
},
};
}
private class ItemSearchContainer : FillFlowContainer<PlaylistItem>, IHasFilterableChildren
{
public string[] FilterTerms => new string[] { };
2017-05-30 15:33:26 +08:00
public bool MatchingFilter
{
set
{
2017-05-02 15:49:27 +08:00
if (value)
InvalidateLayout();
}
}
public IEnumerable<IFilterable> FilterableChildren => Children;
public ItemSearchContainer()
{
LayoutDuration = 200;
LayoutEasing = EasingTypes.OutQuint;
}
}
2017-05-01 14:03:11 +08:00
}
}