1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 08:02:55 +08:00

Hide red tint based on "Show health display even when you can't fail" setting

This commit is contained in:
Power Maker 2020-06-26 14:32:01 +02:00
parent f381cf3ae8
commit 97a212a7f6
2 changed files with 29 additions and 1 deletions

View File

@ -31,6 +31,7 @@ namespace osu.Game.Screens.Play.HUD
/// </summary>
public double LowHealthThreshold = 0.20f;
public readonly Bindable<bool> HUDEnabled = new Bindable<bool>();
private readonly Bindable<bool> enabled = new Bindable<bool>();
private readonly Container boxes;
@ -74,7 +75,7 @@ namespace osu.Game.Screens.Play.HUD
boxes.Colour = color.Red;
configEnabled = config.GetBindable<bool>(OsuSetting.FadePlayfieldWhenHealthLow);
enabled.BindValueChanged(e => this.FadeTo(e.NewValue ? 1 : 0, fade_time, Easing.OutQuint), true);
enabled.BindValueChanged(e => TryToFade(fade_time, Easing.OutQuint, e.NewValue ? true : false), true);
}
protected override void LoadComplete()
@ -105,6 +106,28 @@ namespace osu.Game.Screens.Play.HUD
enabled.Value = false;
}
/// <summary>
/// Tries to fade based on "Fade playfield when health is low" setting
/// </summary>
/// <param name="fadeDuration">Duration of the fade</param>
/// <param name="easing">Type of easing</param>
/// <param name="fadeIn">True when you want to fade in, false when you want to fade out</param>
public void TryToFade(float fadeDuration, Easing easing, bool fadeIn)
{
if (HUDEnabled.Value)
{
if (fadeIn)
{
if (enabled.Value)
this.FadeIn(fadeDuration, easing);
}
else
this.FadeOut(fadeDuration, easing);
}
else
this.FadeOut(fadeDuration, easing);
}
protected override void Update()
{
double target = Math.Clamp(max_alpha * (1 - Current.Value / LowHealthThreshold), 0, max_alpha);

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using Microsoft.Diagnostics.Runtime.Interop;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions;
@ -153,6 +154,8 @@ namespace osu.Game.Screens.Play
// start all elements hidden
hideTargets.ForEach(d => d.Hide());
FailingLayer.HUDEnabled.BindTo(ShowHealthbar);
}
public override void Hide() => throw new InvalidOperationException($"{nameof(HUDOverlay)} should not be hidden as it will remove the ability of a user to quit. Use {nameof(ShowHud)} instead.");
@ -168,11 +171,13 @@ namespace osu.Game.Screens.Play
if (healthBar.NewValue)
{
HealthDisplay.FadeIn(fade_duration, fade_easing);
FailingLayer.TryToFade(fade_duration, fade_easing, true);
topScoreContainer.MoveToY(30, fade_duration, fade_easing);
}
else
{
HealthDisplay.FadeOut(fade_duration, fade_easing);
FailingLayer.TryToFade(fade_duration, fade_easing, false);
topScoreContainer.MoveToY(0, fade_duration, fade_easing);
}
}, true);