2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-03-04 11:05:02 +08:00
|
|
|
|
using System;
|
2022-03-03 01:33:46 +08:00
|
|
|
|
using System.Collections.Generic;
|
2023-09-14 15:06:59 +08:00
|
|
|
|
using System.IO;
|
2020-05-19 03:12:14 +08:00
|
|
|
|
using System.Linq;
|
2019-05-10 15:31:09 +08:00
|
|
|
|
using System.Threading;
|
2023-09-14 15:06:59 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2021-04-16 12:59:10 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2023-09-14 15:06:59 +08:00
|
|
|
|
using osu.Framework.IO.Stores;
|
2020-12-21 12:35:46 +08:00
|
|
|
|
using osu.Framework.Platform;
|
2021-12-21 15:09:19 +08:00
|
|
|
|
using osu.Game.Database;
|
2022-03-03 01:33:46 +08:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2019-03-18 14:25:54 +08:00
|
|
|
|
using osu.Game.Screens.Play;
|
2023-09-14 15:06:59 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Storyboards.Drawables
|
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class DrawableStoryboard : Container<DrawableStoryboardLayer>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2023-09-11 22:59:44 +08:00
|
|
|
|
[Cached(typeof(Storyboard))]
|
2020-01-20 12:50:27 +08:00
|
|
|
|
public Storyboard Storyboard { get; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-05-04 15:48:13 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the storyboard is considered finished.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public IBindable<bool> HasStoryboardEnded => hasStoryboardEnded;
|
|
|
|
|
|
2021-06-18 15:08:49 +08:00
|
|
|
|
private readonly BindableBool hasStoryboardEnded = new BindableBool(true);
|
2021-05-04 15:48:13 +08:00
|
|
|
|
|
2019-11-12 17:45:42 +08:00
|
|
|
|
protected override Container<DrawableStoryboardLayer> Content { get; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-10-17 16:40:44 +08:00
|
|
|
|
protected override Vector2 DrawScale => new Vector2(Parent!.DrawHeight / 480);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
public override bool RemoveCompletedTransforms => false;
|
|
|
|
|
|
2021-05-04 15:48:13 +08:00
|
|
|
|
private double? lastEventEndTime;
|
|
|
|
|
|
2022-03-03 01:33:46 +08:00
|
|
|
|
[Cached(typeof(IReadOnlyList<Mod>))]
|
|
|
|
|
public IReadOnlyList<Mod> Mods { get; }
|
|
|
|
|
|
2023-09-14 15:06:59 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private GameHost host { get; set; } = null!;
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private RealmAccess realm { get; set; } = null!;
|
|
|
|
|
|
|
|
|
|
private DependencyContainer dependencies = null!;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2024-06-14 19:36:40 +08:00
|
|
|
|
private BindableNumber<double> health = null!;
|
|
|
|
|
private readonly BindableBool passing = new BindableBool(true);
|
|
|
|
|
|
2018-07-11 16:07:14 +08:00
|
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) =>
|
|
|
|
|
dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-09-14 15:06:59 +08:00
|
|
|
|
public DrawableStoryboard(Storyboard storyboard, IReadOnlyList<Mod>? mods = null)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Storyboard = storyboard;
|
2022-03-04 11:05:02 +08:00
|
|
|
|
Mods = mods ?? Array.Empty<Mod>();
|
2021-05-25 15:07:17 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Size = new Vector2(640, 480);
|
2021-05-25 15:06:39 +08:00
|
|
|
|
|
2023-05-17 12:51:32 +08:00
|
|
|
|
bool onlyHasVideoElements = Storyboard.Layers.SelectMany(l => l.Elements).All(e => e is StoryboardVideo);
|
2021-05-25 15:07:17 +08:00
|
|
|
|
|
|
|
|
|
Width = Height * (storyboard.BeatmapInfo.WidescreenStoryboard || onlyHasVideoElements ? 16 / 9f : 4 / 3f);
|
2021-05-25 15:06:39 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
|
2019-11-12 17:45:42 +08:00
|
|
|
|
AddInternal(Content = new Container<DrawableStoryboardLayer>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-03-31 03:37:20 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-14 19:36:40 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(IGameplayClock? clock, CancellationToken? cancellationToken, GameplayState? gameplayState)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-03-18 17:19:59 +08:00
|
|
|
|
if (clock != null)
|
2019-03-18 14:25:54 +08:00
|
|
|
|
Clock = clock;
|
|
|
|
|
|
2023-09-14 15:06:59 +08:00
|
|
|
|
dependencies.CacheAs(typeof(TextureStore),
|
|
|
|
|
new TextureStore(host.Renderer, host.CreateTextureLoaderStore(
|
|
|
|
|
CreateResourceLookupStore()
|
|
|
|
|
), false, scaleAdjust: 1));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
foreach (var layer in Storyboard.Layers)
|
2019-05-10 15:31:09 +08:00
|
|
|
|
{
|
2019-05-10 16:42:45 +08:00
|
|
|
|
cancellationToken?.ThrowIfCancellationRequested();
|
2019-05-10 15:31:09 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Add(layer.CreateDrawable());
|
2019-05-10 15:31:09 +08:00
|
|
|
|
}
|
2020-05-19 03:12:14 +08:00
|
|
|
|
|
2021-05-04 15:48:13 +08:00
|
|
|
|
lastEventEndTime = Storyboard.LatestEventTime;
|
2024-06-14 19:36:40 +08: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);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2021-04-16 12:59:10 +08:00
|
|
|
|
|
2023-09-14 15:06:59 +08:00
|
|
|
|
protected virtual IResourceStore<byte[]> CreateResourceLookupStore() => new StoryboardResourceLookupStore(Storyboard, realm, host);
|
|
|
|
|
|
2021-04-16 12:59:10 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
2021-05-04 15:48:13 +08:00
|
|
|
|
hasStoryboardEnded.Value = lastEventEndTime == null || Time.Current >= lastEventEndTime;
|
2021-04-16 12:59:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-04 15:48:13 +08:00
|
|
|
|
public DrawableStoryboardLayer OverlayLayer => Children.Single(layer => layer.Name == "Overlay");
|
2021-04-16 12:59:10 +08:00
|
|
|
|
|
2021-05-04 15:48:13 +08:00
|
|
|
|
private void updateLayerVisibility()
|
2021-04-16 12:59:10 +08:00
|
|
|
|
{
|
2021-05-04 15:48:13 +08:00
|
|
|
|
foreach (var layer in Children)
|
2024-06-14 19:36:40 +08:00
|
|
|
|
layer.Enabled = passing.Value ? layer.Layer.VisibleWhenPassing : layer.Layer.VisibleWhenFailing;
|
2021-04-16 12:59:10 +08:00
|
|
|
|
}
|
2023-09-14 15:06:59 +08: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-20 02:11:16 +08:00
|
|
|
|
public byte[] Get(string name)
|
|
|
|
|
{
|
|
|
|
|
string? storagePath = storyboard.GetStoragePathFromStoryboardPath(name);
|
2023-09-14 15:06:59 +08:00
|
|
|
|
|
2023-09-20 02:11:16 +08:00
|
|
|
|
return string.IsNullOrEmpty(storagePath)
|
|
|
|
|
? null!
|
|
|
|
|
: realmFileStore.Get(storagePath);
|
|
|
|
|
}
|
2023-09-14 15:06:59 +08:00
|
|
|
|
|
2023-09-20 02:11:16 +08: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 15:06:59 +08:00
|
|
|
|
|
|
|
|
|
public IEnumerable<string> GetAvailableResources() =>
|
|
|
|
|
realmFileStore.GetAvailableResources();
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|