diff --git a/src/camera.rs b/src/camera.rs index 379d2b3..aa78ebe 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -305,33 +305,22 @@ pub fn update_fov( pub fn handle_input( keyboard_input: Res>, - mut q_light: Query<&mut DirectionalLight>, - mut settings: ResMut, - mut mapcam: ResMut, + settings: Res, mut ew_sfx: EventWriter, - mut ew_updateoverlays: EventWriter, + mut ew_game: EventWriter, ) { if keyboard_input.just_pressed(settings.key_camera) { - settings.third_person ^= true; + ew_game.send(GameEvent::SetThirdPerson(Toggle)); } if keyboard_input.just_pressed(settings.key_shadows) { - ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click)); - settings.shadows_sun ^= true; - for mut light in &mut q_light { - light.shadows_enabled = settings.shadows_sun; - } + ew_game.send(GameEvent::SetShadows(Toggle)); } if keyboard_input.just_pressed(settings.key_map) { - settings.map_active ^= true; - if settings.map_active { - ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Woosh)); - } - *mapcam = MapCam::default(); - ew_updateoverlays.send(hud::UpdateOverlayVisibility); + ew_game.send(GameEvent::SetMap(Toggle)); } if keyboard_input.just_pressed(settings.key_rotation_stabilizer) { + ew_game.send(GameEvent::SetRotationStabilizer(Toggle)); ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch)); - settings.rotation_stabilizer_active ^= true; } } diff --git a/src/game.rs b/src/game.rs index 99be9c5..20cc2be 100644 --- a/src/game.rs +++ b/src/game.rs @@ -43,6 +43,9 @@ pub enum GameEvent { SetMap(Turn), SetFullscreen(Turn), SetMenu(Turn), + SetThirdPerson(Turn), + SetRotationStabilizer(Turn), + SetShadows(Turn), } pub enum Turn { @@ -69,6 +72,7 @@ fn handle_game_event( 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,6 +116,19 @@ fn handle_game_event( *vis = bool2vis(settings.menu_active); } } + GameEvent::SetThirdPerson(turn) => { + settings.third_person = turn.to_bool(settings.third_person); + } + GameEvent::SetRotationStabilizer(turn) => { + settings.rotation_stabilizer_active + = turn.to_bool(settings.rotation_stabilizer_active); + } + GameEvent::SetShadows(turn) => { + settings.shadows_sun = turn.to_bool(settings.shadows_sun); + for mut light in &mut q_light { + light.shadows_enabled = settings.shadows_sun; + } + } } } } diff --git a/src/menu.rs b/src/menu.rs index 1c87200..ab644d7 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), + ("Toggle Shadows", MenuAction::ToggleShadows), ("Restart Game", MenuAction::Restart), ("Quit", MenuAction::Quit), ]; @@ -55,6 +56,7 @@ pub enum MenuAction { ToggleSound, ToggleMusic, ToggleFullscreen, + ToggleShadows, Restart, Quit, } @@ -311,6 +313,9 @@ pub fn handle_input( MenuAction::ToggleFullscreen => { ew_game.send(GameEvent::SetFullscreen(Toggle)); }, + MenuAction::ToggleShadows => { + ew_game.send(GameEvent::SetShadows(Toggle)); + }, MenuAction::Restart => { settings.god_mode = false; ew_playerdies.send(game::PlayerDiesEvent(actor::DamageType::DivineIntervention));