2019-01-24 08:43:03 +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.
|
2018-06-28 04:43:56 +00:00
|
|
|
|
|
2020-06-16 13:54:50 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2018-06-28 04:43:56 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2020-06-16 13:54:50 +00:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2020-09-29 05:09:51 +00:00
|
|
|
|
using osu.Game.Skinning;
|
2018-06-28 04:43:56 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Storyboards.Drawables
|
|
|
|
|
{
|
2020-09-30 13:42:00 +00:00
|
|
|
|
public class DrawableStoryboardSample : PausableSkinnableSound
|
2018-06-28 04:43:56 +00: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 11:54:39 +00:00
|
|
|
|
private readonly StoryboardSampleInfo sampleInfo;
|
2020-06-18 20:46:32 +00:00
|
|
|
|
|
2018-06-28 04:43:56 +00:00
|
|
|
|
public override bool RemoveWhenNotAlive => false;
|
|
|
|
|
|
2019-08-23 11:54:39 +00:00
|
|
|
|
public DrawableStoryboardSample(StoryboardSampleInfo sampleInfo)
|
2020-09-29 05:09:51 +00:00
|
|
|
|
: base(sampleInfo)
|
2018-06-28 04:43:56 +00:00
|
|
|
|
{
|
2019-08-23 11:54:39 +00:00
|
|
|
|
this.sampleInfo = sampleInfo;
|
|
|
|
|
LifetimeStart = sampleInfo.StartTime;
|
2018-06-28 04:43:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-29 05:09:51 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private IBindable<IReadOnlyList<Mod>> mods { get; set; }
|
2018-06-28 04:43:56 +00:00
|
|
|
|
|
2020-09-29 05:09:51 +00:00
|
|
|
|
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
|
|
|
|
|
{
|
|
|
|
|
base.SkinChanged(skin, allowFallback);
|
2020-06-16 13:54:50 +00:00
|
|
|
|
|
2020-06-19 18:15:14 +00:00
|
|
|
|
foreach (var mod in mods.Value.OfType<IApplicableToSample>())
|
2020-09-29 05:09:51 +00:00
|
|
|
|
{
|
2020-11-30 10:26:25 +00:00
|
|
|
|
foreach (var sample in DrawableSamples)
|
|
|
|
|
mod.ApplyToSample(sample);
|
2020-09-29 05:09:51 +00:00
|
|
|
|
}
|
2018-06-28 04:43:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2019-08-23 11:54:39 +00:00
|
|
|
|
if (Time.Current < sampleInfo.StartTime)
|
2018-06-28 04:43:56 +00:00
|
|
|
|
{
|
|
|
|
|
// We've rewound before the start time of the sample
|
2020-09-29 05:09:51 +00:00
|
|
|
|
Stop();
|
2018-06-28 04:43:56 +00:00
|
|
|
|
|
|
|
|
|
// In the case that the user fast-forwards to a point far beyond the start time of the sample,
|
|
|
|
|
// we want to be able to fall into the if-conditional below (therefore we must not have a life time end)
|
2019-08-23 11:54:39 +00:00
|
|
|
|
LifetimeStart = sampleInfo.StartTime;
|
2018-06-28 04:43:56 +00:00
|
|
|
|
LifetimeEnd = double.MaxValue;
|
|
|
|
|
}
|
2020-06-15 00:38:33 +00:00
|
|
|
|
else if (Time.Current - Time.Elapsed <= sampleInfo.StartTime)
|
2018-06-28 04:43:56 +00: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 13:42:00 +00:00
|
|
|
|
if (!RequestedPlaying && Time.Current - sampleInfo.StartTime < allowable_late_start)
|
2020-09-29 05:09:51 +00:00
|
|
|
|
Play();
|
2018-06-28 04:43:56 +00:00
|
|
|
|
|
|
|
|
|
// In the case that the user rewinds to a point far behind the start time of the sample,
|
|
|
|
|
// we want to be able to fall into the if-conditional above (therefore we must not have a life time start)
|
|
|
|
|
LifetimeStart = double.MinValue;
|
2019-08-23 11:54:39 +00:00
|
|
|
|
LifetimeEnd = sampleInfo.StartTime;
|
2018-06-28 04:43:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|