Skip to content

Commit

Permalink
Fix route node visibility to respect route visibilty
Browse files Browse the repository at this point in the history
Will now hide node labels if route is hidden
  • Loading branch information
Froggy618157725 committed Jul 27, 2024
1 parent 5a8f5f5 commit f207247
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
16 changes: 14 additions & 2 deletions crates/alkahest-renderer/src/ecs/utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>,
) {
let hide_all = hidden.unwrap_or(match scene.entity(entity) {
Ok(e) => e.has::<Hidden>(),
Err(_) => false,
});
let mut prev_visible = false;
if let Ok(children) = scene.get::<&Children>(entity) {
for (i, child_ent) in children.0.iter().enumerate() {
Expand All @@ -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::<Hidden>() {
cmd.remove_one::<Hidden>(e.entity());
}
Expand Down
5 changes: 5 additions & 0 deletions crates/alkahest/src/gui/inspector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ pub fn show_inspector_panel(
} else {
cmd.remove_one::<Hidden>(ent);
}
if e.has::<Route>() {
if let Some(route) = e.get::<&Route>() {
route.fixup_visiblity(scene, cmd, ent, Some(visible));
}
}
}

let title = if let Some(label) = e.get::<&Label>() {
Expand Down
2 changes: 1 addition & 1 deletion crates/alkahest/src/gui/inspector/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion crates/alkahest/src/maplist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/alkahest/src/util/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl Action for SpawnRouteAction {
);
resources.get_mut::<SelectedEntity>().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);
}
}
}
Expand Down

0 comments on commit f207247

Please sign in to comment.