1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:17:23 +08:00

Ensure drag position is reset when transferred to tray

This commit is contained in:
Dean Herbert 2022-09-11 21:52:19 +09:00
parent b5a2f7003e
commit a56cadcf90
2 changed files with 26 additions and 11 deletions

View File

@ -159,7 +159,7 @@ namespace osu.Game.Overlays
if (State.Value == Visibility.Hidden)
{
notification.IsInTray = true;
notification.IsInToastTray = true;
toastTray.Post(notification);
}
else
@ -170,7 +170,7 @@ namespace osu.Game.Overlays
private void addPermanently(Notification notification)
{
notification.IsInTray = false;
notification.IsInToastTray = false;
var ourType = notification.GetType();
int depth = notification.DisplayOnTop ? -runningDepth : runningDepth;

View File

@ -68,10 +68,21 @@ namespace osu.Game.Overlays.Notifications
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
private bool isInToastTray;
/// <summary>
/// Whether this notification is in the <see cref="NotificationOverlayToastTray"/>.
/// </summary>
public bool IsInTray { get; set; }
public bool IsInToastTray
{
private get => isInToastTray;
set
{
isInToastTray = value;
if (!isInToastTray)
dragContainer.ResetPosition();
}
}
private readonly Box initialFlash;
@ -267,10 +278,13 @@ namespace osu.Game.Overlays.Notifications
}
}
protected override bool OnDragStart(DragStartEvent e) => notification.IsInTray;
protected override bool OnDragStart(DragStartEvent e) => notification.IsInToastTray;
protected override void OnDrag(DragEvent e)
{
if (!notification.IsInToastTray)
return;
Vector2 change = e.MousePosition - e.MouseDownPosition;
// Diminish the drag distance as we go further to simulate "rubber band" feeling.
@ -286,14 +300,9 @@ namespace osu.Game.Overlays.Notifications
protected override void OnDragEnd(DragEndEvent e)
{
if (Rotation < -10 || velocity.X < -0.3f)
{
FlingLeft();
}
else
{
this.MoveTo(Vector2.Zero, 800, Easing.OutElastic);
this.RotateTo(0, 800, Easing.OutElastic);
}
ResetPosition();
base.OnDragEnd(e);
}
@ -331,7 +340,7 @@ namespace osu.Game.Overlays.Notifications
public bool FlingLeft()
{
if (!notification.IsInTray)
if (!notification.IsInToastTray)
return false;
if (flinging)
@ -345,6 +354,12 @@ namespace osu.Game.Overlays.Notifications
notification.Close();
return true;
}
public void ResetPosition()
{
this.MoveTo(Vector2.Zero, 800, Easing.OutElastic);
this.RotateTo(0, 800, Easing.OutElastic);
}
}
internal class CloseButton : OsuClickableContainer