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;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Containers
|
|
|
|
{
|
2019-02-24 19:03:24 +08:00
|
|
|
/// <summary>
|
|
|
|
/// A container that applies user-configured dim levels to its contents.
|
|
|
|
/// This container specifies behavior that applies to both Storyboards and Backgrounds.
|
|
|
|
/// </summary>
|
2019-02-20 15:53:57 +08:00
|
|
|
public class UserDimContainer : Container
|
|
|
|
{
|
|
|
|
protected Bindable<double> DimLevel;
|
2019-02-24 19:03:24 +08:00
|
|
|
|
2019-02-21 17:14:58 +08:00
|
|
|
protected Bindable<bool> ShowStoryboard;
|
2019-02-24 19:03:24 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Whether or not user-configured dim levels should be applied to the container.
|
|
|
|
/// </summary>
|
|
|
|
public readonly Bindable<bool> EnableUserDim = new Bindable<bool>();
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Whether or not the storyboard loaded should completely hide the background behind it.
|
|
|
|
/// </summary>
|
2019-02-21 17:14:58 +08:00
|
|
|
public Bindable<bool> StoryboardReplacesBackground = new Bindable<bool>();
|
2019-02-24 19:03:24 +08:00
|
|
|
|
2019-02-22 19:34:51 +08:00
|
|
|
protected Container DimContainer;
|
2019-02-24 19:03:24 +08:00
|
|
|
|
2019-02-22 19:34:51 +08:00
|
|
|
protected override Container<Drawable> Content => DimContainer;
|
2019-02-21 17:14:58 +08:00
|
|
|
|
|
|
|
private readonly bool isStoryboard;
|
|
|
|
|
2019-02-21 17:34:11 +08:00
|
|
|
private const float background_fade_duration = 800;
|
2019-02-21 17:14:58 +08:00
|
|
|
|
2019-02-24 19:03:24 +08:00
|
|
|
/// <summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="isStoryboard">
|
|
|
|
/// Whether or not this instance of UserDimContainer contains a storyboard.
|
|
|
|
/// 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"/>.
|
|
|
|
/// </param>
|
2019-02-21 17:14:58 +08:00
|
|
|
public UserDimContainer(bool isStoryboard = false)
|
|
|
|
{
|
2019-02-22 19:34:51 +08:00
|
|
|
DimContainer = new Container { RelativeSizeAxes = Axes.Both };
|
2019-02-21 17:14:58 +08:00
|
|
|
this.isStoryboard = isStoryboard;
|
2019-02-22 19:34:51 +08:00
|
|
|
AddInternal(DimContainer);
|
2019-02-21 17:14:58 +08:00
|
|
|
}
|
2019-02-20 15:53:57 +08:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuConfigManager config)
|
|
|
|
{
|
|
|
|
DimLevel = config.GetBindable<double>(OsuSetting.DimLevel);
|
2019-02-21 17:14:58 +08:00
|
|
|
ShowStoryboard = config.GetBindable<bool>(OsuSetting.ShowStoryboard);
|
2019-02-20 15:53:57 +08:00
|
|
|
EnableUserDim.ValueChanged += _ => updateBackgroundDim();
|
|
|
|
DimLevel.ValueChanged += _ => updateBackgroundDim();
|
2019-02-21 17:14:58 +08:00
|
|
|
ShowStoryboard.ValueChanged += _ => updateBackgroundDim();
|
2019-02-22 10:41:28 +08:00
|
|
|
StoryboardReplacesBackground.ValueChanged += _ => updateBackgroundDim();
|
2019-02-20 15:53:57 +08:00
|
|
|
}
|
|
|
|
|
2019-02-24 19:03:24 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
updateBackgroundDim();
|
|
|
|
}
|
|
|
|
|
2019-02-20 15:53:57 +08:00
|
|
|
private void updateBackgroundDim()
|
|
|
|
{
|
2019-02-21 17:14:58 +08:00
|
|
|
if (isStoryboard)
|
|
|
|
{
|
2019-02-22 19:44:02 +08:00
|
|
|
DimContainer.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-02-22 19:44:02 +08:00
|
|
|
DimContainer.FadeTo(ShowStoryboard.Value && StoryboardReplacesBackground.Value ? 0 : 1, background_fade_duration, Easing.OutQuint);
|
2019-02-21 17:14:58 +08:00
|
|
|
}
|
|
|
|
|
2019-02-22 19:44:02 +08:00
|
|
|
DimContainer.FadeColour(EnableUserDim.Value ? OsuColour.Gray(1 - (float)DimLevel.Value) : Color4.White, background_fade_duration, Easing.OutQuint);
|
2019-02-20 15:53:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|