mirror of
https://github.com/ppy/osu
synced 2025-01-18 20:10:49 +00: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 NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Timing;
|
using osu.Framework.MathUtils;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
|
using osu.Game.Rulesets.Osu;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
{
|
{
|
||||||
@ -15,22 +17,48 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
[Cached]
|
[Cached]
|
||||||
private MusicController musicController = new MusicController();
|
private MusicController musicController = new MusicController();
|
||||||
|
|
||||||
public TestSceneNowPlayingOverlay()
|
private WorkingBeatmap currentBeatmap;
|
||||||
{
|
|
||||||
Clock = new FramedClock();
|
|
||||||
|
|
||||||
var np = new NowPlayingOverlay
|
private NowPlayingOverlay nowPlayingOverlay;
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
|
||||||
|
|
||||||
|
nowPlayingOverlay = new NowPlayingOverlay
|
||||||
{
|
{
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Anchor = Anchor.Centre
|
Anchor = Anchor.Centre
|
||||||
};
|
};
|
||||||
|
|
||||||
Add(musicController);
|
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);
|
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;
|
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>();
|
private readonly BindableList<BeatmapSetInfo> beatmapSets = new BindableList<BeatmapSetInfo>();
|
||||||
|
|
||||||
public bool IsUserPaused { get; private set; }
|
public bool IsUserPaused { get; private set; }
|
||||||
@ -151,11 +156,19 @@ namespace osu.Game.Overlays
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
/// <returns>Whether the operation was successful.</returns>
|
/// <returns>The <see cref="PreviousTrackResult"/> that indicate the decided action</returns>
|
||||||
public bool PrevTrack()
|
public PreviousTrackResult PreviousTrack()
|
||||||
{
|
{
|
||||||
|
var currentTrackPosition = current?.Track.CurrentTime;
|
||||||
|
|
||||||
|
if (currentTrackPosition >= restart_cutoff_point)
|
||||||
|
{
|
||||||
|
SeekTo(0);
|
||||||
|
return PreviousTrackResult.Restart;
|
||||||
|
}
|
||||||
|
|
||||||
queuedDirection = TrackChangeDirection.Prev;
|
queuedDirection = TrackChangeDirection.Prev;
|
||||||
|
|
||||||
var playable = BeatmapSets.TakeWhile(i => i.ID != current.BeatmapSetInfo.ID).LastOrDefault() ?? BeatmapSets.LastOrDefault();
|
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);
|
working.Value = beatmaps.GetWorkingBeatmap(playable.Beatmaps.First(), beatmap.Value);
|
||||||
beatmap.Value.Track.Restart();
|
beatmap.Value.Track.Restart();
|
||||||
|
|
||||||
return true;
|
return PreviousTrackResult.Previous;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return PreviousTrackResult.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -296,8 +309,16 @@ namespace osu.Game.Overlays
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case GlobalAction.MusicPrev:
|
case GlobalAction.MusicPrev:
|
||||||
if (PrevTrack())
|
switch (PreviousTrack())
|
||||||
onScreenDisplay?.Display(new MusicControllerToast("Previous track"));
|
{
|
||||||
|
case PreviousTrackResult.Restart:
|
||||||
|
onScreenDisplay?.Display(new MusicControllerToast("Restart track"));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PreviousTrackResult.Previous:
|
||||||
|
onScreenDisplay?.Display(new MusicControllerToast("Previous track"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -322,4 +343,11 @@ namespace osu.Game.Overlays
|
|||||||
Next,
|
Next,
|
||||||
Prev
|
Prev
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum PreviousTrackResult
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Restart,
|
||||||
|
Previous
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Action = () => musicController.PrevTrack(),
|
Action = () => musicController.PreviousTrack(),
|
||||||
Icon = FontAwesome.Solid.StepBackward,
|
Icon = FontAwesome.Solid.StepBackward,
|
||||||
},
|
},
|
||||||
playButton = new MusicIconButton
|
playButton = new MusicIconButton
|
||||||
|
Loading…
Reference in New Issue
Block a user