From f20724718446d0ffbc5937b5c43caf736fe3adb6 Mon Sep 17 00:00:00 2001 From: Froggy618157725 Date: Sat, 27 Jul 2024 05:20:42 -0700 Subject: [PATCH] Fix route node visibility to respect route visibilty Will now hide node labels if route is hidden --- crates/alkahest-renderer/src/ecs/utility.rs | 16 ++++++++++++++-- crates/alkahest/src/gui/inspector/mod.rs | 5 +++++ crates/alkahest/src/gui/inspector/util.rs | 2 +- crates/alkahest/src/maplist.rs | 2 +- crates/alkahest/src/util/action.rs | 2 +- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/crates/alkahest-renderer/src/ecs/utility.rs b/crates/alkahest-renderer/src/ecs/utility.rs index 3acaf99..0ba3516 100644 --- a/crates/alkahest-renderer/src/ecs/utility.rs +++ b/crates/alkahest-renderer/src/ecs/utility.rs @@ -250,7 +250,17 @@ impl Route { command } - pub fn fixup_visiblity(&self, scene: &Scene, cmd: &mut hecs::CommandBuffer, entity: Entity) { + pub fn fixup_visiblity( + &self, + scene: &Scene, + cmd: &mut hecs::CommandBuffer, + entity: Entity, + hidden: Option, + ) { + let hide_all = hidden.unwrap_or(match scene.entity(entity) { + Ok(e) => e.has::(), + Err(_) => false, + }); let mut prev_visible = false; if let Ok(children) = scene.get::<&Children>(entity) { for (i, child_ent) in children.0.iter().enumerate() { @@ -268,7 +278,9 @@ impl Route { let Ok(e) = scene.entity(*child_ent) else { return; }; - if self.show_all || prev_visible || current_visible || next_visible { + if !hide_all + && (self.show_all || prev_visible || current_visible || next_visible) + { if e.has::() { cmd.remove_one::(e.entity()); } diff --git a/crates/alkahest/src/gui/inspector/mod.rs b/crates/alkahest/src/gui/inspector/mod.rs index cf9d3ec..faf3910 100644 --- a/crates/alkahest/src/gui/inspector/mod.rs +++ b/crates/alkahest/src/gui/inspector/mod.rs @@ -161,6 +161,11 @@ pub fn show_inspector_panel( } else { cmd.remove_one::(ent); } + if e.has::() { + if let Some(route) = e.get::<&Route>() { + route.fixup_visiblity(scene, cmd, ent, Some(visible)); + } + } } let title = if let Some(label) = e.get::<&Label>() { diff --git a/crates/alkahest/src/gui/inspector/util.rs b/crates/alkahest/src/gui/inspector/util.rs index a953c6b..f844c38 100644 --- a/crates/alkahest/src/gui/inspector/util.rs +++ b/crates/alkahest/src/gui/inspector/util.rs @@ -393,7 +393,7 @@ impl ComponentPanel for Route { let old_value = self.show_all; ui.checkbox(&mut self.show_all, "Show nodes in all maps"); if old_value != self.show_all { - self.fixup_visiblity(scene, cmd, e.entity()); + self.fixup_visiblity(scene, cmd, e.entity(), None); } ui.separator(); diff --git a/crates/alkahest/src/maplist.rs b/crates/alkahest/src/maplist.rs index 7a5cf65..1762980 100644 --- a/crates/alkahest/src/maplist.rs +++ b/crates/alkahest/src/maplist.rs @@ -146,7 +146,7 @@ impl Map { fn fixup_route_visibility(&mut self) { for (e, r) in self.scene.query::<&Route>().iter() { - r.fixup_visiblity(&self.scene, &mut self.command_buffer, e); + r.fixup_visiblity(&self.scene, &mut self.command_buffer, e, None); } } diff --git a/crates/alkahest/src/util/action.rs b/crates/alkahest/src/util/action.rs index 2a0e88c..9ad1fac 100644 --- a/crates/alkahest/src/util/action.rs +++ b/crates/alkahest/src/util/action.rs @@ -248,7 +248,7 @@ impl Action for SpawnRouteAction { ); resources.get_mut::().select(parent); if let Ok(route) = map.scene.get::<&Route>(parent) { - route.fixup_visiblity(&map.scene, &mut map.command_buffer, parent); + route.fixup_visiblity(&map.scene, &mut map.command_buffer, parent, None); } } }