mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 19:53:23 +08:00
Make UserDimContainer abstract
This commit is contained in:
parent
221ee58f55
commit
321266e96f
@ -243,7 +243,7 @@ namespace osu.Game.Tests.Visual.Background
|
|||||||
{
|
{
|
||||||
player.StoryboardEnabled.Value = false;
|
player.StoryboardEnabled.Value = false;
|
||||||
player.ReplacesBackground.Value = false;
|
player.ReplacesBackground.Value = false;
|
||||||
player.CurrentStoryboardContainer.Add(new OsuSpriteText
|
player.CurrentDimmableStoryboardContainer.Add(new OsuSpriteText
|
||||||
{
|
{
|
||||||
Size = new Vector2(500, 50),
|
Size = new Vector2(500, 50),
|
||||||
Alpha = 1,
|
Alpha = 1,
|
||||||
@ -336,9 +336,9 @@ namespace osu.Game.Tests.Visual.Background
|
|||||||
{
|
{
|
||||||
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(Beatmap.Value);
|
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(Beatmap.Value);
|
||||||
|
|
||||||
protected override StoryboardContainer CreateStoryboardContainer(Storyboard storyboard) => new TestStoryboardContainer { RelativeSizeAxes = Axes.Both };
|
protected override DimmableStoryboardContainer CreateStoryboardContainer(Storyboard storyboard) => new TestDimmableStoryboardContainer { RelativeSizeAxes = Axes.Both };
|
||||||
|
|
||||||
public TestStoryboardContainer CurrentStoryboardContainer => (TestStoryboardContainer)StoryboardContainer;
|
public TestDimmableStoryboardContainer CurrentDimmableStoryboardContainer => (TestDimmableStoryboardContainer)DimmableStoryboardContainer;
|
||||||
|
|
||||||
// Whether or not the player should be allowed to load.
|
// Whether or not the player should be allowed to load.
|
||||||
public bool BlockLoad;
|
public bool BlockLoad;
|
||||||
@ -352,9 +352,9 @@ namespace osu.Game.Tests.Visual.Background
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsStoryboardVisible() => CurrentStoryboardContainer.CurrentAlpha == 1;
|
public bool IsStoryboardVisible() => CurrentDimmableStoryboardContainer.CurrentAlpha == 1;
|
||||||
|
|
||||||
public bool IsStoryboardInvisible() => CurrentStoryboardContainer.CurrentAlpha <= 1;
|
public bool IsStoryboardInvisible() => CurrentDimmableStoryboardContainer.CurrentAlpha <= 1;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuConfigManager config, CancellationToken token)
|
private void load(OsuConfigManager config, CancellationToken token)
|
||||||
@ -387,7 +387,7 @@ namespace osu.Game.Tests.Visual.Background
|
|||||||
|
|
||||||
private class FadeAccessibleBackground : BackgroundScreenBeatmap
|
private class FadeAccessibleBackground : BackgroundScreenBeatmap
|
||||||
{
|
{
|
||||||
protected override UserDimContainer CreateFadeContainer() => fadeContainer = new TestUserDimContainer { RelativeSizeAxes = Axes.Both };
|
protected override DimmableBackgroundContainer CreateFadeContainer() => fadeContainer = new TestDimmableBackgroundContainer { RelativeSizeAxes = Axes.Both };
|
||||||
|
|
||||||
public Color4 CurrentColour => fadeContainer.CurrentColour;
|
public Color4 CurrentColour => fadeContainer.CurrentColour;
|
||||||
|
|
||||||
@ -395,7 +395,7 @@ namespace osu.Game.Tests.Visual.Background
|
|||||||
|
|
||||||
public Vector2 CurrentBlur => Background.BlurSigma;
|
public Vector2 CurrentBlur => Background.BlurSigma;
|
||||||
|
|
||||||
private TestUserDimContainer fadeContainer;
|
private TestDimmableBackgroundContainer fadeContainer;
|
||||||
|
|
||||||
public FadeAccessibleBackground(WorkingBeatmap beatmap)
|
public FadeAccessibleBackground(WorkingBeatmap beatmap)
|
||||||
: base(beatmap)
|
: base(beatmap)
|
||||||
@ -403,17 +403,17 @@ namespace osu.Game.Tests.Visual.Background
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestStoryboardContainer : StoryboardContainer
|
private class TestDimmableStoryboardContainer : DimmableStoryboardContainer
|
||||||
{
|
{
|
||||||
public float CurrentAlpha => DimContainer.Alpha;
|
public float CurrentAlpha => DimContainer.Alpha;
|
||||||
|
|
||||||
public TestStoryboardContainer()
|
public TestDimmableStoryboardContainer()
|
||||||
: base(new Storyboard())
|
: base(new Storyboard())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestUserDimContainer : UserDimContainer
|
private class TestDimmableBackgroundContainer : DimmableBackgroundContainer
|
||||||
{
|
{
|
||||||
public Color4 CurrentColour => DimContainer.Colour;
|
public Color4 CurrentColour => DimContainer.Colour;
|
||||||
public float CurrentAlpha => DimContainer.Alpha;
|
public float CurrentAlpha => DimContainer.Alpha;
|
||||||
|
68
osu.Game/Graphics/Containers/DimmableBackgroundContainer.cs
Normal file
68
osu.Game/Graphics/Containers/DimmableBackgroundContainer.cs
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
// 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;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Game.Configuration;
|
||||||
|
using osu.Game.Graphics.Backgrounds;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Graphics.Containers
|
||||||
|
{
|
||||||
|
public class DimmableBackgroundContainer : UserDimContainer
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The amount of blur to be applied to the background in addition to user-specified blur.
|
||||||
|
/// </summary>
|
||||||
|
/// <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 readonly Bindable<float> BlurAmount = new Bindable<float>();
|
||||||
|
|
||||||
|
private Bindable<double> userBlurLevel { get; set; }
|
||||||
|
|
||||||
|
private Background background;
|
||||||
|
|
||||||
|
public Background Background
|
||||||
|
{
|
||||||
|
get => background;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
base.Add(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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// As an optimisation, we add the two blur portions to be applied rather than actually applying two separate blurs.
|
||||||
|
/// </summary>
|
||||||
|
private Vector2 blurTarget => EnableUserDim.Value
|
||||||
|
? new Vector2(BlurAmount.Value + (float)userBlurLevel.Value * 25)
|
||||||
|
: new Vector2(BlurAmount.Value);
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OsuConfigManager config)
|
||||||
|
{
|
||||||
|
userBlurLevel = config.GetBindable<double>(OsuSetting.BlurLevel);
|
||||||
|
BlurAmount.ValueChanged += _ => UpdateVisuals();
|
||||||
|
userBlurLevel.ValueChanged += _ => UpdateVisuals();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void ApplyFade()
|
||||||
|
{
|
||||||
|
// 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);
|
||||||
|
Background?.BlurTo(blurTarget, BACKGROUND_FADE_DURATION, Easing.OutQuint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,16 +11,14 @@ namespace osu.Game.Graphics.Containers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A container that handles <see cref="Storyboard"/> loading, as well as applies user-specified visual settings to it.
|
/// A container that handles <see cref="Storyboard"/> loading, as well as applies user-specified visual settings to it.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class StoryboardContainer : UserDimContainer
|
public class DimmableStoryboardContainer : UserDimContainer
|
||||||
{
|
{
|
||||||
private readonly Storyboard storyboard;
|
private readonly Storyboard storyboard;
|
||||||
private DrawableStoryboard drawableStoryboard;
|
private DrawableStoryboard drawableStoryboard;
|
||||||
|
|
||||||
public StoryboardContainer(Storyboard storyboard)
|
public DimmableStoryboardContainer(Storyboard storyboard)
|
||||||
{
|
{
|
||||||
this.storyboard = storyboard;
|
this.storyboard = storyboard;
|
||||||
EnableUserDim.Default = true;
|
|
||||||
EnableUserDim.Value = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
@ -1,15 +1,11 @@
|
|||||||
// 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;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Graphics.Backgrounds;
|
|
||||||
using osu.Game.Screens.Play;
|
|
||||||
using osuTK;
|
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Graphics.Containers
|
namespace osu.Game.Graphics.Containers
|
||||||
@ -17,7 +13,7 @@ namespace osu.Game.Graphics.Containers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A container that applies user-configured visual settings to its contents.
|
/// A container that applies user-configured visual settings to its contents.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class UserDimContainer : Container
|
public abstract class UserDimContainer : Container
|
||||||
{
|
{
|
||||||
protected const float BACKGROUND_FADE_DURATION = 800;
|
protected const float BACKGROUND_FADE_DURATION = 800;
|
||||||
|
|
||||||
@ -31,14 +27,6 @@ namespace osu.Game.Graphics.Containers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly Bindable<bool> StoryboardReplacesBackground = new Bindable<bool>();
|
public readonly Bindable<bool> StoryboardReplacesBackground = new Bindable<bool>();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The amount of blur to be applied to the background in addition to user-specified blur.
|
|
||||||
/// </summary>
|
|
||||||
/// <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 readonly Bindable<float> BlurAmount = new Bindable<float>();
|
|
||||||
|
|
||||||
protected Bindable<double> UserDimLevel { get; private set; }
|
protected Bindable<double> UserDimLevel { get; private set; }
|
||||||
|
|
||||||
protected Bindable<bool> ShowStoryboard { get; private set; }
|
protected Bindable<bool> ShowStoryboard { get; private set; }
|
||||||
@ -47,62 +35,30 @@ namespace osu.Game.Graphics.Containers
|
|||||||
|
|
||||||
protected override Container<Drawable> Content => DimContainer;
|
protected override Container<Drawable> Content => DimContainer;
|
||||||
|
|
||||||
private Bindable<double> userBlurLevel { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// As an optimisation, we add the two blur portions to be applied rather than actually applying two separate blurs.
|
|
||||||
/// </summary>
|
|
||||||
private Vector2 blurTarget => EnableUserDim.Value
|
|
||||||
? new Vector2(BlurAmount.Value + (float)userBlurLevel.Value * 25)
|
|
||||||
: new Vector2(BlurAmount.Value);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="UserDimContainer"/>.
|
/// Creates a new <see cref="UserDimContainer"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public UserDimContainer()
|
protected UserDimContainer()
|
||||||
{
|
{
|
||||||
AddInternal(DimContainer = new Container { RelativeSizeAxes = Axes.Both });
|
AddInternal(DimContainer = new Container { RelativeSizeAxes = Axes.Both });
|
||||||
}
|
}
|
||||||
|
|
||||||
private Background background;
|
|
||||||
|
|
||||||
public Background Background
|
|
||||||
{
|
|
||||||
get => background;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
base.Add(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);
|
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuConfigManager config)
|
private void load(OsuConfigManager config)
|
||||||
{
|
{
|
||||||
UserDimLevel = config.GetBindable<double>(OsuSetting.DimLevel);
|
UserDimLevel = config.GetBindable<double>(OsuSetting.DimLevel);
|
||||||
userBlurLevel = config.GetBindable<double>(OsuSetting.BlurLevel);
|
|
||||||
ShowStoryboard = config.GetBindable<bool>(OsuSetting.ShowStoryboard);
|
ShowStoryboard = config.GetBindable<bool>(OsuSetting.ShowStoryboard);
|
||||||
|
|
||||||
EnableUserDim.ValueChanged += _ => updateVisuals();
|
EnableUserDim.ValueChanged += _ => UpdateVisuals();
|
||||||
UserDimLevel.ValueChanged += _ => updateVisuals();
|
UserDimLevel.ValueChanged += _ => UpdateVisuals();
|
||||||
ShowStoryboard.ValueChanged += _ => updateVisuals();
|
ShowStoryboard.ValueChanged += _ => UpdateVisuals();
|
||||||
StoryboardReplacesBackground.ValueChanged += _ => updateVisuals();
|
StoryboardReplacesBackground.ValueChanged += _ => UpdateVisuals();
|
||||||
BlurAmount.ValueChanged += _ => updateVisuals();
|
|
||||||
userBlurLevel.ValueChanged += _ => updateVisuals();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
updateVisuals();
|
UpdateVisuals();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -112,14 +68,9 @@ namespace osu.Game.Graphics.Containers
|
|||||||
/// While both backgrounds and storyboards allow user dim levels to be applied, storyboards can be toggled via <see cref="ShowStoryboard"/>
|
/// While both backgrounds and storyboards allow user dim levels to be applied, storyboards can be toggled via <see cref="ShowStoryboard"/>
|
||||||
/// and can cause backgrounds to become hidden via <see cref="StoryboardReplacesBackground"/>. Storyboards are also currently unable to be blurred.
|
/// and can cause backgrounds to become hidden via <see cref="StoryboardReplacesBackground"/>. Storyboards are also currently unable to be blurred.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
protected virtual void ApplyFade()
|
protected abstract void ApplyFade();
|
||||||
{
|
|
||||||
// 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);
|
|
||||||
Background?.BlurTo(blurTarget, BACKGROUND_FADE_DURATION, Easing.OutQuint);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateVisuals()
|
protected void UpdateVisuals()
|
||||||
{
|
{
|
||||||
ApplyFade();
|
ApplyFade();
|
||||||
|
|
||||||
|
@ -30,9 +30,9 @@ namespace osu.Game.Screens.Backgrounds
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly Bindable<float> BlurAmount = new Bindable<float>();
|
public readonly Bindable<float> BlurAmount = new Bindable<float>();
|
||||||
|
|
||||||
private readonly UserDimContainer fadeContainer;
|
private readonly DimmableBackgroundContainer fadeContainer;
|
||||||
|
|
||||||
protected virtual UserDimContainer CreateFadeContainer() => new UserDimContainer { RelativeSizeAxes = Axes.Both };
|
protected virtual DimmableBackgroundContainer CreateFadeContainer() => new DimmableBackgroundContainer() { RelativeSizeAxes = Axes.Both };
|
||||||
|
|
||||||
public BackgroundScreenBeatmap(WorkingBeatmap beatmap = null)
|
public BackgroundScreenBeatmap(WorkingBeatmap beatmap = null)
|
||||||
{
|
{
|
||||||
|
@ -76,9 +76,9 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
protected GameplayClockContainer GameplayClockContainer { get; private set; }
|
protected GameplayClockContainer GameplayClockContainer { get; private set; }
|
||||||
|
|
||||||
protected StoryboardContainer StoryboardContainer { get; private set; }
|
protected DimmableStoryboardContainer DimmableStoryboardContainer { get; private set; }
|
||||||
|
|
||||||
protected virtual StoryboardContainer CreateStoryboardContainer(Storyboard storyboard) => new StoryboardContainer(storyboard) { RelativeSizeAxes = Axes.Both };
|
protected virtual DimmableStoryboardContainer CreateStoryboardContainer(Storyboard storyboard) => new DimmableStoryboardContainer(storyboard) { RelativeSizeAxes = Axes.Both };
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
[Cached(Type = typeof(IBindable<IReadOnlyList<Mod>>))]
|
[Cached(Type = typeof(IBindable<IReadOnlyList<Mod>>))]
|
||||||
@ -124,7 +124,7 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
GameplayClockContainer.Children = new[]
|
GameplayClockContainer.Children = new[]
|
||||||
{
|
{
|
||||||
StoryboardContainer = CreateStoryboardContainer(Beatmap.Value.Storyboard),
|
DimmableStoryboardContainer = CreateStoryboardContainer(Beatmap.Value.Storyboard),
|
||||||
new ScalingContainer(ScalingMode.Gameplay)
|
new ScalingContainer(ScalingMode.Gameplay)
|
||||||
{
|
{
|
||||||
Child = new LocalSkinOverrideContainer(working.Skin)
|
Child = new LocalSkinOverrideContainer(working.Skin)
|
||||||
@ -455,7 +455,7 @@ namespace osu.Game.Screens.Play
|
|||||||
Background.BlurAmount.Value = 0;
|
Background.BlurAmount.Value = 0;
|
||||||
|
|
||||||
Background.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground);
|
Background.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground);
|
||||||
StoryboardContainer.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground);
|
DimmableStoryboardContainer.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground);
|
||||||
|
|
||||||
storyboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable;
|
storyboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user