1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 08:03:12 +08:00

Rework instant blur logic such that updateVisuals doesn't need to be public

This commit is contained in:
David Zhao 2019-03-20 14:17:35 +09:00
parent 3af3baf5e6
commit 15637f9c4a
10 changed files with 61 additions and 47 deletions

View File

@ -273,7 +273,7 @@ namespace osu.Game.Tests.Visual
protected override BackgroundScreen CreateBackground() protected override BackgroundScreen CreateBackground()
{ {
FadeAccessibleBackground background = new FadeAccessibleBackground(Beatmap.Value); FadeAccessibleBackground background = new FadeAccessibleBackground(Beatmap.Value);
DimEnabled.BindTo(background.EnableVisualSettings); DimEnabled.BindTo(background.EnableUserDim);
return background; return background;
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -36,7 +37,7 @@ namespace osu.Game.Graphics.Containers
/// <remarks> /// <remarks>
/// Used in contexts where there can potentially be both user and screen-specified blurring occuring at the same time, such as in <see cref="PlayerLoader"/> /// Used in contexts where there can potentially be both user and screen-specified blurring occuring at the same time, such as in <see cref="PlayerLoader"/>
/// </remarks> /// </remarks>
public Bindable<float> AddedBlur = new Bindable<float>(); public readonly Bindable<float> BlurAmount = new Bindable<float>();
private Bindable<double> dimLevel { get; set; } private Bindable<double> dimLevel { get; set; }
@ -51,8 +52,10 @@ namespace osu.Game.Graphics.Containers
private readonly bool isStoryboard; private readonly bool isStoryboard;
private Vector2 blurTarget => EnableUserDim.Value private Vector2 blurTarget => EnableUserDim.Value
? new Vector2(AddedBlur.Value + (float)blurLevel.Value * 25) ? new Vector2(BlurAmount.Value + (float)blurLevel.Value * 25)
: new Vector2(AddedBlur.Value); : new Vector2(BlurAmount.Value);
private Background background => DimContainer.Children.OfType<Background>().FirstOrDefault();
/// <summary> /// <summary>
/// Creates a new <see cref="UserDimContainer"/>. /// Creates a new <see cref="UserDimContainer"/>.
@ -69,27 +72,38 @@ namespace osu.Game.Graphics.Containers
AddInternal(DimContainer = new Container { RelativeSizeAxes = Axes.Both }); AddInternal(DimContainer = new Container { RelativeSizeAxes = Axes.Both });
} }
/// <summary>
/// Set the blur of the background in this UserDimContainer to our blur target instantly.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
public void ApplyInstantBlur()
{
background?.BlurTo(blurTarget, 0, Easing.OutQuint);
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuConfigManager config) private void load(OsuConfigManager config)
{ {
dimLevel = config.GetBindable<double>(OsuSetting.DimLevel); dimLevel = config.GetBindable<double>(OsuSetting.DimLevel);
blurLevel = config.GetBindable<double>(OsuSetting.BlurLevel); blurLevel = config.GetBindable<double>(OsuSetting.BlurLevel);
showStoryboard = config.GetBindable<bool>(OsuSetting.ShowStoryboard); showStoryboard = config.GetBindable<bool>(OsuSetting.ShowStoryboard);
EnableUserDim.ValueChanged += _ => UpdateVisuals(); EnableUserDim.ValueChanged += _ => updateVisuals();
dimLevel.ValueChanged += _ => UpdateVisuals(); dimLevel.ValueChanged += _ => updateVisuals();
blurLevel.ValueChanged += _ => UpdateVisuals(); blurLevel.ValueChanged += _ => updateVisuals();
showStoryboard.ValueChanged += _ => UpdateVisuals(); showStoryboard.ValueChanged += _ => updateVisuals();
StoryboardReplacesBackground.ValueChanged += _ => UpdateVisuals(); StoryboardReplacesBackground.ValueChanged += _ => updateVisuals();
AddedBlur.ValueChanged += _ => UpdateVisuals(); BlurAmount.ValueChanged += _ => updateVisuals();
} }
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
UpdateVisuals(); updateVisuals();
} }
public void UpdateVisuals(bool instant = false) private void updateVisuals()
{ {
if (isStoryboard) 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 // 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);
foreach (Drawable c in DimContainer)
{
// Only blur if this container contains a background // 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 can't blur the container like we did with the dim because buffered containers add considerable draw overhead.
// 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. // As a result, this blurs the background directly.
((Background)c)?.BlurTo(blurTarget, instant ? 0 : background_fade_duration, Easing.OutQuint); 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); DimContainer.FadeColour(EnableUserDim.Value ? OsuColour.Gray(1 - (float)dimLevel.Value) : Color4.White, background_fade_duration, Easing.OutQuint);

View File

@ -5,15 +5,12 @@ using System;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Graphics.Backgrounds;
using osuTK; using osuTK;
namespace osu.Game.Screens namespace osu.Game.Screens
{ {
public abstract class BackgroundScreen : Screen, IEquatable<BackgroundScreen> public abstract class BackgroundScreen : Screen, IEquatable<BackgroundScreen>
{ {
protected Background Background;
protected BackgroundScreen() protected BackgroundScreen()
{ {
Anchor = Anchor.Centre; Anchor = Anchor.Centre;

View File

@ -13,16 +13,21 @@ namespace osu.Game.Screens.Backgrounds
{ {
public class BackgroundScreenBeatmap : BackgroundScreen public class BackgroundScreenBeatmap : BackgroundScreen
{ {
protected Background Background;
private WorkingBeatmap beatmap; private WorkingBeatmap beatmap;
/// <summary> /// <summary>
/// Whether or not user dim settings should be applied to this Background. /// Whether or not user dim settings should be applied to this Background.
/// </summary> /// </summary>
public readonly Bindable<bool> EnableVisualSettings = new Bindable<bool>(); public readonly Bindable<bool> EnableUserDim = new Bindable<bool>();
public readonly Bindable<bool> StoryboardReplacesBackground = new Bindable<bool>(); public readonly Bindable<bool> StoryboardReplacesBackground = new Bindable<bool>();
public readonly Bindable<float> AddedBlur = new Bindable<float>(); /// <summary>
/// The amount of blur to be applied in addition to user-specified blur.
/// </summary>
public readonly Bindable<float> BlurAmount = new Bindable<float>();
private readonly UserDimContainer fadeContainer; private readonly UserDimContainer fadeContainer;
@ -53,7 +58,7 @@ namespace osu.Game.Screens.Backgrounds
b.Depth = newDepth; b.Depth = newDepth;
fadeContainer.Add(Background = b); fadeContainer.Add(Background = b);
fadeContainer.UpdateVisuals(true); fadeContainer.ApplyInstantBlur();
StoryboardReplacesBackground.BindTo(fadeContainer.StoryboardReplacesBackground); StoryboardReplacesBackground.BindTo(fadeContainer.StoryboardReplacesBackground);
})); }));
}); });
@ -64,8 +69,8 @@ namespace osu.Game.Screens.Backgrounds
{ {
Beatmap = beatmap; Beatmap = beatmap;
InternalChild = fadeContainer = CreateFadeContainer(); InternalChild = fadeContainer = CreateFadeContainer();
fadeContainer.EnableUserDim.BindTo(EnableVisualSettings); fadeContainer.EnableUserDim.BindTo(EnableUserDim);
fadeContainer.AddedBlur.BindTo(AddedBlur); fadeContainer.BlurAmount.BindTo(BlurAmount);
} }
public override bool Equals(BackgroundScreen other) public override bool Equals(BackgroundScreen other)

View File

@ -12,7 +12,7 @@ namespace osu.Game.Screens.Backgrounds
public BackgroundScreenCustom(string textureName) public BackgroundScreenCustom(string textureName)
{ {
this.textureName = textureName; this.textureName = textureName;
AddInternal(Background = new Background(textureName)); AddInternal(new Background(textureName));
} }
public override bool Equals(BackgroundScreen other) public override bool Equals(BackgroundScreen other)

View File

@ -15,6 +15,8 @@ namespace osu.Game.Screens.Backgrounds
{ {
public class BackgroundScreenDefault : BackgroundScreen public class BackgroundScreenDefault : BackgroundScreen
{ {
private Background background;
private int currentDisplay; private int currentDisplay;
private const int background_count = 5; private const int background_count = 5;
@ -39,10 +41,10 @@ namespace osu.Game.Screens.Backgrounds
private void display(Background newBackground) private void display(Background newBackground)
{ {
Background?.FadeOut(800, Easing.InOutSine); background?.FadeOut(800, Easing.InOutSine);
Background?.Expire(); background?.Expire();
AddInternal(Background = newBackground); AddInternal(background = newBackground);
currentDisplay++; currentDisplay++;
} }

View File

@ -321,7 +321,8 @@ namespace osu.Game.Screens.Play
if (enabled.NewValue) initializeStoryboard(true); if (enabled.NewValue) initializeStoryboard(true);
}; };
Background.EnableVisualSettings.Value = true; Background.EnableUserDim.Value = true;
Background.BlurAmount.Value = 0;
Background.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground); Background.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground);
StoryboardContainer.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground); StoryboardContainer.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground);
@ -368,7 +369,7 @@ namespace osu.Game.Screens.Play
float fadeOutDuration = instant ? 0 : 250; float fadeOutDuration = instant ? 0 : 250;
this.FadeOut(fadeOutDuration); this.FadeOut(fadeOutDuration);
Background.EnableVisualSettings.Value = false; Background.EnableUserDim.Value = false;
storyboardReplacesBackground.Value = false; storyboardReplacesBackground.Value = false;
} }

