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