# HG changeset patch # User Alys Brooks # Date 2022-11-13 22:40:03 # Node ID fa8826446e55017a3ebc54e129cc817efcf6e967 # Parent 1798373917e7892605df0055f877400470e63287 Make sound preview use the new volume. Plays the sound at the new volume, not the old volume. Uses nullables, which I'm a little unsure of how well they'll work out in practice. I think this is a reasonable place to experiment. diff --git a/isometric-park-fna/Engines/SoundEffectsEngine.cs b/isometric-park-fna/Engines/SoundEffectsEngine.cs --- a/isometric-park-fna/Engines/SoundEffectsEngine.cs +++ b/isometric-park-fna/Engines/SoundEffectsEngine.cs @@ -55,10 +55,11 @@ in ReadMessages()) { var sound = sounds[message.SoundName]; + var volume = message.Volume ?? this.volume; + if (!muted) { - sound.Play(this.volume, this.pitch, this.pan); + sound.Play(volume, this.pitch, this.pan); } - } } diff --git a/isometric-park-fna/Messages/PlaySoundMessage.cs b/isometric-park-fna/Messages/PlaySoundMessage.cs --- a/isometric-park-fna/Messages/PlaySoundMessage.cs +++ b/isometric-park-fna/Messages/PlaySoundMessage.cs @@ -2,11 +2,14 @@ using Encompass; +#nullable enable + namespace isometricparkfna.Messages { public struct PlaySoundMessage : IMessage { public string SoundName; + public float? Volume; } } diff --git a/isometric-park-fna/UI/OptionsWindow.cs b/isometric-park-fna/UI/OptionsWindow.cs --- a/isometric-park-fna/UI/OptionsWindow.cs +++ b/isometric-park-fna/UI/OptionsWindow.cs @@ -158,7 +158,7 @@ ImGui.DragFloat("##Sfx", ref newSoundEffectVolume, 0.005f, 0.0f, 1.0f, "%.2f"); if ((newSoundEffectVolume != prevSoundEffectVolume) && ImGui.IsItemDeactivatedAfterEdit()) { - bridgeEngine.playSoundMessages.Add(new PlaySoundMessage { SoundName = "Bell" }); + bridgeEngine.playSoundMessages.Add(new PlaySoundMessage { SoundName = "Bell", Volume = newSoundEffectVolume}); prevSoundEffectVolume = newSoundEffectVolume; }