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;
|
|
|
|
|
|
|
|
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
|
|
|
/// </summary>
|
2019-07-11 12:17:28 +08:00
|
|
|
public abstract class UserDimContainer : Container
|
2019-02-20 15:53:57 +08:00
|
|
|
{
|
2019-07-09 15:23:59 +08:00
|
|
|
protected const float BACKGROUND_FADE_DURATION = 800;
|
2019-02-28 19:01:15 +08:00
|
|
|
|
2019-02-24 19:03:24 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Whether or not user-configured dim levels should be applied to the container.
|
|
|
|
/// </summary>
|
2019-07-12 10:40:32 +08:00
|
|
|
public readonly Bindable<bool> EnableUserDim = new Bindable<bool>(true);
|
2019-02-24 19:03:24 +08:00
|
|
|
|
2019-11-24 15:37:06 +08:00
|
|
|
/// <summary>
|
2019-12-11 00:59:31 +08:00
|
|
|
/// Whether or not user-configured settings relating to brightness of elements should be ignored
|
2019-11-24 15:37:06 +08:00
|
|
|
/// </summary>
|
|
|
|
public readonly Bindable<bool> IgnoreUserSettings = 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-07-12 11:04:45 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Whether the content of this container is currently being displayed.
|
|
|
|
/// </summary>
|
|
|
|
public bool ContentDisplayed { get; private set; }
|
|
|
|
|
2019-12-12 01:39:40 +08:00
|
|
|
public double DimLevel => EnableUserDim.Value ? UserDimLevel.Value : 0;
|
2019-12-11 00:59:31 +08:00
|
|
|
|
2019-07-09 15:23:59 +08:00
|
|
|
protected Bindable<double> UserDimLevel { get; private set; }
|
2019-03-19 19:15:28 +08:00
|
|
|
|
2019-07-09 15:23:59 +08:00
|
|
|
protected Bindable<bool> ShowStoryboard { get; private set; }
|
2019-03-19 19:15:28 +08:00
|
|
|
|
2019-08-31 05:42:20 +08:00
|
|
|
protected Bindable<bool> ShowVideo { get; private set; }
|
|
|
|
|
2019-07-12 10:38:15 +08:00
|
|
|
protected override Container<Drawable> Content => dimContent;
|
2019-02-24 19:03:24 +08:00
|
|
|
|
2019-07-12 10:38:15 +08:00
|
|
|
private Container dimContent { get; }
|
2019-02-21 17:14:58 +08:00
|
|
|
|
2019-02-24 19:03:24 +08:00
|
|
|
/// <summary>
|
2019-03-19 12:06:14 +08:00
|
|
|
/// Creates a new <see cref="UserDimContainer"/>.
|
2019-02-24 19:03:24 +08:00
|
|
|
/// </summary>
|
2019-07-11 12:17:28 +08:00
|
|
|
protected UserDimContainer()
|
2019-02-21 17:14:58 +08:00
|
|
|
{
|
2019-07-12 10:38:15 +08:00
|
|
|
AddInternal(dimContent = new Container { 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-07-09 15:23:59 +08:00
|
|
|
UserDimLevel = config.GetBindable<double>(OsuSetting.DimLevel);
|
|
|
|
ShowStoryboard = config.GetBindable<bool>(OsuSetting.ShowStoryboard);
|
2019-08-31 21:20:33 +08:00
|
|
|
ShowVideo = config.GetBindable<bool>(OsuSetting.ShowVideoBackground);
|
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();
|
2019-08-31 05:42:20 +08:00
|
|
|
ShowVideo.ValueChanged += _ => UpdateVisuals();
|
2019-07-11 12:17:28 +08:00
|
|
|
StoryboardReplacesBackground.ValueChanged += _ => UpdateVisuals();
|
2019-12-12 01:39:40 +08:00
|
|
|
IgnoreUserSettings.ValueChanged += _ => updateSettings();
|
2019-02-20 15:53:57 +08:00
|
|
|
}
|
|
|
|
|
2019-02-24 19:03:24 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2019-07-11 12:17:28 +08:00
|
|
|
UpdateVisuals();
|
2019-02-24 19:03:24 +08:00
|
|
|
}
|
|
|
|
|
2019-07-09 15:23:59 +08:00
|
|
|
/// <summary>
|
2019-07-12 10:38:15 +08:00
|
|
|
/// Whether the content of this container should currently be visible.
|
2019-07-09 15:23:59 +08:00
|
|
|
/// </summary>
|
2019-08-09 03:13:48 +08:00
|
|
|
protected virtual bool ShowDimContent => true;
|
2019-03-13 15:47:03 +08:00
|
|
|
|
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-07-09 15:23:59 +08:00
|
|
|
{
|
2019-08-08 22:29:52 +08:00
|
|
|
ContentDisplayed = ShowDimContent;
|
2019-07-12 11:04:45 +08:00
|
|
|
|
2019-08-08 03:18:10 +08:00
|
|
|
dimContent.FadeTo(ContentDisplayed ? 1 : 0, BACKGROUND_FADE_DURATION, Easing.OutQuint);
|
2019-12-12 01:39:40 +08:00
|
|
|
dimContent.FadeColour(OsuColour.Gray(1 - (float)DimLevel), BACKGROUND_FADE_DURATION, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Invoked when the IgnoreUserSettings bindable is changed
|
|
|
|
/// </summary>
|
|
|
|
private void updateSettings()
|
|
|
|
{
|
|
|
|
EnableUserDim.Value = !IgnoreUserSettings.Value;
|
2019-02-20 15:53:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|