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); }