Skip to content

Commit

Permalink
Merge pull request #10330 from peppy/editor-timing-screen-change-hand…
Browse files Browse the repository at this point in the history
…ling

Add change handler callbacks from timing screen / components
  • Loading branch information
smoogipoo authored Oct 5, 2020
2 parents 39f1ceb + d3e1da5 commit 421e061
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 3 deletions.
3 changes: 0 additions & 3 deletions osu.Game/Screens/Edit/EditorChangeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ public void EndChange()
SaveState();
}

/// <summary>
/// Saves the current <see cref="Editor"/> state.
/// </summary>
public void SaveState()
{
if (bulkChangesStarted > 0)
Expand Down
6 changes: 6 additions & 0 deletions osu.Game/Screens/Edit/IEditorChangeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,11 @@ public interface IEditorChangeHandler
/// This should be invoked as soon as possible after <see cref="BeginChange"/> to cause a state change.
/// </remarks>
void EndChange();

/// <summary>
/// Immediately saves the current <see cref="Editor"/> state.
/// Note that this will be a no-op if there is a change in progress via <see cref="BeginChange"/>.
/// </summary>
void SaveState();
}
}
1 change: 1 addition & 0 deletions osu.Game/Screens/Edit/Timing/DifficultySection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ protected override void OnControlPointChanged(ValueChangedEvent<DifficultyContro
if (point.NewValue != null)
{
multiplierSlider.Current = point.NewValue.SpeedMultiplierBindable;
multiplierSlider.Current.BindValueChanged(_ => ChangeHandler?.SaveState());
}
}

Expand Down
3 changes: 3 additions & 0 deletions osu.Game/Screens/Edit/Timing/EffectSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ protected override void OnControlPointChanged(ValueChangedEvent<EffectControlPoi
if (point.NewValue != null)
{
kiai.Current = point.NewValue.KiaiModeBindable;
kiai.Current.BindValueChanged(_ => ChangeHandler?.SaveState());

omitBarLine.Current = point.NewValue.OmitFirstBarLineBindable;
omitBarLine.Current.BindValueChanged(_ => ChangeHandler?.SaveState());
}
}

Expand Down
3 changes: 3 additions & 0 deletions osu.Game/Screens/Edit/Timing/SampleSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ protected override void OnControlPointChanged(ValueChangedEvent<SampleControlPoi
if (point.NewValue != null)
{
bank.Current = point.NewValue.SampleBankBindable;
bank.Current.BindValueChanged(_ => ChangeHandler?.SaveState());

volume.Current = point.NewValue.SampleVolumeBindable;
volume.Current.BindValueChanged(_ => ChangeHandler?.SaveState());
}
}

Expand Down
3 changes: 3 additions & 0 deletions osu.Game/Screens/Edit/Timing/Section.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ internal abstract class Section<T> : CompositeDrawable
[Resolved]
protected Bindable<ControlPointGroup> SelectedGroup { get; private set; }

[Resolved(canBeNull: true)]
protected IEditorChangeHandler ChangeHandler { get; private set; }

[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Expand Down
1 change: 1 addition & 0 deletions osu.Game/Screens/Edit/Timing/SliderWithTextBoxInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public SliderWithTextBoxInput(string labelText)
},
slider = new SettingsSlider<T>
{
TransferValueOnCommit = true,
RelativeSizeAxes = Axes.X,
}
}
Expand Down
4 changes: 4 additions & 0 deletions osu.Game/Screens/Edit/Timing/TimingScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public class ControlPointList : CompositeDrawable
[Resolved]
private Bindable<ControlPointGroup> selectedGroup { get; set; }

[Resolved(canBeNull: true)]
private IEditorChangeHandler changeHandler { get; set; }

[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Expand Down Expand Up @@ -146,6 +149,7 @@ protected override void LoadComplete()
controlGroups.BindCollectionChanged((sender, args) =>
{
table.ControlGroups = controlGroups;
changeHandler.SaveState();
}, true);
}

Expand Down
7 changes: 7 additions & 0 deletions osu.Game/Screens/Edit/Timing/TimingSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ protected override void OnControlPointChanged(ValueChangedEvent<TimingControlPoi
if (point.NewValue != null)
{
bpmSlider.Bindable = point.NewValue.BeatLengthBindable;
bpmSlider.Bindable.BindValueChanged(_ => ChangeHandler?.SaveState());

bpmTextEntry.Bindable = point.NewValue.BeatLengthBindable;
// no need to hook change handler here as it's the same bindable as above

timeSignature.Bindable = point.NewValue.TimeSignatureBindable;
timeSignature.Bindable.BindValueChanged(_ => ChangeHandler?.SaveState());
}
}

Expand Down Expand Up @@ -117,6 +122,8 @@ public BPMSlider()
bpmBindable.BindValueChanged(bpm => beatLengthBindable.Value = beatLengthToBpm(bpm.NewValue));

base.Bindable = bpmBindable;

TransferValueOnCommit = true;
}

public override Bindable<double> Bindable
Expand Down

0 comments on commit 421e061

Please sign in to comment.