Skip to content

Commit

Permalink
Merge pull request #30905 from peppy/fix-multiple-offset-applications
Browse files Browse the repository at this point in the history
Clear previous `LastLocalUserScore` when returning to song select
  • Loading branch information
smoogipoo authored Nov 28, 2024
2 parents d218c19 + c26c84b commit 0777199
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
17 changes: 17 additions & 0 deletions osu.Game.Tests/Visual/Navigation/TestSceneScreenNavigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,23 @@ public void TestRetryCountIncrements()
AddAssert("retry count is 1", () => player.RestartCount == 1);
}

[Test]
public void TestLastScoreNullAfterExitingPlayer()
{
AddUntilStep("wait for last play null", getLastPlay, () => Is.Null);

var getOriginalPlayer = playToCompletion();

AddStep("attempt to retry", () => getOriginalPlayer().ChildrenOfType<HotkeyRetryOverlay>().First().Action());
AddUntilStep("wait for last play matches player", getLastPlay, () => Is.EqualTo(getOriginalPlayer().Score.ScoreInfo));

AddUntilStep("wait for player", () => Game.ScreenStack.CurrentScreen != getOriginalPlayer() && Game.ScreenStack.CurrentScreen is Player);
AddStep("exit player", () => (Game.ScreenStack.CurrentScreen as Player)?.Exit());
AddUntilStep("wait for last play null", getLastPlay, () => Is.Null);

ScoreInfo getLastPlay() => Game.Dependencies.Get<SessionStatics>().Get<ScoreInfo>(Static.LastLocalUserScore);
}

[Test]
public void TestRetryImmediatelyAfterCompletion()
{
Expand Down
4 changes: 3 additions & 1 deletion osu.Game/Configuration/SessionStatics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using osu.Game.Overlays;
using osu.Game.Overlays.Mods;
using osu.Game.Scoring;
using osu.Game.Screens.Play;

namespace osu.Game.Configuration
{
Expand Down Expand Up @@ -77,7 +78,8 @@ public enum Static
TouchInputActive,

/// <summary>
/// Stores the local user's last score (can be completed or aborted).
/// Contains the local user's last score (can be completed or aborted) after exiting <see cref="Player"/>.
/// Will be cleared to <c>null</c> when leaving <see cref="PlayerLoader"/>.
/// </summary>
LastLocalUserScore,

Expand Down
7 changes: 7 additions & 0 deletions osu.Game/Screens/Play/PlayerLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using osu.Game.Overlays;
using osu.Game.Overlays.Notifications;
using osu.Game.Performance;
using osu.Game.Scoring;
using osu.Game.Screens.Menu;
using osu.Game.Screens.Play.PlayerSettings;
using osu.Game.Skinning;
Expand Down Expand Up @@ -78,6 +79,8 @@ public partial class PlayerLoader : ScreenWithBeatmapBackground
private FillFlowContainer disclaimers = null!;
private OsuScrollContainer settingsScroll = null!;

private Bindable<ScoreInfo?> lastScore = null!;

private Bindable<bool> showStoryboards = null!;

private bool backgroundBrightnessReduction;
Expand Down Expand Up @@ -179,6 +182,8 @@ private void load(SessionStatics sessionStatics, OsuConfigManager config)
{
muteWarningShownOnce = sessionStatics.GetBindable<bool>(Static.MutedAudioNotificationShownOnce);
batteryWarningShownOnce = sessionStatics.GetBindable<bool>(Static.LowBatteryNotificationShownOnce);
lastScore = sessionStatics.GetBindable<ScoreInfo?>(Static.LastLocalUserScore);

showStoryboards = config.GetBindable<bool>(OsuSetting.ShowStoryboard);

const float padding = 25;
Expand Down Expand Up @@ -347,6 +352,8 @@ public override bool OnExiting(ScreenExitEvent e)
highPerformanceSession?.Dispose();
highPerformanceSession = null;

lastScore.Value = null;

return base.OnExiting(e);
}

Expand Down

0 comments on commit 0777199

Please sign in to comment.