Merge pull request #12753 from peppy/health-bar-hud-overlay-dependency

Remove downwards dependency from `HUDOverlay` to `HealthDisplay`
This commit is contained in:
Dan Balasescu 2021-05-12 19:27:02 +09:00 committed by GitHub
commit 4e7c079560
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 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 : CompositeDrawable
{
private readonly Bindable<bool> showHealthbar = new Bindable<bool>(true);
[Resolved]
protected HealthProcessor HealthProcessor { get; private set; }
@ -29,12 +32,21 @@ namespace osu.Game.Screens.Play.HUD
{
}
[BackgroundDependencyLoader]
private void load()
{
Current.BindTo(HealthProcessor.Health);
[Resolved(canBeNull: true)]
private HUDOverlay hudOverlay { get; set; }
protected override void LoadComplete()
{
base.LoadComplete();
Current.BindTo(HealthProcessor.Health);
HealthProcessor.NewJudgement += onNewJudgement;
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);
}
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;
@ -96,7 +95,7 @@ namespace osu.Game.Screens.Play
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
HealthDisplay = CreateHealthDisplay(),
CreateHealthDisplay(),
AccuracyCounter = CreateAccuracyCounter(),
ScoreCounter = CreateScoreCounter(),
CreateComboCounter(),
@ -185,7 +184,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());