1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 17:52:56 +08:00

Merge pull request #19594 from BlauFx/improve_retry_behaviour

Skip song intro on quick restart
This commit is contained in:
Dan Balasescu 2022-08-16 20:18:12 +09:00 committed by GitHub
commit 24fd411720
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 78 additions and 10 deletions

View File

@ -29,6 +29,7 @@ using osu.Game.Screens.Play;
using osu.Game.Screens.Play.PlayerSettings;
using osu.Game.Utils;
using osuTK.Input;
using SkipOverlay = osu.Game.Screens.Play.SkipOverlay;
namespace osu.Game.Tests.Visual.Gameplay
{
@ -98,7 +99,13 @@ namespace osu.Game.Tests.Visual.Gameplay
private void prepareBeatmap()
{
var workingBeatmap = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
// Add intro time to test quick retry skipping (TestQuickRetry).
workingBeatmap.BeatmapInfo.AudioLeadIn = 60000;
// Turn on epilepsy warning to test warning display (TestEpilepsyWarning).
workingBeatmap.BeatmapInfo.EpilepsyWarning = epilepsyWarning;
Beatmap.Value = workingBeatmap;
foreach (var mod in SelectedMods.Value.OfType<IApplicableToTrack>())
@ -400,6 +407,37 @@ namespace osu.Game.Tests.Visual.Gameplay
});
}
[Test]
public void TestQuickRetry()
{
TestPlayer getCurrentPlayer() => loader.CurrentPlayer as TestPlayer;
bool checkSkipButtonVisible() => player.ChildrenOfType<SkipOverlay>().FirstOrDefault()?.IsButtonVisible == true;
TestPlayer previousPlayer = null;
AddStep("load dummy beatmap", () => resetPlayer(false));
AddUntilStep("wait for current", () => getCurrentPlayer()?.IsCurrentScreen() == true);
AddStep("store previous player", () => previousPlayer = getCurrentPlayer());
AddStep("Restart map normally", () => getCurrentPlayer().Restart());
AddUntilStep("wait for load", () => getCurrentPlayer()?.LoadedBeatmapSuccessfully == true);
AddUntilStep("restart completed", () => getCurrentPlayer() != null && getCurrentPlayer() != previousPlayer);
AddStep("store previous player", () => previousPlayer = getCurrentPlayer());
AddUntilStep("skip button visible", checkSkipButtonVisible);
AddStep("press quick retry key", () => InputManager.PressKey(Key.Tilde));
AddUntilStep("restart completed", () => getCurrentPlayer() != null && getCurrentPlayer() != previousPlayer);
AddStep("release quick retry key", () => InputManager.ReleaseKey(Key.Tilde));
AddUntilStep("wait for load", () => getCurrentPlayer()?.LoadedBeatmapSuccessfully == true);
AddUntilStep("time reached zero", () => getCurrentPlayer()?.GameplayClockContainer.CurrentTime > 0);
AddUntilStep("skip button not visible", () => !checkSkipButtonVisible());
}
private EpilepsyWarning getWarning() => loader.ChildrenOfType<EpilepsyWarning>().SingleOrDefault();
private class TestPlayerLoader : PlayerLoader

View File

@ -23,7 +23,7 @@ namespace osu.Game.Tests.Visual.Mods
protected override TestPlayer CreateModPlayer(Ruleset ruleset)
{
var player = base.CreateModPlayer(ruleset);
player.RestartRequested = () => restartRequested = true;
player.RestartRequested = _ => restartRequested = true;
return player;
}

View File

