2019-02-20 07:53:57 +00: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.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2019-12-10 12:13:44 +00:00
|
|
|
using System;
|
2019-02-20 07:53:57 +00:00
|
|
|
using osu.Framework.Allocation;
|
2019-02-22 11:44:02 +00:00
|
|
|
using osu.Framework.Bindables;
|
2019-02-20 07:53:57 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Configuration;
|
2019-12-10 12:13:44 +00:00
|
|
|
using osu.Game.Screens.Play;
|
2019-02-20 07:53:57 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Containers
|
|
|
|
{
|
2019-02-24 11:03:24 +00:00
|
|
|
/// <summary>
|
2019-03-13 07:47:03 +00:00
|
|
|
/// A container that applies user-configured visual settings to its contents.
|
2019-02-24 11:03:24 +00:00
|
|
|
/// </summary>
|
2019-07-11 04:17:28 +00:00
|
|
|
public abstract class UserDimContainer : Container
|
2019-02-20 07:53:57 +00:00
|
|
|
{
|
2019-12-11 21:32:39 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Amount of lightening to apply to current dim level during break times.
|
|
|
|
/// </summary>
|
2019-12-12 11:51:58 +00:00
|
|
|
public const float BREAK_LIGHTEN_AMOUNT = 0.3f;
|
2019-12-10 12:13:44 +00:00
|
|
|
|
|
|
|
protected const double BACKGROUND_FADE_DURATION = 800;
|
2019-02-28 11:01:15 +00:00
|
|
|
|
2019-11-24 07:37:06 +00:00
|
|
|
/// <summary>
|
2019-12-10 16:59:31 +00:00
|
|
|
/// Whether or not user-configured settings relating to brightness of elements should be ignored
|
2019-11-24 07:37:06 +00:00
|
|
|
/// </summary>
|
|
|
|
public readonly Bindable<bool> IgnoreUserSettings = new Bindable<bool>();
|
|
|
|
|
2019-02-24 11:03:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Whether or not the storyboard loaded should completely hide the background behind it.
|
|
|
|
/// </summary>
|
2019-02-28 09:25:58 +00:00
|
|
|
public readonly Bindable<bool> StoryboardReplacesBackground = new Bindable<bool>();
|
2019-02-24 11:03:24 +00:00
|
|
|
|
2019-12-10 12:13:44 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Whether player is in break time.
|
2020-03-26 06:28:56 +00:00
|
|
|
/// Must be bound to <see cref="BreakTracker.IsBreakTime"/> to allow for dim adjustments in gameplay.
|
2019-12-10 12:13:44 +00:00
|
|
|
/// </summary>
|
2019-12-11 21:32:39 +00:00
|
|
|
public readonly IBindable<bool> IsBreakTime = new Bindable<bool>();
|
2019-12-10 12:13:44 +00:00
|
|
|
|
2019-07-12 03:04:45 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Whether the content of this container is currently being displayed.
|
|
|
|
/// </summary>
|
|
|
|
public bool ContentDisplayed { get; private set; }
|
|
|
|
|
2019-07-09 07:23:59 +00:00
|
|
|
protected Bindable<double> UserDimLevel { get; private set; }
|
2019-03-19 11:15:28 +00:00
|
|
|
|
2019-12-10 12:13:44 +00:00
|
|
|
protected Bindable<bool> LightenDuringBreaks { get; private set; }
|
|
|
|
|
2019-07-09 07:23:59 +00:00
|
|
|
protected Bindable<bool> ShowStoryboard { get; private set; }
|
2019-03-19 11:15:28 +00:00
|
|
|
|
2019-12-12 11:51:58 +00:00
|
|
|
private float breakLightening => LightenDuringBreaks.Value && IsBreakTime.Value ? BREAK_LIGHTEN_AMOUNT : 0;
|
2019-12-17 03:52:55 +00:00
|
|
|
|
2021-04-13 06:24:35 +00:00
|
|
|
protected float DimLevel => Math.Max(!IgnoreUserSettings.Value ? (float)UserDimLevel.Value - breakLightening : 0, 0);
|
2019-08-08 19:13:48 +00:00
|
|
|
|
2019-07-12 02:38:15 +00:00
|
|
|
protected override Container<Drawable> Content => dimContent;
|
2019-02-24 11:03:24 +00:00
|
|
|
|
2019-07-12 02:38:15 +00:00
|
|
|
private Container dimContent { get; }
|
2019-02-21 09:14:58 +00:00
|
|
|
|
2019-02-24 11:03:24 +00:00
|
|
|
/// <summary>
|
2019-03-19 04:06:14 +00:00
|
|
|
/// Creates a new <see cref="UserDimContainer"/>.
|
2019-02-24 11:03:24 +00:00
|
|
|
/// </summary>
|
2019-07-11 04:17:28 +00:00
|
|
|
protected UserDimContainer()
|
2019-02-21 09:14:58 +00:00
|
|
|
{
|
2019-07-12 02:38:15 +00:00
|
|
|
AddInternal(dimContent = new Container { RelativeSizeAxes = Axes.Both });
|
2019-02-21 09:14:58 +00:00
|
|
|
}
|
2019-02-20 07:53:57 +00:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuConfigManager config)
|
|
|
|
{
|
2019-07-09 07:23:59 +00:00
|
|
|
UserDimLevel = config.GetBindable<double>(OsuSetting.DimLevel);
|
2019-12-10 12:13:44 +00:00
|
|
|
LightenDuringBreaks = config.GetBindable<bool>(OsuSetting.LightenDuringBreaks);
|
2019-07-09 07:23:59 +00:00
|
|
|
ShowStoryboard = config.GetBindable<bool>(OsuSetting.ShowStoryboard);
|
2019-03-20 10:38:53 +00:00
|
|
|
|
2019-07-11 04:17:28 +00:00
|
|
|
UserDimLevel.ValueChanged += _ => UpdateVisuals();
|
2019-12-10 12:13:44 +00:00
|
|
|
LightenDuringBreaks.ValueChanged += _ => UpdateVisuals();
|
|
|
|
IsBreakTime.ValueChanged += _ => UpdateVisuals();
|
2019-07-11 04:17:28 +00:00
|
|
|
ShowStoryboard.ValueChanged += _ => UpdateVisuals();
|
|
|
|
StoryboardReplacesBackground.ValueChanged += _ => UpdateVisuals();
|
2019-12-17 04:21:23 +00:00
|
|
|
IgnoreUserSettings.ValueChanged += _ => UpdateVisuals();
|
2019-02-20 07:53:57 +00:00
|
|
|
}
|
|
|
|
|
2019-02-24 11:03:24 +00:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2019-07-11 04:17:28 +00:00
|
|
|
UpdateVisuals();
|
2019-02-24 11:03:24 +00:00
|
|
|
}
|
|
|
|
|
2019-07-09 07:23:59 +00:00
|
|
|
/// <summary>
|
2019-07-12 02:38:15 +00:00
|
|
|
/// Whether the content of this container should currently be visible.
|
2019-07-09 07:23:59 +00:00
|
|
|
/// </summary>
|
2019-08-08 19:13:48 +00:00
|
|
|
protected virtual bool ShowDimContent => true;
|
2019-03-13 07:47:03 +00:00
|
|
|
|
2019-07-12 02:38:15 +00: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 07:23:59 +00:00
|
|
|
{
|
2019-08-08 14:29:52 +00:00
|
|
|
ContentDisplayed = ShowDimContent;
|
2019-07-12 03:04:45 +00:00
|
|
|
|
2019-08-07 19:18:10 +00:00
|
|
|
dimContent.FadeTo(ContentDisplayed ? 1 : 0, BACKGROUND_FADE_DURATION, Easing.OutQuint);
|
2019-12-10 12:13:44 +00:00
|
|
|
dimContent.FadeColour(OsuColour.Gray(1f - DimLevel), BACKGROUND_FADE_DURATION, Easing.OutQuint);
|
2019-12-11 17:39:40 +00:00
|
|
|
}
|
2019-02-20 07:53:57 +00:00
|
|
|
}
|
|
|
|
}
|