Use play history for back and forward.

This commit is contained in:
Huo Yaoyuan
2016-11-07 21:25:37 +08:00
parent 644e337cf6
commit ad1dccf6ce

View File

@ -30,9 +30,9 @@ namespace osu.Game.Overlays
private Texture fallbackTexture; private Texture fallbackTexture;
private List<BeatmapSetInfo> playList; private List<BeatmapSetInfo> playList;
private List<BeatmapInfo> playHistory; private List<BeatmapInfo> playHistory = new List<BeatmapInfo>();
private int playListIndex; private int playListIndex;
private int playHistoryIndex; private int playHistoryIndex = -1;
private TrackManager trackManager; private TrackManager trackManager;
private BeatmapDatabase database; private BeatmapDatabase database;
@ -216,39 +216,36 @@ namespace osu.Game.Overlays
updateCurrent(current, null); updateCurrent(current, null);
} }
private int findInPlaylist(Beatmap beatmap) private void appendToHistory(BeatmapInfo beatmap)
{ {
if (beatmap == null) return -1; if (playHistoryIndex >= 0)
for (int i = 0; i < playList.Count; i++) {
if (beatmap.BeatmapInfo.BeatmapSetID == playList[i].BeatmapSetID) BeatmapInfo stackHead = playHistory[playHistoryIndex];
return i; if (beatmap.BeatmapSet.Path == stackHead.BeatmapSet.Path && beatmap.Metadata.AudioFile == stackHead.Metadata.AudioFile)
return -1; return;
if (playHistoryIndex < playHistory.Count - 1)
playHistory.RemoveRange(playHistoryIndex + 1, playHistory.Count - playHistoryIndex - 1);
}
playHistory.Insert(++playHistoryIndex, beatmap);
} }
private void prev() private void prev()
{ {
int i = findInPlaylist(current?.Beatmap); if (playHistoryIndex > 0)
if (i == -1) play(playHistory[--playHistoryIndex], false);
{
if (playList.Count > 0)
play(playList[0].Beatmaps[0], null);
else return;
}
i = (i - 1 + playList.Count) % playList.Count;
play(playList[i].Beatmaps[0], false);
} }
private void next() private void next()
{ {
int i = findInPlaylist(current?.Beatmap); if (playHistoryIndex < playHistory.Count - 1)
if (i == -1) play(playHistory[++playHistoryIndex], true);
else
{ {
if (playList.Count > 0) BeatmapInfo nextToPlay = playList[playListIndex++].Beatmaps[0];
play(playList[0].Beatmaps[0], null); if (playListIndex == playList.Count) playListIndex = 0;
else return; play(nextToPlay, true);
appendToHistory(nextToPlay);
} }
i = (i + 1) % playList.Count;
play(playList[i].Beatmaps[0], true);
} }
private void play(BeatmapInfo info, bool? isNext) private void play(BeatmapInfo info, bool? isNext)