2020-03-08 13:32: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.
|
|
|
|
|
|
2024-05-02 05:00:56 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2020-03-08 13:32:03 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
|
using osu.Framework.Graphics.Video;
|
2024-05-02 05:00:56 +08:00
|
|
|
|
using osu.Framework.Utils;
|
|
|
|
|
using osuTK;
|
2020-03-08 13:32:03 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Storyboards.Drawables
|
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class DrawableStoryboardVideo : CompositeDrawable
|
2020-03-08 13:32:03 +08:00
|
|
|
|
{
|
|
|
|
|
public readonly StoryboardVideo Video;
|
2022-08-10 14:48:38 +08:00
|
|
|
|
|
2024-05-02 05:00:56 +08:00
|
|
|
|
private DrawableVideo? drawableVideo;
|
2020-03-08 13:32:03 +08:00
|
|
|
|
|
|
|
|
|
public override bool RemoveWhenNotAlive => false;
|
|
|
|
|
|
|
|
|
|
public DrawableStoryboardVideo(StoryboardVideo video)
|
|
|
|
|
{
|
|
|
|
|
Video = video;
|
|
|
|
|
|
2024-04-23 17:34:52 +08:00
|
|
|
|
// In osu-stable, a mapper can add a scale command for a storyboard video.
|
2024-04-22 18:43:34 +08:00
|
|
|
|
// This allows scaling based on the video's absolute size.
|
|
|
|
|
//
|
|
|
|
|
// If not specified we take up the full available space.
|
2024-05-02 04:57:21 +08:00
|
|
|
|
bool useRelative = !video.Commands.Scale.Any();
|
2024-04-22 18:43:34 +08:00
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = useRelative ? Axes.Both : Axes.None;
|
|
|
|
|
AutoSizeAxes = useRelative ? Axes.None : Axes.Both;
|
|
|
|
|
|
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
|
Origin = Anchor.Centre;
|
2020-03-08 13:32:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-08 14:08:38 +08:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2024-04-22 18:45:02 +08:00
|
|
|
|
private void load(TextureStore textureStore)
|
2020-03-08 13:32:03 +08:00
|
|
|
|
{
|
2023-09-20 02:18:33 +08:00
|
|
|
|
var stream = textureStore.GetStream(Video.Path);
|
2020-03-08 13:32:03 +08:00
|
|
|
|
|
|
|
|
|
if (stream == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-05-02 05:00:56 +08:00
|
|
|
|
InternalChild = drawableVideo = new DrawableVideo(stream, false)
|
2020-03-08 13:32:03 +08:00
|
|
|
|
{
|
2024-04-22 18:43:34 +08:00
|
|
|
|
RelativeSizeAxes = RelativeSizeAxes,
|
2020-03-08 13:32:03 +08:00
|
|
|
|
FillMode = FillMode.Fill,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2020-03-11 14:11:54 +08:00
|
|
|
|
Alpha = 0,
|
2020-03-11 16:55:20 +08:00
|
|
|
|
};
|
2024-04-23 17:37:37 +08:00
|
|
|
|
|
|
|
|
|
Video.ApplyTransforms(drawableVideo);
|
2020-03-08 13:32:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-11 13:50:20 +08:00
|
|
|
|
protected override void LoadComplete()
|
2020-03-08 13:32:03 +08:00
|
|
|
|
{
|
2020-03-11 14:11:54 +08:00
|
|
|
|
base.LoadComplete();
|
2020-03-08 13:32:03 +08:00
|
|
|
|
|
2022-08-10 14:48:38 +08:00
|
|
|
|
if (drawableVideo == null) return;
|
2020-03-27 00:09:22 +08:00
|
|
|
|
|
2022-08-10 14:48:38 +08:00
|
|
|
|
using (drawableVideo.BeginAbsoluteSequence(Video.StartTime))
|
2020-07-16 13:25:45 +08:00
|
|
|
|
{
|
2022-08-10 14:48:38 +08:00
|
|
|
|
Schedule(() => drawableVideo.PlaybackPosition = Time.Current - Video.StartTime);
|
2023-03-07 14:54:33 +08:00
|
|
|
|
|
2022-08-10 14:48:38 +08:00
|
|
|
|
drawableVideo.FadeIn(500);
|
2023-03-07 14:54:33 +08:00
|
|
|
|
|
|
|
|
|
using (drawableVideo.BeginDelayedSequence(drawableVideo.Duration - 500))
|
|
|
|
|
drawableVideo.FadeOut(500);
|
2020-07-16 13:25:45 +08:00
|
|
|
|
}
|
2020-03-08 13:32:03 +08:00
|
|
|
|
}
|
2024-05-02 05:00:56 +08:00
|
|
|
|
|
|
|
|
|
private partial class DrawableVideo : Video, IFlippable, IVectorScalable
|
|
|
|
|
{
|
|
|
|
|
private bool flipH;
|
|
|
|
|
|
|
|
|
|
public bool FlipH
|
|
|
|
|
{
|
|
|
|
|
get => flipH;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (flipH == value)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
flipH = value;
|
|
|
|
|
Invalidate(Invalidation.MiscGeometry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool flipV;
|
|
|
|
|
|
|
|
|
|
public bool FlipV
|
|
|
|
|
{
|
|
|
|
|
get => flipV;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (flipV == value)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
flipV = value;
|
|
|
|
|
Invalidate(Invalidation.MiscGeometry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Vector2 vectorScale = Vector2.One;
|
|
|
|
|
|
|
|
|
|
public Vector2 VectorScale
|
|
|
|
|
{
|
|
|
|
|
get => vectorScale;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (vectorScale == value)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!Validation.IsFinite(value)) throw new ArgumentException($@"{nameof(VectorScale)} must be finite, but is {value}.");
|
|
|
|
|
|
|
|
|
|
vectorScale = value;
|
|
|
|
|
Invalidate(Invalidation.MiscGeometry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Vector2 DrawScale
|
|
|
|
|
=> new Vector2(FlipH ? -base.DrawScale.X : base.DrawScale.X, FlipV ? -base.DrawScale.Y : base.DrawScale.Y) * VectorScale;
|
|
|
|
|
|
|
|
|
|
public override Anchor Origin => StoryboardExtensions.AdjustOrigin(base.Origin, VectorScale, FlipH, FlipV);
|
|
|
|
|
|
|
|
|
|
public DrawableVideo(Stream stream, bool startAtCurrentTime = true)
|
|
|
|
|
: base(stream, startAtCurrentTime)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-08 13:32:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|