mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 09:23:06 +08:00
Add initial animation for health bars
This commit is contained in:
parent
622cbc3af7
commit
82ba545358
@ -212,7 +212,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
}
|
||||
}
|
||||
|
||||
private double missBarValue = 1.0;
|
||||
private double missBarValue;
|
||||
private readonly List<Vector2> missBarVertices = new List<Vector2>();
|
||||
|
||||
public double MissBarValue
|
||||
@ -228,7 +228,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
}
|
||||
}
|
||||
|
||||
private double healthBarValue = 1.0;
|
||||
private double healthBarValue;
|
||||
private readonly List<Vector2> healthBarVertices = new List<Vector2>();
|
||||
|
||||
public double HealthBarValue
|
||||
|
@ -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,16 @@ namespace osu.Game.Screens.Play.HUD
|
||||
[Resolved]
|
||||
protected HealthProcessor HealthProcessor { get; private set; } = null!;
|
||||
|
||||
public Bindable<double> Current { get; } = new BindableDouble(1)
|
||||
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 +58,46 @@ 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 =>
|
||||
{
|
||||
Current.Value = h.NewValue;
|
||||
finishInitialAnimation();
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
startInitialAnimation();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private void onNewJudgement(JudgementResult judgement)
|
||||
|
@ -66,6 +66,7 @@ namespace osu.Game.Skinning
|
||||
marker.Current.BindTo(Current);
|
||||
|
||||
maxFillWidth = fill.Width;
|
||||
fill.Width = 0;
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
|
Loading…
Reference in New Issue
Block a user