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:
parent
8c611a981f
commit
6b0c5bc65d
@ -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", () =>
|
||||
|
47
osu.Game/Screens/Play/HUD/FaillingLayer.cs
Normal file
47
osu.Game/Screens/Play/HUD/FaillingLayer.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user