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
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Notifications
|
|
|
|
|
{
|
|
|
|
|
public class NotificationSection : AlwaysUpdateFillFlowContainer<Drawable>
|
|
|
|
|
{
|
2019-06-20 16:41:12 +08:00
|
|
|
|
private OsuSpriteText countDrawable;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
private FlowContainer<Notification> notifications;
|
|
|
|
|
|
2019-12-17 13:55:48 +08:00
|
|
|
|
public IEnumerable<Notification> Notifications => notifications.Children;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public int DisplayedCount => notifications.Count(n => !n.WasClosed);
|
|
|
|
|
public int UnreadCount => notifications.Count(n => !n.WasClosed && !n.Read);
|
|
|
|
|
|
|
|
|
|
public void Add(Notification notification, float position)
|
|
|
|
|
{
|
2019-07-01 23:41:40 +08:00
|
|
|
|
notifications.Insert((int)position, notification);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Type> AcceptTypes;
|
|
|
|
|
|
2019-06-20 16:41:12 +08:00
|
|
|
|
private readonly string clearButtonText;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-20 16:41:12 +08:00
|
|
|
|
private readonly string titleText;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-20 16:41:12 +08:00
|
|
|
|
public NotificationSection(string title, string clearButtonText)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-06-20 16:41:12 +08:00
|
|
|
|
this.clearButtonText = clearButtonText;
|
|
|
|
|
titleText = title;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
Direction = FillDirection.Vertical;
|
|
|
|
|
|
|
|
|
|
Padding = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Top = 10,
|
|
|
|
|
Bottom = 5,
|
|
|
|
|
Right = 20,
|
|
|
|
|
Left = 20,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
AddRangeInternal(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2019-06-20 16:41:12 +08:00
|
|
|
|
new ClearAllButton
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-06-20 16:41:12 +08:00
|
|
|
|
Text = clearButtonText,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
Action = clearAll
|
|
|
|
|
},
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Bottom = 5
|
|
|
|
|
},
|
|
|
|
|
Spacing = new Vector2(5, 0),
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2019-06-20 16:41:12 +08:00
|
|
|
|
new OsuSpriteText
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-06-20 16:41:12 +08:00
|
|
|
|
Text = titleText.ToUpperInvariant(),
|
2019-02-12 12:04:46 +08:00
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Black)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
2019-06-20 16:41:12 +08:00
|
|
|
|
countDrawable = new OsuSpriteText
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Text = "3",
|
|
|
|
|
Colour = colours.Yellow,
|
2019-02-12 12:04:46 +08:00
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Black)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
notifications = new AlwaysUpdateFillFlowContainer<Notification>
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
LayoutDuration = 150,
|
|
|
|
|
LayoutEasing = Easing.OutQuart,
|
|
|
|
|
Spacing = new Vector2(3),
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void clearAll()
|
|
|
|
|
{
|
|
|
|
|
notifications.Children.ForEach(c => c.Close());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2019-06-20 16:41:12 +08:00
|
|
|
|
countDrawable.Text = notifications.Children.Count(c => c.Alpha > 0.99f).ToString();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class ClearAllButton : OsuClickableContainer
|
|
|
|
|
{
|
|
|
|
|
private readonly OsuSpriteText text;
|
|
|
|
|
|
|
|
|
|
public ClearAllButton()
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
text = new OsuSpriteText()
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Text
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => text.Text;
|
|
|
|
|
set => text.Text = value.ToUpperInvariant();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MarkAllRead()
|
|
|
|
|
{
|
|
|
|
|
notifications?.Children.ForEach(n => n.Read = true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class AlwaysUpdateFillFlowContainer<T> : FillFlowContainer<T>
|
|
|
|
|
where T : Drawable
|
|
|
|
|
{
|
|
|
|
|
// this is required to ensure correct layout and scheduling on children.
|
|
|
|
|
// the layout portion of this is being tracked as a framework issue (https://github.com/ppy/osu-framework/issues/1297).
|
|
|
|
|
protected override bool RequiresChildrenUpdate => true;
|
|
|
|
|
}
|
|
|
|
|
}
|