mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 09:07:52 +08:00
Merge pull request #6464 from GSculerlor/prev-button-revamp
Make previous track button restart current track on first click
This commit is contained in:
commit
7156e1e817
@ -4,8 +4,10 @@
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Framework.MathUtils;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
@ -15,22 +17,48 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
[Cached]
|
||||
private MusicController musicController = new MusicController();
|
||||
|
||||
public TestSceneNowPlayingOverlay()
|
||||
{
|
||||
Clock = new FramedClock();
|
||||
private WorkingBeatmap currentBeatmap;
|
||||
|
||||
var np = new NowPlayingOverlay
|
||||
private NowPlayingOverlay nowPlayingOverlay;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
|
||||
|
||||
nowPlayingOverlay = new NowPlayingOverlay
|
||||
{
|
||||
Origin = Anchor.Centre,
|
||||
Anchor = Anchor.Centre
|
||||
};
|
||||
|
||||
Add(musicController);
|
||||
Add(np);
|
||||
Add(nowPlayingOverlay);
|
||||
}
|
||||
|
||||
AddStep(@"show", () => np.Show());
|
||||
[Test]
|
||||
public void TestShowHideDisable()
|
||||
{
|
||||
AddStep(@"show", () => nowPlayingOverlay.Show());
|
||||
AddToggleStep(@"toggle beatmap lock", state => Beatmap.Disabled = state);
|
||||
AddStep(@"show", () => np.Hide());
|
||||
AddStep(@"hide", () => nowPlayingOverlay.Hide());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPrevTrackBehavior()
|
||||
{
|
||||
AddStep(@"Play track", () =>
|
||||
{
|
||||
musicController.NextTrack();
|
||||
currentBeatmap = Beatmap.Value;
|
||||
});
|
||||
|
||||
AddStep(@"Seek track to 6 second", () => musicController.SeekTo(6000));
|
||||
AddUntilStep(@"Wait for current time to update", () => currentBeatmap.Track.CurrentTime > 5000);
|
||||
AddAssert(@"Check action is restart track", () => musicController.PreviousTrack() == PreviousTrackResult.Restart);
|
||||
AddUntilStep("Wait for current time to update", () => Precision.AlmostEquals(currentBeatmap.Track.CurrentTime, 0));
|
||||
AddAssert(@"Check track didn't change", () => currentBeatmap == Beatmap.Value);
|
||||
AddAssert(@"Check action is not restart", () => musicController.PreviousTrack() != PreviousTrackResult.Restart);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,11 @@ namespace osu.Game.Overlays
|
||||
|
||||
public IBindableList<BeatmapSetInfo> BeatmapSets => beatmapSets;
|
||||
|
||||
/// <summary>
|
||||
/// Point in time after which the current track will be restarted on triggering a "previous track" action.
|
||||
/// </summary>
|
||||
private const double restart_cutoff_point = 5000;
|
||||
|
||||
private readonly BindableList<BeatmapSetInfo> beatmapSets = new BindableList<BeatmapSetInfo>();
|
||||
|
||||
public bool IsUserPaused { get; private set; }
|
||||
@ -151,11 +156,19 @@ namespace osu.Game.Overlays
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Play the previous track.
|
||||
/// Play the previous track or restart the current track if it's current time below <see cref="restart_cutoff_point"/>
|
||||
/// </summary>
|
||||
/// <returns>Whether the operation was successful.</returns>
|
||||
public bool PrevTrack()
|
||||
/// <returns>The <see cref="PreviousTrackResult"/> that indicate the decided action</returns>
|
||||
public PreviousTrackResult PreviousTrack()
|
||||
{
|
||||
var currentTrackPosition = current?.Track.CurrentTime;
|
||||
|
||||
if (currentTrackPosition >= restart_cutoff_point)
|
||||
{
|
||||
SeekTo(0);
|
||||
return PreviousTrackResult.Restart;
|
||||
}
|
||||
|
||||
queuedDirection = TrackChangeDirection.Prev;
|
||||
|
||||
var playable = BeatmapSets.TakeWhile(i => i.ID != current.BeatmapSetInfo.ID).LastOrDefault() ?? BeatmapSets.LastOrDefault();
|
||||
@ -166,10 +179,10 @@ namespace osu.Game.Overlays
|
||||
working.Value = beatmaps.GetWorkingBeatmap(playable.Beatmaps.First(), beatmap.Value);
|
||||
beatmap.Value.Track.Restart();
|
||||
|
||||
return true;
|
||||
return PreviousTrackResult.Previous;
|
||||
}
|
||||
|
||||
return false;
|
||||
return PreviousTrackResult.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -296,8 +309,16 @@ namespace osu.Game.Overlays
|
||||
return true;
|
||||
|
||||
case GlobalAction.MusicPrev:
|
||||
if (PrevTrack())
|
||||
onScreenDisplay?.Display(new MusicControllerToast("Previous track"));
|
||||
switch (PreviousTrack())
|
||||
{
|
||||
case PreviousTrackResult.Restart:
|
||||
onScreenDisplay?.Display(new MusicControllerToast("Restart track"));
|
||||
break;
|
||||
|
||||
case PreviousTrackResult.Previous:
|
||||
onScreenDisplay?.Display(new MusicControllerToast("Previous track"));
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -322,4 +343,11 @@ namespace osu.Game.Overlays
|
||||
Next,
|
||||
Prev
|
||||
}
|
||||
|
||||
public enum PreviousTrackResult
|
||||
{
|
||||
None,
|
||||
Restart,
|
||||
Previous
|
||||
}
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ namespace osu.Game.Overlays
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Action = () => musicController.PrevTrack(),
|
||||
Action = () => musicController.PreviousTrack(),
|
||||
Icon = FontAwesome.Solid.StepBackward,
|
||||
},
|
||||
playButton = new MusicIconButton
|
||||
|
Loading…
Reference in New Issue
Block a user