1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 07:43:00 +08:00

Bind axis checkbox disabled state to CanScaleX/Y

This commit is contained in:
OliBomby 2024-05-28 16:57:24 +02:00
parent 8eb23f8a60
commit 7cdc755c16

View File

@ -35,6 +35,8 @@ namespace osu.Game.Rulesets.Osu.Edit
private Bindable<bool> canScaleX = null!; private Bindable<bool> canScaleX = null!;
private Bindable<bool> canScaleY = null!; private Bindable<bool> canScaleY = null!;
private bool scaleInProgress;
public PreciseScalePopover(SelectionScaleHandler scaleHandler) public PreciseScalePopover(SelectionScaleHandler scaleHandler)
{ {
this.scaleHandler = scaleHandler; this.scaleHandler = scaleHandler;
@ -124,15 +126,26 @@ namespace osu.Game.Rulesets.Osu.Edit
// aggregate two values into canScaleFromSelectionCentre // aggregate two values into canScaleFromSelectionCentre
canScaleX = scaleHandler.CanScaleX.GetBoundCopy(); canScaleX = scaleHandler.CanScaleX.GetBoundCopy();
canScaleX.BindValueChanged(_ => updateCanScaleFromSelectionCentre()); canScaleX.BindValueChanged(_ => updateCanScaleFromSelectionCentre());
canScaleX.BindValueChanged(e => updateAxisCheckBoxEnabled(e.NewValue, xCheckBox.Current), true);
canScaleY = scaleHandler.CanScaleY.GetBoundCopy(); canScaleY = scaleHandler.CanScaleY.GetBoundCopy();
canScaleY.BindValueChanged(_ => updateCanScaleFromSelectionCentre(), true); canScaleY.BindValueChanged(_ => updateCanScaleFromSelectionCentre(), true);
canScaleY.BindValueChanged(e => updateAxisCheckBoxEnabled(e.NewValue, yCheckBox.Current), true);
void updateCanScaleFromSelectionCentre() => void updateCanScaleFromSelectionCentre() =>
selectionCentreButton.Selected.Disabled = !(scaleHandler.CanScaleY.Value || scaleHandler.CanScaleFromPlayfieldOrigin.Value); selectionCentreButton.Selected.Disabled = !(scaleHandler.CanScaleY.Value || scaleHandler.CanScaleFromPlayfieldOrigin.Value);
void updateAxisCheckBoxEnabled(bool enabled, Bindable<bool> current)
{
current.Disabled = false; // enable the bindable to allow setting the value
current.Value = enabled;
current.Disabled = !enabled;
}
scaleInfo.BindValueChanged(scale => scaleInfo.BindValueChanged(scale =>
{ {
if (!scaleInProgress) return;
var newScale = new Vector2(scale.NewValue.XAxis ? scale.NewValue.Scale : 1, scale.NewValue.YAxis ? scale.NewValue.Scale : 1); var newScale = new Vector2(scale.NewValue.XAxis ? scale.NewValue.Scale : 1, scale.NewValue.YAxis ? scale.NewValue.Scale : 1);
scaleHandler.Update(newScale, getOriginPosition(scale.NewValue)); scaleHandler.Update(newScale, getOriginPosition(scale.NewValue));
}); });
@ -172,6 +185,7 @@ namespace osu.Game.Rulesets.Osu.Edit
{ {
base.PopIn(); base.PopIn();
scaleHandler.Begin(); scaleHandler.Begin();
scaleInProgress = true;
updateMaxScale(); updateMaxScale();
} }
@ -180,7 +194,10 @@ namespace osu.Game.Rulesets.Osu.Edit
base.PopOut(); base.PopOut();
if (IsLoaded) if (IsLoaded)
{
scaleHandler.Commit(); scaleHandler.Commit();
scaleInProgress = false;
}
} }
} }