2019-06-17 20:07:30 +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.
|
|
|
|
|
2020-03-06 17:38:29 +08:00
|
|
|
using osu.Framework.Allocation;
|
2019-06-17 20:07:30 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Colour;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Graphics.Video;
|
2019-11-08 15:19:34 +08:00
|
|
|
using osu.Framework.Timing;
|
2019-06-17 20:07:30 +08:00
|
|
|
using osu.Game.Graphics;
|
2020-06-09 23:28:42 +08:00
|
|
|
using osu.Game.Tournament.IO;
|
2019-06-17 20:07:30 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Components
|
|
|
|
{
|
|
|
|
public partial class TourneyVideo : CompositeDrawable
|
|
|
|
{
|
2020-03-06 17:38:29 +08:00
|
|
|
private readonly string filename;
|
|
|
|
private readonly bool drawFallbackGradient;
|
2023-07-25 19:50:55 +08:00
|
|
|
private Video? video;
|
|
|
|
private ManualClock? manualClock;
|
2019-11-08 15:19:34 +08:00
|
|
|
|
2022-07-11 19:42:04 +08:00
|
|
|
public bool VideoAvailable => video != null;
|
|
|
|
|
2020-03-06 17:38:29 +08:00
|
|
|
public TourneyVideo(string filename, bool drawFallbackGradient = false)
|
2019-06-17 20:07:30 +08:00
|
|
|
{
|
2020-03-06 17:38:29 +08:00
|
|
|
this.filename = filename;
|
|
|
|
this.drawFallbackGradient = drawFallbackGradient;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2020-10-19 14:48:15 +08:00
|
|
|
private void load(TournamentVideoResourceStore storage)
|
2020-03-06 17:38:29 +08:00
|
|
|
{
|
2020-10-19 14:48:15 +08:00
|
|
|
var stream = storage.GetStream(filename);
|
2020-03-06 17:38:29 +08:00
|
|
|
|
|
|
|
if (stream != null)
|
2019-06-17 20:07:30 +08:00
|
|
|
{
|
2020-04-03 14:59:56 +08:00
|
|
|
InternalChild = video = new Video(stream, false)
|
2019-06-17 20:07:30 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-03-06 17:38:29 +08:00
|
|
|
FillMode = FillMode.Fit,
|
2020-03-08 13:47:29 +08:00
|
|
|
Clock = new FramedClock(manualClock = new ManualClock()),
|
|
|
|
Loop = loop,
|
2019-06-17 20:07:30 +08:00
|
|
|
};
|
|
|
|
}
|
2020-03-06 17:38:29 +08:00
|
|
|
else if (drawFallbackGradient)
|
2019-11-11 19:53:22 +08:00
|
|
|
{
|
2020-03-06 17:38:29 +08:00
|
|
|
InternalChild = new Box
|
2019-06-17 20:07:30 +08:00
|
|
|
{
|
2020-03-06 17:38:29 +08:00
|
|
|
Colour = ColourInfo.GradientVertical(OsuColour.Gray(0.3f), OsuColour.Gray(0.6f)),
|
2019-06-17 20:07:30 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
};
|
2019-11-11 19:53:22 +08:00
|
|
|
}
|
2019-06-17 20:07:30 +08:00
|
|
|
}
|
|
|
|
|
2020-03-08 13:47:29 +08:00
|
|
|
private bool loop;
|
|
|
|
|
2019-06-17 20:07:30 +08:00
|
|
|
public bool Loop
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
2020-03-08 13:47:29 +08:00
|
|
|
loop = value;
|
2019-06-17 20:07:30 +08:00
|
|
|
if (video != null)
|
|
|
|
video.Loop = value;
|
|
|
|
}
|
|
|
|
}
|
2019-11-08 15:19:34 +08:00
|
|
|
|
2020-03-09 18:07:44 +08:00
|
|
|
public void Reset()
|
|
|
|
{
|
|
|
|
if (manualClock != null)
|
|
|
|
manualClock.CurrentTime = 0;
|
|
|
|
}
|
2020-03-08 13:23:13 +08:00
|
|
|
|
2019-11-08 15:19:34 +08:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2019-11-08 16:13:45 +08:00
|
|
|
if (manualClock != null && Clock.ElapsedFrameTime < 100)
|
|
|
|
{
|
|
|
|
// we want to avoid seeking as much as possible, because we care about performance, not sync.
|
|
|
|
// to avoid seeking completely, we only increment out local clock when in an updating state.
|
|
|
|
manualClock.CurrentTime += Clock.ElapsedFrameTime;
|
|
|
|
}
|
2019-11-08 15:19:34 +08:00
|
|
|
}
|
2019-06-17 20:07:30 +08:00
|
|
|
}
|
|
|
|
}
|