Skip to content

Commit

Permalink
Merge pull request #29702 from peppy/fix-offset-control-wrong-order
Browse files Browse the repository at this point in the history
Fix beatmap offset control not working correctly when calibrating from quitting gameplay
  • Loading branch information
bdach authored Sep 6, 2024
2 parents 36a30cf + 37f61b2 commit 925710d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
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

0 comments on commit 925710d

Please sign in to comment.