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
|
|
|
|
|
2022-03-04 12:05:02 +09:00
|
|
|
|
using System;
|
2022-03-02 20:33:46 +03:00
|
|
|
|
using System.Collections.Generic;
|
2023-09-14 16:06:59 +09:00
|
|
|
|
using System.IO;
|
2020-05-18 21:12:14 +02:00
|
|
|
|
using System.Linq;
|
2019-05-10 16:31:09 +09:00
|
|
|
|
using System.Threading;
|
2023-09-14 16:06:59 +09:00
|
|
|
|
using System.Threading.Tasks;
|
2017-09-07 23:55:05 +02:00
|
|
|
|
using osu.Framework.Allocation;
|
2021-04-16 00:59:10 -04:00
|
|
|
|
using osu.Framework.Bindables;
|
2017-09-07 23:55:05 +02:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2023-09-14 16:06:59 +09:00
|
|
|
|
using osu.Framework.IO.Stores;
|
2020-12-21 13:35:46 +09:00
|
|
|
|
using osu.Framework.Platform;
|
2021-12-21 16:09:19 +09:00
|
|
|
|
using osu.Game.Database;
|
2022-03-02 20:33:46 +03:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2019-03-18 15:25:54 +09:00
|
|
|
|
using osu.Game.Screens.Play;
|
2023-09-14 16:06:59 +09:00
|
|
|
|
using osuTK;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-09-07 23:55:05 +02:00
|
|
|
|
namespace osu.Game.Storyboards.Drawables
|
|
|
|
|
{
|
2017-09-13 11:22:24 +02:00
|
|
|
|
public partial class DrawableStoryboard : Container<DrawableStoryboardLayer>
|
2017-09-07 23:55:05 +02:00
|
|
|
|
{
|
2023-09-11 23:59:44 +09:00
|
|
|
|
[Cached(typeof(Storyboard))]
|
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
|
|
|
|
|
2023-10-17 17:40:44 +09:00
|
|
|
|
protected override Vector2 DrawScale => new Vector2(Parent!.DrawHeight / 480);
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2018-03-04 01:48:00 +09:00
|
|
|
|
public override bool RemoveCompletedTransforms => false;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2021-05-04 16:48:13 +09:00
|
|
|
|
private double? lastEventEndTime;
|
|
|
|
|
|
2022-03-02 20:33:46 +03:00
|
|
|
|
[Cached(typeof(IReadOnlyList<Mod>))]
|
|
|
|
|
public IReadOnlyList<Mod> Mods { get; }
|
|
|
|
|
|
2023-09-14 16:06:59 +09:00
|
|
|
|
[Resolved]
|
|
|
|
|
private GameHost host { get; set; } = null!;
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private RealmAccess realm { get; set; } = null!;
|
|
|
|
|
|
|
|
|
|
private DependencyContainer dependencies = null!;
|
2019-02-28 13:31:40 +09:00
|
|
|
|
|
2024-06-14 13:36:40 +02:00
|
|
|
|
private BindableNumber<double> health = null!;
|
|
|
|
|
private readonly BindableBool passing = new BindableBool(true);
|
|
|
|
|
|
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
|
|
|
|
|
2023-09-14 16:06:59 +09:00
|
|
|
|
public DrawableStoryboard(Storyboard storyboard, IReadOnlyList<Mod>? mods = null)
|
2017-09-07 23:55:05 +02:00
|
|
|
|
{
|
2017-09-13 11:22:24 +02:00
|
|
|
|
Storyboard = storyboard;
|
2022-03-04 12:05:02 +09:00
|
|
|
|
Mods = mods ?? Array.Empty<Mod>();
|
2021-05-25 16:07:17 +09:00
|
|
|
|
|
2017-09-07 23:55:05 +02:00
|
|
|
|
Size = new Vector2(640, 480);
|
2021-05-25 16:06:39 +09:00
|
|
|
|
|
2023-05-16 21:51:32 -07:00
|
|
|
|
bool onlyHasVideoElements = Storyboard.Layers.SelectMany(l => l.Elements).All(e => e is StoryboardVideo);
|
2021-05-25 16:07:17 +09:00
|
|
|
|
|
2024-06-12 13:23:53 +02:00
|
|
|
|
Width = Height * (storyboard.Beatmap.WidescreenStoryboard || onlyHasVideoElements ? 16 / 9f : 4 / 3f);
|
2021-05-25 16:06:39 +09:00
|
|
|
|
|
2017-09-07 23:55:05 +02:00
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
|
Origin = Anchor.Centre;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2019-11-12 17:45:42 +08:00
|
|
|
|
AddInternal(Content = new Container<DrawableStoryboardLayer>
|
2017-09-14 14:28:53 +02:00
|
|
|
|
{
|
2020-03-30 21:37:20 +02:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-09-14 14:28:53 +02:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
});
|
2017-09-07 23:55:05 +02:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2024-06-14 13:36:40 +02:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(IGameplayClock? clock, CancellationToken? cancellationToken, GameplayState? gameplayState)
|
2017-09-07 23:55:05 +02:00
|
|
|
|
{
|
2019-03-18 18:19:59 +09:00
|
|
|
|
if (clock != null)
|
2019-03-18 15:25:54 +09:00
|
|
|
|
Clock = clock;
|
|
|
|
|
|
2023-09-14 16:06:59 +09:00
|
|
|
|
dependencies.CacheAs(typeof(TextureStore),
|
|
|
|
|
new TextureStore(host.Renderer, host.CreateTextureLoaderStore(
|
|
|
|
|
CreateResourceLookupStore()
|
|
|
|
|
), false, scaleAdjust: 1));
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-09-13 11:22:24 +02: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
|
|
|
|
|
2017-09-13 11:22:24 +02: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;
|
2024-06-14 13:36:40 +02:00
|
|
|
|
|
|
|
|
|
health = gameplayState?.HealthProcessor.Health.GetBoundCopy() ?? new BindableDouble(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
health.BindValueChanged(val => passing.Value = val.NewValue >= 0.5, true);
|
|
|
|
|
passing.BindValueChanged(_ => updateLayerVisibility(), true);
|
2017-09-07 23:55:05 +02:00
|
|
|
|
}
|
2021-04-16 00:59:10 -04:00
|
|
|
|
|
2023-09-14 16:06:59 +09:00
|
|
|
|
protected virtual IResourceStore<byte[]> CreateResourceLookupStore() => new StoryboardResourceLookupStore(Storyboard, realm, host);
|
|
|
|
|
|
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)
|
2024-06-14 13:36:40 +02:00
|
|
|
|
layer.Enabled = passing.Value ? layer.Layer.VisibleWhenPassing : layer.Layer.VisibleWhenFailing;
|
2021-04-16 00:59:10 -04:00
|
|
|
|
}
|
2023-09-14 16:06:59 +09:00
|
|
|
|
|
|
|
|
|
private class StoryboardResourceLookupStore : IResourceStore<byte[]>
|
|
|
|
|
{
|
|
|
|
|
private readonly IResourceStore<byte[]> realmFileStore;
|
|
|
|
|
private readonly Storyboard storyboard;
|
|
|
|
|
|
|
|
|
|
public StoryboardResourceLookupStore(Storyboard storyboard, RealmAccess realm, GameHost host)
|
|
|
|
|
{
|
|
|
|
|
realmFileStore = new RealmFileStore(realm, host.Storage).Store;
|
|
|
|
|
this.storyboard = storyboard;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose() =>
|
|
|
|
|
realmFileStore.Dispose();
|
|
|
|
|
|
2023-09-19 20:11:16 +02:00
|
|
|
|
public byte[] Get(string name)
|
|
|
|
|
{
|
|
|
|
|
string? storagePath = storyboard.GetStoragePathFromStoryboardPath(name);
|
2023-09-14 16:06:59 +09:00
|
|
|
|
|
2023-09-19 20:11:16 +02:00
|
|
|
|
return string.IsNullOrEmpty(storagePath)
|
|
|
|
|
? null!
|
|
|
|
|
: realmFileStore.Get(storagePath);
|
|
|
|
|
}
|
2023-09-14 16:06:59 +09:00
|
|
|
|
|
2023-09-19 20:11:16 +02:00
|
|
|
|
public Task<byte[]> GetAsync(string name, CancellationToken cancellationToken = new CancellationToken())
|
|
|
|
|
{
|
|
|
|
|
string? storagePath = storyboard.GetStoragePathFromStoryboardPath(name);
|
|
|
|
|
|
|
|
|
|
return string.IsNullOrEmpty(storagePath)
|
|
|
|
|
? Task.FromResult<byte[]>(null!)
|
|
|
|
|
: realmFileStore.GetAsync(storagePath, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Stream? GetStream(string name)
|
|
|
|
|
{
|
|
|
|
|
string? storagePath = storyboard.GetStoragePathFromStoryboardPath(name);
|
|
|
|
|
|
|
|
|
|
return string.IsNullOrEmpty(storagePath)
|
|
|
|
|
? null
|
|
|
|
|
: realmFileStore.GetStream(storagePath);
|
|
|
|
|
}
|
2023-09-14 16:06:59 +09:00
|
|
|
|
|
|
|
|
|
public IEnumerable<string> GetAvailableResources() =>
|
|
|
|
|
realmFileStore.GetAvailableResources();
|
|
|
|
|
}
|
2017-09-07 23:55:05 +02:00
|
|
|
|
}
|
|
|
|
|
}
|