1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 13:32:54 +08:00

Change fail effect to be less distracting

This commit is contained in:
Dean Herbert 2020-04-09 14:33:11 +09:00
parent 4976f80b71
commit 947745d87e
2 changed files with 34 additions and 11 deletions

View File

@ -1,11 +1,8 @@
// 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.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Testing;
using osu.Game.Configuration;
using osu.Game.Screens.Play.HUD;
@ -40,7 +37,7 @@ namespace osu.Game.Tests.Visual.Gameplay
public void TestLayerFading()
{
AddSliderStep("current health", 0.0, 1.0, 1.0, val => layer.Current.Value = val);
var box = layer.ChildrenOfType<Box>().First();
var box = layer.Child;
AddStep("set health to 0.10", () => layer.Current.Value = 0.10);
AddWaitStep("wait for fade to finish", 5);

View File

@ -4,12 +4,16 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Utils;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Rulesets.Scoring;
using osuTK.Graphics;
namespace osu.Game.Screens.Play.HUD
{
@ -22,8 +26,6 @@ namespace osu.Game.Screens.Play.HUD
private const int fade_time = 400;
private readonly Box box;
private Bindable<bool> enabled;
/// <summary>
@ -31,20 +33,43 @@ namespace osu.Game.Screens.Play.HUD
/// </summary>
public double LowHealthThreshold = 0.20f;
private readonly Container boxes;
public FailingLayer()
{
RelativeSizeAxes = Axes.Both;
Child = box = new Box
Children = new Drawable[]
{
RelativeSizeAxes = Axes.Both,
Alpha = 0
boxes = new Container
{
Blending = BlendingParameters.Additive,
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientVertical(Color4.White, Color4.White.Opacity(0)),
Height = 0.2f,
},
new Box
{
RelativeSizeAxes = Axes.Both,
Height = 0.2f,
Colour = ColourInfo.GradientVertical(Color4.White.Opacity(0), Color4.White),
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
},
}
},
};
}
[BackgroundDependencyLoader]
private void load(OsuColour color, OsuConfigManager config)
{
box.Colour = color.Red;
boxes.Colour = color.Red;
enabled = config.GetBindable<bool>(OsuSetting.FadePlayfieldWhenHealthLow);
enabled.BindValueChanged(e => this.FadeTo(e.NewValue ? 1 : 0, fade_time, Easing.OutQuint), true);
}
@ -53,6 +78,7 @@ namespace osu.Game.Screens.Play.HUD
{
base.BindHealthProcessor(processor);
// don't display ever if the ruleset is not using a draining health display.
if (!(processor is DrainingHealthProcessor))
{
enabled.UnbindBindings();
@ -62,7 +88,7 @@ namespace osu.Game.Screens.Play.HUD
protected override void Update()
{
box.Alpha = (float)Interpolation.ValueAt(Math.Clamp(Clock.ElapsedFrameTime, 0, fade_time), box.Alpha,
boxes.Alpha = (float)Interpolation.ValueAt(Math.Clamp(Clock.ElapsedFrameTime, 0, fade_time), boxes.Alpha,
Math.Clamp(max_alpha * (1 - Current.Value / LowHealthThreshold), 0, max_alpha), 0, fade_time, Easing.Out);
base.Update();