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
|
|
|
|
|
2020-05-18 21:12:14 +02:00
|
|
|
|
using System.Linq;
|
2019-05-10 16:31:09 +09:00
|
|
|
|
using System.Threading;
|
2018-11-20 16:51:59 +09:00
|
|
|
|
using osuTK;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
using osu.Framework.Allocation;
|
2021-04-16 00:59:10 -04:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2020-12-21 13:35:46 +09:00
|
|
|
|
using osu.Framework.Platform;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
using osu.Game.IO;
|
2019-03-18 15:25:54 +09:00
|
|
|
|
using osu.Game.Screens.Play;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Storyboards.Drawables
|
|
|
|
|
{
|
|
|
|
|
public class DrawableStoryboard : Container<DrawableStoryboardLayer>
|
|
|
|
|
{
|
2020-10-19 23:40:20 +02:00
|
|
|
|
[Cached]
|
2020-01-20 13:50:27 +09:00
|
|
|
|
public Storyboard Storyboard { get; }
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2021-05-04 16:48:13 +09:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the storyboard is considered finished.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public IBindable<bool> HasStoryboardEnded => hasStoryboardEnded;
|
|
|
|
|
|
2021-06-18 16:08:49 +09:00
|
|
|
|
private readonly BindableBool hasStoryboardEnded = new BindableBool(true);
|
2021-05-04 16:48:13 +09:00
|
|
|
|
|
2019-11-12 17:45:42 +08:00
|
|
|
|
protected override Container<DrawableStoryboardLayer> Content { get; }
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
|
|
|
|
protected override Vector2 DrawScale => new Vector2(Parent.DrawHeight / 480);
|
|
|
|
|
|
|
|
|
|
private bool passing = true;
|
2019-02-28 13:31:40 +09:00
|
|
|
|
|
2018-04-13 18:19:50 +09:00
|
|
|
|
public bool Passing
|
|
|
|
|
{
|
2019-02-28 13:58:19 +09:00
|
|
|
|
get => passing;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (passing == value) return;
|
2019-02-28 13:31:40 +09:00
|
|
|
|
|
2018-04-13 18:19:50 +09:00
|
|
|
|
passing = value;
|
|
|
|
|
updateLayerVisibility();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool RemoveCompletedTransforms => false;
|
|
|
|
|
|
2021-05-04 16:48:13 +09:00
|
|
|
|
private double? lastEventEndTime;
|
|
|
|
|
|
2018-04-13 18:19:50 +09:00
|
|
|
|
private DependencyContainer dependencies;
|
2019-02-28 13:31:40 +09:00
|
|
|
|
|
2018-07-11 17:07:14 +09:00
|
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) =>
|
|
|
|
|
dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
|
|
|
|
public DrawableStoryboard(Storyboard storyboard)
|
|
|
|
|
{
|
|
|
|
|
Storyboard = storyboard;
|
2021-05-25 16:07:17 +09:00
|
|
|
|
|
2018-04-13 18:19:50 +09:00
|
|
|
|
Size = new Vector2(640, 480);
|
2021-05-25 16:06:39 +09:00
|
|
|
|
|
2021-05-25 18:51:49 +09:00
|
|
|
|
bool onlyHasVideoElements = Storyboard.Layers.SelectMany(l => l.Elements).Any(e => !(e is StoryboardVideo));
|
2021-05-25 16:07:17 +09:00
|
|
|
|
|
|
|
|
|
Width = Height * (storyboard.BeatmapInfo.WidescreenStoryboard || onlyHasVideoElements ? 16 / 9f : 4 / 3f);
|
2021-05-25 16:06:39 +09:00
|
|
|
|
|
2018-04-13 18:19:50 +09:00
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
|
2019-11-12 17:45:42 +08:00
|
|
|
|
AddInternal(Content = new Container<DrawableStoryboardLayer>
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2020-03-30 21:37:20 +02:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2018-04-13 18:19:50 +09:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-18 15:50:34 +09:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2020-12-21 13:35:46 +09:00
|
|
|
|
private void load(FileStore fileStore, GameplayClock clock, CancellationToken? cancellationToken, GameHost host)
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2019-03-18 18:19:59 +09:00
|
|
|
|
if (clock != null)
|
2019-03-18 15:25:54 +09:00
|
|
|
|
Clock = clock;
|
|
|
|
|
|
2020-12-21 13:35:46 +09:00
|
|
|
|
dependencies.Cache(new TextureStore(host.CreateTextureLoaderStore(fileStore.Store), false, scaleAdjust: 1));
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
|
|
|
|
foreach (var layer in Storyboard.Layers)
|
2019-05-10 16:31:09 +09:00
|
|
|
|
{
|
2019-05-10 17:42:45 +09:00
|
|
|
|
cancellationToken?.ThrowIfCancellationRequested();
|
2019-05-10 16:31:09 +09:00
|
|
|
|
|
2018-04-13 18:19:50 +09:00
|
|
|
|
Add(layer.CreateDrawable());
|
2019-05-10 16:31:09 +09:00
|
|
|
|
}
|
2020-05-18 21:12:14 +02:00
|
|
|
|
|
2021-05-04 16:48:13 +09:00
|
|
|
|
lastEventEndTime = Storyboard.LatestEventTime;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
}
|
2021-04-16 00:59:10 -04:00
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
2021-05-04 16:48:13 +09:00
|
|
|
|
hasStoryboardEnded.Value = lastEventEndTime == null || Time.Current >= lastEventEndTime;
|
2021-04-16 00:59:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-04 16:48:13 +09:00
|
|
|
|
public DrawableStoryboardLayer OverlayLayer => Children.Single(layer => layer.Name == "Overlay");
|
2021-04-16 00:59:10 -04:00
|
|
|
|
|
2021-05-04 16:48:13 +09:00
|
|
|
|
private void updateLayerVisibility()
|
2021-04-16 00:59:10 -04:00
|
|
|
|
{
|
2021-05-04 16:48:13 +09:00
|
|
|
|
foreach (var layer in Children)
|
|
|
|
|
layer.Enabled = passing ? layer.Layer.VisibleWhenPassing : layer.Layer.VisibleWhenFailing;
|
2021-04-16 00:59:10 -04:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
}
|
|
|
|
|
}
|