From e1f8bc96924b104665782aacfd223eb2ba9dafed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=C3=AAn=20Minh=20H=E1=BB=93?= Date: Thu, 25 Jan 2024 12:09:39 +0700 Subject: [PATCH 01/15] Rename CanRotate property of SelectionRotationHandler to a more descriptive name --- osu.Game.Rulesets.Osu/Edit/OsuSelectionRotationHandler.cs | 4 +++- osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs | 2 +- osu.Game.Tests/Visual/Editing/TestSceneComposeSelectBox.cs | 2 +- osu.Game/Overlays/SkinEditor/SkinSelectionRotationHandler.cs | 2 +- osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs | 2 +- .../Edit/Compose/Components/SelectionRotationHandler.cs | 5 +++-- 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Edit/OsuSelectionRotationHandler.cs b/osu.Game.Rulesets.Osu/Edit/OsuSelectionRotationHandler.cs index 21fb8a67de55..0ce78e4f6142 100644 --- a/osu.Game.Rulesets.Osu/Edit/OsuSelectionRotationHandler.cs +++ b/osu.Game.Rulesets.Osu/Edit/OsuSelectionRotationHandler.cs @@ -19,6 +19,7 @@ namespace osu.Game.Rulesets.Osu.Edit { public partial class OsuSelectionRotationHandler : SelectionRotationHandler { + public BindableBool CanRotatePlayfieldOrigin { get; private set; } = new(); [Resolved] private IEditorChangeHandler? changeHandler { get; set; } @@ -41,7 +42,8 @@ protected override void LoadComplete() private void updateState() { var quad = GeometryUtils.GetSurroundingQuad(selectedMovableObjects); - CanRotate.Value = quad.Width > 0 || quad.Height > 0; + CanRotateSelectionOrigin.Value = quad.Width > 0 || quad.Height > 0; + CanRotatePlayfieldOrigin.Value = selectedItems.Any(); } private OsuHitObject[]? objectsInRotation; diff --git a/osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs b/osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs index 3da9f5b69b80..291c79e613a7 100644 --- a/osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs +++ b/osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs @@ -53,7 +53,7 @@ protected override void LoadComplete() // bindings to `Enabled` on the buttons are decoupled on purpose // due to the weird `OsuButton` behaviour of resetting `Enabled` to `false` when `Action` is set. - canRotate.BindTo(RotationHandler.CanRotate); + canRotate.BindTo(RotationHandler.CanRotateSelectionOrigin); canRotate.BindValueChanged(_ => rotateButton.Enabled.Value = canRotate.Value, true); } diff --git a/osu.Game.Tests/Visual/Editing/TestSceneComposeSelectBox.cs b/osu.Game.Tests/Visual/Editing/TestSceneComposeSelectBox.cs index f6637d0e80a3..8e4f4a1cfd08 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneComposeSelectBox.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneComposeSelectBox.cs @@ -89,7 +89,7 @@ public TestSelectionRotationHandler(Func getTargetContainer) { this.getTargetContainer = getTargetContainer; - CanRotate.Value = true; + CanRotateSelectionOrigin.Value = true; } [CanBeNull] diff --git a/osu.Game/Overlays/SkinEditor/SkinSelectionRotationHandler.cs b/osu.Game/Overlays/SkinEditor/SkinSelectionRotationHandler.cs index 60f69000a28c..7ecf116b68fb 100644 --- a/osu.Game/Overlays/SkinEditor/SkinSelectionRotationHandler.cs +++ b/osu.Game/Overlays/SkinEditor/SkinSelectionRotationHandler.cs @@ -41,7 +41,7 @@ protected override void LoadComplete() private void updateState() { - CanRotate.Value = selectedItems.Count > 0; + CanRotateSelectionOrigin.Value = selectedItems.Count > 0; } private Drawable[]? objectsInRotation; diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs b/osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs index 0b16941bc479..85ea7364e8ce 100644 --- a/osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs +++ b/osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs @@ -174,7 +174,7 @@ public string Text private void load() { if (rotationHandler != null) - canRotate.BindTo(rotationHandler.CanRotate); + canRotate.BindTo(rotationHandler.CanRotateSelectionOrigin); canRotate.BindValueChanged(_ => recreate(), true); } diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionRotationHandler.cs b/osu.Game/Screens/Edit/Compose/Components/SelectionRotationHandler.cs index 5faa4a108dc5..749e1aab1775 100644 --- a/osu.Game/Screens/Edit/Compose/Components/SelectionRotationHandler.cs +++ b/osu.Game/Screens/Edit/Compose/Components/SelectionRotationHandler.cs @@ -13,9 +13,10 @@ namespace osu.Game.Screens.Edit.Compose.Components public partial class SelectionRotationHandler : Component { /// - /// Whether the rotation can currently be performed. + /// Whether rotation anchored by the selection origin can currently be performed. + /// This is in constrast to rotation anchored by the entire field. /// - public Bindable CanRotate { get; private set; } = new BindableBool(); + public Bindable CanRotateSelectionOrigin { get; private set; } = new BindableBool(); /// /// Performs a single, instant, atomic rotation operation. From 601ba9f194ee029714d85a73f4e0078a7401f910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=C3=AAn=20Minh=20H=E1=BB=93?= Date: Thu, 25 Jan 2024 12:16:35 +0700 Subject: [PATCH 02/15] Change rotate tool button to be enabled on single circle. Inject osu ruleset specific rotate handler instead of generic handler. --- osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs | 5 ++++- osu.Game.Rulesets.Osu/Edit/OsuSelectionHandler.cs | 2 +- osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs | 5 ++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs b/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs index 448cfaf84c5d..a0fb0b06c374 100644 --- a/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs +++ b/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs @@ -101,7 +101,10 @@ private void load() RightToolbox.AddRange(new EditorToolboxGroup[] { - new TransformToolboxGroup { RotationHandler = BlueprintContainer.SelectionHandler.RotationHandler, }, + new TransformToolboxGroup + { + RotationHandler = (OsuSelectionRotationHandler)BlueprintContainer.SelectionHandler.RotationHandler, + }, FreehandlSliderToolboxGroup } ); diff --git a/osu.Game.Rulesets.Osu/Edit/OsuSelectionHandler.cs b/osu.Game.Rulesets.Osu/Edit/OsuSelectionHandler.cs index cea2adc6e215..7e645bc67017 100644 --- a/osu.Game.Rulesets.Osu/Edit/OsuSelectionHandler.cs +++ b/osu.Game.Rulesets.Osu/Edit/OsuSelectionHandler.cs @@ -164,7 +164,7 @@ private static void adjustScaleFromAnchor(ref Vector2 scale, Anchor reference) if ((reference & Anchor.y0) > 0) scale.Y = -scale.Y; } - public override SelectionRotationHandler CreateRotationHandler() => new OsuSelectionRotationHandler(); + public override OsuSelectionRotationHandler CreateRotationHandler() => new OsuSelectionRotationHandler(); private void scaleSlider(Slider slider, Vector2 scale) { diff --git a/osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs b/osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs index 291c79e613a7..c70f35c6fb12 100644 --- a/osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs +++ b/osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs @@ -11,7 +11,6 @@ using osu.Game.Input.Bindings; using osu.Game.Rulesets.Edit; using osu.Game.Screens.Edit.Components; -using osu.Game.Screens.Edit.Compose.Components; using osuTK; namespace osu.Game.Rulesets.Osu.Edit @@ -22,7 +21,7 @@ public partial class TransformToolboxGroup : EditorToolboxGroup, IKeyBindingHand private EditorToolButton rotateButton = null!; - public SelectionRotationHandler RotationHandler { get; init; } = null!; + public OsuSelectionRotationHandler RotationHandler { get; init; } = null!; public TransformToolboxGroup() : base("transform") @@ -53,7 +52,7 @@ protected override void LoadComplete() // bindings to `Enabled` on the buttons are decoupled on purpose // due to the weird `OsuButton` behaviour of resetting `Enabled` to `false` when `Action` is set. - canRotate.BindTo(RotationHandler.CanRotateSelectionOrigin); + canRotate.BindTo(RotationHandler.CanRotatePlayfieldOrigin); canRotate.BindValueChanged(_ => rotateButton.Enabled.Value = canRotate.Value, true); } From 500bed01215f6b99eeb3a6a717563b243c18ccd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=C3=AAn=20Minh=20H=E1=BB=93?= Date: Thu, 25 Jan 2024 14:24:35 +0700 Subject: [PATCH 03/15] Split editor toolbox radio button disabling logic from EditorRadioButton, then add disabling logic for rotate popover --- osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs | 8 +++++++- osu.Game/Rulesets/Edit/HitObjectComposer.cs | 8 ++++++++ .../Edit/Components/RadioButtons/EditorRadioButton.cs | 2 -- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs b/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs index f09d6b78e661..fdab84f38d5a 100644 --- a/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs +++ b/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs @@ -24,6 +24,7 @@ public partial class PreciseRotationPopover : OsuPopover private SliderWithTextBoxInput angleInput = null!; private EditorRadioButtonCollection rotationOrigin = null!; + private RadioButton selectionCentreButton = null!; public PreciseRotationPopover(SelectionRotationHandler rotationHandler) { this.rotationHandler = rotationHandler; @@ -59,7 +60,7 @@ private void load() new RadioButton("Playfield centre", () => rotationInfo.Value = rotationInfo.Value with { Origin = RotationOrigin.PlayfieldCentre }, () => new SpriteIcon { Icon = FontAwesome.Regular.Square }), - new RadioButton("Selection centre", + selectionCentreButton = new RadioButton("Selection centre", () => rotationInfo.Value = rotationInfo.Value with { Origin = RotationOrigin.SelectionCentre }, () => new SpriteIcon { Icon = FontAwesome.Solid.VectorSquare }) } @@ -76,6 +77,11 @@ protected override void LoadComplete() angleInput.Current.BindValueChanged(angle => rotationInfo.Value = rotationInfo.Value with { Degrees = angle.NewValue }); rotationOrigin.Items.First().Select(); + rotationHandler.CanRotateSelectionOrigin.BindValueChanged(e => + { + selectionCentreButton.Selected.Disabled = !e.NewValue; + }, true); + rotationInfo.BindValueChanged(rotation => { rotationHandler.Update(rotation.NewValue.Degrees, rotation.NewValue.Origin == RotationOrigin.PlayfieldCentre ? OsuPlayfield.BASE_SIZE / 2 : null); diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index 50e6393895c4..6abc6cb95bb2 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -244,6 +244,14 @@ protected override void LoadComplete() if (!timing.NewValue) setSelectTool(); }); + + EditorBeatmap.HasTiming.BindValueChanged(hasTiming => + { + foreach (var item in toolboxCollection.Items) + { + item.Selected.Disabled = !hasTiming.NewValue; + } + }, true); } protected override void Update() diff --git a/osu.Game/Screens/Edit/Components/RadioButtons/EditorRadioButton.cs b/osu.Game/Screens/Edit/Components/RadioButtons/EditorRadioButton.cs index 65f3e41c1377..55490956395d 100644 --- a/osu.Game/Screens/Edit/Components/RadioButtons/EditorRadioButton.cs +++ b/osu.Game/Screens/Edit/Components/RadioButtons/EditorRadioButton.cs @@ -76,8 +76,6 @@ protected override void LoadComplete() Selected?.Invoke(Button); }; - editorBeatmap?.HasTiming.BindValueChanged(hasTiming => Button.Selected.Disabled = !hasTiming.NewValue, true); - Button.Selected.BindDisabledChanged(disabled => Enabled.Value = !disabled, true); updateSelectionState(); } From 94ada87cbad0828fcb669d0e4133f850b12a07b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=C3=AAn=20Minh=20H=E1=BB=93?= Date: Thu, 25 Jan 2024 14:24:45 +0700 Subject: [PATCH 04/15] Un-hardcode tooltip from EditorRadioButton and add disabled tooltip for rotation popover --- osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs | 2 ++ osu.Game/Rulesets/Edit/HitObjectComposer.cs | 5 +++++ .../Edit/Components/RadioButtons/EditorRadioButton.cs | 2 +- .../Edit/Components/RadioButtons/RadioButton.cs | 11 +++++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs b/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs index fdab84f38d5a..2cf67992797b 100644 --- a/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs +++ b/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs @@ -25,6 +25,7 @@ public partial class PreciseRotationPopover : OsuPopover private EditorRadioButtonCollection rotationOrigin = null!; private RadioButton selectionCentreButton = null!; + public PreciseRotationPopover(SelectionRotationHandler rotationHandler) { this.rotationHandler = rotationHandler; @@ -67,6 +68,7 @@ private void load() } } }; + selectionCentreButton.TooltipTextWhenDisabled = "We can't rotate a circle around itself! Can we?"; } protected override void LoadComplete() diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index 6abc6cb95bb2..bc8de7f4b274 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -212,6 +212,11 @@ private void load(OsuConfigManager config) .Select(t => new RadioButton(t.Name, () => toolSelected(t), t.CreateIcon)) .ToList(); + foreach (var item in toolboxCollection.Items) + { + item.TooltipTextWhenDisabled = "Add at least one timing point first!"; + } + TernaryStates = CreateTernaryButtons().ToArray(); togglesCollection.AddRange(TernaryStates.Select(b => new DrawableTernaryButton(b))); diff --git a/osu.Game/Screens/Edit/Components/RadioButtons/EditorRadioButton.cs b/osu.Game/Screens/Edit/Components/RadioButtons/EditorRadioButton.cs index 55490956395d..601548faddc0 100644 --- a/osu.Game/Screens/Edit/Components/RadioButtons/EditorRadioButton.cs +++ b/osu.Game/Screens/Edit/Components/RadioButtons/EditorRadioButton.cs @@ -97,6 +97,6 @@ private void updateSelectionState() X = 40f }; - public LocalisableString TooltipText => Enabled.Value ? string.Empty : "Add at least one timing point first!"; + public LocalisableString TooltipText => Enabled.Value ? Button.TooltipTextWhenEnabled : Button.TooltipTextWhenDisabled; } } diff --git a/osu.Game/Screens/Edit/Components/RadioButtons/RadioButton.cs b/osu.Game/Screens/Edit/Components/RadioButtons/RadioButton.cs index 9dcd29bf834a..1b47c028abbd 100644 --- a/osu.Game/Screens/Edit/Components/RadioButtons/RadioButton.cs +++ b/osu.Game/Screens/Edit/Components/RadioButtons/RadioButton.cs @@ -4,6 +4,7 @@ using System; using osu.Framework.Bindables; using osu.Framework.Graphics; +using osu.Framework.Localisation; namespace osu.Game.Screens.Edit.Components.RadioButtons { @@ -11,9 +12,19 @@ public class RadioButton { /// /// Whether this is selected. + /// Disable this bindable to disable the button. /// public readonly BindableBool Selected; + /// + /// Tooltip text that will be shown on hover if button is enabled. + /// + public LocalisableString TooltipTextWhenEnabled { get; set; } = string.Empty; + /// + /// Tooltip text that will be shown on hover if button is disabled. + /// + public LocalisableString TooltipTextWhenDisabled { get; set; } = string.Empty; + /// /// The item related to this button. /// From b87ff4db0d5d69e7f8e787eb1135745c491c074e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=C3=AAn=20Minh=20H=E1=BB=93?= Date: Thu, 25 Jan 2024 15:33:48 +0700 Subject: [PATCH 05/15] Edit test for precise rotation popover --- .../Editor/TestScenePreciseRotation.cs | 41 +++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/osu.Game.Rulesets.Osu.Tests/Editor/TestScenePreciseRotation.cs b/osu.Game.Rulesets.Osu.Tests/Editor/TestScenePreciseRotation.cs index d7dd30d608f0..67283f40da2a 100644 --- a/osu.Game.Rulesets.Osu.Tests/Editor/TestScenePreciseRotation.cs +++ b/osu.Game.Rulesets.Osu.Tests/Editor/TestScenePreciseRotation.cs @@ -24,14 +24,38 @@ public partial class TestScenePreciseRotation : TestSceneOsuEditor [Test] public void TestHotkeyHandling() { - AddStep("select single circle", () => EditorBeatmap.SelectedHitObjects.Add(EditorBeatmap.HitObjects.OfType().First())); + AddStep("deselect everything", () => EditorBeatmap.SelectedHitObjects.Clear()); AddStep("press rotate hotkey", () => { InputManager.PressKey(Key.ControlLeft); InputManager.Key(Key.R); InputManager.ReleaseKey(Key.ControlLeft); }); - AddUntilStep("no popover present", () => this.ChildrenOfType().Count(), () => Is.Zero); + AddUntilStep("no popover present", getPopover, () => Is.Null); + + AddStep("select single circle", + () => EditorBeatmap.SelectedHitObjects.Add(EditorBeatmap.HitObjects.OfType().First())); + AddStep("press rotate hotkey", () => + { + InputManager.PressKey(Key.ControlLeft); + InputManager.Key(Key.R); + InputManager.ReleaseKey(Key.ControlLeft); + }); + AddUntilStep("popover present", getPopover, () => Is.Not.Null); + AddAssert("only playfield centre origin rotation available", () => + { + var popover = getPopover(); + var buttons = popover.ChildrenOfType(); + return buttons.Any(btn => btn.Text == "Selection centre" && btn.Enabled.Value is false) && + buttons.Any(btn => btn.Text == "Playfield centre" && btn.Enabled.Value is true); + }); + AddStep("press rotate hotkey", () => + { + InputManager.PressKey(Key.ControlLeft); + InputManager.Key(Key.R); + InputManager.ReleaseKey(Key.ControlLeft); + }); + AddUntilStep("no popover present", getPopover, () => Is.Null); AddStep("select first three objects", () => { @@ -44,14 +68,23 @@ public void TestHotkeyHandling() InputManager.Key(Key.R); InputManager.ReleaseKey(Key.ControlLeft); }); - AddUntilStep("popover present", () => this.ChildrenOfType().Count(), () => Is.EqualTo(1)); + AddUntilStep("popover present", getPopover, () => Is.Not.Null); + AddAssert("both origin rotation available", () => + { + var popover = getPopover(); + var buttons = popover.ChildrenOfType(); + return buttons.Any(btn => btn.Text == "Selection centre" && btn.Enabled.Value is true) && + buttons.Any(btn => btn.Text == "Playfield centre" && btn.Enabled.Value is true); + }); AddStep("press rotate hotkey", () => { InputManager.PressKey(Key.ControlLeft); InputManager.Key(Key.R); InputManager.ReleaseKey(Key.ControlLeft); }); - AddUntilStep("no popover present", () => this.ChildrenOfType().Count(), () => Is.Zero); + AddUntilStep("no popover present", getPopover, () => Is.Null); + + PreciseRotationPopover? getPopover() => this.ChildrenOfType().SingleOrDefault(); } [Test] From 2fa52de87a07a7bbdbbde850ccd47d5722d1cc55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=C3=AAn=20Minh=20H=E1=BB=93?= Date: Thu, 25 Jan 2024 15:52:57 +0700 Subject: [PATCH 06/15] Fix formatting --- .../Editor/TestScenePreciseRotation.cs | 8 ++++---- osu.Game.Rulesets.Osu/Edit/OsuSelectionRotationHandler.cs | 3 ++- .../Edit/Components/RadioButtons/EditorRadioButton.cs | 3 --- .../Screens/Edit/Components/RadioButtons/RadioButton.cs | 1 + 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/osu.Game.Rulesets.Osu.Tests/Editor/TestScenePreciseRotation.cs b/osu.Game.Rulesets.Osu.Tests/Editor/TestScenePreciseRotation.cs index 67283f40da2a..30e0dbbf2e6f 100644 --- a/osu.Game.Rulesets.Osu.Tests/Editor/TestScenePreciseRotation.cs +++ b/osu.Game.Rulesets.Osu.Tests/Editor/TestScenePreciseRotation.cs @@ -46,8 +46,8 @@ public void TestHotkeyHandling() { var popover = getPopover(); var buttons = popover.ChildrenOfType(); - return buttons.Any(btn => btn.Text == "Selection centre" && btn.Enabled.Value is false) && - buttons.Any(btn => btn.Text == "Playfield centre" && btn.Enabled.Value is true); + return buttons.Any(btn => btn.Text == "Selection centre" && !btn.Enabled.Value) + && buttons.Any(btn => btn.Text == "Playfield centre" && btn.Enabled.Value); }); AddStep("press rotate hotkey", () => { @@ -73,8 +73,8 @@ public void TestHotkeyHandling() { var popover = getPopover(); var buttons = popover.ChildrenOfType(); - return buttons.Any(btn => btn.Text == "Selection centre" && btn.Enabled.Value is true) && - buttons.Any(btn => btn.Text == "Playfield centre" && btn.Enabled.Value is true); + return buttons.Any(btn => btn.Text == "Selection centre" && btn.Enabled.Value) + && buttons.Any(btn => btn.Text == "Playfield centre" && btn.Enabled.Value); }); AddStep("press rotate hotkey", () => { diff --git a/osu.Game.Rulesets.Osu/Edit/OsuSelectionRotationHandler.cs b/osu.Game.Rulesets.Osu/Edit/OsuSelectionRotationHandler.cs index 0ce78e4f6142..cd01fc9f4dcd 100644 --- a/osu.Game.Rulesets.Osu/Edit/OsuSelectionRotationHandler.cs +++ b/osu.Game.Rulesets.Osu/Edit/OsuSelectionRotationHandler.cs @@ -19,7 +19,8 @@ namespace osu.Game.Rulesets.Osu.Edit { public partial class OsuSelectionRotationHandler : SelectionRotationHandler { - public BindableBool CanRotatePlayfieldOrigin { get; private set; } = new(); + public BindableBool CanRotatePlayfieldOrigin { get; private set; } = new BindableBool(); + [Resolved] private IEditorChangeHandler? changeHandler { get; set; } diff --git a/osu.Game/Screens/Edit/Components/RadioButtons/EditorRadioButton.cs b/osu.Game/Screens/Edit/Components/RadioButtons/EditorRadioButton.cs index 601548faddc0..9d1f87e1e0f0 100644 --- a/osu.Game/Screens/Edit/Components/RadioButtons/EditorRadioButton.cs +++ b/osu.Game/Screens/Edit/Components/RadioButtons/EditorRadioButton.cs @@ -33,9 +33,6 @@ public partial class EditorRadioButton : OsuButton, IHasTooltip private Drawable icon = null!; - [Resolved] - private EditorBeatmap? editorBeatmap { get; set; } - public EditorRadioButton(RadioButton button) { Button = button; diff --git a/osu.Game/Screens/Edit/Components/RadioButtons/RadioButton.cs b/osu.Game/Screens/Edit/Components/RadioButtons/RadioButton.cs index 1b47c028abbd..2d1416c9c6a6 100644 --- a/osu.Game/Screens/Edit/Components/RadioButtons/RadioButton.cs +++ b/osu.Game/Screens/Edit/Components/RadioButtons/RadioButton.cs @@ -20,6 +20,7 @@ public class RadioButton /// Tooltip text that will be shown on hover if button is enabled. /// public LocalisableString TooltipTextWhenEnabled { get; set; } = string.Empty; + /// /// Tooltip text that will be shown on hover if button is disabled. /// From d5b70ed09a68c8c99484df97dd4fbd245c233e8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=C3=AAn=20Minh=20H=E1=BB=93?= Date: Thu, 25 Jan 2024 16:56:59 +0700 Subject: [PATCH 07/15] Move CanRotatePlayfieldOrigin bindable to generic rotation handler --- osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs | 5 +---- osu.Game.Rulesets.Osu/Edit/OsuSelectionHandler.cs | 2 +- osu.Game.Rulesets.Osu/Edit/OsuSelectionRotationHandler.cs | 2 -- osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs | 3 ++- .../Edit/Compose/Components/SelectionRotationHandler.cs | 6 +++++- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs b/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs index a0fb0b06c374..448cfaf84c5d 100644 --- a/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs +++ b/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs @@ -101,10 +101,7 @@ private void load() RightToolbox.AddRange(new EditorToolboxGroup[] { - new TransformToolboxGroup - { - RotationHandler = (OsuSelectionRotationHandler)BlueprintContainer.SelectionHandler.RotationHandler, - }, + new TransformToolboxGroup { RotationHandler = BlueprintContainer.SelectionHandler.RotationHandler, }, FreehandlSliderToolboxGroup } ); diff --git a/osu.Game.Rulesets.Osu/Edit/OsuSelectionHandler.cs b/osu.Game.Rulesets.Osu/Edit/OsuSelectionHandler.cs index 7e645bc67017..cea2adc6e215 100644 --- a/osu.Game.Rulesets.Osu/Edit/OsuSelectionHandler.cs +++ b/osu.Game.Rulesets.Osu/Edit/OsuSelectionHandler.cs @@ -164,7 +164,7 @@ private static void adjustScaleFromAnchor(ref Vector2 scale, Anchor reference) if ((reference & Anchor.y0) > 0) scale.Y = -scale.Y; } - public override OsuSelectionRotationHandler CreateRotationHandler() => new OsuSelectionRotationHandler(); + public override SelectionRotationHandler CreateRotationHandler() => new OsuSelectionRotationHandler(); private void scaleSlider(Slider slider, Vector2 scale) { diff --git a/osu.Game.Rulesets.Osu/Edit/OsuSelectionRotationHandler.cs b/osu.Game.Rulesets.Osu/Edit/OsuSelectionRotationHandler.cs index cd01fc9f4dcd..1998e02a5c24 100644 --- a/osu.Game.Rulesets.Osu/Edit/OsuSelectionRotationHandler.cs +++ b/osu.Game.Rulesets.Osu/Edit/OsuSelectionRotationHandler.cs @@ -19,8 +19,6 @@ namespace osu.Game.Rulesets.Osu.Edit { public partial class OsuSelectionRotationHandler : SelectionRotationHandler { - public BindableBool CanRotatePlayfieldOrigin { get; private set; } = new BindableBool(); - [Resolved] private IEditorChangeHandler? changeHandler { get; set; } diff --git a/osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs b/osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs index c70f35c6fb12..19590e9b6e71 100644 --- a/osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs +++ b/osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs @@ -11,6 +11,7 @@ using osu.Game.Input.Bindings; using osu.Game.Rulesets.Edit; using osu.Game.Screens.Edit.Components; +using osu.Game.Screens.Edit.Compose.Components; using osuTK; namespace osu.Game.Rulesets.Osu.Edit @@ -21,7 +22,7 @@ public partial class TransformToolboxGroup : EditorToolboxGroup, IKeyBindingHand private EditorToolButton rotateButton = null!; - public OsuSelectionRotationHandler RotationHandler { get; init; } = null!; + public SelectionRotationHandler RotationHandler { get; init; } = null!; public TransformToolboxGroup() : base("transform") diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionRotationHandler.cs b/osu.Game/Screens/Edit/Compose/Components/SelectionRotationHandler.cs index 749e1aab1775..459e4b0c4119 100644 --- a/osu.Game/Screens/Edit/Compose/Components/SelectionRotationHandler.cs +++ b/osu.Game/Screens/Edit/Compose/Components/SelectionRotationHandler.cs @@ -14,10 +14,14 @@ public partial class SelectionRotationHandler : Component { /// /// Whether rotation anchored by the selection origin can currently be performed. - /// This is in constrast to rotation anchored by the entire field. /// public Bindable CanRotateSelectionOrigin { get; private set; } = new BindableBool(); + /// + /// Whether rotation anchored by the center of the playfield can currently be performed. + /// + public Bindable CanRotatePlayfieldOrigin { get; private set; } = new BindableBool(); + /// /// Performs a single, instant, atomic rotation operation. /// From 8d6358a138605828c5260b4efca907049ed73e92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=C3=AAn=20Minh=20H=E1=BB=93?= Date: Sat, 30 Mar 2024 16:02:31 +0700 Subject: [PATCH 08/15] Fix editor rotation allowing spinner only bug --- osu.Game.Rulesets.Osu/Edit/OsuSelectionRotationHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu/Edit/OsuSelectionRotationHandler.cs b/osu.Game.Rulesets.Osu/Edit/OsuSelectionRotationHandler.cs index 1998e02a5c24..d48bc6a90b19 100644 --- a/osu.Game.Rulesets.Osu/Edit/OsuSelectionRotationHandler.cs +++ b/osu.Game.Rulesets.Osu/Edit/OsuSelectionRotationHandler.cs @@ -42,7 +42,7 @@ private void updateState() { var quad = GeometryUtils.GetSurroundingQuad(selectedMovableObjects); CanRotateSelectionOrigin.Value = quad.Width > 0 || quad.Height > 0; - CanRotatePlayfieldOrigin.Value = selectedItems.Any(); + CanRotatePlayfieldOrigin.Value = selectedMovableObjects.Any(); } private OsuHitObject[]? objectsInRotation; From 5d497ba4a8ada3ae5ad733ed6d856328b39a9576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=C3=AAn=20Minh=20H=E1=BB=93?= Date: Sat, 30 Mar 2024 16:04:22 +0700 Subject: [PATCH 09/15] Simplify TooltipText for EditorRadioButton --- .../Edit/PreciseRotationPopover.cs | 8 +++++++- osu.Game/Rulesets/Edit/HitObjectComposer.cs | 8 +++++++- .../Components/RadioButtons/EditorRadioButton.cs | 2 +- .../Edit/Components/RadioButtons/RadioButton.cs | 13 +++---------- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs b/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs index 2cf67992797b..6c29184be41e 100644 --- a/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs +++ b/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs @@ -68,7 +68,13 @@ private void load() } } }; - selectionCentreButton.TooltipTextWhenDisabled = "We can't rotate a circle around itself! Can we?"; + selectionCentreButton.Selected.DisabledChanged += (isDisabled) => + { + if (isDisabled) + selectionCentreButton.TooltipText = "We can't rotate a circle around itself! Can we?"; + else + selectionCentreButton.TooltipText = string.Empty; + }; } protected override void LoadComplete() diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index bc8de7f4b274..09bac7a7918b 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -214,7 +214,13 @@ private void load(OsuConfigManager config) foreach (var item in toolboxCollection.Items) { - item.TooltipTextWhenDisabled = "Add at least one timing point first!"; + item.Selected.DisabledChanged += (isDisabled) => + { + if (isDisabled) + item.TooltipText = "Add at least one timing point first!"; + else + item.TooltipText = string.Empty; + }; } TernaryStates = CreateTernaryButtons().ToArray(); diff --git a/osu.Game/Screens/Edit/Components/RadioButtons/EditorRadioButton.cs b/osu.Game/Screens/Edit/Components/RadioButtons/EditorRadioButton.cs index 9d1f87e1e0f0..29bb24eb432e 100644 --- a/osu.Game/Screens/Edit/Components/RadioButtons/EditorRadioButton.cs +++ b/osu.Game/Screens/Edit/Components/RadioButtons/EditorRadioButton.cs @@ -94,6 +94,6 @@ private void updateSelectionState() X = 40f }; - public LocalisableString TooltipText => Enabled.Value ? Button.TooltipTextWhenEnabled : Button.TooltipTextWhenDisabled; + public LocalisableString TooltipText => Button.TooltipText; } } diff --git a/osu.Game/Screens/Edit/Components/RadioButtons/RadioButton.cs b/osu.Game/Screens/Edit/Components/RadioButtons/RadioButton.cs index 2d1416c9c6a6..f49fc6f6ab23 100644 --- a/osu.Game/Screens/Edit/Components/RadioButtons/RadioButton.cs +++ b/osu.Game/Screens/Edit/Components/RadioButtons/RadioButton.cs @@ -16,16 +16,6 @@ public class RadioButton /// public readonly BindableBool Selected; - /// - /// Tooltip text that will be shown on hover if button is enabled. - /// - public LocalisableString TooltipTextWhenEnabled { get; set; } = string.Empty; - - /// - /// Tooltip text that will be shown on hover if button is disabled. - /// - public LocalisableString TooltipTextWhenDisabled { get; set; } = string.Empty; - /// /// The item related to this button. /// @@ -62,5 +52,8 @@ public void Select() /// Deselects this . /// public void Deselect() => Selected.Value = false; + + // Tooltip text that will be shown when hovered over + public LocalisableString TooltipText { get; set; } = string.Empty; } } From 6f782266b51b717e996cc258b05da8fb737533d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=C3=AAn=20Minh=20H=E1=BB=93?= Date: Sat, 30 Mar 2024 17:03:40 +0700 Subject: [PATCH 10/15] Fix inspection --- osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs | 7 ++----- osu.Game/Rulesets/Edit/HitObjectComposer.cs | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs b/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs index 6c29184be41e..70441b33dd07 100644 --- a/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs +++ b/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs @@ -68,12 +68,9 @@ private void load() } } }; - selectionCentreButton.Selected.DisabledChanged += (isDisabled) => + selectionCentreButton.Selected.DisabledChanged += isDisabled => { - if (isDisabled) - selectionCentreButton.TooltipText = "We can't rotate a circle around itself! Can we?"; - else - selectionCentreButton.TooltipText = string.Empty; + selectionCentreButton.TooltipText = isDisabled ? "We can't rotate a circle around itself! Can we?" : string.Empty; }; } diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index 09bac7a7918b..4d92a08bed55 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -214,12 +214,9 @@ private void load(OsuConfigManager config) foreach (var item in toolboxCollection.Items) { - item.Selected.DisabledChanged += (isDisabled) => + item.Selected.DisabledChanged += isDisabled => { - if (isDisabled) - item.TooltipText = "Add at least one timing point first!"; - else - item.TooltipText = string.Empty; + item.TooltipText = isDisabled ? "Add at least one timing point first!" : string.Empty; }; } From b445e27ad6bfae93244b89acc1544aef01978bdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=C3=AAn=20Minh=20H=E1=BB=93?= Date: Sat, 30 Mar 2024 17:54:27 +0700 Subject: [PATCH 11/15] Aggregate two CanRotate bindable for enabling the Rotate button --- osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs b/osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs index 19590e9b6e71..3e2cbe9d608a 100644 --- a/osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs +++ b/osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs @@ -51,9 +51,17 @@ protected override void LoadComplete() { base.LoadComplete(); + // aggregate two values into canRotate + RotationHandler.CanRotatePlayfieldOrigin.BindValueChanged(_ => updateCanRotateAggregate()); + RotationHandler.CanRotateSelectionOrigin.BindValueChanged(_ => updateCanRotateAggregate()); + + void updateCanRotateAggregate() + { + canRotate.Value = RotationHandler.CanRotatePlayfieldOrigin.Value || RotationHandler.CanRotateSelectionOrigin.Value; + } + // bindings to `Enabled` on the buttons are decoupled on purpose // due to the weird `OsuButton` behaviour of resetting `Enabled` to `false` when `Action` is set. - canRotate.BindTo(RotationHandler.CanRotatePlayfieldOrigin); canRotate.BindValueChanged(_ => rotateButton.Enabled.Value = canRotate.Value, true); } From 86def7e263ff0bc811a9f7cd4b51c4d7ee1d7129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=C3=AAn=20Minh=20H=E1=BB=93?= <32929093+honguyenminh@users.noreply.github.com> Date: Sun, 31 Mar 2024 16:00:47 +0700 Subject: [PATCH 12/15] Change editor rotate button disabled tooltip text Co-authored-by: Dean Herbert --- osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs b/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs index 70441b33dd07..da5023392083 100644 --- a/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs +++ b/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs @@ -70,7 +70,7 @@ private void load() }; selectionCentreButton.Selected.DisabledChanged += isDisabled => { - selectionCentreButton.TooltipText = isDisabled ? "We can't rotate a circle around itself! Can we?" : string.Empty; + selectionCentreButton.TooltipText = isDisabled ? "Select more than one circles to perform rotation." : string.Empty; }; } From ed5dd5c8cd100f99223a20360e10e52668c64edb Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 2 Apr 2024 13:04:34 +0800 Subject: [PATCH 13/15] Bind using local bindables to avoid potentially event pollution --- osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs b/osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs index 3e2cbe9d608a..9499bacade65 100644 --- a/osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs +++ b/osu.Game.Rulesets.Osu/Edit/TransformToolboxGroup.cs @@ -22,6 +22,9 @@ public partial class TransformToolboxGroup : EditorToolboxGroup, IKeyBindingHand private EditorToolButton rotateButton = null!; + private Bindable canRotatePlayfieldOrigin = null!; + private Bindable canRotateSelectionOrigin = null!; + public SelectionRotationHandler RotationHandler { get; init; } = null!; public TransformToolboxGroup() @@ -52,8 +55,11 @@ protected override void LoadComplete() base.LoadComplete(); // aggregate two values into canRotate - RotationHandler.CanRotatePlayfieldOrigin.BindValueChanged(_ => updateCanRotateAggregate()); - RotationHandler.CanRotateSelectionOrigin.BindValueChanged(_ => updateCanRotateAggregate()); + canRotatePlayfieldOrigin = RotationHandler.CanRotatePlayfieldOrigin.GetBoundCopy(); + canRotatePlayfieldOrigin.BindValueChanged(_ => updateCanRotateAggregate()); + + canRotateSelectionOrigin = RotationHandler.CanRotateSelectionOrigin.GetBoundCopy(); + canRotateSelectionOrigin.BindValueChanged(_ => updateCanRotateAggregate()); void updateCanRotateAggregate() { From eca242c1c73567433a25e34e075740b35ec7119d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 2 Apr 2024 13:17:16 +0800 Subject: [PATCH 14/15] Change tooltip text slightly --- osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs b/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs index da5023392083..caf02d1dda93 100644 --- a/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs +++ b/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs @@ -70,7 +70,7 @@ private void load() }; selectionCentreButton.Selected.DisabledChanged += isDisabled => { - selectionCentreButton.TooltipText = isDisabled ? "Select more than one circles to perform rotation." : string.Empty; + selectionCentreButton.TooltipText = isDisabled ? "Select more than one objects to perform selection-based rotation." : string.Empty; }; } From 6642702fa94e1819ec13243d87a6626c88e88a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=C3=AAn=20Minh=20H=E1=BB=93?= <32929093+honguyenminh@users.noreply.github.com> Date: Tue, 2 Apr 2024 12:36:44 +0700 Subject: [PATCH 15/15] Update plurals in editor rotate button tooltip Co-authored-by: Joseph Madamba --- osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs b/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs index caf02d1dda93..88c3d7414ba0 100644 --- a/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs +++ b/osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs @@ -70,7 +70,7 @@ private void load() }; selectionCentreButton.Selected.DisabledChanged += isDisabled => { - selectionCentreButton.TooltipText = isDisabled ? "Select more than one objects to perform selection-based rotation." : string.Empty; + selectionCentreButton.TooltipText = isDisabled ? "Select more than one object to perform selection-based rotation." : string.Empty; }; }