1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-17 03:02:54 +08:00
osu-lazer/osu.Game/Storyboards/Drawables/DrawableStoryboard.cs

176 lines
6.1 KiB
C#
Raw Normal View History

// 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
using System;
using System.Collections.Generic;
using System.IO;
2020-05-19 03:12:14 +08:00
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
2018-04-13 17:19:50 +08:00
using osu.Framework.Allocation;
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;
using osu.Framework.IO.Stores;
using osu.Framework.Platform;
using osu.Game.Database;
using osu.Game.Rulesets.Mods;
2019-03-18 14:25:54 +08:00
using osu.Game.Screens.Play;
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
{
[Cached(typeof(Storyboard))]
public Storyboard Storyboard { get; }
2018-04-13 17:19:50 +08:00
/// <summary>
/// Whether the storyboard is considered finished.
/// </summary>
public IBindable<bool> HasStoryboardEnded => hasStoryboardEnded;
private readonly BindableBool hasStoryboardEnded = new BindableBool(true);
2019-11-12 17:45:42 +08:00
protected override Container<DrawableStoryboardLayer> Content { get; }
2018-04-13 17:19:50 +08:00
protected override Vector2 DrawScale => new Vector2(Parent!.DrawHeight / 480);
2018-04-13 17:19:50 +08:00
public override bool RemoveCompletedTransforms => false;
private double? lastEventEndTime;
[Cached(typeof(IReadOnlyList<Mod>))]
public IReadOnlyList<Mod> Mods { get; }
[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
Implement toggling visibility of pass and fail storyboard layers Closes https://github.com/ppy/osu/issues/6842. This is a rather barebones implementation, just to get this in place somehow at least. The logic is simple - 50% health or above shows pass layer, anything below shows fail layer. This does not match stable logic all across the board because I have no idea how to package that. Stable defines "passing" in like fifty ways: - in mania it's >80% HP (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Rulesets/Mania/RulesetMania.cs#L333-L336) - in taiko it's >80% *accuracy* (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Rulesets/Taiko/RulesetTaiko.cs#L486-L492) - there's also the part where "geki additions" will unconditionally set passing state (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Player.cs#L3561-L3564) - and also the part where at the end of the map, the final passing state is determined by checking whether the user passed more sections than failed (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Player.cs#L3320) The biggest issues of these are probably the first two, and they can *probably* be fixed, but would require a new member on `Ruleset` and I'm not sure how to make one look, so I'm not doing that at this time pending collection of ideas on how to do that.
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
public DrawableStoryboard(Storyboard storyboard, IReadOnlyList<Mod>? mods = null)
2018-04-13 17:19:50 +08:00
{
Storyboard = storyboard;
Mods = mods ?? Array.Empty<Mod>();
2018-04-13 17:19:50 +08:00
Size = new Vector2(640, 480);
bool onlyHasVideoElements = Storyboard.Layers.SelectMany(l => l.Elements).All(e => e is StoryboardVideo);
Width = Height * (storyboard.BeatmapInfo.WidescreenStoryboard || onlyHasVideoElements ? 16 / 9f : 4 / 3f);
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
{
RelativeSizeAxes = Axes.Both,
2018-04-13 17:19:50 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
});
}
Implement toggling visibility of pass and fail storyboard layers Closes https://github.com/ppy/osu/issues/6842. This is a rather barebones implementation, just to get this in place somehow at least. The logic is simple - 50% health or above shows pass layer, anything below shows fail layer. This does not match stable logic all across the board because I have no idea how to package that. Stable defines "passing" in like fifty ways: - in mania it's >80% HP (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Rulesets/Mania/RulesetMania.cs#L333-L336) - in taiko it's >80% *accuracy* (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Rulesets/Taiko/RulesetTaiko.cs#L486-L492) - there's also the part where "geki additions" will unconditionally set passing state (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Player.cs#L3561-L3564) - and also the part where at the end of the map, the final passing state is determined by checking whether the user passed more sections than failed (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Player.cs#L3320) The biggest issues of these are probably the first two, and they can *probably* be fixed, but would require a new member on `Ruleset` and I'm not sure how to make one look, so I'm not doing that at this time pending collection of ideas on how to do that.
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;
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 16:42:45 +08:00
cancellationToken?.ThrowIfCancellationRequested();
2018-04-13 17:19:50 +08:00
Add(layer.CreateDrawable());
}
2020-05-19 03:12:14 +08:00
lastEventEndTime = Storyboard.LatestEventTime;
Implement toggling visibility of pass and fail storyboard layers Closes https://github.com/ppy/osu/issues/6842. This is a rather barebones implementation, just to get this in place somehow at least. The logic is simple - 50% health or above shows pass layer, anything below shows fail layer. This does not match stable logic all across the board because I have no idea how to package that. Stable defines "passing" in like fifty ways: - in mania it's >80% HP (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Rulesets/Mania/RulesetMania.cs#L333-L336) - in taiko it's >80% *accuracy* (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Rulesets/Taiko/RulesetTaiko.cs#L486-L492) - there's also the part where "geki additions" will unconditionally set passing state (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Player.cs#L3561-L3564) - and also the part where at the end of the map, the final passing state is determined by checking whether the user passed more sections than failed (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Player.cs#L3320) The biggest issues of these are probably the first two, and they can *probably* be fixed, but would require a new member on `Ruleset` and I'm not sure how to make one look, so I'm not doing that at this time pending collection of ideas on how to do that.
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
}
protected virtual IResourceStore<byte[]> CreateResourceLookupStore() => new StoryboardResourceLookupStore(Storyboard, realm, host);
protected override void Update()
{
base.Update();
hasStoryboardEnded.Value = lastEventEndTime == null || Time.Current >= lastEventEndTime;
}
public DrawableStoryboardLayer OverlayLayer => Children.Single(layer => layer.Name == "Overlay");
private void updateLayerVisibility()
{
foreach (var layer in Children)
Implement toggling visibility of pass and fail storyboard layers Closes https://github.com/ppy/osu/issues/6842. This is a rather barebones implementation, just to get this in place somehow at least. The logic is simple - 50% health or above shows pass layer, anything below shows fail layer. This does not match stable logic all across the board because I have no idea how to package that. Stable defines "passing" in like fifty ways: - in mania it's >80% HP (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Rulesets/Mania/RulesetMania.cs#L333-L336) - in taiko it's >80% *accuracy* (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Rulesets/Taiko/RulesetTaiko.cs#L486-L492) - there's also the part where "geki additions" will unconditionally set passing state (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Player.cs#L3561-L3564) - and also the part where at the end of the map, the final passing state is determined by checking whether the user passed more sections than failed (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Player.cs#L3320) The biggest issues of these are probably the first two, and they can *probably* be fixed, but would require a new member on `Ruleset` and I'm not sure how to make one look, so I'm not doing that at this time pending collection of ideas on how to do that.
2024-06-14 19:36:40 +08:00
layer.Enabled = passing.Value ? layer.Layer.VisibleWhenPassing : layer.Layer.VisibleWhenFailing;
}
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();
public byte[] Get(string name)
{
string? storagePath = storyboard.GetStoragePathFromStoryboardPath(name);
return string.IsNullOrEmpty(storagePath)
? null!
: realmFileStore.Get(storagePath);
}
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);
}
public IEnumerable<string> GetAvailableResources() =>
realmFileStore.GetAvailableResources();
}
2018-04-13 17:19:50 +08:00
}
}