1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 16:47:29 +08:00

Merge pull request #24986 from peppy/health-animates-in-intro

Add initial animation for health bars
This commit is contained in:
Dean Herbert 2023-10-07 10:31:34 +09:00 committed by GitHub
commit 7c7771afca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 8 deletions

View File

@ -12,6 +12,7 @@ using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play.HUD;
using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Tests.Visual.Gameplay
{
@ -20,9 +21,9 @@ namespace osu.Game.Tests.Visual.Gameplay
[Cached(typeof(HealthProcessor))]
private HealthProcessor healthProcessor = new DrainingHealthProcessor(0);
protected override Drawable CreateArgonImplementation() => new ArgonHealthDisplay();
protected override Drawable CreateDefaultImplementation() => new DefaultHealthDisplay();
protected override Drawable CreateLegacyImplementation() => new LegacyHealthDisplay();
protected override Drawable CreateArgonImplementation() => new ArgonHealthDisplay { Scale = new Vector2(0.6f) };
protected override Drawable CreateDefaultImplementation() => new DefaultHealthDisplay { Scale = new Vector2(0.6f) };
protected override Drawable CreateLegacyImplementation() => new LegacyHealthDisplay { Scale = new Vector2(0.6f) };
[SetUpSteps]
public void SetUpSteps()
@ -62,4 +63,4 @@ namespace osu.Game.Tests.Visual.Gameplay
}, 3);
}
}
}
}

View File

@ -64,7 +64,7 @@ namespace osu.Game.Screens.Play.HUD
private readonly List<Vector2> missBarVertices = new List<Vector2>();
private readonly List<Vector2> healthBarVertices = new List<Vector2>();
private double glowBarValue = 1;
private double glowBarValue;
public double GlowBarValue
{
@ -79,7 +79,7 @@ namespace osu.Game.Screens.Play.HUD
}
}
private double healthBarValue = 1;
private double healthBarValue;
public double HealthBarValue
{

View File

@ -29,6 +29,8 @@ namespace osu.Game.Screens.Play.HUD
/// </summary>
public readonly Bindable<bool> ShowHealth = new Bindable<bool>();
protected override bool PlayInitialIncreaseAnimation => false;
private const float max_alpha = 0.4f;
private const int fade_time = 400;
private const float gradient_size = 0.2f;

View File

@ -6,7 +6,9 @@ using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Threading;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI;
@ -23,12 +25,18 @@ namespace osu.Game.Screens.Play.HUD
[Resolved]
protected HealthProcessor HealthProcessor { get; private set; } = null!;
public Bindable<double> Current { get; } = new BindableDouble(1)
protected virtual bool PlayInitialIncreaseAnimation => true;
public Bindable<double> Current { get; } = new BindableDouble
{
MinValue = 0,
MaxValue = 1
};
private BindableNumber<double> health = null!;
private ScheduledDelegate? initialIncrease;
/// <summary>
/// Triggered when a <see cref="Judgement"/> is a successful hit, signaling the health display to perform a flash animation (if designed to do so).
/// </summary>
@ -52,14 +60,56 @@ namespace osu.Game.Screens.Play.HUD
{
base.LoadComplete();
Current.BindTo(HealthProcessor.Health);
HealthProcessor.NewJudgement += onNewJudgement;
// Don't bind directly so we can animate the startup procedure.
health = HealthProcessor.Health.GetBoundCopy();
health.BindValueChanged(h =>
{
finishInitialAnimation();
Current.Value = h.NewValue;
});
if (hudOverlay != null)
showHealthBar.BindTo(hudOverlay.ShowHealthBar);
// this probably shouldn't be operating on `this.`
showHealthBar.BindValueChanged(healthBar => this.FadeTo(healthBar.NewValue ? 1 : 0, HUDOverlay.FADE_DURATION, HUDOverlay.FADE_EASING), true);
if (PlayInitialIncreaseAnimation)
startInitialAnimation();
else
Current.Value = 1;
}
private void startInitialAnimation()
{
// TODO: this should run in gameplay time, including showing a larger increase when skipping.
// TODO: it should also start increasing relative to the first hitobject.
const double increase_delay = 150;
initialIncrease = Scheduler.AddDelayed(() =>
{
double newValue = Current.Value + 0.05f;
this.TransformBindableTo(Current, newValue, increase_delay);
Flash(new JudgementResult(new HitObject(), new Judgement()));
if (newValue >= 1)
finishInitialAnimation();
}, increase_delay, true);
}
private void finishInitialAnimation()
{
initialIncrease?.Cancel();
initialIncrease = null;
// aside from the repeating `initialIncrease` scheduled task,
// there may also be a `Current` transform in progress from that schedule.
// ensure it plays out fully, to prevent changes to `Current.Value` being discarded by the ongoing transform.
// and yes, this funky `targetMember` spec is seemingly the only way to do this
// (see: https://github.com/ppy/osu-framework/blob/fe2769171c6e26d1b6fdd6eb7ea8353162fe9065/osu.Framework/Graphics/Transforms/TransformBindable.cs#L21)
FinishTransforms(targetMember: $"{Current.GetHashCode()}.{nameof(Current.Value)}");
}
private void onNewJudgement(JudgementResult judgement)

View File

@ -66,6 +66,7 @@ namespace osu.Game.Skinning
marker.Current.BindTo(Current);
maxFillWidth = fill.Width;
fill.Width = 0;
}
protected override void Update()