1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 16:07:25 +08:00
osu-lazer/osu.Game.Tests/Visual/Background/TestSceneUserDimContainer.cs

97 lines
3.6 KiB
C#
Raw Normal View History

// 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
{
private readonly TestUserDimContainer container;
private readonly BindableBool isBreakTime = new BindableBool();
private readonly Bindable<bool> lightenDuringBreaks = new Bindable<bool>();
public TestSceneUserDimContainer()
{
Add(container = new TestUserDimContainer
{
RelativeSizeAxes = Axes.Both,
Child = new Box
{
Colour = Color4.White,
RelativeSizeAxes = Axes.Both,
},
});
container.IsBreakTime.BindTo(isBreakTime);
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
config.BindWith(OsuSetting.LightenDuringBreaks, lightenDuringBreaks);
}
[SetUp]
2019-12-12 06:10:43 +08:00
public void SetUp() => Schedule(() =>
{
isBreakTime.Value = false;
lightenDuringBreaks.Value = false;
2019-12-12 06:10:43 +08:00
});
[TestCase(0.6f, 0.3f)]
[TestCase(0.2f, 0.0f)]
[TestCase(0.0f, 0.0f)]
public void TestBreakLightening(float userDim, float expectedBreakDim)
{
AddStep($"set dim level {userDim}", () => container.UserDimLevel.Value = userDim);
AddStep("set lighten during break", () => lightenDuringBreaks.Value = true);
AddStep("set break", () => isBreakTime.Value = true);
AddUntilStep("has lightened", () => container.DimEqual(expectedBreakDim));
AddStep("clear break", () => isBreakTime.Value = false);
AddUntilStep("not lightened", () => container.DimEqual(userDim));
}
[Test]
public void TestEnableSettingDuringBreak()
{
AddStep("set dim level 0.6", () => container.UserDimLevel.Value = 0.6f);
AddStep("set break", () => isBreakTime.Value = true);
AddUntilStep("not lightened", () => container.DimEqual(0.6f));
AddStep("set lighten during break", () => lightenDuringBreaks.Value = true);
AddUntilStep("has lightened", () => container.DimEqual(0.3f));
}
[Test]
public void TestDisableSettingDuringBreak()
{
AddStep("set dim level 0.6", () => container.UserDimLevel.Value = 0.6f);
AddStep("set lighten during break", () => lightenDuringBreaks.Value = true);
AddStep("set break", () => isBreakTime.Value = true);
AddUntilStep("has lightened", () => container.DimEqual(0.3f));
AddStep("clear lighten during break", () => lightenDuringBreaks.Value = false);
AddUntilStep("not lightened", () => container.DimEqual(0.6f));
AddStep("clear break", () => isBreakTime.Value = false);
AddUntilStep("not lightened", () => container.DimEqual(0.6f));
}
private class TestUserDimContainer : UserDimContainer
{
public bool DimEqual(float expectedDimLevel) => Content.Colour == OsuColour.Gray(1f - expectedDimLevel);
public new Bindable<double> UserDimLevel => base.UserDimLevel;
}
}
}