implement sfx volume controls

This commit is contained in:
yuni 2024-10-03 23:59:15 +02:00
parent 09115f8e3c
commit a2423fa642
4 changed files with 31 additions and 21 deletions

View file

@ -227,7 +227,7 @@ pub fn play_sfx(
if let Some(source) = sounds.0.get(&sfx.0) { if let Some(source) = sounds.0.get(&sfx.0) {
commands.spawn(AudioBundle { commands.spawn(AudioBundle {
source: source.clone(), 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; continue;
} }
if suit.oxygen <= 0.0 && !settings.god_mode { if suit.oxygen <= 0.0 && !settings.god_mode {
if settings.mute_sfx { sink.set_volume(settings.volume_sfx * 0.6);
sink.set_volume(0.0);
} else {
sink.set_volume(0.6);
}
sink.play(); sink.play();
} else { } else {
if !sink.is_paused() { if !sink.is_paused() {

View file

@ -672,7 +672,9 @@ pub fn apply_input_to_player(
let speed = sink.speed(); let speed = sink.speed();
let action = pitch_yaw_rot.length_squared().powf(0.2) * 0.0005; let action = pitch_yaw_rot.length_squared().powf(0.2) * 0.0005;
if play_reactionwheel_sound && !settings.mute_sfx && bike.is_some() { 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.set_speed((speed + action * 0.2).clamp(0.2, 0.5));
sink.play() sink.play()
} else { } else {
@ -706,22 +708,21 @@ pub fn apply_input_to_player(
sink.pause(); sink.pause();
} else { } else {
let volume = sink.volume(); let volume = sink.volume();
let maxvol = settings.volume_sfx * vol_boost;
if engine.engine_type == engine_type { if engine.engine_type == engine_type {
if play_thruster_sound { if play_thruster_sound {
sink.set_speed(speed); sink.set_speed(speed);
sink.play(); sink.play();
if volume < 1.0 { if volume < maxvol {
let maxvol = vol_boost;
//let maxvol = engine.current_warmup * vol_boost;
sink.set_volume( sink.set_volume(
(volume + dt / seconds_to_max_vol).clamp(0.0, maxvol), (volume + dt / seconds_to_max_vol).clamp(0.0, maxvol),
); );
} }
} else { } 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 { } 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 { if volume < 0.0001 {
sink.pause(); sink.pause();

View file

@ -471,9 +471,9 @@ pub fn update_menu(
.noise_cancellation_modes .noise_cancellation_modes
.get(settings.noise_cancellation_mode) .get(settings.noise_cancellation_mode)
{ {
noisecancel &noisecancel.0
} else { } else {
&settings.noise_cancellation_modes[0] &settings.noise_cancellation_modes[0].0
}; };
text.sections[i].value = format!("\nNoise Cancellation: {noisecancel}\n"); text.sections[i].value = format!("\nNoise Cancellation: {noisecancel}\n");
} }

View file

@ -41,11 +41,11 @@ pub struct Settings {
pub alive: bool, pub alive: bool,
pub mute_sfx: bool, pub mute_sfx: bool,
pub noise_cancellation_mode: usize, pub noise_cancellation_mode: usize,
pub noise_cancellation_modes: Vec<String>, pub noise_cancellation_modes: Vec<(String, f32)>,
pub radio_mode: usize, pub radio_mode: usize,
pub radio_modes: Vec<String>, // see also: settings.is_radio_playing() pub radio_modes: Vec<String>, // see also: settings.is_radio_playing()
pub volume_sfx: u8, pub volume_sfx: f32,
pub volume_music: u8, pub volume_music: f32,
pub mouse_sensitivity: f32, pub mouse_sensitivity: f32,
pub fov: f32, pub fov: f32,
pub fov_highspeed: f32, pub fov_highspeed: f32,
@ -173,7 +173,12 @@ impl Default for Settings {
alive: true, alive: true,
mute_sfx: false, mute_sfx: false,
noise_cancellation_mode: 0, 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_mode: 1,
radio_modes: vec![ radio_modes: vec![
// see also: settings.is_radio_playing() // see also: settings.is_radio_playing()
@ -181,8 +186,8 @@ impl Default for Settings {
"Space Wave Radio".to_string(), "Space Wave Radio".to_string(),
"Amplify outside recordings".to_string(), "Amplify outside recordings".to_string(),
], ],
volume_sfx: 100, volume_sfx: 1.0,
volume_music: 100, volume_music: 1.0,
mouse_sensitivity: 0.4, mouse_sensitivity: 0.4,
fov: 50.0, fov: 50.0,
fov_highspeed: 25.0, fov_highspeed: 25.0,
@ -349,7 +354,15 @@ impl Settings {
value value
}; };
self.noise_cancellation_mode = 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;
} }
} }