1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 03:03:21 +08:00
osu-lazer/osu.Game/Overlays/Toolbar/ToolbarNotificationButton.cs

102 lines
3.2 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 osu.Framework.Allocation;
using osu.Framework.Configuration;
2017-02-10 15:26:43 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
2017-02-10 15:26:43 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using OpenTK;
using OpenTK.Graphics;
2017-02-10 15:26:43 +08:00
namespace osu.Game.Overlays.Toolbar
{
public class ToolbarNotificationButton : ToolbarOverlayToggleButton
2017-02-10 15:26:43 +08:00
{
protected override Anchor TooltipAnchor => Anchor.TopRight;
public BindableInt NotificationCount = new BindableInt();
2017-12-26 00:56:57 +08:00
private readonly CountCircle countDisplay;
2017-02-10 15:26:43 +08:00
public ToolbarNotificationButton()
{
Icon = FontAwesome.fa_bars;
TooltipMain = "Notifications";
TooltipSub = "Waiting for 'ya";
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-02-10 15:26:43 +08:00
}
[BackgroundDependencyLoader(true)]
private void load(NotificationOverlay notificationOverlay)
2017-02-10 15:26:43 +08:00
{
StateContainer = notificationOverlay;
2017-12-26 00:56:57 +08:00
if (notificationOverlay != null)
NotificationCount.BindTo(notificationOverlay.UnreadCount);
NotificationCount.ValueChanged += count =>
{
if (count == 0)
countDisplay.FadeOut(200, Easing.OutQuint);
else
2017-12-26 00:56:57 +08:00
{
countDisplay.Count = count;
countDisplay.FadeIn(200, Easing.OutQuint);
2017-12-26 00:56:57 +08:00
}
};
}
private class CountCircle : CompositeDrawable
{
private readonly OsuSpriteText count;
2017-12-26 00:56:57 +08:00
private readonly Circle circle;
public int Count
{
2017-12-26 00:56:57 +08:00
set
{
count.Text = value.ToString("#,0");
circle.FlashColour(Color4.White, 600, Easing.OutQuint);
this.ScaleTo(1.1f).Then().ScaleTo(1, 600, Easing.OutElastic);
}
}
public CountCircle()
{
AutoSizeAxes = Axes.X;
InternalChildren = new Drawable[]
{
2017-12-26 00:56:57 +08:00
circle = new Circle
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Red
},
count = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Y = -1,
TextSize = 14,
Padding = new MarginPadding(5),
Colour = Color4.White,
UseFullGlyphHeight = true,
Font = "Exo2.0-Bold",
}
};
}
2017-02-10 15:26:43 +08:00
}
}
}