View File

@ -119,18 +119,12 @@ namespace osu.Game.Screens.Play
private void contentIn() private void contentIn()
{ {
Background.AddedBlur.Value = BACKGROUND_BLUR;
Background.EnableVisualSettings.Value = false;
content.ScaleTo(1, 650, Easing.OutQuint); content.ScaleTo(1, 650, Easing.OutQuint);
content.FadeInFromZero(400); content.FadeInFromZero(400);
} }
private void contentOut() private void contentOut()
{ {
Background.AddedBlur.Value = 0;
Background.EnableVisualSettings.Value = true;
content.ScaleTo(0.7f, 300, Easing.InQuint); content.ScaleTo(0.7f, 300, Easing.InQuint);
content.FadeOut(250); content.FadeOut(250);
} }
@ -166,10 +160,12 @@ namespace osu.Game.Screens.Play
protected override bool OnHover(HoverEvent e) 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()) if (this.IsCurrentScreen())
{ {
Background.AddedBlur.Value = BACKGROUND_BLUR; Background.BlurAmount.Value = BACKGROUND_BLUR;
Background.EnableVisualSettings.Value = false; Background.EnableUserDim.Value = false;
} }
return base.OnHover(e); return base.OnHover(e);
@ -177,12 +173,14 @@ namespace osu.Game.Screens.Play
protected override void OnHoverLost(HoverLostEvent e) 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 (GetContainingInputManager()?.HoveredDrawables.Contains(VisualSettings) == true)
{ {
if (this.IsCurrentScreen() && Background != null) if (this.IsCurrentScreen() && Background != null)
{ {
Background.AddedBlur.Value = 0; Background.BlurAmount.Value = 0;
Background.EnableVisualSettings.Value = true; Background.EnableUserDim.Value = true;
} }
} }
@ -241,7 +239,7 @@ namespace osu.Game.Screens.Play
public override void OnSuspending(IScreen next) public override void OnSuspending(IScreen next)
{ {
Background.EnableVisualSettings.Value = true; Background.EnableUserDim.Value = true;
base.OnSuspending(next); base.OnSuspending(next);
cancelLoad(); cancelLoad();
@ -253,7 +251,7 @@ namespace osu.Game.Screens.Play
this.FadeOut(150); this.FadeOut(150);
cancelLoad(); cancelLoad();
Background.EnableVisualSettings.Value = false; Background.EnableUserDim.Value = false;
return base.OnExiting(next); return base.OnExiting(next);
} }

