osu/osu.Game/Overlays/Music/PlaylistList.cs

61 lines
1.8 KiB
C#
Raw Normal View History

2017-05-01 06:03:11 +00: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 06:09:14 +00:00
using System.Linq;
2017-05-01 06:03:11 +00: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 06:09:14 +00:00
items.Children = value.Select(item => new PlaylistItem(item) { OnSelect = itemSelected }).ToList();
2017-05-01 06:03:11 +00:00
}
}
2017-05-01 06:09:14 +00:00
private void itemSelected(BeatmapSetInfo b)
{
OnSelect?.Invoke(b);
}
2017-05-01 06:03:11 +00:00
2017-05-01 06:09:14 +00:00
public Action<BeatmapSetInfo> OnSelect;
public BeatmapSetInfo SelectedItem
2017-05-01 06:03:11 +00:00
{
2017-05-01 06:09:14 +00:00
get { return items.Children.FirstOrDefault(i => i.Selected)?.BeatmapSetInfo; }
2017-05-01 06:03:11 +00:00
set
{
foreach (PlaylistItem s in items.Children)
2017-05-01 06:09:14 +00:00
s.Selected = s.BeatmapSetInfo.ID == value?.ID;
2017-05-01 06:03:11 +00:00
}
}
public PlaylistList()
{
Children = new Drawable[]
{
new ScrollContainer
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
items = new FillFlowContainer<PlaylistItem>
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
},
},
},
};
}
}
}