2020-03-26 19:14:44 +08:00
|
|
|
|
// 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 NUnit.Framework;
|
2020-04-01 21:12:31 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2020-06-26 20:58:42 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2020-04-09 13:47:48 +08:00
|
|
|
|
using osu.Framework.Testing;
|
2020-04-01 21:12:31 +08:00
|
|
|
|
using osu.Game.Configuration;
|
2020-04-09 13:47:48 +08:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2020-03-26 19:14:44 +08:00
|
|
|
|
using osu.Game.Screens.Play.HUD;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
|
|
|
|
{
|
|
|
|
|
public class TestSceneFailingLayer : OsuTestScene
|
|
|
|
|
{
|
2020-04-09 13:47:48 +08:00
|
|
|
|
private FailingLayer layer;
|
2020-03-26 19:14:44 +08:00
|
|
|
|
|
2020-06-27 01:03:41 +08:00
|
|
|
|
private readonly Bindable<bool> showHealth = new Bindable<bool>();
|
2020-06-26 20:58:42 +08:00
|
|
|
|
|
2020-04-01 21:12:31 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuConfigManager config { get; set; }
|
|
|
|
|
|
2020-04-09 13:47:48 +08:00
|
|
|
|
[SetUpSteps]
|
|
|
|
|
public void SetUpSteps()
|
2020-03-26 19:14:44 +08:00
|
|
|
|
{
|
2020-04-14 14:24:34 +08:00
|
|
|
|
AddStep("create layer", () =>
|
|
|
|
|
{
|
|
|
|
|
Child = layer = new FailingLayer();
|
|
|
|
|
layer.BindHealthProcessor(new DrainingHealthProcessor(1));
|
2020-06-27 01:03:41 +08:00
|
|
|
|
layer.ShowHealth.BindTo(showHealth);
|
2020-04-14 14:24:34 +08:00
|
|
|
|
});
|
|
|
|
|
|
2020-06-27 01:03:41 +08:00
|
|
|
|
AddStep("show health", () => showHealth.Value = true);
|
2021-03-17 15:10:16 +08:00
|
|
|
|
AddStep("enable layer", () => config.SetValue(OsuSetting.FadePlayfieldWhenHealthLow, true));
|
2020-04-09 13:47:48 +08:00
|
|
|
|
AddUntilStep("layer is visible", () => layer.IsPresent);
|
2020-03-26 19:14:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 13:52:40 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestLayerFading()
|
|
|
|
|
{
|
|
|
|
|
AddSliderStep("current health", 0.0, 1.0, 1.0, val =>
|
|
|
|
|
{
|
|
|
|
|
if (layer != null)
|
|
|
|
|
layer.Current.Value = val;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddStep("set health to 0.10", () => layer.Current.Value = 0.1);
|
|
|
|
|
AddUntilStep("layer fade is visible", () => layer.Child.Alpha > 0.1f);
|
|
|
|
|
AddStep("set health to 1", () => layer.Current.Value = 1f);
|
|
|
|
|
AddUntilStep("layer fade is invisible", () => !layer.Child.IsPresent);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-01 21:12:31 +08:00
|
|
|
|
[Test]
|
2020-04-09 13:47:48 +08:00
|
|
|
|
public void TestLayerDisabledViaConfig()
|
2020-04-01 21:12:31 +08:00
|
|
|
|
{
|
2021-03-17 15:10:16 +08:00
|
|
|
|
AddStep("disable layer", () => config.SetValue(OsuSetting.FadePlayfieldWhenHealthLow, false));
|
2020-04-14 14:24:34 +08:00
|
|
|
|
AddStep("set health to 0.10", () => layer.Current.Value = 0.1);
|
2020-04-09 13:47:48 +08:00
|
|
|
|
AddUntilStep("layer is not visible", () => !layer.IsPresent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestLayerVisibilityWithAccumulatingProcessor()
|
|
|
|
|
{
|
|
|
|
|
AddStep("bind accumulating processor", () => layer.BindHealthProcessor(new AccumulatingHealthProcessor(1)));
|
2020-04-14 14:24:34 +08:00
|
|
|
|
AddStep("set health to 0.10", () => layer.Current.Value = 0.1);
|
2020-04-09 13:47:48 +08:00
|
|
|
|
AddUntilStep("layer is not visible", () => !layer.IsPresent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestLayerVisibilityWithDrainingProcessor()
|
|
|
|
|
{
|
|
|
|
|
AddStep("bind accumulating processor", () => layer.BindHealthProcessor(new DrainingHealthProcessor(1)));
|
2020-04-14 14:24:34 +08:00
|
|
|
|
AddStep("set health to 0.10", () => layer.Current.Value = 0.1);
|
2020-04-09 13:47:48 +08:00
|
|
|
|
AddWaitStep("wait for potential fade", 10);
|
|
|
|
|
AddAssert("layer is still visible", () => layer.IsPresent);
|
2020-04-01 21:12:31 +08:00
|
|
|
|
}
|
2020-06-26 20:58:42 +08:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestLayerVisibilityWithDifferentOptions()
|
|
|
|
|
{
|
|
|
|
|
AddStep("set health to 0.10", () => layer.Current.Value = 0.1);
|
|
|
|
|
|
2020-06-27 01:03:41 +08:00
|
|
|
|
AddStep("don't show health", () => showHealth.Value = false);
|
2021-03-17 15:10:16 +08:00
|
|
|
|
AddStep("disable FadePlayfieldWhenHealthLow", () => config.SetValue(OsuSetting.FadePlayfieldWhenHealthLow, false));
|
2020-06-26 20:58:42 +08:00
|
|
|
|
AddUntilStep("layer fade is invisible", () => !layer.IsPresent);
|
|
|
|
|
|
2020-06-27 01:03:41 +08:00
|
|
|
|
AddStep("don't show health", () => showHealth.Value = false);
|
2021-03-17 15:10:16 +08:00
|
|
|
|
AddStep("enable FadePlayfieldWhenHealthLow", () => config.SetValue(OsuSetting.FadePlayfieldWhenHealthLow, true));
|
2020-06-26 20:58:42 +08:00
|
|
|
|
AddUntilStep("layer fade is invisible", () => !layer.IsPresent);
|
|
|
|
|
|
2020-06-27 01:03:41 +08:00
|
|
|
|
AddStep("show health", () => showHealth.Value = true);
|
2021-03-17 15:10:16 +08:00
|
|
|
|
AddStep("disable FadePlayfieldWhenHealthLow", () => config.SetValue(OsuSetting.FadePlayfieldWhenHealthLow, false));
|
2020-06-26 20:58:42 +08:00
|
|
|
|
AddUntilStep("layer fade is invisible", () => !layer.IsPresent);
|
|
|
|
|
|
2020-06-27 01:03:41 +08:00
|
|
|
|
AddStep("show health", () => showHealth.Value = true);
|
2021-03-17 15:10:16 +08:00
|
|
|
|
AddStep("enable FadePlayfieldWhenHealthLow", () => config.SetValue(OsuSetting.FadePlayfieldWhenHealthLow, true));
|
2020-06-26 20:58:42 +08:00
|
|
|
|
AddUntilStep("layer fade is visible", () => layer.IsPresent);
|
|
|
|
|
}
|
2020-03-26 19:14:44 +08:00
|
|
|
|
}
|
|
|
|
|
}
|