From 6d206c25162d34b1933162371957a2b0ae26896d Mon Sep 17 00:00:00 2001 From: HenintsoaSky Date: Wed, 11 Dec 2024 16:18:19 +0300 Subject: [PATCH 1/9] Make editor sidebar panel expand when clicked --- .../TestSceneExpandingToolboxContainer.cs | 50 +++++++++++++++++++ .../Edit/ExpandingToolboxContainer.cs | 7 ++- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs diff --git a/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs b/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs new file mode 100644 index 000000000000..2b9e88c0bd77 --- /dev/null +++ b/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs @@ -0,0 +1,50 @@ +using NUnit.Framework; +using osu.Framework.Graphics; +using osu.Framework.Testing; +using osu.Game.Rulesets.Edit; +using osuTK; +using osuTK.Input; + +namespace osu.Game.Tests.Visual.Editing +{ + [TestFixture] + public partial class TestSceneExpandingToolboxContainer : EditorClockTestScene + { + private ExpandingToolboxContainer toolbox; + + [SetUpSteps] + public void SetUpSteps() + { + AddStep("create toolbox", () => + { + toolbox = new ExpandingToolboxContainer(50, 200) + { + RelativeSizeAxes = Axes.Y, + Size = new Vector2(200, 500), + }; + Child = toolbox; + }); + } + + [Test] + public void TestOnMouseUpFunctionality() + { + AddStep("click on sidebar", () => + { + InputManager.MoveMouseTo(toolbox.ScreenSpaceDrawQuad.Centre); + InputManager.PressButton(MouseButton.Left); + InputManager.ReleaseButton(MouseButton.Left); + }); + AddAssert("sidebar remains expanded", () => toolbox.Expanded.Value); + + AddStep("hold and move cursor inside, release", () => + { + InputManager.MoveMouseTo(toolbox.ScreenSpaceDrawQuad.Centre); + InputManager.PressButton(MouseButton.Left); + InputManager.MoveMouseTo(toolbox.ScreenSpaceDrawQuad.BottomLeft); + InputManager.ReleaseButton(MouseButton.Left); + }); + AddAssert("sidebar remains expanded", () => toolbox.Expanded.Value); + } + } +} diff --git a/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs b/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs index 8af795f8804d..a0c1e7bdfa77 100644 --- a/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs +++ b/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs @@ -63,6 +63,11 @@ protected override void Update() protected override bool OnMouseDown(MouseDownEvent e) => true; - protected override bool OnClick(ClickEvent e) => true; + protected override void OnMouseUp(MouseUpEvent e) + { + base.OnMouseUp(e); + + Expanded.Value = FillFlow.ScreenSpaceDrawQuad.Contains(e.ScreenSpaceMousePosition); + } } } From cdf35f0688b7877f09253be94841bc26c7e13ac3 Mon Sep 17 00:00:00 2001 From: HenintsoaSky Date: Wed, 11 Dec 2024 16:57:34 +0300 Subject: [PATCH 2/9] Fix license header missing --- .../Visual/Editing/TestSceneExpandingToolboxContainer.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs b/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs index 2b9e88c0bd77..05537375134b 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs @@ -1,3 +1,6 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Testing; From fb74ea29452141ef86900090c40c854f46efe105 Mon Sep 17 00:00:00 2001 From: HenintsoaSky Date: Wed, 11 Dec 2024 17:14:22 +0300 Subject: [PATCH 3/9] Fix CI failures --- .../Visual/Editing/TestSceneExpandingToolboxContainer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs b/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs index 05537375134b..a43674404e81 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs @@ -13,7 +13,7 @@ namespace osu.Game.Tests.Visual.Editing [TestFixture] public partial class TestSceneExpandingToolboxContainer : EditorClockTestScene { - private ExpandingToolboxContainer toolbox; + private ExpandingToolboxContainer toolbox = null!; [SetUpSteps] public void SetUpSteps() From 07a86fc6bb9b6be53909f10813593a994d191df5 Mon Sep 17 00:00:00 2001 From: HenintsoaSky Date: Thu, 12 Dec 2024 11:24:44 +0300 Subject: [PATCH 4/9] Change behaviour Use OnClick instead of OnMouseUp --- osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs b/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs index a0c1e7bdfa77..33161f3855df 100644 --- a/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs +++ b/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs @@ -63,11 +63,16 @@ protected override void Update() protected override bool OnMouseDown(MouseDownEvent e) => true; - protected override void OnMouseUp(MouseUpEvent e) + protected override bool OnClick(ClickEvent e) { - base.OnMouseUp(e); + if (!ReceivePositionalInputAt(e.ScreenSpaceMousePosition)) return false; - Expanded.Value = FillFlow.ScreenSpaceDrawQuad.Contains(e.ScreenSpaceMousePosition); + base.OnClick(e); + + if (contractSidebars.Value) + Expanded.Value = !Expanded.Value; + + return true; } } } From 3325b032dd493738d5713a179250e7225e666546 Mon Sep 17 00:00:00 2001 From: HenintsoaSky Date: Thu, 12 Dec 2024 13:08:14 +0300 Subject: [PATCH 5/9] Prevent unnecessary collapsing on click Adjusted OnClick logic in ExpandingToolboxContainer to ensure the container does not collapse when clicked after being expanded. --- osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs b/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs index 33161f3855df..aa9050d9ed57 100644 --- a/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs +++ b/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs @@ -69,8 +69,10 @@ protected override bool OnClick(ClickEvent e) base.OnClick(e); - if (contractSidebars.Value) - Expanded.Value = !Expanded.Value; + if (contractSidebars.Value && !Expanded.Value) + { + Expanded.Value = true; + } return true; } From dd012604fecf5b04f54cc91f7dcda9ecd6a8cb40 Mon Sep 17 00:00:00 2001 From: HenintsoaSky Date: Fri, 13 Dec 2024 11:38:59 +0300 Subject: [PATCH 6/9] Change tests --- .../TestSceneExpandingToolboxContainer.cs | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs b/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs index a43674404e81..9ef7db27cf6a 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs @@ -4,6 +4,8 @@ using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Testing; +using osu.Framework.Bindables; +using osu.Game.Configuration; using osu.Game.Rulesets.Edit; using osuTK; using osuTK.Input; @@ -14,6 +16,7 @@ namespace osu.Game.Tests.Visual.Editing public partial class TestSceneExpandingToolboxContainer : EditorClockTestScene { private ExpandingToolboxContainer toolbox = null!; + private Bindable contractSidebars = null!; [SetUpSteps] public void SetUpSteps() @@ -27,27 +30,35 @@ public void SetUpSteps() }; Child = toolbox; }); + AddStep("load contractSidebars configuration", () => + { + var config = new OsuConfigManager(LocalStorage); + contractSidebars = config.GetBindable(OsuSetting.EditorContractSidebars); + contractSidebars.Value = true; + }); } [Test] - public void TestOnMouseUpFunctionality() + public void TestExpandingToolbox() { - AddStep("click on sidebar", () => + AddStep("state - sidebar collapsed", () => toolbox.Expanded.Value = false); + AddStep("click on toolbox", () => { InputManager.MoveMouseTo(toolbox.ScreenSpaceDrawQuad.Centre); - InputManager.PressButton(MouseButton.Left); - InputManager.ReleaseButton(MouseButton.Left); + InputManager.Click(MouseButton.Left); + AddAssert("sidebar expands after click", () => toolbox.Expanded.Value); }); - AddAssert("sidebar remains expanded", () => toolbox.Expanded.Value); - AddStep("hold and move cursor inside, release", () => + AddStep("state - sidebar collapsed", () => toolbox.Expanded.Value = false); + + AddStep("hold and move cursor inside", () => { - InputManager.MoveMouseTo(toolbox.ScreenSpaceDrawQuad.Centre); + InputManager.MoveMouseTo(toolbox.ScreenSpaceDrawQuad.TopLeft); InputManager.PressButton(MouseButton.Left); - InputManager.MoveMouseTo(toolbox.ScreenSpaceDrawQuad.BottomLeft); + InputManager.MoveMouseTo(toolbox.ScreenSpaceDrawQuad.BottomRight); InputManager.ReleaseButton(MouseButton.Left); + AddAssert("sidebar remains collapsed", () => !toolbox.Expanded.Value); }); - AddAssert("sidebar remains expanded", () => toolbox.Expanded.Value); } } } From b5c844200b8820a153b288e0bdbb64a90c618cfd Mon Sep 17 00:00:00 2001 From: HenintsoaSky Date: Tue, 17 Dec 2024 18:12:07 +0300 Subject: [PATCH 7/9] Address comments - Removed redundant conditional check: `if (!ReceivePositionalInputAt(e.ScreenSpaceMousePosition)) return false;` - Unnested `AddAssert("sidebar expands after click", () => toolbox.Expanded.Value)` --- .../Visual/Editing/TestSceneExpandingToolboxContainer.cs | 2 +- osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs b/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs index 9ef7db27cf6a..bcede3d90722 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs @@ -46,8 +46,8 @@ public void TestExpandingToolbox() { InputManager.MoveMouseTo(toolbox.ScreenSpaceDrawQuad.Centre); InputManager.Click(MouseButton.Left); - AddAssert("sidebar expands after click", () => toolbox.Expanded.Value); }); + AddAssert("sidebar expands after click", () => toolbox.Expanded.Value); AddStep("state - sidebar collapsed", () => toolbox.Expanded.Value = false); diff --git a/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs b/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs index aa9050d9ed57..2b242548caee 100644 --- a/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs +++ b/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs @@ -65,8 +65,6 @@ protected override void Update() protected override bool OnClick(ClickEvent e) { - if (!ReceivePositionalInputAt(e.ScreenSpaceMousePosition)) return false; - base.OnClick(e); if (contractSidebars.Value && !Expanded.Value) From df3e581253b11ff8e44ccf1ffe16f2e75529614d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 26 Dec 2024 10:31:24 +0100 Subject: [PATCH 8/9] Fix broken test & remove weird dependency on config --- .../TestSceneExpandingToolboxContainer.cs | 32 ++++++++----------- .../Edit/ExpandingToolboxContainer.cs | 4 +-- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs b/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs index bcede3d90722..ad73c0dbc797 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs @@ -4,19 +4,16 @@ using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Testing; -using osu.Framework.Bindables; -using osu.Game.Configuration; +using osu.Framework.Graphics.Shapes; using osu.Game.Rulesets.Edit; -using osuTK; using osuTK.Input; namespace osu.Game.Tests.Visual.Editing { [TestFixture] - public partial class TestSceneExpandingToolboxContainer : EditorClockTestScene + public partial class TestSceneExpandingToolboxContainer : OsuManualInputManagerTestScene { private ExpandingToolboxContainer toolbox = null!; - private Bindable contractSidebars = null!; [SetUpSteps] public void SetUpSteps() @@ -25,40 +22,37 @@ public void SetUpSteps() { toolbox = new ExpandingToolboxContainer(50, 200) { - RelativeSizeAxes = Axes.Y, - Size = new Vector2(200, 500), + Child = new Box + { + RelativeSizeAxes = Axes.X, + Height = 1000, + Colour = Colour4.Red, + } }; Child = toolbox; }); - AddStep("load contractSidebars configuration", () => - { - var config = new OsuConfigManager(LocalStorage); - contractSidebars = config.GetBindable(OsuSetting.EditorContractSidebars); - contractSidebars.Value = true; - }); } [Test] public void TestExpandingToolbox() { - AddStep("state - sidebar collapsed", () => toolbox.Expanded.Value = false); + AddStep("collapse toolbox", () => toolbox.Expanded.Value = false); AddStep("click on toolbox", () => { InputManager.MoveMouseTo(toolbox.ScreenSpaceDrawQuad.Centre); InputManager.Click(MouseButton.Left); }); - AddAssert("sidebar expands after click", () => toolbox.Expanded.Value); - - AddStep("state - sidebar collapsed", () => toolbox.Expanded.Value = false); + AddUntilStep("toolbox expanded", () => toolbox.Expanded.Value); - AddStep("hold and move cursor inside", () => + AddStep("collapse toolbox", () => toolbox.Expanded.Value = false); + AddStep("drag cursor inside", () => { InputManager.MoveMouseTo(toolbox.ScreenSpaceDrawQuad.TopLeft); InputManager.PressButton(MouseButton.Left); InputManager.MoveMouseTo(toolbox.ScreenSpaceDrawQuad.BottomRight); InputManager.ReleaseButton(MouseButton.Left); - AddAssert("sidebar remains collapsed", () => !toolbox.Expanded.Value); }); + AddAssert("toolbox remains collapsed", () => !toolbox.Expanded.Value); } } } diff --git a/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs b/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs index 2b242548caee..381c72d51a45 100644 --- a/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs +++ b/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs @@ -67,10 +67,8 @@ protected override bool OnClick(ClickEvent e) { base.OnClick(e); - if (contractSidebars.Value && !Expanded.Value) - { + if (!Expanded.Value) Expanded.Value = true; - } return true; } From d37b4bc116363f1d14b02180d7d635161382f4fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 26 Dec 2024 10:35:50 +0100 Subject: [PATCH 9/9] Move click-to-expand logic to a higher level Think it makes more sense there. --- osu.Game/Graphics/Containers/ExpandingContainer.cs | 10 ++++++++++ osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs | 10 ---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/osu.Game/Graphics/Containers/ExpandingContainer.cs b/osu.Game/Graphics/Containers/ExpandingContainer.cs index 2abdb508aebf..baab7476e499 100644 --- a/osu.Game/Graphics/Containers/ExpandingContainer.cs +++ b/osu.Game/Graphics/Containers/ExpandingContainer.cs @@ -71,6 +71,16 @@ protected override bool OnHover(HoverEvent e) return true; } + protected override bool OnClick(ClickEvent e) + { + base.OnClick(e); + + if (!Expanded.Value) + Expanded.Value = true; + + return true; + } + protected override bool OnMouseMove(MouseMoveEvent e) { updateHoverExpansion(); diff --git a/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs b/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs index 381c72d51a45..d0164ceae24b 100644 --- a/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs +++ b/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs @@ -62,15 +62,5 @@ protected override void Update() private bool anyToolboxHovered(Vector2 screenSpacePos) => FillFlow.ScreenSpaceDrawQuad.Contains(screenSpacePos); protected override bool OnMouseDown(MouseDownEvent e) => true; - - protected override bool OnClick(ClickEvent e) - { - base.OnClick(e); - - if (!Expanded.Value) - Expanded.Value = true; - - return true; - } } }