Use playlist queue

This commit is contained in:
DrabWeb 2017-04-09 06:11:53 -03:00
parent fe17cb924d
commit a88c82705b
2 changed files with 47 additions and 59 deletions

View File

@ -23,6 +23,7 @@ using osu.Game.Graphics;
using osu.Framework.Graphics.Primitives;
using osu.Game.Graphics.Sprites;
using osu.Framework.Extensions.Color4Extensions;
using System.Linq;
namespace osu.Game.Overlays
{
@ -39,9 +40,7 @@ namespace osu.Game.Overlays
private Color4 activeColour;
private List<BeatmapSetInfo> playList;
private readonly List<BeatmapInfo> playHistory = new List<BeatmapInfo>();
private int playListIndex;
private int playHistoryIndex = -1;
private int playListIndex = -1;
private TrackManager trackManager;
private Bindable<WorkingBeatmap> beatmapSource;
@ -64,6 +63,8 @@ namespace osu.Game.Overlays
Margin = new MarginPadding(10);
}
protected override bool InternalContains(Vector2 screenSpacePos) => playlist.State == Visibility.Visible ? dragContainer.Contains(screenSpacePos) : playerContainer.Contains(screenSpacePos);
protected override bool OnDragStart(InputState state) => true;
protected override bool OnDrag(InputState state)
@ -104,12 +105,13 @@ namespace osu.Game.Overlays
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = player_height + 10 },
//todo: this is the logic I expect, but maybe not others
OnSelect = (set) =>
OnSelect = (set, index) =>
{
if (set.ID == (current?.BeatmapSetInfo?.ID ?? -1))
current?.Track?.Seek(0);
play(set.Beatmaps[0], true);
play(set.Beatmaps[0], true);
playListIndex = index;
},
},
playerContainer = new Container
@ -220,7 +222,6 @@ namespace osu.Game.Overlays
preferUnicode.ValueChanged += unicode => updateDisplay(current, TransformDirection.None);
beatmapSource = game.Beatmap ?? new Bindable<WorkingBeatmap>();
//playList = playlist;
currentBackground = new MusicControllerBackground();
playerContainer.Add(currentBackground);
@ -231,6 +232,7 @@ namespace osu.Game.Overlays
{
beatmapSource.ValueChanged += workingChanged;
beatmapSource.TriggerChange();
playList = playlist.List.ToList();
base.LoadComplete();
}
@ -263,57 +265,32 @@ namespace osu.Game.Overlays
bool audioEquals = current?.BeatmapInfo?.AudioEquals(beatmap?.BeatmapInfo) ?? false;
current = beatmap;
updateDisplay(current, audioEquals ? TransformDirection.None : TransformDirection.Next);
appendToHistory(current?.BeatmapInfo);
}
private void appendToHistory(BeatmapInfo beatmap)
{
if (beatmap == null) return;
if (playHistoryIndex >= 0)
{
if (beatmap.AudioEquals(playHistory[playHistoryIndex]))
return;
if (playHistoryIndex < playHistory.Count - 1)
playHistory.RemoveRange(playHistoryIndex + 1, playHistory.Count - playHistoryIndex - 1);
}
playHistory.Insert(++playHistoryIndex, beatmap);
}
private void prev()
{
if (playHistoryIndex > 0)
play(playHistory[--playHistoryIndex], false);
if (playList.Count == 0) return;
if (current != null && playList.Count == 1) return;
int n = playListIndex - 1;
if (n < 0)
n = playList.Count - 1;
play(playList[n].Beatmaps[0], false);
playListIndex = n;
}
private void next()
{
if (playHistoryIndex < playHistory.Count - 1)
play(playHistory[++playHistoryIndex], true);
else
{
if (playList.Count == 0) return;
if (current != null && playList.Count == 1) return;
//shuffle
BeatmapInfo nextToPlay;
do
{
int j = RNG.Next(playListIndex, playList.Count);
if (j != playListIndex)
{
BeatmapSetInfo temp = playList[playListIndex];
playList[playListIndex] = playList[j];
playList[j] = temp;
}
if (playList.Count == 0) return;
if (current != null && playList.Count == 1) return;
nextToPlay = playList[playListIndex++].Beatmaps[0];
if (playListIndex == playList.Count) playListIndex = 0;
}
while (nextToPlay.AudioEquals(current?.BeatmapInfo));
play(nextToPlay, true);
appendToHistory(nextToPlay);
}
int n = playListIndex + 1;
if (n >= playList.Count)
n = 0;
play(playList[n].Beatmaps[0], true);
playListIndex = n;
}
private void play(BeatmapInfo info, bool isNext)

View File

@ -28,7 +28,15 @@ namespace osu.Game.Overlays
private FilterControl filter;
private Playlist list;
public Action<BeatmapSetInfo> OnSelect
public BeatmapSetInfo[] List
{
get
{
return list.Sets;
}
}
public Action<BeatmapSetInfo,int> OnSelect
{
get { return list.OnSelect; }
set { list.OnSelect = value; }
@ -223,11 +231,12 @@ namespace osu.Game.Overlays
sets = value;
List<PlaylistItem> newItems = new List<PlaylistItem>();
foreach (BeatmapSetInfo s in value)
for (int i = 0; i < value.Length; i++)
{
newItems.Add(new PlaylistItem(s)
{
OnSelect = OnSelect,
newItems.Add(new PlaylistItem(value[i], i)
{
OnSelect = OnSelect,
});
}
@ -239,8 +248,8 @@ namespace osu.Game.Overlays
// because the scroller can be seen when scrolled to the bottom and PlaylistController is closed
public readonly ScrollContainer ScrollContainer;
private Action<BeatmapSetInfo> onSelect;
public Action<BeatmapSetInfo> OnSelect
private Action<BeatmapSetInfo,int> onSelect;
public Action<BeatmapSetInfo,int> OnSelect
{
get { return onSelect; }
set
@ -293,8 +302,9 @@ namespace osu.Game.Overlays
private TextAwesome icon;
private OsuSpriteText title, artist;
public readonly int Index;
public readonly BeatmapSetInfo RepresentedSet;
public Action<BeatmapSetInfo> OnSelect;
public Action<BeatmapSetInfo,int> OnSelect;
private bool current;
public bool Current
@ -309,8 +319,9 @@ namespace osu.Game.Overlays
}
}
public PlaylistItem(BeatmapSetInfo set)
public PlaylistItem(BeatmapSetInfo set, int index)
{
Index = index;
RepresentedSet = set;
RelativeSizeAxes = Axes.X;
@ -377,7 +388,7 @@ namespace osu.Game.Overlays
protected override bool OnClick(Framework.Input.InputState state)
{
OnSelect?.Invoke(RepresentedSet);
OnSelect?.Invoke(RepresentedSet, Index);
return true;
}
}