1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 08:27:49 +08:00

disable playfield centre origin when scaling slider and simplify logic

This commit is contained in:
OliBomby 2024-05-28 18:27:01 +02:00
parent 9548585b15
commit 9a18ba2699
2 changed files with 21 additions and 27 deletions

View File

@ -29,6 +29,11 @@ namespace osu.Game.Rulesets.Osu.Edit
/// </summary> /// </summary>
public Bindable<bool> CanScaleFromPlayfieldOrigin { get; private set; } = new BindableBool(); public Bindable<bool> CanScaleFromPlayfieldOrigin { get; private set; } = new BindableBool();
/// <summary>
/// Whether a single slider is currently selected, which results in a different scaling behaviour.
/// </summary>
public Bindable<bool> IsScalingSlider { get; private set; } = new BindableBool();
[Resolved] [Resolved]
private IEditorChangeHandler? changeHandler { get; set; } private IEditorChangeHandler? changeHandler { get; set; }
@ -59,6 +64,7 @@ namespace osu.Game.Rulesets.Osu.Edit
CanScaleY.Value = quad.Height > 0; CanScaleY.Value = quad.Height > 0;
CanScaleDiagonally.Value = CanScaleX.Value && CanScaleY.Value; CanScaleDiagonally.Value = CanScaleX.Value && CanScaleY.Value;
CanScaleFromPlayfieldOrigin.Value = selectedMovableObjects.Any(); CanScaleFromPlayfieldOrigin.Value = selectedMovableObjects.Any();
IsScalingSlider.Value = selectedMovableObjects.Count() == 1 && selectedMovableObjects.First() is Slider;
} }
private Dictionary<OsuHitObject, OriginalHitObjectState>? objectsInScale; private Dictionary<OsuHitObject, OriginalHitObjectState>? objectsInScale;

View File

@ -26,16 +26,12 @@ namespace osu.Game.Rulesets.Osu.Edit
private BindableNumber<float> scaleInputBindable = null!; private BindableNumber<float> scaleInputBindable = null!;
private EditorRadioButtonCollection scaleOrigin = null!; private EditorRadioButtonCollection scaleOrigin = null!;
private RadioButton playfieldCentreButton = null!;
private RadioButton selectionCentreButton = null!; private RadioButton selectionCentreButton = null!;
private OsuCheckbox xCheckBox = null!; private OsuCheckbox xCheckBox = null!;
private OsuCheckbox yCheckBox = null!; private OsuCheckbox yCheckBox = null!;
private Bindable<bool> canScaleX = null!;
private Bindable<bool> canScaleY = null!;
private bool scaleInProgress;
public PreciseScalePopover(OsuSelectionScaleHandler scaleHandler) public PreciseScalePopover(OsuSelectionScaleHandler scaleHandler)
{ {
this.scaleHandler = scaleHandler; this.scaleHandler = scaleHandler;
@ -70,7 +66,7 @@ namespace osu.Game.Rulesets.Osu.Edit
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Items = new[] Items = new[]
{ {
new RadioButton("Playfield centre", playfieldCentreButton = new RadioButton("Playfield centre",
() => setOrigin(ScaleOrigin.PlayfieldCentre), () => setOrigin(ScaleOrigin.PlayfieldCentre),
() => new SpriteIcon { Icon = FontAwesome.Regular.Square }), () => new SpriteIcon { Icon = FontAwesome.Regular.Square }),
selectionCentreButton = new RadioButton("Selection centre", selectionCentreButton = new RadioButton("Selection centre",
@ -101,6 +97,10 @@ namespace osu.Game.Rulesets.Osu.Edit
}, },
} }
}; };
playfieldCentreButton.Selected.DisabledChanged += isDisabled =>
{
playfieldCentreButton.TooltipText = isDisabled ? "Select something other than a single slider to perform playfield-based scaling." : string.Empty;
};
selectionCentreButton.Selected.DisabledChanged += isDisabled => selectionCentreButton.Selected.DisabledChanged += isDisabled =>
{ {
selectionCentreButton.TooltipText = isDisabled ? "Select more than one object to perform selection-based scaling." : string.Empty; selectionCentreButton.TooltipText = isDisabled ? "Select more than one object to perform selection-based scaling." : string.Empty;
@ -117,27 +117,20 @@ namespace osu.Game.Rulesets.Osu.Edit
scaleInput.SelectAll(); scaleInput.SelectAll();
}); });
scaleInput.Current.BindValueChanged(scale => scaleInfo.Value = scaleInfo.Value with { Scale = scale.NewValue }); scaleInput.Current.BindValueChanged(scale => scaleInfo.Value = scaleInfo.Value with { Scale = scale.NewValue });
scaleOrigin.Items.First().Select();
xCheckBox.Current.BindValueChanged(x => setAxis(x.NewValue, yCheckBox.Current.Value)); xCheckBox.Current.BindValueChanged(x => setAxis(x.NewValue, yCheckBox.Current.Value));
yCheckBox.Current.BindValueChanged(y => setAxis(xCheckBox.Current.Value, y.NewValue)); yCheckBox.Current.BindValueChanged(y => setAxis(xCheckBox.Current.Value, y.NewValue));
// aggregate two values into canScaleFromSelectionCentre selectionCentreButton.Selected.Disabled = !(scaleHandler.CanScaleX.Value || scaleHandler.CanScaleY.Value);
canScaleX = scaleHandler.CanScaleX.GetBoundCopy(); playfieldCentreButton.Selected.Disabled = scaleHandler.IsScalingSlider.Value && !selectionCentreButton.Selected.Disabled;
canScaleX.BindValueChanged(_ => updateCanScaleFromSelectionCentre());
canScaleX.BindValueChanged(e => updateAxisCheckBoxesEnabled());
canScaleY = scaleHandler.CanScaleY.GetBoundCopy(); if (playfieldCentreButton.Selected.Disabled)
canScaleY.BindValueChanged(_ => updateCanScaleFromSelectionCentre(), true); scaleOrigin.Items.Last().Select();
canScaleY.BindValueChanged(e => updateAxisCheckBoxesEnabled(), true); else
scaleOrigin.Items.First().Select();
void updateCanScaleFromSelectionCentre() =>
selectionCentreButton.Selected.Disabled = !(scaleHandler.CanScaleX.Value || scaleHandler.CanScaleY.Value);
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));
}); });
@ -152,8 +145,8 @@ namespace osu.Game.Rulesets.Osu.Edit
} }
else else
{ {
setBindableEnabled(canScaleX.Value, xCheckBox.Current); setBindableEnabled(scaleHandler.CanScaleX.Value, xCheckBox.Current);
setBindableEnabled(canScaleY.Value, yCheckBox.Current); setBindableEnabled(scaleHandler.CanScaleY.Value, yCheckBox.Current);
} }
} }
@ -199,7 +192,6 @@ namespace osu.Game.Rulesets.Osu.Edit
{ {
base.PopIn(); base.PopIn();
scaleHandler.Begin(); scaleHandler.Begin();
scaleInProgress = true;
updateMaxScale(); updateMaxScale();
} }
@ -207,11 +199,7 @@ namespace osu.Game.Rulesets.Osu.Edit
{ {
base.PopOut(); base.PopOut();
if (IsLoaded) if (IsLoaded) scaleHandler.Commit();
{
scaleHandler.Commit();
scaleInProgress = false;
}
} }
} }