2019-01-24 16:43:03 +08: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 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
2018-11-17 00:30:58 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-04-02 13:51:28 +08:00
|
|
|
|
using osu.Framework.Graphics.Effects;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2020-02-26 19:45:57 +08:00
|
|
|
|
using osu.Framework.Utils;
|
2021-04-30 11:42:32 +08:00
|
|
|
|
using osu.Game.Skinning;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
|
|
|
|
{
|
2021-04-28 17:34:34 +08:00
|
|
|
|
public class DefaultHealthDisplay : HealthDisplay, IHasAccentColour, ISkinnableComponent
|
2018-04-13 17:19:50 +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;
|
|
|
|
|
|
|
|
|
|
private readonly Container fill;
|
|
|
|
|
|
|
|
|
|
public Color4 AccentColour
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => fill.Colour;
|
|
|
|
|
set => fill.Colour = value;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4 glowColour;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public Color4 GlowColour
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => glowColour;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (glowColour == value)
|
|
|
|
|
return;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
glowColour = value;
|
|
|
|
|
|
|
|
|
|
fill.EdgeEffect = new EdgeEffectParameters
|
|
|
|
|
{
|
|
|
|
|
Colour = glowColour.Opacity(base_glow_opacity),
|
|
|
|
|
Radius = 8,
|
|
|
|
|
Roundness = 4,
|
|
|
|
|
Type = EdgeEffectType.Glow,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-16 12:42:50 +08:00
|
|
|
|
public DefaultHealthDisplay()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-10-16 12:42:50 +08:00
|
|
|
|
Size = new Vector2(1, 5);
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
Margin = new MarginPadding { Top = 20 };
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.Black,
|
|
|
|
|
},
|
|
|
|
|
fill = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Size = new Vector2(0, 1),
|
|
|
|
|
Masking = true,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-17 00:30:58 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
AccentColour = colours.BlueLighter;
|
|
|
|
|
GlowColour = colours.BlueDarker;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 15:56:24 +08:00
|
|
|
|
protected override void Flash(JudgementResult result) => Scheduler.AddOnce(flash);
|
2020-02-26 19:45:57 +08:00
|
|
|
|
|
|
|
|
|
private void flash()
|
|
|
|
|
{
|
2018-04-13 17:19:50 +08:00
|
|
|
|
fill.FadeEdgeEffectTo(Math.Min(1, fill.EdgeEffect.Colour.Linear.A + (1f - base_glow_opacity) / glow_max_hits), 50, Easing.OutQuint)
|
|
|
|
|
.Delay(glow_fade_delay)
|
|
|
|
|
.FadeEdgeEffectTo(base_glow_opacity, glow_fade_time, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-26 19:45:57 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
fill.Width = Interpolation.ValueAt(
|
|
|
|
|
Math.Clamp(Clock.ElapsedFrameTime, 0, 200),
|
|
|
|
|
fill.Width, (float)Current.Value, 0, 200, Easing.OutQuint);
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|