2019-07-09 07:23:59 +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.
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2020-05-19 17:47:01 +00:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-07-12 02:50:06 +00:00
|
|
|
using osu.Game.Graphics.Containers;
|
2019-07-09 07:23:59 +00:00
|
|
|
using osu.Game.Storyboards;
|
|
|
|
using osu.Game.Storyboards.Drawables;
|
|
|
|
|
2019-07-12 02:50:06 +00:00
|
|
|
namespace osu.Game.Screens.Play
|
2019-07-09 07:23:59 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// A container that handles <see cref="Storyboard"/> loading, as well as applies user-specified visual settings to it.
|
|
|
|
/// </summary>
|
2019-07-12 02:50:06 +00:00
|
|
|
public class DimmableStoryboard : UserDimContainer
|
2019-07-09 07:23:59 +00:00
|
|
|
{
|
2020-05-20 06:08:33 +00:00
|
|
|
public Container OverlayLayerContainer { get; private set; }
|
2020-05-19 17:47:01 +00:00
|
|
|
|
2019-07-09 07:23:59 +00:00
|
|
|
private readonly Storyboard storyboard;
|
|
|
|
private DrawableStoryboard drawableStoryboard;
|
|
|
|
|
2019-07-12 02:50:06 +00:00
|
|
|
public DimmableStoryboard(Storyboard storyboard)
|
2019-07-09 07:23:59 +00:00
|
|
|
{
|
|
|
|
this.storyboard = storyboard;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2020-05-19 17:47:01 +00:00
|
|
|
Add(OverlayLayerContainer = new Container());
|
|
|
|
|
2019-07-09 07:23:59 +00:00
|
|
|
initializeStoryboard(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
2019-07-10 03:24:05 +00:00
|
|
|
ShowStoryboard.BindValueChanged(_ => initializeStoryboard(true), true);
|
2019-07-09 07:23:59 +00:00
|
|
|
base.LoadComplete();
|
|
|
|
}
|
|
|
|
|
2019-11-24 07:42:39 +00:00
|
|
|
protected override bool ShowDimContent => IgnoreUserSettings.Value || (ShowStoryboard.Value && DimLevel < 1);
|
2019-07-09 07:23:59 +00:00
|
|
|
|
|
|
|
private void initializeStoryboard(bool async)
|
|
|
|
{
|
|
|
|
if (drawableStoryboard != null)
|
|
|
|
return;
|
|
|
|
|
2019-11-24 07:37:06 +00:00
|
|
|
if (!ShowStoryboard.Value && !IgnoreUserSettings.Value)
|
2019-07-09 07:23:59 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
drawableStoryboard = storyboard.CreateDrawable();
|
|
|
|
|
|
|
|
if (async)
|
2020-05-19 17:47:01 +00:00
|
|
|
LoadComponentAsync(drawableStoryboard, onStoryboardCreated);
|
2019-07-09 07:23:59 +00:00
|
|
|
else
|
2020-05-19 17:47:01 +00:00
|
|
|
onStoryboardCreated(drawableStoryboard);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onStoryboardCreated(DrawableStoryboard storyboard)
|
|
|
|
{
|
|
|
|
Add(storyboard);
|
|
|
|
OverlayLayerContainer.Add(storyboard.OverlayLayer.CreateProxy());
|
2019-07-09 07:23:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|