2019-12-11 21:32:39 +00: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;
|
|
|
|
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;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Background
|
|
|
|
{
|
|
|
|
public class TestSceneUserDimContainer : OsuTestScene
|
|
|
|
{
|
2019-12-12 12:04:56 +00:00
|
|
|
private TestUserDimContainer userDimContainer;
|
2019-12-11 21:32:39 +00:00
|
|
|
|
2019-12-12 12:04:56 +00:00
|
|
|
private readonly BindableBool isBreakTime = new BindableBool();
|
2019-12-11 21:32:39 +00:00
|
|
|
|
2019-12-12 12:04:56 +00:00
|
|
|
private Bindable<bool> lightenDuringBreaks = new Bindable<bool>();
|
2019-12-11 21:32:39 +00:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuConfigManager config)
|
|
|
|
{
|
2019-12-12 12:04:56 +00:00
|
|
|
lightenDuringBreaks = config.GetBindable<bool>(OsuSetting.LightenDuringBreaks);
|
2019-12-11 21:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[SetUp]
|
2019-12-11 22:10:43 +00:00
|
|
|
public void SetUp() => Schedule(() =>
|
2019-12-11 21:32:39 +00:00
|
|
|
{
|
2019-12-12 12:04:56 +00:00
|
|
|
Child = userDimContainer = new TestUserDimContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Child = new Box
|
|
|
|
{
|
|
|
|
Colour = Color4.White,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
userDimContainer.IsBreakTime.BindTo(isBreakTime);
|
2019-12-11 21:32:39 +00:00
|
|
|
isBreakTime.Value = false;
|
2019-12-12 12:04:56 +00:00
|
|
|
|
2019-12-11 21:32:39 +00:00
|
|
|
lightenDuringBreaks.Value = false;
|
2019-12-11 22:10:43 +00:00
|
|
|
});
|
2019-12-11 21:32:39 +00:00
|
|
|
|
2019-12-12 11:51:58 +00:00
|
|
|
private const float test_user_dim = 0.6f;
|
|
|
|
private const float test_user_dim_lightened = test_user_dim - UserDimContainer.BREAK_LIGHTEN_AMOUNT;
|
|
|
|
|
|
|
|
[TestCase(test_user_dim, test_user_dim_lightened)]
|
2019-12-11 21:32:39 +00:00
|
|
|
[TestCase(0.2f, 0.0f)]
|
|
|
|
[TestCase(0.0f, 0.0f)]
|
|
|
|
public void TestBreakLightening(float userDim, float expectedBreakDim)
|
|
|
|
{
|
2019-12-12 12:04:56 +00:00
|
|
|
AddStep($"set dim level {userDim}", () => userDimContainer.UserDimLevel.Value = userDim);
|
2019-12-12 06:20:56 +00:00
|
|
|
AddStep("set lighten during break", () => lightenDuringBreaks.Value = true);
|
2019-12-11 21:32:39 +00:00
|
|
|
|
|
|
|
AddStep("set break", () => isBreakTime.Value = true);
|
2019-12-12 12:04:56 +00:00
|
|
|
AddUntilStep("has lightened", () => userDimContainer.DimEqual(expectedBreakDim));
|
2019-12-12 06:20:56 +00:00
|
|
|
AddStep("clear break", () => isBreakTime.Value = false);
|
2019-12-12 12:04:56 +00:00
|
|
|
AddUntilStep("not lightened", () => userDimContainer.DimEqual(userDim));
|
2019-12-12 06:20:56 +00:00
|
|
|
}
|
2019-12-11 21:32:39 +00:00
|
|
|
|
2019-12-12 06:20:56 +00:00
|
|
|
[Test]
|
|
|
|
public void TestEnableSettingDuringBreak()
|
|
|
|
{
|
2019-12-12 12:04:56 +00:00
|
|
|
AddStep("set dim level 0.6", () => userDimContainer.UserDimLevel.Value = test_user_dim);
|
2019-12-12 06:20:56 +00:00
|
|
|
|
|
|
|
AddStep("set break", () => isBreakTime.Value = true);
|
2019-12-12 12:04:56 +00:00
|
|
|
AddUntilStep("not lightened", () => userDimContainer.DimEqual(test_user_dim));
|
2019-12-11 21:32:39 +00:00
|
|
|
AddStep("set lighten during break", () => lightenDuringBreaks.Value = true);
|
2019-12-12 12:04:56 +00:00
|
|
|
AddUntilStep("has lightened", () => userDimContainer.DimEqual(test_user_dim_lightened));
|
2019-12-12 06:20:56 +00:00
|
|
|
}
|
2019-12-11 21:32:39 +00:00
|
|
|
|
2019-12-12 06:20:56 +00:00
|
|
|
[Test]
|
|
|
|
public void TestDisableSettingDuringBreak()
|
|
|
|
{
|
2019-12-12 12:04:56 +00:00
|
|
|
AddStep("set dim level 0.6", () => userDimContainer.UserDimLevel.Value = test_user_dim);
|
2019-12-12 06:20:56 +00:00
|
|
|
AddStep("set lighten during break", () => lightenDuringBreaks.Value = true);
|
2019-12-11 21:32:39 +00:00
|
|
|
|
2019-12-12 06:20:56 +00:00
|
|
|
AddStep("set break", () => isBreakTime.Value = true);
|
2019-12-12 12:04:56 +00:00
|
|
|
AddUntilStep("has lightened", () => userDimContainer.DimEqual(test_user_dim_lightened));
|
2019-12-12 06:20:56 +00:00
|
|
|
AddStep("clear lighten during break", () => lightenDuringBreaks.Value = false);
|
2019-12-12 12:04:56 +00:00
|
|
|
AddUntilStep("not lightened", () => userDimContainer.DimEqual(test_user_dim));
|
2019-12-11 21:32:39 +00:00
|
|
|
AddStep("clear break", () => isBreakTime.Value = false);
|
2019-12-12 12:04:56 +00:00
|
|
|
AddUntilStep("not lightened", () => userDimContainer.DimEqual(test_user_dim));
|
2019-12-11 21:32:39 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 04:21:23 +00:00
|
|
|
[Test]
|
|
|
|
public void TestIgnoreUserSettings()
|
|
|
|
{
|
|
|
|
AddStep("set dim level 0.6", () => userDimContainer.UserDimLevel.Value = test_user_dim);
|
|
|
|
AddUntilStep("dim reached", () => userDimContainer.DimEqual(test_user_dim));
|
|
|
|
|
2019-12-17 05:04:03 +00:00
|
|
|
AddStep("ignore settings", () => userDimContainer.IgnoreUserSettings.Value = true);
|
2019-12-17 04:21:23 +00:00
|
|
|
AddUntilStep("no dim", () => userDimContainer.DimEqual(0));
|
|
|
|
AddStep("set break", () => isBreakTime.Value = true);
|
|
|
|
AddAssert("no dim", () => userDimContainer.DimEqual(0));
|
|
|
|
AddStep("clear break", () => isBreakTime.Value = false);
|
|
|
|
AddAssert("no dim", () => userDimContainer.DimEqual(0));
|
|
|
|
}
|
|
|
|
|
2019-12-11 21:32:39 +00:00
|
|
|
private class TestUserDimContainer : UserDimContainer
|
|
|
|
{
|
|
|
|
public bool DimEqual(float expectedDimLevel) => Content.Colour == OsuColour.Gray(1f - expectedDimLevel);
|
|
|
|
|
|
|
|
public new Bindable<double> UserDimLevel => base.UserDimLevel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|