2019-02-15 15:17:01 +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.
|
|
|
|
|
2019-02-22 13:43:05 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2019-02-21 14:24:26 +08:00
|
|
|
using System.Threading;
|
2019-02-15 15:38:27 +08:00
|
|
|
using NUnit.Framework;
|
2019-02-21 14:24:26 +08:00
|
|
|
using osu.Framework.Allocation;
|
2019-02-22 19:44:02 +08:00
|
|
|
using osu.Framework.Bindables;
|
2019-02-21 14:24:26 +08:00
|
|
|
using osu.Framework.Graphics;
|
2019-02-19 18:44:26 +08:00
|
|
|
using osu.Framework.Screens;
|
|
|
|
using osu.Game.Beatmaps;
|
2019-02-22 10:41:28 +08:00
|
|
|
using osu.Game.Configuration;
|
2019-02-15 15:17:01 +08:00
|
|
|
using osu.Game.Graphics;
|
2019-02-22 19:34:51 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
2019-02-19 18:44:26 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
2019-02-18 17:58:34 +08:00
|
|
|
using osu.Game.Scoring;
|
2019-02-15 15:17:01 +08:00
|
|
|
using osu.Game.Screens;
|
|
|
|
using osu.Game.Screens.Backgrounds;
|
|
|
|
using osu.Game.Screens.Play;
|
2019-02-21 14:24:26 +08:00
|
|
|
using osu.Game.Screens.Play.PlayerSettings;
|
2019-02-19 18:44:26 +08:00
|
|
|
using osu.Game.Tests.Beatmaps;
|
2019-02-18 18:53:55 +08:00
|
|
|
using osu.Game.Users;
|
2019-02-19 18:44:26 +08:00
|
|
|
using osuTK;
|
2019-02-18 18:53:55 +08:00
|
|
|
using osuTK.Graphics;
|
2019-02-15 15:17:01 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
{
|
2019-02-15 15:38:27 +08:00
|
|
|
[TestFixture]
|
2019-02-21 14:24:26 +08:00
|
|
|
public class TestCaseBackgroundScreenBeatmap : ManualInputManagerTestCase
|
2019-02-15 15:17:01 +08:00
|
|
|
{
|
2019-02-22 13:43:05 +08:00
|
|
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
|
|
|
{
|
|
|
|
typeof(ScreenWithBeatmapBackground),
|
|
|
|
typeof(PlayerLoader),
|
2019-02-22 19:34:51 +08:00
|
|
|
typeof(Player),
|
|
|
|
typeof(UserDimContainer)
|
2019-02-22 13:43:05 +08:00
|
|
|
};
|
|
|
|
|
2019-02-19 18:44:26 +08:00
|
|
|
private DummySongSelect songSelect;
|
2019-02-21 14:24:26 +08:00
|
|
|
private DimAccessiblePlayerLoader playerLoader;
|
|
|
|
private DimAccessiblePlayer player;
|
2019-02-22 19:34:51 +08:00
|
|
|
private readonly ScreenStack screen;
|
2019-02-21 14:24:26 +08:00
|
|
|
|
|
|
|
[Cached]
|
|
|
|
private BackgroundScreenStack backgroundStack;
|
|
|
|
|
2019-02-24 17:10:59 +08:00
|
|
|
private void performSetup()
|
|
|
|
{
|
|
|
|
createSongSelect();
|
|
|
|
|
|
|
|
AddStep("Load new player to song select", () => songSelect.Push(player = new DimAccessiblePlayer { Ready = true }));
|
|
|
|
AddUntilStep(() => player?.IsLoaded ?? false, "Wait for player to load");
|
|
|
|
}
|
|
|
|
|
2019-02-22 19:34:51 +08:00
|
|
|
private void createSongSelect()
|
|
|
|
{
|
|
|
|
AddStep("Create song select if required", () =>
|
|
|
|
{
|
|
|
|
if (songSelect == null)
|
|
|
|
{
|
|
|
|
LoadComponentAsync(new DummySongSelect(), p =>
|
|
|
|
{
|
|
|
|
songSelect = p;
|
|
|
|
screen.Push(p);
|
|
|
|
songSelect.UpdateBindables();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
AddUntilStep(() => songSelect?.IsLoaded ?? false, "Wait for song select to load");
|
2019-02-22 15:56:03 +08:00
|
|
|
AddUntilStep(() =>
|
|
|
|
{
|
|
|
|
if (!songSelect.IsCurrentScreen())
|
|
|
|
{
|
|
|
|
songSelect.MakeCurrent();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}, "Wait for song select is current");
|
|
|
|
}
|
|
|
|
|
2019-02-19 18:44:26 +08:00
|
|
|
public TestCaseBackgroundScreenBeatmap()
|
2019-02-18 17:12:45 +08:00
|
|
|
{
|
2019-02-21 14:24:26 +08:00
|
|
|
InputManager.Add(backgroundStack = new BackgroundScreenStack {RelativeSizeAxes = Axes.Both});
|
|
|
|
InputManager.Add(screen = new ScreenStack { RelativeSizeAxes = Axes.Both });
|
|
|
|
|
2019-02-19 18:44:26 +08:00
|
|
|
AddStep("Create beatmap", () =>
|
|
|
|
{
|
|
|
|
Beatmap.Value = new TestWorkingBeatmap(new Beatmap<OsuHitObject>
|
|
|
|
{
|
|
|
|
HitObjects =
|
|
|
|
{
|
2019-02-19 18:57:55 +08:00
|
|
|
new HitCircle
|
2019-02-19 18:44:26 +08:00
|
|
|
{
|
|
|
|
StartTime = 3000,
|
|
|
|
Position = new Vector2(0, 0),
|
|
|
|
},
|
2019-02-19 18:57:55 +08:00
|
|
|
new HitCircle
|
2019-02-19 18:44:26 +08:00
|
|
|
{
|
|
|
|
StartTime = 15000,
|
|
|
|
Position = new Vector2(0, 0),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2019-02-24 17:10:59 +08:00
|
|
|
}
|
2019-02-21 14:24:26 +08:00
|
|
|
|
2019-02-24 17:10:59 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Check if PlayerLoader properly triggers background dim previews when a user hovers over the visual settings panel.
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void PlayerLoaderSettingsHoverTest()
|
|
|
|
{
|
|
|
|
createSongSelect();
|
2019-02-21 14:24:26 +08:00
|
|
|
AddStep("Start player loader", () => songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer())));
|
|
|
|
AddUntilStep(() => playerLoader?.IsLoaded ?? false, "Wait for Player Loader to load");
|
2019-02-22 13:43:05 +08:00
|
|
|
AddAssert("Background retained from song select", () => songSelect.AssertBackgroundCurrent());
|
2019-02-21 14:24:26 +08:00
|
|
|
AddStep("Trigger background preview", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(playerLoader.ScreenPos);
|
|
|
|
InputManager.MoveMouseTo(playerLoader.VisualSettingsPos);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddWaitStep(5, "Wait for dim");
|
|
|
|
AddAssert("Screen is dimmed", () => songSelect.AssertDimmed());
|
2019-02-24 17:10:59 +08:00
|
|
|
}
|
2019-02-21 14:24:26 +08:00
|
|
|
|
2019-02-24 17:10:59 +08:00
|
|
|
/// <summary>
|
|
|
|
/// In the case of a user triggering the dim preview the instant player gets loaded, then moving the cursor off of the visual settings:
|
|
|
|
/// The OnHover of PlayerLoader will trigger, which could potentially trigger an undim unless checked for in PlayerLoader.
|
|
|
|
/// We need to check that in this scenario, the dim is still properly applied after entering player.
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void PlayerLoaderTransitionTest()
|
|
|
|
{
|
|
|
|
createSongSelect();
|
|
|
|
AddStep("Start player loader", () => songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer())));
|
|
|
|
AddUntilStep(() => playerLoader?.IsLoaded ?? false, "Wait for Player Loader to load");
|
2019-02-21 14:24:26 +08:00
|
|
|
AddStep("Allow beatmap to load", () =>
|
2019-02-19 18:44:26 +08:00
|
|
|
{
|
2019-02-21 14:24:26 +08:00
|
|
|
player.Ready = true;
|
|
|
|
InputManager.MoveMouseTo(playerLoader.ScreenPos);
|
2019-02-19 18:44:26 +08:00
|
|
|
});
|
2019-02-21 14:24:26 +08:00
|
|
|
AddUntilStep(() => player?.IsLoaded ?? false, "Wait for player to load");
|
2019-02-22 13:43:05 +08:00
|
|
|
AddAssert("Background retained from song select", () => songSelect.AssertBackgroundCurrent());
|
2019-02-22 10:41:28 +08:00
|
|
|
AddStep("Trigger background preview when loaded", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(playerLoader.VisualSettingsPos);
|
|
|
|
InputManager.MoveMouseTo(playerLoader.ScreenPos);
|
|
|
|
});
|
2019-02-21 14:24:26 +08:00
|
|
|
AddWaitStep(5, "Wait for dim");
|
|
|
|
AddAssert("Screen is dimmed", () => songSelect.AssertDimmed());
|
2019-02-24 17:10:59 +08:00
|
|
|
}
|
2019-02-22 10:41:28 +08:00
|
|
|
|
2019-02-24 17:10:59 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Make sure the background is fully invisible (Alpha == 0) when the background should be disabled by the storyboard.
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void StoryboardBackgroundVisibilityTest()
|
|
|
|
{
|
|
|
|
performSetup();
|
2019-02-22 10:41:28 +08:00
|
|
|
AddStep("Enable storyboard", () =>
|
|
|
|
{
|
|
|
|
player.ReplacesBackground.Value = true;
|
|
|
|
player.StoryboardEnabled.Value = true;
|
|
|
|
});
|
|
|
|
AddWaitStep(5, "Wait for dim");
|
|
|
|
AddAssert("Background is invisible", () => songSelect.AssertInvisible());
|
|
|
|
AddStep("Disable storyboard", () => player.ReplacesBackground.Value = false);
|
|
|
|
AddWaitStep(5, "Wait for dim");
|
|
|
|
AddAssert("Background is visible", () => songSelect.AssertVisible());
|
2019-02-18 17:58:34 +08:00
|
|
|
}
|
|
|
|
|
2019-02-18 18:53:55 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Check if the fade container is properly being reset when screen dim is disabled.
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void DisableUserDimTest()
|
|
|
|
{
|
2019-02-22 15:56:03 +08:00
|
|
|
performSetup();
|
|
|
|
AddStep("Test User Undimming", () => songSelect.DimEnabled.Value = false);
|
2019-02-18 18:53:55 +08:00
|
|
|
AddWaitStep(5, "Wait for dim");
|
2019-02-21 14:24:26 +08:00
|
|
|
AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed());
|
2019-02-18 18:53:55 +08:00
|
|
|
}
|
|
|
|
|
2019-02-15 15:50:37 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Check if the fade container is properly being faded when screen dim is enabled.
|
|
|
|
/// </summary>
|
2019-02-15 15:17:01 +08:00
|
|
|
[Test]
|
|
|
|
public void EnableUserDimTest()
|
|
|
|
{
|
2019-02-22 15:56:03 +08:00
|
|
|
performSetup();
|
|
|
|
AddStep("Test User Dimming", () => songSelect.DimEnabled.Value = true);
|
2019-02-15 15:38:27 +08:00
|
|
|
AddWaitStep(5, "Wait for dim");
|
2019-02-21 14:24:26 +08:00
|
|
|
AddAssert("Screen is dimmed", () => songSelect.AssertDimmed());
|
2019-02-15 15:17:01 +08:00
|
|
|
}
|
|
|
|
|
2019-02-15 15:50:37 +08:00
|
|
|
/// <summary>
|
2019-02-18 18:53:55 +08:00
|
|
|
/// Check if the fade container retains dim when pausing
|
2019-02-15 15:50:37 +08:00
|
|
|
/// </summary>
|
2019-02-15 15:38:27 +08:00
|
|
|
[Test]
|
2019-02-18 18:53:55 +08:00
|
|
|
public void PauseTest()
|
2019-02-15 15:38:27 +08:00
|
|
|
{
|
2019-02-22 15:56:03 +08:00
|
|
|
performSetup();
|
2019-02-22 13:43:05 +08:00
|
|
|
AddStep("Transition to Pause", () =>
|
|
|
|
{
|
2019-02-24 17:10:59 +08:00
|
|
|
if (!player.IsPaused.Value)
|
2019-02-22 13:43:05 +08:00
|
|
|
player.Exit();
|
|
|
|
});
|
2019-02-15 15:38:27 +08:00
|
|
|
AddWaitStep(5, "Wait for dim");
|
2019-02-21 14:24:26 +08:00
|
|
|
AddAssert("Screen is dimmed", () => songSelect.AssertDimmed());
|
2019-02-18 18:53:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2019-02-19 18:44:26 +08:00
|
|
|
/// Check if the fade container removes user dim when suspending player for results
|
2019-02-18 18:53:55 +08:00
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void TransitionTest()
|
|
|
|
{
|
2019-02-22 15:56:03 +08:00
|
|
|
performSetup();
|
2019-02-21 14:24:26 +08:00
|
|
|
AddStep("Transition to Results", () => player.Push(new FadeAccesibleResults(new ScoreInfo { User = new User { Username = "osu!" }})));
|
2019-02-19 18:44:26 +08:00
|
|
|
AddWaitStep(5, "Wait for dim");
|
2019-02-21 14:24:26 +08:00
|
|
|
AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed());
|
2019-02-22 13:43:05 +08:00
|
|
|
AddAssert("Background retained from song select", () => songSelect.AssertBackgroundCurrent());
|
2019-02-19 18:44:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Check if background gets undimmed when leaving the player for the previous screen
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void TransitionOutTest()
|
|
|
|
{
|
2019-02-22 15:56:03 +08:00
|
|
|
performSetup();
|
2019-02-22 16:15:05 +08:00
|
|
|
AddUntilStep(() =>
|
|
|
|
{
|
|
|
|
if (!songSelect.IsCurrentScreen())
|
|
|
|
{
|
|
|
|
songSelect.MakeCurrent();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}, "Wait for song select is current");
|
2019-02-18 18:53:55 +08:00
|
|
|
AddWaitStep(5, "Wait for dim");
|
2019-02-21 14:24:26 +08:00
|
|
|
AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed());
|
2019-02-15 15:38:27 +08:00
|
|
|
}
|
|
|
|
|
2019-02-19 18:44:26 +08:00
|
|
|
private class DummySongSelect : OsuScreen
|
|
|
|
{
|
|
|
|
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground();
|
2019-02-22 15:56:03 +08:00
|
|
|
public readonly Bindable<bool> DimEnabled = new Bindable<bool>();
|
2019-02-24 17:10:59 +08:00
|
|
|
private readonly Bindable<double> dimLevel = new Bindable<double>();
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuConfigManager config)
|
|
|
|
{
|
|
|
|
config.BindWith(OsuSetting.DimLevel, dimLevel);
|
|
|
|
}
|
2019-02-22 15:56:03 +08:00
|
|
|
|
|
|
|
public void UpdateBindables()
|
|
|
|
{
|
|
|
|
DimEnabled.BindTo(((FadeAccessibleBackground)Background).EnableUserDim);
|
|
|
|
}
|
2019-02-21 14:24:26 +08:00
|
|
|
|
|
|
|
public bool AssertDimmed()
|
|
|
|
{
|
2019-02-24 17:10:59 +08:00
|
|
|
return ((FadeAccessibleBackground)Background).CurrentColour == OsuColour.Gray(1 - (float)dimLevel.Value);
|
2019-02-21 14:24:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool AssertUndimmed()
|
|
|
|
{
|
2019-02-24 17:10:59 +08:00
|
|
|
return ((FadeAccessibleBackground)Background).CurrentColour == Color4.White;
|
2019-02-21 14:24:26 +08:00
|
|
|
}
|
2019-02-22 10:41:28 +08:00
|
|
|
|
|
|
|
public bool AssertInvisible()
|
|
|
|
{
|
2019-02-24 17:10:59 +08:00
|
|
|
return ((FadeAccessibleBackground)Background).CurrentAlpha == 0;
|
2019-02-22 10:41:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool AssertVisible()
|
|
|
|
{
|
2019-02-24 17:10:59 +08:00
|
|
|
return ((FadeAccessibleBackground)Background).CurrentAlpha == 1;
|
2019-02-22 10:41:28 +08:00
|
|
|
}
|
2019-02-22 13:43:05 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Make sure every time a screen gets pushed, the background doesn't get replaced
|
|
|
|
/// </summary>
|
2019-02-24 19:03:24 +08:00
|
|
|
/// <returns>Whether or not the original background (The one created in DummySongSelect) is still the current background</returns>
|
2019-02-22 13:43:05 +08:00
|
|
|
public bool AssertBackgroundCurrent()
|
|
|
|
{
|
|
|
|
return ((FadeAccessibleBackground)Background).IsCurrentScreen();
|
|
|
|
}
|
2019-02-19 18:44:26 +08:00
|
|
|
}
|
2019-02-15 15:17:01 +08:00
|
|
|
|
2019-02-18 18:53:55 +08:00
|
|
|
private class FadeAccesibleResults : SoloResults
|
|
|
|
{
|
|
|
|
public FadeAccesibleResults(ScoreInfo score) : base(score)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground();
|
|
|
|
}
|
|
|
|
|
2019-02-15 15:17:01 +08:00
|
|
|
private class DimAccessiblePlayer : Player
|
|
|
|
{
|
2019-02-18 17:58:34 +08:00
|
|
|
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground();
|
2019-02-15 15:17:01 +08:00
|
|
|
|
2019-02-24 17:10:59 +08:00
|
|
|
// Whether or not the player should be allowed to load.
|
2019-02-21 14:24:26 +08:00
|
|
|
public bool Ready;
|
|
|
|
|
2019-02-22 10:41:28 +08:00
|
|
|
public Bindable<bool> StoryboardEnabled;
|
|
|
|
public readonly Bindable<bool> ReplacesBackground = new Bindable<bool>();
|
2019-02-24 17:10:59 +08:00
|
|
|
public readonly Bindable<bool> IsPaused = new Bindable<bool>();
|
2019-02-22 13:43:05 +08:00
|
|
|
|
2019-02-21 14:24:26 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2019-02-22 10:41:28 +08:00
|
|
|
private void load(OsuConfigManager config)
|
2019-02-15 15:17:01 +08:00
|
|
|
{
|
2019-02-21 14:24:26 +08:00
|
|
|
while (!Ready)
|
|
|
|
Thread.Sleep(1);
|
2019-02-22 10:41:28 +08:00
|
|
|
StoryboardEnabled = config.GetBindable<bool>(OsuSetting.ShowStoryboard);
|
|
|
|
ReplacesBackground.BindTo(Background.StoryboardReplacesBackground);
|
2019-02-24 17:10:59 +08:00
|
|
|
RulesetContainer.IsPaused.BindTo(IsPaused);
|
2019-02-15 15:17:01 +08:00
|
|
|
}
|
2019-02-21 14:24:26 +08:00
|
|
|
}
|
2019-02-15 15:17:01 +08:00
|
|
|
|
2019-02-21 14:24:26 +08:00
|
|
|
private class DimAccessiblePlayerLoader : PlayerLoader
|
|
|
|
{
|
|
|
|
public VisualSettings VisualSettingsPos => VisualSettings;
|
2019-02-22 10:41:28 +08:00
|
|
|
public BackgroundScreen ScreenPos => Background;
|
2019-02-21 14:24:26 +08:00
|
|
|
|
|
|
|
public DimAccessiblePlayerLoader(Player player) : base(() => player)
|
2019-02-15 15:38:27 +08:00
|
|
|
{
|
|
|
|
}
|
2019-02-21 17:19:50 +08:00
|
|
|
|
2019-02-21 14:24:26 +08:00
|
|
|
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground();
|
2019-02-18 18:53:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private class FadeAccessibleBackground : BackgroundScreenBeatmap
|
|
|
|
{
|
2019-02-22 19:34:51 +08:00
|
|
|
protected override UserDimContainer CreateFadeContainer() => new TestUserDimContainer { RelativeSizeAxes = Axes.Both };
|
2019-02-22 17:01:50 +08:00
|
|
|
|
2019-02-24 17:10:59 +08:00
|
|
|
public Color4 CurrentColour => ((TestUserDimContainer)FadeContainer).CurrentColour;
|
|
|
|
public float CurrentAlpha => ((TestUserDimContainer)FadeContainer).CurrentAlpha;
|
2019-02-22 19:34:51 +08:00
|
|
|
|
|
|
|
private class TestUserDimContainer : UserDimContainer
|
|
|
|
{
|
|
|
|
public Color4 CurrentColour => DimContainer.Colour;
|
|
|
|
public float CurrentAlpha => DimContainer.Alpha;
|
2019-02-22 10:41:28 +08:00
|
|
|
}
|
2019-02-15 15:17:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|