2019-06-17 12:07:30 +00: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.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2020-03-06 09:38:29 +00:00
|
|
|
using osu.Framework.Allocation;
|
2019-06-17 12:07:30 +00: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 07:19:34 +00:00
|
|
|
using osu.Framework.Timing;
|
2019-06-17 12:07:30 +00:00
|
|
|
using osu.Game.Graphics;
|
2020-06-09 15:28:42 +00:00
|
|
|
using osu.Game.Tournament.IO;
|
2019-06-17 12:07:30 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Components
|
|
|
|
{
|
|
|
|
public class TourneyVideo : CompositeDrawable
|
|
|
|
{
|
2020-03-06 09:38:29 +00:00
|
|
|
private readonly string filename;
|
|
|
|
private readonly bool drawFallbackGradient;
|
2020-04-03 06:59:56 +00:00
|
|
|
private Video video;
|
2020-03-06 09:38:29 +00:00
|
|
|
private ManualClock manualClock;
|
2019-11-08 07:19:34 +00:00
|
|
|
|
2022-07-11 11:42:04 +00:00
|
|
|
public bool VideoAvailable => video != null;
|
|
|
|
|
2020-03-06 09:38:29 +00:00
|
|
|
public TourneyVideo(string filename, bool drawFallbackGradient = false)
|
2019-06-17 12:07:30 +00:00
|
|
|
{
|
2020-03-06 09:38:29 +00:00
|
|
|
this.filename = filename;
|
|
|
|
this.drawFallbackGradient = drawFallbackGradient;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2020-10-19 06:48:15 +00:00
|
|
|
private void load(TournamentVideoResourceStore storage)
|
2020-03-06 09:38:29 +00:00
|
|
|
{
|
2020-10-19 06:48:15 +00:00
|
|
|
var stream = storage.GetStream(filename);
|
2020-03-06 09:38:29 +00:00
|
|
|
|
|
|
|
if (stream != null)
|
2019-06-17 12:07:30 +00:00
|
|
|
{
|
2020-04-03 06:59:56 +00:00
|
|
|
InternalChild = video = new Video(stream, false)
|
2019-06-17 12:07:30 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-03-06 09:38:29 +00:00
|
|
|
FillMode = FillMode.Fit,
|
2020-03-08 05:47:29 +00:00
|
|
|
Clock = new FramedClock(manualClock = new ManualClock()),
|
|
|
|
Loop = loop,
|
2019-06-17 12:07:30 +00:00
|
|
|
};
|
|
|
|
}
|
2020-03-06 09:38:29 +00:00
|
|
|
else if (drawFallbackGradient)
|
2019-11-11 11:53:22 +00:00
|
|
|
{
|
2020-03-06 09:38:29 +00:00
|
|
|
InternalChild = new Box
|
2019-06-17 12:07:30 +00:00
|
|
|
{
|
2020-03-06 09:38:29 +00:00
|
|
|
Colour = ColourInfo.GradientVertical(OsuColour.Gray(0.3f), OsuColour.Gray(0.6f)),
|
2019-06-17 12:07:30 +00:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
};
|
2019-11-11 11:53:22 +00:00
|
|
|
}
|
2019-06-17 12:07:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-08 05:47:29 +00:00
|
|
|
private bool loop;
|
|
|
|
|
2019-06-17 12:07:30 +00:00
|
|
|
public bool Loop
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
2020-03-08 05:47:29 +00:00
|
|
|
loop = value;
|
2019-06-17 12:07:30 +00:00
|
|
|
if (video != null)
|
|
|
|
video.Loop = value;
|
|
|
|
}
|
|
|
|
}
|
2019-11-08 07:19:34 +00:00
|
|
|
|
2020-03-09 10:07:44 +00:00
|
|
|
public void Reset()
|
|
|
|
{
|
|
|
|
if (manualClock != null)
|
|
|
|
manualClock.CurrentTime = 0;
|
|
|
|
}
|
2020-03-08 05:23:13 +00:00
|
|
|
|
2019-11-08 07:19:34 +00:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2019-11-08 08:13:45 +00: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 07:19:34 +00:00
|
|
|
}
|
2019-06-17 12:07:30 +00:00
|
|
|
}
|
|
|
|
}
|