View File

@ -58,7 +58,7 @@ namespace osu.Game.Screens.Ranking
public override void OnEntering(IScreen last) public override void OnEntering(IScreen last)
{ {
base.OnEntering(last); base.OnEntering(last);
((BackgroundScreenBeatmap)Background).AddedBlur.Value = BACKGROUND_BLUR; ((BackgroundScreenBeatmap)Background).BlurAmount.Value = BACKGROUND_BLUR;
Background.ScaleTo(1.1f, transition_time, Easing.OutQuint); Background.ScaleTo(1.1f, transition_time, Easing.OutQuint);
allCircles.ForEach(c => allCircles.ForEach(c =>

View File

@ -556,7 +556,7 @@ namespace osu.Game.Screens.Select
if (Background is BackgroundScreenBeatmap backgroundModeBeatmap) if (Background is BackgroundScreenBeatmap backgroundModeBeatmap)
{ {
backgroundModeBeatmap.Beatmap = beatmap; backgroundModeBeatmap.Beatmap = beatmap;
backgroundModeBeatmap.AddedBlur.Value = BACKGROUND_BLUR; backgroundModeBeatmap.BlurAmount.Value = BACKGROUND_BLUR;
backgroundModeBeatmap.FadeColour(Color4.White, 250); backgroundModeBeatmap.FadeColour(Color4.White, 250);
} }