1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 21:03:08 +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 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,
},
};
}

View File

@ -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,
});
}
private class ConfirmFillBox : HoldToConfirmContainer
AddInternal(confirmContainer = new DangerousConfirmContainer
{
private Box box;
protected override double? HoldActivationDelay => 500;
Action = () => Action(),
RelativeSizeAxes = Axes.Both,
});
}
protected override void LoadComplete()
{
base.LoadComplete();
Child = box = new Box
{
RelativeSizeAxes = Axes.Both,
};
Progress.BindValueChanged(progress => box.Width = (float)progress.NewValue, true);
confirmContainer.Progress.BindValueChanged(progress => progressBox.Width = (float)progress.NewValue, true);
}
private class DangerousConfirmContainer : HoldToConfirmContainer
{
protected override double? HoldActivationDelay => 500;
protected override bool OnMouseDown(MouseDownEvent e)
{
BeginConfirm();