mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 15:53:51 +08:00
Allow dismissing notifications without performing action using middle / right click
This commit is contained in:
parent
7f5fe56c1d
commit
efe3b1aa7b
@ -12,11 +12,13 @@ using osu.Framework.Utils;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
using osuTK;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestSceneNotificationOverlay : OsuTestScene
|
||||
public class TestSceneNotificationOverlay : OsuManualInputManagerTestScene
|
||||
{
|
||||
private NotificationOverlay notificationOverlay = null!;
|
||||
|
||||
@ -32,7 +34,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
TimeToCompleteProgress = 2000;
|
||||
progressingNotifications.Clear();
|
||||
|
||||
Content.Children = new Drawable[]
|
||||
Children = new Drawable[]
|
||||
{
|
||||
notificationOverlay = new NotificationOverlay
|
||||
{
|
||||
@ -45,6 +47,60 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
notificationOverlay.UnreadCount.ValueChanged += count => { displayedCount.Text = $"displayed count: {count.NewValue}"; };
|
||||
});
|
||||
|
||||
[Test]
|
||||
public void TestDismissWithoutActivationRightClick()
|
||||
{
|
||||
bool activated = false;
|
||||
SimpleNotification notification = null!;
|
||||
|
||||
AddStep("post", () =>
|
||||
{
|
||||
activated = false;
|
||||
notificationOverlay.Post(notification = new SimpleNotification
|
||||
{
|
||||
Text = @"Welcome to osu!. Enjoy your stay!",
|
||||
Activated = () => activated = true,
|
||||
});
|
||||
});
|
||||
|
||||
AddStep("click to activate", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(notificationOverlay.ChildrenOfType<Notification>().Single());
|
||||
InputManager.Click(MouseButton.Right);
|
||||
});
|
||||
|
||||
AddUntilStep("wait for closed", () => notification.WasClosed);
|
||||
AddAssert("was not activated", () => !activated);
|
||||
AddStep("reset mouse position", () => InputManager.MoveMouseTo(Vector2.Zero));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestActivate()
|
||||
{
|
||||
bool activated = false;
|
||||
SimpleNotification notification = null!;
|
||||
|
||||
AddStep("post", () =>
|
||||
{
|
||||
activated = false;
|
||||
notificationOverlay.Post(notification = new SimpleNotification
|
||||
{
|
||||
Text = @"Welcome to osu!. Enjoy your stay!",
|
||||
Activated = () => activated = true,
|
||||
});
|
||||
});
|
||||
|
||||
AddStep("click to activate", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(notificationOverlay.ChildrenOfType<Notification>().Single());
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
AddUntilStep("wait for closed", () => notification.WasClosed);
|
||||
AddAssert("was activated", () => activated);
|
||||
AddStep("reset mouse position", () => InputManager.MoveMouseTo(Vector2.Zero));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPresence()
|
||||
{
|
||||
|
@ -16,6 +16,7 @@ using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Overlays.Notifications
|
||||
{
|
||||
@ -170,11 +171,25 @@ namespace osu.Game.Overlays.Notifications
|
||||
base.OnHoverLost(e);
|
||||
}
|
||||
|
||||
protected override bool OnMouseDown(MouseDownEvent e)
|
||||
{
|
||||
// right click doesn't trigger OnClick so we need to handle here until that changes.
|
||||
if (e.Button != MouseButton.Left)
|
||||
{
|
||||
Close();
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.OnMouseDown(e);
|
||||
}
|
||||
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
{
|
||||
if (Activated?.Invoke() ?? true)
|
||||
Close();
|
||||
// Clicking with anything but left button should dismiss but not perform the activation action.
|
||||
if (e.Button == MouseButton.Left)
|
||||
Activated?.Invoke();
|
||||
|
||||
Close();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user