diff --git a/src/audio.rs b/src/audio.rs index 1311b24..8a899ab 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -227,7 +227,7 @@ pub fn play_sfx( if let Some(source) = sounds.0.get(&sfx.0) { commands.spawn(AudioBundle { source: source.clone(), - settings: PlaybackSettings::DESPAWN, + settings: PlaybackSettings::DESPAWN.with_volume(Volume::new(settings.volume_sfx)), }); } } @@ -278,11 +278,7 @@ pub fn play_gasp_sfx( continue; } if suit.oxygen <= 0.0 && !settings.god_mode { - if settings.mute_sfx { - sink.set_volume(0.0); - } else { - sink.set_volume(0.6); - } + sink.set_volume(settings.volume_sfx * 0.6); sink.play(); } else { if !sink.is_paused() { diff --git a/src/camera.rs b/src/camera.rs index 42b062f..8c4f17e 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -672,7 +672,9 @@ pub fn apply_input_to_player( let speed = sink.speed(); let action = pitch_yaw_rot.length_squared().powf(0.2) * 0.0005; if play_reactionwheel_sound && !settings.mute_sfx && bike.is_some() { - sink.set_volume(reactionwheel_volume * (volume + action).clamp(0.0, 1.0)); + sink.set_volume( + settings.volume_sfx * reactionwheel_volume * (volume + action).clamp(0.0, 1.0), + ); sink.set_speed((speed + action * 0.2).clamp(0.2, 0.5)); sink.play() } else { @@ -706,22 +708,21 @@ pub fn apply_input_to_player( sink.pause(); } else { let volume = sink.volume(); + let maxvol = settings.volume_sfx * vol_boost; if engine.engine_type == engine_type { if play_thruster_sound { sink.set_speed(speed); sink.play(); - if volume < 1.0 { - let maxvol = vol_boost; - //let maxvol = engine.current_warmup * vol_boost; + if volume < maxvol { sink.set_volume( (volume + dt / seconds_to_max_vol).clamp(0.0, maxvol), ); } } else { - sink.set_volume((volume - dt / seconds_to_min_vol).clamp(0.0, 1.0)); + sink.set_volume((volume - dt / seconds_to_min_vol).clamp(0.0, maxvol)); } } else if volume > 0.0 { - sink.set_volume((volume - dt / seconds_to_min_vol).clamp(0.0, 1.0)); + sink.set_volume((volume - dt / seconds_to_min_vol).clamp(0.0, maxvol)); } if volume < 0.0001 { sink.pause(); diff --git a/src/menu.rs b/src/menu.rs index edaf68d..9da8457 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -471,9 +471,9 @@ pub fn update_menu( .noise_cancellation_modes .get(settings.noise_cancellation_mode) { - noisecancel + &noisecancel.0 } else { - &settings.noise_cancellation_modes[0] + &settings.noise_cancellation_modes[0].0 }; text.sections[i].value = format!("\nNoise Cancellation: {noisecancel}\n"); } diff --git a/src/var.rs b/src/var.rs index 4f84228..9b1451b 100644 --- a/src/var.rs +++ b/src/var.rs @@ -41,11 +41,11 @@ pub struct Settings { pub alive: bool, pub mute_sfx: bool, pub noise_cancellation_mode: usize, - pub noise_cancellation_modes: Vec, + pub noise_cancellation_modes: Vec<(String, f32)>, pub radio_mode: usize, pub radio_modes: Vec, // see also: settings.is_radio_playing() - pub volume_sfx: u8, - pub volume_music: u8, + pub volume_sfx: f32, + pub volume_music: f32, pub mouse_sensitivity: f32, pub fov: f32, pub fov_highspeed: f32, @@ -173,7 +173,12 @@ impl Default for Settings { alive: true, mute_sfx: false, noise_cancellation_mode: 0, - noise_cancellation_modes: vec!["Off".to_string(), "On".to_string()], + noise_cancellation_modes: vec![ + ("Off".to_string(), 1.0), + ("33%".to_string(), 0.66), + ("66%".to_string(), 0.33), + ("100%".to_string(), 0.0), + ], radio_mode: 1, radio_modes: vec![ // see also: settings.is_radio_playing() @@ -181,8 +186,8 @@ impl Default for Settings { "Space Wave Radio".to_string(), "Amplify outside recordings".to_string(), ], - volume_sfx: 100, - volume_music: 100, + volume_sfx: 1.0, + volume_music: 1.0, mouse_sensitivity: 0.4, fov: 50.0, fov_highspeed: 25.0, @@ -349,7 +354,15 @@ impl Settings { value }; self.noise_cancellation_mode = value; - self.mute_sfx = value >= 1; + self.volume_sfx = if let Some(noisecancel) = self + .noise_cancellation_modes + .get(self.noise_cancellation_mode) + { + noisecancel.1 + } else { + self.noise_cancellation_modes[0].1 + }; + self.mute_sfx = value >= 3; } }