From 82ba545358723a8560de4444568b107f029a6bfa Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 2 Oct 2023 17:01:56 +0900 Subject: [PATCH] Add initial animation for health bars --- .../Screens/Play/HUD/ArgonHealthDisplay.cs | 4 +- osu.Game/Screens/Play/HUD/HealthDisplay.cs | 42 ++++++++++++++++++- osu.Game/Skinning/LegacyHealthDisplay.cs | 1 + 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/osu.Game/Screens/Play/HUD/ArgonHealthDisplay.cs b/osu.Game/Screens/Play/HUD/ArgonHealthDisplay.cs index 6cf1daa10264..68685d7eb599 100644 --- a/osu.Game/Screens/Play/HUD/ArgonHealthDisplay.cs +++ b/osu.Game/Screens/Play/HUD/ArgonHealthDisplay.cs @@ -212,7 +212,7 @@ protected override void Flash(JudgementResult result) } } - private double missBarValue = 1.0; + private double missBarValue; private readonly List missBarVertices = new List(); public double MissBarValue @@ -228,7 +228,7 @@ public double MissBarValue } } - private double healthBarValue = 1.0; + private double healthBarValue; private readonly List healthBarVertices = new List(); public double HealthBarValue diff --git a/osu.Game/Screens/Play/HUD/HealthDisplay.cs b/osu.Game/Screens/Play/HUD/HealthDisplay.cs index 5131f93ca29e..e4bb91e7ca96 100644 --- a/osu.Game/Screens/Play/HUD/HealthDisplay.cs +++ b/osu.Game/Screens/Play/HUD/HealthDisplay.cs @@ -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; @@ -23,12 +25,16 @@ public abstract partial class HealthDisplay : CompositeDrawable [Resolved] protected HealthProcessor HealthProcessor { get; private set; } = null!; - public Bindable Current { get; } = new BindableDouble(1) + public Bindable Current { get; } = new BindableDouble { MinValue = 0, MaxValue = 1 }; + private BindableNumber health = null!; + + private ScheduledDelegate? initialIncrease; + /// /// Triggered when a is a successful hit, signaling the health display to perform a flash animation (if designed to do so). /// @@ -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) diff --git a/osu.Game/Skinning/LegacyHealthDisplay.cs b/osu.Game/Skinning/LegacyHealthDisplay.cs index f785022f8416..08add79fc161 100644 --- a/osu.Game/Skinning/LegacyHealthDisplay.cs +++ b/osu.Game/Skinning/LegacyHealthDisplay.cs @@ -66,6 +66,7 @@ private void load(ISkinSource source) marker.Current.BindTo(Current); maxFillWidth = fill.Width; + fill.Width = 0; } protected override void Update()