osu/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs

74 lines
2.6 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.
2018-04-13 09:19:50 +00:00
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Screens;
using osu.Game.Configuration;
using osu.Game.Graphics;
2018-04-13 09:19:50 +00:00
using osu.Game.Screens.Backgrounds;
2018-11-20 07:51:59 +00:00
using osuTK;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Screens.Play
{
public abstract class ScreenWithBeatmapBackground : OsuScreen
{
protected override BackgroundScreen CreateBackground() => new UserDimmableBackgroundScreenBeatmap(Beatmap.Value);
2018-04-13 09:19:50 +00:00
protected new UserDimmableBackgroundScreenBeatmap Background => base.Background as UserDimmableBackgroundScreenBeatmap;
2018-04-13 09:19:50 +00:00
public override bool AllowBeatmapRulesetChange => false;
protected const float BACKGROUND_FADE_DURATION = 800;
protected float BackgroundOpacity => 1 - (float)DimLevel;
#region User Settings
protected Bindable<double> DimLevel;
protected Bindable<double> BlurLevel;
protected Bindable<bool> ShowStoryboard;
#endregion
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
DimLevel = config.GetBindable<double>(OsuSetting.DimLevel);
BlurLevel = config.GetBindable<double>(OsuSetting.BlurLevel);
ShowStoryboard = config.GetBindable<bool>(OsuSetting.ShowStoryboard);
}
2019-01-23 11:52:00 +00:00
public override void OnEntering(IScreen last)
2018-04-13 09:19:50 +00:00
{
base.OnEntering(last);
BlurLevel.ValueChanged += _ => UpdateBackgroundElements();
ShowStoryboard.ValueChanged += _ => UpdateBackgroundElements();
InitializeBackgroundElements();
2018-04-13 09:19:50 +00:00
}
2019-01-23 11:52:00 +00:00
public override void OnResuming(IScreen last)
2018-04-13 09:19:50 +00:00
{
base.OnResuming(last);
InitializeBackgroundElements();
2018-04-13 09:19:50 +00:00
}
/// <summary>
/// Called once on entering screen. By Default, performs a full <see cref="UpdateBackgroundElements"/> call.
/// </summary>
protected virtual void InitializeBackgroundElements() => UpdateBackgroundElements();
/// <summary>
2019-01-23 08:14:08 +00:00
/// Called when background elements require updates, usually due to a user changing a setting.
/// </summary>
/// <param name="userChange"></param>
2018-04-13 09:19:50 +00:00
protected virtual void UpdateBackgroundElements()
{
2019-01-23 11:52:00 +00:00
if (!this.IsCurrentScreen()) return;
2018-04-13 09:19:50 +00:00
Background?.BlurTo(new Vector2((float)BlurLevel.Value * 25), BACKGROUND_FADE_DURATION, Easing.OutQuint);
2018-04-13 09:19:50 +00:00
}
}
}