From 14ffd9efe834d7fca72b871daa5012fa5ad5b3ef Mon Sep 17 00:00:00 2001 From: David Zhao Date: Wed, 27 Feb 2019 17:02:04 +0900 Subject: [PATCH] Add fake storyboard to visually assess storyboard dim --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 52 ++++++++++++++----- osu.Game/Screens/Play/Player.cs | 14 ++--- 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 6d7e2ea19c..fa38598e4b 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -10,6 +10,8 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.Sprites; using osu.Framework.Platform; using osu.Framework.Screens; using osu.Game.Beatmaps; @@ -27,6 +29,7 @@ using osu.Game.Screens.Play.PlayerSettings; using osu.Game.Screens.Select; using osu.Game.Tests.Resources; using osu.Game.Users; +using osuTK; using osuTK.Graphics; namespace osu.Game.Tests.Visual @@ -68,13 +71,21 @@ namespace osu.Game.Tests.Visual Dependencies.Cache(rulesets = new RulesetStore(factory)); Dependencies.Cache(manager = new BeatmapManager(LocalStorage, factory, rulesets, null, null, host, Beatmap.Default)); + Dependencies.Cache(new OsuConfigManager(LocalStorage)); Beatmap.SetDefault(); } [SetUp] - public virtual void SetUp() => - Schedule(() => { manager?.Delete(manager.GetAllUsableBeatmapSets()); }); + public virtual void SetUp() + { + Schedule(() => + { + manager.Delete(manager.GetAllUsableBeatmapSets()); + var temp = TestResources.GetTestBeatmapForImport(); + manager.Import(temp); + }); + } /// /// Check if PlayerLoader properly triggers background dim previews when a user hovers over the visual settings panel. @@ -134,9 +145,18 @@ namespace osu.Game.Tests.Visual { 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", + }); }); waitForDim(); - AddAssert("Background is invisible", () => songSelect.IsBackgroundInvisible()); + 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()); @@ -153,6 +173,11 @@ namespace osu.Game.Tests.Visual { player.ReplacesBackground.Value = true; player.StoryboardEnabled.Value = true; + player.CurrentStoryboardContainer.Add(new Box + { + Alpha = 1, + Colour = Color4.Tomato + }); }); AddUntilStep(() => { @@ -194,7 +219,7 @@ namespace osu.Game.Tests.Visual [Test] public void PauseTest() { - performSetup(); + performSetup(true); AddStep("Transition to Pause", () => { if (!player.IsPaused.Value) @@ -240,7 +265,7 @@ namespace osu.Game.Tests.Visual private void waitForDim() => AddWaitStep(5, "Wait for dim"); - private void performSetup() + private void performSetup(bool allowPause = false) { createSongSelect(); @@ -248,6 +273,7 @@ namespace osu.Game.Tests.Visual { AllowLeadIn = false, AllowResults = false, + AllowPause = allowPause, Ready = true, })); }); AddUntilStep(() => playerLoader.IsLoaded, "Wait for Player Loader to load"); @@ -259,15 +285,14 @@ namespace osu.Game.Tests.Visual { AddStep("Create new screen stack", () => Child = screenStackContainer = new ScreenStackCacheContainer { RelativeSizeAxes = Axes.Both }); AddUntilStep(() => screenStackContainer.IsLoaded,"Wait for screen stack creation"); - AddStep("create new song select", () => screenStackContainer.ScreenStack.Push(songSelect = new DummySongSelect())); + AddStep("Create new song select", () => screenStackContainer.ScreenStack.Push(songSelect = new DummySongSelect())); AddUntilStep(() => songSelect.IsLoaded, "Wait for song select to load"); - AddStep("Add map", () => + AddStep("Set user settings", () => { - var temp = TestResources.GetTestBeatmapForImport(); - manager.Import(temp); Beatmap.Value.Mods.Value = Beatmap.Value.Mods.Value.Concat(new[] { new OsuModNoFail() }); + songSelect.DimLevel.Value = 0.7f; }); - AddUntilStep(() => songSelect.Carousel.SelectedBeatmap != null, "has selection"); + AddUntilStep(() => songSelect.Carousel.SelectedBeatmap != null, "Song select has selection"); } private class DummySongSelect : PlaySongSelect @@ -280,17 +305,17 @@ namespace osu.Game.Tests.Visual } public readonly Bindable DimEnabled = new Bindable(); - private readonly Bindable dimLevel = new Bindable(); + public readonly Bindable DimLevel = new Bindable(); public new BeatmapCarousel Carousel => base.Carousel; [BackgroundDependencyLoader] private void load(OsuConfigManager config) { - config.BindWith(OsuSetting.DimLevel, dimLevel); + config.BindWith(OsuSetting.DimLevel, DimLevel); } - public bool IsBackgroundDimmed() => ((FadeAccessibleBackground)Background).CurrentColour == OsuColour.Gray(1 - (float)dimLevel.Value); + public bool IsBackgroundDimmed() => ((FadeAccessibleBackground)Background).CurrentColour == OsuColour.Gray(1 - (float)DimLevel.Value); public bool IsBackgroundUndimmed() => ((FadeAccessibleBackground)Background).CurrentColour == Color4.White; @@ -319,6 +344,7 @@ namespace osu.Game.Tests.Visual { protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(Beatmap.Value); + public UserDimContainer CurrentStoryboardContainer => StoryboardContainer; // Whether or not the player should be allowed to load. public bool Ready; diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 8caa09cc7b..62b06b5dd1 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -87,7 +87,7 @@ namespace osu.Game.Screens.Play private FailOverlay failOverlay; private DrawableStoryboard storyboard; - private UserDimContainer storyboardContainer; + protected UserDimContainer StoryboardContainer; public bool LoadedBeatmapSuccessfully => RulesetContainer?.Objects.Any() == true; @@ -176,10 +176,10 @@ namespace osu.Game.Screens.Play CheckCanPause = () => AllowPause && ValidForResume && !HasFailed && !RulesetContainer.HasReplayLoaded.Value, Children = new Container[] { - storyboardContainer = new UserDimContainer(true) + StoryboardContainer = new UserDimContainer(true) { RelativeSizeAxes = Axes.Both, - Alpha = 0, + Alpha = 1, EnableUserDim = { Value = true } }, new ScalingContainer(ScalingMode.Gameplay) @@ -355,7 +355,7 @@ namespace osu.Game.Screens.Play Background.EnableUserDim.Value = true; storyboardReplacesBackground.BindTo(Background.StoryboardReplacesBackground); - storyboardContainer.StoryboardReplacesBackground.BindTo(Background.StoryboardReplacesBackground); + StoryboardContainer.StoryboardReplacesBackground.BindTo(Background.StoryboardReplacesBackground); storyboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable; Task.Run(() => @@ -422,7 +422,7 @@ namespace osu.Game.Screens.Play private void initializeStoryboard(bool asyncLoad) { - if (storyboardContainer == null) + if (StoryboardContainer == null) return; var beatmap = Beatmap.Value; @@ -431,9 +431,9 @@ namespace osu.Game.Screens.Play storyboard.Masking = true; if (asyncLoad) - LoadComponentAsync(storyboard, storyboardContainer.Add); + LoadComponentAsync(storyboard, StoryboardContainer.Add); else - storyboardContainer.Add(storyboard); + StoryboardContainer.Add(storyboard); } protected override void UpdateBackgroundElements()