From a541591b840b97ecefcf342d86a97f1262fcdc10 Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 18 Mar 2024 04:10:08 +0100 Subject: [PATCH] add "m" key for muting SFX --- src/audio.rs | 9 +++++++-- src/camera.rs | 12 +++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/audio.rs b/src/audio.rs index 5fb2242..be5271a 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -61,7 +61,7 @@ pub fn setup( source: SoundBGM(asset_server.load(ASSET_BGM)).0.clone(), settings: PlaybackSettings { mode: PlaybackMode::Loop, - paused: settings.hud_active, + paused: settings.hud_active || settings.mute_music, ..default() }, }, @@ -72,7 +72,7 @@ pub fn setup( source: SoundBGM(asset_server.load(ASSET_RADIO)).0.clone(), settings: PlaybackSettings { mode: PlaybackMode::Loop, - paused: !settings.hud_active, + paused: !settings.hud_active || settings.mute_music, ..default() }, }, @@ -111,6 +111,11 @@ pub fn toggle_bgm( evwriter_click.send(AudioClickEvent()); evwriter_toggle.send(ToggleMusicEvent()); } + if keyboard_input.just_pressed(KeyCode::KeyM) { + settings.mute_sfx ^= true; + evwriter_click.send(AudioClickEvent()); + evwriter_toggle.send(ToggleMusicEvent()); + } } pub fn play_sfx( diff --git a/src/camera.rs b/src/camera.rs index 2a8dec0..db104a2 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -2,7 +2,7 @@ use bevy::prelude::*; use bevy::input::mouse::MouseMotion; use bevy::window::PrimaryWindow; use std::{f32::consts::*, fmt}; -use crate::audio; +use crate::{settings, audio}; pub struct CameraControllerPlugin; @@ -31,7 +31,6 @@ pub struct CameraController { pub key_run: KeyCode, pub key_stop: KeyCode, pub mouse_key_cursor_grab: MouseButton, - pub keyboard_key_toggle_cursor_grab: KeyCode, pub move_speed: f32, pub friction: f32, pub pitch: f32, @@ -54,7 +53,6 @@ impl Default for CameraController { key_run: KeyCode::KeyR, key_stop: KeyCode::Space, mouse_key_cursor_grab: MouseButton::Left, - keyboard_key_toggle_cursor_grab: KeyCode::KeyM, move_speed: 1.0, friction: 0.1, pitch: 1.0, // pitch=0/yaw=0 -> face sun @@ -72,13 +70,11 @@ impl fmt::Display for CameraController { Freecam Controls: Mouse\t- Move camera orientation {:?}\t- Hold to grab cursor - {:?}\t- Toggle cursor grab {:?} & {:?}\t- Fly forward & backwards {:?} & {:?}\t- Fly sideways left & right {:?} & {:?}\t- Fly up & down {:?}\t- Fly faster while held", self.mouse_key_cursor_grab, - self.keyboard_key_toggle_cursor_grab, self.key_forward, self.key_back, self.key_left, @@ -93,6 +89,7 @@ Freecam Controls: #[allow(clippy::too_many_arguments)] fn run_camera_controller( time: Res