mirror of
https://github.com/osukey/osukey.git
synced 2025-05-15 02:27:33 +09:00
Merge pull request #20215 from peppy/notification-dismiss
Allow dismissing notifications without performing action using middle / right click
This commit is contained in:
commit
b0980a7bf1
@ -12,12 +12,14 @@ using osu.Framework.Utils;
|
|||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.Notifications;
|
using osu.Game.Overlays.Notifications;
|
||||||
|
using osuTK;
|
||||||
|
using osuTK.Input;
|
||||||
using osu.Game.Updater;
|
using osu.Game.Updater;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class TestSceneNotificationOverlay : OsuTestScene
|
public class TestSceneNotificationOverlay : OsuManualInputManagerTestScene
|
||||||
{
|
{
|
||||||
private NotificationOverlay notificationOverlay = null!;
|
private NotificationOverlay notificationOverlay = null!;
|
||||||
|
|
||||||
@ -33,7 +35,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
TimeToCompleteProgress = 2000;
|
TimeToCompleteProgress = 2000;
|
||||||
progressingNotifications.Clear();
|
progressingNotifications.Clear();
|
||||||
|
|
||||||
Content.Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
notificationOverlay = new NotificationOverlay
|
notificationOverlay = new NotificationOverlay
|
||||||
{
|
{
|
||||||
@ -46,6 +48,89 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
notificationOverlay.UnreadCount.ValueChanged += count => { displayedCount.Text = $"displayed count: {count.NewValue}"; };
|
notificationOverlay.UnreadCount.ValueChanged += count => { displayedCount.Text = $"displayed count: {count.NewValue}"; };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestDismissWithoutActivationCloseButton()
|
||||||
|
{
|
||||||
|
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()
|
||||||
|
.ChildrenOfType<Notification.CloseButton>().Single());
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddUntilStep("wait for closed", () => notification.WasClosed);
|
||||||
|
AddAssert("was not activated", () => !activated);
|
||||||
|
AddStep("reset mouse position", () => InputManager.MoveMouseTo(Vector2.Zero));
|
||||||
|
}
|
||||||
|
|
||||||
|
[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]
|
[Test]
|
||||||
public void TestPresence()
|
public void TestPresence()
|
||||||
{
|
{
|
||||||
|
@ -16,6 +16,7 @@ using osu.Game.Graphics;
|
|||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
using osuTK.Input;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Notifications
|
namespace osu.Game.Overlays.Notifications
|
||||||
{
|
{
|
||||||
@ -170,11 +171,25 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
base.OnHoverLost(e);
|
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)
|
protected override bool OnClick(ClickEvent e)
|
||||||
{
|
{
|
||||||
if (Activated?.Invoke() ?? true)
|
// Clicking with anything but left button should dismiss but not perform the activation action.
|
||||||
Close();
|
if (e.Button == MouseButton.Left)
|
||||||
|
Activated?.Invoke();
|
||||||
|
|
||||||
|
Close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,7 +218,7 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
Expire();
|
Expire();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class CloseButton : OsuClickableContainer
|
internal class CloseButton : OsuClickableContainer
|
||||||
{
|
{
|
||||||
private SpriteIcon icon = null!;
|
private SpriteIcon icon = null!;
|
||||||
private Box background = null!;
|
private Box background = null!;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user