Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix not being able to apply last play offset after returning to song select #31386

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions osu.Game.Tests/Visual/Gameplay/TestSceneBeatmapOffsetControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,7 @@ public partial class TestSceneBeatmapOffsetControl : OsuTestScene
[SetUpSteps]
public void SetUpSteps()
{
AddStep("Create control", () =>
{
Child = new PlayerSettingsGroup("Some settings")
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new Drawable[]
{
offsetControl = new BeatmapOffsetControl()
}
};
});
recreateControl();
}

[Test]
Expand Down Expand Up @@ -123,13 +112,14 @@ public void TestModRemovingTimedInputs()
[Test]
public void TestCalibrationFromZero()
{
ScoreInfo referenceScore = null!;
const double average_error = -4.5;

AddAssert("Offset is neutral", () => offsetControl.Current.Value == 0);
AddAssert("No calibration button", () => !offsetControl.ChildrenOfType<SettingsButton>().Any());
AddStep("Set reference score", () =>
{
offsetControl.ReferenceScore.Value = new ScoreInfo
offsetControl.ReferenceScore.Value = referenceScore = new ScoreInfo
{
HitEvents = TestSceneHitEventTimingDistributionGraph.CreateDistributedHitEvents(average_error),
BeatmapInfo = Beatmap.Value.BeatmapInfo,
Expand All @@ -143,6 +133,10 @@ public void TestCalibrationFromZero()
AddUntilStep("Button is disabled", () => !offsetControl.ChildrenOfType<SettingsButton>().Single().Enabled.Value);
AddStep("Remove reference score", () => offsetControl.ReferenceScore.Value = null);
AddAssert("No calibration button", () => !offsetControl.ChildrenOfType<SettingsButton>().Any());

recreateControl();
AddStep("Set same reference score", () => offsetControl.ReferenceScore.Value = referenceScore);
AddAssert("No calibration button", () => !offsetControl.ChildrenOfType<SettingsButton>().Any());
}

/// <summary>
Expand Down Expand Up @@ -251,5 +245,21 @@ public void TestCalibrationNoChange()
AddStep("Remove reference score", () => offsetControl.ReferenceScore.Value = null);
AddAssert("No calibration button", () => !offsetControl.ChildrenOfType<SettingsButton>().Any());
}

private void recreateControl()
{
AddStep("Create control", () =>
{
Child = new PlayerSettingsGroup("Some settings")
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new Drawable[]
{
offsetControl = new BeatmapOffsetControl()
}
};
});
}
}
}
8 changes: 4 additions & 4 deletions osu.Game.Tests/Visual/Navigation/TestSceneScreenNavigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,18 +355,18 @@ public void TestRetryCountIncrements()
}

[Test]
public void TestLastScoreNullAfterExitingPlayer()
public void TestLastScoreNotNullAfterExitingPlayer()
{
AddUntilStep("wait for last play null", getLastPlay, () => Is.Null);
AddUntilStep("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("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);
AddUntilStep("last play not null", getLastPlay, () => Is.Not.Null);

ScoreInfo getLastPlay() => Game.Dependencies.Get<SessionStatics>().Get<ScoreInfo>(Static.LastLocalUserScore);
}
Expand Down
10 changes: 7 additions & 3 deletions osu.Game/Configuration/SessionStatics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using osu.Game.Overlays;
using osu.Game.Overlays.Mods;
using osu.Game.Scoring;
using osu.Game.Screens.Play;

namespace osu.Game.Configuration
{
Expand All @@ -30,6 +29,7 @@ protected override void InitialiseDefaults()
SetDefault<APISeasonalBackgrounds>(Static.SeasonalBackgrounds, null);
SetDefault(Static.TouchInputActive, RuntimeInfo.IsMobile);
SetDefault<ScoreInfo>(Static.LastLocalUserScore, null);
SetDefault<ScoreInfo>(Static.LastAppliedOffsetScore, null);
}

/// <summary>
Expand Down Expand Up @@ -78,11 +78,15 @@ public enum Static
TouchInputActive,

/// <summary>
/// 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"/>.
/// Stores the local user's last score (can be completed or aborted).
/// </summary>
LastLocalUserScore,

/// <summary>
/// Stores the local user's last score which was used to apply an offset.
/// </summary>
LastAppliedOffsetScore,

/// <summary>
/// Whether the intro animation for the daily challenge screen has been played once.
/// This is reset when a new challenge is up.
Expand Down
7 changes: 0 additions & 7 deletions osu.Game/Screens/Play/PlayerLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
using osu.Game.Overlays.Notifications;
using osu.Game.Overlays.Volume;
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 @@ -80,8 +79,6 @@ 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 @@ -183,8 +180,6 @@ 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 @@ -354,8 +349,6 @@ public override bool OnExiting(ScreenExitEvent e)
highPerformanceSession?.Dispose();
highPerformanceSession = null;

lastScore.Value = null;

return base.OnExiting(e);
}

Expand Down
18 changes: 17 additions & 1 deletion osu.Game/Screens/Play/PlayerSettings/BeatmapOffsetControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using osu.Framework.Localisation;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
Expand All @@ -36,6 +37,8 @@ public partial class BeatmapOffsetControl : CompositeDrawable, IKeyBindingHandle
{
public Bindable<ScoreInfo?> ReferenceScore { get; } = new Bindable<ScoreInfo?>();

private Bindable<ScoreInfo?> lastAppliedScore { get; } = new Bindable<ScoreInfo?>();

public BindableDouble Current { get; } = new BindableDouble
{
MinValue = -50,
Expand Down Expand Up @@ -100,6 +103,12 @@ public BeatmapOffsetControl()
};
}

[BackgroundDependencyLoader]
private void load(SessionStatics statics)
{
statics.BindWith(Static.LastAppliedOffsetScore, lastAppliedScore);
}

protected override void LoadComplete()
{
base.LoadComplete();
Expand Down Expand Up @@ -176,6 +185,9 @@ private void scoreChanged(ValueChangedEvent<ScoreInfo?> score)
if (score.NewValue == null)
return;

if (score.NewValue.Equals(lastAppliedScore.Value))
return;

if (!score.NewValue.BeatmapInfo.AsNonNull().Equals(beatmap.Value.BeatmapInfo))
return;

Expand Down Expand Up @@ -230,7 +242,11 @@ private void scoreChanged(ValueChangedEvent<ScoreInfo?> score)
useAverageButton = new SettingsButton
{
Text = BeatmapOffsetControlStrings.CalibrateUsingLastPlay,
Action = () => Current.Value = lastPlayBeatmapOffset - lastPlayAverage,
Action = () =>
{
Current.Value = lastPlayBeatmapOffset - lastPlayAverage;
lastAppliedScore.Value = ReferenceScore.Value;
},
Enabled = { Value = !Precision.AlmostEquals(lastPlayAverage, 0, Current.Precision / 2) }
},
globalOffsetText = new LinkFlowContainer
Expand Down
Loading