2019-07-09 15:23:59 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2024-09-23 17:08:31 +08:00
|
|
|
using System;
|
2022-03-03 01:33:46 +08:00
|
|
|
using System.Collections.Generic;
|
2024-09-23 17:08:31 +08:00
|
|
|
using System.Linq;
|
2019-07-09 15:23:59 +08:00
|
|
|
using osu.Framework.Allocation;
|
2021-04-16 12:59:10 +08:00
|
|
|
using osu.Framework.Bindables;
|
2020-05-20 01:47:01 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-07-12 10:50:06 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
2022-03-03 01:33:46 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2019-07-09 15:23:59 +08:00
|
|
|
using osu.Game.Storyboards;
|
|
|
|
using osu.Game.Storyboards.Drawables;
|
|
|
|
|
2019-07-12 10:50:06 +08:00
|
|
|
namespace osu.Game.Screens.Play
|
2019-07-09 15:23:59 +08:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// A container that handles <see cref="Storyboard"/> loading, as well as applies user-specified visual settings to it.
|
|
|
|
/// </summary>
|
2019-07-12 10:50:06 +08:00
|
|
|
public partial class DimmableStoryboard : UserDimContainer
|
2019-07-09 15:23:59 +08:00
|
|
|
{
|
2020-05-20 14:08:33 +08:00
|
|
|
public Container OverlayLayerContainer { get; private set; }
|
2020-05-20 01:47:01 +08:00
|
|
|
|
2019-07-09 15:23:59 +08:00
|
|
|
private readonly Storyboard storyboard;
|
2022-03-03 01:33:46 +08:00
|
|
|
private readonly IReadOnlyList<Mod> mods;
|
|
|
|
|
2024-09-23 17:08:31 +08:00
|
|
|
/// <summary>
|
|
|
|
/// In certain circumstances, the storyboard cannot be hidden entirely even if it is fully dimmed. Such circumstances include:
|
|
|
|
/// <list type="bullet">
|
|
|
|
/// <item>
|
|
|
|
/// cases where the storyboard has an overlay layer sprite, as it should continue to display fully dimmed
|
|
|
|
/// <i>in front of</i> the playfield (https://github.com/ppy/osu/issues/29867),
|
|
|
|
/// </item>
|
|
|
|
/// <item>
|
|
|
|
/// cases where the storyboard includes samples - as they are played back via drawable samples,
|
|
|
|
/// they must be present for the playback to occur (https://github.com/ppy/osu/issues/9315).
|
|
|
|
/// </item>
|
|
|
|
/// </list>
|
|
|
|
/// </summary>
|
|
|
|
private readonly Lazy<bool> storyboardMustAlwaysBePresent;
|
|
|
|
|
2019-07-09 15:23:59 +08:00
|
|
|
private DrawableStoryboard drawableStoryboard;
|
|
|
|
|
2021-04-18 11:35:54 +08: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);
|
|
|
|
|
2022-03-03 01:33:46 +08:00
|
|
|
public DimmableStoryboard(Storyboard storyboard, IReadOnlyList<Mod> mods)
|
2019-07-09 15:23:59 +08:00
|
|
|
{
|
|
|
|
this.storyboard = storyboard;
|
2022-03-03 01:33:46 +08:00
|
|
|
this.mods = mods;
|
2024-09-23 17:08:31 +08:00
|
|
|
|
|
|
|
storyboardMustAlwaysBePresent = new Lazy<bool>(() => storyboard.GetLayer(@"Overlay").Elements.Any() || storyboard.Layers.Any(l => l.Elements.OfType<StoryboardSampleInfo>().Any()));
|
2019-07-09 15:23:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2020-05-20 01:47:01 +08:00
|
|
|
Add(OverlayLayerContainer = new Container());
|
|
|
|
|
2019-07-09 15:23:59 +08:00
|
|
|
initializeStoryboard(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
2019-07-10 11:24:05 +08:00
|
|
|
ShowStoryboard.BindValueChanged(_ => initializeStoryboard(true), true);
|
2019-07-09 15:23:59 +08:00
|
|
|
base.LoadComplete();
|
|
|
|
}
|
|
|
|
|
2024-09-23 17:08:31 +08:00
|
|
|
protected override bool ShowDimContent => IgnoreUserSettings.Value || (ShowStoryboard.Value && (DimLevel < 1 || storyboardMustAlwaysBePresent.Value));
|
2019-07-09 15:23:59 +08:00
|
|
|
|
|
|
|
private void initializeStoryboard(bool async)
|
|
|
|
{
|
|
|
|
if (drawableStoryboard != null)
|
|
|
|
return;
|
|
|
|
|
2019-11-24 15:37:06 +08:00
|
|
|
if (!ShowStoryboard.Value && !IgnoreUserSettings.Value)
|
2019-07-09 15:23:59 +08:00
|
|
|
return;
|
|
|
|
|
2022-03-03 01:33:46 +08:00
|
|
|
drawableStoryboard = storyboard.CreateDrawable(mods);
|
2021-04-18 05:55:46 +08:00
|
|
|
HasStoryboardEnded.BindTo(drawableStoryboard.HasStoryboardEnded);
|
2019-07-09 15:23:59 +08:00
|
|
|
|
|
|
|
if (async)
|
2020-05-20 01:47:01 +08:00
|
|
|
LoadComponentAsync(drawableStoryboard, onStoryboardCreated);
|
2019-07-09 15:23:59 +08:00
|
|
|
else
|
2020-05-20 01:47:01 +08:00
|
|
|
onStoryboardCreated(drawableStoryboard);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onStoryboardCreated(DrawableStoryboard storyboard)
|
|
|
|
{
|
|
|
|
Add(storyboard);
|
|
|
|
OverlayLayerContainer.Add(storyboard.OverlayLayer.CreateProxy());
|
2019-07-09 15:23:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|