From ba89bfee0c195e5368545ee85a5f2b7da4f02422 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 20 Mar 2019 20:12:46 +0900 Subject: [PATCH] Define explicit method to add background Also cleans up some redundant/misplaced comments. --- .../Graphics/Containers/UserDimContainer.cs | 27 ++++++++++++------- .../Backgrounds/BackgroundScreenBeatmap.cs | 2 +- osu.Game/Screens/Play/PlayerLoader.cs | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/osu.Game/Graphics/Containers/UserDimContainer.cs b/osu.Game/Graphics/Containers/UserDimContainer.cs index c790d6777d..18a45dd0cd 100644 --- a/osu.Game/Graphics/Containers/UserDimContainer.cs +++ b/osu.Game/Graphics/Containers/UserDimContainer.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 System; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -50,12 +51,13 @@ public class UserDimContainer : Container private readonly bool isStoryboard; + /// + /// As an optimisation, we add the two blur portions to be applied rather than actually applying two separate blurs. + /// private Vector2 blurTarget => EnableUserDim.Value ? new Vector2(BlurAmount.Value + (float)userBlurLevel.Value * 25) : new Vector2(BlurAmount.Value); - private Background background; - /// /// Creates a new . /// @@ -71,14 +73,22 @@ public UserDimContainer(bool isStoryboard = false) AddInternal(DimContainer = new Container { RelativeSizeAxes = Axes.Both }); } - public override void Add(Drawable drawable) + private Background background; + + public Background Background { - // Make sure we're already at the correct blur target when a background is added to the container. - if (drawable is Background b) + get => background; + set { - background = b; + background = value; background.BlurTo(blurTarget, 0, Easing.OutQuint); } + } + + public override void Add(Drawable drawable) + { + if (drawable is Background) + throw new InvalidOperationException($"Use {nameof(Background)} to set a background."); base.Add(drawable); } @@ -115,10 +125,7 @@ private void updateVisuals() // 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); - // This only works if the background is a direct child of DimContainer. - // We can't blur the container like we did with the dim because buffered containers add considerable draw overhead. - // As a result, this blurs the background directly via the direct children of DimContainer. - background?.BlurTo(blurTarget, background_fade_duration, Easing.OutQuint); + Background?.BlurTo(blurTarget, background_fade_duration, Easing.OutQuint); } DimContainer.FadeColour(EnableUserDim.Value ? OsuColour.Gray(1 - (float)userDimLevel.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 111cc9d2c1..6df418753c 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -85,7 +85,7 @@ private void switchBackground(BeatmapBackground b) } b.Depth = newDepth; - fadeContainer.Add(Background = b); + fadeContainer.Background = Background = b; StoryboardReplacesBackground.BindTo(fadeContainer.StoryboardReplacesBackground); } diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index 9eebce4888..e9ee5d3fa8 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -164,7 +164,7 @@ protected override void LoadComplete() private ScheduledDelegate pushDebounce; protected VisualSettings VisualSettings; - // required for IsHovered usage in readyForPush + // Hhere because IsHovered will not update unless we do so. public override bool HandlePositionalInput => true; private bool readyForPush => player.LoadState == LoadState.Ready && IsHovered && GetContainingInputManager()?.DraggedDrawable == null;