From dc077ca1411501baff8d97427ce89c4ba898a660 Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 5 Apr 2024 22:43:14 +0200 Subject: [PATCH] targeting now only works in AR --- src/hud.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/hud.rs b/src/hud.rs index f1d0168..7714edd 100644 --- a/src/hud.rs +++ b/src/hud.rs @@ -48,6 +48,7 @@ impl Plugin for HudPlugin { #[derive(Component)] struct ChatText; #[derive(Component)] struct Reticule; #[derive(Component)] struct ToggleableHudElement; +#[derive(Component)] struct OnlyHideWhenTogglingHud; #[derive(Component)] struct Selectagon; #[derive(Component)] pub struct IsClickable; #[derive(Component)] pub struct IsTargeted; @@ -442,8 +443,11 @@ fn setup( // Selectagon commands.spawn(( Selectagon, + ToggleableHudElement, + OnlyHideWhenTogglingHud, SceneBundle { scene: asset_server.load(world::asset_name_to_path("selectagon")), + visibility: Visibility::Hidden, ..default() }, )); @@ -593,7 +597,7 @@ fn handle_input( keyboard_input: Res>, mouse_input: Res>, mut settings: ResMut, - mut q_hud: Query<&mut Visibility, With>, + mut q_hud: Query<(&mut Visibility, Option<&OnlyHideWhenTogglingHud>), With>, mut ew_sfx: EventWriter, mut ew_togglemusic: EventWriter, mut ew_target: EventWriter, @@ -603,15 +607,17 @@ fn handle_input( ) { if keyboard_input.just_pressed(settings.key_togglehud) { if settings.hud_active { - for mut hudelement_visibility in q_hud.iter_mut() { + for (mut hudelement_visibility, _) in q_hud.iter_mut() { *hudelement_visibility = Visibility::Hidden; } settings.hud_active = false; ambient_light.brightness = AMBIENT_LIGHT; } else { - for mut hudelement_visibility in q_hud.iter_mut() { - *hudelement_visibility = Visibility::Inherited; + for (mut hudelement_visibility, only_hide) in q_hud.iter_mut() { + if only_hide.is_none() { + *hudelement_visibility = Visibility::Inherited; + } } settings.hud_active = true; ambient_light.brightness = AMBIENT_LIGHT_AR; @@ -619,7 +625,7 @@ fn handle_input( ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch)); ew_togglemusic.send(audio::ToggleMusicEvent()); } - if mouse_input.just_pressed(settings.key_selectobject) { + if settings.hud_active && mouse_input.just_pressed(settings.key_selectobject) { if let Ok(camtrans) = q_camera.get_single() { let objects: Vec<(Entity, &Transform)> = q_objects.iter().collect(); if let (Some(new_target), _dist) = camera::find_closest_target::(objects, camtrans) { @@ -658,11 +664,12 @@ fn handle_target_event( } fn update_target_selectagon( + settings: Res, mut q_selectagon: Query<(&mut Transform, &mut Visibility), (With, Without, Without)>, q_target: Query<&Transform, (With, Without, Without)>, q_camera: Query<&Transform, (With, Without, Without)>, ) { - if q_camera.is_empty() { + if !settings.hud_active || q_camera.is_empty() { return; } let camera_trans = q_camera.get_single().unwrap();