From 4ae9f81c73f39828e4e812cc362bacbda2656c9f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 22 Apr 2024 18:43:15 +0800 Subject: [PATCH 1/8] Apply transforms to storyboard videos This requires that they are a `StoryboardSprite` for simplicity. Luckily this works just fine. --- .../Beatmaps/Formats/LegacyStoryboardDecoder.cs | 2 +- osu.Game/Storyboards/StoryboardVideo.cs | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs index 6689f087cb..b5d9ad1194 100644 --- a/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs @@ -114,7 +114,7 @@ namespace osu.Game.Beatmaps.Formats if (!OsuGameBase.VIDEO_EXTENSIONS.Contains(Path.GetExtension(path).ToLowerInvariant())) break; - storyboard.GetLayer("Video").Add(new StoryboardVideo(path, offset)); + storyboard.GetLayer("Video").Add(storyboardSprite = new StoryboardVideo(path, offset)); break; } diff --git a/osu.Game/Storyboards/StoryboardVideo.cs b/osu.Game/Storyboards/StoryboardVideo.cs index 8c11e19a06..bd1b933b6f 100644 --- a/osu.Game/Storyboards/StoryboardVideo.cs +++ b/osu.Game/Storyboards/StoryboardVideo.cs @@ -3,23 +3,18 @@ using osu.Framework.Graphics; using osu.Game.Storyboards.Drawables; +using osuTK; namespace osu.Game.Storyboards { - public class StoryboardVideo : IStoryboardElement + public class StoryboardVideo : StoryboardSprite { - public string Path { get; } - - public bool IsDrawable => true; - - public double StartTime { get; } - public StoryboardVideo(string path, double offset) + : base(path, Anchor.Centre, Vector2.Zero) { - Path = path; - StartTime = offset; + TimelineGroup.Alpha.Add(Easing.None, offset, offset, 0, 1); } - public Drawable CreateDrawable() => new DrawableStoryboardVideo(this); + public override Drawable CreateDrawable() => new DrawableStoryboardVideo(this); } } From c43c383abf5d05caa5827b23b1fd53f61cff5b55 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 22 Apr 2024 18:43:34 +0800 Subject: [PATCH 2/8] Allow storboard videos to take on no-relative size when specified by a mapper --- .../Drawables/DrawableStoryboardVideo.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs b/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs index 9a5db4bb39..98cb01d5f3 100644 --- a/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs +++ b/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs @@ -23,7 +23,17 @@ namespace osu.Game.Storyboards.Drawables { Video = video; - RelativeSizeAxes = Axes.Both; + // In osu-stable, a mapper can add a scale command for a storyboard. + // This allows scaling based on the video's absolute size. + // + // If not specified we take up the full available space. + bool useRelative = !video.TimelineGroup.Scale.HasCommands; + + RelativeSizeAxes = useRelative ? Axes.Both : Axes.None; + AutoSizeAxes = useRelative ? Axes.None : Axes.Both; + + Anchor = Anchor.Centre; + Origin = Anchor.Centre; } [BackgroundDependencyLoader(true)] @@ -36,7 +46,7 @@ namespace osu.Game.Storyboards.Drawables InternalChild = drawableVideo = new Video(stream, false) { - RelativeSizeAxes = Axes.Both, + RelativeSizeAxes = RelativeSizeAxes, FillMode = FillMode.Fill, Anchor = Anchor.Centre, Origin = Anchor.Centre, From 9e7182acf0cfa3fc658758b78af4dc7378cef536 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 22 Apr 2024 18:45:02 +0800 Subject: [PATCH 3/8] Remove unused DI beatmap paramater --- osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs b/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs index 98cb01d5f3..ca2c7b774c 100644 --- a/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs +++ b/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs @@ -2,12 +2,10 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.Allocation; -using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Video; -using osu.Game.Beatmaps; namespace osu.Game.Storyboards.Drawables { @@ -37,7 +35,7 @@ namespace osu.Game.Storyboards.Drawables } [BackgroundDependencyLoader(true)] - private void load(IBindable beatmap, TextureStore textureStore) + private void load(TextureStore textureStore) { var stream = textureStore.GetStream(Video.Path); From 50afd48812aaf7e4deb437855202836280c93339 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 22 Apr 2024 23:04:56 +0800 Subject: [PATCH 4/8] Add manual test coverage of storyboard videos --- .../TestSceneDrawableStoryboardSprite.cs | 98 ++++++++++++++----- 1 file changed, 75 insertions(+), 23 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs index 32693c2bb2..6ac112cc5f 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs @@ -10,6 +10,7 @@ using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Framework.IO.Stores; using osu.Framework.Testing; @@ -40,7 +41,7 @@ namespace osu.Game.Tests.Visual.Gameplay AddStep("disallow all lookups", () => { storyboard.UseSkinSprites = false; - storyboard.AlwaysProvideTexture = false; + storyboard.ProvideResources = false; }); AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero))); @@ -55,7 +56,7 @@ namespace osu.Game.Tests.Visual.Gameplay AddStep("allow storyboard lookup", () => { storyboard.UseSkinSprites = false; - storyboard.AlwaysProvideTexture = true; + storyboard.ProvideResources = true; }); AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero))); @@ -67,13 +68,47 @@ namespace osu.Game.Tests.Visual.Gameplay assertStoryboardSourced(); } + [TestCase(false)] + [TestCase(true)] + public void TestVideo(bool scaleTransformProvided) + { + AddStep("allow storyboard lookup", () => + { + storyboard.ProvideResources = true; + }); + + AddStep("create video", () => SetContents(_ => + { + var layer = storyboard.GetLayer("Video"); + + var sprite = new StoryboardVideo("Videos/test-video.mp4", Time.Current); + + sprite.AddLoop(Time.Current, 100).Alpha.Add(Easing.None, 0, 10000, 1, 1); + + if (scaleTransformProvided) + sprite.TimelineGroup.Scale.Add(Easing.None, Time.Current, Time.Current, 1, 1); + + layer.Elements.Clear(); + layer.Add(sprite); + + return new Container + { + RelativeSizeAxes = Axes.Both, + Children = new Drawable[] + { + storyboard.CreateDrawable() + } + }; + })); + } + [Test] public void TestSkinLookupPreferredOverStoryboard() { AddStep("allow all lookups", () => { storyboard.UseSkinSprites = true; - storyboard.AlwaysProvideTexture = true; + storyboard.ProvideResources = true; }); AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero))); @@ -91,7 +126,7 @@ namespace osu.Game.Tests.Visual.Gameplay AddStep("allow skin lookup", () => { storyboard.UseSkinSprites = true; - storyboard.AlwaysProvideTexture = false; + storyboard.ProvideResources = false; }); AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero))); @@ -109,7 +144,7 @@ namespace osu.Game.Tests.Visual.Gameplay AddStep("allow all lookups", () => { storyboard.UseSkinSprites = true; - storyboard.AlwaysProvideTexture = true; + storyboard.ProvideResources = true; }); AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero))); @@ -127,7 +162,7 @@ namespace osu.Game.Tests.Visual.Gameplay AddStep("allow all lookups", () => { storyboard.UseSkinSprites = true; - storyboard.AlwaysProvideTexture = true; + storyboard.ProvideResources = true; }); AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero))); @@ -142,7 +177,7 @@ namespace osu.Game.Tests.Visual.Gameplay AddStep("allow all lookups", () => { storyboard.UseSkinSprites = true; - storyboard.AlwaysProvideTexture = true; + storyboard.ProvideResources = true; }); AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero))); @@ -156,7 +191,7 @@ namespace osu.Game.Tests.Visual.Gameplay AddStep("allow all lookups", () => { storyboard.UseSkinSprites = true; - storyboard.AlwaysProvideTexture = true; + storyboard.ProvideResources = true; }); AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero))); @@ -170,7 +205,7 @@ namespace osu.Game.Tests.Visual.Gameplay AddAssert("origin back", () => sprites.All(s => s.Origin == Anchor.TopLeft)); } - private DrawableStoryboard createSprite(string lookupName, Anchor origin, Vector2 initialPosition) + private Drawable createSprite(string lookupName, Anchor origin, Vector2 initialPosition) { var layer = storyboard.GetLayer("Background"); @@ -180,7 +215,14 @@ namespace osu.Game.Tests.Visual.Gameplay layer.Elements.Clear(); layer.Add(sprite); - return storyboard.CreateDrawable().With(s => s.RelativeSizeAxes = Axes.Both); + return new Container + { + RelativeSizeAxes = Axes.Both, + Children = new Drawable[] + { + storyboard.CreateDrawable() + } + }; } private void assertStoryboardSourced() @@ -202,42 +244,52 @@ namespace osu.Game.Tests.Visual.Gameplay return new TestDrawableStoryboard(this, mods); } - public bool AlwaysProvideTexture { get; set; } + public bool ProvideResources { get; set; } - public override string GetStoragePathFromStoryboardPath(string path) => AlwaysProvideTexture ? path : string.Empty; + public override string GetStoragePathFromStoryboardPath(string path) => ProvideResources ? path : string.Empty; private partial class TestDrawableStoryboard : DrawableStoryboard { - private readonly bool alwaysProvideTexture; + private readonly bool provideResources; public TestDrawableStoryboard(TestStoryboard storyboard, IReadOnlyList? mods) : base(storyboard, mods) { - alwaysProvideTexture = storyboard.AlwaysProvideTexture; + provideResources = storyboard.ProvideResources; } - protected override IResourceStore CreateResourceLookupStore() => alwaysProvideTexture - ? new AlwaysReturnsTextureStore() + protected override IResourceStore CreateResourceLookupStore() => provideResources + ? new ResourcesTextureStore() : new ResourceStore(); - internal class AlwaysReturnsTextureStore : IResourceStore + internal class ResourcesTextureStore : IResourceStore { - private const string test_image = "Resources/Textures/test-image.png"; - private readonly DllResourceStore store; - public AlwaysReturnsTextureStore() + public ResourcesTextureStore() { store = TestResources.GetStore(); } public void Dispose() => store.Dispose(); - public byte[] Get(string name) => store.Get(test_image); + public byte[] Get(string name) => store.Get(map(name)); - public Task GetAsync(string name, CancellationToken cancellationToken = new CancellationToken()) => store.GetAsync(test_image, cancellationToken); + public Task GetAsync(string name, CancellationToken cancellationToken = new CancellationToken()) => store.GetAsync(map(name), cancellationToken); - public Stream GetStream(string name) => store.GetStream(test_image); + public Stream GetStream(string name) => store.GetStream(map(name)); + + private string map(string name) + { + switch (name) + { + case lookup_name: + return "Resources/Textures/test-image.png"; + + default: + return $"Resources/{name}"; + } + } public IEnumerable GetAvailableResources() => store.GetAvailableResources(); } From 7eeac0f3b90d34d71a8e2d7390b4a0310b89288b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 23 Apr 2024 17:34:52 +0800 Subject: [PATCH 5/8] Fix incorrect xmldoc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bartłomiej Dach --- osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs b/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs index ca2c7b774c..848699a4d2 100644 --- a/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs +++ b/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs @@ -21,7 +21,7 @@ namespace osu.Game.Storyboards.Drawables { Video = video; - // In osu-stable, a mapper can add a scale command for a storyboard. + // In osu-stable, a mapper can add a scale command for a storyboard video. // This allows scaling based on the video's absolute size. // // If not specified we take up the full available space. From 17ca29c2c6e0e5f141f5393923a511cfa2d61437 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 23 Apr 2024 17:37:37 +0800 Subject: [PATCH 6/8] Actually apply transforms to the video --- osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs b/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs index 848699a4d2..f2454be190 100644 --- a/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs +++ b/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs @@ -50,6 +50,8 @@ namespace osu.Game.Storyboards.Drawables Origin = Anchor.Centre, Alpha = 0, }; + + Video.ApplyTransforms(drawableVideo); } protected override void LoadComplete() From 564dec7a142b8fe3bf6729b9223bc490df18b5c7 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 23 Apr 2024 19:21:55 +0800 Subject: [PATCH 7/8] Add test coverage of transforms actually being applied to video --- .../Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs index 6ac112cc5f..fc52d749b3 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs @@ -86,7 +86,10 @@ namespace osu.Game.Tests.Visual.Gameplay sprite.AddLoop(Time.Current, 100).Alpha.Add(Easing.None, 0, 10000, 1, 1); if (scaleTransformProvided) - sprite.TimelineGroup.Scale.Add(Easing.None, Time.Current, Time.Current, 1, 1); + { + sprite.TimelineGroup.Scale.Add(Easing.None, Time.Current, Time.Current + 1000, 1, 2); + sprite.TimelineGroup.Scale.Add(Easing.None, Time.Current + 1000, Time.Current + 2000, 2, 1); + } layer.Elements.Clear(); layer.Add(sprite); From 602b16f533dd5e578025144d025dc3a9c7336fa7 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 23 Apr 2024 22:03:32 +0800 Subject: [PATCH 8/8] Fix fade-in no longer working on videos --- .../Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs | 2 -- osu.Game/Storyboards/StoryboardVideo.cs | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs index fc52d749b3..8fa2c9922e 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs @@ -83,8 +83,6 @@ namespace osu.Game.Tests.Visual.Gameplay var sprite = new StoryboardVideo("Videos/test-video.mp4", Time.Current); - sprite.AddLoop(Time.Current, 100).Alpha.Add(Easing.None, 0, 10000, 1, 1); - if (scaleTransformProvided) { sprite.TimelineGroup.Scale.Add(Easing.None, Time.Current, Time.Current + 1000, 1, 2); diff --git a/osu.Game/Storyboards/StoryboardVideo.cs b/osu.Game/Storyboards/StoryboardVideo.cs index bd1b933b6f..5573162d26 100644 --- a/osu.Game/Storyboards/StoryboardVideo.cs +++ b/osu.Game/Storyboards/StoryboardVideo.cs @@ -12,7 +12,9 @@ namespace osu.Game.Storyboards public StoryboardVideo(string path, double offset) : base(path, Anchor.Centre, Vector2.Zero) { - TimelineGroup.Alpha.Add(Easing.None, offset, offset, 0, 1); + // This is just required to get a valid StartTime based on the incoming offset. + // Actual fades are handled inside DrawableStoryboardVideo for now. + TimelineGroup.Alpha.Add(Easing.None, offset, offset, 0, 0); } public override Drawable CreateDrawable() => new DrawableStoryboardVideo(this);