From 15637f9c4a9ef0d3bdc1af745223b4523464779b Mon Sep 17 00:00:00 2001 From: David Zhao Date: Wed, 20 Mar 2019 14:17:35 +0900 Subject: [PATCH] Rework instant blur logic such that updateVisuals doesn't need to be public --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 2 +- .../Graphics/Containers/UserDimContainer.cs | 47 ++++++++++++------- osu.Game/Screens/BackgroundScreen.cs | 3 -- .../Backgrounds/BackgroundScreenBeatmap.cs | 15 ++++-- .../Backgrounds/BackgroundScreenCustom.cs | 2 +- .../Backgrounds/BackgroundScreenDefault.cs | 8 ++-- osu.Game/Screens/Play/Player.cs | 5 +- osu.Game/Screens/Play/PlayerLoader.cs | 22 ++++----- osu.Game/Screens/Ranking/Results.cs | 2 +- osu.Game/Screens/Select/SongSelect.cs | 2 +- 10 files changed, 61 insertions(+), 47 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 263cfe0fc8..084bb6a02e 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -273,7 +273,7 @@ namespace osu.Game.Tests.Visual protected override BackgroundScreen CreateBackground() { FadeAccessibleBackground background = new FadeAccessibleBackground(Beatmap.Value); - DimEnabled.BindTo(background.EnableVisualSettings); + DimEnabled.BindTo(background.EnableUserDim); return background; } diff --git a/osu.Game/Graphics/Containers/UserDimContainer.cs b/osu.Game/Graphics/Containers/UserDimContainer.cs index 3593394495..d68f607dcd 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.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -36,7 +37,7 @@ namespace osu.Game.Graphics.Containers /// /// Used in contexts where there can potentially be both user and screen-specified blurring occuring at the same time, such as in /// - public Bindable AddedBlur = new Bindable(); + public readonly Bindable BlurAmount = new Bindable(); private Bindable dimLevel { get; set; } @@ -51,8 +52,10 @@ namespace osu.Game.Graphics.Containers private readonly bool isStoryboard; private Vector2 blurTarget => EnableUserDim.Value - ? new Vector2(AddedBlur.Value + (float)blurLevel.Value * 25) - : new Vector2(AddedBlur.Value); + ? new Vector2(BlurAmount.Value + (float)blurLevel.Value * 25) + : new Vector2(BlurAmount.Value); + + private Background background => DimContainer.Children.OfType().FirstOrDefault(); /// /// Creates a new . @@ -69,27 +72,38 @@ namespace osu.Game.Graphics.Containers AddInternal(DimContainer = new Container { RelativeSizeAxes = Axes.Both }); } + /// + /// Set the blur of the background in this UserDimContainer to our blur target instantly. + /// + /// + /// We need to support instant blurring here in the case of changing beatmap backgrounds, where blurring shouldn't be from 0 every time the beatmap is changed. + /// + public void ApplyInstantBlur() + { + background?.BlurTo(blurTarget, 0, Easing.OutQuint); + } + [BackgroundDependencyLoader] private void load(OsuConfigManager config) { dimLevel = config.GetBindable(OsuSetting.DimLevel); blurLevel = config.GetBindable(OsuSetting.BlurLevel); showStoryboard = config.GetBindable(OsuSetting.ShowStoryboard); - EnableUserDim.ValueChanged += _ => UpdateVisuals(); - dimLevel.ValueChanged += _ => UpdateVisuals(); - blurLevel.ValueChanged += _ => UpdateVisuals(); - showStoryboard.ValueChanged += _ => UpdateVisuals(); - StoryboardReplacesBackground.ValueChanged += _ => UpdateVisuals(); - AddedBlur.ValueChanged += _ => UpdateVisuals(); + EnableUserDim.ValueChanged += _ => updateVisuals(); + dimLevel.ValueChanged += _ => updateVisuals(); + blurLevel.ValueChanged += _ => updateVisuals(); + showStoryboard.ValueChanged += _ => updateVisuals(); + StoryboardReplacesBackground.ValueChanged += _ => updateVisuals(); + BlurAmount.ValueChanged += _ => updateVisuals(); } protected override void LoadComplete() { base.LoadComplete(); - UpdateVisuals(); + updateVisuals(); } - public void UpdateVisuals(bool instant = false) + private void updateVisuals() { if (isStoryboard) { @@ -100,13 +114,10 @@ namespace osu.Game.Graphics.Containers // 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); - foreach (Drawable c in DimContainer) - { - // Only blur if this container contains a background - // 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. - // We need to support instant blurring here in the case of SongSelect, where blurring shouldn't be from 0 every time the beatmap is changed. - ((Background)c)?.BlurTo(blurTarget, instant ? 0 : background_fade_duration, Easing.OutQuint); - } + // Only blur if this container contains a background + // 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. + background?.BlurTo(blurTarget, 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/BackgroundScreen.cs b/osu.Game/Screens/BackgroundScreen.cs index 7eca192a6b..bbe162cf7c 100644 --- a/osu.Game/Screens/BackgroundScreen.cs +++ b/osu.Game/Screens/BackgroundScreen.cs @@ -5,15 +5,12 @@ using System; using osu.Framework.Screens; using osu.Framework.Graphics; using osu.Framework.Input.Events; -using osu.Game.Graphics.Backgrounds; using osuTK; namespace osu.Game.Screens { public abstract class BackgroundScreen : Screen, IEquatable { - protected Background Background; - protected BackgroundScreen() { Anchor = Anchor.Centre; diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 1baa711f86..5f86fe8d20 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -13,16 +13,21 @@ namespace osu.Game.Screens.Backgrounds { public class BackgroundScreenBeatmap : BackgroundScreen { + protected Background Background; + private WorkingBeatmap beatmap; /// /// Whether or not user dim settings should be applied to this Background. /// - public readonly Bindable EnableVisualSettings = new Bindable(); + public readonly Bindable EnableUserDim = new Bindable(); public readonly Bindable StoryboardReplacesBackground = new Bindable(); - public readonly Bindable AddedBlur = new Bindable(); + /// + /// The amount of blur to be applied in addition to user-specified blur. + /// + public readonly Bindable BlurAmount = new Bindable(); private readonly UserDimContainer fadeContainer; @@ -53,7 +58,7 @@ namespace osu.Game.Screens.Backgrounds b.Depth = newDepth; fadeContainer.Add(Background = b); - fadeContainer.UpdateVisuals(true); + fadeContainer.ApplyInstantBlur(); StoryboardReplacesBackground.BindTo(fadeContainer.StoryboardReplacesBackground); })); }); @@ -64,8 +69,8 @@ namespace osu.Game.Screens.Backgrounds { Beatmap = beatmap; InternalChild = fadeContainer = CreateFadeContainer(); - fadeContainer.EnableUserDim.BindTo(EnableVisualSettings); - fadeContainer.AddedBlur.BindTo(AddedBlur); + fadeContainer.EnableUserDim.BindTo(EnableUserDim); + fadeContainer.BlurAmount.BindTo(BlurAmount); } public override bool Equals(BackgroundScreen other) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenCustom.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenCustom.cs index 538f347737..0cb41bc562 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenCustom.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenCustom.cs @@ -12,7 +12,7 @@ namespace osu.Game.Screens.Backgrounds public BackgroundScreenCustom(string textureName) { this.textureName = textureName; - AddInternal(Background = new Background(textureName)); + AddInternal(new Background(textureName)); } public override bool Equals(BackgroundScreen other) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs index 73590b3318..3aeb2f9923 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs @@ -15,6 +15,8 @@ namespace osu.Game.Screens.Backgrounds { public class BackgroundScreenDefault : BackgroundScreen { + private Background background; + private int currentDisplay; private const int background_count = 5; @@ -39,10 +41,10 @@ namespace osu.Game.Screens.Backgrounds private void display(Background newBackground) { - Background?.FadeOut(800, Easing.InOutSine); - Background?.Expire(); + background?.FadeOut(800, Easing.InOutSine); + background?.Expire(); - AddInternal(Background = newBackground); + AddInternal(background = newBackground); currentDisplay++; } diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index fc24e55de2..1ce8bf559d 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -321,7 +321,8 @@ namespace osu.Game.Screens.Play if (enabled.NewValue) initializeStoryboard(true); }; - Background.EnableVisualSettings.Value = true; + Background.EnableUserDim.Value = true; + Background.BlurAmount.Value = 0; Background.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground); StoryboardContainer.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground); @@ -368,7 +369,7 @@ namespace osu.Game.Screens.Play float fadeOutDuration = instant ? 0 : 250; this.FadeOut(fadeOutDuration); - Background.EnableVisualSettings.Value = false; + Background.EnableUserDim.Value = false; storyboardReplacesBackground.Value = false; } diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index 4200a7390d..86156e292c 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -119,18 +119,12 @@ namespace osu.Game.Screens.Play private void contentIn() { - Background.AddedBlur.Value = BACKGROUND_BLUR; - Background.EnableVisualSettings.Value = false; - content.ScaleTo(1, 650, Easing.OutQuint); content.FadeInFromZero(400); } private void contentOut() { - Background.AddedBlur.Value = 0; - Background.EnableVisualSettings.Value = true; - content.ScaleTo(0.7f, 300, Easing.InQuint); content.FadeOut(250); } @@ -166,10 +160,12 @@ namespace osu.Game.Screens.Play protected override bool OnHover(HoverEvent e) { + // Acts as an "on hover lost" trigger for the visual settings panel. + // Returns background dim and blur to the values specified by PlayerLoader. if (this.IsCurrentScreen()) { - Background.AddedBlur.Value = BACKGROUND_BLUR; - Background.EnableVisualSettings.Value = false; + Background.BlurAmount.Value = BACKGROUND_BLUR; + Background.EnableUserDim.Value = false; } return base.OnHover(e); @@ -177,12 +173,14 @@ namespace osu.Game.Screens.Play protected override void OnHoverLost(HoverLostEvent e) { + // Acts as an "on hover" trigger for the visual settings panel. + // Preview user-defined background dim and blur when hovered on the visual settings panel. if (GetContainingInputManager()?.HoveredDrawables.Contains(VisualSettings) == true) { if (this.IsCurrentScreen() && Background != null) { - Background.AddedBlur.Value = 0; - Background.EnableVisualSettings.Value = true; + Background.BlurAmount.Value = 0; + Background.EnableUserDim.Value = true; } } @@ -241,7 +239,7 @@ namespace osu.Game.Screens.Play public override void OnSuspending(IScreen next) { - Background.EnableVisualSettings.Value = true; + Background.EnableUserDim.Value = true; base.OnSuspending(next); cancelLoad(); @@ -253,7 +251,7 @@ namespace osu.Game.Screens.Play this.FadeOut(150); cancelLoad(); - Background.EnableVisualSettings.Value = false; + Background.EnableUserDim.Value = false; return base.OnExiting(next); } diff --git a/osu.Game/Screens/Ranking/Results.cs b/osu.Game/Screens/Ranking/Results.cs index bd8daa6b03..dafb4c0aad 100644 --- a/osu.Game/Screens/Ranking/Results.cs +++ b/osu.Game/Screens/Ranking/Results.cs @@ -58,7 +58,7 @@ namespace osu.Game.Screens.Ranking public override void OnEntering(IScreen last) { base.OnEntering(last); - ((BackgroundScreenBeatmap)Background).AddedBlur.Value = BACKGROUND_BLUR; + ((BackgroundScreenBeatmap)Background).BlurAmount.Value = BACKGROUND_BLUR; Background.ScaleTo(1.1f, transition_time, Easing.OutQuint); allCircles.ForEach(c => diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index 385c4e0a0d..9985f984a0 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -556,7 +556,7 @@ namespace osu.Game.Screens.Select if (Background is BackgroundScreenBeatmap backgroundModeBeatmap) { backgroundModeBeatmap.Beatmap = beatmap; - backgroundModeBeatmap.AddedBlur.Value = BACKGROUND_BLUR; + backgroundModeBeatmap.BlurAmount.Value = BACKGROUND_BLUR; backgroundModeBeatmap.FadeColour(Color4.White, 250); }