2021-06-02 07:50:58 +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.
|
|
|
|
|
2021-12-27 10:28:20 +00:00
|
|
|
#nullable enable
|
|
|
|
|
2021-06-03 03:33:16 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
2021-06-04 05:56:10 +00:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-06-02 07:50:58 +00:00
|
|
|
using osu.Framework.Timing;
|
|
|
|
using osu.Game.Beatmaps;
|
2021-12-27 10:28:20 +00:00
|
|
|
using osu.Game.Overlays;
|
2021-06-02 07:50:58 +00:00
|
|
|
using osu.Game.Storyboards.Drawables;
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Backgrounds
|
|
|
|
{
|
|
|
|
public class BeatmapBackgroundWithStoryboard : BeatmapBackground
|
|
|
|
{
|
2021-12-27 10:28:20 +00:00
|
|
|
private InterpolatingFramedClock storyboardClock = null!;
|
|
|
|
|
|
|
|
[Resolved(CanBeNull = true)]
|
|
|
|
private MusicController? musicController { get; set; }
|
|
|
|
|
2021-06-02 07:50:58 +00:00
|
|
|
public BeatmapBackgroundWithStoryboard(WorkingBeatmap beatmap, string fallbackTextureName = "Backgrounds/bg1")
|
|
|
|
: base(beatmap, fallbackTextureName)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-06-03 03:33:16 +00:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
2021-06-02 07:50:58 +00:00
|
|
|
{
|
2021-06-04 05:56:10 +00:00
|
|
|
if (!Beatmap.Storyboard.HasDrawable)
|
2021-06-03 05:56:14 +00:00
|
|
|
return;
|
|
|
|
|
2021-06-04 05:56:10 +00:00
|
|
|
if (Beatmap.Storyboard.ReplacesBackground)
|
|
|
|
Sprite.Alpha = 0;
|
|
|
|
|
2021-06-04 06:18:16 +00:00
|
|
|
LoadComponentAsync(new AudioContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Volume = { Value = 0 },
|
2021-12-27 10:28:20 +00:00
|
|
|
Child = new DrawableStoryboard(Beatmap.Storyboard) { Clock = storyboardClock = new InterpolatingFramedClock(Beatmap.Track) }
|
2021-06-04 06:18:16 +00:00
|
|
|
}, AddInternal);
|
2021-06-02 07:50:58 +00:00
|
|
|
}
|
2021-12-27 10:28:20 +00:00
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
if (musicController != null)
|
|
|
|
musicController.TrackChanged += onTrackChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onTrackChanged(WorkingBeatmap newBeatmap, TrackChangeDirection _)
|
|
|
|
{
|
|
|
|
if (newBeatmap != Beatmap)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// `MusicController` will sometimes reload the track, even when the working beatmap technically hasn't changed.
|
|
|
|
// ensure that the storyboard's clock is always using the latest track instance.
|
|
|
|
storyboardClock.ChangeSource(newBeatmap.Track);
|
|
|
|
storyboardClock.ProcessFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
if (musicController != null)
|
|
|
|
musicController.TrackChanged -= onTrackChanged;
|
|
|
|
}
|
2021-06-02 07:50:58 +00:00
|
|
|
}
|
|
|
|
}
|