Make DrawableStoryboardSample a SkinnableSound

Allows sharing pause logic with gameplay samples.
This commit is contained in:
Dean Herbert
2020-09-29 14:09:51 +09:00
parent 74e74e1c31
commit 136843c8e4
7 changed files with 94 additions and 95 deletions

View File

@ -22,7 +22,10 @@ namespace osu.Game.Skinning
[Resolved]
private ISampleStore samples { get; set; }
private bool requestedPlaying;
/// <summary>
/// Whether playback of this sound has been requested, regardless of whether it could be played or not (due to being paused, for instance).
/// </summary>
protected bool PlaybackRequested;
public override bool RemoveWhenNotAlive => false;
public override bool RemoveCompletedTransforms => false;
@ -39,7 +42,7 @@ namespace osu.Game.Skinning
protected virtual bool PlayWhenPaused => false;
private readonly AudioContainer<DrawableSample> samplesContainer;
protected readonly AudioContainer<DrawableSample> SamplesContainer;
public SkinnableSound(ISampleInfo hitSamples)
: this(new[] { hitSamples })
@ -49,7 +52,7 @@ namespace osu.Game.Skinning
public SkinnableSound(IEnumerable<ISampleInfo> hitSamples)
{
this.hitSamples = hitSamples.ToArray();
InternalChild = samplesContainer = new AudioContainer<DrawableSample>();
InternalChild = SamplesContainer = new AudioContainer<DrawableSample>();
}
private readonly IBindable<bool> samplePlaybackDisabled = new Bindable<bool>();
@ -63,7 +66,7 @@ namespace osu.Game.Skinning
samplePlaybackDisabled.BindTo(samplePlaybackDisabler.SamplePlaybackDisabled);
samplePlaybackDisabled.BindValueChanged(disabled =>
{
if (requestedPlaying)
if (PlaybackRequested)
{
if (disabled.NewValue && !PlayWhenPaused)
stop();
@ -87,13 +90,13 @@ namespace osu.Game.Skinning
looping = value;
samplesContainer.ForEach(c => c.Looping = looping);
SamplesContainer.ForEach(c => c.Looping = looping);
}
}
public void Play()
{
requestedPlaying = true;
PlaybackRequested = true;
play();
}
@ -102,7 +105,7 @@ namespace osu.Game.Skinning
if (samplePlaybackDisabled.Value && !PlayWhenPaused)
return;
samplesContainer.ForEach(c =>
SamplesContainer.ForEach(c =>
{
if (PlayWhenZeroVolume || c.AggregateVolume.Value > 0)
c.Play();
@ -111,13 +114,13 @@ namespace osu.Game.Skinning
public void Stop()
{
requestedPlaying = false;
PlaybackRequested = false;
stop();
}
private void stop()
{
samplesContainer.ForEach(c => c.Stop());
SamplesContainer.ForEach(c => c.Stop());
}
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
@ -146,7 +149,7 @@ namespace osu.Game.Skinning
return ch;
}).Where(c => c != null);
samplesContainer.ChildrenEnumerable = channels.Select(c => new DrawableSample(c));
SamplesContainer.ChildrenEnumerable = channels.Select(c => new DrawableSample(c));
// Start playback internally for the new samples if the previous ones were playing beforehand.
if (wasPlaying)
@ -155,24 +158,24 @@ namespace osu.Game.Skinning
#region Re-expose AudioContainer
public BindableNumber<double> Volume => samplesContainer.Volume;
public BindableNumber<double> Volume => SamplesContainer.Volume;
public BindableNumber<double> Balance => samplesContainer.Balance;
public BindableNumber<double> Balance => SamplesContainer.Balance;
public BindableNumber<double> Frequency => samplesContainer.Frequency;
public BindableNumber<double> Frequency => SamplesContainer.Frequency;
public BindableNumber<double> Tempo => samplesContainer.Tempo;
public BindableNumber<double> Tempo => SamplesContainer.Tempo;
public void AddAdjustment(AdjustableProperty type, BindableNumber<double> adjustBindable)
=> samplesContainer.AddAdjustment(type, adjustBindable);
=> SamplesContainer.AddAdjustment(type, adjustBindable);
public void RemoveAdjustment(AdjustableProperty type, BindableNumber<double> adjustBindable)
=> samplesContainer.RemoveAdjustment(type, adjustBindable);
=> SamplesContainer.RemoveAdjustment(type, adjustBindable);
public void RemoveAllAdjustments(AdjustableProperty type)
=> samplesContainer.RemoveAllAdjustments(type);
=> SamplesContainer.RemoveAllAdjustments(type);
public bool IsPlaying => samplesContainer.Any(s => s.Playing);
public bool IsPlaying => SamplesContainer.Any(s => s.Playing);
#endregion
}