@ -77,7 +77,7 @@ namespace osu.Game.Screens.Play
/// </summary>
protected virtual bool PauseOnFocusLost => true;
public Action RestartRequested;
public Action<bool> RestartRequested;
private bool isRestarting;
@ -267,7 +267,7 @@ namespace osu.Game.Screens.Play
FailOverlay = new FailOverlay
{
SaveReplay = prepareAndImportScore,
OnRetry = Restart,
OnRetry = () => Restart(),
OnQuit = () => PerformExit(true),
},
new HotkeyExitOverlay
@ -294,7 +294,7 @@ namespace osu.Game.Screens.Play
if (!this.IsCurrentScreen()) return;
fadeOut(true);
Restart();
Restart(true);
},
});
}
@ -371,6 +371,9 @@ namespace osu.Game.Screens.Play
IsBreakTime.BindTo(breakTracker.IsBreakTime);
IsBreakTime.BindValueChanged(onBreakTimeChanged, true);
if (Configuration.AutomaticallySkipIntro)
skipIntroOverlay.SkipWhenReady();
}
protected virtual GameplayClockContainer CreateGameplayClockContainer(WorkingBeatmap beatmap, double gameplayStart) => new MasterGameplayClockContainer(beatmap, gameplayStart);
@ -441,7 +444,7 @@ namespace osu.Game.Screens.Play
{
OnResume = Resume,
Retries = RestartCount,
OnRetry = Restart,
OnRetry = () => Restart(),
OnQuit = () => PerformExit(true),
},
},
@ -648,7 +651,8 @@ namespace osu.Game.Screens.Play
/// Restart gameplay via a parent <see cref="PlayerLoader"/>.
/// <remarks>This can be called from a child screen in order to trigger the restart process.</remarks>
/// </summary>
public void Restart()
/// <param name="quickRestart">Whether a quick restart was requested (skipping intro etc.).</param>
public void Restart(bool quickRestart = false)
{
if (!Configuration.AllowRestart)
return;
@ -660,7 +664,7 @@ namespace osu.Game.Screens.Play
musicController.Stop();
sampleRestart?.Play();
RestartRequested?.Invoke();
RestartRequested?.Invoke(quickRestart);
PerformExit(false);
}
@ -840,7 +844,7 @@ namespace osu.Game.Screens.Play
failAnimationLayer.Start();
if (GameplayState.Mods.OfType<IApplicableFailOverride>().Any(m => m.RestartOnFail))
Restart();
Restart(true);
return true;
}

View File

@ -31,5 +31,10 @@ namespace osu.Game.Screens.Play
/// Whether the player should be allowed to skip intros/outros, advancing to the start of gameplay or the end of a storyboard.
/// </summary>
public bool AllowSkipping { get; set; } = true;
/// <summary>
/// Whether the intro should be skipped by default.
/// </summary>
public bool AutomaticallySkipIntro { get; set; }
}
}

View File

@ -123,6 +123,8 @@ namespace osu.Game.Screens.Play
private EpilepsyWarning? epilepsyWarning;
private bool quickRestart;
[Resolved(CanBeNull = true)]
private INotificationOverlay? notificationOverlay { get; set; }
@ -361,6 +363,7 @@ namespace osu.Game.Screens.Play
return;
CurrentPlayer = createPlayer();
CurrentPlayer.Configuration.AutomaticallySkipIntro = quickRestart;
CurrentPlayer.RestartCount = restartCount++;
CurrentPlayer.RestartRequested = restartRequested;
@ -375,8 +378,9 @@ namespace osu.Game.Screens.Play
{
}
private void restartRequested()
private void restartRequested(bool quickRestartRequested)
{
quickRestart = quickRestartRequested;
hideOverlays = true;
ValidForResume = true;
}

View File

@ -39,10 +39,13 @@ namespace osu.Game.Screens.Play
private double displayTime;
private bool isClickable;
private bool skipQueued;
[Resolved]
private IGameplayClock gameplayClock { get; set; }
internal bool IsButtonVisible => fadeContainer.State == Visibility.Visible && buttonContainer.State.Value == Visibility.Visible;
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
/// <summary>
@ -123,6 +126,20 @@ namespace osu.Game.Screens.Play
displayTime = gameplayClock.CurrentTime;
fadeContainer.TriggerShow();
if (skipQueued)
{
Scheduler.AddDelayed(() => button.TriggerClick(), 200);
skipQueued = false;
}
}
public void SkipWhenReady()
{
if (IsLoaded)
button.TriggerClick();
else
skipQueued = true;
}
protected override void Update()

View File

@ -177,7 +177,7 @@ namespace osu.Game.Screens.Ranking
{
if (!this.IsCurrentScreen()) return;
player?.Restart();
player?.Restart(true);
},
});
}