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

Merge pull request #17776 from frenzibyte/dangerous-dialog-button-bounds

Fix dialog dangerous button being clickable at edges
This commit is contained in:
Dean Herbert 2022-04-12 15:40:50 +09:00 committed by GitHub
commit e901857610
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 22 deletions

View File

@ -4,25 +4,58 @@
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Testing;
using osu.Game.Overlays.Dialog; using osu.Game.Overlays.Dialog;
using osuTK;
using osuTK.Input;
namespace osu.Game.Tests.Visual.UserInterface namespace osu.Game.Tests.Visual.UserInterface
{ {
[TestFixture] public class TestScenePopupDialog : OsuManualInputManagerTestScene
public class TestScenePopupDialog : OsuTestScene
{ {
public TestScenePopupDialog() private TestPopupDialog dialog;
[SetUpSteps]
public void SetUpSteps()
{ {
AddStep("new popup", () => AddStep("new popup", () =>
Add(new TestPopupDialog {
Add(dialog = new TestPopupDialog
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
State = { Value = Framework.Graphics.Containers.Visibility.Visible }, 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 private class TestPopupDialog : PopupDialog
{ {
public PopupDialogDangerousButton DangerousButton { get; }
public bool DangerousButtonInvoked;
public TestPopupDialog() public TestPopupDialog()
{ {
Icon = FontAwesome.Solid.AssistiveListeningSystems; Icon = FontAwesome.Solid.AssistiveListeningSystems;
@ -40,9 +73,10 @@ namespace osu.Game.Tests.Visual.UserInterface
{ {
Text = @"You're a fake!", Text = @"You're a fake!",
}, },
new PopupDialogDangerousButton DangerousButton = new PopupDialogDangerousButton
{ {
Text = @"Careful with this one..", Text = @"Careful with this one..",
Action = () => DangerousButtonInvoked = true,
}, },
}; };
} }

View File

@ -12,37 +12,38 @@ namespace osu.Game.Overlays.Dialog
{ {
public class PopupDialogDangerousButton : PopupDialogButton public class PopupDialogDangerousButton : PopupDialogButton
{ {
private Box progressBox;
private DangerousConfirmContainer confirmContainer;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
ButtonColour = colours.Red3; ButtonColour = colours.Red3;
ColourContainer.Add(new ConfirmFillBox ColourContainer.Add(progressBox = new Box
{ {
Action = () => Action(),
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Blending = BlendingParameters.Additive, Blending = BlendingParameters.Additive,
}); });
}
private class ConfirmFillBox : HoldToConfirmContainer AddInternal(confirmContainer = new DangerousConfirmContainer
{ {
private Box box; Action = () => Action(),
RelativeSizeAxes = Axes.Both,
protected override double? HoldActivationDelay => 500; });
}
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
Child = box = new Box confirmContainer.Progress.BindValueChanged(progress => progressBox.Width = (float)progress.NewValue, true);
{
RelativeSizeAxes = Axes.Both,
};
Progress.BindValueChanged(progress => box.Width = (float)progress.NewValue, true);
} }
private class DangerousConfirmContainer : HoldToConfirmContainer
{
protected override double? HoldActivationDelay => 500;
protected override bool OnMouseDown(MouseDownEvent e) protected override bool OnMouseDown(MouseDownEvent e)
{ {
BeginConfirm(); BeginConfirm();