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

Rename to LowHealthLayer to FaillingLayer.

This commit is contained in:
Lucas A 2020-03-17 22:32:07 +01:00
parent 8c611a981f
commit 6b0c5bc65d
3 changed files with 47 additions and 79 deletions

View File

@ -103,38 +103,6 @@ namespace osu.Game.Tests.Visual.Gameplay
AddStep("return value", () => config.Set<bool>(OsuSetting.KeyOverlay, keyCounterVisibleValue));
}
[Test]
public void TestChangeHealthValue()
{
void applyToHealthDisplays(double value)
{
if (hudOverlay == null) return;
hudOverlay.LowHealthDisplay.Current.Value = value;
hudOverlay.HealthDisplay.Current.Value = value;
}
createNew();
AddSliderStep("health value", 0, 1, 0.5, applyToHealthDisplays);
AddStep("enable low health display", () =>
{
config.Set(OsuSetting.FadePlayfieldWhenLowHealth, true);
hudOverlay.LowHealthDisplay.FinishTransforms(true);
});
AddAssert("low health display is visible", () => hudOverlay.LowHealthDisplay.IsPresent);
AddStep("set health to 30%", () => applyToHealthDisplays(0.3));
AddAssert("hud is not faded to red", () => !hudOverlay.LowHealthDisplay.Child.IsPresent);
AddStep("set health to < 10%", () => applyToHealthDisplays(0.1f));
AddAssert("hud is faded to red", () => hudOverlay.LowHealthDisplay.Child.IsPresent);
AddStep("disable low health display", () =>
{
config.Set(OsuSetting.FadePlayfieldWhenLowHealth, false);
hudOverlay.LowHealthDisplay.FinishTransforms(true);
});
AddAssert("low health display is not visible", () => !hudOverlay.LowHealthDisplay.IsPresent);
}
private void createNew(Action<HUDOverlay> action = null)
{
AddStep("create overlay", () =>

View File

@ -0,0 +1,47 @@
// 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.
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
namespace osu.Game.Screens.Play.HUD
{
/// <summary>
/// An overlay layer on top of the player HUD which fades to red when the current player health falls a certain threshold defined by <see cref="LowHealthThreshold"/>.
/// </summary>
public class FaillingLayer : HealthDisplay
{
private const float max_alpha = 0.4f;
private readonly Box box;
/// <summary>
/// The threshold under which the current player life should be considered low and the layer should start fading in.
/// </summary>
protected virtual double LowHealthThreshold => 0.20f;
public FaillingLayer()
{
Child = box = new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0
};
}
[BackgroundDependencyLoader]
private void load(OsuColour color)
{
box.Colour = color.Red;
}
protected override void Update()
{
box.Alpha = (float)Math.Clamp(max_alpha * (1 - Current.Value / LowHealthThreshold), 0, max_alpha);
base.Update();
}
}
}

View File

@ -1,47 +0,0 @@
// 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.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Game.Configuration;
using osu.Game.Graphics;
namespace osu.Game.Screens.Play.HUD
{
public class LowHealthLayer : HealthDisplay
{
private const float max_alpha = 0.4f;
private const double fade_time = 300;
private readonly Box box;
private Bindable<bool> configFadeRedWhenLowHealth;
public LowHealthLayer()
{
Child = box = new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0
};
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config, OsuColour color)
{
configFadeRedWhenLowHealth = config.GetBindable<bool>(OsuSetting.FadePlayfieldWhenLowHealth);
box.Colour = color.Red;
configFadeRedWhenLowHealth.BindValueChanged(value =>
{
if (value.NewValue)
this.FadeIn(fade_time, Easing.OutQuint);
else
this.FadeOut(fade_time, Easing.OutQuint);
}, true);
}
}
}