add Restart Game to menu
This commit is contained in:
parent
1c10a0c561
commit
556e98deec
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
15
src/game.rs
15
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<hud::UpdateOverlayVisibility>,
|
||||
mut ew_togglemusic: EventWriter<audio::ToggleMusicEvent>,
|
||||
mut q_window: Query<&mut Window, With<PrimaryWindow>>,
|
||||
mut q_menu_vis: Query<&mut Visibility, With<menu::MenuElement>>,
|
||||
mut mapcam: ResMut<camera::MapCam>,
|
||||
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();
|
||||
|
||||
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 {
|
||||
|
|
22
src/menu.rs
22
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<DeathScreenElement>>,
|
||||
mut q_text: Query<&mut Text, With<DeathText>>,
|
||||
mut ew_pausesfx: EventWriter<audio::PauseAllSfxEvent>,
|
||||
mut ew_game: EventWriter<GameEvent>,
|
||||
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
||||
mut ew_effect: EventWriter<visual::SpawnEffectEvent>,
|
||||
mut ew_respawn: EventWriter<world::RespawnEvent>,
|
||||
mut ew_respawnaudiosinks: EventWriter<audio::RespawnSinksEvent>,
|
||||
mut timer: ResMut<DeathScreenInputDelayTimer>,
|
||||
mut menustate: ResMut<MenuState>,
|
||||
mut settings: ResMut<Settings>,
|
||||
) {
|
||||
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<ButtonInput<KeyCode>>,
|
||||
mut settings: ResMut<Settings>,
|
||||
mut q_vis: Query<&mut Visibility, With<MenuElement>>,
|
||||
mut menustate: ResMut<MenuState>,
|
||||
mut app_exit_events: ResMut<Events<bevy::app::AppExit>>,
|
||||
mut ew_game: EventWriter<game::GameEvent>,
|
||||
mut ew_playerdies: EventWriter<game::PlayerDiesEvent>,
|
||||
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
||||
) {
|
||||
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);
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue