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
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2017-12-26 00:36:58 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2017-12-26 00:36:58 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2020-08-06 16:17:24 +08:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
namespace osu.Game.Overlays.Toolbar
|
|
|
|
|
{
|
2017-11-21 10:49:42 +08:00
|
|
|
|
public class ToolbarNotificationButton : ToolbarOverlayToggleButton
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
|
|
|
|
protected override Anchor TooltipAnchor => Anchor.TopRight;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-04-19 10:10:11 +08:00
|
|
|
|
public IBindable<int> NotificationCount = new BindableInt();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-12-26 00:56:57 +08:00
|
|
|
|
private readonly CountCircle countDisplay;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
public ToolbarNotificationButton()
|
|
|
|
|
{
|
2020-08-06 16:17:24 +08:00
|
|
|
|
Hotkey = GlobalAction.ToggleNotifications;
|
|
|
|
|
|
2017-12-26 00:36:58 +08:00
|
|
|
|
Add(countDisplay = new CountCircle
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
Height = 16,
|
|
|
|
|
RelativePositionAxes = Axes.Both,
|
2017-12-26 00:56:57 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Position = new Vector2(0.7f, 0.25f),
|
2017-12-26 00:36:58 +08:00
|
|
|
|
});
|
2017-02-10 15:26:43 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-04-19 10:10:11 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(INotificationOverlay notificationOverlay)
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
2022-04-19 10:10:11 +08:00
|
|
|
|
StateContainer = notificationOverlay as NotificationOverlay;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-12-26 00:56:57 +08:00
|
|
|
|
if (notificationOverlay != null)
|
|
|
|
|
NotificationCount.BindTo(notificationOverlay.UnreadCount);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-12-26 00:36:58 +08:00
|
|
|
|
NotificationCount.ValueChanged += count =>
|
|
|
|
|
{
|
2019-02-22 16:51:39 +08:00
|
|
|
|
if (count.NewValue == 0)
|
2017-12-26 00:36:58 +08:00
|
|
|
|
countDisplay.FadeOut(200, Easing.OutQuint);
|
|
|
|
|
else
|
2017-12-26 00:56:57 +08:00
|
|
|
|
{
|
2019-02-22 16:51:39 +08:00
|
|
|
|
countDisplay.Count = count.NewValue;
|
2017-12-26 00:36:58 +08:00
|
|
|
|
countDisplay.FadeIn(200, Easing.OutQuint);
|
2017-12-26 00:56:57 +08:00
|
|
|
|
}
|
2017-12-26 00:36:58 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-12-26 00:36:58 +08:00
|
|
|
|
private class CountCircle : CompositeDrawable
|
|
|
|
|
{
|
2017-12-26 14:52:36 +08:00
|
|
|
|
private readonly OsuSpriteText countText;
|
2017-12-26 00:56:57 +08:00
|
|
|
|
private readonly Circle circle;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-12-26 14:52:36 +08:00
|
|
|
|
private int count;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-12-26 00:36:58 +08:00
|
|
|
|
public int Count
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => count;
|
2017-12-26 00:56:57 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-12-26 14:52:36 +08:00
|
|
|
|
if (count == value)
|
|
|
|
|
return;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-12-26 14:52:36 +08:00
|
|
|
|
if (value > count)
|
|
|
|
|
{
|
|
|
|
|
circle.FlashColour(Color4.White, 600, Easing.OutQuint);
|
|
|
|
|
this.ScaleTo(1.1f).Then().ScaleTo(1, 600, Easing.OutElastic);
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-12-26 14:52:36 +08:00
|
|
|
|
count = value;
|
|
|
|
|
countText.Text = value.ToString("#,0");
|
2017-12-26 00:56:57 +08:00
|
|
|
|
}
|
2017-12-26 00:36:58 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-12-26 00:36:58 +08:00
|
|
|
|
public CountCircle()
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.X;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-12-26 00:36:58 +08:00
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
|
{
|
2017-12-26 00:56:57 +08:00
|
|
|
|
circle = new Circle
|
2017-12-26 00:36:58 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.Red
|
|
|
|
|
},
|
2017-12-26 14:52:36 +08:00
|
|
|
|
countText = new OsuSpriteText
|
2017-12-26 00:36:58 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Y = -1,
|
2019-02-12 12:04:46 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold),
|
2017-12-26 00:36:58 +08:00
|
|
|
|
Padding = new MarginPadding(5),
|
|
|
|
|
Colour = Color4.White,
|
|
|
|
|
UseFullGlyphHeight = true,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-02-10 15:26:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-21 10:49:42 +08:00
|
|
|
|
}
|