1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 19:27:52 +08:00
osu-lazer/osu.Game/Screens/Play/DimmableVideo.cs

89 lines
2.3 KiB
C#
Raw Normal View History

2019-08-31 04:48:38 +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.
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2019-09-14 11:32:00 +08:00
using osu.Framework.Graphics.Shapes;
2019-08-31 04:48:38 +08:00
using osu.Framework.Graphics.Video;
using osu.Game.Graphics.Containers;
2019-09-14 11:32:00 +08:00
using osuTK.Graphics;
2019-08-31 04:48:38 +08:00
namespace osu.Game.Screens.Play
{
public class DimmableVideo : UserDimContainer
{
private readonly VideoSprite video;
private DrawableVideo drawableVideo;
public DimmableVideo(VideoSprite video)
{
this.video = video;
}
[BackgroundDependencyLoader]
private void load()
{
initializeVideo(false);
}
protected override void LoadComplete()
{
2019-08-31 05:42:20 +08:00
ShowVideo.BindValueChanged(_ => initializeVideo(true), true);
2019-08-31 04:48:38 +08:00
base.LoadComplete();
}
2019-08-31 05:42:20 +08:00
protected override bool ShowDimContent => ShowVideo.Value && DimLevel < 1;
2019-08-31 04:48:38 +08:00
private void initializeVideo(bool async)
{
2019-08-31 21:10:07 +08:00
if (video == null)
return;
2019-08-31 04:48:38 +08:00
if (drawableVideo != null)
return;
2019-08-31 05:42:20 +08:00
if (!ShowVideo.Value)
2019-08-31 04:48:38 +08:00
return;
drawableVideo = new DrawableVideo(video);
if (async)
LoadComponentAsync(drawableVideo, Add);
else
Add(drawableVideo);
}
private class DrawableVideo : Container
{
public DrawableVideo(VideoSprite video)
{
RelativeSizeAxes = Axes.Both;
Masking = true;
video.RelativeSizeAxes = Axes.Both;
2019-09-14 11:28:59 +08:00
video.FillMode = FillMode.Fit;
video.Anchor = Anchor.Centre;
video.Origin = Anchor.Centre;
2019-09-14 11:32:00 +08:00
AddRangeInternal(new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
},
video,
});
2019-08-31 04:48:38 +08:00
}
2019-08-31 05:09:23 +08:00
[BackgroundDependencyLoader]
private void load(GameplayClock clock)
{
if (clock != null)
Clock = clock;
}
2019-08-31 04:48:38 +08:00
}
}
}