2017-03-10 11:26:46 +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
|
|
|
|
|
|
2017-05-05 12:00:05 +08:00
|
|
|
|
using System;
|
2017-04-20 16:11:58 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2017-03-10 11:26:46 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics;
|
2017-04-20 16:11:58 +08:00
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2017-05-05 12:00:05 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-03-10 11:26:46 +08:00
|
|
|
|
|
2017-05-05 12:00:05 +08:00
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
2017-03-10 11:26:46 +08:00
|
|
|
|
{
|
2017-04-13 09:04:12 +08:00
|
|
|
|
public class StandardHealthDisplay : HealthDisplay, IHasAccentColour
|
2017-03-10 11:26:46 +08:00
|
|
|
|
{
|
2017-04-20 16:11:58 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The base opacity of the glow.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const float base_glow_opacity = 0.6f;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The number of sequential hits required within <see cref="glow_fade_delay"/> to reach the maximum glow opacity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const int glow_max_hits = 8;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The amount of time to delay before fading the glow opacity back to <see cref="base_glow_opacity"/>.
|
|
|
|
|
/// <para>
|
|
|
|
|
/// This is calculated to require a stream snapped to 1/4 at 150bpm to reach the maximum glow opacity with <see cref="glow_max_hits"/> hits.
|
|
|
|
|
/// </para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const float glow_fade_delay = 100;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The amount of time to fade the glow to <see cref="base_glow_opacity"/> after <see cref="glow_fade_delay"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const double glow_fade_time = 500;
|
|
|
|
|
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly Container fill;
|
2017-03-10 11:26:46 +08:00
|
|
|
|
|
2017-04-13 09:04:12 +08:00
|
|
|
|
public Color4 AccentColour
|
|
|
|
|
{
|
|
|
|
|
get { return fill.Colour; }
|
|
|
|
|
set { fill.Colour = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4 glowColour;
|
|
|
|
|
public Color4 GlowColour
|
|
|
|
|
{
|
|
|
|
|
get { return glowColour; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (glowColour == value)
|
|
|
|
|
return;
|
|
|
|
|
glowColour = value;
|
|
|
|
|
|
2017-06-12 11:48:47 +08:00
|
|
|
|
fill.EdgeEffect = new EdgeEffectParameters
|
2017-04-13 09:04:12 +08:00
|
|
|
|
{
|
2017-04-20 16:11:58 +08:00
|
|
|
|
Colour = glowColour.Opacity(base_glow_opacity),
|
2017-04-13 09:04:12 +08:00
|
|
|
|
Radius = 8,
|
2017-04-20 16:11:15 +08:00
|
|
|
|
Roundness = 4,
|
|
|
|
|
Type = EdgeEffectType.Glow,
|
2017-04-13 09:04:12 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 11:26:46 +08:00
|
|
|
|
public StandardHealthDisplay()
|
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.Black,
|
|
|
|
|
},
|
|
|
|
|
fill = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-04-20 16:11:15 +08:00
|
|
|
|
Size = new Vector2(0, 1),
|
2017-03-10 11:26:46 +08:00
|
|
|
|
Masking = true,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-20 18:45:15 +08:00
|
|
|
|
public void Flash(Judgement judgement)
|
2017-04-20 16:11:58 +08:00
|
|
|
|
{
|
|
|
|
|
if (judgement.Result == HitResult.Miss)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-07-23 02:50:25 +08:00
|
|
|
|
fill.FadeEdgeEffectTo(Math.Min(1, fill.EdgeEffect.Colour.Linear.A + (1f - base_glow_opacity) / glow_max_hits), 50, Easing.OutQuint)
|
2017-07-17 21:51:21 +08:00
|
|
|
|
.Delay(glow_fade_delay)
|
2017-07-23 02:50:25 +08:00
|
|
|
|
.FadeEdgeEffectTo(base_glow_opacity, glow_fade_time, Easing.OutQuint);
|
2017-04-20 16:11:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-23 02:50:25 +08:00
|
|
|
|
protected override void SetHealth(float value) => fill.ResizeTo(new Vector2(value, 1), 200, Easing.OutQuint);
|
2017-03-10 11:26:46 +08:00
|
|
|
|
}
|
|
|
|
|
}
|