From 7d14e6e6cf5400c40b441ea3194bde80067ebf5c Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 28 Oct 2016 20:08:27 +0800 Subject: [PATCH] Make prev and next work again. --- .../Tests/TestCaseMusicController.cs | 1 - osu.Game/Overlays/MusicController.cs | 30 +++++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs b/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs index 524768a122..8706990964 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs @@ -34,7 +34,6 @@ public override void Reset() { base.Reset(); ourClock.ProcessFrame(); - mc?.CurrentTrack?.Stop(); mc = new MusicController { Origin = Anchor.Centre, diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 6692ace775..d19f982e08 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -186,6 +186,10 @@ public override void Load(BaseGame game) playButton.Icon = FontAwesome.pause; updateCurrent(beatmapSource, null); } + else if (playList.Count > 0) + { + play(playList[0].Beatmaps[0], null); + } } protected override void Update() @@ -196,22 +200,36 @@ protected override void Update() if (CurrentTrack.HasCompleted) next(); } + private int findInPlaylist(Beatmap beatmap) + { + if (beatmap == null) return -1; + for (int i = 0; i < playList.Count; i++) + if (beatmap.BeatmapInfo.BeatmapSetID == playList[i].BeatmapSetID) + return i; + return -1; + } + private void prev() { - int i = playList.IndexOf(currentPlay); + int i = findInPlaylist(beatmapSource.Value?.Beatmap); if (i == -1) return; i = (i - 1 + playList.Count) % playList.Count; - currentPlay = playList[i]; - play(currentPlay, false); + play(playList[i].Beatmaps[0], false); } private void next() { - int i = playList.IndexOf(currentPlay); + int i = findInPlaylist(beatmapSource.Value?.Beatmap); if (i == -1) return; i = (i + 1) % playList.Count; - currentPlay = playList[i]; - play(currentPlay, true); + play(playList[i].Beatmaps[0], true); + } + + private void play(BeatmapInfo info, bool? isNext) + { + WorkingBeatmap working = database.GetWorkingBeatmap(info, beatmapSource.Value); + beatmapSource.Value = working; + updateCurrent(working, isNext); } private void updateCurrent(WorkingBeatmap beatmap, bool? isNext)