From 556e98deec6166631e7a717900e3e884fb2c5004 Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 13 May 2024 20:53:08 +0200 Subject: [PATCH] add Restart Game to menu --- src/actor.rs | 3 ++- src/game.rs | 15 +++++++++++++++ src/menu.rs | 22 +++++++++++++--------- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/actor.rs b/src/actor.rs index df0424c..6230114 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -53,6 +53,7 @@ pub enum DamageType { Trauma, GForce, Asphyxiation, + DivineIntervention, //Poison, //Radiation, //Freeze, @@ -364,7 +365,7 @@ pub fn handle_input( } else if keyboard_input.just_pressed(settings.key_restart) { settings.god_mode = false; - ew_playerdies.send(game::PlayerDiesEvent(DamageType::Mental)); + ew_playerdies.send(game::PlayerDiesEvent(DamageType::DivineIntervention)); } } diff --git a/src/game.rs b/src/game.rs index e4bf3c9..99be9c5 100644 --- a/src/game.rs +++ b/src/game.rs @@ -42,6 +42,7 @@ pub enum GameEvent { SetSound(Turn), SetMap(Turn), SetFullscreen(Turn), + SetMenu(Turn), } pub enum Turn { @@ -67,6 +68,7 @@ fn handle_game_event( mut ew_updateoverlays: EventWriter, mut ew_togglemusic: EventWriter, mut q_window: Query<&mut Window, With>, + mut q_menu_vis: Query<&mut Visibility, With>, mut mapcam: ResMut, opt: Res, ) { @@ -104,6 +106,12 @@ fn handle_game_event( }; } } + GameEvent::SetMenu(turn) => { + settings.menu_active = turn.to_bool(settings.menu_active); + for mut vis in &mut q_menu_vis { + *vis = bool2vis(settings.menu_active); + } + } } } } @@ -136,6 +144,13 @@ fn handle_player_death( log.clear(); match death.0 { + actor::DamageType::DivineIntervention => { + settings.death_cause = "Divine Intervention".to_string(); + ew_effect.send(visual::SpawnEffectEvent { + class: visual::Effects::FadeIn(Color::BLACK), + duration: 4.0, + }); + } actor::DamageType::Mental => { settings.death_cause = "Brain Damage".to_string(); ew_effect.send(visual::SpawnEffectEvent { diff --git a/src/menu.rs b/src/menu.rs index 0aa6d33..1c87200 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -44,6 +44,7 @@ pub const MENUDEF: &[(&str, MenuAction)] = &[ ("Toggle Sound", MenuAction::ToggleSound), ("Toggle Music", MenuAction::ToggleMusic), ("Toggle Fullscreen", MenuAction::ToggleFullscreen), + ("Restart Game", MenuAction::Restart), ("Quit", MenuAction::Quit), ]; @@ -54,6 +55,7 @@ pub enum MenuAction { ToggleSound, ToggleMusic, ToggleFullscreen, + Restart, Quit, } @@ -178,11 +180,13 @@ pub fn show_deathscreen( mut q_vis: Query<&mut Visibility, With>, mut q_text: Query<&mut Text, With>, mut ew_pausesfx: EventWriter, + mut ew_game: EventWriter, mut ew_sfx: EventWriter, mut ew_effect: EventWriter, mut ew_respawn: EventWriter, mut ew_respawnaudiosinks: EventWriter, mut timer: ResMut, + mut menustate: ResMut, mut settings: ResMut, ) { for event in er_deathscreen.read() { @@ -195,6 +199,8 @@ pub fn show_deathscreen( if show { timer.0.reset(); + *menustate = MenuState::default(); + ew_game.send(GameEvent::SetMenu(Turn::Off)); ew_pausesfx.send(audio::PauseAllSfxEvent); if let Ok(mut text) = q_text.get_single_mut() { let poems: Vec<&str> = POEMS.split("\n\n").collect(); @@ -256,19 +262,16 @@ pub fn update_menu( pub fn handle_input( keyboard_input: Res>, mut settings: ResMut, - mut q_vis: Query<&mut Visibility, With>, mut menustate: ResMut, mut app_exit_events: ResMut>, mut ew_game: EventWriter, + mut ew_playerdies: EventWriter, mut ew_sfx: EventWriter, ) { if keyboard_input.just_pressed(settings.key_menu) || keyboard_input.just_pressed(settings.key_vehicle) && settings.menu_active { - settings.menu_active ^= true; - for mut vis in &mut q_vis { - *vis = bool2vis(settings.menu_active); - } + ew_game.send(GameEvent::SetMenu(Toggle)); } if !settings.menu_active { return; @@ -294,10 +297,7 @@ pub fn handle_input( match MENUDEF[menustate.cursor].1 { MenuAction::ToggleMap => { ew_game.send(GameEvent::SetMap(Toggle)); - settings.menu_active = false; - for mut vis in &mut q_vis { - *vis = Visibility::Hidden; - } + ew_game.send(GameEvent::SetMenu(Turn::Off)); }, MenuAction::ToggleAR => { ew_game.send(GameEvent::SetAR(Toggle)); @@ -311,6 +311,10 @@ pub fn handle_input( MenuAction::ToggleFullscreen => { ew_game.send(GameEvent::SetFullscreen(Toggle)); }, + MenuAction::Restart => { + settings.god_mode = false; + ew_playerdies.send(game::PlayerDiesEvent(actor::DamageType::DivineIntervention)); + }, MenuAction::Quit => { app_exit_events.send(bevy::app::AppExit); },