2019-01-24 08:43:03 +00: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 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-03-27 10:29:27 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Toolbar
|
|
|
|
|
{
|
|
|
|
|
public class ToolbarNotificationButton : ToolbarOverlayToggleButton
|
|
|
|
|
{
|
|
|
|
|
protected override Anchor TooltipAnchor => Anchor.TopRight;
|
|
|
|
|
|
|
|
|
|
public BindableInt NotificationCount = new BindableInt();
|
|
|
|
|
|
|
|
|
|
private readonly CountCircle countDisplay;
|
|
|
|
|
|
|
|
|
|
public ToolbarNotificationButton()
|
|
|
|
|
{
|
2019-04-02 10:55:24 +00:00
|
|
|
|
Icon = FontAwesome.Solid.Bars;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
TooltipMain = "Notifications";
|
|
|
|
|
TooltipSub = "Waiting for 'ya";
|
|
|
|
|
|
|
|
|
|
Add(countDisplay = new CountCircle
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
Height = 16,
|
|
|
|
|
RelativePositionAxes = Axes.Both,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Position = new Vector2(0.7f, 0.25f),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader(true)]
|
|
|
|
|
private void load(NotificationOverlay notificationOverlay)
|
|
|
|
|
{
|
|
|
|
|
StateContainer = notificationOverlay;
|
|
|
|
|
|
|
|
|
|
if (notificationOverlay != null)
|
|
|
|
|
NotificationCount.BindTo(notificationOverlay.UnreadCount);
|
|
|
|
|
|
|
|
|
|
NotificationCount.ValueChanged += count =>
|
|
|
|
|
{
|
2019-02-22 08:51:39 +00:00
|
|
|
|
if (count.NewValue == 0)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
countDisplay.FadeOut(200, Easing.OutQuint);
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-02-22 08:51:39 +00:00
|
|
|
|
countDisplay.Count = count.NewValue;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
countDisplay.FadeIn(200, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class CountCircle : CompositeDrawable
|
|
|
|
|
{
|
|
|
|
|
private readonly OsuSpriteText countText;
|
|
|
|
|
private readonly Circle circle;
|
|
|
|
|
|
|
|
|
|
private int count;
|
|
|
|
|
|
|
|
|
|
public int Count
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
get => count;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (count == value)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (value > count)
|
|
|
|
|
{
|
|
|
|
|
circle.FlashColour(Color4.White, 600, Easing.OutQuint);
|
|
|
|
|
this.ScaleTo(1.1f).Then().ScaleTo(1, 600, Easing.OutElastic);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
count = value;
|
|
|
|
|
countText.Text = value.ToString("#,0");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CountCircle()
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.X;
|
|
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
circle = new Circle
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.Red
|
|
|
|
|
},
|
|
|
|
|
countText = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Y = -1,
|
2019-02-12 04:04:46 +00:00
|
|
|
|
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold),
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Padding = new MarginPadding(5),
|
|
|
|
|
Colour = Color4.White,
|
|
|
|
|
UseFullGlyphHeight = true,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|