2019-01-24 16:43:03 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
using System;
|
2022-09-11 20:32:22 +08:00
|
|
|
|
using System.Linq;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2017-03-05 02:42:37 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Colour;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-04-02 13:51:28 +08:00
|
|
|
|
using osu.Framework.Graphics.Effects;
|
2022-09-11 20:32:22 +08:00
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-03-27 18:29:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2022-01-25 22:38:46 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2022-09-11 20:32:22 +08:00
|
|
|
|
using osu.Framework.Utils;
|
2022-08-31 11:48:30 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2017-06-27 20:05:49 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2021-09-05 12:22:37 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2022-09-10 13:10:49 +08:00
|
|
|
|
using osuTK.Input;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
namespace osu.Game.Overlays.Notifications
|
|
|
|
|
{
|
|
|
|
|
public abstract partial class Notification : Container
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2022-09-16 15:36:56 +08:00
|
|
|
|
/// Notification was closed, either by user or otherwise.
|
|
|
|
|
/// Importantly, this event may be fired from a non-update thread.
|
2017-02-10 15:26:43 +08:00
|
|
|
|
/// </summary>
|
2022-08-30 14:51:46 +08:00
|
|
|
|
public event Action? Closed;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-01-25 22:38:46 +08:00
|
|
|
|
public abstract LocalisableString Text { get; set; }
|
|
|
|
|
|
2018-07-13 20:25:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether this notification should forcefully display itself.
|
|
|
|
|
/// </summary>
|
2018-07-16 12:00:21 +08:00
|
|
|
|
public virtual bool IsImportant => true;
|
2018-07-13 20:25:08 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Run on user activating the notification. Return true to close.
|
|
|
|
|
/// </summary>
|
2022-08-30 14:51:46 +08:00
|
|
|
|
public Func<bool>? Activated;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-09-12 19:18:40 +08:00
|
|
|
|
public Action? ForwardToOverlay { get; set; }
|
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Should we show at the top of our section on display?
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual bool DisplayOnTop => true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-09-05 12:22:37 +08:00
|
|
|
|
public virtual string PopInSampleName => "UI/notification-pop-in";
|
2021-01-15 14:21:50 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
protected NotificationLight Light;
|
2022-08-30 16:33:08 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
protected Container IconContent;
|
2022-08-30 16:33:08 +08:00
|
|
|
|
|
2022-09-16 15:36:56 +08:00
|
|
|
|
public bool WasClosed { get; private set; }
|
|
|
|
|
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly Container content;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
protected override Container<Drawable> Content => content;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-08-30 16:49:29 +08:00
|
|
|
|
protected Container MainContent;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-09-11 20:32:22 +08:00
|
|
|
|
private readonly DragContainer dragContainer;
|
|
|
|
|
|
2017-03-07 09:59:19 +08:00
|
|
|
|
public virtual bool Read { get; set; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-09-26 13:30:40 +08:00
|
|
|
|
protected virtual bool AllowFlingDismiss => true;
|
|
|
|
|
|
2022-09-12 14:21:01 +08:00
|
|
|
|
public new bool IsDragged => dragContainer.IsDragged;
|
|
|
|
|
|
2022-08-30 16:37:43 +08:00
|
|
|
|
protected virtual IconUsage CloseButtonIcon => FontAwesome.Solid.Check;
|
|
|
|
|
|
2022-08-30 16:58:32 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
|
|
|
|
|
2022-09-12 15:25:32 +08:00
|
|
|
|
public override bool PropagatePositionalInputSubTree => base.PropagatePositionalInputSubTree && !WasClosed;
|
|
|
|
|
|
2022-09-11 20:52:19 +08:00
|
|
|
|
private bool isInToastTray;
|
|
|
|
|
|
2022-09-11 20:34:35 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether this notification is in the <see cref="NotificationOverlayToastTray"/>.
|
|
|
|
|
/// </summary>
|
2022-09-11 20:52:19 +08:00
|
|
|
|
public bool IsInToastTray
|
|
|
|
|
{
|
2022-09-12 14:16:45 +08:00
|
|
|
|
get => isInToastTray;
|
2022-09-11 20:52:19 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
isInToastTray = value;
|
2022-09-12 14:16:45 +08:00
|
|
|
|
|
2022-09-11 20:52:19 +08:00
|
|
|
|
if (!isInToastTray)
|
2022-09-12 14:16:45 +08:00
|
|
|
|
{
|
2022-09-11 20:52:19 +08:00
|
|
|
|
dragContainer.ResetPosition();
|
2022-09-12 14:16:45 +08:00
|
|
|
|
if (!Read)
|
|
|
|
|
Light.FadeIn(100);
|
|
|
|
|
}
|
2022-09-11 20:52:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-11 20:34:35 +08:00
|
|
|
|
|
2022-08-30 19:34:27 +08:00
|
|
|
|
private readonly Box initialFlash;
|
|
|
|
|
|
2022-08-30 16:58:32 +08:00
|
|
|
|
private Box background = null!;
|
|
|
|
|
|
2017-03-09 13:01:08 +08:00
|
|
|
|
protected Notification()
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-08-30 16:33:08 +08:00
|
|
|
|
InternalChildren = new Drawable[]
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
|
|
|
|
Light = new NotificationLight
|
|
|
|
|
{
|
2022-09-12 14:16:45 +08:00
|
|
|
|
Alpha = 0,
|
2017-02-10 15:26:43 +08:00
|
|
|
|
Margin = new MarginPadding { Right = 5 },
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
},
|
2022-09-11 20:32:22 +08:00
|
|
|
|
dragContainer = new DragContainer(this)
|
|
|
|
|
{
|
2022-09-12 15:46:45 +08:00
|
|
|
|
// Use margin instead of FillFlow spacing to fix extra padding appearing when notification shrinks
|
|
|
|
|
// in height.
|
|
|
|
|
Padding = new MarginPadding { Vertical = 3f },
|
2022-09-11 20:32:22 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
}.WithChild(MainContent = new Container
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
2022-08-30 16:58:32 +08:00
|
|
|
|
CornerRadius = 6,
|
2017-02-10 15:26:43 +08:00
|
|
|
|
Masking = true,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2017-07-28 15:54:09 +08:00
|
|
|
|
AutoSizeDuration = 400,
|
|
|
|
|
AutoSizeEasing = Easing.OutQuint,
|
2017-02-10 15:26:43 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2022-08-30 16:33:08 +08:00
|
|
|
|
new GridContainer
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2017-07-28 15:54:09 +08:00
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2022-08-30 16:33:08 +08:00
|
|
|
|
RowDimensions = new[]
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
2022-08-30 16:33:08 +08:00
|
|
|
|
new Dimension(GridSizeMode.AutoSize, minSize: 60)
|
|
|
|
|
},
|
|
|
|
|
ColumnDimensions = new[]
|
|
|
|
|
{
|
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
|
new Dimension(),
|
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
|
},
|
|
|
|
|
Content = new[]
|
|
|
|
|
{
|
|
|
|
|
new Drawable[]
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
2022-08-30 16:33:08 +08:00
|
|
|
|
IconContent = new Container
|
|
|
|
|
{
|
|
|
|
|
Width = 40,
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
},
|
|
|
|
|
new Container
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
2022-08-30 16:33:08 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Padding = new MarginPadding(10),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
content = new Container
|
|
|
|
|
{
|
2022-08-30 18:17:40 +08:00
|
|
|
|
Masking = true,
|
2022-08-30 16:33:08 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
},
|
|
|
|
|
}
|
2017-02-10 15:26:43 +08:00
|
|
|
|
},
|
2022-08-30 16:37:43 +08:00
|
|
|
|
new CloseButton(CloseButtonIcon)
|
2022-08-30 16:33:08 +08:00
|
|
|
|
{
|
2022-09-12 15:54:25 +08:00
|
|
|
|
Action = () => Close(true),
|
2022-08-30 16:33:08 +08:00
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
}
|
2017-02-10 15:26:43 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2022-08-30 16:33:08 +08:00
|
|
|
|
},
|
2022-08-30 19:34:27 +08:00
|
|
|
|
initialFlash = new Box
|
|
|
|
|
{
|
|
|
|
|
Colour = Color4.White.Opacity(0.8f),
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Blending = BlendingParameters.Additive,
|
|
|
|
|
},
|
2017-02-10 15:26:43 +08:00
|
|
|
|
}
|
2022-09-11 20:32:22 +08:00
|
|
|
|
})
|
2022-08-30 16:33:08 +08:00
|
|
|
|
};
|
2017-02-10 15:26:43 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-08-30 16:33:08 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2022-08-30 16:58:32 +08:00
|
|
|
|
private void load()
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
2022-08-30 16:58:32 +08:00
|
|
|
|
MainContent.Add(background = new Box
|
2022-08-30 16:33:08 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = colourProvider.Background3,
|
|
|
|
|
Depth = float.MaxValue
|
|
|
|
|
});
|
2017-02-10 15:26:43 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-08-30 16:58:32 +08:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
|
{
|
|
|
|
|
background.FadeColour(colourProvider.Background2, 200, Easing.OutQuint);
|
|
|
|
|
return base.OnHover(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
|
{
|
|
|
|
|
background.FadeColour(colourProvider.Background3, 200, Easing.OutQuint);
|
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-10 13:10:49 +08:00
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
2022-09-10 13:10:49 +08:00
|
|
|
|
// right click doesn't trigger OnClick so we need to handle here until that changes.
|
|
|
|
|
if (e.Button != MouseButton.Left)
|
|
|
|
|
{
|
2022-09-12 15:54:25 +08:00
|
|
|
|
Close(true);
|
2022-09-10 13:10:49 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.OnMouseDown(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
|
{
|
|
|
|
|
// Clicking with anything but left button should dismiss but not perform the activation action.
|
2022-09-21 05:15:45 +08:00
|
|
|
|
if (e.Button == MouseButton.Left && Activated?.Invoke() == false)
|
|
|
|
|
return true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-09-12 17:57:18 +08:00
|
|
|
|
Close(false);
|
2017-02-10 15:26:43 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2021-01-15 14:21:50 +08:00
|
|
|
|
|
2017-07-15 00:18:12 +08:00
|
|
|
|
this.FadeInFromZero(200);
|
2022-08-30 16:33:08 +08:00
|
|
|
|
|
2022-08-30 16:49:29 +08:00
|
|
|
|
MainContent.MoveToX(DrawSize.X);
|
|
|
|
|
MainContent.MoveToX(0, 500, Easing.OutQuint);
|
2022-08-30 19:34:27 +08:00
|
|
|
|
|
|
|
|
|
initialFlash.FadeOutFromOne(2000, Easing.OutQuart);
|
2017-02-10 15:26:43 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-09-12 17:57:18 +08:00
|
|
|
|
public virtual void Close(bool runFlingAnimation)
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
2017-08-23 11:47:20 +08:00
|
|
|
|
if (WasClosed) return;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2017-08-23 11:47:20 +08:00
|
|
|
|
WasClosed = true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-09-12 18:00:03 +08:00
|
|
|
|
Closed?.Invoke();
|
2022-09-16 15:36:56 +08:00
|
|
|
|
|
|
|
|
|
Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
if (runFlingAnimation && dragContainer.FlingLeft())
|
|
|
|
|
this.FadeOut(600, Easing.In);
|
|
|
|
|
else
|
|
|
|
|
this.FadeOut(100);
|
|
|
|
|
|
|
|
|
|
Expire();
|
|
|
|
|
});
|
2017-02-10 15:26:43 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-09-11 20:32:22 +08:00
|
|
|
|
private partial class DragContainer : Container
|
|
|
|
|
{
|
|
|
|
|
private Vector2 velocity;
|
|
|
|
|
private Vector2 lastPosition;
|
|
|
|
|
|
|
|
|
|
private readonly Notification notification;
|
|
|
|
|
|
|
|
|
|
public DragContainer(Notification notification)
|
|
|
|
|
{
|
|
|
|
|
this.notification = notification;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override RectangleF BoundingBox
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var childBounding = Children.First().BoundingBox;
|
|
|
|
|
|
2022-09-12 15:39:46 +08:00
|
|
|
|
if (X < 0) childBounding *= new Vector2(1, Math.Max(0, 1 + (X / 300)));
|
|
|
|
|
if (Y > 0) childBounding *= new Vector2(1, Math.Max(0, 1 - (Y / 200)));
|
2022-09-11 20:32:22 +08:00
|
|
|
|
|
|
|
|
|
return childBounding;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-11 20:52:19 +08:00
|
|
|
|
protected override bool OnDragStart(DragStartEvent e) => notification.IsInToastTray;
|
2022-09-11 20:32:22 +08:00
|
|
|
|
|
|
|
|
|
protected override void OnDrag(DragEvent e)
|
|
|
|
|
{
|
2022-09-11 20:52:19 +08:00
|
|
|
|
if (!notification.IsInToastTray)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-09-11 20:32:22 +08:00
|
|
|
|
Vector2 change = e.MousePosition - e.MouseDownPosition;
|
|
|
|
|
|
|
|
|
|
// Diminish the drag distance as we go further to simulate "rubber band" feeling.
|
2022-09-12 14:37:48 +08:00
|
|
|
|
change *= change.Length <= 0 ? 0 : MathF.Pow(change.Length, 0.8f) / change.Length;
|
2022-09-11 20:32:22 +08:00
|
|
|
|
|
|
|
|
|
// Only apply Y change if dragging to the left.
|
2022-09-12 14:37:48 +08:00
|
|
|
|
if (change.X >= 0)
|
2022-09-11 20:32:22 +08:00
|
|
|
|
change.Y = 0;
|
2022-09-12 14:37:48 +08:00
|
|
|
|
else
|
|
|
|
|
change.Y *= (float)Interpolation.ApplyEasing(Easing.InOutQuart, Math.Min(1, -change.X / 200));
|
2022-09-11 20:32:22 +08:00
|
|
|
|
|
|
|
|
|
this.MoveTo(change);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnDragEnd(DragEndEvent e)
|
|
|
|
|
{
|
2022-09-26 13:30:40 +08:00
|
|
|
|
if (notification.AllowFlingDismiss && (Rotation < -10 || velocity.X < -0.3f))
|
2022-09-12 18:00:03 +08:00
|
|
|
|
notification.Close(true);
|
2022-09-12 19:18:40 +08:00
|
|
|
|
else if (X > 30 || velocity.X > 0.3f)
|
|
|
|
|
notification.ForwardToOverlay?.Invoke();
|
2022-09-11 20:32:22 +08:00
|
|
|
|
else
|
2022-09-11 20:52:19 +08:00
|
|
|
|
ResetPosition();
|
2022-09-11 20:32:22 +08:00
|
|
|
|
|
|
|
|
|
base.OnDragEnd(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool flinging;
|
|
|
|
|
|
|
|
|
|
protected override void UpdateAfterChildren()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateAfterChildren();
|
|
|
|
|
|
|
|
|
|
Rotation = Math.Min(0, X * 0.1f);
|
|
|
|
|
|
|
|
|
|
if (flinging)
|
|
|
|
|
{
|
|
|
|
|
velocity.Y += (float)Clock.ElapsedFrameTime * 0.005f;
|
|
|
|
|
Position += (float)Clock.ElapsedFrameTime * velocity;
|
|
|
|
|
}
|
2022-09-12 15:25:32 +08:00
|
|
|
|
else if (Clock.ElapsedFrameTime > 0)
|
2022-09-11 20:32:22 +08:00
|
|
|
|
{
|
|
|
|
|
Vector2 change = (Position - lastPosition) / (float)Clock.ElapsedFrameTime;
|
|
|
|
|
|
|
|
|
|
if (velocity.X == 0)
|
|
|
|
|
velocity = change;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
velocity = new Vector2(
|
|
|
|
|
(float)Interpolation.DampContinuously(velocity.X, change.X, 40, Clock.ElapsedFrameTime),
|
|
|
|
|
(float)Interpolation.DampContinuously(velocity.Y, change.Y, 40, Clock.ElapsedFrameTime)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lastPosition = Position;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool FlingLeft()
|
|
|
|
|
{
|
2022-09-11 20:52:19 +08:00
|
|
|
|
if (!notification.IsInToastTray)
|
2022-09-11 20:32:22 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (flinging)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (velocity.X > -0.3f)
|
|
|
|
|
velocity.X = -0.3f - 0.5f * RNG.NextSingle();
|
|
|
|
|
|
|
|
|
|
flinging = true;
|
|
|
|
|
ClearTransforms();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-09-11 20:52:19 +08:00
|
|
|
|
|
|
|
|
|
public void ResetPosition()
|
|
|
|
|
{
|
|
|
|
|
this.MoveTo(Vector2.Zero, 800, Easing.OutElastic);
|
|
|
|
|
this.RotateTo(0, 800, Easing.OutElastic);
|
|
|
|
|
}
|
2022-09-11 20:32:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-10 14:18:32 +08:00
|
|
|
|
internal partial class CloseButton : OsuClickableContainer
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
2022-08-30 16:33:08 +08:00
|
|
|
|
private SpriteIcon icon = null!;
|
|
|
|
|
private Box background = null!;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-08-30 16:37:43 +08:00
|
|
|
|
private readonly IconUsage iconUsage;
|
|
|
|
|
|
2022-08-30 16:33:08 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
|
|
|
|
|
2022-08-30 16:37:43 +08:00
|
|
|
|
public CloseButton(IconUsage iconUsage)
|
|
|
|
|
{
|
|
|
|
|
this.iconUsage = iconUsage;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-30 16:33:08 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
2022-08-30 16:33:08 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
2022-08-30 16:58:32 +08:00
|
|
|
|
Width = 28;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-08-30 16:33:08 +08:00
|
|
|
|
Children = new Drawable[]
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
2022-08-30 16:33:08 +08:00
|
|
|
|
background = new Box
|
|
|
|
|
{
|
2022-08-31 11:48:30 +08:00
|
|
|
|
Colour = OsuColour.Gray(0).Opacity(0.15f),
|
2022-08-30 16:33:08 +08:00
|
|
|
|
Alpha = 0,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
|
|
|
|
icon = new SpriteIcon
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
2017-03-06 16:06:48 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
2022-08-30 16:37:43 +08:00
|
|
|
|
Icon = iconUsage,
|
2022-08-30 16:33:08 +08:00
|
|
|
|
Size = new Vector2(12),
|
|
|
|
|
Colour = colourProvider.Foreground1,
|
2017-02-10 15:26:43 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
2022-08-30 16:58:32 +08:00
|
|
|
|
background.FadeIn(200, Easing.OutQuint);
|
|
|
|
|
icon.FadeColour(colourProvider.Content1, 200, Easing.OutQuint);
|
2018-10-02 11:02:47 +08:00
|
|
|
|
return base.OnHover(e);
|
2017-02-10 15:26:43 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
2022-08-30 16:58:32 +08:00
|
|
|
|
background.FadeOut(200, Easing.OutQuint);
|
|
|
|
|
icon.FadeColour(colourProvider.Foreground1, 200, Easing.OutQuint);
|
2018-10-02 11:02:47 +08:00
|
|
|
|
base.OnHoverLost(e);
|
2017-02-10 15:26:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
public partial class NotificationLight : Container
|
|
|
|
|
{
|
|
|
|
|
private bool pulsate;
|
2022-08-30 14:51:46 +08:00
|
|
|
|
private Container pulsateLayer = null!;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
public bool Pulsate
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => pulsate;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-07-09 17:23:34 +08:00
|
|
|
|
if (pulsate == value) return;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
pulsate = value;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-25 20:12:39 +08:00
|
|
|
|
pulsateLayer.ClearTransforms();
|
2017-02-10 15:26:43 +08:00
|
|
|
|
pulsateLayer.Alpha = 1;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
if (pulsate)
|
|
|
|
|
{
|
|
|
|
|
const float length = 1000;
|
2017-07-15 00:18:12 +08:00
|
|
|
|
pulsateLayer.Loop(length / 2,
|
2017-07-23 02:50:25 +08:00
|
|
|
|
p => p.FadeTo(0.4f, length, Easing.In).Then().FadeTo(1, length, Easing.Out)
|
2017-07-15 00:18:12 +08:00
|
|
|
|
);
|
2017-02-10 15:26:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
public new SRGBColour Colour
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
base.Colour = value;
|
2017-06-12 11:48:47 +08:00
|
|
|
|
pulsateLayer.EdgeEffect = new EdgeEffectParameters
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
|
|
|
|
Colour = ((Color4)value).Opacity(0.5f), //todo: avoid cast
|
|
|
|
|
Type = EdgeEffectType.Glow,
|
|
|
|
|
Radius = 12,
|
|
|
|
|
Roundness = 12,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2017-02-27 22:32:32 +08:00
|
|
|
|
private void load()
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(6, 15);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
pulsateLayer = new CircularContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Masking = true,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-25 17:31:32 +08:00
|
|
|
|
}
|