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;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2022-01-28 12:53:48 +08:00
|
|
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-02-22 16:14:00 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2021-02-26 16:11:47 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2023-07-06 23:31:32 +08:00
|
|
|
|
using osu.Game.Localisation;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
namespace osu.Game.Overlays.Notifications
|
|
|
|
|
{
|
2017-12-27 20:19:06 +08:00
|
|
|
|
public partial class NotificationSection : AlwaysUpdateFillFlowContainer<Drawable>
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
2023-06-23 13:58:19 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// All notifications currently being displayed in this section.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public IEnumerable<Notification> Notifications => notifications;
|
|
|
|
|
|
2022-08-30 14:51:46 +08:00
|
|
|
|
private OsuSpriteText countDrawable = null!;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-08-30 14:51:46 +08:00
|
|
|
|
private FlowContainer<Notification> notifications = null!;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-08-23 11:47:20 +08:00
|
|
|
|
public int DisplayedCount => notifications.Count(n => !n.WasClosed);
|
2017-12-26 00:50:05 +08:00
|
|
|
|
public int UnreadCount => notifications.Count(n => !n.WasClosed && !n.Read);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-06 16:20:58 +08:00
|
|
|
|
public void Add(Notification notification, float position)
|
|
|
|
|
{
|
2019-07-01 23:41:40 +08:00
|
|
|
|
notifications.Insert((int)position, notification);
|
2018-03-06 16:20:58 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-10-13 16:31:00 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Enumerable of notification types accepted in this section.
|
|
|
|
|
/// If <see langword="null"/>, the section accepts any and all notifications.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public IEnumerable<Type>? AcceptedNotificationTypes { get; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-01-28 12:53:48 +08:00
|
|
|
|
private readonly LocalisableString titleText;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-10-13 16:31:00 +08:00
|
|
|
|
public NotificationSection(LocalisableString title, IEnumerable<Type>? acceptedNotificationTypes = null)
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
2023-10-13 16:31:00 +08:00
|
|
|
|
AcceptedNotificationTypes = acceptedNotificationTypes?.ToArray();
|
2022-08-30 14:51:46 +08:00
|
|
|
|
|
2019-06-20 16:41:12 +08:00
|
|
|
|
titleText = title;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2017-03-04 18:00:17 +08:00
|
|
|
|
Direction = FillDirection.Vertical;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
Padding = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Top = 10,
|
|
|
|
|
Bottom = 5,
|
|
|
|
|
Right = 20,
|
|
|
|
|
Left = 20,
|
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-07-11 21:58:06 +08:00
|
|
|
|
AddRangeInternal(new Drawable[]
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2023-07-07 12:10:49 +08:00
|
|
|
|
Children = new Drawable[]
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
2023-07-07 12:10:49 +08:00
|
|
|
|
new ClearAllButton
|
|
|
|
|
{
|
2023-07-08 20:10:05 +08:00
|
|
|
|
Text = NotificationsStrings.ClearAll.ToUpper(),
|
2023-07-07 12:10:49 +08:00
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
Action = clearAll
|
|
|
|
|
},
|
2017-03-02 02:33:01 +08:00
|
|
|
|
new FillFlowContainer
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Bottom = 5
|
|
|
|
|
},
|
2017-03-02 02:33:01 +08:00
|
|
|
|
Spacing = new Vector2(5, 0),
|
2017-02-10 15:26:43 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2019-06-20 16:41:12 +08:00
|
|
|
|
new OsuSpriteText
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
2022-01-28 12:53:48 +08:00
|
|
|
|
Text = titleText.ToUpper(),
|
2020-03-17 07:32:25 +08:00
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Bold)
|
2017-02-10 15:26:43 +08:00
|
|
|
|
},
|
2019-06-20 16:41:12 +08:00
|
|
|
|
countDrawable = new OsuSpriteText
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
|
|
|
|
Text = "3",
|
|
|
|
|
Colour = colours.Yellow,
|
2020-03-17 07:32:25 +08:00
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Bold)
|
2017-02-10 15:26:43 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-12-27 20:19:06 +08:00
|
|
|
|
notifications = new AlwaysUpdateFillFlowContainer<Notification>
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
LayoutDuration = 150,
|
2017-07-23 02:50:25 +08:00
|
|
|
|
LayoutEasing = Easing.OutQuart,
|
2017-02-10 15:26:43 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-07-07 12:10:49 +08:00
|
|
|
|
private void clearAll() => notifications.Children.ForEach(c =>
|
|
|
|
|
{
|
2023-07-08 20:11:58 +08:00
|
|
|
|
if (c is not ProgressNotification p || !p.Ongoing)
|
2023-07-07 12:10:49 +08:00
|
|
|
|
c.Close(true);
|
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-02-26 16:11:47 +08:00
|
|
|
|
countDrawable.Text = getVisibleCount().ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int getVisibleCount()
|
|
|
|
|
{
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
|
|
foreach (var c in notifications)
|
|
|
|
|
{
|
|
|
|
|
if (c.Alpha > 0.99f)
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return count;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-06-27 20:05:49 +08:00
|
|
|
|
private partial class ClearAllButton : OsuClickableContainer
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly OsuSpriteText text;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
public ClearAllButton()
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
text = new OsuSpriteText()
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-02-22 16:14:00 +08:00
|
|
|
|
public LocalisableString Text
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => text.Text;
|
2021-02-22 16:14:00 +08:00
|
|
|
|
set => text.Text = value;
|
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 void MarkAllRead()
|
|
|
|
|
{
|
2022-08-30 14:51:46 +08:00
|
|
|
|
notifications.Children.ForEach(n => n.Read = true);
|
2017-02-10 15:26:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-12-27 20:19:06 +08:00
|
|
|
|
public partial 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;
|
|
|
|
|
}
|
2017-12-26 00:50:05 +08:00
|
|
|
|
}
|