2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-02-10 15:26:43 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2017-12-26 00:36:58 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
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;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
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;
|
|
|
|
|
|
2017-12-26 00:36:58 +08:00
|
|
|
|
public BindableInt NotificationCount = new BindableInt();
|
|
|
|
|
|
2017-12-26 00:56:57 +08:00
|
|
|
|
private readonly CountCircle countDisplay;
|
2017-12-26 00:36:58 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
public ToolbarNotificationButton()
|
|
|
|
|
{
|
|
|
|
|
Icon = FontAwesome.fa_bars;
|
|
|
|
|
TooltipMain = "Notifications";
|
|
|
|
|
TooltipSub = "Waiting for 'ya";
|
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
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 00:12:46 +08:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2017-07-28 13:51:49 +08:00
|
|
|
|
private void load(NotificationOverlay notificationOverlay)
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
2017-07-28 13:51:49 +08:00
|
|
|
|
StateContainer = notificationOverlay;
|
2017-12-26 00:36:58 +08:00
|
|
|
|
|
2017-12-26 00:56:57 +08:00
|
|
|
|
if (notificationOverlay != null)
|
|
|
|
|
NotificationCount.BindTo(notificationOverlay.UnreadCount);
|
|
|
|
|
|
2017-12-26 00:36:58 +08:00
|
|
|
|
NotificationCount.ValueChanged += count =>
|
|
|
|
|
{
|
|
|
|
|
if (count == 0)
|
|
|
|
|
countDisplay.FadeOut(200, Easing.OutQuint);
|
|
|
|
|
else
|
2017-12-26 00:56:57 +08:00
|
|
|
|
{
|
|
|
|
|
countDisplay.Count = count;
|
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
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
2017-12-26 00:36:58 +08:00
|
|
|
|
|
2017-12-26 14:52:36 +08:00
|
|
|
|
private int count;
|
|
|
|
|
|
2017-12-26 00:36:58 +08:00
|
|
|
|
public int Count
|
|
|
|
|
{
|
2017-12-26 14:52:36 +08:00
|
|
|
|
get { return count; }
|
2017-12-26 00:56:57 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-12-26 14:52:36 +08:00
|
|
|
|
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");
|
2017-12-26 00:56:57 +08:00
|
|
|
|
}
|
2017-12-26 00:36:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CountCircle()
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.X;
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
TextSize = 14,
|
|
|
|
|
Padding = new MarginPadding(5),
|
|
|
|
|
Colour = Color4.White,
|
|
|
|
|
UseFullGlyphHeight = true,
|
|
|
|
|
Font = "Exo2.0-Bold",
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-02-10 15:26:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-21 10:49:42 +08:00
|
|
|
|
}
|