add Restart Game to menu

This commit is contained in:
yuni 2024-05-13 20:53:08 +02:00
parent 1c10a0c561
commit 556e98deec
3 changed files with 30 additions and 10 deletions

View file

@ -53,6 +53,7 @@ pub enum DamageType {
Trauma, Trauma,
GForce, GForce,
Asphyxiation, Asphyxiation,
DivineIntervention,
//Poison, //Poison,
//Radiation, //Radiation,
//Freeze, //Freeze,
@ -364,7 +365,7 @@ pub fn handle_input(
} }
else if keyboard_input.just_pressed(settings.key_restart) { else if keyboard_input.just_pressed(settings.key_restart) {
settings.god_mode = false; settings.god_mode = false;
ew_playerdies.send(game::PlayerDiesEvent(DamageType::Mental)); ew_playerdies.send(game::PlayerDiesEvent(DamageType::DivineIntervention));
} }
} }

View file

@ -42,6 +42,7 @@ pub enum GameEvent {
SetSound(Turn), SetSound(Turn),
SetMap(Turn), SetMap(Turn),
SetFullscreen(Turn), SetFullscreen(Turn),
SetMenu(Turn),
} }
pub enum Turn { pub enum Turn {
@ -67,6 +68,7 @@ fn handle_game_event(
mut ew_updateoverlays: EventWriter<hud::UpdateOverlayVisibility>, mut ew_updateoverlays: EventWriter<hud::UpdateOverlayVisibility>,
mut ew_togglemusic: EventWriter<audio::ToggleMusicEvent>, mut ew_togglemusic: EventWriter<audio::ToggleMusicEvent>,
mut q_window: Query<&mut Window, With<PrimaryWindow>>, mut q_window: Query<&mut Window, With<PrimaryWindow>>,
mut q_menu_vis: Query<&mut Visibility, With<menu::MenuElement>>,
mut mapcam: ResMut<camera::MapCam>, mut mapcam: ResMut<camera::MapCam>,
opt: Res<var::CommandLineOptions>, opt: Res<var::CommandLineOptions>,
) { ) {
@ -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(); log.clear();
match death.0 { 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 => { actor::DamageType::Mental => {
settings.death_cause = "Brain Damage".to_string(); settings.death_cause = "Brain Damage".to_string();
ew_effect.send(visual::SpawnEffectEvent { ew_effect.send(visual::SpawnEffectEvent {

View file

@ -44,6 +44,7 @@ pub const MENUDEF: &[(&str, MenuAction)] = &[
("Toggle Sound", MenuAction::ToggleSound), ("Toggle Sound", MenuAction::ToggleSound),
("Toggle Music", MenuAction::ToggleMusic), ("Toggle Music", MenuAction::ToggleMusic),
("Toggle Fullscreen", MenuAction::ToggleFullscreen), ("Toggle Fullscreen", MenuAction::ToggleFullscreen),
("Restart Game", MenuAction::Restart),
("Quit", MenuAction::Quit), ("Quit", MenuAction::Quit),
]; ];
@ -54,6 +55,7 @@ pub enum MenuAction {
ToggleSound, ToggleSound,
ToggleMusic, ToggleMusic,
ToggleFullscreen, ToggleFullscreen,
Restart,
Quit, Quit,
} }
@ -178,11 +180,13 @@ pub fn show_deathscreen(
mut q_vis: Query<&mut Visibility, With<DeathScreenElement>>, mut q_vis: Query<&mut Visibility, With<DeathScreenElement>>,
mut q_text: Query<&mut Text, With<DeathText>>, mut q_text: Query<&mut Text, With<DeathText>>,
mut ew_pausesfx: EventWriter<audio::PauseAllSfxEvent>, mut ew_pausesfx: EventWriter<audio::PauseAllSfxEvent>,
mut ew_game: EventWriter<GameEvent>,
mut ew_sfx: EventWriter<audio::PlaySfxEvent>, mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
mut ew_effect: EventWriter<visual::SpawnEffectEvent>, mut ew_effect: EventWriter<visual::SpawnEffectEvent>,
mut ew_respawn: EventWriter<world::RespawnEvent>, mut ew_respawn: EventWriter<world::RespawnEvent>,
mut ew_respawnaudiosinks: EventWriter<audio::RespawnSinksEvent>, mut ew_respawnaudiosinks: EventWriter<audio::RespawnSinksEvent>,
mut timer: ResMut<DeathScreenInputDelayTimer>, mut timer: ResMut<DeathScreenInputDelayTimer>,
mut menustate: ResMut<MenuState>,
mut settings: ResMut<Settings>, mut settings: ResMut<Settings>,
) { ) {
for event in er_deathscreen.read() { for event in er_deathscreen.read() {
@ -195,6 +199,8 @@ pub fn show_deathscreen(
if show { if show {
timer.0.reset(); timer.0.reset();
*menustate = MenuState::default();
ew_game.send(GameEvent::SetMenu(Turn::Off));
ew_pausesfx.send(audio::PauseAllSfxEvent); ew_pausesfx.send(audio::PauseAllSfxEvent);
if let Ok(mut text) = q_text.get_single_mut() { if let Ok(mut text) = q_text.get_single_mut() {
let poems: Vec<&str> = POEMS.split("\n\n").collect(); let poems: Vec<&str> = POEMS.split("\n\n").collect();
@ -256,19 +262,16 @@ pub fn update_menu(
pub fn handle_input( pub fn handle_input(
keyboard_input: Res<ButtonInput<KeyCode>>, keyboard_input: Res<ButtonInput<KeyCode>>,
mut settings: ResMut<Settings>, mut settings: ResMut<Settings>,
mut q_vis: Query<&mut Visibility, With<MenuElement>>,
mut menustate: ResMut<MenuState>, mut menustate: ResMut<MenuState>,
mut app_exit_events: ResMut<Events<bevy::app::AppExit>>, mut app_exit_events: ResMut<Events<bevy::app::AppExit>>,
mut ew_game: EventWriter<game::GameEvent>, mut ew_game: EventWriter<game::GameEvent>,
mut ew_playerdies: EventWriter<game::PlayerDiesEvent>,
mut ew_sfx: EventWriter<audio::PlaySfxEvent>, mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
) { ) {
if keyboard_input.just_pressed(settings.key_menu) if keyboard_input.just_pressed(settings.key_menu)
|| keyboard_input.just_pressed(settings.key_vehicle) && settings.menu_active || keyboard_input.just_pressed(settings.key_vehicle) && settings.menu_active
{ {
settings.menu_active ^= true; ew_game.send(GameEvent::SetMenu(Toggle));
for mut vis in &mut q_vis {
*vis = bool2vis(settings.menu_active);
}
} }
if !settings.menu_active { if !settings.menu_active {
return; return;
@ -294,10 +297,7 @@ pub fn handle_input(
match MENUDEF[menustate.cursor].1 { match MENUDEF[menustate.cursor].1 {
MenuAction::ToggleMap => { MenuAction::ToggleMap => {
ew_game.send(GameEvent::SetMap(Toggle)); ew_game.send(GameEvent::SetMap(Toggle));
settings.menu_active = false; ew_game.send(GameEvent::SetMenu(Turn::Off));
for mut vis in &mut q_vis {
*vis = Visibility::Hidden;
}
}, },
MenuAction::ToggleAR => { MenuAction::ToggleAR => {
ew_game.send(GameEvent::SetAR(Toggle)); ew_game.send(GameEvent::SetAR(Toggle));
@ -311,6 +311,10 @@ pub fn handle_input(
MenuAction::ToggleFullscreen => { MenuAction::ToggleFullscreen => {
ew_game.send(GameEvent::SetFullscreen(Toggle)); ew_game.send(GameEvent::SetFullscreen(Toggle));
}, },
MenuAction::Restart => {
settings.god_mode = false;
ew_playerdies.send(game::PlayerDiesEvent(actor::DamageType::DivineIntervention));
},
MenuAction::Quit => { MenuAction::Quit => {
app_exit_events.send(bevy::app::AppExit); app_exit_events.send(bevy::app::AppExit);
}, },