2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
|
using osu.Game.Configuration;
|
2019-01-23 15:52:25 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Screens.Backgrounds;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
|
{
|
|
|
|
|
public abstract class ScreenWithBeatmapBackground : OsuScreen
|
|
|
|
|
{
|
2018-05-23 16:37:39 +08:00
|
|
|
|
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap.Value);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-08-02 17:16:36 +08:00
|
|
|
|
protected new BackgroundScreenBeatmap Background => (BackgroundScreenBeatmap)base.Background;
|
|
|
|
|
|
2018-04-13 17:19:50 +08: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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnEntering(Screen last)
|
|
|
|
|
{
|
|
|
|
|
base.OnEntering(last);
|
|
|
|
|
DimLevel.ValueChanged += _ => UpdateBackgroundElements();
|
|
|
|
|
BlurLevel.ValueChanged += _ => UpdateBackgroundElements();
|
|
|
|
|
ShowStoryboard.ValueChanged += _ => UpdateBackgroundElements();
|
2018-08-02 17:16:36 +08:00
|
|
|
|
InitializeBackgroundElements();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnResuming(Screen last)
|
|
|
|
|
{
|
|
|
|
|
base.OnResuming(last);
|
2018-08-02 17:16:36 +08:00
|
|
|
|
InitializeBackgroundElements();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-02 17:16:36 +08: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 16:14:08 +08:00
|
|
|
|
/// Called when background elements require updates, usually due to a user changing a setting.
|
2018-08-02 17:16:36 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="userChange"></param>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
protected virtual void UpdateBackgroundElements()
|
|
|
|
|
{
|
|
|
|
|
if (!IsCurrentScreen) return;
|
|
|
|
|
|
2019-01-23 15:52:25 +08:00
|
|
|
|
Background?.FadeColour(OsuColour.Gray(BackgroundOpacity), BACKGROUND_FADE_DURATION, Easing.OutQuint);
|
2018-08-02 17:16:36 +08:00
|
|
|
|
Background?.BlurTo(new Vector2((float)BlurLevel.Value * 25), BACKGROUND_FADE_DURATION, Easing.OutQuint);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|