mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 04:53:29 +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
|
||||
- Added StringBuilder overloads to GenericFont
|
||||
- Added ColorExtensions.Multiply
|
||||
- Added SoundEffectInstanceHandler.Stop
|
||||
|
||||
Improvements
|
||||
- Generify GenericFont's string drawing
|
||||
|
|
|
@ -19,8 +19,7 @@ namespace MLEM.Sound {
|
|||
/// Creates a new sound effect instance handler with the given settings
|
||||
/// </summary>
|
||||
/// <param name="game">The game instance</param>
|
||||
public SoundEffectInstanceHandler(Game game) : base(game) {
|
||||
}
|
||||
public SoundEffectInstanceHandler(Game game) : base(game) {}
|
||||
|
||||
/// <inheritdoc cref="Update()"/>
|
||||
public override void Update(GameTime gameTime) {
|
||||
|
@ -36,8 +35,7 @@ namespace MLEM.Sound {
|
|||
for (var i = this.playingSounds.Count - 1; i >= 0; i--) {
|
||||
var entry = this.playingSounds[i];
|
||||
if (entry.Instance.IsDisposed || entry.Instance.State == SoundState.Stopped) {
|
||||
entry.Instance.Stop(true);
|
||||
entry.OnStopped?.Invoke(entry.Instance);
|
||||
entry.StopAndNotify();
|
||||
this.playingSounds.RemoveAt(i);
|
||||
} else {
|
||||
entry.TryApply3D(this.listeners);
|
||||
|
@ -69,6 +67,16 @@ namespace MLEM.Sound {
|
|||
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>
|
||||
/// Adds a new <see cref="SoundEffectInstance"/> to this handler.
|
||||
/// This also starts playing the instance.
|
||||
|
@ -132,7 +140,7 @@ namespace MLEM.Sound {
|
|||
/// </summary>
|
||||
public readonly SoundEffectInstance Instance;
|
||||
/// <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()"/>.
|
||||
/// </summary>
|
||||
public readonly Action<SoundEffectInstance> OnStopped;
|
||||
|
@ -153,6 +161,11 @@ namespace MLEM.Sound {
|
|||
this.Instance.Apply3D(listeners, this.Emitter);
|
||||
}
|
||||
|
||||
internal void StopAndNotify() {
|
||||
this.Instance.Stop(true);
|
||||
this.OnStopped?.Invoke(this.Instance);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue