1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 05:42:54 +08:00
osu-lazer/osu.Game/Overlays/NotificationOverlay.cs

127 lines
4.3 KiB
C#
Raw Normal View History

2017-02-10 15:26:43 +08:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Overlays.Notifications;
using OpenTK.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.Containers;
2017-02-10 15:26:43 +08:00
namespace osu.Game.Overlays
{
public class NotificationOverlay : OsuFocusedOverlayContainer
2017-02-10 15:26:43 +08:00
{
private const float width = 320;
public const float TRANSITION_LENGTH = 600;
private ScrollContainer scrollContainer;
private FlowContainer<NotificationSection> sections;
[BackgroundDependencyLoader]
private void load()
2017-02-10 15:26:43 +08:00
{
Width = width;
RelativeSizeAxes = Axes.Y;
AlwaysPresent = true;
2017-02-10 15:26:43 +08:00
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
Alpha = 0.6f,
},
scrollContainer = new OsuScrollContainer
2017-02-10 15:26:43 +08:00
{
RelativeSizeAxes = Axes.Both,
2017-02-10 15:26:43 +08:00
Margin = new MarginPadding { Top = Toolbar.Toolbar.HEIGHT },
Children = new[]
{
2017-03-02 02:33:01 +08:00
sections = new FillFlowContainer<NotificationSection>
2017-02-10 15:26:43 +08:00
{
2017-03-04 18:00:17 +08:00
Direction = FillDirection.Vertical,
2017-02-10 15:26:43 +08:00
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
2017-06-08 15:27:35 +08:00
Children = new[]
2017-02-10 15:26:43 +08:00
{
new NotificationSection
{
Title = @"Notifications",
ClearText = @"Clear All",
2017-06-08 15:27:35 +08:00
AcceptTypes = new[] { typeof(SimpleNotification) },
2017-02-10 15:26:43 +08:00
},
new NotificationSection
{
Title = @"Running Tasks",
ClearText = @"Cancel All",
2017-06-08 15:27:35 +08:00
AcceptTypes = new[] { typeof(ProgressNotification) },
2017-02-10 15:26:43 +08:00
},
}
}
}
}
};
}
2017-03-07 09:59:19 +08:00
private int runningDepth;
2017-02-10 15:26:43 +08:00
private void notificationClosed()
{
// hide ourselves if all notifications have been dismissed.
if (sections.Select(c => c.DisplayedCount).Sum() == 0)
State = Visibility.Hidden;
}
2017-02-10 15:26:43 +08:00
public void Post(Notification notification)
{
Schedule(() =>
{
State = Visibility.Visible;
++runningDepth;
notification.Depth = notification.DisplayOnTop ? runningDepth : -runningDepth;
2017-02-10 15:26:43 +08:00
notification.Closed += notificationClosed;
var hasCompletionTarget = notification as IHasCompletionTarget;
if (hasCompletionTarget != null)
hasCompletionTarget.CompletionTarget = Post;
2017-02-10 15:26:43 +08:00
var ourType = notification.GetType();
sections.Children.FirstOrDefault(s => s.AcceptTypes.Any(accept => accept.IsAssignableFrom(ourType)))?.Add(notification);
});
2017-02-10 15:26:43 +08:00
}
protected override void PopIn()
{
base.PopIn();
2017-07-23 02:50:25 +08:00
scrollContainer.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint);
this.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint);
this.FadeTo(1, TRANSITION_LENGTH / 2);
2017-02-10 15:26:43 +08:00
}
private void markAllRead()
{
sections.Children.ForEach(s => s.MarkAllRead());
}
protected override void PopOut()
{
base.PopOut();
markAllRead();
2017-07-23 02:50:25 +08:00
this.MoveToX(width, TRANSITION_LENGTH, Easing.OutQuint);
this.FadeTo(0, TRANSITION_LENGTH / 2);
2017-02-10 15:26:43 +08:00
}
}
}