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;
|
2021-04-16 04:59:10 +00:00
|
|
|
using osu.Framework.Bindables;
|
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;
|
|
|
|
|
2021-04-18 03:35:54 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Whether the storyboard is considered finished.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// This is true by default in here, until an actual drawable storyboard is loaded, in which case it'll bind to it.
|
|
|
|
/// </remarks>
|
|
|
|
public IBindable<bool> HasStoryboardEnded = new BindableBool(true);
|
|
|
|
|
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();
|
2021-04-17 21:55:46 +00:00
|
|
|
HasStoryboardEnded.BindTo(drawableStoryboard.HasStoryboardEnded);
|
2019-07-09 07:23:59 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|