From e2a312a663da3044544ca4d1a1d6fce21bab8938 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Thu, 14 Feb 2019 17:47:53 +0900 Subject: [PATCH 01/69] Move user dimming logic into its own container --- .idea/.idea.osu/.idea/.name | 1 + .../Backgrounds/BackgroundScreenBeatmap.cs | 19 +++++-- .../UserDimmableBackgroundScreenBeatmap.cs | 57 +++++++++++++++++++ osu.Game/Screens/Play/Player.cs | 1 + .../Play/ScreenWithBeatmapBackground.cs | 6 +- 5 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 .idea/.idea.osu/.idea/.name create mode 100644 osu.Game/Screens/Backgrounds/UserDimmableBackgroundScreenBeatmap.cs diff --git a/.idea/.idea.osu/.idea/.name b/.idea/.idea.osu/.idea/.name new file mode 100644 index 0000000000..21cb4db60e --- /dev/null +++ b/.idea/.idea.osu/.idea/.name @@ -0,0 +1 @@ +osu \ No newline at end of file diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 8706cc6668..4fe0f0627e 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -2,18 +2,24 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.Allocation; +using osu.Framework.Configuration; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Textures; +using osu.Framework.Screens; using osu.Game.Beatmaps; +using osu.Game.Configuration; +using osu.Game.Graphics; using osu.Game.Graphics.Backgrounds; +using osuTK; namespace osu.Game.Screens.Backgrounds { public class BackgroundScreenBeatmap : BlurrableBackgroundScreen { - private WorkingBeatmap beatmap; + protected WorkingBeatmap beatmap; - public WorkingBeatmap Beatmap + public virtual WorkingBeatmap Beatmap { get { return beatmap; } set @@ -37,13 +43,18 @@ namespace osu.Game.Screens.Backgrounds } b.Depth = newDepth; - AddInternal(Background = b); + AddBackground(Background = b); Background.BlurSigma = BlurTarget; })); }); } } + protected virtual void AddBackground(Drawable d) + { + AddInternal(d); + } + public BackgroundScreenBeatmap(WorkingBeatmap beatmap = null) { Beatmap = beatmap; @@ -57,7 +68,7 @@ namespace osu.Game.Screens.Backgrounds return base.Equals(other) && beatmap == otherBeatmapBackground.Beatmap; } - private class BeatmapBackground : Background + protected class BeatmapBackground : Background { private readonly WorkingBeatmap beatmap; diff --git a/osu.Game/Screens/Backgrounds/UserDimmableBackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/UserDimmableBackgroundScreenBeatmap.cs new file mode 100644 index 0000000000..2902626702 --- /dev/null +++ b/osu.Game/Screens/Backgrounds/UserDimmableBackgroundScreenBeatmap.cs @@ -0,0 +1,57 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Screens; +using osu.Game.Beatmaps; +using osu.Game.Configuration; +using osu.Game.Graphics; +using osuTK; + +namespace osu.Game.Screens.Backgrounds +{ + public class UserDimmableBackgroundScreenBeatmap : BackgroundScreenBeatmap + { + protected Bindable DimLevel; + protected float BackgroundOpacity => 1 - (float)DimLevel; + private Container fadeContainer; + + [BackgroundDependencyLoader] + private void load(OsuConfigManager config) + { + DimLevel = config.GetBindable(OsuSetting.DimLevel); + fadeContainer = new Container { RelativeSizeAxes = Axes.Both}; + } + + protected override void AddBackground(Drawable d) + { + fadeContainer.Child = d; + InternalChild = fadeContainer; + } + + public override void OnEntering(IScreen last) + { + base.OnEntering(last); + DimLevel.ValueChanged += _ => updateBackgroundDim(); + updateBackgroundDim(); + } + public override void OnResuming(IScreen last) + { + base.OnResuming(last); + updateBackgroundDim(); + } + + public UserDimmableBackgroundScreenBeatmap(WorkingBeatmap beatmap = null) + :base(beatmap) + { + } + + private void updateBackgroundDim() + { + fadeContainer?.FadeColour(OsuColour.Gray(BackgroundOpacity), 800, Easing.OutQuint); + } + } +} diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 71b7b77e5d..fa9b05cd73 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -29,6 +29,7 @@ using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; using osu.Game.Scoring; +using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Ranking; using osu.Game.Skinning; using osu.Game.Storyboards.Drawables; diff --git a/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs b/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs index 93ec7347c8..698fd7d98b 100644 --- a/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs +++ b/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs @@ -14,9 +14,9 @@ namespace osu.Game.Screens.Play { public abstract class ScreenWithBeatmapBackground : OsuScreen { - protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap.Value); + protected override BackgroundScreen CreateBackground() => new UserDimmableBackgroundScreenBeatmap(Beatmap.Value); - protected new BackgroundScreenBeatmap Background => base.Background as BackgroundScreenBeatmap; + protected new UserDimmableBackgroundScreenBeatmap Background => base.Background as UserDimmableBackgroundScreenBeatmap; public override bool AllowBeatmapRulesetChange => false; @@ -43,7 +43,6 @@ namespace osu.Game.Screens.Play public override void OnEntering(IScreen last) { base.OnEntering(last); - DimLevel.ValueChanged += _ => UpdateBackgroundElements(); BlurLevel.ValueChanged += _ => UpdateBackgroundElements(); ShowStoryboard.ValueChanged += _ => UpdateBackgroundElements(); InitializeBackgroundElements(); @@ -68,7 +67,6 @@ namespace osu.Game.Screens.Play { if (!this.IsCurrentScreen()) return; - Background?.FadeColour(OsuColour.Gray(BackgroundOpacity), BACKGROUND_FADE_DURATION, Easing.OutQuint); Background?.BlurTo(new Vector2((float)BlurLevel.Value * 25), BACKGROUND_FADE_DURATION, Easing.OutQuint); } } From a09e0790e1815b8ddd4ab38af20d319aa56b31ea Mon Sep 17 00:00:00 2001 From: David Zhao Date: Thu, 14 Feb 2019 18:07:28 +0900 Subject: [PATCH 02/69] Fix storyboards not dimming --- osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs b/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs index 698fd7d98b..703a68a1c1 100644 --- a/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs +++ b/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using FFmpeg.AutoGen; using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Graphics; @@ -43,6 +44,7 @@ namespace osu.Game.Screens.Play public override void OnEntering(IScreen last) { base.OnEntering(last); + DimLevel.ValueChanged += _ => UpdateBackgroundElements(); BlurLevel.ValueChanged += _ => UpdateBackgroundElements(); ShowStoryboard.ValueChanged += _ => UpdateBackgroundElements(); InitializeBackgroundElements(); From 3a74ad678a1f3e53eb650d767687227fc2ad2f43 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Thu, 14 Feb 2019 18:41:10 +0900 Subject: [PATCH 03/69] clean up unused includes --- osu.Game/Screens/Play/Player.cs | 1 - osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs | 2 -- 2 files changed, 3 deletions(-) diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index fa9b05cd73..71b7b77e5d 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -29,7 +29,6 @@ using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; using osu.Game.Scoring; -using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Ranking; using osu.Game.Skinning; using osu.Game.Storyboards.Drawables; diff --git a/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs b/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs index 703a68a1c1..a1665a85c8 100644 --- a/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs +++ b/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs @@ -1,13 +1,11 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using FFmpeg.AutoGen; using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Screens; using osu.Game.Configuration; -using osu.Game.Graphics; using osu.Game.Screens.Backgrounds; using osuTK; From 6da9f94ae3dd9404a3c2fb8c93dd205055185174 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 15 Feb 2019 16:17:01 +0900 Subject: [PATCH 04/69] Fix regression with background dim --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 65 +++++++++++++++++++ osu.Game/Configuration/OsuConfigManager.cs | 2 +- .../Backgrounds/BackgroundScreenBeatmap.cs | 48 ++++++++++++-- .../UserDimmableBackgroundScreenBeatmap.cs | 57 ---------------- osu.Game/Screens/Play/Player.cs | 4 ++ .../Play/ScreenWithBeatmapBackground.cs | 4 +- 6 files changed, 116 insertions(+), 64 deletions(-) create mode 100644 osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs delete mode 100644 osu.Game/Screens/Backgrounds/UserDimmableBackgroundScreenBeatmap.cs diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs new file mode 100644 index 0000000000..69faf99416 --- /dev/null +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -0,0 +1,65 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using NUnit.Framework.Internal; +using osu.Framework.Allocation; +using osu.Game.Configuration; +using osu.Game.Graphics; +using osu.Game.Rulesets; +using osu.Game.Screens; +using osu.Game.Screens.Backgrounds; +using osu.Game.Screens.Play; + +namespace osu.Game.Tests.Visual +{ + public class TestCaseBackgroundScreenBeatmap : TestCasePlayer + { + + [BackgroundDependencyLoader] + private void load(OsuConfigManager manager) + { + LoadScreen(new DimAccessiblePlayer()); + } + + [Test] + public void EnableUserDimTest() + { + AddStep("Test User Dimming", () => ((DimAccessiblePlayer)Player).EnableScreenDim()); + AddAssert("Check screen dim", () => ((DimAccessiblePlayer)Player).AssertDimState()); + } + + protected override Player CreatePlayer(Ruleset ruleset) => new DimAccessiblePlayer(); + + private class DimAccessiblePlayer : Player + { + protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); + public void EnableScreenDim() + { + Background.UpdateDim.Value = true; + } + + public void DisableScreenDim() + { + Background.UpdateDim.Value = false; + } + + public bool AssertDimState() + { + return ((FadeAccessibleBackground)Background).AssertDimState(); + } + + private class FadeAccessibleBackground : BackgroundScreenBeatmap + { + public bool AssertDimState() + { + return FadeContainer.Colour == OsuColour.Gray(BackgroundOpacity); + } + } + } + } + + internal class SetupAttribute : Attribute + { + } +} diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index 613efe1801..747dc7ddeb 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -170,6 +170,6 @@ namespace osu.Game.Configuration ScalingPositionY, ScalingSizeX, ScalingSizeY, - UIScale + UIScale, } } diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 4fe0f0627e..be0d18f59e 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -18,6 +18,17 @@ namespace osu.Game.Screens.Backgrounds public class BackgroundScreenBeatmap : BlurrableBackgroundScreen { protected WorkingBeatmap beatmap; + protected Bindable DimLevel; + public Bindable UpdateDim; + + protected float BackgroundOpacity => 1 - (float)DimLevel; + protected Container FadeContainer; + + [BackgroundDependencyLoader] + private void load(OsuConfigManager config) + { + DimLevel = config.GetBindable(OsuSetting.DimLevel); + } public virtual WorkingBeatmap Beatmap { @@ -31,6 +42,7 @@ namespace osu.Game.Screens.Backgrounds Schedule(() => { + FadeContainer = new Container { RelativeSizeAxes = Axes.Both }; LoadComponentAsync(new BeatmapBackground(beatmap), b => Schedule(() => { float newDepth = 0; @@ -41,23 +53,51 @@ namespace osu.Game.Screens.Backgrounds Background.FadeOut(250); Background.Expire(); } - b.Depth = newDepth; - AddBackground(Background = b); + FadeContainer.Child = Background = b; + InternalChild = FadeContainer; Background.BlurSigma = BlurTarget; })); }); } } - protected virtual void AddBackground(Drawable d) + public override void OnEntering(IScreen last) { - AddInternal(d); + base.OnEntering(last); + DimLevel.ValueChanged += _ => updateBackgroundDim(); + UpdateDim.ValueChanged += _ => updateBackgroundDim(); + updateBackgroundDim(); + } + public override void OnResuming(IScreen last) + { + base.OnResuming(last); + updateBackgroundDim(); + } + + public override bool OnExiting(IScreen last) + { + UpdateDim.Value = false; + return base.OnExiting(last); + } + + private void updateBackgroundDim() + { + if (UpdateDim) + FadeContainer?.FadeColour(OsuColour.Gray(BackgroundOpacity), 800, Easing.OutQuint); + else + FadeContainer?.FadeColour(OsuColour.Gray(1.0f), 800, Easing.InQuint); } public BackgroundScreenBeatmap(WorkingBeatmap beatmap = null) { Beatmap = beatmap; + UpdateDim = new Bindable(); + } + + public void EnableUserDim() + { + UpdateDim.Value = true; } public override bool Equals(BackgroundScreen other) diff --git a/osu.Game/Screens/Backgrounds/UserDimmableBackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/UserDimmableBackgroundScreenBeatmap.cs deleted file mode 100644 index 2902626702..0000000000 --- a/osu.Game/Screens/Backgrounds/UserDimmableBackgroundScreenBeatmap.cs +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Framework.Allocation; -using osu.Framework.Configuration; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Screens; -using osu.Game.Beatmaps; -using osu.Game.Configuration; -using osu.Game.Graphics; -using osuTK; - -namespace osu.Game.Screens.Backgrounds -{ - public class UserDimmableBackgroundScreenBeatmap : BackgroundScreenBeatmap - { - protected Bindable DimLevel; - protected float BackgroundOpacity => 1 - (float)DimLevel; - private Container fadeContainer; - - [BackgroundDependencyLoader] - private void load(OsuConfigManager config) - { - DimLevel = config.GetBindable(OsuSetting.DimLevel); - fadeContainer = new Container { RelativeSizeAxes = Axes.Both}; - } - - protected override void AddBackground(Drawable d) - { - fadeContainer.Child = d; - InternalChild = fadeContainer; - } - - public override void OnEntering(IScreen last) - { - base.OnEntering(last); - DimLevel.ValueChanged += _ => updateBackgroundDim(); - updateBackgroundDim(); - } - public override void OnResuming(IScreen last) - { - base.OnResuming(last); - updateBackgroundDim(); - } - - public UserDimmableBackgroundScreenBeatmap(WorkingBeatmap beatmap = null) - :base(beatmap) - { - } - - private void updateBackgroundDim() - { - fadeContainer?.FadeColour(OsuColour.Gray(BackgroundOpacity), 800, Easing.OutQuint); - } - } -} diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 71b7b77e5d..819a85e88e 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -247,6 +247,8 @@ namespace osu.Game.Screens.Play foreach (var mod in Beatmap.Value.Mods.Value.OfType()) mod.ApplyToScoreProcessor(ScoreProcessor); + + Background?.EnableUserDim(); } private void applyRateFromMods() @@ -395,6 +397,8 @@ namespace osu.Game.Screens.Play if (LoadedBeatmapSuccessfully) pauseContainer?.Pause(); + Background.UpdateDim.Value = false; + return true; } diff --git a/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs b/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs index a1665a85c8..dbfce3e628 100644 --- a/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs +++ b/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs @@ -13,9 +13,9 @@ namespace osu.Game.Screens.Play { public abstract class ScreenWithBeatmapBackground : OsuScreen { - protected override BackgroundScreen CreateBackground() => new UserDimmableBackgroundScreenBeatmap(Beatmap.Value); + protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap.Value); - protected new UserDimmableBackgroundScreenBeatmap Background => base.Background as UserDimmableBackgroundScreenBeatmap; + protected new BackgroundScreenBeatmap Background => base.Background as BackgroundScreenBeatmap; public override bool AllowBeatmapRulesetChange => false; From ad9dae975dc3e98fef2084f997791383a3c128a9 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 15 Feb 2019 16:38:27 +0900 Subject: [PATCH 05/69] Add visual test for background dimming --- .idea/.idea.osu/.idea/.name | 1 - .../Visual/TestCaseBackgroundScreenBeatmap.cs | 33 ++++++++++++------- 2 files changed, 21 insertions(+), 13 deletions(-) delete mode 100644 .idea/.idea.osu/.idea/.name diff --git a/.idea/.idea.osu/.idea/.name b/.idea/.idea.osu/.idea/.name deleted file mode 100644 index 21cb4db60e..0000000000 --- a/.idea/.idea.osu/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -osu \ No newline at end of file diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 69faf99416..38c66ef2e6 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -2,7 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; -using NUnit.Framework.Internal; +using NUnit.Framework; using osu.Framework.Allocation; using osu.Game.Configuration; using osu.Game.Graphics; @@ -13,22 +13,25 @@ using osu.Game.Screens.Play; namespace osu.Game.Tests.Visual { + [TestFixture] public class TestCaseBackgroundScreenBeatmap : TestCasePlayer { - - [BackgroundDependencyLoader] - private void load(OsuConfigManager manager) - { - LoadScreen(new DimAccessiblePlayer()); - } - [Test] public void EnableUserDimTest() { AddStep("Test User Dimming", () => ((DimAccessiblePlayer)Player).EnableScreenDim()); + AddWaitStep(5, "Wait for dim"); AddAssert("Check screen dim", () => ((DimAccessiblePlayer)Player).AssertDimState()); } + [Test] + public void DisableUserDimTest() + { + AddStep("Test User Dimming", () => ((DimAccessiblePlayer)Player).DisableScreenDim()); + AddWaitStep(5, "Wait for dim"); + AddAssert("Check screen dim", () => ((DimAccessiblePlayer)Player).AssertUndimmed()); + } + protected override Player CreatePlayer(Ruleset ruleset) => new DimAccessiblePlayer(); private class DimAccessiblePlayer : Player @@ -49,17 +52,23 @@ namespace osu.Game.Tests.Visual return ((FadeAccessibleBackground)Background).AssertDimState(); } + public bool AssertUndimmed() + { + return ((FadeAccessibleBackground)Background).AssertUndimmed(); + } + private class FadeAccessibleBackground : BackgroundScreenBeatmap { public bool AssertDimState() { return FadeContainer.Colour == OsuColour.Gray(BackgroundOpacity); } + + public bool AssertUndimmed() + { + return FadeContainer.Colour == OsuColour.Gray(1.0f); + } } } } - - internal class SetupAttribute : Attribute - { - } } From 0a60f6dacdfac123210d762d173b1ebf8ccbe10e Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 15 Feb 2019 16:50:37 +0900 Subject: [PATCH 06/69] Documentation for tests and changes --- osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs | 9 ++++++--- osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 38c66ef2e6..aadc033a7c 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -1,10 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; using NUnit.Framework; -using osu.Framework.Allocation; -using osu.Game.Configuration; using osu.Game.Graphics; using osu.Game.Rulesets; using osu.Game.Screens; @@ -16,6 +13,9 @@ namespace osu.Game.Tests.Visual [TestFixture] public class TestCaseBackgroundScreenBeatmap : TestCasePlayer { + /// + /// Check if the fade container is properly being faded when screen dim is enabled. + /// [Test] public void EnableUserDimTest() { @@ -24,6 +24,9 @@ namespace osu.Game.Tests.Visual AddAssert("Check screen dim", () => ((DimAccessiblePlayer)Player).AssertDimState()); } + /// + /// Check if the fade container is properly being reset when screen dim is disabled. + /// [Test] public void DisableUserDimTest() { diff --git a/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs b/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs index dbfce3e628..9b79393092 100644 --- a/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs +++ b/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs @@ -41,6 +41,7 @@ namespace osu.Game.Screens.Play public override void OnEntering(IScreen last) { + // We need to update on dim here because player still needs to know if it needs to dim the storyboard base.OnEntering(last); DimLevel.ValueChanged += _ => UpdateBackgroundElements(); BlurLevel.ValueChanged += _ => UpdateBackgroundElements(); From 53b7fdd834717f15776710018a8f6824796f58c5 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 15 Feb 2019 16:57:53 +0900 Subject: [PATCH 07/69] Clean up test code and unused includes --- osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index be0d18f59e..9764bed971 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -11,13 +11,12 @@ using osu.Game.Beatmaps; using osu.Game.Configuration; using osu.Game.Graphics; using osu.Game.Graphics.Backgrounds; -using osuTK; namespace osu.Game.Screens.Backgrounds { public class BackgroundScreenBeatmap : BlurrableBackgroundScreen { - protected WorkingBeatmap beatmap; + private WorkingBeatmap beatmap; protected Bindable DimLevel; public Bindable UpdateDim; From fcc3cf3b7e6fd44d634ba6e43a46671a8e195b7d Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 15 Feb 2019 17:21:47 +0900 Subject: [PATCH 08/69] Remove extra comma --- osu.Game/Configuration/OsuConfigManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index 747dc7ddeb..613efe1801 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -170,6 +170,6 @@ namespace osu.Game.Configuration ScalingPositionY, ScalingSizeX, ScalingSizeY, - UIScale, + UIScale } } From 0a265c6d35ece031f0a4680b1896731b47cac026 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 18 Feb 2019 11:54:25 +0900 Subject: [PATCH 09/69] Update osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs Co-Authored-By: nyquillerium --- osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 9764bed971..90b9a129d4 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -85,7 +85,7 @@ namespace osu.Game.Screens.Backgrounds if (UpdateDim) FadeContainer?.FadeColour(OsuColour.Gray(BackgroundOpacity), 800, Easing.OutQuint); else - FadeContainer?.FadeColour(OsuColour.Gray(1.0f), 800, Easing.InQuint); + FadeContainer?.FadeColour(OsuColour.Gray(1.0f), 800, Easing.OutQuint); } public BackgroundScreenBeatmap(WorkingBeatmap beatmap = null) From df148f8787c1d743c0a4056a47111cba5a408468 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Mon, 18 Feb 2019 12:55:42 +0900 Subject: [PATCH 10/69] Fix background dim not being disabled on playerloader exit --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 1 + .../Screens/Backgrounds/BackgroundScreenBeatmap.cs | 12 +++--------- osu.Game/Screens/Play/Player.cs | 11 ++++++----- osu.Game/Screens/Play/PlayerLoader.cs | 1 + 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index aadc033a7c..a94f13b0b2 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -40,6 +40,7 @@ namespace osu.Game.Tests.Visual private class DimAccessiblePlayer : Player { protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); + public void EnableScreenDim() { Background.UpdateDim.Value = true; diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 90b9a129d4..6ea8899876 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -11,6 +11,7 @@ using osu.Game.Beatmaps; using osu.Game.Configuration; using osu.Game.Graphics; using osu.Game.Graphics.Backgrounds; +using osuTK.Graphics; namespace osu.Game.Screens.Backgrounds { @@ -20,7 +21,6 @@ namespace osu.Game.Screens.Backgrounds protected Bindable DimLevel; public Bindable UpdateDim; - protected float BackgroundOpacity => 1 - (float)DimLevel; protected Container FadeContainer; [BackgroundDependencyLoader] @@ -76,16 +76,15 @@ namespace osu.Game.Screens.Backgrounds public override bool OnExiting(IScreen last) { - UpdateDim.Value = false; return base.OnExiting(last); } private void updateBackgroundDim() { if (UpdateDim) - FadeContainer?.FadeColour(OsuColour.Gray(BackgroundOpacity), 800, Easing.OutQuint); + FadeContainer?.FadeColour(OsuColour.Gray(1 - (float)DimLevel), 800, Easing.OutQuint); else - FadeContainer?.FadeColour(OsuColour.Gray(1.0f), 800, Easing.OutQuint); + FadeContainer?.FadeColour(Color4.White, 800, Easing.OutQuint); } public BackgroundScreenBeatmap(WorkingBeatmap beatmap = null) @@ -94,11 +93,6 @@ namespace osu.Game.Screens.Backgrounds UpdateDim = new Bindable(); } - public void EnableUserDim() - { - UpdateDim.Value = true; - } - public override bool Equals(BackgroundScreen other) { var otherBeatmapBackground = other as BackgroundScreenBeatmap; diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index e2decab69c..2526b2e3ab 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -248,7 +248,7 @@ namespace osu.Game.Screens.Play foreach (var mod in Beatmap.Value.Mods.Value.OfType()) mod.ApplyToScoreProcessor(ScoreProcessor); - Background?.EnableUserDim(); + Background.UpdateDim.Value = true; } private void applyRateFromMods() @@ -298,7 +298,7 @@ namespace osu.Game.Screens.Play if (RulesetContainer.ReplayScore == null) scoreManager.Import(score, true); - this.Push(CreateResults(score)); + this.Push(CreateResults(score)); onCompletionEvent = null; }); @@ -389,15 +389,16 @@ namespace osu.Game.Screens.Play { // In the case of replays, we may have changed the playback rate. applyRateFromMods(); - + Background.UpdateDim.Value = false; fadeOut(); return base.OnExiting(next); } if (LoadedBeatmapSuccessfully) + { pauseContainer?.Pause(); - - Background.UpdateDim.Value = false; + return true; + } return true; } diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index c55c05f61c..4bb126e0e2 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -242,6 +242,7 @@ namespace osu.Game.Screens.Play content.ScaleTo(0.7f, 150, Easing.InQuint); this.FadeOut(150); cancelLoad(); + Background.UpdateDim.Value = false; return base.OnExiting(next); } From f241d67e5f79e8fea111bbf936215d7d67093804 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Mon, 18 Feb 2019 15:23:03 +0900 Subject: [PATCH 11/69] Use conditional operator isntead of if --- osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs | 5 +---- osu.Game/Screens/Play/Player.cs | 1 + osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs | 2 -- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 6ea8899876..d1c75f0e21 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -81,10 +81,7 @@ namespace osu.Game.Screens.Backgrounds private void updateBackgroundDim() { - if (UpdateDim) - FadeContainer?.FadeColour(OsuColour.Gray(1 - (float)DimLevel), 800, Easing.OutQuint); - else - FadeContainer?.FadeColour(Color4.White, 800, Easing.OutQuint); + FadeContainer?.FadeColour(UpdateDim ? OsuColour.Gray(1 - (float)DimLevel) : Color4.White, 800, Easing.OutQuint); } public BackgroundScreenBeatmap(WorkingBeatmap beatmap = null) diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 2526b2e3ab..5aed939c03 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -61,6 +61,7 @@ namespace osu.Game.Screens.Play public CursorContainer Cursor => RulesetContainer.Cursor; public bool ProvidingUserCursor => RulesetContainer?.Cursor != null && !RulesetContainer.HasReplayLoaded.Value; + protected float BackgroundOpacity => 1 - (float)DimLevel; private IAdjustableClock sourceClock; diff --git a/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs b/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs index 24d0e1a19d..f2a57b2e1d 100644 --- a/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs +++ b/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs @@ -19,8 +19,6 @@ namespace osu.Game.Screens.Play protected const float BACKGROUND_FADE_DURATION = 800; - protected float BackgroundOpacity => 1 - (float)DimLevel; - #region User Settings protected Bindable DimLevel; From 79b12ef08547048be26e71cbb0a12ff5fc9b75f9 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Mon, 18 Feb 2019 15:29:39 +0900 Subject: [PATCH 12/69] Fix test build failure --- osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index a94f13b0b2..9f50759b04 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -65,7 +65,7 @@ namespace osu.Game.Tests.Visual { public bool AssertDimState() { - return FadeContainer.Colour == OsuColour.Gray(BackgroundOpacity); + return FadeContainer.Colour == OsuColour.Gray(1 - (float)DimLevel); } public bool AssertUndimmed() From 9be25c37589c3a3a33a3e7a6cbf96700d873af8e Mon Sep 17 00:00:00 2001 From: David Zhao Date: Mon, 18 Feb 2019 16:00:59 +0900 Subject: [PATCH 13/69] Fix unit tests --- osu.Game/Screens/Play/Player.cs | 3 ++- osu.Game/Screens/Play/PlayerLoader.cs | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 5aed939c03..2281324ce3 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -249,7 +249,8 @@ namespace osu.Game.Screens.Play foreach (var mod in Beatmap.Value.Mods.Value.OfType()) mod.ApplyToScoreProcessor(ScoreProcessor); - Background.UpdateDim.Value = true; + if (Background != null) + Background.UpdateDim.Value = true; } private void applyRateFromMods() diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index 4bb126e0e2..4844883dfe 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -242,7 +242,9 @@ namespace osu.Game.Screens.Play content.ScaleTo(0.7f, 150, Easing.InQuint); this.FadeOut(150); cancelLoad(); - Background.UpdateDim.Value = false; + + if (Background != null) + Background.UpdateDim.Value = false; return base.OnExiting(next); } From 80800f29314ba5c8abd1d540646534578c6dd24c Mon Sep 17 00:00:00 2001 From: David Zhao Date: Mon, 18 Feb 2019 16:34:11 +0900 Subject: [PATCH 14/69] Match up fade behavior with current master --- osu.Game/Screens/Play/Player.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 2281324ce3..a022088d18 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -248,9 +248,6 @@ namespace osu.Game.Screens.Play foreach (var mod in Beatmap.Value.Mods.Value.OfType()) mod.ApplyToScoreProcessor(ScoreProcessor); - - if (Background != null) - Background.UpdateDim.Value = true; } private void applyRateFromMods() @@ -302,6 +299,8 @@ namespace osu.Game.Screens.Play this.Push(CreateResults(score)); + Background.UpdateDim.Value = false; + onCompletionEvent = null; }); } @@ -349,6 +348,8 @@ namespace osu.Game.Screens.Play .Delay(250) .FadeIn(250); + Background.UpdateDim.Value = true; + Task.Run(() => { sourceClock.Reset(); @@ -391,7 +392,6 @@ namespace osu.Game.Screens.Play { // In the case of replays, we may have changed the playback rate. applyRateFromMods(); - Background.UpdateDim.Value = false; fadeOut(); return base.OnExiting(next); } @@ -409,7 +409,7 @@ namespace osu.Game.Screens.Play { float fadeOutDuration = instant ? 0 : 250; this.FadeOut(fadeOutDuration); - Background?.FadeColour(Color4.White, fadeOutDuration, Easing.OutQuint); + Background.UpdateDim.Value = false; } protected override bool OnScroll(ScrollEvent e) => mouseWheelDisabled.Value && !pauseContainer.IsPaused; From 1d80674fbd04a3d5f4795644bb3150e32f8bddde Mon Sep 17 00:00:00 2001 From: David Zhao Date: Mon, 18 Feb 2019 17:11:38 +0900 Subject: [PATCH 15/69] Fix fadecontainer being added to multiple containers --- osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index d1c75f0e21..8b717f68d1 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -54,9 +54,9 @@ namespace osu.Game.Screens.Backgrounds } b.Depth = newDepth; FadeContainer.Child = Background = b; - InternalChild = FadeContainer; Background.BlurSigma = BlurTarget; })); + AddInternal(FadeContainer); }); } } From 4e07aba54852715882b3f5b53f5a5f1e96f78d61 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Mon, 18 Feb 2019 18:12:45 +0900 Subject: [PATCH 16/69] Make it so visual tests only load the osu ruleset --- osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs | 5 +++++ osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 9f50759b04..1c318ffbfe 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -4,6 +4,7 @@ using NUnit.Framework; using osu.Game.Graphics; using osu.Game.Rulesets; +using osu.Game.Rulesets.Osu; using osu.Game.Screens; using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Play; @@ -13,6 +14,10 @@ namespace osu.Game.Tests.Visual [TestFixture] public class TestCaseBackgroundScreenBeatmap : TestCasePlayer { + public TestCaseBackgroundScreenBeatmap() : base(new OsuRuleset()) + { + } + /// /// Check if the fade container is properly being faded when screen dim is enabled. /// diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 8b717f68d1..312d760410 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -56,7 +56,8 @@ namespace osu.Game.Screens.Backgrounds FadeContainer.Child = Background = b; Background.BlurSigma = BlurTarget; })); - AddInternal(FadeContainer); + InternalChild = FadeContainer; + updateBackgroundDim(); }); } } From b353b6958763207cb95ea997319d4ac26e3c9c67 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Mon, 18 Feb 2019 18:58:34 +0900 Subject: [PATCH 17/69] Use a bindable for updating dim status instead --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 1c318ffbfe..1a41bff84c 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -2,9 +2,11 @@ // See the LICENCE file in the repository root for full licence text. using NUnit.Framework; +using osu.Framework.Configuration; using osu.Game.Graphics; using osu.Game.Rulesets; using osu.Game.Rulesets.Osu; +using osu.Game.Scoring; using osu.Game.Screens; using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Play; @@ -18,13 +20,19 @@ namespace osu.Game.Tests.Visual { } + [SetUp] + public void Setup() + { + ((DimAccessiblePlayer)Player).UpdateBindables(); + } + /// /// Check if the fade container is properly being faded when screen dim is enabled. /// [Test] public void EnableUserDimTest() { - AddStep("Test User Dimming", () => ((DimAccessiblePlayer)Player).EnableScreenDim()); + AddStep("Test User Dimming", () => ((DimAccessiblePlayer)Player).DimEnabled.Value = true); AddWaitStep(5, "Wait for dim"); AddAssert("Check screen dim", () => ((DimAccessiblePlayer)Player).AssertDimState()); } @@ -35,7 +43,7 @@ namespace osu.Game.Tests.Visual [Test] public void DisableUserDimTest() { - AddStep("Test User Dimming", () => ((DimAccessiblePlayer)Player).DisableScreenDim()); + AddStep("Test User Undimming", () => ((DimAccessiblePlayer)Player).DimEnabled.Value = false); AddWaitStep(5, "Wait for dim"); AddAssert("Check screen dim", () => ((DimAccessiblePlayer)Player).AssertUndimmed()); } @@ -44,16 +52,13 @@ namespace osu.Game.Tests.Visual private class DimAccessiblePlayer : Player { + public Bindable DimEnabled; + protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); - public void EnableScreenDim() + public void UpdateBindables() { - Background.UpdateDim.Value = true; - } - - public void DisableScreenDim() - { - Background.UpdateDim.Value = false; + DimEnabled = Background.UpdateDim; } public bool AssertDimState() From af049004dde44028843f366af51d83e75c3e4ed4 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Mon, 18 Feb 2019 19:53:55 +0900 Subject: [PATCH 18/69] Add test cases for transitioning into pause overlay and into results --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 81 ++++++++++++++----- osu.Game/Screens/Play/Player.cs | 2 - 2 files changed, 60 insertions(+), 23 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 1a41bff84c..dc078aeeea 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -10,6 +10,9 @@ using osu.Game.Scoring; using osu.Game.Screens; using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Play; +using osu.Game.Screens.Select; +using osu.Game.Users; +using osuTK.Graphics; namespace osu.Game.Tests.Visual { @@ -26,17 +29,6 @@ namespace osu.Game.Tests.Visual ((DimAccessiblePlayer)Player).UpdateBindables(); } - /// - /// Check if the fade container is properly being faded when screen dim is enabled. - /// - [Test] - public void EnableUserDimTest() - { - AddStep("Test User Dimming", () => ((DimAccessiblePlayer)Player).DimEnabled.Value = true); - AddWaitStep(5, "Wait for dim"); - AddAssert("Check screen dim", () => ((DimAccessiblePlayer)Player).AssertDimState()); - } - /// /// Check if the fade container is properly being reset when screen dim is disabled. /// @@ -45,11 +37,53 @@ namespace osu.Game.Tests.Visual { AddStep("Test User Undimming", () => ((DimAccessiblePlayer)Player).DimEnabled.Value = false); AddWaitStep(5, "Wait for dim"); - AddAssert("Check screen dim", () => ((DimAccessiblePlayer)Player).AssertUndimmed()); + AddAssert("Screen is undimmed", () => ((DimAccessiblePlayer)Player).AssertUndimmed()); + } + + /// + /// Check if the fade container is properly being faded when screen dim is enabled. + /// + [Test] + public void EnableUserDimTest() + { + AddStep("Test User Dimming", () => ((DimAccessiblePlayer)Player).DimEnabled.Value = true); + AddWaitStep(5, "Wait for dim"); + AddAssert("Screen is dimmed", () => ((DimAccessiblePlayer)Player).AssertDimState()); + } + + /// + /// Check if the fade container retains dim when pausing + /// + [Test] + public void PauseTest() + { + AddStep("Transition to Results", () => ((DimAccessiblePlayer)Player).TriggerExit()); + AddWaitStep(5, "Wait for dim"); + AddAssert("Screen is dimmed", () => ((DimAccessiblePlayer)Player).AssertDimState()); + } + + /// + /// Check if the fade container removes user dim when leaving the player + /// + [Test] + public void TransitionTest() + { + AddStep("Transition to Results", () => LoadScreen(new FadeAccesibleResults(new ScoreInfo { User = new User { Username = "osu!" }}))); + AddWaitStep(5, "Wait for dim"); + AddAssert("Screen is undimmed", () => ((DimAccessiblePlayer)Player).AssertUndimmed()); } protected override Player CreatePlayer(Ruleset ruleset) => new DimAccessiblePlayer(); + private class FadeAccesibleResults : SoloResults + { + public FadeAccesibleResults(ScoreInfo score) : base(score) + { + } + + protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); + } + private class DimAccessiblePlayer : Player { public Bindable DimEnabled; @@ -71,17 +105,22 @@ namespace osu.Game.Tests.Visual return ((FadeAccessibleBackground)Background).AssertUndimmed(); } - private class FadeAccessibleBackground : BackgroundScreenBeatmap + public void TriggerExit() { - public bool AssertDimState() - { - return FadeContainer.Colour == OsuColour.Gray(1 - (float)DimLevel); - } + OnExiting(new PlaySongSelect()); + } + } - public bool AssertUndimmed() - { - return FadeContainer.Colour == OsuColour.Gray(1.0f); - } + private class FadeAccessibleBackground : BackgroundScreenBeatmap + { + public bool AssertDimState() + { + return FadeContainer.Colour == OsuColour.Gray(1 - (float)DimLevel); + } + + public bool AssertUndimmed() + { + return FadeContainer.Colour == Color4.White; } } } diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index a022088d18..2c0172b272 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -299,8 +299,6 @@ namespace osu.Game.Screens.Play this.Push(CreateResults(score)); - Background.UpdateDim.Value = false; - onCompletionEvent = null; }); } From 2e375a918656886726b457cddd31c80f8deec720 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Tue, 19 Feb 2019 19:44:26 +0900 Subject: [PATCH 19/69] Add test cases for upwards traversal of screen stack --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 95 ++++++++++++++----- 1 file changed, 71 insertions(+), 24 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index dc078aeeea..53695b1247 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -3,30 +3,64 @@ using NUnit.Framework; using osu.Framework.Configuration; +using osu.Framework.Screens; +using osu.Game.Beatmaps; using osu.Game.Graphics; -using osu.Game.Rulesets; -using osu.Game.Rulesets.Osu; +using osu.Game.Rulesets.Osu.Objects; using osu.Game.Scoring; using osu.Game.Screens; using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Play; -using osu.Game.Screens.Select; +using osu.Game.Tests.Beatmaps; using osu.Game.Users; +using osuTK; using osuTK.Graphics; namespace osu.Game.Tests.Visual { [TestFixture] - public class TestCaseBackgroundScreenBeatmap : TestCasePlayer + public class TestCaseBackgroundScreenBeatmap : ScreenTestCase { - public TestCaseBackgroundScreenBeatmap() : base(new OsuRuleset()) + private DummySongSelect songSelect; + protected Player Player; + public TestCaseBackgroundScreenBeatmap() { - } + AddStep("Load Song Select", () => + { + LoadComponentAsync(new DummySongSelect(), p => + { + songSelect = p; + LoadScreen(p); + }); + }); + AddUntilStep(() => songSelect?.IsLoaded ?? false, "Wait for song select to load"); + AddStep("Create beatmap", () => + { + Beatmap.Value = new TestWorkingBeatmap(new Beatmap + { + HitObjects = + { + new HitCircle() + { + StartTime = 3000, + Position = new Vector2(0, 0), + }, + new HitCircle() + { + StartTime = 15000, + Position = new Vector2(0, 0), + } + }, + }); + }); + AddStep("Load Player", () => + { + var p = new DimAccessiblePlayer(); + songSelect.Push(Player = p); + }); - [SetUp] - public void Setup() - { - ((DimAccessiblePlayer)Player).UpdateBindables(); + AddUntilStep(() => Player?.IsLoaded ?? false, "Wait for player to load"); + AddStep("Update bindables", () => ((DimAccessiblePlayer)Player).UpdateBindables()); } /// @@ -48,7 +82,7 @@ namespace osu.Game.Tests.Visual { AddStep("Test User Dimming", () => ((DimAccessiblePlayer)Player).DimEnabled.Value = true); AddWaitStep(5, "Wait for dim"); - AddAssert("Screen is dimmed", () => ((DimAccessiblePlayer)Player).AssertDimState()); + AddAssert("Screen is dimmed", () => ((DimAccessiblePlayer)Player).AssertDimmed()); } /// @@ -57,23 +91,41 @@ namespace osu.Game.Tests.Visual [Test] public void PauseTest() { - AddStep("Transition to Results", () => ((DimAccessiblePlayer)Player).TriggerExit()); + AddStep("Transition to Pause", () => ((DimAccessiblePlayer)Player).Exit()); AddWaitStep(5, "Wait for dim"); - AddAssert("Screen is dimmed", () => ((DimAccessiblePlayer)Player).AssertDimState()); + AddAssert("Screen is dimmed", () => ((DimAccessiblePlayer)Player).AssertDimmed()); } /// - /// Check if the fade container removes user dim when leaving the player + /// Check if the fade container removes user dim when suspending player for results /// [Test] public void TransitionTest() { - AddStep("Transition to Results", () => LoadScreen(new FadeAccesibleResults(new ScoreInfo { User = new User { Username = "osu!" }}))); + AddStep("Transition to Results", () => Player.Push(new FadeAccesibleResults(new ScoreInfo { User = new User { Username = "osu!" }}))); AddWaitStep(5, "Wait for dim"); AddAssert("Screen is undimmed", () => ((DimAccessiblePlayer)Player).AssertUndimmed()); } - protected override Player CreatePlayer(Ruleset ruleset) => new DimAccessiblePlayer(); + /// + /// Check if background gets undimmed when leaving the player for the previous screen + /// + [Test] + public void TransitionOutTest() + { + AddStep("Exit player", () => + { + Player.MakeCurrent(); + Player.Exit(); + }); + AddWaitStep(5, "Wait for dim"); + AddAssert("Screen is undimmed", () => ((DimAccessiblePlayer)Player).AssertUndimmed()); + } + + private class DummySongSelect : OsuScreen + { + protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); + } private class FadeAccesibleResults : SoloResults { @@ -95,25 +147,20 @@ namespace osu.Game.Tests.Visual DimEnabled = Background.UpdateDim; } - public bool AssertDimState() + public bool AssertDimmed() { - return ((FadeAccessibleBackground)Background).AssertDimState(); + return ((FadeAccessibleBackground)Background).AssertDimmed(); } public bool AssertUndimmed() { return ((FadeAccessibleBackground)Background).AssertUndimmed(); } - - public void TriggerExit() - { - OnExiting(new PlaySongSelect()); - } } private class FadeAccessibleBackground : BackgroundScreenBeatmap { - public bool AssertDimState() + public bool AssertDimmed() { return FadeContainer.Colour == OsuColour.Gray(1 - (float)DimLevel); } From 87717dcf9eade431480d8b3f9800b896fcc68e52 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Tue, 19 Feb 2019 19:57:55 +0900 Subject: [PATCH 20/69] Remove redundant constructors --- osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 53695b1247..89b9088681 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -40,12 +40,12 @@ namespace osu.Game.Tests.Visual { HitObjects = { - new HitCircle() + new HitCircle { StartTime = 3000, Position = new Vector2(0, 0), }, - new HitCircle() + new HitCircle { StartTime = 15000, Position = new Vector2(0, 0), From 1bd1b6b0997ad3a9851cbb7fbbc4c5c56d2cfeab Mon Sep 17 00:00:00 2001 From: David Zhao Date: Wed, 20 Feb 2019 16:53:57 +0900 Subject: [PATCH 21/69] Move user dim logic into UserDimContainer instead --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 2 +- .../Graphics/Containers/UserDimContainer.cs | 36 +++++++++++++++++++ .../Backgrounds/BackgroundScreenBeatmap.cs | 36 +++++-------------- osu.Game/Screens/Play/Player.cs | 18 +++++----- osu.Game/Screens/Play/PlayerLoader.cs | 3 -- 5 files changed, 53 insertions(+), 42 deletions(-) create mode 100644 osu.Game/Graphics/Containers/UserDimContainer.cs diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 89b9088681..1cc89da3b7 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -144,7 +144,7 @@ namespace osu.Game.Tests.Visual public void UpdateBindables() { - DimEnabled = Background.UpdateDim; + DimEnabled = Background.UpdateUserDim; } public bool AssertDimmed() diff --git a/osu.Game/Graphics/Containers/UserDimContainer.cs b/osu.Game/Graphics/Containers/UserDimContainer.cs new file mode 100644 index 0000000000..4b4faae253 --- /dev/null +++ b/osu.Game/Graphics/Containers/UserDimContainer.cs @@ -0,0 +1,36 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Configuration; +using osuTK.Graphics; + +namespace osu.Game.Graphics.Containers +{ + public class UserDimContainer : Container + { + #region User Settings + + protected Bindable DimLevel; + + #endregion + + public Bindable EnableUserDim = new Bindable(); + + [BackgroundDependencyLoader] + private void load(OsuConfigManager config) + { + DimLevel = config.GetBindable(OsuSetting.DimLevel); + EnableUserDim.ValueChanged += _ => updateBackgroundDim(); + DimLevel.ValueChanged += _ => updateBackgroundDim(); + } + + private void updateBackgroundDim() + { + this.FadeColour(EnableUserDim ? OsuColour.Gray(1 - (float)DimLevel) : Color4.White, 800, Easing.OutQuint); + } + } +} diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 312d760410..23fa6b6b6f 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -11,6 +11,9 @@ using osu.Game.Beatmaps; using osu.Game.Configuration; using osu.Game.Graphics; using osu.Game.Graphics.Backgrounds; +using osu.Game.Graphics.Containers; +using osu.Game.Users; +using osuTK; using osuTK.Graphics; namespace osu.Game.Screens.Backgrounds @@ -19,9 +22,10 @@ namespace osu.Game.Screens.Backgrounds { private WorkingBeatmap beatmap; protected Bindable DimLevel; - public Bindable UpdateDim; + protected Bindable BlurLevel; + public Bindable EnableUserDim; - protected Container FadeContainer; + protected UserDimContainer FadeContainer; [BackgroundDependencyLoader] private void load(OsuConfigManager config) @@ -41,7 +45,7 @@ namespace osu.Game.Screens.Backgrounds Schedule(() => { - FadeContainer = new Container { RelativeSizeAxes = Axes.Both }; + FadeContainer = new UserDimContainer { RelativeSizeAxes = Axes.Both }; LoadComponentAsync(new BeatmapBackground(beatmap), b => Schedule(() => { float newDepth = 0; @@ -57,38 +61,14 @@ namespace osu.Game.Screens.Backgrounds Background.BlurSigma = BlurTarget; })); InternalChild = FadeContainer; - updateBackgroundDim(); + EnableUserDim = FadeContainer.EnableUserDim; }); } } - public override void OnEntering(IScreen last) - { - base.OnEntering(last); - DimLevel.ValueChanged += _ => updateBackgroundDim(); - UpdateDim.ValueChanged += _ => updateBackgroundDim(); - updateBackgroundDim(); - } - public override void OnResuming(IScreen last) - { - base.OnResuming(last); - updateBackgroundDim(); - } - - public override bool OnExiting(IScreen last) - { - return base.OnExiting(last); - } - - private void updateBackgroundDim() - { - FadeContainer?.FadeColour(UpdateDim ? OsuColour.Gray(1 - (float)DimLevel) : Color4.White, 800, Easing.OutQuint); - } - public BackgroundScreenBeatmap(WorkingBeatmap beatmap = null) { Beatmap = beatmap; - UpdateDim = new Bindable(); } public override bool Equals(BackgroundScreen other) diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 2c0172b272..3826271a7e 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -19,7 +19,6 @@ using osu.Framework.Threading; using osu.Framework.Timing; using osu.Game.Beatmaps; using osu.Game.Configuration; -using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Cursor; using osu.Game.Online.API; @@ -61,7 +60,6 @@ namespace osu.Game.Screens.Play public CursorContainer Cursor => RulesetContainer.Cursor; public bool ProvidingUserCursor => RulesetContainer?.Cursor != null && !RulesetContainer.HasReplayLoaded.Value; - protected float BackgroundOpacity => 1 - (float)DimLevel; private IAdjustableClock sourceClock; @@ -88,7 +86,7 @@ namespace osu.Game.Screens.Play private FailOverlay failOverlay; private DrawableStoryboard storyboard; - private Container storyboardContainer; + private UserDimContainer storyboardContainer; public bool LoadedBeatmapSuccessfully => RulesetContainer?.Objects.Any() == true; @@ -175,9 +173,9 @@ namespace osu.Game.Screens.Play OnRetry = Restart, OnQuit = performUserRequestedExit, CheckCanPause = () => AllowPause && ValidForResume && !HasFailed && !RulesetContainer.HasReplayLoaded, - Children = new[] + Children = new Container[] { - storyboardContainer = new Container + storyboardContainer = new UserDimContainer { RelativeSizeAxes = Axes.Both, Alpha = 0, @@ -242,6 +240,8 @@ namespace osu.Game.Screens.Play if (ShowStoryboard) initializeStoryboard(false); + storyboardContainer.EnableUserDim.Value = true; + // Bind ScoreProcessor to ourselves ScoreProcessor.AllJudged += onCompletion; ScoreProcessor.Failed += onFail; @@ -346,7 +346,7 @@ namespace osu.Game.Screens.Play .Delay(250) .FadeIn(250); - Background.UpdateDim.Value = true; + Background.EnableUserDim.Value = true; Task.Run(() => { @@ -407,7 +407,7 @@ namespace osu.Game.Screens.Play { float fadeOutDuration = instant ? 0 : 250; this.FadeOut(fadeOutDuration); - Background.UpdateDim.Value = false; + Background.EnableUserDim.Value = false; } protected override bool OnScroll(ScrollEvent e) => mouseWheelDisabled.Value && !pauseContainer.IsPaused; @@ -440,9 +440,7 @@ namespace osu.Game.Screens.Play var beatmap = Beatmap.Value; var storyboardVisible = ShowStoryboard && beatmap.Storyboard.HasDrawable; - storyboardContainer? - .FadeColour(OsuColour.Gray(BackgroundOpacity), BACKGROUND_FADE_DURATION, Easing.OutQuint) - .FadeTo(storyboardVisible && BackgroundOpacity > 0 ? 1 : 0, BACKGROUND_FADE_DURATION, Easing.OutQuint); + storyboardContainer?.FadeTo(storyboardVisible && 1 - (float)DimLevel > 0 ? 1 : 0, BACKGROUND_FADE_DURATION, Easing.OutQuint); if (storyboardVisible && beatmap.Storyboard.ReplacesBackground) Background?.FadeColour(Color4.Black, BACKGROUND_FADE_DURATION, Easing.OutQuint); diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index 4844883dfe..c55c05f61c 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -243,9 +243,6 @@ namespace osu.Game.Screens.Play this.FadeOut(150); cancelLoad(); - if (Background != null) - Background.UpdateDim.Value = false; - return base.OnExiting(next); } From 5bf405f9496695f35268be2856112855b450fa57 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Wed, 20 Feb 2019 16:56:57 +0900 Subject: [PATCH 22/69] Fix bindable name in tests --- osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 1cc89da3b7..9e981952a9 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -144,7 +144,7 @@ namespace osu.Game.Tests.Visual public void UpdateBindables() { - DimEnabled = Background.UpdateUserDim; + DimEnabled = Background.EnableUserDim; } public bool AssertDimmed() From 3f000dfe2ef656cea11bc53942ebd8cd28231a72 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Wed, 20 Feb 2019 16:58:12 +0900 Subject: [PATCH 23/69] Remove unnecessary region --- osu.Game/Graphics/Containers/UserDimContainer.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/osu.Game/Graphics/Containers/UserDimContainer.cs b/osu.Game/Graphics/Containers/UserDimContainer.cs index 4b4faae253..717078ab99 100644 --- a/osu.Game/Graphics/Containers/UserDimContainer.cs +++ b/osu.Game/Graphics/Containers/UserDimContainer.cs @@ -12,12 +12,8 @@ namespace osu.Game.Graphics.Containers { public class UserDimContainer : Container { - #region User Settings - protected Bindable DimLevel; - #endregion - public Bindable EnableUserDim = new Bindable(); [BackgroundDependencyLoader] From d703a9511a9d523cb0c2e80c3417a3253e757b3a Mon Sep 17 00:00:00 2001 From: David Zhao Date: Wed, 20 Feb 2019 17:20:45 +0900 Subject: [PATCH 24/69] Fix background dim previews --- osu.Game/Screens/Play/PlayerLoader.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index c55c05f61c..c8149cefef 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -161,6 +161,8 @@ namespace osu.Game.Screens.Play { // restore our screen defaults InitializeBackgroundElements(); + if (this.IsCurrentScreen()) + Background.EnableUserDim.Value = false; return base.OnHover(e); } @@ -170,6 +172,8 @@ namespace osu.Game.Screens.Play { // show user setting preview UpdateBackgroundElements(); + if (this.IsCurrentScreen()) + Background.EnableUserDim.Value = true; } base.OnHoverLost(e); @@ -243,6 +247,8 @@ namespace osu.Game.Screens.Play this.FadeOut(150); cancelLoad(); + Background.EnableUserDim.Value = false; + return base.OnExiting(next); } From 25e7dcb3755cc9c7d0ce5be6ede5da9c455f1427 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Wed, 20 Feb 2019 17:39:35 +0900 Subject: [PATCH 25/69] Remove unused includes --- osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 23fa6b6b6f..1596e26ce5 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -4,17 +4,11 @@ using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Textures; -using osu.Framework.Screens; using osu.Game.Beatmaps; using osu.Game.Configuration; -using osu.Game.Graphics; using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Containers; -using osu.Game.Users; -using osuTK; -using osuTK.Graphics; namespace osu.Game.Screens.Backgrounds { From ad5e81f0cdb273c8a6ffd2d9d879339bfeb89cc5 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Thu, 21 Feb 2019 15:24:26 +0900 Subject: [PATCH 26/69] Add test case for background preview, fix unit tests --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 106 +++++++++++++----- .../Backgrounds/BackgroundScreenBeatmap.cs | 7 +- osu.Game/Screens/Play/Player.cs | 4 + osu.Game/Screens/Play/PlayerLoader.cs | 11 +- .../Play/ScreenWithBeatmapBackground.cs | 3 - 5 files changed, 93 insertions(+), 38 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 9e981952a9..9d7c1de780 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -1,8 +1,11 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Threading; using NUnit.Framework; +using osu.Framework.Allocation; using osu.Framework.Configuration; +using osu.Framework.Graphics; using osu.Framework.Screens; using osu.Game.Beatmaps; using osu.Game.Graphics; @@ -11,6 +14,7 @@ using osu.Game.Scoring; using osu.Game.Screens; using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Play; +using osu.Game.Screens.Play.PlayerSettings; using osu.Game.Tests.Beatmaps; using osu.Game.Users; using osuTK; @@ -19,20 +23,30 @@ using osuTK.Graphics; namespace osu.Game.Tests.Visual { [TestFixture] - public class TestCaseBackgroundScreenBeatmap : ScreenTestCase + public class TestCaseBackgroundScreenBeatmap : ManualInputManagerTestCase { private DummySongSelect songSelect; - protected Player Player; + private DimAccessiblePlayerLoader playerLoader; + private DimAccessiblePlayer player; + + [Cached] + private BackgroundScreenStack backgroundStack; + public TestCaseBackgroundScreenBeatmap() { + ScreenStack screen; + InputManager.Add(backgroundStack = new BackgroundScreenStack {RelativeSizeAxes = Axes.Both}); + InputManager.Add(screen = new ScreenStack { RelativeSizeAxes = Axes.Both }); + AddStep("Load Song Select", () => { LoadComponentAsync(new DummySongSelect(), p => { songSelect = p; - LoadScreen(p); + screen.Push(p); }); }); + AddUntilStep(() => songSelect?.IsLoaded ?? false, "Wait for song select to load"); AddStep("Create beatmap", () => { @@ -53,14 +67,30 @@ namespace osu.Game.Tests.Visual }, }); }); - AddStep("Load Player", () => + + AddStep("Start player loader", () => songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer()))); + AddUntilStep(() => playerLoader?.IsLoaded ?? false, "Wait for Player Loader to load"); + AddStep("Update bindables", () => playerLoader.UpdateBindables()); + AddStep("Trigger background preview", () => { - var p = new DimAccessiblePlayer(); - songSelect.Push(Player = p); + InputManager.MoveMouseTo(playerLoader.ScreenPos); + InputManager.MoveMouseTo(playerLoader.VisualSettingsPos); }); - AddUntilStep(() => Player?.IsLoaded ?? false, "Wait for player to load"); - AddStep("Update bindables", () => ((DimAccessiblePlayer)Player).UpdateBindables()); + AddWaitStep(5, "Wait for dim"); + AddAssert("Screen is dimmed", () => songSelect.AssertDimmed()); + + AddStep("Allow beatmap to load", () => + { + player.Ready = true; + InputManager.MoveMouseTo(playerLoader.ScreenPos); + }); + + // In the case of a user triggering the dim preview the instant player gets loaded, the user dim needs to be applied when the map starts. + AddUntilStep(() => player?.IsLoaded ?? false, "Wait for player to load"); + AddStep("Trigger background preview when loaded", () => InputManager.MoveMouseTo(playerLoader.VisualSettingsPos)); + AddWaitStep(5, "Wait for dim"); + AddAssert("Screen is dimmed", () => songSelect.AssertDimmed()); } /// @@ -69,9 +99,9 @@ namespace osu.Game.Tests.Visual [Test] public void DisableUserDimTest() { - AddStep("Test User Undimming", () => ((DimAccessiblePlayer)Player).DimEnabled.Value = false); + AddStep("Test User Undimming", () => playerLoader.DimEnabled.Value = false); AddWaitStep(5, "Wait for dim"); - AddAssert("Screen is undimmed", () => ((DimAccessiblePlayer)Player).AssertUndimmed()); + AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed()); } /// @@ -80,9 +110,9 @@ namespace osu.Game.Tests.Visual [Test] public void EnableUserDimTest() { - AddStep("Test User Dimming", () => ((DimAccessiblePlayer)Player).DimEnabled.Value = true); + AddStep("Test User Dimming", () => playerLoader.DimEnabled.Value = true); AddWaitStep(5, "Wait for dim"); - AddAssert("Screen is dimmed", () => ((DimAccessiblePlayer)Player).AssertDimmed()); + AddAssert("Screen is dimmed", () => songSelect.AssertDimmed()); } /// @@ -91,9 +121,9 @@ namespace osu.Game.Tests.Visual [Test] public void PauseTest() { - AddStep("Transition to Pause", () => ((DimAccessiblePlayer)Player).Exit()); + AddStep("Transition to Pause", () => player.Exit()); AddWaitStep(5, "Wait for dim"); - AddAssert("Screen is dimmed", () => ((DimAccessiblePlayer)Player).AssertDimmed()); + AddAssert("Screen is dimmed", () => songSelect.AssertDimmed()); } /// @@ -102,9 +132,9 @@ namespace osu.Game.Tests.Visual [Test] public void TransitionTest() { - AddStep("Transition to Results", () => Player.Push(new FadeAccesibleResults(new ScoreInfo { User = new User { Username = "osu!" }}))); + AddStep("Transition to Results", () => player.Push(new FadeAccesibleResults(new ScoreInfo { User = new User { Username = "osu!" }}))); AddWaitStep(5, "Wait for dim"); - AddAssert("Screen is undimmed", () => ((DimAccessiblePlayer)Player).AssertUndimmed()); + AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed()); } /// @@ -115,16 +145,28 @@ namespace osu.Game.Tests.Visual { AddStep("Exit player", () => { - Player.MakeCurrent(); - Player.Exit(); + player.MakeCurrent(); + player.Exit(); }); AddWaitStep(5, "Wait for dim"); - AddAssert("Screen is undimmed", () => ((DimAccessiblePlayer)Player).AssertUndimmed()); + AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed()); } private class DummySongSelect : OsuScreen { protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); + + public bool BackgroundLoaded => Background?.IsLoaded ?? false; + + public bool AssertDimmed() + { + return ((FadeAccessibleBackground)Background).AssertDimmed(); + } + + public bool AssertUndimmed() + { + return ((FadeAccessibleBackground)Background).AssertUndimmed(); + } } private class FadeAccesibleResults : SoloResults @@ -137,25 +179,35 @@ namespace osu.Game.Tests.Visual } private class DimAccessiblePlayer : Player + { + protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); + + public bool Ready; + + [BackgroundDependencyLoader] + private void load() + { + while (!Ready) + Thread.Sleep(1); + } + } + + private class DimAccessiblePlayerLoader : PlayerLoader { public Bindable DimEnabled; - protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); + public VisualSettings VisualSettingsPos => VisualSettings; + public Vector2 ScreenPos => VisualSettings.ScreenSpaceDrawQuad.BottomLeft - new Vector2(20, 20); public void UpdateBindables() { DimEnabled = Background.EnableUserDim; } - public bool AssertDimmed() + public DimAccessiblePlayerLoader(Player player) : base(() => player) { - return ((FadeAccessibleBackground)Background).AssertDimmed(); - } - - public bool AssertUndimmed() - { - return ((FadeAccessibleBackground)Background).AssertUndimmed(); } + protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); } private class FadeAccessibleBackground : BackgroundScreenBeatmap diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 1596e26ce5..2bbaee417e 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -37,9 +37,12 @@ namespace osu.Game.Screens.Backgrounds beatmap = value; + FadeContainer = new UserDimContainer { RelativeSizeAxes = Axes.Both }; + InternalChild = FadeContainer; + EnableUserDim = FadeContainer.EnableUserDim; + Schedule(() => { - FadeContainer = new UserDimContainer { RelativeSizeAxes = Axes.Both }; LoadComponentAsync(new BeatmapBackground(beatmap), b => Schedule(() => { float newDepth = 0; @@ -54,8 +57,6 @@ namespace osu.Game.Screens.Backgrounds FadeContainer.Child = Background = b; Background.BlurSigma = BlurTarget; })); - InternalChild = FadeContainer; - EnableUserDim = FadeContainer.EnableUserDim; }); } } diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 3826271a7e..3f9f1a83d5 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -346,6 +346,10 @@ namespace osu.Game.Screens.Play .Delay(250) .FadeIn(250); + // We need to update background elements when the user dim gets updated + // The storyboard needs to know whether or not to completely fade at 100% dim + DimLevel.ValueChanged += _ => UpdateBackgroundElements(); + ShowStoryboard.ValueChanged += _ => UpdateBackgroundElements(); Background.EnableUserDim.Value = true; Task.Run(() => diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index c8149cefef..5f3688475d 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -78,7 +78,7 @@ namespace osu.Game.Screens.Play Margin = new MarginPadding(25), Children = new PlayerSettingsGroup[] { - visualSettings = new VisualSettings(), + VisualSettings = new VisualSettings(), new InputSettings() } } @@ -153,7 +153,7 @@ namespace osu.Game.Screens.Play } private ScheduledDelegate pushDebounce; - private VisualSettings visualSettings; + protected VisualSettings VisualSettings; private bool readyForPush => player.LoadState == LoadState.Ready && IsHovered && GetContainingInputManager()?.DraggedDrawable == null; @@ -161,14 +161,14 @@ namespace osu.Game.Screens.Play { // restore our screen defaults InitializeBackgroundElements(); - if (this.IsCurrentScreen()) + if (this.IsCurrentScreen() && (Background?.IsLoaded ?? false)) Background.EnableUserDim.Value = false; return base.OnHover(e); } protected override void OnHoverLost(HoverLostEvent e) { - if (GetContainingInputManager()?.HoveredDrawables.Contains(visualSettings) == true) + if (GetContainingInputManager()?.HoveredDrawables.Contains(VisualSettings) == true) { // show user setting preview UpdateBackgroundElements(); @@ -247,7 +247,8 @@ namespace osu.Game.Screens.Play this.FadeOut(150); cancelLoad(); - Background.EnableUserDim.Value = false; + if (Background != null) + Background.EnableUserDim.Value = false; return base.OnExiting(next); } diff --git a/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs b/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs index f2a57b2e1d..15016d2bc2 100644 --- a/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs +++ b/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs @@ -37,11 +37,8 @@ namespace osu.Game.Screens.Play public override void OnEntering(IScreen last) { - // We need to update on dim here because player still needs to know if it needs to dim the storyboard base.OnEntering(last); - DimLevel.ValueChanged += _ => UpdateBackgroundElements(); BlurLevel.ValueChanged += _ => UpdateBackgroundElements(); - ShowStoryboard.ValueChanged += _ => UpdateBackgroundElements(); InitializeBackgroundElements(); } From 0677194f4664b3aa6bf7d8647001fbff061b061c Mon Sep 17 00:00:00 2001 From: David Zhao Date: Thu, 21 Feb 2019 18:14:58 +0900 Subject: [PATCH 27/69] Move all storyboard show logic into UserDimContainer --- .../Graphics/Containers/UserDimContainer.cs | 26 +++++++++++++++++-- .../Backgrounds/BackgroundScreenBeatmap.cs | 3 ++- osu.Game/Screens/Play/Player.cs | 13 +++------- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/osu.Game/Graphics/Containers/UserDimContainer.cs b/osu.Game/Graphics/Containers/UserDimContainer.cs index 717078ab99..c0c2525175 100644 --- a/osu.Game/Graphics/Containers/UserDimContainer.cs +++ b/osu.Game/Graphics/Containers/UserDimContainer.cs @@ -13,20 +13,42 @@ namespace osu.Game.Graphics.Containers public class UserDimContainer : Container { protected Bindable DimLevel; - + protected Bindable ShowStoryboard; public Bindable EnableUserDim = new Bindable(); + public Bindable StoryboardReplacesBackground = new Bindable(); + + private readonly bool isStoryboard; + + private const float BACKGROUND_FADE_DURATION = 800; + + public UserDimContainer(bool isStoryboard = false) + { + this.isStoryboard = isStoryboard; + } [BackgroundDependencyLoader] private void load(OsuConfigManager config) { DimLevel = config.GetBindable(OsuSetting.DimLevel); + ShowStoryboard = config.GetBindable(OsuSetting.ShowStoryboard); EnableUserDim.ValueChanged += _ => updateBackgroundDim(); DimLevel.ValueChanged += _ => updateBackgroundDim(); + ShowStoryboard.ValueChanged += _ => updateBackgroundDim(); } private void updateBackgroundDim() { - this.FadeColour(EnableUserDim ? OsuColour.Gray(1 - (float)DimLevel) : Color4.White, 800, Easing.OutQuint); + if (isStoryboard) + { + this.FadeTo(!ShowStoryboard || DimLevel == 1 ? 0 : 1, BACKGROUND_FADE_DURATION, Easing.OutQuint); + } + else + { + // The background needs to be hidden in the case of it being replaced + this.FadeTo(ShowStoryboard && StoryboardReplacesBackground ? 0 : 1, BACKGROUND_FADE_DURATION, Easing.OutQuint); + } + + this.FadeColour(EnableUserDim ? OsuColour.Gray(1 - (float)DimLevel) : Color4.White, BACKGROUND_FADE_DURATION, Easing.OutQuint); } } } diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 2bbaee417e..d62cea4511 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -16,8 +16,8 @@ namespace osu.Game.Screens.Backgrounds { private WorkingBeatmap beatmap; protected Bindable DimLevel; - protected Bindable BlurLevel; public Bindable EnableUserDim; + public Bindable StoryboardReplacesBackground = new Bindable(); protected UserDimContainer FadeContainer; @@ -56,6 +56,7 @@ namespace osu.Game.Screens.Backgrounds b.Depth = newDepth; FadeContainer.Child = Background = b; Background.BlurSigma = BlurTarget; + FadeContainer.StoryboardReplacesBackground.BindTo(StoryboardReplacesBackground); })); }); } diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 3f9f1a83d5..13c7703af9 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -175,7 +175,7 @@ namespace osu.Game.Screens.Play CheckCanPause = () => AllowPause && ValidForResume && !HasFailed && !RulesetContainer.HasReplayLoaded, Children = new Container[] { - storyboardContainer = new UserDimContainer + storyboardContainer = new UserDimContainer(true) { RelativeSizeAxes = Axes.Both, Alpha = 0, @@ -351,6 +351,8 @@ namespace osu.Game.Screens.Play DimLevel.ValueChanged += _ => UpdateBackgroundElements(); ShowStoryboard.ValueChanged += _ => UpdateBackgroundElements(); Background.EnableUserDim.Value = true; + storyboardContainer.StoryboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable; + storyboardContainer.StoryboardReplacesBackground.BindTo(Background?.StoryboardReplacesBackground); Task.Run(() => { @@ -412,6 +414,7 @@ namespace osu.Game.Screens.Play float fadeOutDuration = instant ? 0 : 250; this.FadeOut(fadeOutDuration); Background.EnableUserDim.Value = false; + storyboardContainer.StoryboardReplacesBackground.Value = false; } protected override bool OnScroll(ScrollEvent e) => mouseWheelDisabled.Value && !pauseContainer.IsPaused; @@ -440,14 +443,6 @@ namespace osu.Game.Screens.Play if (ShowStoryboard && storyboard == null) initializeStoryboard(true); - - var beatmap = Beatmap.Value; - var storyboardVisible = ShowStoryboard && beatmap.Storyboard.HasDrawable; - - storyboardContainer?.FadeTo(storyboardVisible && 1 - (float)DimLevel > 0 ? 1 : 0, BACKGROUND_FADE_DURATION, Easing.OutQuint); - - if (storyboardVisible && beatmap.Storyboard.ReplacesBackground) - Background?.FadeColour(Color4.Black, BACKGROUND_FADE_DURATION, Easing.OutQuint); } protected virtual Results CreateResults(ScoreInfo score) => new SoloResults(score); From bf06674e87b5bb610ee7e5143cb51c7a08795cce Mon Sep 17 00:00:00 2001 From: David Zhao Date: Thu, 21 Feb 2019 18:19:50 +0900 Subject: [PATCH 28/69] Clean up test case --- osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 9d7c1de780..b78c0b811b 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -156,8 +156,6 @@ namespace osu.Game.Tests.Visual { protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); - public bool BackgroundLoaded => Background?.IsLoaded ?? false; - public bool AssertDimmed() { return ((FadeAccessibleBackground)Background).AssertDimmed(); @@ -207,6 +205,7 @@ namespace osu.Game.Tests.Visual public DimAccessiblePlayerLoader(Player player) : base(() => player) { } + protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); } From 97db8abd5913f216089b26d6a5a8be94578febfb Mon Sep 17 00:00:00 2001 From: David Zhao Date: Thu, 21 Feb 2019 18:34:11 +0900 Subject: [PATCH 29/69] Remove unused includes --- osu.Game/Graphics/Containers/UserDimContainer.cs | 8 ++++---- osu.Game/Screens/Play/Player.cs | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/osu.Game/Graphics/Containers/UserDimContainer.cs b/osu.Game/Graphics/Containers/UserDimContainer.cs index c0c2525175..c1dee94eeb 100644 --- a/osu.Game/Graphics/Containers/UserDimContainer.cs +++ b/osu.Game/Graphics/Containers/UserDimContainer.cs @@ -19,7 +19,7 @@ namespace osu.Game.Graphics.Containers private readonly bool isStoryboard; - private const float BACKGROUND_FADE_DURATION = 800; + private const float background_fade_duration = 800; public UserDimContainer(bool isStoryboard = false) { @@ -40,15 +40,15 @@ namespace osu.Game.Graphics.Containers { if (isStoryboard) { - this.FadeTo(!ShowStoryboard || DimLevel == 1 ? 0 : 1, BACKGROUND_FADE_DURATION, Easing.OutQuint); + this.FadeTo(!ShowStoryboard || DimLevel == 1 ? 0 : 1, background_fade_duration, Easing.OutQuint); } else { // The background needs to be hidden in the case of it being replaced - this.FadeTo(ShowStoryboard && StoryboardReplacesBackground ? 0 : 1, BACKGROUND_FADE_DURATION, Easing.OutQuint); + this.FadeTo(ShowStoryboard && StoryboardReplacesBackground ? 0 : 1, background_fade_duration, Easing.OutQuint); } - this.FadeColour(EnableUserDim ? OsuColour.Gray(1 - (float)DimLevel) : Color4.White, BACKGROUND_FADE_DURATION, Easing.OutQuint); + this.FadeColour(EnableUserDim ? OsuColour.Gray(1 - (float)DimLevel) : Color4.White, background_fade_duration, Easing.OutQuint); } } } diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 13c7703af9..c6b6ad8821 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -31,7 +31,6 @@ using osu.Game.Scoring; using osu.Game.Screens.Ranking; using osu.Game.Skinning; using osu.Game.Storyboards.Drawables; -using osuTK.Graphics; namespace osu.Game.Screens.Play { From 94bc552282a950ec7f9ec79de72149e3c2c59d22 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 22 Feb 2019 11:41:28 +0900 Subject: [PATCH 30/69] Fix backgrounds not fading out when replaced by storyboard, add test for this --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 56 +++++++++++++++++-- .../Graphics/Containers/UserDimContainer.cs | 1 + 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index b78c0b811b..6f6d43acc8 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -8,6 +8,7 @@ using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Screens; using osu.Game.Beatmaps; +using osu.Game.Configuration; using osu.Game.Graphics; using osu.Game.Rulesets.Osu.Objects; using osu.Game.Scoring; @@ -40,6 +41,8 @@ namespace osu.Game.Tests.Visual AddStep("Load Song Select", () => { + songSelect?.Exit(); + LoadComponentAsync(new DummySongSelect(), p => { songSelect = p; @@ -86,11 +89,29 @@ namespace osu.Game.Tests.Visual InputManager.MoveMouseTo(playerLoader.ScreenPos); }); - // In the case of a user triggering the dim preview the instant player gets loaded, the user dim needs to be applied when the map starts. + // 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. AddUntilStep(() => player?.IsLoaded ?? false, "Wait for player to load"); - AddStep("Trigger background preview when loaded", () => InputManager.MoveMouseTo(playerLoader.VisualSettingsPos)); + AddStep("Trigger background preview when loaded", () => + { + InputManager.MoveMouseTo(playerLoader.VisualSettingsPos); + InputManager.MoveMouseTo(playerLoader.ScreenPos); + }); AddWaitStep(5, "Wait for dim"); AddAssert("Screen is dimmed", () => songSelect.AssertDimmed()); + + // Make sure the background is fully invisible (not dimmed) when the background should be disabled by the storyboard. + 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()); } /// @@ -165,6 +186,16 @@ namespace osu.Game.Tests.Visual { return ((FadeAccessibleBackground)Background).AssertUndimmed(); } + + public bool AssertInvisible() + { + return ((FadeAccessibleBackground)Background).AssertInvisible(); + } + + public bool AssertVisible() + { + return ((FadeAccessibleBackground)Background).AssertVisible(); + } } private class FadeAccesibleResults : SoloResults @@ -182,20 +213,25 @@ namespace osu.Game.Tests.Visual public bool Ready; + public Bindable StoryboardEnabled; + public readonly Bindable ReplacesBackground = new Bindable(); + [BackgroundDependencyLoader] - private void load() + private void load(OsuConfigManager config) { while (!Ready) Thread.Sleep(1); + StoryboardEnabled = config.GetBindable(OsuSetting.ShowStoryboard); + ReplacesBackground.BindTo(Background.StoryboardReplacesBackground); } } private class DimAccessiblePlayerLoader : PlayerLoader { - public Bindable DimEnabled; + public Bindable DimEnabled = new Bindable(); public VisualSettings VisualSettingsPos => VisualSettings; - public Vector2 ScreenPos => VisualSettings.ScreenSpaceDrawQuad.BottomLeft - new Vector2(20, 20); + public BackgroundScreen ScreenPos => Background; public void UpdateBindables() { @@ -220,6 +256,16 @@ namespace osu.Game.Tests.Visual { return FadeContainer.Colour == Color4.White; } + + public bool AssertInvisible() + { + return FadeContainer.Alpha == 0; + } + + public bool AssertVisible() + { + return FadeContainer.Alpha == 1; + } } } } diff --git a/osu.Game/Graphics/Containers/UserDimContainer.cs b/osu.Game/Graphics/Containers/UserDimContainer.cs index c1dee94eeb..d44df875d3 100644 --- a/osu.Game/Graphics/Containers/UserDimContainer.cs +++ b/osu.Game/Graphics/Containers/UserDimContainer.cs @@ -34,6 +34,7 @@ namespace osu.Game.Graphics.Containers EnableUserDim.ValueChanged += _ => updateBackgroundDim(); DimLevel.ValueChanged += _ => updateBackgroundDim(); ShowStoryboard.ValueChanged += _ => updateBackgroundDim(); + StoryboardReplacesBackground.ValueChanged += _ => updateBackgroundDim(); } private void updateBackgroundDim() From 65cdac60c3aa926dc0f0c91cd2459a548db1a7ec Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 22 Feb 2019 14:43:05 +0900 Subject: [PATCH 31/69] Add tests to make sure the background is always the same through screen transitions --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 35 ++++++++++++++++++- .../Play/ScreenWithBeatmapBackground.cs | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 6f6d43acc8..a09843318c 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; +using System.Collections.Generic; using System.Threading; using NUnit.Framework; using osu.Framework.Allocation; @@ -26,6 +28,13 @@ namespace osu.Game.Tests.Visual [TestFixture] public class TestCaseBackgroundScreenBeatmap : ManualInputManagerTestCase { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(ScreenWithBeatmapBackground), + typeof(PlayerLoader), + typeof(Player) + }; + private DummySongSelect songSelect; private DimAccessiblePlayerLoader playerLoader; private DimAccessiblePlayer player; @@ -36,11 +45,13 @@ namespace osu.Game.Tests.Visual public TestCaseBackgroundScreenBeatmap() { ScreenStack screen; + InputManager.Add(backgroundStack = new BackgroundScreenStack {RelativeSizeAxes = Axes.Both}); InputManager.Add(screen = new ScreenStack { RelativeSizeAxes = Axes.Both }); AddStep("Load Song Select", () => { + songSelect?.MakeCurrent(); songSelect?.Exit(); LoadComponentAsync(new DummySongSelect(), p => @@ -73,6 +84,8 @@ namespace osu.Game.Tests.Visual AddStep("Start player loader", () => songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer()))); AddUntilStep(() => playerLoader?.IsLoaded ?? false, "Wait for Player Loader to load"); + AddAssert("Background retained from song select", () => songSelect.AssertBackgroundCurrent()); + AddStep("Update bindables", () => playerLoader.UpdateBindables()); AddStep("Trigger background preview", () => { @@ -93,6 +106,7 @@ namespace osu.Game.Tests.Visual // 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. AddUntilStep(() => player?.IsLoaded ?? false, "Wait for player to load"); + AddAssert("Background retained from song select", () => songSelect.AssertBackgroundCurrent()); AddStep("Trigger background preview when loaded", () => { InputManager.MoveMouseTo(playerLoader.VisualSettingsPos); @@ -142,7 +156,11 @@ namespace osu.Game.Tests.Visual [Test] public void PauseTest() { - AddStep("Transition to Pause", () => player.Exit()); + AddStep("Transition to Pause", () => + { + if (!player.IsPaused) + player.Exit(); + }); AddWaitStep(5, "Wait for dim"); AddAssert("Screen is dimmed", () => songSelect.AssertDimmed()); } @@ -156,6 +174,7 @@ namespace osu.Game.Tests.Visual AddStep("Transition to Results", () => player.Push(new FadeAccesibleResults(new ScoreInfo { User = new User { Username = "osu!" }}))); AddWaitStep(5, "Wait for dim"); AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed()); + AddAssert("Background retained from song select", () => songSelect.AssertBackgroundCurrent()); } /// @@ -196,6 +215,15 @@ namespace osu.Game.Tests.Visual { return ((FadeAccessibleBackground)Background).AssertVisible(); } + + /// + /// Make sure every time a screen gets pushed, the background doesn't get replaced + /// + /// Whether or not the original background is still the current background + public bool AssertBackgroundCurrent() + { + return ((FadeAccessibleBackground)Background).IsCurrentScreen(); + } } private class FadeAccesibleResults : SoloResults @@ -216,6 +244,8 @@ namespace osu.Game.Tests.Visual public Bindable StoryboardEnabled; public readonly Bindable ReplacesBackground = new Bindable(); + public bool IsPaused => RulesetContainer.IsPaused; + [BackgroundDependencyLoader] private void load(OsuConfigManager config) { @@ -233,6 +263,9 @@ namespace osu.Game.Tests.Visual public VisualSettings VisualSettingsPos => VisualSettings; public BackgroundScreen ScreenPos => Background; + [Resolved] + private BackgroundScreenStack stack { get; set; } + public void UpdateBindables() { DimEnabled = Background.EnableUserDim; diff --git a/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs b/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs index 15016d2bc2..93223b6607 100644 --- a/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs +++ b/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs @@ -15,7 +15,7 @@ namespace osu.Game.Screens.Play { protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap.Value); - protected new BackgroundScreenBeatmap Background => base.Background as BackgroundScreenBeatmap; + protected new BackgroundScreenBeatmap Background => (BackgroundScreenBeatmap)base.Background; protected const float BACKGROUND_FADE_DURATION = 800; From 918a60ebbf6d644af3ab63a95466bdd5bb6b6d1a Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 22 Feb 2019 16:56:03 +0900 Subject: [PATCH 32/69] Create a new player every time a test is performed. --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 47 ++++++++++++------- .../Backgrounds/BackgroundScreenBeatmap.cs | 8 ++-- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index a09843318c..5829ba38b5 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -42,6 +42,21 @@ namespace osu.Game.Tests.Visual [Cached] private BackgroundScreenStack backgroundStack; + private void performSetup() + { + AddUntilStep(() => + { + if (!songSelect.IsCurrentScreen()) + { + songSelect.MakeCurrent(); + return false; + } + return true; + }, "Wait for song select is current"); + AddStep("Load new player to song select", () => songSelect.Push(player = new DimAccessiblePlayer { Ready = true })); + AddUntilStep(() => player?.IsLoaded ?? false, "Wait for player to load"); + } + public TestCaseBackgroundScreenBeatmap() { ScreenStack screen; @@ -58,6 +73,7 @@ namespace osu.Game.Tests.Visual { songSelect = p; screen.Push(p); + songSelect.UpdateBindables(); }); }); @@ -85,8 +101,6 @@ namespace osu.Game.Tests.Visual AddStep("Start player loader", () => songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer()))); AddUntilStep(() => playerLoader?.IsLoaded ?? false, "Wait for Player Loader to load"); AddAssert("Background retained from song select", () => songSelect.AssertBackgroundCurrent()); - - AddStep("Update bindables", () => playerLoader.UpdateBindables()); AddStep("Trigger background preview", () => { InputManager.MoveMouseTo(playerLoader.ScreenPos); @@ -134,7 +148,8 @@ namespace osu.Game.Tests.Visual [Test] public void DisableUserDimTest() { - AddStep("Test User Undimming", () => playerLoader.DimEnabled.Value = false); + performSetup(); + AddStep("Test User Undimming", () => songSelect.DimEnabled.Value = false); AddWaitStep(5, "Wait for dim"); AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed()); } @@ -145,7 +160,8 @@ namespace osu.Game.Tests.Visual [Test] public void EnableUserDimTest() { - AddStep("Test User Dimming", () => playerLoader.DimEnabled.Value = true); + performSetup(); + AddStep("Test User Dimming", () => songSelect.DimEnabled.Value = true); AddWaitStep(5, "Wait for dim"); AddAssert("Screen is dimmed", () => songSelect.AssertDimmed()); } @@ -156,6 +172,7 @@ namespace osu.Game.Tests.Visual [Test] public void PauseTest() { + performSetup(); AddStep("Transition to Pause", () => { if (!player.IsPaused) @@ -171,6 +188,7 @@ namespace osu.Game.Tests.Visual [Test] public void TransitionTest() { + performSetup(); AddStep("Transition to Results", () => player.Push(new FadeAccesibleResults(new ScoreInfo { User = new User { Username = "osu!" }}))); AddWaitStep(5, "Wait for dim"); AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed()); @@ -183,11 +201,8 @@ namespace osu.Game.Tests.Visual [Test] public void TransitionOutTest() { - AddStep("Exit player", () => - { - player.MakeCurrent(); - player.Exit(); - }); + performSetup(); + AddStep("Exit player", () => songSelect.MakeCurrent()); AddWaitStep(5, "Wait for dim"); AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed()); } @@ -195,6 +210,12 @@ namespace osu.Game.Tests.Visual private class DummySongSelect : OsuScreen { protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); + public readonly Bindable DimEnabled = new Bindable(); + + public void UpdateBindables() + { + DimEnabled.BindTo(((FadeAccessibleBackground)Background).EnableUserDim); + } public bool AssertDimmed() { @@ -258,19 +279,11 @@ namespace osu.Game.Tests.Visual private class DimAccessiblePlayerLoader : PlayerLoader { - public Bindable DimEnabled = new Bindable(); - public VisualSettings VisualSettingsPos => VisualSettings; public BackgroundScreen ScreenPos => Background; [Resolved] private BackgroundScreenStack stack { get; set; } - - public void UpdateBindables() - { - DimEnabled = Background.EnableUserDim; - } - public DimAccessiblePlayerLoader(Player player) : base(() => player) { } diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index d62cea4511..c793197f19 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -15,8 +15,8 @@ namespace osu.Game.Screens.Backgrounds public class BackgroundScreenBeatmap : BlurrableBackgroundScreen { private WorkingBeatmap beatmap; - protected Bindable DimLevel; - public Bindable EnableUserDim; + protected Bindable DimLevel = new Bindable(); + public Bindable EnableUserDim = new Bindable(); public Bindable StoryboardReplacesBackground = new Bindable(); protected UserDimContainer FadeContainer; @@ -24,7 +24,7 @@ namespace osu.Game.Screens.Backgrounds [BackgroundDependencyLoader] private void load(OsuConfigManager config) { - DimLevel = config.GetBindable(OsuSetting.DimLevel); + config.BindWith(OsuSetting.DimLevel, DimLevel); } public virtual WorkingBeatmap Beatmap @@ -39,7 +39,7 @@ namespace osu.Game.Screens.Backgrounds FadeContainer = new UserDimContainer { RelativeSizeAxes = Axes.Both }; InternalChild = FadeContainer; - EnableUserDim = FadeContainer.EnableUserDim; + EnableUserDim.BindTo(FadeContainer.EnableUserDim); Schedule(() => { From 263972a048590262c5708d29b382d385823459bf Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 22 Feb 2019 17:00:00 +0900 Subject: [PATCH 33/69] Remove DimLevel bindable from ScreenWithBeatmapBackground --- osu.Game/Screens/Play/Player.cs | 3 --- osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs | 2 -- 2 files changed, 5 deletions(-) diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index c6b6ad8821..3f132c421e 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -345,9 +345,6 @@ namespace osu.Game.Screens.Play .Delay(250) .FadeIn(250); - // We need to update background elements when the user dim gets updated - // The storyboard needs to know whether or not to completely fade at 100% dim - DimLevel.ValueChanged += _ => UpdateBackgroundElements(); ShowStoryboard.ValueChanged += _ => UpdateBackgroundElements(); Background.EnableUserDim.Value = true; storyboardContainer.StoryboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable; diff --git a/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs b/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs index 93223b6607..405218ae2d 100644 --- a/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs +++ b/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs @@ -21,7 +21,6 @@ namespace osu.Game.Screens.Play #region User Settings - protected Bindable DimLevel; protected Bindable BlurLevel; protected Bindable ShowStoryboard; @@ -30,7 +29,6 @@ namespace osu.Game.Screens.Play [BackgroundDependencyLoader] private void load(OsuConfigManager config) { - DimLevel = config.GetBindable(OsuSetting.DimLevel); BlurLevel = config.GetBindable(OsuSetting.BlurLevel); ShowStoryboard = config.GetBindable(OsuSetting.ShowStoryboard); } From 6bf831b96f2f558dc24ef3484d8486ff5a22d80a Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 22 Feb 2019 17:15:05 +0900 Subject: [PATCH 34/69] Fix TransitiouOutTest getting stuck on pause --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 5829ba38b5..9871209760 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -202,7 +202,15 @@ namespace osu.Game.Tests.Visual public void TransitionOutTest() { performSetup(); - AddStep("Exit player", () => songSelect.MakeCurrent()); + AddUntilStep(() => + { + if (!songSelect.IsCurrentScreen()) + { + songSelect.MakeCurrent(); + return false; + } + return true; + }, "Wait for song select is current"); AddWaitStep(5, "Wait for dim"); AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed()); } From a4162a69fb89e7713c65692bb968aadadd1f2620 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 22 Feb 2019 18:01:50 +0900 Subject: [PATCH 35/69] Remove leftover usage of dimlevel in BackgroundScreenBeatmap --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 10 +++++++++- .../Screens/Backgrounds/BackgroundScreenBeatmap.cs | 8 -------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 9871209760..bbffb910d5 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -301,9 +301,17 @@ namespace osu.Game.Tests.Visual private class FadeAccessibleBackground : BackgroundScreenBeatmap { + private Bindable dimLevel; + + [BackgroundDependencyLoader] + private void load(OsuConfigManager config) + { + dimLevel = config.GetBindable(OsuSetting.DimLevel); + } + public bool AssertDimmed() { - return FadeContainer.Colour == OsuColour.Gray(1 - (float)DimLevel); + return FadeContainer.Colour == OsuColour.Gray(1 - dimLevel); } public bool AssertUndimmed() diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index c793197f19..8aa3ef620c 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -6,7 +6,6 @@ using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Textures; using osu.Game.Beatmaps; -using osu.Game.Configuration; using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Containers; @@ -15,18 +14,11 @@ namespace osu.Game.Screens.Backgrounds public class BackgroundScreenBeatmap : BlurrableBackgroundScreen { private WorkingBeatmap beatmap; - protected Bindable DimLevel = new Bindable(); public Bindable EnableUserDim = new Bindable(); public Bindable StoryboardReplacesBackground = new Bindable(); protected UserDimContainer FadeContainer; - [BackgroundDependencyLoader] - private void load(OsuConfigManager config) - { - config.BindWith(OsuSetting.DimLevel, DimLevel); - } - public virtual WorkingBeatmap Beatmap { get { return beatmap; } From 76de39a3444c3c59c376fb95f40a365e34396445 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 22 Feb 2019 20:34:51 +0900 Subject: [PATCH 36/69] Put user dim logic in yet another container inside UserDimContainer --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 61 ++++++++++++------- .../Graphics/Containers/UserDimContainer.cs | 10 ++- .../Backgrounds/BackgroundScreenBeatmap.cs | 3 +- 3 files changed, 47 insertions(+), 27 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index bbffb910d5..881ece1dc4 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -12,6 +12,7 @@ using osu.Framework.Screens; using osu.Game.Beatmaps; using osu.Game.Configuration; using osu.Game.Graphics; +using osu.Game.Graphics.Containers; using osu.Game.Rulesets.Osu.Objects; using osu.Game.Scoring; using osu.Game.Screens; @@ -32,18 +33,38 @@ namespace osu.Game.Tests.Visual { typeof(ScreenWithBeatmapBackground), typeof(PlayerLoader), - typeof(Player) + typeof(Player), + typeof(UserDimContainer) }; private DummySongSelect songSelect; private DimAccessiblePlayerLoader playerLoader; private DimAccessiblePlayer player; + private readonly ScreenStack screen; [Cached] private BackgroundScreenStack backgroundStack; + 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"); + } + private void performSetup() { + createSongSelect(); AddUntilStep(() => { if (!songSelect.IsCurrentScreen()) @@ -53,31 +74,17 @@ namespace osu.Game.Tests.Visual } return true; }, "Wait for song select is current"); + AddStep("Load new player to song select", () => songSelect.Push(player = new DimAccessiblePlayer { Ready = true })); AddUntilStep(() => player?.IsLoaded ?? false, "Wait for player to load"); } public TestCaseBackgroundScreenBeatmap() { - ScreenStack screen; - InputManager.Add(backgroundStack = new BackgroundScreenStack {RelativeSizeAxes = Axes.Both}); InputManager.Add(screen = new ScreenStack { RelativeSizeAxes = Axes.Both }); - AddStep("Load Song Select", () => - { - songSelect?.MakeCurrent(); - songSelect?.Exit(); - - LoadComponentAsync(new DummySongSelect(), p => - { - songSelect = p; - screen.Push(p); - songSelect.UpdateBindables(); - }); - }); - - AddUntilStep(() => songSelect?.IsLoaded ?? false, "Wait for song select to load"); + createSongSelect(); AddStep("Create beatmap", () => { Beatmap.Value = new TestWorkingBeatmap(new Beatmap @@ -301,32 +308,40 @@ namespace osu.Game.Tests.Visual private class FadeAccessibleBackground : BackgroundScreenBeatmap { - private Bindable dimLevel; + private readonly Bindable dimLevel = new Bindable(); + + protected override UserDimContainer CreateFadeContainer() => new TestUserDimContainer { RelativeSizeAxes = Axes.Both }; [BackgroundDependencyLoader] private void load(OsuConfigManager config) { - dimLevel = config.GetBindable(OsuSetting.DimLevel); + config.BindWith(OsuSetting.DimLevel, dimLevel); } public bool AssertDimmed() { - return FadeContainer.Colour == OsuColour.Gray(1 - dimLevel); + return ((TestUserDimContainer)FadeContainer).CurrentColour == OsuColour.Gray(1 - (float)dimLevel); } public bool AssertUndimmed() { - return FadeContainer.Colour == Color4.White; + return ((TestUserDimContainer)FadeContainer).CurrentColour == Color4.White; } public bool AssertInvisible() { - return FadeContainer.Alpha == 0; + return ((TestUserDimContainer)FadeContainer).CurrentAlpha == 0; } public bool AssertVisible() { - return FadeContainer.Alpha == 1; + return ((TestUserDimContainer)FadeContainer).CurrentAlpha == 1; + } + + private class TestUserDimContainer : UserDimContainer + { + public Color4 CurrentColour => DimContainer.Colour; + public float CurrentAlpha => DimContainer.Alpha; } } } diff --git a/osu.Game/Graphics/Containers/UserDimContainer.cs b/osu.Game/Graphics/Containers/UserDimContainer.cs index d44df875d3..5d2dc8c9a0 100644 --- a/osu.Game/Graphics/Containers/UserDimContainer.cs +++ b/osu.Game/Graphics/Containers/UserDimContainer.cs @@ -16,6 +16,8 @@ namespace osu.Game.Graphics.Containers protected Bindable ShowStoryboard; public Bindable EnableUserDim = new Bindable(); public Bindable StoryboardReplacesBackground = new Bindable(); + protected Container DimContainer; + protected override Container Content => DimContainer; private readonly bool isStoryboard; @@ -23,7 +25,9 @@ namespace osu.Game.Graphics.Containers public UserDimContainer(bool isStoryboard = false) { + DimContainer = new Container { RelativeSizeAxes = Axes.Both }; this.isStoryboard = isStoryboard; + AddInternal(DimContainer); } [BackgroundDependencyLoader] @@ -41,15 +45,15 @@ namespace osu.Game.Graphics.Containers { if (isStoryboard) { - this.FadeTo(!ShowStoryboard || DimLevel == 1 ? 0 : 1, background_fade_duration, Easing.OutQuint); + DimContainer.FadeTo(!ShowStoryboard || DimLevel == 1 ? 0 : 1, background_fade_duration, Easing.OutQuint); } else { // The background needs to be hidden in the case of it being replaced - this.FadeTo(ShowStoryboard && StoryboardReplacesBackground ? 0 : 1, background_fade_duration, Easing.OutQuint); + DimContainer.FadeTo(ShowStoryboard && StoryboardReplacesBackground ? 0 : 1, background_fade_duration, Easing.OutQuint); } - this.FadeColour(EnableUserDim ? OsuColour.Gray(1 - (float)DimLevel) : Color4.White, background_fade_duration, Easing.OutQuint); + DimContainer.FadeColour(EnableUserDim ? OsuColour.Gray(1 - (float)DimLevel) : Color4.White, background_fade_duration, Easing.OutQuint); } } } diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 8aa3ef620c..9716e0fb48 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -18,6 +18,7 @@ namespace osu.Game.Screens.Backgrounds public Bindable StoryboardReplacesBackground = new Bindable(); protected UserDimContainer FadeContainer; + protected virtual UserDimContainer CreateFadeContainer() => new UserDimContainer { RelativeSizeAxes = Axes.Both }; public virtual WorkingBeatmap Beatmap { @@ -29,7 +30,7 @@ namespace osu.Game.Screens.Backgrounds beatmap = value; - FadeContainer = new UserDimContainer { RelativeSizeAxes = Axes.Both }; + FadeContainer = CreateFadeContainer(); InternalChild = FadeContainer; EnableUserDim.BindTo(FadeContainer.EnableUserDim); From bb01948283838ce780e781d95f93601f1a27c218 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 22 Feb 2019 20:44:02 +0900 Subject: [PATCH 37/69] Use .Value with new bindable changes --- osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs | 6 +++--- osu.Game/Graphics/Containers/UserDimContainer.cs | 8 ++++---- osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 881ece1dc4..78615c982e 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Threading; using NUnit.Framework; using osu.Framework.Allocation; -using osu.Framework.Configuration; +using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Screens; using osu.Game.Beatmaps; @@ -280,7 +280,7 @@ namespace osu.Game.Tests.Visual public Bindable StoryboardEnabled; public readonly Bindable ReplacesBackground = new Bindable(); - public bool IsPaused => RulesetContainer.IsPaused; + public bool IsPaused => RulesetContainer.IsPaused.Value; [BackgroundDependencyLoader] private void load(OsuConfigManager config) @@ -320,7 +320,7 @@ namespace osu.Game.Tests.Visual public bool AssertDimmed() { - return ((TestUserDimContainer)FadeContainer).CurrentColour == OsuColour.Gray(1 - (float)dimLevel); + return ((TestUserDimContainer)FadeContainer).CurrentColour == OsuColour.Gray(1 - (float)dimLevel.Value); } public bool AssertUndimmed() diff --git a/osu.Game/Graphics/Containers/UserDimContainer.cs b/osu.Game/Graphics/Containers/UserDimContainer.cs index 5d2dc8c9a0..43e85a7492 100644 --- a/osu.Game/Graphics/Containers/UserDimContainer.cs +++ b/osu.Game/Graphics/Containers/UserDimContainer.cs @@ -2,7 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.Allocation; -using osu.Framework.Configuration; +using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Configuration; @@ -45,15 +45,15 @@ namespace osu.Game.Graphics.Containers { if (isStoryboard) { - DimContainer.FadeTo(!ShowStoryboard || DimLevel == 1 ? 0 : 1, background_fade_duration, Easing.OutQuint); + DimContainer.FadeTo(!ShowStoryboard.Value || DimLevel.Value == 1 ? 0 : 1, background_fade_duration, Easing.OutQuint); } else { // The background needs to be hidden in the case of it being replaced - DimContainer.FadeTo(ShowStoryboard && StoryboardReplacesBackground ? 0 : 1, background_fade_duration, Easing.OutQuint); + DimContainer.FadeTo(ShowStoryboard.Value && StoryboardReplacesBackground.Value ? 0 : 1, background_fade_duration, Easing.OutQuint); } - DimContainer.FadeColour(EnableUserDim ? OsuColour.Gray(1 - (float)DimLevel) : Color4.White, background_fade_duration, Easing.OutQuint); + DimContainer.FadeColour(EnableUserDim.Value ? OsuColour.Gray(1 - (float)DimLevel.Value) : Color4.White, background_fade_duration, Easing.OutQuint); } } } diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 9716e0fb48..6533276568 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -2,7 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.Allocation; -using osu.Framework.Configuration; +using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Textures; using osu.Game.Beatmaps; From f8d18285a8314633dabfdeaf543cfb41caa793e7 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Sat, 23 Feb 2019 14:59:54 +0900 Subject: [PATCH 38/69] Fix backgrounds not properly being faded in song select --- osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 6533276568..b804a86282 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -30,10 +30,6 @@ namespace osu.Game.Screens.Backgrounds beatmap = value; - FadeContainer = CreateFadeContainer(); - InternalChild = FadeContainer; - EnableUserDim.BindTo(FadeContainer.EnableUserDim); - Schedule(() => { LoadComponentAsync(new BeatmapBackground(beatmap), b => Schedule(() => @@ -47,7 +43,7 @@ namespace osu.Game.Screens.Backgrounds Background.Expire(); } b.Depth = newDepth; - FadeContainer.Child = Background = b; + FadeContainer.Add(Background = b); Background.BlurSigma = BlurTarget; FadeContainer.StoryboardReplacesBackground.BindTo(StoryboardReplacesBackground); })); @@ -57,6 +53,9 @@ namespace osu.Game.Screens.Backgrounds public BackgroundScreenBeatmap(WorkingBeatmap beatmap = null) { + FadeContainer = CreateFadeContainer(); + InternalChild = FadeContainer; + EnableUserDim.BindTo(FadeContainer.EnableUserDim); Beatmap = beatmap; } From f56f1fc4f7ebe161bd42b748ac27ba0c53f2adf9 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Sat, 23 Feb 2019 15:06:04 +0900 Subject: [PATCH 39/69] Clean up left over test code --- osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 78615c982e..a1d302d93a 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -297,8 +297,6 @@ namespace osu.Game.Tests.Visual public VisualSettings VisualSettingsPos => VisualSettings; public BackgroundScreen ScreenPos => Background; - [Resolved] - private BackgroundScreenStack stack { get; set; } public DimAccessiblePlayerLoader(Player player) : base(() => player) { } From f4acd6e48f916749c0df9d8e9a0033fb523cdc68 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Sun, 24 Feb 2019 18:10:59 +0900 Subject: [PATCH 40/69] Move PlayerLoader tests out of constructor, Improve Documentation --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 101 +++++++++--------- osu.Game/Screens/Play/Player.cs | 3 - 2 files changed, 53 insertions(+), 51 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index a1d302d93a..47215a0551 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -45,6 +45,14 @@ namespace osu.Game.Tests.Visual [Cached] private BackgroundScreenStack backgroundStack; + 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"); + } + private void createSongSelect() { AddStep("Create song select if required", () => @@ -60,11 +68,6 @@ namespace osu.Game.Tests.Visual } }); AddUntilStep(() => songSelect?.IsLoaded ?? false, "Wait for song select to load"); - } - - private void performSetup() - { - createSongSelect(); AddUntilStep(() => { if (!songSelect.IsCurrentScreen()) @@ -74,9 +77,6 @@ namespace osu.Game.Tests.Visual } return true; }, "Wait for song select is current"); - - AddStep("Load new player to song select", () => songSelect.Push(player = new DimAccessiblePlayer { Ready = true })); - AddUntilStep(() => player?.IsLoaded ?? false, "Wait for player to load"); } public TestCaseBackgroundScreenBeatmap() @@ -84,7 +84,6 @@ namespace osu.Game.Tests.Visual InputManager.Add(backgroundStack = new BackgroundScreenStack {RelativeSizeAxes = Axes.Both}); InputManager.Add(screen = new ScreenStack { RelativeSizeAxes = Axes.Both }); - createSongSelect(); AddStep("Create beatmap", () => { Beatmap.Value = new TestWorkingBeatmap(new Beatmap @@ -104,7 +103,15 @@ namespace osu.Game.Tests.Visual }, }); }); + } + /// + /// Check if PlayerLoader properly triggers background dim previews when a user hovers over the visual settings panel. + /// + [Test] + public void PlayerLoaderSettingsHoverTest() + { + createSongSelect(); AddStep("Start player loader", () => songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer()))); AddUntilStep(() => playerLoader?.IsLoaded ?? false, "Wait for Player Loader to load"); AddAssert("Background retained from song select", () => songSelect.AssertBackgroundCurrent()); @@ -116,16 +123,24 @@ namespace osu.Game.Tests.Visual AddWaitStep(5, "Wait for dim"); AddAssert("Screen is dimmed", () => songSelect.AssertDimmed()); + } + /// + /// 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. + /// + [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"); AddStep("Allow beatmap to load", () => { player.Ready = true; InputManager.MoveMouseTo(playerLoader.ScreenPos); }); - - // 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. AddUntilStep(() => player?.IsLoaded ?? false, "Wait for player to load"); AddAssert("Background retained from song select", () => songSelect.AssertBackgroundCurrent()); AddStep("Trigger background preview when loaded", () => @@ -135,8 +150,15 @@ namespace osu.Game.Tests.Visual }); AddWaitStep(5, "Wait for dim"); AddAssert("Screen is dimmed", () => songSelect.AssertDimmed()); + } - // Make sure the background is fully invisible (not dimmed) when the background should be disabled by the storyboard. + /// + /// Make sure the background is fully invisible (Alpha == 0) when the background should be disabled by the storyboard. + /// + [Test] + public void StoryboardBackgroundVisibilityTest() + { + performSetup(); AddStep("Enable storyboard", () => { player.ReplacesBackground.Value = true; @@ -182,7 +204,7 @@ namespace osu.Game.Tests.Visual performSetup(); AddStep("Transition to Pause", () => { - if (!player.IsPaused) + if (!player.IsPaused.Value) player.Exit(); }); AddWaitStep(5, "Wait for dim"); @@ -226,6 +248,13 @@ namespace osu.Game.Tests.Visual { protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); public readonly Bindable DimEnabled = new Bindable(); + private readonly Bindable dimLevel = new Bindable(); + + [BackgroundDependencyLoader] + private void load(OsuConfigManager config) + { + config.BindWith(OsuSetting.DimLevel, dimLevel); + } public void UpdateBindables() { @@ -234,22 +263,22 @@ namespace osu.Game.Tests.Visual public bool AssertDimmed() { - return ((FadeAccessibleBackground)Background).AssertDimmed(); + return ((FadeAccessibleBackground)Background).CurrentColour == OsuColour.Gray(1 - (float)dimLevel.Value); } public bool AssertUndimmed() { - return ((FadeAccessibleBackground)Background).AssertUndimmed(); + return ((FadeAccessibleBackground)Background).CurrentColour == Color4.White; } public bool AssertInvisible() { - return ((FadeAccessibleBackground)Background).AssertInvisible(); + return ((FadeAccessibleBackground)Background).CurrentAlpha == 0; } public bool AssertVisible() { - return ((FadeAccessibleBackground)Background).AssertVisible(); + return ((FadeAccessibleBackground)Background).CurrentAlpha == 1; } /// @@ -275,12 +304,12 @@ namespace osu.Game.Tests.Visual { protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); + // Whether or not the player should be allowed to load. public bool Ready; public Bindable StoryboardEnabled; public readonly Bindable ReplacesBackground = new Bindable(); - - public bool IsPaused => RulesetContainer.IsPaused.Value; + public readonly Bindable IsPaused = new Bindable(); [BackgroundDependencyLoader] private void load(OsuConfigManager config) @@ -289,6 +318,7 @@ namespace osu.Game.Tests.Visual Thread.Sleep(1); StoryboardEnabled = config.GetBindable(OsuSetting.ShowStoryboard); ReplacesBackground.BindTo(Background.StoryboardReplacesBackground); + RulesetContainer.IsPaused.BindTo(IsPaused); } } @@ -306,35 +336,10 @@ namespace osu.Game.Tests.Visual private class FadeAccessibleBackground : BackgroundScreenBeatmap { - private readonly Bindable dimLevel = new Bindable(); - protected override UserDimContainer CreateFadeContainer() => new TestUserDimContainer { RelativeSizeAxes = Axes.Both }; - [BackgroundDependencyLoader] - private void load(OsuConfigManager config) - { - config.BindWith(OsuSetting.DimLevel, dimLevel); - } - - public bool AssertDimmed() - { - return ((TestUserDimContainer)FadeContainer).CurrentColour == OsuColour.Gray(1 - (float)dimLevel.Value); - } - - public bool AssertUndimmed() - { - return ((TestUserDimContainer)FadeContainer).CurrentColour == Color4.White; - } - - public bool AssertInvisible() - { - return ((TestUserDimContainer)FadeContainer).CurrentAlpha == 0; - } - - public bool AssertVisible() - { - return ((TestUserDimContainer)FadeContainer).CurrentAlpha == 1; - } + public Color4 CurrentColour => ((TestUserDimContainer)FadeContainer).CurrentColour; + public float CurrentAlpha => ((TestUserDimContainer)FadeContainer).CurrentAlpha; private class TestUserDimContainer : UserDimContainer { diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index c683ebef3d..38808c479a 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -397,10 +397,7 @@ namespace osu.Game.Screens.Play } if (LoadedBeatmapSuccessfully) - { pauseContainer?.Pause(); - return true; - } return true; } From 24f5bc7a75fde89fa04cc63a35edf57ea4f856ca Mon Sep 17 00:00:00 2001 From: David Zhao Date: Sun, 24 Feb 2019 20:03:24 +0900 Subject: [PATCH 41/69] Add documentation and move storyboard init logic --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 2 +- .../Graphics/Containers/UserDimContainer.cs | 32 +++++++++++++++++-- .../Backgrounds/BackgroundScreenBeatmap.cs | 6 ++++ osu.Game/Screens/Play/Player.cs | 10 +++--- 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 47215a0551..8e0957a38c 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -284,7 +284,7 @@ namespace osu.Game.Tests.Visual /// /// Make sure every time a screen gets pushed, the background doesn't get replaced /// - /// Whether or not the original background is still the current background + /// Whether or not the original background (The one created in DummySongSelect) is still the current background public bool AssertBackgroundCurrent() { return ((FadeAccessibleBackground)Background).IsCurrentScreen(); diff --git a/osu.Game/Graphics/Containers/UserDimContainer.cs b/osu.Game/Graphics/Containers/UserDimContainer.cs index 43e85a7492..5aa0cad148 100644 --- a/osu.Game/Graphics/Containers/UserDimContainer.cs +++ b/osu.Game/Graphics/Containers/UserDimContainer.cs @@ -10,19 +10,41 @@ using osuTK.Graphics; namespace osu.Game.Graphics.Containers { + /// + /// A container that applies user-configured dim levels to its contents. + /// This container specifies behavior that applies to both Storyboards and Backgrounds. + /// public class UserDimContainer : Container { protected Bindable DimLevel; + protected Bindable ShowStoryboard; - public Bindable EnableUserDim = new Bindable(); + + /// + /// Whether or not user-configured dim levels should be applied to the container. + /// + public readonly Bindable EnableUserDim = new Bindable(); + + /// + /// Whether or not the storyboard loaded should completely hide the background behind it. + /// public Bindable StoryboardReplacesBackground = new Bindable(); + protected Container DimContainer; + protected override Container Content => DimContainer; private readonly bool isStoryboard; private const float background_fade_duration = 800; + /// + /// + /// + /// Whether or not this instance of UserDimContainer contains a storyboard. + /// While both backgrounds and storyboards allow user dim levels to be applied, storyboards can be toggled via + /// and can cause backgrounds to become hidden via . + /// public UserDimContainer(bool isStoryboard = false) { DimContainer = new Container { RelativeSizeAxes = Axes.Both }; @@ -41,6 +63,12 @@ namespace osu.Game.Graphics.Containers StoryboardReplacesBackground.ValueChanged += _ => updateBackgroundDim(); } + protected override void LoadComplete() + { + base.LoadComplete(); + updateBackgroundDim(); + } + private void updateBackgroundDim() { if (isStoryboard) @@ -49,7 +77,7 @@ namespace osu.Game.Graphics.Containers } else { - // The background needs to be hidden in the case of it being replaced + // The background needs to be hidden in the case of it being replaced by the storyboard DimContainer.FadeTo(ShowStoryboard.Value && StoryboardReplacesBackground.Value ? 0 : 1, background_fade_duration, Easing.OutQuint); } diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index b804a86282..382c3f57ba 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -14,10 +14,16 @@ namespace osu.Game.Screens.Backgrounds public class BackgroundScreenBeatmap : BlurrableBackgroundScreen { private WorkingBeatmap beatmap; + + /// + /// Whether or not user dim settings should be applied to this Background. + /// public Bindable EnableUserDim = new Bindable(); + public Bindable StoryboardReplacesBackground = new Bindable(); protected UserDimContainer FadeContainer; + protected virtual UserDimContainer CreateFadeContainer() => new UserDimContainer { RelativeSizeAxes = Axes.Both }; public virtual WorkingBeatmap Beatmap diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 38808c479a..e51845271c 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -345,7 +345,12 @@ namespace osu.Game.Screens.Play .Delay(250) .FadeIn(250); - ShowStoryboard.ValueChanged += _ => UpdateBackgroundElements(); + ShowStoryboard.ValueChanged += _ => + { + if (ShowStoryboard.Value && storyboard == null) + initializeStoryboard(true); + }; + Background.EnableUserDim.Value = true; storyboardContainer.StoryboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable; storyboardContainer.StoryboardReplacesBackground.BindTo(Background?.StoryboardReplacesBackground); @@ -433,9 +438,6 @@ namespace osu.Game.Screens.Play if (!this.IsCurrentScreen()) return; base.UpdateBackgroundElements(); - - if (ShowStoryboard.Value && storyboard == null) - initializeStoryboard(true); } protected virtual Results CreateResults(ScoreInfo score) => new SoloResults(score); From af4606f3d20309e07a7d4412062b5fcb8618ec09 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Mon, 25 Feb 2019 12:35:01 +0900 Subject: [PATCH 42/69] Create new test for StoryboardReplacesBackground --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 25 +++++++++++++++++++ osu.Game/Screens/Play/Player.cs | 3 +-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 8e0957a38c..7edacc7586 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -171,6 +171,31 @@ namespace osu.Game.Tests.Visual AddAssert("Background is visible", () => songSelect.AssertVisible()); } + /// + /// When exiting player, the screen that it suspends/exits to needs to have a fully visible (Alpha == 1) background. + /// + [Test] + public void StoryboardTransitionTest() + { + performSetup(); + AddStep("Enable storyboard", () => + { + player.ReplacesBackground.Value = true; + player.StoryboardEnabled.Value = true; + }); + AddUntilStep(() => + { + if (!songSelect.IsCurrentScreen()) + { + songSelect.MakeCurrent(); + return false; + } + return true; + }, "Wait for song select is current"); + AddWaitStep(5, "Wait for dim"); + AddAssert("Background is visible", () => songSelect.AssertVisible()); + } + /// /// Check if the fade container is properly being reset when screen dim is disabled. /// diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index e51845271c..be4c3fd3f6 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -178,6 +178,7 @@ namespace osu.Game.Screens.Play { RelativeSizeAxes = Axes.Both, Alpha = 0, + EnableUserDim = { Value = true } }, new ScalingContainer(ScalingMode.Gameplay) { @@ -239,8 +240,6 @@ namespace osu.Game.Screens.Play if (ShowStoryboard.Value) initializeStoryboard(false); - storyboardContainer.EnableUserDim.Value = true; - // Bind ScoreProcessor to ourselves ScoreProcessor.AllJudged += onCompletion; ScoreProcessor.Failed += onFail; From ccc86b66faa5c913447b16c5e1830deb11c038d7 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Mon, 25 Feb 2019 13:15:37 +0900 Subject: [PATCH 43/69] Use local private bindable in Player.cs --- osu.Game/Screens/Play/Player.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index be4c3fd3f6..43a2fe3f40 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -54,6 +54,7 @@ namespace osu.Game.Screens.Play private Bindable mouseWheelDisabled; private Bindable userAudioOffset; + private Bindable storyboardReplacesBackground; public int RestartCount; @@ -344,15 +345,17 @@ namespace osu.Game.Screens.Play .Delay(250) .FadeIn(250); - ShowStoryboard.ValueChanged += _ => + ShowStoryboard.ValueChanged += s => { - if (ShowStoryboard.Value && storyboard == null) + if (s.NewValue && storyboard == null) initializeStoryboard(true); }; Background.EnableUserDim.Value = true; - storyboardContainer.StoryboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable; - storyboardContainer.StoryboardReplacesBackground.BindTo(Background?.StoryboardReplacesBackground); + + storyboardReplacesBackground.BindTo(Background?.StoryboardReplacesBackground); + storyboardReplacesBackground.BindTo(storyboardContainer.StoryboardReplacesBackground); + storyboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable; Task.Run(() => { @@ -411,7 +414,7 @@ namespace osu.Game.Screens.Play float fadeOutDuration = instant ? 0 : 250; this.FadeOut(fadeOutDuration); Background.EnableUserDim.Value = false; - storyboardContainer.StoryboardReplacesBackground.Value = false; + storyboardReplacesBackground.Value = false; } protected override bool OnScroll(ScrollEvent e) => mouseWheelDisabled.Value && !pauseContainer.IsPaused.Value; From 16fa30f71e5ed7a2395898b321c48676794656c0 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Mon, 25 Feb 2019 13:27:44 +0900 Subject: [PATCH 44/69] Fix bindable --- osu.Game/Screens/Play/Player.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 43a2fe3f40..fe12fce09b 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -54,7 +54,8 @@ namespace osu.Game.Screens.Play private Bindable mouseWheelDisabled; private Bindable userAudioOffset; - private Bindable storyboardReplacesBackground; + + private readonly Bindable storyboardReplacesBackground = new Bindable(); public int RestartCount; From d750023c5201ce1fc787fd62112e8ae7746e0a2a Mon Sep 17 00:00:00 2001 From: David Zhao Date: Mon, 25 Feb 2019 22:05:49 +0900 Subject: [PATCH 45/69] Fix TestCasePlayerLoader not having a background stack --- osu.Game.Tests/Visual/TestCasePlayerLoader.cs | 12 ++++++++++-- osu.Game/Screens/Play/Player.cs | 4 ++-- osu.Game/Screens/Play/PlayerLoader.cs | 8 ++++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCasePlayerLoader.cs b/osu.Game.Tests/Visual/TestCasePlayerLoader.cs index 16cb94c65e..3e3f9eb9f3 100644 --- a/osu.Game.Tests/Visual/TestCasePlayerLoader.cs +++ b/osu.Game.Tests/Visual/TestCasePlayerLoader.cs @@ -6,6 +6,7 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Screens; using osu.Game.Beatmaps; +using osu.Game.Screens; using osu.Game.Screens.Play; namespace osu.Game.Tests.Visual @@ -15,13 +16,20 @@ namespace osu.Game.Tests.Visual private PlayerLoader loader; private ScreenStack stack; + [Cached] + private BackgroundScreenStack backgroundStack; + + public TestCasePlayerLoader() + { + InputManager.Add(backgroundStack = new BackgroundScreenStack {RelativeSizeAxes = Axes.Both}); + InputManager.Add(stack = new ScreenStack { RelativeSizeAxes = Axes.Both }); + } + [BackgroundDependencyLoader] private void load(OsuGameBase game) { Beatmap.Value = new DummyWorkingBeatmap(game); - InputManager.Add(stack = new ScreenStack { RelativeSizeAxes = Axes.Both }); - AddStep("load dummy beatmap", () => stack.Push(loader = new PlayerLoader(() => new Player { AllowPause = false, diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index fe12fce09b..8caa09cc7b 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -354,8 +354,8 @@ namespace osu.Game.Screens.Play Background.EnableUserDim.Value = true; - storyboardReplacesBackground.BindTo(Background?.StoryboardReplacesBackground); - storyboardReplacesBackground.BindTo(storyboardContainer.StoryboardReplacesBackground); + storyboardReplacesBackground.BindTo(Background.StoryboardReplacesBackground); + storyboardContainer.StoryboardReplacesBackground.BindTo(Background.StoryboardReplacesBackground); storyboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable; Task.Run(() => diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index 6b066fbe91..e358188fe9 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -159,7 +159,7 @@ namespace osu.Game.Screens.Play { // restore our screen defaults InitializeBackgroundElements(); - if (this.IsCurrentScreen() && (Background?.IsLoaded ?? false)) + if (this.IsCurrentScreen()) Background.EnableUserDim.Value = false; return base.OnHover(e); } @@ -168,7 +168,8 @@ namespace osu.Game.Screens.Play { if (GetContainingInputManager()?.HoveredDrawables.Contains(VisualSettings) == true) { - // show user setting preview + // Update background elements is only being called here because blur logic still exists in Player. + // Will need to be removed when resolving https://github.com/ppy/osu/issues/4322 UpdateBackgroundElements(); if (this.IsCurrentScreen()) Background.EnableUserDim.Value = true; @@ -245,8 +246,7 @@ namespace osu.Game.Screens.Play this.FadeOut(150); cancelLoad(); - if (Background != null) - Background.EnableUserDim.Value = false; + Background.EnableUserDim.Value = false; return base.OnExiting(next); } From a7585dea216a233f2b4e8feaf4101c9bf2d7b866 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Mon, 25 Feb 2019 22:17:51 +0900 Subject: [PATCH 46/69] Make screen stack readonly --- osu.Game.Tests/Visual/TestCasePlayerLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/TestCasePlayerLoader.cs b/osu.Game.Tests/Visual/TestCasePlayerLoader.cs index 3e3f9eb9f3..156393670d 100644 --- a/osu.Game.Tests/Visual/TestCasePlayerLoader.cs +++ b/osu.Game.Tests/Visual/TestCasePlayerLoader.cs @@ -14,7 +14,7 @@ namespace osu.Game.Tests.Visual public class TestCasePlayerLoader : ManualInputManagerTestCase { private PlayerLoader loader; - private ScreenStack stack; + private readonly ScreenStack stack; [Cached] private BackgroundScreenStack backgroundStack; From 14e427fed76a284cce4a9bbc6a93e5053c192e93 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Feb 2019 09:54:28 +0900 Subject: [PATCH 47/69] Rename some methods (they weren't Asserting) --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 51 +++++++------------ 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 7edacc7586..8002255b54 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -114,7 +114,7 @@ namespace osu.Game.Tests.Visual createSongSelect(); AddStep("Start player loader", () => songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer()))); AddUntilStep(() => playerLoader?.IsLoaded ?? false, "Wait for Player Loader to load"); - AddAssert("Background retained from song select", () => songSelect.AssertBackgroundCurrent()); + AddAssert("Background retained from song select", () => songSelect.IsBackgroundCurrent()); AddStep("Trigger background preview", () => { InputManager.MoveMouseTo(playerLoader.ScreenPos); @@ -122,7 +122,7 @@ namespace osu.Game.Tests.Visual }); AddWaitStep(5, "Wait for dim"); - AddAssert("Screen is dimmed", () => songSelect.AssertDimmed()); + AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed()); } /// @@ -142,14 +142,14 @@ namespace osu.Game.Tests.Visual InputManager.MoveMouseTo(playerLoader.ScreenPos); }); AddUntilStep(() => player?.IsLoaded ?? false, "Wait for player to load"); - AddAssert("Background retained from song select", () => songSelect.AssertBackgroundCurrent()); + AddAssert("Background retained from song select", () => songSelect.IsBackgroundCurrent()); AddStep("Trigger background preview when loaded", () => { InputManager.MoveMouseTo(playerLoader.VisualSettingsPos); InputManager.MoveMouseTo(playerLoader.ScreenPos); }); AddWaitStep(5, "Wait for dim"); - AddAssert("Screen is dimmed", () => songSelect.AssertDimmed()); + AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed()); } /// @@ -165,10 +165,10 @@ namespace osu.Game.Tests.Visual player.StoryboardEnabled.Value = true; }); AddWaitStep(5, "Wait for dim"); - AddAssert("Background is invisible", () => songSelect.AssertInvisible()); + AddAssert("Background is invisible", () => songSelect.IsBackgroundInvisible()); AddStep("Disable storyboard", () => player.ReplacesBackground.Value = false); AddWaitStep(5, "Wait for dim"); - AddAssert("Background is visible", () => songSelect.AssertVisible()); + AddAssert("Background is visible", () => songSelect.IsBackgroundVisible()); } /// @@ -193,7 +193,7 @@ namespace osu.Game.Tests.Visual return true; }, "Wait for song select is current"); AddWaitStep(5, "Wait for dim"); - AddAssert("Background is visible", () => songSelect.AssertVisible()); + AddAssert("Background is visible", () => songSelect.IsBackgroundVisible()); } /// @@ -205,7 +205,7 @@ namespace osu.Game.Tests.Visual performSetup(); AddStep("Test User Undimming", () => songSelect.DimEnabled.Value = false); AddWaitStep(5, "Wait for dim"); - AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed()); + AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed()); } /// @@ -217,7 +217,7 @@ namespace osu.Game.Tests.Visual performSetup(); AddStep("Test User Dimming", () => songSelect.DimEnabled.Value = true); AddWaitStep(5, "Wait for dim"); - AddAssert("Screen is dimmed", () => songSelect.AssertDimmed()); + AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed()); } /// @@ -233,7 +233,7 @@ namespace osu.Game.Tests.Visual player.Exit(); }); AddWaitStep(5, "Wait for dim"); - AddAssert("Screen is dimmed", () => songSelect.AssertDimmed()); + AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed()); } /// @@ -245,8 +245,8 @@ namespace osu.Game.Tests.Visual performSetup(); AddStep("Transition to Results", () => player.Push(new FadeAccesibleResults(new ScoreInfo { User = new User { Username = "osu!" }}))); AddWaitStep(5, "Wait for dim"); - AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed()); - AddAssert("Background retained from song select", () => songSelect.AssertBackgroundCurrent()); + AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed()); + AddAssert("Background retained from song select", () => songSelect.IsBackgroundCurrent()); } /// @@ -266,7 +266,7 @@ namespace osu.Game.Tests.Visual return true; }, "Wait for song select is current"); AddWaitStep(5, "Wait for dim"); - AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed()); + AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed()); } private class DummySongSelect : OsuScreen @@ -286,34 +286,19 @@ namespace osu.Game.Tests.Visual DimEnabled.BindTo(((FadeAccessibleBackground)Background).EnableUserDim); } - public bool AssertDimmed() - { - return ((FadeAccessibleBackground)Background).CurrentColour == OsuColour.Gray(1 - (float)dimLevel.Value); - } + public bool IsBackgroundDimmed() => ((FadeAccessibleBackground)Background).CurrentColour == OsuColour.Gray(1 - (float)dimLevel.Value); - public bool AssertUndimmed() - { - return ((FadeAccessibleBackground)Background).CurrentColour == Color4.White; - } + public bool IsBackgroundUndimmed() => ((FadeAccessibleBackground)Background).CurrentColour == Color4.White; - public bool AssertInvisible() - { - return ((FadeAccessibleBackground)Background).CurrentAlpha == 0; - } + public bool IsBackgroundInvisible() => ((FadeAccessibleBackground)Background).CurrentAlpha == 0; - public bool AssertVisible() - { - return ((FadeAccessibleBackground)Background).CurrentAlpha == 1; - } + public bool IsBackgroundVisible() => ((FadeAccessibleBackground)Background).CurrentAlpha == 1; /// /// Make sure every time a screen gets pushed, the background doesn't get replaced /// /// Whether or not the original background (The one created in DummySongSelect) is still the current background - public bool AssertBackgroundCurrent() - { - return ((FadeAccessibleBackground)Background).IsCurrentScreen(); - } + public bool IsBackgroundCurrent() => ((FadeAccessibleBackground)Background).IsCurrentScreen(); } private class FadeAccesibleResults : SoloResults From c58d305fc67540ddd44faefb0d80b327dba871db Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Feb 2019 09:56:22 +0900 Subject: [PATCH 48/69] private goes after public --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 81 ++++++++++--------- 1 file changed, 43 insertions(+), 38 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 8002255b54..046e8048b1 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -45,43 +45,9 @@ namespace osu.Game.Tests.Visual [Cached] private BackgroundScreenStack backgroundStack; - 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"); - } - - 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"); - AddUntilStep(() => - { - if (!songSelect.IsCurrentScreen()) - { - songSelect.MakeCurrent(); - return false; - } - return true; - }, "Wait for song select is current"); - } - public TestCaseBackgroundScreenBeatmap() { - InputManager.Add(backgroundStack = new BackgroundScreenStack {RelativeSizeAxes = Axes.Both}); + InputManager.Add(backgroundStack = new BackgroundScreenStack { RelativeSizeAxes = Axes.Both }); InputManager.Add(screen = new ScreenStack { RelativeSizeAxes = Axes.Both }); AddStep("Create beatmap", () => @@ -190,6 +156,7 @@ namespace osu.Game.Tests.Visual songSelect.MakeCurrent(); return false; } + return true; }, "Wait for song select is current"); AddWaitStep(5, "Wait for dim"); @@ -243,7 +210,7 @@ namespace osu.Game.Tests.Visual public void TransitionTest() { performSetup(); - AddStep("Transition to Results", () => player.Push(new FadeAccesibleResults(new ScoreInfo { User = new User { Username = "osu!" }}))); + AddStep("Transition to Results", () => player.Push(new FadeAccesibleResults(new ScoreInfo { User = new User { Username = "osu!" } }))); AddWaitStep(5, "Wait for dim"); AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed()); AddAssert("Background retained from song select", () => songSelect.IsBackgroundCurrent()); @@ -263,12 +230,48 @@ namespace osu.Game.Tests.Visual songSelect.MakeCurrent(); return false; } + return true; }, "Wait for song select is current"); AddWaitStep(5, "Wait for dim"); AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed()); } + 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"); + } + + 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"); + AddUntilStep(() => + { + if (!songSelect.IsCurrentScreen()) + { + songSelect.MakeCurrent(); + return false; + } + + return true; + }, "Wait for song select is current"); + } + private class DummySongSelect : OsuScreen { protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); @@ -303,7 +306,8 @@ namespace osu.Game.Tests.Visual private class FadeAccesibleResults : SoloResults { - public FadeAccesibleResults(ScoreInfo score) : base(score) + public FadeAccesibleResults(ScoreInfo score) + : base(score) { } @@ -337,7 +341,8 @@ namespace osu.Game.Tests.Visual public VisualSettings VisualSettingsPos => VisualSettings; public BackgroundScreen ScreenPos => Background; - public DimAccessiblePlayerLoader(Player player) : base(() => player) + public DimAccessiblePlayerLoader(Player player) + : base(() => player) { } From 217f692798e54e6c07a314430e6b8a6954b987c0 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Feb 2019 10:11:36 +0900 Subject: [PATCH 49/69] Extract wait logic into separate method Also reduces the required wait time. --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 046e8048b1..2fe6498a09 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -87,7 +87,7 @@ namespace osu.Game.Tests.Visual InputManager.MoveMouseTo(playerLoader.VisualSettingsPos); }); - AddWaitStep(5, "Wait for dim"); + waitForDim(); AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed()); } @@ -114,7 +114,7 @@ namespace osu.Game.Tests.Visual InputManager.MoveMouseTo(playerLoader.VisualSettingsPos); InputManager.MoveMouseTo(playerLoader.ScreenPos); }); - AddWaitStep(5, "Wait for dim"); + waitForDim(); AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed()); } @@ -130,10 +130,10 @@ namespace osu.Game.Tests.Visual player.ReplacesBackground.Value = true; player.StoryboardEnabled.Value = true; }); - AddWaitStep(5, "Wait for dim"); + waitForDim(); AddAssert("Background is invisible", () => songSelect.IsBackgroundInvisible()); AddStep("Disable storyboard", () => player.ReplacesBackground.Value = false); - AddWaitStep(5, "Wait for dim"); + waitForDim(); AddAssert("Background is visible", () => songSelect.IsBackgroundVisible()); } @@ -159,7 +159,7 @@ namespace osu.Game.Tests.Visual return true; }, "Wait for song select is current"); - AddWaitStep(5, "Wait for dim"); + waitForDim(); AddAssert("Background is visible", () => songSelect.IsBackgroundVisible()); } @@ -171,7 +171,7 @@ namespace osu.Game.Tests.Visual { performSetup(); AddStep("Test User Undimming", () => songSelect.DimEnabled.Value = false); - AddWaitStep(5, "Wait for dim"); + waitForDim(); AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed()); } @@ -183,7 +183,7 @@ namespace osu.Game.Tests.Visual { performSetup(); AddStep("Test User Dimming", () => songSelect.DimEnabled.Value = true); - AddWaitStep(5, "Wait for dim"); + waitForDim(); AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed()); } @@ -199,7 +199,7 @@ namespace osu.Game.Tests.Visual if (!player.IsPaused.Value) player.Exit(); }); - AddWaitStep(5, "Wait for dim"); + waitForDim(); AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed()); } @@ -211,7 +211,7 @@ namespace osu.Game.Tests.Visual { performSetup(); AddStep("Transition to Results", () => player.Push(new FadeAccesibleResults(new ScoreInfo { User = new User { Username = "osu!" } }))); - AddWaitStep(5, "Wait for dim"); + waitForDim(); AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed()); AddAssert("Background retained from song select", () => songSelect.IsBackgroundCurrent()); } @@ -233,10 +233,12 @@ namespace osu.Game.Tests.Visual return true; }, "Wait for song select is current"); - AddWaitStep(5, "Wait for dim"); + waitForDim(); AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed()); } + private void waitForDim() => AddWaitStep(3, "Wait for dim"); + private void performSetup() { createSongSelect(); From 3549369822540125889043728fc3d24209631be7 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Feb 2019 10:27:54 +0900 Subject: [PATCH 50/69] Restore previous wait time For whatever reason, this is required? --- osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 2fe6498a09..d05faec52c 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -237,7 +237,7 @@ namespace osu.Game.Tests.Visual AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed()); } - private void waitForDim() => AddWaitStep(3, "Wait for dim"); + private void waitForDim() => AddWaitStep(5, "Wait for dim"); private void performSetup() { From 60ecb99dfb9326759cdac72564d523c7f478454d Mon Sep 17 00:00:00 2001 From: David Zhao Date: Tue, 26 Feb 2019 17:31:21 +0900 Subject: [PATCH 51/69] Have test cases create a new screen stack each time --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 127 +++++++++--------- 1 file changed, 63 insertions(+), 64 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index d05faec52c..105bf28374 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -3,11 +3,14 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Threading; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Logging; using osu.Framework.Screens; using osu.Game.Beatmaps; using osu.Game.Configuration; @@ -34,42 +37,15 @@ namespace osu.Game.Tests.Visual typeof(ScreenWithBeatmapBackground), typeof(PlayerLoader), typeof(Player), - typeof(UserDimContainer) + typeof(UserDimContainer), + typeof(OsuScreen) }; private DummySongSelect songSelect; private DimAccessiblePlayerLoader playerLoader; private DimAccessiblePlayer player; - private readonly ScreenStack screen; - [Cached] - private BackgroundScreenStack backgroundStack; - - public TestCaseBackgroundScreenBeatmap() - { - InputManager.Add(backgroundStack = new BackgroundScreenStack { RelativeSizeAxes = Axes.Both }); - InputManager.Add(screen = new ScreenStack { RelativeSizeAxes = Axes.Both }); - - AddStep("Create beatmap", () => - { - Beatmap.Value = new TestWorkingBeatmap(new Beatmap - { - HitObjects = - { - new HitCircle - { - StartTime = 3000, - Position = new Vector2(0, 0), - }, - new HitCircle - { - StartTime = 15000, - Position = new Vector2(0, 0), - } - }, - }); - }); - } + private ScreenStackCacheContainer screenStackContainer; /// /// Check if PlayerLoader properly triggers background dim previews when a user hovers over the visual settings panel. @@ -100,7 +76,7 @@ namespace osu.Game.Tests.Visual public void PlayerLoaderTransitionTest() { createSongSelect(); - AddStep("Start player loader", () => songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer()))); + AddStep("Start player loader", () => { songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer())); }); AddUntilStep(() => playerLoader?.IsLoaded ?? false, "Wait for Player Loader to load"); AddStep("Allow beatmap to load", () => { @@ -151,13 +127,9 @@ namespace osu.Game.Tests.Visual }); AddUntilStep(() => { - if (!songSelect.IsCurrentScreen()) - { - songSelect.MakeCurrent(); - return false; - } - - return true; + if (songSelect.IsCurrentScreen()) return true; + songSelect.MakeCurrent(); + return false; }, "Wait for song select is current"); waitForDim(); AddAssert("Background is visible", () => songSelect.IsBackgroundVisible()); @@ -243,40 +215,57 @@ namespace osu.Game.Tests.Visual { createSongSelect(); - AddStep("Load new player to song select", () => songSelect.Push(player = new DimAccessiblePlayer { Ready = true })); + AddStep("Load new player to song select", () => songSelect.Push(player = new DimAccessiblePlayer + { + Ready = true, + AllowLeadIn = false, + AllowResults = false, + })); AddUntilStep(() => player?.IsLoaded ?? false, "Wait for player to load"); } private void createSongSelect() { - AddStep("Create song select if required", () => + AddStep("Create new screen stack", () => { - if (songSelect == null) - { - LoadComponentAsync(new DummySongSelect(), p => - { - songSelect = p; - screen.Push(p); - songSelect.UpdateBindables(); - }); - } + screenStackContainer = new ScreenStackCacheContainer { RelativeSizeAxes = Axes.Both }; + Child = screenStackContainer; }); - AddUntilStep(() => songSelect?.IsLoaded ?? false, "Wait for song select to load"); - AddUntilStep(() => + AddStep("Create song select", () => { - if (!songSelect.IsCurrentScreen()) + songSelect = new DummySongSelect(); + screenStackContainer.ScreenStack.Push(songSelect); + }); + AddStep("Create beatmap", () => + { + Beatmap.Value = new TestWorkingBeatmap(new Beatmap { - songSelect.MakeCurrent(); - return false; - } - - return true; - }, "Wait for song select is current"); + HitObjects = + { + new HitCircle + { + StartTime = 3000, + Position = new Vector2(0, 0), + }, + new HitCircle + { + StartTime = 15000, + Position = new Vector2(0, 0), + } + }, + }); + }); } private class DummySongSelect : OsuScreen { - protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); + protected override BackgroundScreen CreateBackground() + { + FadeAccessibleBackground background = new FadeAccessibleBackground(); + DimEnabled.BindTo(background.EnableUserDim); + return background; + } + public readonly Bindable DimEnabled = new Bindable(); private readonly Bindable dimLevel = new Bindable(); @@ -284,11 +273,7 @@ namespace osu.Game.Tests.Visual private void load(OsuConfigManager config) { config.BindWith(OsuSetting.DimLevel, dimLevel); - } - - public void UpdateBindables() - { - DimEnabled.BindTo(((FadeAccessibleBackground)Background).EnableUserDim); + Logger.Log(dimLevel.Value.ToString(CultureInfo.InvariantCulture)); } public bool IsBackgroundDimmed() => ((FadeAccessibleBackground)Background).CurrentColour == OsuColour.Gray(1 - (float)dimLevel.Value); @@ -338,6 +323,20 @@ namespace osu.Game.Tests.Visual } } + private class ScreenStackCacheContainer : Container + { + [Cached] + private BackgroundScreenStack backgroundScreenStack; + + public readonly ScreenStack ScreenStack; + + public ScreenStackCacheContainer() + { + Add(backgroundScreenStack = new BackgroundScreenStack { RelativeSizeAxes = Axes.Both }); + Add(ScreenStack = new ScreenStack { RelativeSizeAxes = Axes.Both }); + } + } + private class DimAccessiblePlayerLoader : PlayerLoader { public VisualSettings VisualSettingsPos => VisualSettings; From d23f399375af4d7b1a8c1f4c54181d9d56aeb949 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Tue, 26 Feb 2019 17:43:42 +0900 Subject: [PATCH 52/69] Add back song select wait --- osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 105bf28374..7e1d1c54d5 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -236,6 +236,7 @@ namespace osu.Game.Tests.Visual songSelect = new DummySongSelect(); screenStackContainer.ScreenStack.Push(songSelect); }); + AddUntilStep(() => songSelect?.IsLoaded ?? false, "Wait for song select to load"); AddStep("Create beatmap", () => { Beatmap.Value = new TestWorkingBeatmap(new Beatmap From 59fca568c9befbad42938fa1ee6448b657362a7a Mon Sep 17 00:00:00 2001 From: David Zhao Date: Tue, 26 Feb 2019 17:56:42 +0900 Subject: [PATCH 53/69] Remove null checks for synchronous loads --- osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 7e1d1c54d5..4c81cdc030 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -221,7 +221,7 @@ namespace osu.Game.Tests.Visual AllowLeadIn = false, AllowResults = false, })); - AddUntilStep(() => player?.IsLoaded ?? false, "Wait for player to load"); + AddUntilStep(() => player.IsLoaded, "Wait for player to load"); } private void createSongSelect() @@ -236,7 +236,7 @@ namespace osu.Game.Tests.Visual songSelect = new DummySongSelect(); screenStackContainer.ScreenStack.Push(songSelect); }); - AddUntilStep(() => songSelect?.IsLoaded ?? false, "Wait for song select to load"); + AddUntilStep(() => songSelect.IsLoaded, "Wait for song select to load"); AddStep("Create beatmap", () => { Beatmap.Value = new TestWorkingBeatmap(new Beatmap From ebec944bb84f6e24033205ad77561a8d310a353d Mon Sep 17 00:00:00 2001 From: David Zhao Date: Wed, 27 Feb 2019 14:15:45 +0900 Subject: [PATCH 54/69] Use actual song select for test case with beatmap import --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 100 +++++++++++------- 1 file changed, 59 insertions(+), 41 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 4c81cdc030..6d7e2ea19c 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -3,28 +3,30 @@ using System; using System.Collections.Generic; -using System.Globalization; +using System.Linq; using System.Threading; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Logging; +using osu.Framework.Platform; using osu.Framework.Screens; using osu.Game.Beatmaps; using osu.Game.Configuration; +using osu.Game.Database; using osu.Game.Graphics; using osu.Game.Graphics.Containers; -using osu.Game.Rulesets.Osu.Objects; +using osu.Game.Rulesets; +using osu.Game.Rulesets.Osu.Mods; using osu.Game.Scoring; using osu.Game.Screens; using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Play; using osu.Game.Screens.Play.PlayerSettings; -using osu.Game.Tests.Beatmaps; +using osu.Game.Screens.Select; +using osu.Game.Tests.Resources; using osu.Game.Users; -using osuTK; using osuTK.Graphics; namespace osu.Game.Tests.Visual @@ -44,9 +46,36 @@ namespace osu.Game.Tests.Visual private DummySongSelect songSelect; private DimAccessiblePlayerLoader playerLoader; private DimAccessiblePlayer player; + private DatabaseContextFactory factory; + private BeatmapManager manager; + private RulesetStore rulesets; private ScreenStackCacheContainer screenStackContainer; + [BackgroundDependencyLoader] + private void load(GameHost host) + { + factory = new DatabaseContextFactory(LocalStorage); + factory.ResetDatabase(); + + using (var usage = factory.Get()) + usage.Migrate(); + + factory.ResetDatabase(); + + using (var usage = factory.Get()) + usage.Migrate(); + + Dependencies.Cache(rulesets = new RulesetStore(factory)); + Dependencies.Cache(manager = new BeatmapManager(LocalStorage, factory, rulesets, null, null, host, Beatmap.Default)); + + Beatmap.SetDefault(); + } + + [SetUp] + public virtual void SetUp() => + Schedule(() => { manager?.Delete(manager.GetAllUsableBeatmapSets()); }); + /// /// Check if PlayerLoader properly triggers background dim previews when a user hovers over the visual settings panel. /// @@ -215,54 +244,37 @@ namespace osu.Game.Tests.Visual { createSongSelect(); - AddStep("Load new player to song select", () => songSelect.Push(player = new DimAccessiblePlayer + AddStep("Start player loader", () => { songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer { - Ready = true, AllowLeadIn = false, AllowResults = false, - })); + Ready = true, + })); }); + AddUntilStep(() => playerLoader.IsLoaded, "Wait for Player Loader to load"); + AddStep("Move mouse to center of screen", () => InputManager.MoveMouseTo(playerLoader.ScreenPos)); AddUntilStep(() => player.IsLoaded, "Wait for player to load"); } private void createSongSelect() { - AddStep("Create new screen stack", () => - { - screenStackContainer = new ScreenStackCacheContainer { RelativeSizeAxes = Axes.Both }; - Child = screenStackContainer; - }); - AddStep("Create song select", () => - { - songSelect = new DummySongSelect(); - screenStackContainer.ScreenStack.Push(songSelect); - }); + 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())); AddUntilStep(() => songSelect.IsLoaded, "Wait for song select to load"); - AddStep("Create beatmap", () => + AddStep("Add map", () => { - Beatmap.Value = new TestWorkingBeatmap(new Beatmap - { - HitObjects = - { - new HitCircle - { - StartTime = 3000, - Position = new Vector2(0, 0), - }, - new HitCircle - { - StartTime = 15000, - Position = new Vector2(0, 0), - } - }, - }); + var temp = TestResources.GetTestBeatmapForImport(); + manager.Import(temp); + Beatmap.Value.Mods.Value = Beatmap.Value.Mods.Value.Concat(new[] { new OsuModNoFail() }); }); + AddUntilStep(() => songSelect.Carousel.SelectedBeatmap != null, "has selection"); } - private class DummySongSelect : OsuScreen + private class DummySongSelect : PlaySongSelect { protected override BackgroundScreen CreateBackground() { - FadeAccessibleBackground background = new FadeAccessibleBackground(); + FadeAccessibleBackground background = new FadeAccessibleBackground(Beatmap.Value); DimEnabled.BindTo(background.EnableUserDim); return background; } @@ -270,11 +282,12 @@ namespace osu.Game.Tests.Visual public readonly Bindable DimEnabled = new Bindable(); private readonly Bindable dimLevel = new Bindable(); + public new BeatmapCarousel Carousel => base.Carousel; + [BackgroundDependencyLoader] private void load(OsuConfigManager config) { config.BindWith(OsuSetting.DimLevel, dimLevel); - Logger.Log(dimLevel.Value.ToString(CultureInfo.InvariantCulture)); } public bool IsBackgroundDimmed() => ((FadeAccessibleBackground)Background).CurrentColour == OsuColour.Gray(1 - (float)dimLevel.Value); @@ -299,12 +312,12 @@ namespace osu.Game.Tests.Visual { } - protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); + protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(Beatmap.Value); } private class DimAccessiblePlayer : Player { - protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); + protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(Beatmap.Value); // Whether or not the player should be allowed to load. public bool Ready; @@ -348,7 +361,7 @@ namespace osu.Game.Tests.Visual { } - protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); + protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(Beatmap.Value); } private class FadeAccessibleBackground : BackgroundScreenBeatmap @@ -358,6 +371,11 @@ namespace osu.Game.Tests.Visual public Color4 CurrentColour => ((TestUserDimContainer)FadeContainer).CurrentColour; public float CurrentAlpha => ((TestUserDimContainer)FadeContainer).CurrentAlpha; + public FadeAccessibleBackground(WorkingBeatmap beatmap) + : base(beatmap) + { + } + private class TestUserDimContainer : UserDimContainer { public Color4 CurrentColour => DimContainer.Colour; From 14ffd9efe834d7fca72b871daa5012fa5ad5b3ef Mon Sep 17 00:00:00 2001 From: David Zhao Date: Wed, 27 Feb 2019 17:02:04 +0900 Subject: [PATCH 55/69] 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() From 882fff16312ff6bcb73b30c3d687a970bc5cd79c Mon Sep 17 00:00:00 2001 From: David Zhao Date: Wed, 27 Feb 2019 17:56:44 +0900 Subject: [PATCH 56/69] 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) From 246240e93635faeb0bd172eb31699d7033500ba4 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Wed, 27 Feb 2019 18:04:33 +0900 Subject: [PATCH 57/69] Remove unused includes --- osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 44d2bce0e6..47ea1a0213 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -11,7 +11,6 @@ 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; @@ -29,7 +28,6 @@ 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 From e5607d7711be01085c6dd1ddc72d89d4c76b26aa Mon Sep 17 00:00:00 2001 From: David Zhao Date: Thu, 28 Feb 2019 14:33:29 +0900 Subject: [PATCH 58/69] Add back "THIS IS A STORYBOARD" storyboard --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 47ea1a0213..9198e60bcb 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -10,7 +10,7 @@ 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; @@ -249,10 +249,14 @@ namespace osu.Game.Tests.Visual { player.ReplacesBackground.Value = true; player.StoryboardEnabled.Value = true; - player.CurrentStoryboardContainer.Add(new Box + player.CurrentStoryboardContainer.Add(new SpriteText { + Size = new Vector2(250, 50), Alpha = 1, - Colour = Color4.Tomato + Colour = Color4.White, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Text = "THIS IS A STORYBOARD", }); }); From 4ceafef79c877dbe25bbfc7685e58f79139c0aa9 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Thu, 28 Feb 2019 14:40:31 +0900 Subject: [PATCH 59/69] Add missing reference --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 9198e60bcb..2a6bb4e691 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -28,6 +28,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 @@ -123,11 +124,9 @@ namespace osu.Game.Tests.Visual }); AddUntilStep(() => player?.IsLoaded ?? false, "Wait for player to load"); AddAssert("Background retained from song select", () => songSelect.IsBackgroundCurrent()); - AddStep("Trigger background preview when loaded", () => - { - InputManager.MoveMouseTo(playerLoader.VisualSettingsPos); - InputManager.MoveMouseTo(playerLoader.ScreenPos); - }); + AddStep("Trigger background preview when loaded", () => InputManager.MoveMouseTo(playerLoader.VisualSettingsPos)); + AddWaitStep(1); + AddStep("Untrigger background preview", () => InputManager.MoveMouseTo(playerLoader.ScreenPos)); waitForDim(); AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed()); } @@ -310,6 +309,7 @@ namespace osu.Game.Tests.Visual 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; From dbe5887f7e3f19130e724fb87d73f8c7631e2fda Mon Sep 17 00:00:00 2001 From: David Zhao Date: Thu, 28 Feb 2019 16:18:46 +0900 Subject: [PATCH 60/69] Fix issue for user hover blur for now by checking for current screen, fix test. --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 2a6bb4e691..bec113430b 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -11,6 +11,8 @@ using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; +using osu.Framework.Input.Events; +using osu.Framework.Input.States; using osu.Framework.Platform; using osu.Framework.Screens; using osu.Game.Beatmaps; @@ -123,12 +125,11 @@ namespace osu.Game.Tests.Visual InputManager.MoveMouseTo(playerLoader.ScreenPos); }); AddUntilStep(() => player?.IsLoaded ?? false, "Wait for player to load"); + AddStep("Trigger hover event", () => playerLoader.TriggerOnHover()); AddAssert("Background retained from song select", () => songSelect.IsBackgroundCurrent()); - AddStep("Trigger background preview when loaded", () => InputManager.MoveMouseTo(playerLoader.VisualSettingsPos)); - AddWaitStep(1); - AddStep("Untrigger background preview", () => InputManager.MoveMouseTo(playerLoader.ScreenPos)); waitForDim(); AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed()); + AddAssert("Screen is unblurred", () => songSelect.IsBackgroundUnblurred()); } /// @@ -252,7 +253,7 @@ namespace osu.Game.Tests.Visual { Size = new Vector2(250, 50), Alpha = 1, - Colour = Color4.White, + Colour = Color4.Tomato, Anchor = Anchor.Centre, Origin = Anchor.Centre, Text = "THIS IS A STORYBOARD", @@ -285,6 +286,7 @@ namespace osu.Game.Tests.Visual { Beatmap.Value.Mods.Value = Beatmap.Value.Mods.Value.Concat(new[] { new OsuModNoFail() }); songSelect.DimLevel.Value = 0.7f; + songSelect.BlurLevel.Value = 0.0f; }); AddUntilStep(() => songSelect.Carousel.SelectedBeatmap != null, "Song select has selection"); } @@ -300,6 +302,7 @@ namespace osu.Game.Tests.Visual public readonly Bindable DimEnabled = new Bindable(); public readonly Bindable DimLevel = new Bindable(); + public readonly Bindable BlurLevel = new Bindable(); public new BeatmapCarousel Carousel => base.Carousel; @@ -307,11 +310,13 @@ namespace osu.Game.Tests.Visual private void load(OsuConfigManager config) { config.BindWith(OsuSetting.DimLevel, DimLevel); + config.BindWith(OsuSetting.BlurLevel, BlurLevel); } - //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 IsBackgroundUnblurred() => ((FadeAccessibleBackground)Background).CurrentBlur == new Vector2(0); + public bool IsBackgroundUndimmed() => ((FadeAccessibleBackground)Background).CurrentColour == Color4.White; public bool IsBackgroundInvisible() => ((FadeAccessibleBackground)Background).CurrentAlpha == 0; @@ -396,6 +401,11 @@ namespace osu.Game.Tests.Visual { } + public void TriggerOnHover() + { + OnHover(new HoverEvent(new InputState())); + } + protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(Beatmap.Value); } @@ -406,6 +416,8 @@ namespace osu.Game.Tests.Visual public Color4 CurrentColour => ((TestUserDimContainer)FadeContainer).CurrentColour; public float CurrentAlpha => ((TestUserDimContainer)FadeContainer).CurrentAlpha; + public Vector2 CurrentBlur => Background.BlurSigma; + public FadeAccessibleBackground(WorkingBeatmap beatmap) : base(beatmap) { From 69b1c76dce86e928c8ead423c78fea902542aefb Mon Sep 17 00:00:00 2001 From: David Zhao Date: Thu, 28 Feb 2019 16:51:17 +0900 Subject: [PATCH 61/69] Actually implement blurring fix --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 20 ++++++++++++------- osu.Game.Tests/Visual/TestCasePlayerLoader.cs | 2 +- .../Graphics/Containers/UserDimContainer.cs | 4 ++-- .../Backgrounds/BackgroundScreenBeatmap.cs | 1 + osu.Game/Screens/Play/PlayerLoader.cs | 5 ++++- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index bec113430b..4ef52ec712 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -162,6 +162,7 @@ namespace osu.Game.Tests.Visual AddUntilStep(() => { if (songSelect.IsCurrentScreen()) return true; + songSelect.MakeCurrent(); return false; }, "Wait for song select is current"); @@ -264,13 +265,16 @@ namespace osu.Game.Tests.Visual { createSongSelect(); - AddStep("Start player loader", () => { songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer + AddStep("Start player loader", () => { - AllowLeadIn = false, - AllowResults = false, - AllowPause = allowPause, - Ready = true, - })); }); + songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer + { + AllowLeadIn = false, + AllowResults = false, + AllowPause = allowPause, + Ready = true, + })); + }); AddUntilStep(() => playerLoader.IsLoaded, "Wait for Player Loader to load"); AddStep("Move mouse to center of screen", () => InputManager.MoveMouseTo(playerLoader.ScreenPos)); AddUntilStep(() => player.IsLoaded, "Wait for player to load"); @@ -279,7 +283,7 @@ namespace osu.Game.Tests.Visual private void createSongSelect() { AddStep("Create new screen stack", () => Child = screenStackContainer = new ScreenStackCacheContainer { RelativeSizeAxes = Axes.Both }); - AddUntilStep(() => screenStackContainer.IsLoaded,"Wait for screen stack creation"); + AddUntilStep(() => screenStackContainer.IsLoaded, "Wait for screen stack creation"); AddStep("Create new song select", () => screenStackContainer.ScreenStack.Push(songSelect = new DummySongSelect())); AddUntilStep(() => songSelect.IsLoaded, "Wait for song select to load"); AddStep("Set user settings", () => @@ -355,6 +359,7 @@ namespace osu.Game.Tests.Visual } public UserDimContainer CurrentStoryboardContainer => StoryboardContainer; + // Whether or not the player should be allowed to load. public bool Ready; @@ -430,6 +435,7 @@ namespace osu.Game.Tests.Visual : base(isStoryboard) { } + public Color4 CurrentColour => DimContainer.Colour; public float CurrentAlpha => DimContainer.Alpha; } diff --git a/osu.Game.Tests/Visual/TestCasePlayerLoader.cs b/osu.Game.Tests/Visual/TestCasePlayerLoader.cs index 156393670d..244f553e97 100644 --- a/osu.Game.Tests/Visual/TestCasePlayerLoader.cs +++ b/osu.Game.Tests/Visual/TestCasePlayerLoader.cs @@ -21,7 +21,7 @@ namespace osu.Game.Tests.Visual public TestCasePlayerLoader() { - InputManager.Add(backgroundStack = new BackgroundScreenStack {RelativeSizeAxes = Axes.Both}); + InputManager.Add(backgroundStack = new BackgroundScreenStack { RelativeSizeAxes = Axes.Both }); InputManager.Add(stack = new ScreenStack { RelativeSizeAxes = Axes.Both }); } diff --git a/osu.Game/Graphics/Containers/UserDimContainer.cs b/osu.Game/Graphics/Containers/UserDimContainer.cs index 5aa0cad148..6e3b9c0d79 100644 --- a/osu.Game/Graphics/Containers/UserDimContainer.cs +++ b/osu.Game/Graphics/Containers/UserDimContainer.cs @@ -57,8 +57,8 @@ namespace osu.Game.Graphics.Containers { DimLevel = config.GetBindable(OsuSetting.DimLevel); ShowStoryboard = config.GetBindable(OsuSetting.ShowStoryboard); - EnableUserDim.ValueChanged += _ => updateBackgroundDim(); - DimLevel.ValueChanged += _ => updateBackgroundDim(); + EnableUserDim.ValueChanged += _ => updateBackgroundDim(); + DimLevel.ValueChanged += _ => updateBackgroundDim(); ShowStoryboard.ValueChanged += _ => updateBackgroundDim(); StoryboardReplacesBackground.ValueChanged += _ => updateBackgroundDim(); } diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 382c3f57ba..5ccff7b93b 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -48,6 +48,7 @@ namespace osu.Game.Screens.Backgrounds Background.FadeOut(250); Background.Expire(); } + b.Depth = newDepth; FadeContainer.Add(Background = b); Background.BlurSigma = BlurTarget; diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index e358188fe9..5c9acade7b 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -158,9 +158,12 @@ namespace osu.Game.Screens.Play protected override bool OnHover(HoverEvent e) { // restore our screen defaults - InitializeBackgroundElements(); if (this.IsCurrentScreen()) + { + InitializeBackgroundElements(); Background.EnableUserDim.Value = false; + } + return base.OnHover(e); } From 99812bd448b8ee7a28660eba80adee368db9587a Mon Sep 17 00:00:00 2001 From: Dan Balasescu <1329837+smoogipoo@users.noreply.github.com> Date: Thu, 28 Feb 2019 18:25:58 +0900 Subject: [PATCH 62/69] Apply suggestions from code review Co-Authored-By: nyquillerium --- osu.Game/Graphics/Containers/UserDimContainer.cs | 9 +++++---- osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs | 6 +++--- osu.Game/Screens/Play/Player.cs | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/osu.Game/Graphics/Containers/UserDimContainer.cs b/osu.Game/Graphics/Containers/UserDimContainer.cs index 6e3b9c0d79..25a81b011d 100644 --- a/osu.Game/Graphics/Containers/UserDimContainer.cs +++ b/osu.Game/Graphics/Containers/UserDimContainer.cs @@ -16,9 +16,9 @@ namespace osu.Game.Graphics.Containers /// public class UserDimContainer : Container { - protected Bindable DimLevel; + protected Bindable DimLevel { get; private set; } - protected Bindable ShowStoryboard; + protected Bindable ShowStoryboard { get; private set; } /// /// Whether or not user-configured dim levels should be applied to the container. @@ -28,9 +28,9 @@ namespace osu.Game.Graphics.Containers /// /// Whether or not the storyboard loaded should completely hide the background behind it. /// - public Bindable StoryboardReplacesBackground = new Bindable(); + public readonly Bindable StoryboardReplacesBackground = new Bindable(); - protected Container DimContainer; + protected Container DimContainer { get; private set; } protected override Container Content => DimContainer; @@ -39,6 +39,7 @@ namespace osu.Game.Graphics.Containers private const float background_fade_duration = 800; /// + /// Creates a new . /// /// /// Whether or not this instance of UserDimContainer contains a storyboard. diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 9fb452e15d..9333685e6c 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -18,11 +18,11 @@ namespace osu.Game.Screens.Backgrounds /// /// Whether or not user dim settings should be applied to this Background. /// - public Bindable EnableUserDim = new Bindable(); + public readonly Bindable EnableUserDim = new Bindable(); - public Bindable StoryboardReplacesBackground = new Bindable(); + public readonly Bindable StoryboardReplacesBackground = new Bindable(); - protected UserDimContainer FadeContainer; + protected UserDimContainer FadeContainer { get; private set; } protected virtual UserDimContainer CreateFadeContainer() => new UserDimContainer { RelativeSizeAxes = Axes.Both }; diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 2f5d776244..2880013b32 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; - protected UserDimContainer StoryboardContainer; + protected UserDimContainer StoryboardContainer { get; private set; } protected virtual UserDimContainer CreateStoryboardContainer() => new UserDimContainer(true) { @@ -358,7 +358,7 @@ namespace osu.Game.Screens.Play Background.EnableUserDim.Value = true; storyboardReplacesBackground.BindTo(Background.StoryboardReplacesBackground); - StoryboardContainer.StoryboardReplacesBackground.BindTo(Background.StoryboardReplacesBackground); + StoryboardContainer.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground); storyboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable; Task.Run(() => From 19d529c1c8ee1c764c7835a4936577f84eb6c7e5 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Thu, 28 Feb 2019 18:26:41 +0900 Subject: [PATCH 63/69] Move test steps into setup --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 4ef52ec712..ab8d039a40 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -85,6 +85,8 @@ namespace osu.Game.Tests.Visual manager.Delete(manager.GetAllUsableBeatmapSets()); var temp = TestResources.GetTestBeatmapForImport(); manager.Import(temp); + Child = screenStackContainer = new ScreenStackCacheContainer { RelativeSizeAxes = Axes.Both }; + screenStackContainer.ScreenStack.Push(songSelect = new DummySongSelect()); }); } @@ -94,7 +96,7 @@ namespace osu.Game.Tests.Visual [Test] public void PlayerLoaderSettingsHoverTest() { - createSongSelect(); + setupUserSettings(); AddStep("Start player loader", () => songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer()))); AddUntilStep(() => playerLoader?.IsLoaded ?? false, "Wait for Player Loader to load"); AddAssert("Background retained from song select", () => songSelect.IsBackgroundCurrent()); @@ -116,7 +118,7 @@ namespace osu.Game.Tests.Visual [Test] public void PlayerLoaderTransitionTest() { - createSongSelect(); + setupUserSettings(); AddStep("Start player loader", () => { songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer())); }); AddUntilStep(() => playerLoader?.IsLoaded ?? false, "Wait for Player Loader to load"); AddStep("Allow beatmap to load", () => @@ -138,7 +140,7 @@ namespace osu.Game.Tests.Visual [Test] public void StoryboardBackgroundVisibilityTest() { - performSetup(); + performFullSetup(); createFakeStoryboard(); waitForDim(); AddAssert("Background is invisible, storyboard is visible", () => songSelect.IsBackgroundInvisible() && player.IsStoryboardVisible()); @@ -157,7 +159,7 @@ namespace osu.Game.Tests.Visual [Test] public void StoryboardTransitionTest() { - performSetup(); + performFullSetup(); createFakeStoryboard(); AddUntilStep(() => { @@ -176,7 +178,7 @@ namespace osu.Game.Tests.Visual [Test] public void DisableUserDimTest() { - performSetup(); + performFullSetup(); AddStep("Test User Undimming", () => songSelect.DimEnabled.Value = false); waitForDim(); AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed()); @@ -188,7 +190,7 @@ namespace osu.Game.Tests.Visual [Test] public void EnableUserDimTest() { - performSetup(); + performFullSetup(); AddStep("Test User Dimming", () => songSelect.DimEnabled.Value = true); waitForDim(); AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed()); @@ -200,7 +202,7 @@ namespace osu.Game.Tests.Visual [Test] public void PauseTest() { - performSetup(true); + performFullSetup(true); AddStep("Transition to Pause", () => { if (!player.IsPaused.Value) @@ -216,7 +218,7 @@ namespace osu.Game.Tests.Visual [Test] public void TransitionTest() { - performSetup(); + performFullSetup(); AddStep("Transition to Results", () => player.Push(new FadeAccesibleResults(new ScoreInfo { User = new User { Username = "osu!" } }))); waitForDim(); AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed()); @@ -229,7 +231,7 @@ namespace osu.Game.Tests.Visual [Test] public void TransitionOutTest() { - performSetup(); + performFullSetup(); AddUntilStep(() => { if (!songSelect.IsCurrentScreen()) @@ -261,9 +263,9 @@ namespace osu.Game.Tests.Visual }); }); - private void performSetup(bool allowPause = false) + private void performFullSetup(bool allowPause = false) { - createSongSelect(); + setupUserSettings(); AddStep("Start player loader", () => { @@ -280,19 +282,15 @@ namespace osu.Game.Tests.Visual AddUntilStep(() => player.IsLoaded, "Wait for player to load"); } - private void createSongSelect() + private void setupUserSettings() { - 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())); - AddUntilStep(() => songSelect.IsLoaded, "Wait for song select to load"); - AddStep("Set user settings", () => + AddUntilStep(() => songSelect.Carousel.SelectedBeatmap != null, "Song select has selection"); + AddStep("Set default user settings", () => { Beatmap.Value.Mods.Value = Beatmap.Value.Mods.Value.Concat(new[] { new OsuModNoFail() }); songSelect.DimLevel.Value = 0.7f; songSelect.BlurLevel.Value = 0.0f; }); - AddUntilStep(() => songSelect.Carousel.SelectedBeatmap != null, "Song select has selection"); } private class DummySongSelect : PlaySongSelect From e3338e94d1def591ca114382ca9e1d2b5fce5d78 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Thu, 28 Feb 2019 20:01:15 +0900 Subject: [PATCH 64/69] Make test cases more compact, add two way toggles --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 113 +++++++----------- .../Graphics/Containers/UserDimContainer.cs | 9 +- .../Backgrounds/BackgroundScreenBeatmap.cs | 12 +- osu.Game/Screens/Play/Player.cs | 26 ++-- 4 files changed, 66 insertions(+), 94 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index ab8d039a40..d850c58f09 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -91,7 +91,7 @@ namespace osu.Game.Tests.Visual } /// - /// Check if PlayerLoader properly triggers background dim previews when a user hovers over the visual settings panel. + /// Check if properly triggers background dim previews when a user hovers over the visual settings panel. /// [Test] public void PlayerLoaderSettingsHoverTest() @@ -105,9 +105,11 @@ namespace osu.Game.Tests.Visual InputManager.MoveMouseTo(playerLoader.ScreenPos); InputManager.MoveMouseTo(playerLoader.VisualSettingsPos); }); - waitForDim(); AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed()); + AddStep("Stop background preview", () => InputManager.MoveMouseTo(playerLoader.ScreenPos)); + waitForDim(); + AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed()); } /// @@ -118,20 +120,11 @@ namespace osu.Game.Tests.Visual [Test] public void PlayerLoaderTransitionTest() { - setupUserSettings(); - AddStep("Start player loader", () => { songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer())); }); - AddUntilStep(() => playerLoader?.IsLoaded ?? false, "Wait for Player Loader to load"); - AddStep("Allow beatmap to load", () => - { - player.Ready = true; - InputManager.MoveMouseTo(playerLoader.ScreenPos); - }); - AddUntilStep(() => player?.IsLoaded ?? false, "Wait for player to load"); + performFullSetup(); AddStep("Trigger hover event", () => playerLoader.TriggerOnHover()); AddAssert("Background retained from song select", () => songSelect.IsBackgroundCurrent()); waitForDim(); - AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed()); - AddAssert("Screen is unblurred", () => songSelect.IsBackgroundUnblurred()); + AddAssert("Screen is dimmed and unblurred", () => songSelect.IsBackgroundDimmed() && songSelect.IsBackgroundUnblurred()); } /// @@ -142,9 +135,14 @@ namespace osu.Game.Tests.Visual { performFullSetup(); createFakeStoryboard(); + AddStep("Storyboard Enabled", () => + { + player.ReplacesBackground.Value = true; + player.StoryboardEnabled.Value = true; + }); waitForDim(); AddAssert("Background is invisible, storyboard is visible", () => songSelect.IsBackgroundInvisible() && player.IsStoryboardVisible()); - AddStep("Disable storyboard", () => + AddStep("Storyboard Disabled", () => { player.ReplacesBackground.Value = false; player.StoryboardEnabled.Value = false; @@ -161,37 +159,24 @@ namespace osu.Game.Tests.Visual { performFullSetup(); createFakeStoryboard(); - AddUntilStep(() => - { - if (songSelect.IsCurrentScreen()) return true; - - songSelect.MakeCurrent(); - return false; - }, "Wait for song select is current"); + AddStep("Exit to song select", () => player.Exit()); waitForDim(); AddAssert("Background is visible", () => songSelect.IsBackgroundVisible()); } /// - /// Check if the fade container is properly being reset when screen dim is disabled. + /// Check if the is properly accepting user dim changes at all. /// [Test] public void DisableUserDimTest() { performFullSetup(); - AddStep("Test User Undimming", () => songSelect.DimEnabled.Value = false); + waitForDim(); + AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed()); + AddStep("EnableUserDim disabled", () => songSelect.DimEnabled.Value = false); waitForDim(); AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed()); - } - - /// - /// Check if the fade container is properly being faded when screen dim is enabled. - /// - [Test] - public void EnableUserDimTest() - { - performFullSetup(); - AddStep("Test User Dimming", () => songSelect.DimEnabled.Value = true); + AddStep("EnableUserDim enabled", () => songSelect.DimEnabled.Value = true); waitForDim(); AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed()); } @@ -203,55 +188,44 @@ namespace osu.Game.Tests.Visual public void PauseTest() { performFullSetup(true); - AddStep("Transition to Pause", () => - { - if (!player.IsPaused.Value) - player.Exit(); - }); + AddStep("Pause", () => player.CurrentPauseContainer.Pause()); + waitForDim(); + AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed()); + AddStep("Unpause", () => player.CurrentPauseContainer.Resume()); waitForDim(); AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed()); } /// - /// Check if the fade container removes user dim when suspending player for results + /// Check if the fade container removes user dim when suspending for /// [Test] public void TransitionTest() { performFullSetup(); - AddStep("Transition to Results", () => player.Push(new FadeAccesibleResults(new ScoreInfo { User = new User { Username = "osu!" } }))); + AddStep("Transition to Results", () => player.Push(new FadeAccessibleResults(new ScoreInfo { User = new User { Username = "osu!" } }))); waitForDim(); - AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed()); - AddAssert("Background retained from song select", () => songSelect.IsBackgroundCurrent()); + AddAssert("Screen is undimmed and is original background", () => songSelect.IsBackgroundUndimmed() && songSelect.IsBackgroundCurrent()); } /// - /// Check if background gets undimmed when leaving the player for the previous screen + /// Check if background gets undimmed when leaving for /// [Test] public void TransitionOutTest() { performFullSetup(); - AddUntilStep(() => - { - if (!songSelect.IsCurrentScreen()) - { - songSelect.MakeCurrent(); - return false; - } - - return true; - }, "Wait for song select is current"); + AddStep("Exit to song select", () => player.Exit()); waitForDim(); AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed()); } private void waitForDim() => AddWaitStep(5, "Wait for dim"); - private void createFakeStoryboard() => AddStep("Enable storyboard", () => + private void createFakeStoryboard() => AddStep("Create storyboard", () => { - player.ReplacesBackground.Value = true; - player.StoryboardEnabled.Value = true; + player.StoryboardEnabled.Value = false; + player.ReplacesBackground.Value = false; player.CurrentStoryboardContainer.Add(new SpriteText { Size = new Vector2(250, 50), @@ -271,8 +245,6 @@ namespace osu.Game.Tests.Visual { songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer { - AllowLeadIn = false, - AllowResults = false, AllowPause = allowPause, Ready = true, })); @@ -332,9 +304,9 @@ namespace osu.Game.Tests.Visual public bool IsBackgroundCurrent() => ((FadeAccessibleBackground)Background).IsCurrentScreen(); } - private class FadeAccesibleResults : SoloResults + private class FadeAccessibleResults : SoloResults { - public FadeAccesibleResults(ScoreInfo score) + public FadeAccessibleResults(ScoreInfo score) : base(score) { } @@ -356,6 +328,8 @@ namespace osu.Game.Tests.Visual }; } + public PauseContainer CurrentPauseContainer => PauseContainer; + public UserDimContainer CurrentStoryboardContainer => StoryboardContainer; // Whether or not the player should be allowed to load. @@ -404,23 +378,22 @@ namespace osu.Game.Tests.Visual { } - public void TriggerOnHover() - { - OnHover(new HoverEvent(new InputState())); - } + public void TriggerOnHover() => OnHover(new HoverEvent(new InputState())); protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(Beatmap.Value); } private class FadeAccessibleBackground : BackgroundScreenBeatmap { - protected override UserDimContainer CreateFadeContainer() => new TestUserDimContainer { RelativeSizeAxes = Axes.Both }; + protected override UserDimContainer CreateFadeContainer() => fadeContainer = new TestUserDimContainer { RelativeSizeAxes = Axes.Both }; - public Color4 CurrentColour => ((TestUserDimContainer)FadeContainer).CurrentColour; - public float CurrentAlpha => ((TestUserDimContainer)FadeContainer).CurrentAlpha; + public Color4 CurrentColour => fadeContainer.CurrentColour; + public float CurrentAlpha => fadeContainer.CurrentAlpha; public Vector2 CurrentBlur => Background.BlurSigma; + private TestUserDimContainer fadeContainer; + public FadeAccessibleBackground(WorkingBeatmap beatmap) : base(beatmap) { @@ -429,13 +402,13 @@ namespace osu.Game.Tests.Visual private class TestUserDimContainer : UserDimContainer { + public Color4 CurrentColour => DimContainer.Colour; + public float CurrentAlpha => DimContainer.Alpha; + public TestUserDimContainer(bool isStoryboard = false) : base(isStoryboard) { } - - public Color4 CurrentColour => DimContainer.Colour; - public float CurrentAlpha => DimContainer.Alpha; } } } diff --git a/osu.Game/Graphics/Containers/UserDimContainer.cs b/osu.Game/Graphics/Containers/UserDimContainer.cs index 25a81b011d..e70bec1d2d 100644 --- a/osu.Game/Graphics/Containers/UserDimContainer.cs +++ b/osu.Game/Graphics/Containers/UserDimContainer.cs @@ -16,6 +16,8 @@ namespace osu.Game.Graphics.Containers /// public class UserDimContainer : Container { + private const float background_fade_duration = 800; + protected Bindable DimLevel { get; private set; } protected Bindable ShowStoryboard { get; private set; } @@ -30,14 +32,12 @@ namespace osu.Game.Graphics.Containers /// public readonly Bindable StoryboardReplacesBackground = new Bindable(); - protected Container DimContainer { get; private set; } + protected Container DimContainer { get; } protected override Container Content => DimContainer; private readonly bool isStoryboard; - private const float background_fade_duration = 800; - /// /// Creates a new . /// @@ -48,9 +48,8 @@ namespace osu.Game.Graphics.Containers /// public UserDimContainer(bool isStoryboard = false) { - DimContainer = new Container { RelativeSizeAxes = Axes.Both }; this.isStoryboard = isStoryboard; - AddInternal(DimContainer); + AddInternal(DimContainer = new Container { RelativeSizeAxes = Axes.Both }); } [BackgroundDependencyLoader] diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 9333685e6c..5883f61982 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -8,6 +8,7 @@ using osu.Framework.Graphics.Textures; using osu.Game.Beatmaps; using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Containers; +using osu.Game.Users; namespace osu.Game.Screens.Backgrounds { @@ -22,7 +23,7 @@ namespace osu.Game.Screens.Backgrounds public readonly Bindable StoryboardReplacesBackground = new Bindable(); - protected UserDimContainer FadeContainer { get; private set; } + private readonly UserDimContainer fadeContainer; protected virtual UserDimContainer CreateFadeContainer() => new UserDimContainer { RelativeSizeAxes = Axes.Both }; @@ -50,9 +51,9 @@ namespace osu.Game.Screens.Backgrounds } b.Depth = newDepth; - FadeContainer.Add(Background = b); + fadeContainer.Add(Background = b); Background.BlurSigma = BlurTarget; - FadeContainer.StoryboardReplacesBackground.BindTo(StoryboardReplacesBackground); + StoryboardReplacesBackground.BindTo(fadeContainer.StoryboardReplacesBackground); })); }); } @@ -60,10 +61,9 @@ namespace osu.Game.Screens.Backgrounds public BackgroundScreenBeatmap(WorkingBeatmap beatmap = null) { - FadeContainer = CreateFadeContainer(); - InternalChild = FadeContainer; - EnableUserDim.BindTo(FadeContainer.EnableUserDim); Beatmap = beatmap; + InternalChild = fadeContainer = CreateFadeContainer(); + fadeContainer.EnableUserDim.BindTo(EnableUserDim); } public override bool Equals(BackgroundScreen other) diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 2880013b32..fe139fd9dd 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -72,7 +72,7 @@ namespace osu.Game.Screens.Play [Resolved] private ScoreManager scoreManager { get; set; } - private PauseContainer pauseContainer; + protected PauseContainer PauseContainer { get; private set; } private RulesetInfo ruleset; @@ -80,10 +80,10 @@ namespace osu.Game.Screens.Play private SampleChannel sampleRestart; - protected ScoreProcessor ScoreProcessor; - protected RulesetContainer RulesetContainer; + protected ScoreProcessor ScoreProcessor { get; private set; } + protected RulesetContainer RulesetContainer { get; private set; } - protected HUDOverlay HUDOverlay; + protected HUDOverlay HUDOverlay { get; private set; } private FailOverlay failOverlay; private DrawableStoryboard storyboard; @@ -175,7 +175,7 @@ namespace osu.Game.Screens.Play InternalChildren = new Drawable[] { - pauseContainer = new PauseContainer(offsetClock, adjustableClock) + PauseContainer = new PauseContainer(offsetClock, adjustableClock) { Retries = RestartCount, OnRetry = Restart, @@ -239,7 +239,7 @@ namespace osu.Game.Screens.Play HUDOverlay.HoldToQuit.Action = performUserRequestedExit; HUDOverlay.KeyCounter.Visible.BindTo(RulesetContainer.HasReplayLoaded); - RulesetContainer.IsPaused.BindTo(pauseContainer.IsPaused); + RulesetContainer.IsPaused.BindTo(PauseContainer.IsPaused); if (ShowStoryboard.Value) initializeStoryboard(false); @@ -357,7 +357,7 @@ namespace osu.Game.Screens.Play Background.EnableUserDim.Value = true; - storyboardReplacesBackground.BindTo(Background.StoryboardReplacesBackground); + Background.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground); StoryboardContainer.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground); storyboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable; @@ -372,7 +372,7 @@ namespace osu.Game.Screens.Play this.Delay(750).Schedule(() => { - if (!pauseContainer.IsPaused.Value) + if (!PauseContainer.IsPaused.Value) { adjustableClock.Start(); } @@ -380,8 +380,8 @@ namespace osu.Game.Screens.Play }); }); - pauseContainer.Alpha = 0; - pauseContainer.FadeIn(750, Easing.OutQuint); + PauseContainer.Alpha = 0; + PauseContainer.FadeIn(750, Easing.OutQuint); } public override void OnSuspending(IScreen next) @@ -399,7 +399,7 @@ namespace osu.Game.Screens.Play return true; } - if ((!AllowPause || HasFailed || !ValidForResume || pauseContainer?.IsPaused.Value != false || RulesetContainer?.HasReplayLoaded.Value != false) && (!pauseContainer?.IsResuming ?? true)) + if ((!AllowPause || HasFailed || !ValidForResume || PauseContainer?.IsPaused.Value != false || RulesetContainer?.HasReplayLoaded.Value != false) && (!PauseContainer?.IsResuming ?? true)) { // In the case of replays, we may have changed the playback rate. applyRateFromMods(); @@ -408,7 +408,7 @@ namespace osu.Game.Screens.Play } if (LoadedBeatmapSuccessfully) - pauseContainer?.Pause(); + PauseContainer?.Pause(); return true; } @@ -421,7 +421,7 @@ namespace osu.Game.Screens.Play storyboardReplacesBackground.Value = false; } - protected override bool OnScroll(ScrollEvent e) => mouseWheelDisabled.Value && !pauseContainer.IsPaused.Value; + protected override bool OnScroll(ScrollEvent e) => mouseWheelDisabled.Value && !PauseContainer.IsPaused.Value; private void initializeStoryboard(bool asyncLoad) { From c5270dd577cb607566d2aeeafb21b3d0de514d1f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Feb 2019 20:17:00 +0900 Subject: [PATCH 65/69] Remove unnecessary using --- osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 5883f61982..13d1ff39ef 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -8,7 +8,6 @@ using osu.Framework.Graphics.Textures; using osu.Game.Beatmaps; using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Containers; -using osu.Game.Users; namespace osu.Game.Screens.Backgrounds { From 6861163226851ae02d41c9529868f210ed80e455 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Feb 2019 20:21:27 +0900 Subject: [PATCH 66/69] Remove pointless method --- osu.Game/Screens/Play/Player.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index fe139fd9dd..94f0a91b1c 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -439,13 +439,6 @@ namespace osu.Game.Screens.Play StoryboardContainer.Add(storyboard); } - protected override void UpdateBackgroundElements() - { - if (!this.IsCurrentScreen()) return; - - base.UpdateBackgroundElements(); - } - protected virtual Results CreateResults(ScoreInfo score) => new SoloResults(score); } } From 86913e720fd92ee34edacea1b330f89f65f0a0c0 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Feb 2019 20:24:09 +0900 Subject: [PATCH 67/69] Remove extra space --- osu.Game/Graphics/Containers/UserDimContainer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Graphics/Containers/UserDimContainer.cs b/osu.Game/Graphics/Containers/UserDimContainer.cs index e70bec1d2d..4d4b9da76f 100644 --- a/osu.Game/Graphics/Containers/UserDimContainer.cs +++ b/osu.Game/Graphics/Containers/UserDimContainer.cs @@ -39,7 +39,7 @@ namespace osu.Game.Graphics.Containers private readonly bool isStoryboard; /// - /// Creates a new . + /// Creates a new . /// /// /// Whether or not this instance of UserDimContainer contains a storyboard. From 53eb0e7e4e3adc354bae27005ea69b10ea895b74 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Feb 2019 20:30:23 +0900 Subject: [PATCH 68/69] More formatting fixes --- .../Graphics/Containers/UserDimContainer.cs | 25 ++++++++++--------- osu.Game/Screens/Play/Player.cs | 2 ++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/osu.Game/Graphics/Containers/UserDimContainer.cs b/osu.Game/Graphics/Containers/UserDimContainer.cs index 4d4b9da76f..4c8928e122 100644 --- a/osu.Game/Graphics/Containers/UserDimContainer.cs +++ b/osu.Game/Graphics/Containers/UserDimContainer.cs @@ -18,9 +18,9 @@ namespace osu.Game.Graphics.Containers { private const float background_fade_duration = 800; - protected Bindable DimLevel { get; private set; } + private Bindable dimLevel { get; set; } - protected Bindable ShowStoryboard { get; private set; } + private Bindable showStoryboard { get; set; } /// /// Whether or not user-configured dim levels should be applied to the container. @@ -41,10 +41,11 @@ namespace osu.Game.Graphics.Containers /// /// Creates a new . /// - /// - /// Whether or not this instance of UserDimContainer contains a storyboard. - /// While both backgrounds and storyboards allow user dim levels to be applied, storyboards can be toggled via + /// Whether or not this instance of UserDimContainer contains a storyboard. + /// + /// While both backgrounds and storyboards allow user dim levels to be applied, storyboards can be toggled via /// and can cause backgrounds to become hidden via . + /// /// public UserDimContainer(bool isStoryboard = false) { @@ -55,11 +56,11 @@ namespace osu.Game.Graphics.Containers [BackgroundDependencyLoader] private void load(OsuConfigManager config) { - DimLevel = config.GetBindable(OsuSetting.DimLevel); - ShowStoryboard = config.GetBindable(OsuSetting.ShowStoryboard); + dimLevel = config.GetBindable(OsuSetting.DimLevel); + showStoryboard = config.GetBindable(OsuSetting.ShowStoryboard); EnableUserDim.ValueChanged += _ => updateBackgroundDim(); - DimLevel.ValueChanged += _ => updateBackgroundDim(); - ShowStoryboard.ValueChanged += _ => updateBackgroundDim(); + dimLevel.ValueChanged += _ => updateBackgroundDim(); + showStoryboard.ValueChanged += _ => updateBackgroundDim(); StoryboardReplacesBackground.ValueChanged += _ => updateBackgroundDim(); } @@ -73,15 +74,15 @@ namespace osu.Game.Graphics.Containers { if (isStoryboard) { - DimContainer.FadeTo(!ShowStoryboard.Value || DimLevel.Value == 1 ? 0 : 1, background_fade_duration, Easing.OutQuint); + DimContainer.FadeTo(!showStoryboard.Value || dimLevel.Value == 1 ? 0 : 1, background_fade_duration, Easing.OutQuint); } else { // The background needs to be hidden in the case of it being replaced by the storyboard - DimContainer.FadeTo(ShowStoryboard.Value && StoryboardReplacesBackground.Value ? 0 : 1, background_fade_duration, Easing.OutQuint); + DimContainer.FadeTo(showStoryboard.Value && StoryboardReplacesBackground.Value ? 0 : 1, background_fade_duration, Easing.OutQuint); } - DimContainer.FadeColour(EnableUserDim.Value ? OsuColour.Gray(1 - (float)DimLevel.Value) : Color4.White, background_fade_duration, Easing.OutQuint); + DimContainer.FadeColour(EnableUserDim.Value ? OsuColour.Gray(1 - (float)dimLevel.Value) : Color4.White, background_fade_duration, Easing.OutQuint); } } } diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 94f0a91b1c..27a888f58a 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -359,6 +359,7 @@ namespace osu.Game.Screens.Play Background.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground); StoryboardContainer.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground); + storyboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable; Task.Run(() => @@ -417,6 +418,7 @@ namespace osu.Game.Screens.Play { float fadeOutDuration = instant ? 0 : 250; this.FadeOut(fadeOutDuration); + Background.EnableUserDim.Value = false; storyboardReplacesBackground.Value = false; } From 30e820d107c9ddff861bdbae0d3bea47b6c60d04 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Feb 2019 20:36:00 +0900 Subject: [PATCH 69/69] Fix storyboard potentially being loaded many times --- osu.Game/Screens/Play/Player.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 27a888f58a..bb2211a533 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -349,10 +349,9 @@ namespace osu.Game.Screens.Play .Delay(250) .FadeIn(250); - ShowStoryboard.ValueChanged += s => + ShowStoryboard.ValueChanged += enabled => { - if (s.NewValue && storyboard == null) - initializeStoryboard(true); + if (enabled.NewValue) initializeStoryboard(true); }; Background.EnableUserDim.Value = true; @@ -427,7 +426,7 @@ namespace osu.Game.Screens.Play private void initializeStoryboard(bool asyncLoad) { - if (StoryboardContainer == null) + if (StoryboardContainer == null || storyboard != null) return; var beatmap = Beatmap.Value;