// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Configuration; using osuTK.Graphics; namespace osu.Game.Graphics.Containers { public class UserDimContainer : Container { protected Bindable DimLevel; protected Bindable ShowStoryboard; public Bindable EnableUserDim = new Bindable(); public Bindable StoryboardReplacesBackground = new Bindable(); private readonly bool isStoryboard; private const float BACKGROUND_FADE_DURATION = 800; public UserDimContainer(bool isStoryboard = false) { this.isStoryboard = isStoryboard; } [BackgroundDependencyLoader] private void load(OsuConfigManager config) { DimLevel = config.GetBindable(OsuSetting.DimLevel); ShowStoryboard = config.GetBindable(OsuSetting.ShowStoryboard); EnableUserDim.ValueChanged += _ => updateBackgroundDim(); DimLevel.ValueChanged += _ => updateBackgroundDim(); ShowStoryboard.ValueChanged += _ => updateBackgroundDim(); } private void updateBackgroundDim() { if (isStoryboard) { this.FadeTo(!ShowStoryboard || DimLevel == 1 ? 0 : 1, BACKGROUND_FADE_DURATION, Easing.OutQuint); } else { // The background needs to be hidden in the case of it being replaced this.FadeTo(ShowStoryboard && StoryboardReplacesBackground ? 0 : 1, BACKGROUND_FADE_DURATION, Easing.OutQuint); } this.FadeColour(EnableUserDim ? OsuColour.Gray(1 - (float)DimLevel) : Color4.White, BACKGROUND_FADE_DURATION, Easing.OutQuint); } } }