1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 18:47:27 +08:00

Fix weirdness around spurious adjustments firing due to overloaded bindable

This commit is contained in:
Bartłomiej Dach 2024-09-02 10:49:31 +02:00
parent 3eaffbb70a
commit 57f1259a33
No known key found for this signature in database

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -43,16 +44,16 @@ namespace osu.Game.Screens.Edit.Timing
if (!isRebinding) ChangeHandler?.SaveState(); if (!isRebinding) ChangeHandler?.SaveState();
} }
bpmTextEntry.Bindable.BindValueChanged(val => bpmTextEntry.OnCommit = (oldBeatLength, _) =>
{ {
if (!Beatmap.AdjustNotesOnOffsetBPMChange.Value || ControlPoint.Value == null) if (!Beatmap.AdjustNotesOnOffsetBPMChange.Value || ControlPoint.Value == null)
return; return;
Beatmap.BeginChange(); Beatmap.BeginChange();
TimingSectionAdjustments.SetHitObjectBPM(Beatmap, ControlPoint.Value, val.OldValue); TimingSectionAdjustments.SetHitObjectBPM(Beatmap, ControlPoint.Value, oldBeatLength);
Beatmap.UpdateAllHitObjects(); Beatmap.UpdateAllHitObjects();
Beatmap.EndChange(); Beatmap.EndChange();
}); };
} }
private bool isRebinding; private bool isRebinding;
@ -85,6 +86,8 @@ namespace osu.Game.Screens.Edit.Timing
private partial class BPMTextBox : LabelledTextBox private partial class BPMTextBox : LabelledTextBox
{ {
public new Action<double, double>? OnCommit { get; set; }
private readonly BindableNumber<double> beatLengthBindable = new TimingControlPoint().BeatLengthBindable; private readonly BindableNumber<double> beatLengthBindable = new TimingControlPoint().BeatLengthBindable;
public BPMTextBox() public BPMTextBox()
@ -92,10 +95,12 @@ namespace osu.Game.Screens.Edit.Timing
Label = "BPM"; Label = "BPM";
SelectAllOnFocus = true; SelectAllOnFocus = true;
OnCommit += (_, isNew) => base.OnCommit += (_, isNew) =>
{ {
if (!isNew) return; if (!isNew) return;
double oldBeatLength = beatLengthBindable.Value;
try try
{ {
if (double.TryParse(Current.Value, out double doubleVal) && doubleVal > 0) if (double.TryParse(Current.Value, out double doubleVal) && doubleVal > 0)
@ -109,6 +114,7 @@ namespace osu.Game.Screens.Edit.Timing
// This is run regardless of parsing success as the parsed number may not actually trigger a change // This is run regardless of parsing success as the parsed number may not actually trigger a change
// due to bindable clamping. Even in such a case we want to update the textbox to a sane visual state. // due to bindable clamping. Even in such a case we want to update the textbox to a sane visual state.
beatLengthBindable.TriggerChange(); beatLengthBindable.TriggerChange();
OnCommit?.Invoke(oldBeatLength, beatLengthBindable.Value);
}; };
beatLengthBindable.BindValueChanged(val => beatLengthBindable.BindValueChanged(val =>