From 74dfa79f17c36949189e247b4ab9cdd0aaa8b949 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 11 Apr 2022 20:50:19 +0300 Subject: [PATCH 1/2] Add failing test case --- .../UserInterface/TestScenePopupDialog.cs | 46 ++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestScenePopupDialog.cs b/osu.Game.Tests/Visual/UserInterface/TestScenePopupDialog.cs index 6bd6115e68..b5f2544071 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestScenePopupDialog.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestScenePopupDialog.cs @@ -4,25 +4,58 @@ using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; +using osu.Framework.Testing; using osu.Game.Overlays.Dialog; +using osuTK; +using osuTK.Input; namespace osu.Game.Tests.Visual.UserInterface { - [TestFixture] - public class TestScenePopupDialog : OsuTestScene + public class TestScenePopupDialog : OsuManualInputManagerTestScene { - public TestScenePopupDialog() + private TestPopupDialog dialog; + + [SetUpSteps] + public void SetUpSteps() { AddStep("new popup", () => - Add(new TestPopupDialog + { + Add(dialog = new TestPopupDialog { RelativeSizeAxes = Axes.Both, State = { Value = Framework.Graphics.Containers.Visibility.Visible }, - })); + }); + }); + } + + [Test] + public void TestDangerousButton([Values(false, true)] bool atEdge) + { + if (atEdge) + { + AddStep("move mouse to button edge", () => + { + var dangerousButtonQuad = dialog.DangerousButton.ScreenSpaceDrawQuad; + InputManager.MoveMouseTo(new Vector2(dangerousButtonQuad.TopLeft.X + 5, dangerousButtonQuad.Centre.Y)); + }); + } + else + AddStep("move mouse to button", () => InputManager.MoveMouseTo(dialog.DangerousButton)); + + AddStep("click button", () => InputManager.Click(MouseButton.Left)); + AddAssert("action not invoked", () => !dialog.DangerousButtonInvoked); + + AddStep("hold button", () => InputManager.PressButton(MouseButton.Left)); + AddUntilStep("action invoked", () => dialog.DangerousButtonInvoked); + AddStep("release button", () => InputManager.ReleaseButton(MouseButton.Left)); } private class TestPopupDialog : PopupDialog { + public PopupDialogDangerousButton DangerousButton { get; } + + public bool DangerousButtonInvoked; + public TestPopupDialog() { Icon = FontAwesome.Solid.AssistiveListeningSystems; @@ -40,9 +73,10 @@ namespace osu.Game.Tests.Visual.UserInterface { Text = @"You're a fake!", }, - new PopupDialogDangerousButton + DangerousButton = new PopupDialogDangerousButton { Text = @"Careful with this one..", + Action = () => DangerousButtonInvoked = true, }, }; } From bad30d9e602537a6e2afbfb41333d89d9235a4c4 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 11 Apr 2022 21:05:37 +0300 Subject: [PATCH 2/2] Fix dialog dangerous button being clickable at edges --- .../Dialog/PopupDialogDangerousButton.cs | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/osu.Game/Overlays/Dialog/PopupDialogDangerousButton.cs b/osu.Game/Overlays/Dialog/PopupDialogDangerousButton.cs index 1911a4fa56..adc627e15b 100644 --- a/osu.Game/Overlays/Dialog/PopupDialogDangerousButton.cs +++ b/osu.Game/Overlays/Dialog/PopupDialogDangerousButton.cs @@ -12,37 +12,38 @@ namespace osu.Game.Overlays.Dialog { public class PopupDialogDangerousButton : PopupDialogButton { + private Box progressBox; + private DangerousConfirmContainer confirmContainer; + [BackgroundDependencyLoader] private void load(OsuColour colours) { ButtonColour = colours.Red3; - ColourContainer.Add(new ConfirmFillBox + ColourContainer.Add(progressBox = new Box { - Action = () => Action(), RelativeSizeAxes = Axes.Both, Blending = BlendingParameters.Additive, }); + + AddInternal(confirmContainer = new DangerousConfirmContainer + { + Action = () => Action(), + RelativeSizeAxes = Axes.Both, + }); } - private class ConfirmFillBox : HoldToConfirmContainer + protected override void LoadComplete() { - private Box box; + base.LoadComplete(); + confirmContainer.Progress.BindValueChanged(progress => progressBox.Width = (float)progress.NewValue, true); + } + + private class DangerousConfirmContainer : HoldToConfirmContainer + { protected override double? HoldActivationDelay => 500; - protected override void LoadComplete() - { - base.LoadComplete(); - - Child = box = new Box - { - RelativeSizeAxes = Axes.Both, - }; - - Progress.BindValueChanged(progress => box.Width = (float)progress.NewValue, true); - } - protected override bool OnMouseDown(MouseDownEvent e) { BeginConfirm();