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 beatmap offset control not working correctly when calibrating from quitting gameplay #29702

Merged
merged 2 commits into from
Sep 6, 2024
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
54 changes: 54 additions & 0 deletions osu.Game.Tests/Visual/Gameplay/TestSceneBeatmapOffsetControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Overlays.Settings;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Mods;
Expand Down Expand Up @@ -136,6 +137,59 @@ public void TestCalibrationFromNonZero()
AddAssert("No calibration button", () => !offsetControl.ChildrenOfType<SettingsButton>().Any());
}

[Test]
public void TestCalibrationFromNonZeroWithImmediateReferenceScore()
{
const double average_error = -4.5;
const double initial_offset = -2;

AddStep("Set beatmap offset non-neutral", () => Realm.Write(r =>
{
r.Add(new BeatmapInfo
{
ID = Beatmap.Value.BeatmapInfo.ID,
Ruleset = Beatmap.Value.BeatmapInfo.Ruleset,
UserSettings =
{
Offset = initial_offset,
}
});
}));

AddStep("Create control with preloaded reference score", () =>
{
Child = new PlayerSettingsGroup("Some settings")
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new Drawable[]
{
offsetControl = new BeatmapOffsetControl
{
ReferenceScore =
{
Value = new ScoreInfo
{
HitEvents = TestSceneHitEventTimingDistributionGraph.CreateDistributedHitEvents(average_error),
BeatmapInfo = Beatmap.Value.BeatmapInfo,
}
}
}
}
};
});

AddUntilStep("Has calibration button", () => offsetControl.ChildrenOfType<SettingsButton>().Any());
AddStep("Press button", () => offsetControl.ChildrenOfType<SettingsButton>().Single().TriggerClick());
AddAssert("Offset is adjusted", () => offsetControl.Current.Value, () => Is.EqualTo(initial_offset - average_error));

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());

AddStep("Clean up beatmap", () => Realm.Write(r => r.RemoveAll<BeatmapInfo>()));
}

[Test]
public void TestCalibrationNoChange()
{
Expand Down
3 changes: 1 addition & 2 deletions osu.Game/Screens/Play/PlayerSettings/BeatmapOffsetControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ protected override void LoadComplete()
{
base.LoadComplete();

ReferenceScore.BindValueChanged(scoreChanged, true);

beatmapOffsetSubscription = realm.SubscribeToPropertyChanged(
r => r.Find<BeatmapInfo>(beatmap.Value.BeatmapInfo.ID)?.UserSettings,
settings => settings.Offset,
Expand All @@ -124,6 +122,7 @@ protected override void LoadComplete()
});

Current.BindValueChanged(currentChanged);
ReferenceScore.BindValueChanged(scoreChanged, true);
}

private void currentChanged(ValueChangedEvent<double> offset)
Expand Down
Loading