Skip to content

Commit

Permalink
Add initial animation for health bars
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Oct 2, 2023
1 parent 622cbc3 commit 82ba545
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
4 changes: 2 additions & 2 deletions osu.Game/Screens/Play/HUD/ArgonHealthDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ protected override void Flash(JudgementResult result)
}
}

private double missBarValue = 1.0;
private double missBarValue;
private readonly List<Vector2> missBarVertices = new List<Vector2>();

public double MissBarValue
Expand All @@ -228,7 +228,7 @@ public double MissBarValue
}
}

private double healthBarValue = 1.0;
private double healthBarValue;
private readonly List<Vector2> healthBarVertices = new List<Vector2>();

public double HealthBarValue
Expand Down
42 changes: 40 additions & 2 deletions osu.Game/Screens/Play/HUD/HealthDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
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;

Expand All @@ -23,12 +25,16 @@ public abstract partial class HealthDisplay : CompositeDrawable
[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>
Expand All @@ -52,14 +58,46 @@ protected override void LoadComplete()
{
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)
Expand Down
1 change: 1 addition & 0 deletions osu.Game/Skinning/LegacyHealthDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private void load(ISkinSource source)
marker.Current.BindTo(Current);

maxFillWidth = fill.Width;
fill.Width = 0;
}

protected override void Update()
Expand Down

0 comments on commit 82ba545

Please sign in to comment.