mirror of
https://github.com/ppy/osu
synced 2024-12-17 20:35:21 +00:00
Merge pull request #9375 from power9maker/red-tint
Hide red tint when "Show health display even when you can't fail" option is off
This commit is contained in:
commit
50ae69b111
@ -3,6 +3,7 @@
|
||||
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
@ -14,6 +15,8 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
{
|
||||
private FailingLayer layer;
|
||||
|
||||
private readonly Bindable<bool> showHealth = new Bindable<bool>();
|
||||
|
||||
[Resolved]
|
||||
private OsuConfigManager config { get; set; }
|
||||
|
||||
@ -24,8 +27,10 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
{
|
||||
Child = layer = new FailingLayer();
|
||||
layer.BindHealthProcessor(new DrainingHealthProcessor(1));
|
||||
layer.ShowHealth.BindTo(showHealth);
|
||||
});
|
||||
|
||||
AddStep("show health", () => showHealth.Value = true);
|
||||
AddStep("enable layer", () => config.Set(OsuSetting.FadePlayfieldWhenHealthLow, true));
|
||||
AddUntilStep("layer is visible", () => layer.IsPresent);
|
||||
}
|
||||
@ -69,5 +74,27 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
AddWaitStep("wait for potential fade", 10);
|
||||
AddAssert("layer is still visible", () => layer.IsPresent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLayerVisibilityWithDifferentOptions()
|
||||
{
|
||||
AddStep("set health to 0.10", () => layer.Current.Value = 0.1);
|
||||
|
||||
AddStep("don't show health", () => showHealth.Value = false);
|
||||
AddStep("disable FadePlayfieldWhenHealthLow", () => config.Set(OsuSetting.FadePlayfieldWhenHealthLow, false));
|
||||
AddUntilStep("layer fade is invisible", () => !layer.IsPresent);
|
||||
|
||||
AddStep("don't show health", () => showHealth.Value = false);
|
||||
AddStep("enable FadePlayfieldWhenHealthLow", () => config.Set(OsuSetting.FadePlayfieldWhenHealthLow, true));
|
||||
AddUntilStep("layer fade is invisible", () => !layer.IsPresent);
|
||||
|
||||
AddStep("show health", () => showHealth.Value = true);
|
||||
AddStep("disable FadePlayfieldWhenHealthLow", () => config.Set(OsuSetting.FadePlayfieldWhenHealthLow, false));
|
||||
AddUntilStep("layer fade is invisible", () => !layer.IsPresent);
|
||||
|
||||
AddStep("show health", () => showHealth.Value = true);
|
||||
AddStep("enable FadePlayfieldWhenHealthLow", () => config.Set(OsuSetting.FadePlayfieldWhenHealthLow, true));
|
||||
AddUntilStep("layer fade is visible", () => layer.IsPresent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,10 +18,15 @@ using osuTK.Graphics;
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
/// <summary>
|
||||
/// An overlay layer on top of the playfield which fades to red when the current player health falls below a certain threshold defined by <see cref="LowHealthThreshold"/>.
|
||||
/// An overlay layer on top of the playfield which fades to red when the current player health falls below a certain threshold defined by <see cref="low_health_threshold"/>.
|
||||
/// </summary>
|
||||
public class FailingLayer : HealthDisplay
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether the current player health should be shown on screen.
|
||||
/// </summary>
|
||||
public readonly Bindable<bool> ShowHealth = new Bindable<bool>();
|
||||
|
||||
private const float max_alpha = 0.4f;
|
||||
private const int fade_time = 400;
|
||||
private const float gradient_size = 0.3f;
|
||||
@ -29,12 +34,11 @@ namespace osu.Game.Screens.Play.HUD
|
||||
/// <summary>
|
||||
/// The threshold under which the current player life should be considered low and the layer should start fading in.
|
||||
/// </summary>
|
||||
public double LowHealthThreshold = 0.20f;
|
||||
private const double low_health_threshold = 0.20f;
|
||||
|
||||
private readonly Bindable<bool> enabled = new Bindable<bool>();
|
||||
private readonly Container boxes;
|
||||
|
||||
private Bindable<bool> configEnabled;
|
||||
private Bindable<bool> fadePlayfieldWhenHealthLow;
|
||||
private HealthProcessor healthProcessor;
|
||||
|
||||
public FailingLayer()
|
||||
@ -73,14 +77,15 @@ 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);
|
||||
fadePlayfieldWhenHealthLow = config.GetBindable<bool>(OsuSetting.FadePlayfieldWhenHealthLow);
|
||||
fadePlayfieldWhenHealthLow.BindValueChanged(_ => updateState());
|
||||
ShowHealth.BindValueChanged(_ => updateState());
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
updateBindings();
|
||||
updateState();
|
||||
}
|
||||
|
||||
public override void BindHealthProcessor(HealthProcessor processor)
|
||||
@ -88,26 +93,19 @@ namespace osu.Game.Screens.Play.HUD
|
||||
base.BindHealthProcessor(processor);
|
||||
|
||||
healthProcessor = processor;
|
||||
updateBindings();
|
||||
updateState();
|
||||
}
|
||||
|
||||
private void updateBindings()
|
||||
private void updateState()
|
||||
{
|
||||
if (LoadState < LoadState.Ready)
|
||||
return;
|
||||
|
||||
enabled.UnbindBindings();
|
||||
|
||||
// Don't display ever if the ruleset is not using a draining health display.
|
||||
if (healthProcessor is DrainingHealthProcessor)
|
||||
enabled.BindTo(configEnabled);
|
||||
else
|
||||
enabled.Value = false;
|
||||
var showLayer = healthProcessor is DrainingHealthProcessor && fadePlayfieldWhenHealthLow.Value && ShowHealth.Value;
|
||||
this.FadeTo(showLayer ? 1 : 0, fade_time, Easing.OutQuint);
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
double target = Math.Clamp(max_alpha * (1 - Current.Value / LowHealthThreshold), 0, max_alpha);
|
||||
double target = Math.Clamp(max_alpha * (1 - Current.Value / low_health_threshold), 0, max_alpha);
|
||||
|
||||
boxes.Alpha = (float)Interpolation.Lerp(boxes.Alpha, target, Clock.ElapsedFrameTime * 0.01f);
|
||||
|
||||
|
@ -262,7 +262,10 @@ namespace osu.Game.Screens.Play
|
||||
Margin = new MarginPadding { Top = 20 }
|
||||
};
|
||||
|
||||
protected virtual FailingLayer CreateFailingLayer() => new FailingLayer();
|
||||
protected virtual FailingLayer CreateFailingLayer() => new FailingLayer
|
||||
{
|
||||
ShowHealth = { BindTarget = ShowHealthbar }
|
||||
};
|
||||
|
||||
protected virtual KeyCounterDisplay CreateKeyCounter() => new KeyCounterDisplay
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user