From ea25c7fed35386c939a2a3b9fef40ce4723ba6c2 Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 13 May 2024 04:33:03 +0200 Subject: [PATCH] add audio::PauseAllSfxEvent --- src/audio.rs | 11 +++++++++++ src/menu.rs | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/audio.rs b/src/audio.rs index 65b93a7..ccbe27f 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -21,9 +21,11 @@ impl Plugin for AudioPlugin { app.add_systems(Startup, setup); app.add_systems(Update, toggle_bgm); app.add_systems(Update, play_zoom_sfx); + app.add_systems(Update, pause_all.run_if(on_event::())); app.add_systems(PostUpdate, play_sfx); app.add_systems(PostUpdate, update_music); app.add_event::(); + app.add_event::(); app.add_event::(); app.insert_resource(ZoomTimer( Timer::from_seconds(0.09, TimerMode::Repeating))); @@ -91,6 +93,7 @@ pub enum SfxType { } #[derive(Event)] pub struct PlaySfxEvent(pub Sfx); +#[derive(Event)] pub struct PauseAllSfxEvent; #[derive(Event)] pub struct ToggleMusicEvent(); #[derive(Resource)] pub struct Sounds(HashMap>); @@ -213,3 +216,11 @@ pub fn play_zoom_sfx( *last_zoom_level = mapcam.target_zoom_level; } } + +pub fn pause_all( + q_audiosinks: Query<&AudioSink, With>, +) { + for sink in &q_audiosinks { + sink.pause(); + } +} diff --git a/src/menu.rs b/src/menu.rs index 2967733..462e401 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -104,6 +104,7 @@ pub fn show_deathscreen( mut er_deathscreen: EventReader, mut q_vis: Query<&mut Visibility, With>, mut q_text: Query<&mut Text, With>, + mut ew_pausesfx: EventWriter, mut ew_sfx: EventWriter, mut ew_effect: EventWriter, mut ew_respawn: EventWriter, @@ -117,6 +118,7 @@ pub fn show_deathscreen( settings.deathscreen_active = show; if show { + ew_pausesfx.send(audio::PauseAllSfxEvent); if let Ok(mut text) = q_text.get_single_mut() { let poems: Vec<&str> = POEMS.split("\n\n").collect(); if poems.len() > 0 {