allow clicking only on visible actors

This commit is contained in:
yuni 2024-11-30 03:01:25 +01:00
parent 67703072d7
commit b0400b1ea5
2 changed files with 13 additions and 3 deletions

View file

@ -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 {

View file

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