diff --git a/src/game.rs b/src/game.rs index 20cc2be..23ac10d 100644 --- a/src/game.rs +++ b/src/game.rs @@ -69,9 +69,9 @@ fn handle_game_event( mut er_game: EventReader, mut ew_sfx: EventWriter, mut ew_updateoverlays: EventWriter, + mut ew_updatemenu: EventWriter, mut ew_togglemusic: EventWriter, mut q_window: Query<&mut Window, With>, - mut q_menu_vis: Query<&mut Visibility, With>, mut q_light: Query<&mut DirectionalLight>, mut mapcam: ResMut, opt: Res, @@ -112,9 +112,7 @@ 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); - } + ew_updatemenu.send(menu::UpdateMenuEvent); } GameEvent::SetThirdPerson(turn) => { settings.third_person = turn.to_bool(settings.third_person); diff --git a/src/menu.rs b/src/menu.rs index b043572..3bdb1f4 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -22,12 +22,13 @@ impl Plugin for MenuPlugin { app.add_systems(Startup, setup.after(hud::setup)); app.add_systems(PreUpdate, show_deathscreen.run_if(on_event::())); app.add_systems(Update, handle_deathscreen_input); - app.add_systems(PostUpdate, update_menu); + app.add_systems(PostUpdate, update_menu.run_if(on_event::())); app.add_systems(Update, handle_input.run_if(alive)); app.insert_resource(DeathScreenInputDelayTimer( Timer::from_seconds(1.0, TimerMode::Once))); app.insert_resource(MenuState::default()); app.add_event::(); + app.add_event::(); } } @@ -36,15 +37,16 @@ impl Plugin for MenuPlugin { #[derive(Component)] pub struct MenuTopLevel; #[derive(Component)] pub struct DeathScreenElement; #[derive(Component)] pub struct DeathText; +#[derive(Event)] pub struct UpdateMenuEvent; #[derive(Event, PartialEq)] pub enum DeathScreenEvent { Show, Hide } pub const MENUDEF: &[(&str, MenuAction)] = &[ - ("Toggle Map [M]", MenuAction::ToggleMap), - ("Toggle Augmented Reality [TAB]", MenuAction::ToggleAR), - ("Toggle Sound", MenuAction::ToggleSound), - ("Toggle Music", MenuAction::ToggleMusic), + ("", MenuAction::ToggleMap), + ("", MenuAction::ToggleAR), + ("", MenuAction::ToggleSound), + ("", MenuAction::ToggleMusic), ("Toggle Fullscreen [F11]", MenuAction::ToggleFullscreen), - ("Toggle Shadows", MenuAction::ToggleShadows), + ("", MenuAction::ToggleShadows), ("Restart Game", MenuAction::Restart), ("Quit", MenuAction::Quit), ]; @@ -244,11 +246,15 @@ pub struct MenuState { pub fn update_menu( mut q_text: Query<&mut Text, With>, + mut q_vis: Query<&mut Visibility, With>, menustate: Res, settings: Res, ) { - if !settings.menu_active { - return; + for mut vis in &mut q_vis { + *vis = bool2vis(settings.menu_active); + } + fn bool2string(boolean: bool) -> String { + if boolean { "On" } else { "Off" }.to_string() } if let Ok(mut text) = q_text.get_single_mut() { for i in 0..text.sections.len() { @@ -257,6 +263,34 @@ pub fn update_menu( } else { text.sections[i].style.color = settings.hud_color; } + + match MENUDEF[i].1 { + MenuAction::ToggleSound => { + let onoff = bool2string(!settings.mute_sfx); + text.sections[i].value = format!("Sound: {onoff}\n"); + } + MenuAction::ToggleMusic => { + let onoff = bool2string(!settings.mute_music); + text.sections[i].value = format!("Music: {onoff}\n"); + } + MenuAction::ToggleAR => { + let onoff = bool2string(settings.hud_active); + text.sections[i].value = format!("Augmented Reality: {onoff} [TAB]\n"); + } + MenuAction::ToggleMap => { + let onoff = bool2string(settings.map_active); + text.sections[i].value = format!("Map: {onoff} [M]\n"); + } + MenuAction::ToggleShadows => { + let onoff = if settings.shadows_sun { + "Flashlight + Sun" + } else { + "Flashlight Only" + }; + text.sections[i].value = format!("Shadows: {onoff}\n"); + } + _ => {} + } } } } @@ -269,6 +303,7 @@ pub fn handle_input( mut ew_game: EventWriter, mut ew_playerdies: EventWriter, mut ew_sfx: EventWriter, + mut ew_updatemenu: EventWriter, ) { if keyboard_input.just_pressed(settings.key_menu) || keyboard_input.just_pressed(settings.key_vehicle) && settings.menu_active @@ -284,6 +319,7 @@ pub fn handle_input( { menustate.cursor = menustate.cursor.saturating_sub(1); ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click)); + ew_updatemenu.send(UpdateMenuEvent); } if keyboard_input.just_pressed(settings.key_back) || keyboard_input.just_pressed(settings.key_mousedown) @@ -291,6 +327,7 @@ pub fn handle_input( { menustate.cursor = (menustate.cursor + 1).min(MENUDEF.len() - 1); ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click)); + ew_updatemenu.send(UpdateMenuEvent); } if keyboard_input.just_pressed(settings.key_interact) || keyboard_input.just_pressed(KeyCode::Enter) @@ -300,21 +337,26 @@ pub fn handle_input( MenuAction::ToggleMap => { ew_game.send(GameEvent::SetMap(Toggle)); ew_game.send(GameEvent::SetMenu(Turn::Off)); + ew_updatemenu.send(UpdateMenuEvent); }, MenuAction::ToggleAR => { ew_game.send(GameEvent::SetAR(Toggle)); + ew_updatemenu.send(UpdateMenuEvent); }, MenuAction::ToggleMusic => { ew_game.send(GameEvent::SetMusic(Toggle)); + ew_updatemenu.send(UpdateMenuEvent); }, MenuAction::ToggleSound => { ew_game.send(GameEvent::SetSound(Toggle)); + ew_updatemenu.send(UpdateMenuEvent); }, MenuAction::ToggleFullscreen => { ew_game.send(GameEvent::SetFullscreen(Toggle)); }, MenuAction::ToggleShadows => { ew_game.send(GameEvent::SetShadows(Toggle)); + ew_updatemenu.send(UpdateMenuEvent); }, MenuAction::Restart => { settings.god_mode = false;