2023-09-26 07:23:29 +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.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
2023-10-06 15:52:00 +08:00
|
|
|
using osu.Framework.Bindables;
|
2023-09-26 07:23:29 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
using osu.Framework.Graphics;
|
2023-10-01 20:20:03 +08:00
|
|
|
using osu.Framework.Graphics.Colour;
|
2023-09-26 07:23:29 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Lines;
|
2023-10-06 15:52:00 +08:00
|
|
|
using osu.Framework.Layout;
|
2023-09-26 07:23:29 +08:00
|
|
|
using osu.Framework.Threading;
|
|
|
|
using osu.Framework.Utils;
|
2023-10-06 15:52:00 +08:00
|
|
|
using osu.Game.Configuration;
|
2023-09-26 07:23:29 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
|
|
|
{
|
|
|
|
public partial class ArgonHealthDisplay : HealthDisplay, ISerialisableDrawable
|
|
|
|
{
|
2023-10-03 16:31:50 +08:00
|
|
|
public bool UsesFixedAnchor { get; set; }
|
|
|
|
|
2023-10-06 15:52:00 +08:00
|
|
|
[SettingSource("Bar height")]
|
2023-11-04 07:46:28 +08:00
|
|
|
public BindableFloat BarHeight { get; } = new BindableFloat(20)
|
2023-10-06 15:52:00 +08:00
|
|
|
{
|
|
|
|
MinValue = 0,
|
|
|
|
MaxValue = 64,
|
|
|
|
Precision = 1
|
|
|
|
};
|
|
|
|
|
2023-11-07 07:03:16 +08:00
|
|
|
[SettingSource("Use relative size")]
|
|
|
|
public BindableBool UseRelativeSize { get; } = new BindableBool(true);
|
2023-10-06 15:52:00 +08:00
|
|
|
|
2023-10-03 16:41:10 +08:00
|
|
|
private BarPath mainBar = null!;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Used to show a glow at the end of the main bar, or red "damage" area when missing.
|
|
|
|
/// </summary>
|
|
|
|
private BarPath glowBar = null!;
|
|
|
|
|
2023-10-03 16:31:50 +08:00
|
|
|
private BackgroundPath background = null!;
|
2023-09-26 07:23:29 +08:00
|
|
|
|
|
|
|
private SliderPath barPath = null!;
|
|
|
|
|
2023-10-03 16:31:50 +08:00
|
|
|
private static readonly Colour4 main_bar_colour = Colour4.White;
|
|
|
|
private static readonly Colour4 main_bar_glow_colour = Color4Extensions.FromHex("#7ED7FD").Opacity(0.5f);
|
2023-09-26 07:23:29 +08:00
|
|
|
|
2023-10-03 16:31:50 +08:00
|
|
|
private ScheduledDelegate? resetMissBarDelegate;
|
2023-09-26 07:23:29 +08:00
|
|
|
|
2023-10-03 16:31:50 +08:00
|
|
|
private readonly List<Vector2> missBarVertices = new List<Vector2>();
|
|
|
|
private readonly List<Vector2> healthBarVertices = new List<Vector2>();
|
2023-09-26 07:23:29 +08:00
|
|
|
|
2023-10-04 19:53:42 +08:00
|
|
|
private double glowBarValue;
|
2023-09-26 07:23:29 +08:00
|
|
|
|
2023-10-03 16:41:10 +08:00
|
|
|
public double GlowBarValue
|
2023-09-26 07:23:29 +08:00
|
|
|
{
|
2023-10-03 16:41:10 +08:00
|
|
|
get => glowBarValue;
|
2023-10-03 16:31:50 +08:00
|
|
|
set
|
|
|
|
{
|
2023-10-03 16:41:10 +08:00
|
|
|
if (glowBarValue == value)
|
2023-10-03 16:31:50 +08:00
|
|
|
return;
|
2023-09-26 07:23:29 +08:00
|
|
|
|
2023-10-03 16:41:10 +08:00
|
|
|
glowBarValue = value;
|
2023-10-10 14:45:35 +08:00
|
|
|
Scheduler.AddOnce(updatePathVertices);
|
2023-10-03 16:31:50 +08:00
|
|
|
}
|
|
|
|
}
|
2023-09-26 07:23:29 +08:00
|
|
|
|
2023-10-04 19:53:42 +08:00
|
|
|
private double healthBarValue;
|
2023-10-03 16:31:50 +08:00
|
|
|
|
|
|
|
public double HealthBarValue
|
|
|
|
{
|
|
|
|
get => healthBarValue;
|
|
|
|
set
|
2023-09-26 07:23:29 +08:00
|
|
|
{
|
2023-10-03 16:31:50 +08:00
|
|
|
if (healthBarValue == value)
|
|
|
|
return;
|
2023-09-26 07:23:29 +08:00
|
|
|
|
2023-10-03 16:31:50 +08:00
|
|
|
healthBarValue = value;
|
2023-10-10 14:45:35 +08:00
|
|
|
Scheduler.AddOnce(updatePathVertices);
|
2023-10-03 16:31:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-08 07:06:51 +08:00
|
|
|
public const float MAIN_PATH_RADIUS = 10f;
|
2023-10-06 15:52:00 +08:00
|
|
|
|
2023-11-11 19:42:45 +08:00
|
|
|
private readonly LayoutValue drawSizeLayout = new LayoutValue(Invalidation.DrawSize);
|
|
|
|
|
|
|
|
public ArgonHealthDisplay()
|
|
|
|
{
|
|
|
|
AddLayout(drawSizeLayout);
|
|
|
|
}
|
|
|
|
|
2023-10-03 16:31:50 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2023-10-06 15:52:00 +08:00
|
|
|
AutoSizeAxes = Axes.Y;
|
2023-09-26 07:23:29 +08:00
|
|
|
|
2023-11-05 06:52:12 +08:00
|
|
|
InternalChild = new Container
|
2023-09-26 07:23:29 +08:00
|
|
|
{
|
2023-11-05 06:52:12 +08:00
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
2023-09-26 07:23:29 +08:00
|
|
|
{
|
2023-11-05 06:52:12 +08:00
|
|
|
background = new BackgroundPath
|
|
|
|
{
|
2023-11-08 07:06:51 +08:00
|
|
|
PathRadius = MAIN_PATH_RADIUS,
|
2023-11-05 06:52:12 +08:00
|
|
|
},
|
|
|
|
glowBar = new BarPath
|
|
|
|
{
|
|
|
|
BarColour = Color4.White,
|
|
|
|
GlowColour = main_bar_glow_colour,
|
|
|
|
Blending = BlendingParameters.Additive,
|
|
|
|
Colour = ColourInfo.GradientHorizontal(Color4.White.Opacity(0.8f), Color4.White),
|
|
|
|
PathRadius = 40f,
|
|
|
|
// Kinda hacky, but results in correct positioning with increased path radius.
|
|
|
|
Margin = new MarginPadding(-30f),
|
|
|
|
GlowPortion = 0.9f,
|
|
|
|
},
|
|
|
|
mainBar = new BarPath
|
2023-10-06 17:56:31 +08:00
|
|
|
{
|
2023-11-05 06:52:12 +08:00
|
|
|
AutoSizeAxes = Axes.None,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Blending = BlendingParameters.Additive,
|
|
|
|
BarColour = main_bar_colour,
|
|
|
|
GlowColour = main_bar_glow_colour,
|
2023-11-08 07:06:51 +08:00
|
|
|
PathRadius = MAIN_PATH_RADIUS,
|
2023-11-05 06:52:12 +08:00
|
|
|
GlowPortion = 0.6f,
|
|
|
|
},
|
2023-10-06 17:56:31 +08:00
|
|
|
}
|
2023-09-26 07:23:29 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2023-10-10 21:12:20 +08:00
|
|
|
Current.BindValueChanged(_ => Scheduler.AddOnce(updateCurrent), true);
|
2023-10-06 15:52:00 +08:00
|
|
|
|
2023-11-11 19:42:45 +08:00
|
|
|
UseRelativeSize.BindValueChanged(v => RelativeSizeAxes = v.NewValue ? Axes.X : Axes.None, true);
|
2023-11-07 07:03:16 +08:00
|
|
|
|
|
|
|
BarHeight.BindValueChanged(_ => updatePath(), true);
|
2023-10-06 15:52:00 +08:00
|
|
|
}
|
|
|
|
|
2023-10-10 15:17:34 +08:00
|
|
|
private void updateCurrent()
|
|
|
|
{
|
|
|
|
if (Current.Value >= GlowBarValue) finishMissDisplay();
|
|
|
|
|
|
|
|
double time = Current.Value > GlowBarValue ? 500 : 250;
|
|
|
|
|
|
|
|
// TODO: this should probably use interpolation in update.
|
|
|
|
this.TransformTo(nameof(HealthBarValue), Current.Value, time, Easing.OutQuint);
|
|
|
|
if (resetMissBarDelegate == null) this.TransformTo(nameof(GlowBarValue), Current.Value, time, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
|
2023-10-01 20:25:23 +08:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2023-11-11 19:42:45 +08:00
|
|
|
if (!drawSizeLayout.IsValid)
|
|
|
|
{
|
|
|
|
updatePath();
|
|
|
|
drawSizeLayout.Validate();
|
|
|
|
}
|
|
|
|
|
2023-10-03 16:41:10 +08:00
|
|
|
mainBar.Alpha = (float)Interpolation.DampContinuously(mainBar.Alpha, Current.Value > 0 ? 1 : 0, 40, Time.Elapsed);
|
|
|
|
glowBar.Alpha = (float)Interpolation.DampContinuously(glowBar.Alpha, GlowBarValue > 0 ? 1 : 0, 40, Time.Elapsed);
|
2023-10-01 20:25:23 +08:00
|
|
|
}
|
|
|
|
|
2023-10-10 21:10:44 +08:00
|
|
|
protected override void Flash()
|
2023-10-03 16:31:50 +08:00
|
|
|
{
|
2023-10-10 21:10:44 +08:00
|
|
|
base.Flash();
|
2023-10-03 16:31:50 +08:00
|
|
|
|
2023-10-03 16:41:10 +08:00
|
|
|
mainBar.TransformTo(nameof(BarPath.GlowColour), main_bar_glow_colour.Opacity(0.8f))
|
|
|
|
.TransformTo(nameof(BarPath.GlowColour), main_bar_glow_colour, 300, Easing.OutQuint);
|
2023-10-03 16:31:50 +08:00
|
|
|
|
|
|
|
if (resetMissBarDelegate == null)
|
|
|
|
{
|
2023-10-10 14:10:42 +08:00
|
|
|
glowBar.TransformTo(nameof(BarPath.BarColour), Colour4.White, 30, Easing.OutQuint)
|
2023-10-03 16:31:50 +08:00
|
|
|
.Then()
|
2023-10-10 14:10:42 +08:00
|
|
|
.TransformTo(nameof(BarPath.BarColour), main_bar_colour, 1000, Easing.OutQuint);
|
2023-10-03 16:31:50 +08:00
|
|
|
|
2023-10-10 14:10:42 +08:00
|
|
|
glowBar.TransformTo(nameof(BarPath.GlowColour), Colour4.White, 30, Easing.OutQuint)
|
|
|
|
.Then()
|
|
|
|
.TransformTo(nameof(BarPath.GlowColour), main_bar_glow_colour, 300, Easing.OutQuint);
|
2023-10-03 16:31:50 +08:00
|
|
|
}
|
|
|
|
}
|
2023-09-26 07:23:29 +08:00
|
|
|
|
2023-10-10 21:10:44 +08:00
|
|
|
protected override void Miss()
|
2023-09-26 07:23:29 +08:00
|
|
|
{
|
2023-10-10 21:10:44 +08:00
|
|
|
base.Miss();
|
2023-09-26 07:23:29 +08:00
|
|
|
|
|
|
|
if (resetMissBarDelegate != null)
|
2023-10-01 20:20:03 +08:00
|
|
|
{
|
2023-09-26 07:23:29 +08:00
|
|
|
resetMissBarDelegate.Cancel();
|
2023-10-01 20:20:03 +08:00
|
|
|
resetMissBarDelegate = null;
|
|
|
|
}
|
2023-09-26 07:23:29 +08:00
|
|
|
else
|
2023-10-03 16:41:10 +08:00
|
|
|
{
|
|
|
|
// Reset any ongoing animation immediately, else things get weird.
|
|
|
|
this.TransformTo(nameof(GlowBarValue), HealthBarValue);
|
|
|
|
}
|
2023-09-26 07:23:29 +08:00
|
|
|
|
|
|
|
this.Delay(500).Schedule(() =>
|
|
|
|
{
|
2023-10-03 16:41:10 +08:00
|
|
|
this.TransformTo(nameof(GlowBarValue), Current.Value, 300, Easing.OutQuint);
|
|
|
|
finishMissDisplay();
|
2023-09-26 07:23:29 +08:00
|
|
|
}, out resetMissBarDelegate);
|
|
|
|
|
2023-10-03 16:41:10 +08:00
|
|
|
glowBar.TransformTo(nameof(BarPath.BarColour), new Colour4(255, 147, 147, 255), 100, Easing.OutQuint).Then()
|
2023-10-03 16:31:50 +08:00
|
|
|
.TransformTo(nameof(BarPath.BarColour), new Colour4(255, 93, 93, 255), 800, Easing.OutQuint);
|
2023-09-26 07:23:29 +08:00
|
|
|
|
2023-10-03 16:41:10 +08:00
|
|
|
glowBar.TransformTo(nameof(BarPath.GlowColour), new Colour4(253, 0, 0, 255).Lighten(0.2f))
|
2023-10-03 16:31:50 +08:00
|
|
|
.TransformTo(nameof(BarPath.GlowColour), new Colour4(253, 0, 0, 255), 800, Easing.OutQuint);
|
2023-09-26 07:23:29 +08:00
|
|
|
}
|
|
|
|
|
2023-10-03 16:41:10 +08:00
|
|
|
private void finishMissDisplay()
|
2023-10-01 23:42:47 +08:00
|
|
|
{
|
2023-10-10 14:09:33 +08:00
|
|
|
if (resetMissBarDelegate == null)
|
|
|
|
return;
|
|
|
|
|
2023-10-01 23:42:47 +08:00
|
|
|
if (Current.Value > 0)
|
|
|
|
{
|
2023-10-03 16:41:10 +08:00
|
|
|
glowBar.TransformTo(nameof(BarPath.BarColour), main_bar_colour, 300, Easing.In);
|
|
|
|
glowBar.TransformTo(nameof(BarPath.GlowColour), main_bar_glow_colour, 300, Easing.In);
|
2023-10-01 23:42:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
resetMissBarDelegate?.Cancel();
|
|
|
|
resetMissBarDelegate = null;
|
|
|
|
}
|
|
|
|
|
2023-10-03 16:31:50 +08:00
|
|
|
private void updatePath()
|
2023-09-26 07:23:29 +08:00
|
|
|
{
|
2023-11-08 07:06:51 +08:00
|
|
|
float barLength = DrawWidth - MAIN_PATH_RADIUS * 2;
|
2023-10-06 15:52:00 +08:00
|
|
|
float curveStart = barLength - 70;
|
|
|
|
float curveEnd = barLength - 40;
|
2023-10-03 16:41:52 +08:00
|
|
|
|
2023-10-06 15:52:00 +08:00
|
|
|
const float curve_smoothness = 10;
|
2023-10-03 16:41:52 +08:00
|
|
|
|
2023-10-06 15:52:00 +08:00
|
|
|
Vector2 diagonalDir = (new Vector2(curveEnd, BarHeight.Value) - new Vector2(curveStart, 0)).Normalized();
|
2023-10-02 01:03:45 +08:00
|
|
|
|
2023-10-03 16:31:50 +08:00
|
|
|
barPath = new SliderPath(new[]
|
2023-09-26 07:23:29 +08:00
|
|
|
{
|
2023-10-03 16:31:50 +08:00
|
|
|
new PathControlPoint(new Vector2(0, 0), PathType.Linear),
|
2023-10-06 15:52:00 +08:00
|
|
|
new PathControlPoint(new Vector2(curveStart - curve_smoothness, 0), PathType.Bezier),
|
|
|
|
new PathControlPoint(new Vector2(curveStart, 0)),
|
|
|
|
new PathControlPoint(new Vector2(curveStart, 0) + diagonalDir * curve_smoothness, PathType.Linear),
|
|
|
|
new PathControlPoint(new Vector2(curveEnd, BarHeight.Value) - diagonalDir * curve_smoothness, PathType.Bezier),
|
|
|
|
new PathControlPoint(new Vector2(curveEnd, BarHeight.Value)),
|
|
|
|
new PathControlPoint(new Vector2(curveEnd + curve_smoothness, BarHeight.Value), PathType.Linear),
|
|
|
|
new PathControlPoint(new Vector2(barLength, BarHeight.Value)),
|
2023-10-03 16:31:50 +08:00
|
|
|
});
|
2023-09-26 07:23:29 +08:00
|
|
|
|
2023-10-03 16:31:50 +08:00
|
|
|
List<Vector2> vertices = new List<Vector2>();
|
|
|
|
barPath.GetPathToProgress(vertices, 0.0, 1.0);
|
2023-09-26 07:23:29 +08:00
|
|
|
|
2023-10-03 16:31:50 +08:00
|
|
|
background.Vertices = vertices;
|
2023-10-03 16:41:10 +08:00
|
|
|
mainBar.Vertices = vertices;
|
|
|
|
glowBar.Vertices = vertices;
|
2023-09-26 07:23:29 +08:00
|
|
|
|
2023-10-03 16:31:50 +08:00
|
|
|
updatePathVertices();
|
2023-09-26 07:23:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updatePathVertices()
|
|
|
|
{
|
|
|
|
barPath.GetPathToProgress(healthBarVertices, 0.0, healthBarValue);
|
2023-10-03 16:41:10 +08:00
|
|
|
barPath.GetPathToProgress(missBarVertices, healthBarValue, Math.Max(glowBarValue, healthBarValue));
|
2023-09-26 07:23:29 +08:00
|
|
|
|
|
|
|
if (healthBarVertices.Count == 0)
|
|
|
|
healthBarVertices.Add(Vector2.Zero);
|
|
|
|
|
|
|
|
if (missBarVertices.Count == 0)
|
|
|
|
missBarVertices.Add(Vector2.Zero);
|
|
|
|
|
2023-10-03 16:41:10 +08:00
|
|
|
glowBar.Vertices = missBarVertices.Select(v => v - missBarVertices[0]).ToList();
|
|
|
|
glowBar.Position = missBarVertices[0];
|
2023-09-26 07:23:29 +08:00
|
|
|
|
2023-10-03 16:41:10 +08:00
|
|
|
mainBar.Vertices = healthBarVertices.Select(v => v - healthBarVertices[0]).ToList();
|
|
|
|
mainBar.Position = healthBarVertices[0];
|
2023-09-26 07:23:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private partial class BackgroundPath : SmoothPath
|
|
|
|
{
|
|
|
|
protected override Color4 ColourAt(float position)
|
|
|
|
{
|
2023-10-06 15:52:00 +08:00
|
|
|
if (position <= 0.16f)
|
2023-10-03 16:17:11 +08:00
|
|
|
return Color4.White.Opacity(0.8f);
|
2023-09-26 07:23:29 +08:00
|
|
|
|
2023-10-03 16:17:11 +08:00
|
|
|
return Interpolation.ValueAt(position,
|
|
|
|
Color4.White.Opacity(0.8f),
|
|
|
|
Color4.Black.Opacity(0.2f),
|
|
|
|
-0.5f, 1f, Easing.OutQuint);
|
2023-09-26 07:23:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private partial class BarPath : SmoothPath
|
|
|
|
{
|
|
|
|
private Colour4 barColour;
|
|
|
|
|
|
|
|
public Colour4 BarColour
|
|
|
|
{
|
|
|
|
get => barColour;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (barColour == value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
barColour = value;
|
|
|
|
InvalidateTexture();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Colour4 glowColour;
|
|
|
|
|
|
|
|
public Colour4 GlowColour
|
|
|
|
{
|
|
|
|
get => glowColour;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (glowColour == value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
glowColour = value;
|
|
|
|
InvalidateTexture();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-01 18:39:36 +08:00
|
|
|
public float GlowPortion { get; init; }
|
|
|
|
|
2023-09-26 07:23:29 +08:00
|
|
|
protected override Color4 ColourAt(float position)
|
|
|
|
{
|
2023-10-01 18:39:36 +08:00
|
|
|
if (position >= GlowPortion)
|
2023-09-26 07:23:29 +08:00
|
|
|
return BarColour;
|
|
|
|
|
2023-10-01 23:56:29 +08:00
|
|
|
return Interpolation.ValueAt(position, Colour4.Black.Opacity(0.0f), GlowColour, 0.0, GlowPortion, Easing.InQuint);
|
2023-09-26 07:23:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|