2019-01-24 16:43:03 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-05-07 15:56:24 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2021-05-10 14:40:33 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-10-16 12:42:50 +08:00
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
2020-03-18 05:57:47 +08:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2020-03-18 15:17:41 +08:00
|
|
|
|
using osu.Game.Rulesets.UI;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
|
|
|
|
{
|
2020-03-18 15:17:41 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A container for components displaying the current player health.
|
2021-05-07 15:56:24 +08:00
|
|
|
|
/// Gets bound automatically to the <see cref="Rulesets.Scoring.HealthProcessor"/> when inserted to <see cref="DrawableRuleset.Overlays"/> hierarchy.
|
2020-03-18 15:17:41 +08:00
|
|
|
|
/// </summary>
|
2021-05-11 11:21:31 +08:00
|
|
|
|
public abstract class HealthDisplay : CompositeDrawable
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-05-12 11:53:30 +08:00
|
|
|
|
private readonly Bindable<bool> showHealthbar = new Bindable<bool>(true);
|
2021-05-10 14:40:33 +08:00
|
|
|
|
|
2021-05-07 15:56:24 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
protected HealthProcessor HealthProcessor { get; private set; }
|
|
|
|
|
|
2020-10-16 12:42:50 +08:00
|
|
|
|
public Bindable<double> Current { get; } = new BindableDouble(1)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
MinValue = 0,
|
|
|
|
|
MaxValue = 1
|
|
|
|
|
};
|
2020-03-18 15:17:41 +08:00
|
|
|
|
|
2021-05-07 15:56:24 +08:00
|
|
|
|
protected virtual void Flash(JudgementResult result)
|
2020-10-16 12:42:50 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-12 11:53:30 +08:00
|
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
|
private HUDOverlay hudOverlay { get; set; }
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
2021-05-07 15:56:24 +08:00
|
|
|
|
{
|
2021-05-12 11:53:30 +08:00
|
|
|
|
base.LoadComplete();
|
2021-05-07 15:56:24 +08:00
|
|
|
|
|
2021-05-12 11:53:30 +08:00
|
|
|
|
Current.BindTo(HealthProcessor.Health);
|
2021-05-07 15:56:24 +08:00
|
|
|
|
HealthProcessor.NewJudgement += onNewJudgement;
|
2021-05-10 14:40:33 +08:00
|
|
|
|
|
2021-05-12 11:53:30 +08:00
|
|
|
|
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);
|
2021-05-07 15:56:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onNewJudgement(JudgementResult judgement)
|
2020-03-18 05:57:47 +08:00
|
|
|
|
{
|
2021-05-10 12:41:04 +08:00
|
|
|
|
if (judgement.IsHit && judgement.Type != HitResult.IgnoreHit)
|
|
|
|
|
Flash(judgement);
|
2021-05-07 15:56:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
|
|
if (HealthProcessor != null)
|
|
|
|
|
HealthProcessor.NewJudgement -= onNewJudgement;
|
2020-03-18 05:57:47 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|