1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-15 11:47:18 +08:00

Remove downwards dependency from HUDOverlay to HealthDisplay

This commit is contained in:
Dean Herbert 2021-05-10 15:40:33 +09:00
parent 95a497e9df
commit df72656aa1
2 changed files with 11 additions and 5 deletions

View File

@ -3,6 +3,7 @@
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring;
@ -16,6 +17,8 @@ namespace osu.Game.Screens.Play.HUD
/// </summary>
public abstract class HealthDisplay : Container
{
private Bindable<bool> showHealthbar;
[Resolved]
protected HealthProcessor HealthProcessor { get; private set; }
@ -29,12 +32,18 @@ namespace osu.Game.Screens.Play.HUD
{
}
[BackgroundDependencyLoader]
private void load()
[BackgroundDependencyLoader(true)]
private void load(HUDOverlay hud)
{
Current.BindTo(HealthProcessor.Health);
HealthProcessor.NewJudgement += onNewJudgement;
if (hud != null)
{
showHealthbar = hud.ShowHealthbar.GetBoundCopy();
showHealthbar.BindValueChanged(healthBar => this.FadeTo(healthBar.NewValue ? 1 : 0, HUDOverlay.FADE_DURATION, HUDOverlay.FADE_EASING), true);
}
}
private void onNewJudgement(JudgementResult judgement)

View File

@ -36,7 +36,6 @@ namespace osu.Game.Screens.Play
public readonly KeyCounterDisplay KeyCounter;
public readonly SkinnableScoreCounter ScoreCounter;
public readonly SkinnableAccuracyCounter AccuracyCounter;
public readonly SkinnableHealthDisplay HealthDisplay;
public readonly SongProgress Progress;
public readonly ModDisplay ModDisplay;
public readonly HoldForMenuButton HoldToQuit;
@ -108,7 +107,6 @@ namespace osu.Game.Screens.Play
{
// remaining cross-dependencies need tidying.
// kept to ensure non-null, but hidden for testing.
HealthDisplay = new SkinnableHealthDisplay(),
AccuracyCounter = new SkinnableAccuracyCounter(),
ScoreCounter = new SkinnableScoreCounter(),
}
@ -206,7 +204,6 @@ namespace osu.Game.Screens.Play
{
base.LoadComplete();
ShowHealthbar.BindValueChanged(healthBar => HealthDisplay.FadeTo(healthBar.NewValue ? 1 : 0, FADE_DURATION, FADE_EASING), true);
ShowHud.BindValueChanged(visible => hideTargets.ForEach(d => d.FadeTo(visible.NewValue ? 1 : 0, FADE_DURATION, FADE_EASING)));
IsBreakTime.BindValueChanged(_ => updateVisibility());