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

View File

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