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 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;
|
2023-12-06 00:44:01 +08:00
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2023-09-26 07:23:29 +08:00
|
|
|
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;
|
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-12-05 04:23:48 +08:00
|
|
|
using osu.Game.Rulesets.Judgements;
|
2024-01-11 19:55:04 +08:00
|
|
|
using osu.Game.Screens.Play.HUD.ArgonHealthDisplayParts;
|
2023-09-26 07:23:29 +08:00
|
|
|
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-10-06 17:46:50 +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
|
|
|
|
2024-01-11 21:10:06 +08:00
|
|
|
private ArgonHealthDisplayBar mainBar = null!;
|
2023-10-03 16:41:10 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Used to show a glow at the end of the main bar, or red "damage" area when missing.
|
|
|
|
/// </summary>
|
2024-01-11 21:10:06 +08:00
|
|
|
private ArgonHealthDisplayBar glowBar = null!;
|
2023-10-03 16:41:10 +08:00
|
|
|
|
2024-01-11 21:10:06 +08:00
|
|
|
private Container content = null!;
|
2023-09-26 07:23:29 +08:00
|
|
|
|
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-12-05 04:23:48 +08:00
|
|
|
private bool displayingMiss => resetMissBarDelegate != null;
|
|
|
|
|
2023-10-04 19:53:42 +08:00
|
|
|
private double glowBarValue;
|
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
|
|
|
|
2023-11-08 07:06:51 +08:00
|
|
|
public const float MAIN_PATH_RADIUS = 10f;
|
2023-11-15 12:33:12 +08:00
|
|
|
private const float padding = MAIN_PATH_RADIUS * 2;
|
|
|
|
|
2023-11-11 19:42:45 +08:00
|
|
|
private readonly LayoutValue drawSizeLayout = new LayoutValue(Invalidation.DrawSize);
|
|
|
|
|
|
|
|
public ArgonHealthDisplay()
|
|
|
|
{
|
|
|
|
AddLayout(drawSizeLayout);
|
2023-11-15 11:24:47 +08:00
|
|
|
|
|
|
|
// sane default width specification.
|
|
|
|
// this only matters if the health display isn't part of the default skin
|
|
|
|
// (in which case width will be set to 300 via `ArgonSkin.GetDrawableComponent()`),
|
|
|
|
// and if the user hasn't applied their own modifications
|
|
|
|
// (which are applied via `SerialisedDrawableInfo.ApplySerialisedInfo()`).
|
|
|
|
Width = 0.98f;
|
2023-11-11 19:42:45 +08:00
|
|
|
}
|
2023-10-06 15:52:00 +08:00
|
|
|
|
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
|
|
|
|
2024-01-11 21:10:06 +08:00
|
|
|
InternalChild = content = new Container
|
2023-09-26 07:23:29 +08:00
|
|
|
{
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2024-01-11 19:55:04 +08:00
|
|
|
new ArgonHealthDisplayBackground
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
PathRadius = MAIN_PATH_RADIUS,
|
|
|
|
PathPadding = MAIN_PATH_RADIUS
|
2023-09-26 07:23:29 +08:00
|
|
|
},
|
2024-01-11 21:10:06 +08:00
|
|
|
new Container
|
2023-09-26 07:23:29 +08:00
|
|
|
{
|
2024-01-11 21:10:06 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Padding = new MarginPadding(-30f),
|
|
|
|
Child = glowBar = new ArgonHealthDisplayBar
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
BarColour = Color4.White,
|
|
|
|
GlowColour = main_bar_glow_colour,
|
|
|
|
Blending = BlendingParameters.Additive,
|
|
|
|
Colour = ColourInfo.GradientHorizontal(Color4.White.Opacity(0.8f), Color4.White),
|
|
|
|
PathRadius = 40f,
|
|
|
|
PathPadding = 40f,
|
|
|
|
GlowPortion = 0.9f,
|
|
|
|
}
|
2023-10-06 17:56:31 +08:00
|
|
|
},
|
2024-01-11 21:10:06 +08:00
|
|
|
mainBar = new ArgonHealthDisplayBar
|
2023-10-06 17:56:31 +08:00
|
|
|
{
|
|
|
|
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,
|
2024-01-11 21:10:06 +08:00
|
|
|
PathPadding = MAIN_PATH_RADIUS,
|
2023-10-06 17:56:31 +08:00
|
|
|
GlowPortion = 0.6f,
|
2024-01-11 19:55:04 +08:00
|
|
|
}
|
2023-10-06 17:56:31 +08:00
|
|
|
}
|
2023-09-26 07:23:29 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-12-06 02:57:53 +08:00
|
|
|
private bool pendingMissAnimation;
|
2023-12-05 04:23:48 +08:00
|
|
|
|
2023-09-26 07:23:29 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2023-12-06 00:44:01 +08:00
|
|
|
HealthProcessor.NewJudgement += onNewJudgement;
|
2023-10-06 15:52:00 +08:00
|
|
|
|
2023-11-14 20:46:57 +08:00
|
|
|
// we're about to set `RelativeSizeAxes` depending on the value of `UseRelativeSize`.
|
|
|
|
// setting `RelativeSizeAxes` internally transforms absolute sizing to relative and back to keep the size the same,
|
|
|
|
// but that is not what we want in this case, since the width at this point is valid in the *target* sizing mode.
|
|
|
|
// to counteract this, store the numerical value here, and restore it after setting the correct initial relative sizing axes.
|
|
|
|
float previousWidth = Width;
|
2023-11-11 19:42:45 +08:00
|
|
|
UseRelativeSize.BindValueChanged(v => RelativeSizeAxes = v.NewValue ? Axes.X : Axes.None, true);
|
2023-11-14 20:46:57 +08:00
|
|
|
Width = previousWidth;
|
2023-10-06 15:52:00 +08:00
|
|
|
|
2024-01-11 21:10:06 +08:00
|
|
|
BarHeight.BindValueChanged(_ => updateContentSize(), true);
|
2023-09-26 07:23:29 +08:00
|
|
|
}
|
|
|
|
|
2023-12-06 02:57:53 +08:00
|
|
|
private void onNewJudgement(JudgementResult result) => pendingMissAnimation |= !result.IsHit;
|
2023-12-06 00:44:01 +08:00
|
|
|
|
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)
|
|
|
|
{
|
2024-01-11 21:10:06 +08:00
|
|
|
updateContentSize();
|
2023-11-11 19:42:45 +08:00
|
|
|
drawSizeLayout.Validate();
|
|
|
|
}
|
|
|
|
|
2024-01-09 16:30:13 +08:00
|
|
|
healthBarValue = Interpolation.DampContinuously(healthBarValue, Current.Value, 50, Time.Elapsed);
|
|
|
|
if (!displayingMiss)
|
|
|
|
glowBarValue = Interpolation.DampContinuously(glowBarValue, Current.Value, 50, Time.Elapsed);
|
|
|
|
|
2023-10-03 16:41:10 +08:00
|
|
|
mainBar.Alpha = (float)Interpolation.DampContinuously(mainBar.Alpha, Current.Value > 0 ? 1 : 0, 40, Time.Elapsed);
|
2024-01-09 16:20:49 +08:00
|
|
|
glowBar.Alpha = (float)Interpolation.DampContinuously(glowBar.Alpha, glowBarValue > 0 ? 1 : 0, 40, Time.Elapsed);
|
2024-01-09 15:50:27 +08:00
|
|
|
|
2024-01-11 21:10:06 +08:00
|
|
|
updatePathProgress();
|
2024-01-09 16:30:13 +08:00
|
|
|
}
|
2024-01-09 15:50:27 +08:00
|
|
|
|
2024-01-09 16:30:13 +08:00
|
|
|
protected override void HealthChanged(bool increase)
|
|
|
|
{
|
|
|
|
if (Current.Value >= glowBarValue)
|
2024-01-09 15:50:27 +08:00
|
|
|
finishMissDisplay();
|
|
|
|
|
2024-01-09 17:18:11 +08:00
|
|
|
if (pendingMissAnimation)
|
|
|
|
{
|
2024-01-09 15:50:27 +08:00
|
|
|
triggerMissDisplay();
|
2024-01-09 17:18:11 +08:00
|
|
|
pendingMissAnimation = false;
|
|
|
|
}
|
2024-01-09 16:20:49 +08:00
|
|
|
|
2024-01-09 16:30:13 +08:00
|
|
|
base.HealthChanged(increase);
|
2023-10-01 20:25:23 +08:00
|
|
|
}
|
|
|
|
|
2023-12-05 04:55:31 +08:00
|
|
|
protected override void FinishInitialAnimation(double value)
|
|
|
|
{
|
|
|
|
base.FinishInitialAnimation(value);
|
2024-01-09 16:20:49 +08:00
|
|
|
this.TransformTo(nameof(healthBarValue), value, 500, Easing.OutQuint);
|
|
|
|
this.TransformTo(nameof(glowBarValue), value, 250, Easing.OutQuint);
|
2023-12-05 04:55:31 +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-12-05 04:23:48 +08:00
|
|
|
if (!displayingMiss)
|
2023-10-03 16:31:50 +08:00
|
|
|
{
|
2024-01-11 21:10:06 +08:00
|
|
|
glowBar.TransformTo(nameof(ArgonHealthDisplayBar.GlowColour), Colour4.White, 30, Easing.OutQuint)
|
2023-10-10 14:10:42 +08:00
|
|
|
.Then()
|
2024-01-11 21:10:06 +08:00
|
|
|
.TransformTo(nameof(ArgonHealthDisplayBar.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-12-05 04:23:48 +08:00
|
|
|
private void triggerMissDisplay()
|
2023-09-26 07:23:29 +08:00
|
|
|
{
|
2023-12-05 04:23:48 +08:00
|
|
|
resetMissBarDelegate?.Cancel();
|
|
|
|
resetMissBarDelegate = null;
|
2023-09-26 07:23:29 +08:00
|
|
|
|
|
|
|
this.Delay(500).Schedule(() =>
|
|
|
|
{
|
2024-01-09 16:20:49 +08:00
|
|
|
this.TransformTo(nameof(glowBarValue), Current.Value, 300, Easing.OutQuint);
|
2023-10-03 16:41:10 +08:00
|
|
|
finishMissDisplay();
|
2023-09-26 07:23:29 +08:00
|
|
|
}, out resetMissBarDelegate);
|
|
|
|
|
2024-01-11 21:10:06 +08:00
|
|
|
glowBar.TransformTo(nameof(ArgonHealthDisplayBar.BarColour), new Colour4(255, 147, 147, 255), 100, Easing.OutQuint).Then()
|
|
|
|
.TransformTo(nameof(ArgonHealthDisplayBar.BarColour), new Colour4(255, 93, 93, 255), 800, Easing.OutQuint);
|
2023-09-26 07:23:29 +08:00
|
|
|
|
2024-01-11 21:10:06 +08:00
|
|
|
glowBar.TransformTo(nameof(ArgonHealthDisplayBar.GlowColour), new Colour4(253, 0, 0, 255).Lighten(0.2f))
|
|
|
|
.TransformTo(nameof(ArgonHealthDisplayBar.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-12-05 04:23:48 +08:00
|
|
|
if (!displayingMiss)
|
2023-10-10 14:09:33 +08:00
|
|
|
return;
|
|
|
|
|
2023-10-01 23:42:47 +08:00
|
|
|
if (Current.Value > 0)
|
|
|
|
{
|
2024-01-11 21:10:06 +08:00
|
|
|
glowBar.TransformTo(nameof(ArgonHealthDisplayBar.BarColour), main_bar_colour, 300, Easing.In);
|
|
|
|
glowBar.TransformTo(nameof(ArgonHealthDisplayBar.GlowColour), main_bar_glow_colour, 300, Easing.In);
|
2023-10-01 23:42:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
resetMissBarDelegate?.Cancel();
|
|
|
|
resetMissBarDelegate = null;
|
|
|
|
}
|
|
|
|
|
2024-01-11 21:10:06 +08:00
|
|
|
private void updateContentSize()
|
2023-09-26 07:23:29 +08:00
|
|
|
{
|
2023-11-15 12:33:12 +08:00
|
|
|
float usableWidth = DrawWidth - padding;
|
|
|
|
|
|
|
|
if (usableWidth < 0) enforceMinimumWidth();
|
|
|
|
|
2024-01-11 21:10:06 +08:00
|
|
|
content.Size = new Vector2(DrawWidth, BarHeight.Value + padding);
|
|
|
|
updatePathProgress();
|
2023-11-15 12:33:12 +08:00
|
|
|
|
|
|
|
void enforceMinimumWidth()
|
|
|
|
{
|
2023-11-15 18:01:52 +08:00
|
|
|
// Switch to absolute in order to be able to define a minimum width.
|
|
|
|
// Then switch back is required. Framework will handle the conversion for us.
|
|
|
|
Axes relativeAxes = RelativeSizeAxes;
|
2023-11-15 12:33:12 +08:00
|
|
|
RelativeSizeAxes = Axes.None;
|
2023-11-15 18:01:52 +08:00
|
|
|
|
2023-11-15 12:33:12 +08:00
|
|
|
Width = padding;
|
2023-11-15 18:01:52 +08:00
|
|
|
|
2023-11-15 12:33:12 +08:00
|
|
|
RelativeSizeAxes = relativeAxes;
|
|
|
|
}
|
2023-09-26 07:23:29 +08:00
|
|
|
}
|
|
|
|
|
2024-01-11 21:10:06 +08:00
|
|
|
private void updatePathProgress()
|
2023-09-26 07:23:29 +08:00
|
|
|
{
|
2024-01-12 07:54:04 +08:00
|
|
|
mainBar.ProgressRange = new Vector2(0f, (float)healthBarValue);
|
|
|
|
glowBar.ProgressRange = new Vector2((float)healthBarValue, (float)Math.Max(glowBarValue, healthBarValue));
|
2023-09-26 07:23:29 +08:00
|
|
|
}
|
|
|
|
|
2023-12-06 00:44:01 +08:00
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
if (HealthProcessor.IsNotNull())
|
|
|
|
HealthProcessor.NewJudgement -= onNewJudgement;
|
|
|
|
}
|
2023-09-26 07:23:29 +08:00
|
|
|
}
|
|
|
|
}
|