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 System;
|
|
|
|
|
using osu.Framework.Allocation;
|
2017-03-05 02:42:37 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Colour;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-06-27 20:05:49 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Notifications
|
|
|
|
|
{
|
|
|
|
|
public abstract class Notification : Container
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2017-08-22 18:51:42 +08:00
|
|
|
|
/// User requested close.
|
2017-02-10 15:26:43 +08:00
|
|
|
|
/// </summary>
|
2017-08-22 18:51:42 +08:00
|
|
|
|
public event Action Closed;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Run on user activating the notification. Return true to close.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Func<bool> Activated;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Should we show at the top of our section on display?
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual bool DisplayOnTop => true;
|
|
|
|
|
|
|
|
|
|
protected NotificationLight Light;
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly CloseButton closeButton;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
protected Container IconContent;
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly Container content;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
|
|
|
|
|
protected override Container<Drawable> Content => content;
|
|
|
|
|
|
|
|
|
|
protected Container NotificationContent;
|
|
|
|
|
|
2017-03-07 09:59:19 +08:00
|
|
|
|
public virtual bool Read { get; set; }
|
2017-02-10 15:26:43 +08:00
|
|
|
|
|
2017-03-09 13:01:08 +08:00
|
|
|
|
protected Notification()
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
2017-07-11 21:58:06 +08:00
|
|
|
|
AddRangeInternal(new Drawable[]
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
|
|
|
|
Light = new NotificationLight
|
|
|
|
|
{
|
|
|
|
|
Margin = new MarginPadding { Right = 5 },
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
},
|
|
|
|
|
NotificationContent = new Container
|
|
|
|
|
{
|
|
|
|
|
CornerRadius = 8,
|
|
|
|
|
Masking = true,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2017-07-28 15:54:09 +08:00
|
|
|
|
AutoSizeDuration = 400,
|
|
|
|
|
AutoSizeEasing = Easing.OutQuint,
|
2017-02-10 15:26:43 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.White,
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Padding = new MarginPadding(5),
|
2017-07-28 15:54:09 +08:00
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2017-02-10 15:26:43 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
IconContent = new Container
|
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(40),
|
|
|
|
|
Masking = true,
|
|
|
|
|
CornerRadius = 5,
|
|
|
|
|
},
|
|
|
|
|
content = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Padding = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Top = 5,
|
|
|
|
|
Left = 45,
|
|
|
|
|
Right = 30
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
closeButton = new CloseButton
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
Action = Close,
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Right = 5
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
|
|
|
|
closeButton.FadeIn(75);
|
|
|
|
|
return base.OnHover(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
|
{
|
|
|
|
|
closeButton.FadeOut(75);
|
|
|
|
|
base.OnHoverLost(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnClick(InputState state)
|
|
|
|
|
{
|
|
|
|
|
if (Activated?.Invoke() ?? true)
|
|
|
|
|
Close();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2017-07-15 00:18:12 +08:00
|
|
|
|
this.FadeInFromZero(200);
|
2017-02-10 15:26:43 +08:00
|
|
|
|
NotificationContent.MoveToX(DrawSize.X);
|
2017-07-23 02:50:25 +08:00
|
|
|
|
NotificationContent.MoveToX(0, 500, Easing.OutQuint);
|
2017-02-10 15:26:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-23 11:47:20 +08:00
|
|
|
|
public bool WasClosed;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
|
|
|
|
|
public virtual void Close()
|
|
|
|
|
{
|
2017-08-23 11:47:20 +08:00
|
|
|
|
if (WasClosed) return;
|
|
|
|
|
WasClosed = true;
|
2017-02-10 15:26:43 +08:00
|
|
|
|
|
|
|
|
|
Closed?.Invoke();
|
2017-07-15 00:18:12 +08:00
|
|
|
|
this.FadeOut(100);
|
2017-02-10 15:26:43 +08:00
|
|
|
|
Expire();
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-27 20:05:49 +08:00
|
|
|
|
private class CloseButton : OsuClickableContainer
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
|
|
|
|
private Color4 hoverColour;
|
|
|
|
|
|
|
|
|
|
public CloseButton()
|
|
|
|
|
{
|
|
|
|
|
Colour = OsuColour.Gray(0.2f);
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
2017-08-03 13:36:21 +08:00
|
|
|
|
new SpriteIcon
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
2017-03-06 16:06:48 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
2017-02-10 15:26:43 +08:00
|
|
|
|
Icon = FontAwesome.fa_times_circle,
|
2017-08-03 13:36:21 +08:00
|
|
|
|
Size = new Vector2(20),
|
2017-02-10 15:26:43 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
hoverColour = colours.Yellow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
2017-07-15 00:18:12 +08:00
|
|
|
|
this.FadeColour(hoverColour, 200);
|
2017-02-10 15:26:43 +08:00
|
|
|
|
return base.OnHover(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
|
{
|
2017-07-15 00:18:12 +08:00
|
|
|
|
this.FadeColour(OsuColour.Gray(0.2f), 200);
|
2017-02-10 15:26:43 +08:00
|
|
|
|
base.OnHoverLost(state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class NotificationLight : Container
|
|
|
|
|
{
|
|
|
|
|
private bool pulsate;
|
|
|
|
|
private Container pulsateLayer;
|
|
|
|
|
|
|
|
|
|
public bool Pulsate
|
|
|
|
|
{
|
|
|
|
|
get { return pulsate; }
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-07-09 17:23:34 +08:00
|
|
|
|
if (pulsate == value) return;
|
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
pulsate = value;
|
|
|
|
|
|
2017-02-25 20:12:39 +08:00
|
|
|
|
pulsateLayer.ClearTransforms();
|
2017-02-10 15:26:43 +08:00
|
|
|
|
pulsateLayer.Alpha = 1;
|
|
|
|
|
|
|
|
|
|
if (pulsate)
|
|
|
|
|
{
|
|
|
|
|
const float length = 1000;
|
2017-07-15 00:18:12 +08:00
|
|
|
|
pulsateLayer.Loop(length / 2,
|
2017-07-23 02:50:25 +08:00
|
|
|
|
p => p.FadeTo(0.4f, length, Easing.In).Then().FadeTo(1, length, Easing.Out)
|
2017-07-15 00:18:12 +08:00
|
|
|
|
);
|
2017-02-10 15:26:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public new SRGBColour Colour
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
base.Colour = value;
|
2017-06-12 11:48:47 +08:00
|
|
|
|
pulsateLayer.EdgeEffect = new EdgeEffectParameters
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
|
|
|
|
Colour = ((Color4)value).Opacity(0.5f), //todo: avoid cast
|
|
|
|
|
Type = EdgeEffectType.Glow,
|
|
|
|
|
Radius = 12,
|
|
|
|
|
Roundness = 12,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2017-02-27 22:32:32 +08:00
|
|
|
|
private void load()
|
2017-02-10 15:26:43 +08:00
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(6, 15);
|
|
|
|
|
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
pulsateLayer = new CircularContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Masking = true,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|