2019-01-24 16:43:03 +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.
|
2018-06-28 12:43:56 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2020-06-16 21:54:50 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2018-06-28 12:43:56 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2020-06-16 21:54:50 +08:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2020-09-29 13:09:51 +08:00
|
|
|
|
using osu.Game.Skinning;
|
2018-06-28 12:43:56 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Storyboards.Drawables
|
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class DrawableStoryboardSample : PausableSkinnableSound
|
2018-06-28 12:43:56 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The amount of time allowable beyond the start time of the sample, for the sample to start.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const double allowable_late_start = 100;
|
|
|
|
|
|
2019-08-23 19:54:39 +08:00
|
|
|
|
private readonly StoryboardSampleInfo sampleInfo;
|
2020-06-19 04:46:32 +08:00
|
|
|
|
|
2018-06-28 12:43:56 +08:00
|
|
|
|
public override bool RemoveWhenNotAlive => false;
|
|
|
|
|
|
2019-08-23 19:54:39 +08:00
|
|
|
|
public DrawableStoryboardSample(StoryboardSampleInfo sampleInfo)
|
2020-09-29 13:09:51 +08:00
|
|
|
|
: base(sampleInfo)
|
2018-06-28 12:43:56 +08:00
|
|
|
|
{
|
2019-08-23 19:54:39 +08:00
|
|
|
|
this.sampleInfo = sampleInfo;
|
|
|
|
|
LifetimeStart = sampleInfo.StartTime;
|
2021-01-22 06:46:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-03 01:33:46 +08:00
|
|
|
|
[Resolved(CanBeNull = true)]
|
|
|
|
|
private IReadOnlyList<Mod> mods { get; set; }
|
2021-01-22 09:06:24 +08:00
|
|
|
|
|
2021-05-27 13:50:42 +08:00
|
|
|
|
protected override void SkinChanged(ISkinSource skin)
|
2020-09-29 13:09:51 +08:00
|
|
|
|
{
|
2021-05-27 13:50:42 +08:00
|
|
|
|
base.SkinChanged(skin);
|
2020-06-16 21:54:50 +08:00
|
|
|
|
|
2022-03-03 01:33:46 +08:00
|
|
|
|
if (mods != null)
|
2020-09-29 13:09:51 +08:00
|
|
|
|
{
|
2022-03-03 01:33:46 +08:00
|
|
|
|
foreach (var mod in mods.OfType<IApplicableToSample>())
|
|
|
|
|
{
|
|
|
|
|
foreach (var sample in DrawableSamples)
|
|
|
|
|
mod.ApplyToSample(sample);
|
|
|
|
|
}
|
2020-09-29 13:09:51 +08:00
|
|
|
|
}
|
2018-06-28 12:43:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-26 13:36:32 +08:00
|
|
|
|
protected override void SamplePlaybackDisabledChanged(ValueChangedEvent<bool> disabled)
|
|
|
|
|
{
|
|
|
|
|
if (!RequestedPlaying) return;
|
|
|
|
|
|
2021-02-01 15:43:53 +08:00
|
|
|
|
if (!Looping && disabled.NewValue)
|
2021-01-27 12:08:51 +08:00
|
|
|
|
{
|
2021-02-01 15:43:53 +08:00
|
|
|
|
// the default behaviour for sample disabling is to allow one-shot samples to play out.
|
|
|
|
|
// storyboards regularly have long running samples that can cause this behaviour to lead to unintended results.
|
|
|
|
|
// for this reason, we immediately stop such samples.
|
|
|
|
|
Stop();
|
2021-01-27 12:08:51 +08:00
|
|
|
|
}
|
2021-02-01 15:43:53 +08:00
|
|
|
|
|
|
|
|
|
base.SamplePlaybackDisabledChanged(disabled);
|
2021-01-26 13:36:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-28 12:43:56 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2021-04-20 15:51:24 +08:00
|
|
|
|
// Check if we've yet to pass the sample start time.
|
2019-08-23 19:54:39 +08:00
|
|
|
|
if (Time.Current < sampleInfo.StartTime)
|
2018-06-28 12:43:56 +08:00
|
|
|
|
{
|
2020-09-29 13:09:51 +08:00
|
|
|
|
Stop();
|
2018-06-28 12:43:56 +08:00
|
|
|
|
|
2021-04-20 15:51:24 +08:00
|
|
|
|
// Playback has stopped, but if the user fast-forwards to a point after the start time of the sample then
|
|
|
|
|
// we must not have a lifetime end in order to continue receiving updates and start the sample below.
|
2019-08-23 19:54:39 +08:00
|
|
|
|
LifetimeStart = sampleInfo.StartTime;
|
2018-06-28 12:43:56 +08:00
|
|
|
|
LifetimeEnd = double.MaxValue;
|
2021-04-20 15:51:24 +08:00
|
|
|
|
|
|
|
|
|
return;
|
2018-06-28 12:43:56 +08:00
|
|
|
|
}
|
2021-04-20 15:51:24 +08:00
|
|
|
|
|
|
|
|
|
// Ensure that we've elapsed from a point before the sample's start time before playing.
|
|
|
|
|
if (Time.Current - Time.Elapsed <= sampleInfo.StartTime)
|
2018-06-28 12:43:56 +08:00
|
|
|
|
{
|
|
|
|
|
// We've passed the start time of the sample. We only play the sample if we're within an allowable range
|
|
|
|
|
// from the sample's start, to reduce layering if we've been fast-forwarded far into the future
|
2020-09-30 21:42:00 +08:00
|
|
|
|
if (!RequestedPlaying && Time.Current - sampleInfo.StartTime < allowable_late_start)
|
2020-09-29 13:09:51 +08:00
|
|
|
|
Play();
|
2018-06-28 12:43:56 +08:00
|
|
|
|
}
|
2021-04-20 15:51:24 +08:00
|
|
|
|
|
|
|
|
|
// Playback has started, but if the user rewinds to a point before the start time of the sample then
|
|
|
|
|
// we must not have a lifetime start in order to continue receiving updates and stop the sample above.
|
|
|
|
|
LifetimeStart = double.MinValue;
|
|
|
|
|
LifetimeEnd = sampleInfo.StartTime;
|
2018-06-28 12:43:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|