1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 15:27:26 +08:00

Use PlaylistList to manage Prev/Next tracks

This commit is contained in:
Kelvin 2017-08-28 00:56:03 -07:00
parent 5c3b7ac12c
commit 97ebf38288
3 changed files with 27 additions and 9 deletions

View File

@ -29,8 +29,8 @@ namespace osu.Game.Overlays.Music
private IEnumerable<SpriteText> titleSprites;
private UnicodeBindableString titleBind;
private UnicodeBindableString artistBind;
private FillFlowContainer<PlaylistItem> Playlist;
private readonly FillFlowContainer<PlaylistItem> Playlist;
public readonly BeatmapSetInfo BeatmapSetInfo;
public Action<BeatmapSetInfo> OnSelect;

View File

@ -46,6 +46,24 @@ namespace osu.Game.Overlays.Music
}
}
public BeatmapSetInfo NextItem
{
get
{
var available = items.Children;
return (available.SkipWhile(i => !i.Selected).Skip(1).FirstOrDefault() ?? available.FirstOrDefault())?.BeatmapSetInfo;
}
}
public BeatmapSetInfo PreviousItem
{
get
{
var available = items.Children.Reverse();
return (available.SkipWhile(i => !i.Selected).Skip(1).FirstOrDefault() ?? available.FirstOrDefault())?.BeatmapSetInfo;
}
}
public PlaylistList()
{
Children = new Drawable[]

View File

@ -126,24 +126,24 @@ namespace osu.Game.Overlays.Music
public void PlayPrevious()
{
var currentID = beatmapBacking.Value?.BeatmapSetInfo.ID ?? -1;
var available = BeatmapSets.Reverse();
var playable = available.SkipWhile(b => b.ID != currentID).Skip(1).FirstOrDefault() ?? available.FirstOrDefault();
var playable = list.PreviousItem;
if (playable != null)
{
playSpecified(playable.Beatmaps[0]);
list.SelectedItem = playable;
}
}
public void PlayNext()
{
var currentID = beatmapBacking.Value?.BeatmapSetInfo.ID ?? -1;
var available = BeatmapSets;
var playable = available.SkipWhile(b => b.ID != currentID).Skip(1).FirstOrDefault() ?? available.FirstOrDefault();
var playable = list.NextItem;
if (playable != null)
{
playSpecified(playable.Beatmaps[0]);
list.SelectedItem = playable;
}
}
private void playSpecified(BeatmapInfo info)