From 882fff16312ff6bcb73b30c3d687a970bc5cd79c Mon Sep 17 00:00:00 2001 From: David Zhao Date: Wed, 27 Feb 2019 17:56:44 +0900 Subject: [PATCH] Assert storyboard visibilty at both steps of toggle --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 69 +++++++++++-------- osu.Game/Screens/Play/Player.cs | 14 ++-- 2 files changed, 48 insertions(+), 35 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index fa38598e4b..44d2bce0e6 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -141,25 +141,16 @@ namespace osu.Game.Tests.Visual public void StoryboardBackgroundVisibilityTest() { performSetup(); - AddStep("Enable storyboard", () => + createFakeStoryboard(); + waitForDim(); + AddAssert("Background is invisible, storyboard is visible", () => songSelect.IsBackgroundInvisible() && player.IsStoryboardVisible()); + AddStep("Disable storyboard", () => { - player.ReplacesBackground.Value = true; - player.StoryboardEnabled.Value = true; - player.CurrentStoryboardContainer.Add(new SpriteText - { - Size = new Vector2(250, 50), - Alpha = 1, - Colour = Color4.White, - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Text = "THIS IS A STORYBOARD", - }); + player.ReplacesBackground.Value = false; + player.StoryboardEnabled.Value = false; }); waitForDim(); - AddAssert("Background is invisible, storyboard is visible", () => songSelect.IsBackgroundInvisible() && player.CurrentStoryboardContainer.Alpha == 1); - AddStep("Disable storyboard", () => player.ReplacesBackground.Value = false); - waitForDim(); - AddAssert("Background is visible", () => songSelect.IsBackgroundVisible()); + AddAssert("Background is visible, storyboard is invisible", () => songSelect.IsBackgroundVisible() && player.IsStoryboardInvisible()); } /// @@ -169,16 +160,7 @@ namespace osu.Game.Tests.Visual public void StoryboardTransitionTest() { performSetup(); - AddStep("Enable storyboard", () => - { - player.ReplacesBackground.Value = true; - player.StoryboardEnabled.Value = true; - player.CurrentStoryboardContainer.Add(new Box - { - Alpha = 1, - Colour = Color4.Tomato - }); - }); + createFakeStoryboard(); AddUntilStep(() => { if (songSelect.IsCurrentScreen()) return true; @@ -265,6 +247,17 @@ namespace osu.Game.Tests.Visual private void waitForDim() => AddWaitStep(5, "Wait for dim"); + private void createFakeStoryboard() => AddStep("Enable storyboard", () => + { + player.ReplacesBackground.Value = true; + player.StoryboardEnabled.Value = true; + player.CurrentStoryboardContainer.Add(new Box + { + Alpha = 1, + Colour = Color4.Tomato + }); + }); + private void performSetup(bool allowPause = false) { createSongSelect(); @@ -344,6 +337,16 @@ namespace osu.Game.Tests.Visual { protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(Beatmap.Value); + protected override UserDimContainer CreateStoryboardContainer() + { + return new TestUserDimContainer(true) + { + RelativeSizeAxes = Axes.Both, + Alpha = 1, + EnableUserDim = { Value = true } + }; + } + public UserDimContainer CurrentStoryboardContainer => StoryboardContainer; // Whether or not the player should be allowed to load. public bool Ready; @@ -352,6 +355,10 @@ namespace osu.Game.Tests.Visual public readonly Bindable ReplacesBackground = new Bindable(); public readonly Bindable IsPaused = new Bindable(); + public bool IsStoryboardVisible() => ((TestUserDimContainer)CurrentStoryboardContainer).CurrentAlpha == 1; + + public bool IsStoryboardInvisible() => ((TestUserDimContainer)CurrentStoryboardContainer).CurrentAlpha <= 1; + [BackgroundDependencyLoader] private void load(OsuConfigManager config) { @@ -401,12 +408,16 @@ namespace osu.Game.Tests.Visual : base(beatmap) { } + } - private class TestUserDimContainer : UserDimContainer + private class TestUserDimContainer : UserDimContainer + { + public TestUserDimContainer(bool isStoryboard = false) + : base(isStoryboard) { - public Color4 CurrentColour => DimContainer.Colour; - public float CurrentAlpha => DimContainer.Alpha; } + public Color4 CurrentColour => DimContainer.Colour; + public float CurrentAlpha => DimContainer.Alpha; } } } diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 62b06b5dd1..fc57ba089d 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -89,6 +89,13 @@ namespace osu.Game.Screens.Play private DrawableStoryboard storyboard; protected UserDimContainer StoryboardContainer; + protected virtual UserDimContainer CreateStoryboardContainer() => new UserDimContainer(true) + { + RelativeSizeAxes = Axes.Both, + Alpha = 1, + EnableUserDim = { Value = true } + }; + public bool LoadedBeatmapSuccessfully => RulesetContainer?.Objects.Any() == true; [BackgroundDependencyLoader] @@ -176,12 +183,7 @@ namespace osu.Game.Screens.Play CheckCanPause = () => AllowPause && ValidForResume && !HasFailed && !RulesetContainer.HasReplayLoaded.Value, Children = new Container[] { - StoryboardContainer = new UserDimContainer(true) - { - RelativeSizeAxes = Axes.Both, - Alpha = 1, - EnableUserDim = { Value = true } - }, + StoryboardContainer = CreateStoryboardContainer(), new ScalingContainer(ScalingMode.Gameplay) { Child = new LocalSkinOverrideContainer(working.Skin)