1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 03:25:11 +08:00

Restore editor clock time after difficulty switch

This commit is contained in:
Bartłomiej Dach 2021-09-11 18:36:57 +02:00
parent 80e54d51f2
commit 3fc72271f1
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
3 changed files with 41 additions and 3 deletions

View File

@ -476,6 +476,8 @@ namespace osu.Game.Screens.Edit
});
resetTrack(true);
if (loader?.State != null)
restoreState(loader.State);
}
public override bool OnExiting(IScreen next)
@ -740,7 +742,16 @@ namespace osu.Game.Screens.Edit
return new DifficultyMenuItem(beatmapInfo, isCurrentDifficulty, SwitchToDifficulty);
}
protected void SwitchToDifficulty(BeatmapInfo beatmapInfo) => loader?.ScheduleDifficultySwitch(beatmapInfo);
protected void SwitchToDifficulty(BeatmapInfo nextBeatmap) => loader?.ScheduleDifficultySwitch(nextBeatmap, new EditorState
{
Time = clock.CurrentTimeAccurate
});
private void restoreState([NotNull] EditorState state)
{
if (state.Time != null)
clock.Seek(state.Time.Value);
}
private void cancelExit() => loader?.CancelPendingDifficultySwitch();

View File

@ -20,6 +20,13 @@ namespace osu.Game.Screens.Edit
/// </summary>
public class EditorLoader : ScreenWithBeatmapBackground
{
/// <summary>
/// The stored state from the last editor opened.
/// This will be read by the next editor instance to be opened to restore any relevant previous state.
/// </summary>
[CanBeNull]
public EditorState State;
public override float BackgroundParallaxAmount => 0.1f;
public override bool AllowBackButton => false;
@ -61,7 +68,7 @@ namespace osu.Game.Screens.Edit
}
}
public void ScheduleDifficultySwitch(BeatmapInfo beatmapInfo)
public void ScheduleDifficultySwitch(BeatmapInfo nextBeatmap, EditorState editorState)
{
scheduledDifficultySwitch?.Cancel();
ValidForResume = true;
@ -70,7 +77,8 @@ namespace osu.Game.Screens.Edit
scheduledDifficultySwitch = Schedule(() =>
{
Beatmap.Value = beatmapManager.GetWorkingBeatmap(beatmapInfo);
Beatmap.Value = beatmapManager.GetWorkingBeatmap(nextBeatmap);
State = editorState;
// This screen is a weird exception to the rule that nothing after song select changes the global beatmap.
// Because of this, we need to update the background stack's beatmap to match.

View File

@ -0,0 +1,19 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable enable
namespace osu.Game.Screens.Edit
{
/// <summary>
/// Structure used to transport data between <see cref="Editor"/> instances on difficulty change.
/// It's intended to be received by <see cref="EditorLoader"/> from one editor instance and passed down to the next one.
/// </summary>
public class EditorState
{
/// <summary>
/// The current clock time when a difficulty switch was requested.
/// </summary>
public double? Time { get; set; }
}
}