1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 13:17:26 +08:00
osu-lazer/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs

75 lines
2.3 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.
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Textures;
using osu.Framework.Graphics.Video;
namespace osu.Game.Storyboards.Drawables
{
2022-11-24 13:32:20 +08:00
public partial class DrawableStoryboardVideo : CompositeDrawable
{
public readonly StoryboardVideo Video;
private Video? drawableVideo;
public override bool RemoveWhenNotAlive => false;
public DrawableStoryboardVideo(StoryboardVideo video)
{
Video = video;
// 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.
2024-05-02 04:57:21 +08:00
bool useRelative = !video.Commands.Scale.Any();
RelativeSizeAxes = useRelative ? Axes.Both : Axes.None;
AutoSizeAxes = useRelative ? Axes.None : Axes.Both;
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
}
[BackgroundDependencyLoader(true)]
2024-04-22 18:45:02 +08:00
private void load(TextureStore textureStore)
{
var stream = textureStore.GetStream(Video.Path);
if (stream == null)
return;
InternalChild = drawableVideo = new Video(stream, false)
{
RelativeSizeAxes = RelativeSizeAxes,
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-11 13:50:20 +08:00
protected override void LoadComplete()
{
2020-03-11 14:11:54 +08:00
base.LoadComplete();
if (drawableVideo == null) return;
using (drawableVideo.BeginAbsoluteSequence(Video.StartTime))
{
Schedule(() => drawableVideo.PlaybackPosition = Time.Current - Video.StartTime);
drawableVideo.FadeIn(500);
using (drawableVideo.BeginDelayedSequence(drawableVideo.Duration - 500))
drawableVideo.FadeOut(500);
}
}
}
}