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
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-06-28 12:43:56 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Storyboards.Drawables
|
|
|
|
|
{
|
|
|
|
|
public class DrawableStoryboardSample : Component
|
|
|
|
|
{
|
|
|
|
|
/// <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;
|
2018-06-28 12:43:56 +08:00
|
|
|
|
private SampleChannel channel;
|
|
|
|
|
|
|
|
|
|
public override bool RemoveWhenNotAlive => false;
|
|
|
|
|
|
2019-08-23 19:54:39 +08:00
|
|
|
|
public DrawableStoryboardSample(StoryboardSampleInfo sampleInfo)
|
2018-06-28 12:43:56 +08:00
|
|
|
|
{
|
2019-08-23 19:54:39 +08:00
|
|
|
|
this.sampleInfo = sampleInfo;
|
|
|
|
|
LifetimeStart = sampleInfo.StartTime;
|
2018-06-28 12:43:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2019-02-01 14:42:15 +08:00
|
|
|
|
private void load(IBindable<WorkingBeatmap> beatmap)
|
2018-06-28 12:43:56 +08:00
|
|
|
|
{
|
2019-08-23 19:54:39 +08:00
|
|
|
|
channel = beatmap.Value.Skin.GetSample(sampleInfo);
|
2018-06-28 12:43:56 +08:00
|
|
|
|
|
|
|
|
|
if (channel != null)
|
2019-08-23 19:54:39 +08:00
|
|
|
|
channel.Volume.Value = sampleInfo.Volume / 100.0;
|
2018-06-28 12:43:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2018-09-15 22:30:11 +08:00
|
|
|
|
// TODO: this logic will need to be consolidated with other game samples like hit sounds.
|
2019-08-23 19:54:39 +08:00
|
|
|
|
if (Time.Current < sampleInfo.StartTime)
|
2018-06-28 12:43:56 +08:00
|
|
|
|
{
|
|
|
|
|
// We've rewound before the start time of the sample
|
|
|
|
|
channel?.Stop();
|
|
|
|
|
|
|
|
|
|
// 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 19:54:39 +08:00
|
|
|
|
LifetimeStart = sampleInfo.StartTime;
|
2018-06-28 12:43:56 +08:00
|
|
|
|
LifetimeEnd = double.MaxValue;
|
|
|
|
|
}
|
2019-08-23 19:54:39 +08:00
|
|
|
|
else 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
|
2019-08-23 19:54:39 +08:00
|
|
|
|
if (Time.Current - sampleInfo.StartTime < allowable_late_start)
|
2018-06-28 12:43:56 +08:00
|
|
|
|
channel?.Play();
|
|
|
|
|
|
|
|
|
|
// 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 19:54:39 +08:00
|
|
|
|
LifetimeEnd = sampleInfo.StartTime;
|
2018-06-28 12:43:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-03 18:28:10 +08:00
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
channel?.Stop();
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
}
|
2018-06-28 12:43:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|