1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 20:47:25 +08:00
osu-lazer/osu.Game/Graphics/Containers/UserDimContainer.cs

86 lines
3.1 KiB
C#
Raw Normal View History

// 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;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Configuration;
using osuTK.Graphics;
namespace osu.Game.Graphics.Containers
{
/// <summary>
/// A container that applies user-configured visual settings to its contents.
/// </summary>
2019-07-11 12:17:28 +08:00
public abstract class UserDimContainer : Container
{
protected const float BACKGROUND_FADE_DURATION = 800;
/// <summary>
/// Whether or not user-configured dim levels should be applied to the container.
/// </summary>
public readonly Bindable<bool> EnableUserDim = new Bindable<bool>(true);
/// <summary>
/// Whether or not the storyboard loaded should completely hide the background behind it.
/// </summary>
public readonly Bindable<bool> StoryboardReplacesBackground = new Bindable<bool>();
/// <summary>
/// Whether the content of this container is currently being displayed.
/// </summary>
public bool ContentDisplayed { get; private set; }
protected Bindable<double> UserDimLevel { get; private set; }
protected Bindable<bool> ShowStoryboard { get; private set; }
2019-07-12 10:38:15 +08:00
protected override Container<Drawable> Content => dimContent;
2019-07-12 10:38:15 +08:00
private Container dimContent { get; }
/// <summary>
2019-03-19 12:06:14 +08:00
/// Creates a new <see cref="UserDimContainer"/>.
/// </summary>
2019-07-11 12:17:28 +08:00
protected UserDimContainer()
{
2019-07-12 10:38:15 +08:00
AddInternal(dimContent = new Container { RelativeSizeAxes = Axes.Both });
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
UserDimLevel = config.GetBindable<double>(OsuSetting.DimLevel);
ShowStoryboard = config.GetBindable<bool>(OsuSetting.ShowStoryboard);
2019-03-20 18:38:53 +08:00
2019-07-11 12:17:28 +08:00
EnableUserDim.ValueChanged += _ => UpdateVisuals();
UserDimLevel.ValueChanged += _ => UpdateVisuals();
ShowStoryboard.ValueChanged += _ => UpdateVisuals();
StoryboardReplacesBackground.ValueChanged += _ => UpdateVisuals();
}
protected override void LoadComplete()
{
base.LoadComplete();
2019-07-11 12:17:28 +08:00
UpdateVisuals();
}
/// <summary>
2019-07-12 10:38:15 +08:00
/// Whether the content of this container should currently be visible.
/// </summary>
protected virtual bool ShowDimContent => !EnableUserDim.Value;
2019-07-12 10:38:15 +08:00
/// <summary>
/// Should be invoked when any dependent dim level or user setting is changed and bring the visual state up-to-date.
/// </summary>
protected virtual void UpdateVisuals()
{
2019-08-08 22:29:52 +08:00
ContentDisplayed = ShowDimContent;
dimContent.FadeTo(ContentDisplayed ? 1 : 0, BACKGROUND_FADE_DURATION, Easing.OutQuint);
2019-07-12 10:38:15 +08:00
dimContent.FadeColour(EnableUserDim.Value ? OsuColour.Gray(1 - (float)UserDimLevel.Value) : Color4.White, BACKGROUND_FADE_DURATION, Easing.OutQuint);
}
}
}