add Toggle Shadows menu entry

This commit is contained in:
yuni 2024-05-13 21:11:27 +02:00
parent 556e98deec
commit b505312f6e
3 changed files with 28 additions and 17 deletions

View file

@ -305,33 +305,22 @@ pub fn update_fov(
pub fn handle_input(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut q_light: Query<&mut DirectionalLight>,
mut settings: ResMut<var::Settings>,
mut mapcam: ResMut<MapCam>,
settings: Res<var::Settings>,
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
mut ew_updateoverlays: EventWriter<hud::UpdateOverlayVisibility>,
mut ew_game: EventWriter<GameEvent>,
) {
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;
}
}

View file

@ -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<audio::ToggleMusicEvent>,
mut q_window: Query<&mut Window, With<PrimaryWindow>>,
mut q_menu_vis: Query<&mut Visibility, With<menu::MenuElement>>,
mut q_light: Query<&mut DirectionalLight>,
mut mapcam: ResMut<camera::MapCam>,
opt: Res<var::CommandLineOptions>,
) {
@ -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;
}
}
}
}
}

View file

@ -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));