From 3008ade8a2b2182c1daf8a4afb52b1769eb5bb8e Mon Sep 17 00:00:00 2001 From: Ganendra Afrasya Date: Fri, 11 Oct 2019 16:41:54 +0700 Subject: [PATCH] Using enum to determine the action --- osu.Game/Overlays/MusicController.cs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 9b54a6c9a6..12de2019cb 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -27,6 +27,8 @@ namespace osu.Game.Overlays public IBindableList BeatmapSets => beatmapSets; + private const double restart_cutoff_point = 5000; + private readonly BindableList beatmapSets = new BindableList(); public bool IsUserPaused { get; private set; } @@ -135,22 +137,26 @@ namespace osu.Game.Overlays return true; } + private PreviousButtonAction? prevAction; + /// - /// Play the previous track or restart the current track if it's current time below 5000ms + /// Play the previous track or restart the current track if it's current time below /// /// Whether the operation was successful. public bool PrevTrack() { var currentTrackPosition = current?.Track.CurrentTime; - if (currentTrackPosition >= 5000) + if (currentTrackPosition >= restart_cutoff_point) { SeekTo(0); + prevAction = PreviousButtonAction.Restart; return true; } queuedDirection = TrackChangeDirection.Prev; + prevAction = PreviousButtonAction.Previous; var playable = BeatmapSets.TakeWhile(i => i.ID != current.BeatmapSetInfo.ID).LastOrDefault() ?? BeatmapSets.LastOrDefault(); @@ -269,9 +275,8 @@ namespace osu.Game.Overlays return true; case GlobalAction.MusicPrev: - var shouldRestart = current?.Track.CurrentTime >= 5000; if (PrevTrack()) - onScreenDisplay?.Display(new MusicControllerToast(shouldRestart ? "Restart track" : "Previous track")); + onScreenDisplay?.Display(new MusicControllerToast(prevAction == PreviousButtonAction.Restart ? "Restart track" : "Previous track")); return true; } @@ -296,4 +301,11 @@ namespace osu.Game.Overlays Next, Prev } + + internal enum PreviousButtonAction + { + None, + Restart, + Previous + } }