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

Merge pull request #20478 from peppy/fix-progress-notification-fling

Fix progress notifications being able to be flung (and cancelled)
This commit is contained in:
Dan Balasescu 2022-09-26 18:21:12 +09:00 committed by GitHub
commit e5894ccd6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 3 deletions

View File

@ -107,9 +107,9 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("start drag", () =>
{
InputManager.MoveMouseTo(notification.ChildrenOfType<Notification>().Single());
InputManager.MoveMouseTo(notificationOverlay.ChildrenOfType<Notification>().Single());
InputManager.PressButton(MouseButton.Left);
InputManager.MoveMouseTo(notification.ChildrenOfType<Notification>().Single().ScreenSpaceDrawQuad.Centre + new Vector2(-500, 0));
InputManager.MoveMouseTo(notificationOverlay.ChildrenOfType<Notification>().Single().ScreenSpaceDrawQuad.Centre + new Vector2(-500, 0));
});
AddStep("fling away", () =>
@ -123,6 +123,45 @@ namespace osu.Game.Tests.Visual.UserInterface
AddAssert("unread count zero", () => notificationOverlay.UnreadCount.Value == 0);
}
[Test]
public void TestProgressNotificationCantBeFlung()
{
bool activated = false;
ProgressNotification notification = null!;
AddStep("post", () =>
{
activated = false;
notificationOverlay.Post(notification = new ProgressNotification
{
Text = @"Uploading to BSS...",
CompletionText = "Uploaded to BSS!",
Activated = () => activated = true,
});
progressingNotifications.Add(notification);
});
AddStep("start drag", () =>
{
InputManager.MoveMouseTo(notificationOverlay.ChildrenOfType<Notification>().Single());
InputManager.PressButton(MouseButton.Left);
InputManager.MoveMouseTo(notificationOverlay.ChildrenOfType<Notification>().Single().ScreenSpaceDrawQuad.Centre + new Vector2(-500, 0));
});
AddStep("attempt fling", () =>
{
InputManager.ReleaseButton(MouseButton.Left);
});
AddUntilStep("was not closed", () => !notification.WasClosed);
AddUntilStep("was not cancelled", () => notification.State == ProgressNotificationState.Active);
AddAssert("was not activated", () => !activated);
AddStep("reset mouse position", () => InputManager.MoveMouseTo(Vector2.Zero));
AddUntilStep("was completed", () => notification.State == ProgressNotificationState.Completed);
}
[Test]
public void TestDismissWithoutActivationCloseButton()
{

View File

@ -68,6 +68,8 @@ namespace osu.Game.Overlays.Notifications
public virtual bool Read { get; set; }
protected virtual bool AllowFlingDismiss => true;
public new bool IsDragged => dragContainer.IsDragged;
protected virtual IconUsage CloseButtonIcon => FontAwesome.Solid.Check;
@ -315,7 +317,7 @@ namespace osu.Game.Overlays.Notifications
protected override void OnDragEnd(DragEndEvent e)
{
if (Rotation < -10 || velocity.X < -0.3f)
if (notification.AllowFlingDismiss && (Rotation < -10 || velocity.X < -0.3f))
notification.Close(true);
else if (X > 30 || velocity.X > 0.3f)
notification.ForwardToOverlay?.Invoke();

View File

@ -25,6 +25,8 @@ namespace osu.Game.Overlays.Notifications
public Func<bool>? CancelRequested { get; set; }
protected override bool AllowFlingDismiss => false;
/// <summary>
/// The function to post completion notifications back to.
/// </summary>