From b0400b1ea5c243d5c17dab2d788c8226abea4d29 Mon Sep 17 00:00:00 2001 From: yuni <hut@hut.pm> Date: Sat, 30 Nov 2024 03:01:25 +0100 Subject: [PATCH] allow clicking only on visible actors --- src/common.rs | 8 ++++++++ src/hud.rs | 8 +++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/common.rs b/src/common.rs index ade281a..83724df 100644 --- a/src/common.rs +++ b/src/common.rs @@ -42,6 +42,14 @@ pub fn bool2vis(boolean: bool) -> Visibility { } } +#[inline] +pub fn vis2bool(vis: Visibility) -> bool { + match vis { + Visibility::Hidden => false, + _ => true, + } +} + #[inline] pub fn style_fullscreen() -> Style { Style { diff --git a/src/hud.rs b/src/hud.rs index 3f7e586..99ab194 100644 --- a/src/hud.rs +++ b/src/hud.rs @@ -1227,7 +1227,7 @@ fn handle_input( mut ew_target: EventWriter<TargetEvent>, mut ew_game: EventWriter<GameEvent>, q_objects: Query< - (Entity, &Transform, &IsClickable), + (Entity, &Transform, &Visibility, &IsClickable), ( With<IsClickable>, Without<IsTargeted>, @@ -1245,8 +1245,10 @@ fn handle_input( if let Ok(camtrans) = q_camera.get_single() { let objects: Vec<(Entity, &Transform)> = q_objects .iter() - .filter(|(_, _, clickable)| !settings.map_active || !clickable.disable_in_map) - .map(|(entity, trans, _)| (entity, trans)) + .filter(|(_, _, vis, clickable)| { + vis2bool(**vis) && (!settings.map_active || !clickable.disable_in_map) + }) + .map(|(entity, trans, _, _)| (entity, trans)) .collect(); if let (Some(new_target), _dist) = camera::find_closest_target::<Entity>(objects, camtrans)