1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 02:22:56 +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()
{
FadeAccessibleBackground background = new FadeAccessibleBackground(Beatmap.Value);
DimEnabled.BindTo(background.EnableVisualSettings);
DimEnabled.BindTo(background.EnableUserDim);
return background;
}

View File

@ -1,6 +1,7 @@
// 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.
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -36,7 +37,7 @@ namespace osu.Game.Graphics.Containers
/// <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"/>
/// </remarks>
public Bindable<float> AddedBlur = new Bindable<float>();
public readonly Bindable<float> BlurAmount = new Bindable<float>();
private Bindable<double> 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<Background>().FirstOrDefault();
/// <summary>
/// Creates a new <see cref="UserDimContainer"/>.
@ -69,27 +72,38 @@ namespace osu.Game.Graphics.Containers
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]
private void load(OsuConfigManager config)
{
dimLevel = config.GetBindable<double>(OsuSetting.DimLevel);
blurLevel = config.GetBindable<double>(OsuSetting.BlurLevel);
showStoryboard = config.GetBindable<bool>(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);

View File

@ -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<BackgroundScreen>
{
protected Background Background;
protected BackgroundScreen()
{
Anchor = Anchor.Centre;

View File

@ -13,16 +13,21 @@ namespace osu.Game.Screens.Backgrounds
{
public class BackgroundScreenBeatmap : BackgroundScreen
{
protected Background Background;
private WorkingBeatmap beatmap;
/// <summary>
/// Whether or not user dim settings should be applied to this Background.
/// </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<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;
@ -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)

View File

@ -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)

View File

@ -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++;
}

View File

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

View File

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

View File

@ -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 =>

View File

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