2019-02-20 15:53:57 +08:00
|
|
|
// 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 osu.Framework.Allocation;
|
2019-02-22 19:44:02 +08:00
|
|
|
using osu.Framework.Bindables;
|
2019-02-20 15:53:57 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Configuration;
|
2019-03-13 15:47:03 +08:00
|
|
|
using osuTK;
|
2019-02-20 15:53:57 +08:00
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Containers
|
|
|
|
{
|
2019-02-24 19:03:24 +08:00
|
|
|
/// <summary>
|
2019-03-13 15:47:03 +08:00
|
|
|
/// A container that applies user-configured visual settings to its contents.
|
2019-02-24 19:03:24 +08:00
|
|
|
/// This container specifies behavior that applies to both Storyboards and Backgrounds.
|
|
|
|
/// </summary>
|
2019-03-13 15:47:03 +08:00
|
|
|
public class VisualSettingsContainer : Container
|
2019-02-20 15:53:57 +08:00
|
|
|
{
|
2019-02-28 19:01:15 +08:00
|
|
|
private const float background_fade_duration = 800;
|
|
|
|
|
2019-02-28 19:30:23 +08:00
|
|
|
private Bindable<double> dimLevel { get; set; }
|
2019-02-24 19:03:24 +08:00
|
|
|
|
2019-03-13 15:47:03 +08:00
|
|
|
private Bindable<double> blurLevel { get; set; }
|
|
|
|
|
2019-02-28 19:30:23 +08:00
|
|
|
private Bindable<bool> showStoryboard { get; set; }
|
2019-02-24 19:03:24 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Whether or not user-configured dim levels should be applied to the container.
|
|
|
|
/// </summary>
|
2019-03-13 15:47:03 +08:00
|
|
|
public readonly Bindable<bool> EnableVisualSettings = new Bindable<bool>();
|
2019-02-24 19:03:24 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Whether or not the storyboard loaded should completely hide the background behind it.
|
|
|
|
/// </summary>
|
2019-02-28 17:25:58 +08:00
|
|
|
public readonly Bindable<bool> StoryboardReplacesBackground = new Bindable<bool>();
|
2019-02-24 19:03:24 +08:00
|
|
|
|
2019-03-13 15:47:03 +08:00
|
|
|
protected BufferedContainer LocalContainer { get; }
|
2019-02-24 19:03:24 +08:00
|
|
|
|
2019-03-13 15:47:03 +08:00
|
|
|
protected override Container<Drawable> Content => LocalContainer;
|
2019-02-21 17:14:58 +08:00
|
|
|
|
|
|
|
private readonly bool isStoryboard;
|
|
|
|
|
2019-03-13 15:47:03 +08:00
|
|
|
private Vector2 returnBlur;
|
|
|
|
|
2019-02-24 19:03:24 +08:00
|
|
|
/// <summary>
|
2019-03-13 15:47:03 +08:00
|
|
|
/// Creates a new <see cref="VisualSettingsContainer"/>.
|
2019-02-24 19:03:24 +08:00
|
|
|
/// </summary>
|
2019-03-13 15:47:03 +08:00
|
|
|
/// <param name="isStoryboard"> Whether or not this instance contains a storyboard.
|
2019-02-28 19:30:23 +08:00
|
|
|
/// <remarks>
|
|
|
|
/// While both backgrounds and storyboards allow user dim levels to be applied, storyboards can be toggled via <see cref="showStoryboard"/>
|
2019-03-13 15:47:03 +08:00
|
|
|
/// and can cause backgrounds to become hidden via <see cref="StoryboardReplacesBackground"/>. Storyboards are also currently unable to be blurred.
|
2019-02-28 19:30:23 +08:00
|
|
|
/// </remarks>
|
2019-02-24 19:03:24 +08:00
|
|
|
/// </param>
|
2019-03-13 15:47:03 +08:00
|
|
|
public VisualSettingsContainer(bool isStoryboard = false)
|
2019-02-21 17:14:58 +08:00
|
|
|
{
|
|
|
|
this.isStoryboard = isStoryboard;
|
2019-03-13 15:47:03 +08:00
|
|
|
AddInternal(LocalContainer = new BufferedContainer { RelativeSizeAxes = Axes.Both });
|
2019-02-21 17:14:58 +08:00
|
|
|
}
|
2019-02-20 15:53:57 +08:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuConfigManager config)
|
|
|
|
{
|
2019-02-28 19:30:23 +08:00
|
|
|
dimLevel = config.GetBindable<double>(OsuSetting.DimLevel);
|
2019-03-13 15:47:03 +08:00
|
|
|
blurLevel = config.GetBindable<double>(OsuSetting.BlurLevel);
|
2019-02-28 19:30:23 +08:00
|
|
|
showStoryboard = config.GetBindable<bool>(OsuSetting.ShowStoryboard);
|
2019-03-13 15:47:03 +08:00
|
|
|
EnableVisualSettings.ValueChanged += _ => updateVisuals();
|
|
|
|
dimLevel.ValueChanged += _ => updateVisuals();
|
|
|
|
blurLevel.ValueChanged += _ => updateVisuals();
|
|
|
|
showStoryboard.ValueChanged += _ => updateVisuals();
|
|
|
|
StoryboardReplacesBackground.ValueChanged += _ => updateVisuals();
|
2019-02-20 15:53:57 +08:00
|
|
|
}
|
|
|
|
|
2019-02-24 19:03:24 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2019-03-13 15:47:03 +08:00
|
|
|
updateVisuals();
|
2019-02-24 19:03:24 +08:00
|
|
|
}
|
|
|
|
|
2019-03-13 15:47:03 +08:00
|
|
|
private void updateVisuals()
|
2019-02-20 15:53:57 +08:00
|
|
|
{
|
2019-02-21 17:14:58 +08:00
|
|
|
if (isStoryboard)
|
|
|
|
{
|
2019-03-13 15:47:03 +08:00
|
|
|
LocalContainer.FadeTo(!showStoryboard.Value || dimLevel.Value == 1 ? 0 : 1, background_fade_duration, Easing.OutQuint);
|
2019-02-21 17:14:58 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-24 19:03:24 +08:00
|
|
|
// The background needs to be hidden in the case of it being replaced by the storyboard
|
2019-03-13 15:47:03 +08:00
|
|
|
LocalContainer.FadeTo(showStoryboard.Value && StoryboardReplacesBackground.Value ? 0 : 1, background_fade_duration, Easing.OutQuint);
|
|
|
|
|
|
|
|
// Only blur if this container contains a background
|
|
|
|
LocalContainer.BlurTo(EnableVisualSettings.Value ? new Vector2((float)blurLevel.Value * 25) : new Vector2(0), background_fade_duration, Easing.OutQuint);
|
2019-02-21 17:14:58 +08:00
|
|
|
}
|
|
|
|
|
2019-03-13 15:47:03 +08:00
|
|
|
LocalContainer.FadeColour(EnableVisualSettings.Value ? OsuColour.Gray(1 - (float)dimLevel.Value) : Color4.White, background_fade_duration, Easing.OutQuint);
|
2019-02-20 15:53:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|