mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-26 06:28:35 +01:00
Added SoundEffectInstanceHandler.Stop
This commit is contained in:
parent
7e49eaef10
commit
b4f79f0753
2 changed files with 19 additions and 5 deletions
|
@ -12,6 +12,7 @@ Jump to version:
|
||||||
Additions
|
Additions
|
||||||
- Added StringBuilder overloads to GenericFont
|
- Added StringBuilder overloads to GenericFont
|
||||||
- Added ColorExtensions.Multiply
|
- Added ColorExtensions.Multiply
|
||||||
|
- Added SoundEffectInstanceHandler.Stop
|
||||||
|
|
||||||
Improvements
|
Improvements
|
||||||
- Generify GenericFont's string drawing
|
- Generify GenericFont's string drawing
|
||||||
|
|
|
@ -19,8 +19,7 @@ namespace MLEM.Sound {
|
||||||
/// Creates a new sound effect instance handler with the given settings
|
/// Creates a new sound effect instance handler with the given settings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="game">The game instance</param>
|
/// <param name="game">The game instance</param>
|
||||||
public SoundEffectInstanceHandler(Game game) : base(game) {
|
public SoundEffectInstanceHandler(Game game) : base(game) {}
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc cref="Update()"/>
|
/// <inheritdoc cref="Update()"/>
|
||||||
public override void Update(GameTime gameTime) {
|
public override void Update(GameTime gameTime) {
|
||||||
|
@ -36,8 +35,7 @@ namespace MLEM.Sound {
|
||||||
for (var i = this.playingSounds.Count - 1; i >= 0; i--) {
|
for (var i = this.playingSounds.Count - 1; i >= 0; i--) {
|
||||||
var entry = this.playingSounds[i];
|
var entry = this.playingSounds[i];
|
||||||
if (entry.Instance.IsDisposed || entry.Instance.State == SoundState.Stopped) {
|
if (entry.Instance.IsDisposed || entry.Instance.State == SoundState.Stopped) {
|
||||||
entry.Instance.Stop(true);
|
entry.StopAndNotify();
|
||||||
entry.OnStopped?.Invoke(entry.Instance);
|
|
||||||
this.playingSounds.RemoveAt(i);
|
this.playingSounds.RemoveAt(i);
|
||||||
} else {
|
} else {
|
||||||
entry.TryApply3D(this.listeners);
|
entry.TryApply3D(this.listeners);
|
||||||
|
@ -69,6 +67,16 @@ namespace MLEM.Sound {
|
||||||
entry.Instance.Resume();
|
entry.Instance.Resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stops all of the sound effect instances in this handler
|
||||||
|
/// </summary>
|
||||||
|
public void Stop() {
|
||||||
|
this.playingSounds.RemoveAll(e => {
|
||||||
|
e.StopAndNotify();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a new <see cref="SoundEffectInstance"/> to this handler.
|
/// Adds a new <see cref="SoundEffectInstance"/> to this handler.
|
||||||
/// This also starts playing the instance.
|
/// This also starts playing the instance.
|
||||||
|
@ -132,7 +140,7 @@ namespace MLEM.Sound {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly SoundEffectInstance Instance;
|
public readonly SoundEffectInstance Instance;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An action that is invoked when this entry's <see cref="Instance"/> is stopped.
|
/// An action that is invoked when this entry's <see cref="Instance"/> is stopped or after it finishes naturally.
|
||||||
/// This action is invoked in <see cref="SoundEffectInstanceHandler.Update()"/>.
|
/// This action is invoked in <see cref="SoundEffectInstanceHandler.Update()"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly Action<SoundEffectInstance> OnStopped;
|
public readonly Action<SoundEffectInstance> OnStopped;
|
||||||
|
@ -153,6 +161,11 @@ namespace MLEM.Sound {
|
||||||
this.Instance.Apply3D(listeners, this.Emitter);
|
this.Instance.Apply3D(listeners, this.Emitter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void StopAndNotify() {
|
||||||
|
this.Instance.Stop(true);
|
||||||
|
this.OnStopped?.Invoke(this.Instance);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue