1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 00:42:55 +08:00

Merge pull request #16678 from peppy/hold-for-menu-always-fade

Ensure hold for menu button fades out if the cursor is never moved
This commit is contained in:
Dan Balasescu 2022-01-28 15:55:41 +09:00 committed by GitHub
commit b94984bd2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 15 deletions

View File

@ -3,9 +3,9 @@
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Testing;
using osu.Game.Screens.Play.HUD;
using osuTK;
using osuTK.Input;
@ -19,28 +19,35 @@ namespace osu.Game.Tests.Visual.Gameplay
protected override double TimePerAction => 100; // required for the early exit test, since hold-to-confirm delay is 200ms
[BackgroundDependencyLoader]
private void load()
private HoldForMenuButton holdForMenuButton;
[SetUpSteps]
public void SetUpSteps()
{
HoldForMenuButton holdForMenuButton;
Add(holdForMenuButton = new HoldForMenuButton
AddStep("create button", () =>
{
Origin = Anchor.BottomRight,
Anchor = Anchor.BottomRight,
Action = () => exitAction = true
exitAction = false;
Child = holdForMenuButton = new HoldForMenuButton
{
Scale = new Vector2(2),
Origin = Anchor.CentreRight,
Anchor = Anchor.CentreRight,
Action = () => exitAction = true
};
});
}
var text = holdForMenuButton.Children.OfType<SpriteText>().First();
[Test]
public void TestMovementAndTrigger()
{
AddStep("Trigger text fade in", () => InputManager.MoveMouseTo(holdForMenuButton));
AddUntilStep("Text visible", () => text.IsPresent && !exitAction);
AddUntilStep("Text visible", () => getSpriteText().IsPresent && !exitAction);
AddStep("Trigger text fade out", () => InputManager.MoveMouseTo(Vector2.One));
AddUntilStep("Text is not visible", () => !text.IsPresent && !exitAction);
AddUntilStep("Text is not visible", () => !getSpriteText().IsPresent && !exitAction);
AddStep("Trigger exit action", () =>
{
exitAction = false;
InputManager.MoveMouseTo(holdForMenuButton);
InputManager.PressButton(MouseButton.Left);
});
@ -50,6 +57,17 @@ namespace osu.Game.Tests.Visual.Gameplay
AddStep("Trigger exit action", () => InputManager.PressButton(MouseButton.Left));
AddUntilStep($"{nameof(holdForMenuButton.Action)} was triggered", () => exitAction);
AddStep("Release", () => InputManager.ReleaseButton(MouseButton.Left));
}
[Test]
public void TestFadeOnNoInput()
{
AddStep("move mouse away", () => InputManager.MoveMouseTo(Vector2.One));
AddUntilStep("wait for text fade out", () => !getSpriteText().IsPresent);
AddUntilStep("wait for button fade out", () => holdForMenuButton.Alpha < 0.1f);
}
private SpriteText getSpriteText() => holdForMenuButton.Children.OfType<SpriteText>().First();
}
}

View File

@ -80,7 +80,7 @@ namespace osu.Game.Screens.Play.HUD
base.LoadComplete();
}
private float positionalAdjust;
private float positionalAdjust = 1; // Start at 1 to handle the case where a user never send positional input.
protected override bool OnMouseMove(MouseMoveEvent e)
{