From 6f20994dababae1febd10522b5a676093dda93f0 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Wed, 18 Jun 2025 18:07:43 +0200 Subject: [PATCH] feat(topola-egui): Add checkbox to hide pathfinding scores --- crates/topola-egui/src/actions.rs | 7 +++++ crates/topola-egui/src/menu_bar.rs | 2 ++ crates/topola-egui/src/viewport.rs | 46 +++++++++++++++++------------- locales/en-US/main.ftl | 1 + 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/crates/topola-egui/src/actions.rs b/crates/topola-egui/src/actions.rs index a25cd1c..3fa88e5 100644 --- a/crates/topola-egui/src/actions.rs +++ b/crates/topola-egui/src/actions.rs @@ -166,6 +166,7 @@ pub struct ViewActions { pub zoom_to_fit: Switch, pub show_ratsnest: Switch, pub show_navmesh: Switch, + pub show_pathfinding_scores: Switch, pub show_topo_navmesh: Switch, pub show_bboxes: Switch, pub show_origin_destination: Switch, @@ -178,6 +179,10 @@ impl ViewActions { zoom_to_fit: Action::new_keyless(tr.text("tr-menu-view-zoom-to-fit")).into_switch(), show_ratsnest: Action::new_keyless(tr.text("tr-menu-view-show-ratsnest")).into_switch(), show_navmesh: Action::new_keyless(tr.text("tr-menu-view-show-navmesh")).into_switch(), + show_pathfinding_scores: Action::new_keyless( + tr.text("tr-menu-view-show-pathfinding-scores"), + ) + .into_switch(), show_topo_navmesh: Action::new_keyless(tr.text("tr-menu-view-show-topo-navmesh")) .into_switch(), show_bboxes: Action::new_keyless(tr.text("tr-menu-view-show-bboxes")).into_switch(), @@ -206,6 +211,8 @@ impl ViewActions { ui.add_enabled_ui(have_workspace, |ui| { self.show_ratsnest.checkbox(ui, &mut menu_bar.show_ratsnest); self.show_navmesh.checkbox(ui, &mut menu_bar.show_navmesh); + self.show_pathfinding_scores + .checkbox(ui, &mut menu_bar.show_pathfinding_scores); self.show_topo_navmesh .checkbox(ui, &mut menu_bar.show_topo_navmesh); self.show_bboxes.checkbox(ui, &mut menu_bar.show_bboxes); diff --git a/crates/topola-egui/src/menu_bar.rs b/crates/topola-egui/src/menu_bar.rs index 93f21ac..225725d 100644 --- a/crates/topola-egui/src/menu_bar.rs +++ b/crates/topola-egui/src/menu_bar.rs @@ -26,6 +26,7 @@ pub struct MenuBar { pub is_placing_via: bool, pub show_ratsnest: bool, pub show_navmesh: bool, + pub show_pathfinding_scores: bool, pub show_topo_navmesh: bool, pub show_bboxes: bool, pub show_origin_destination: bool, @@ -47,6 +48,7 @@ impl MenuBar { is_placing_via: false, show_ratsnest: true, show_navmesh: false, + show_pathfinding_scores: false, show_topo_navmesh: false, show_bboxes: false, show_origin_destination: false, diff --git a/crates/topola-egui/src/viewport.rs b/crates/topola-egui/src/viewport.rs index a4ee563..2c06b8a 100644 --- a/crates/topola-egui/src/viewport.rs +++ b/crates/topola-egui/src/viewport.rs @@ -354,27 +354,33 @@ impl Viewport { None => [0.0, 0.0].into(), }; - //TODO "{astar.scores[index]} ({astar.estimate_scores[index]}) (...)" - let score_text = astar - .scores() - .get(&navnode) - .map_or_else(String::new, |s| format!("g={:.2}", s)); - let estimate_score_text = astar - .estimate_scores() - .get(&navnode) - .map_or_else(String::new, |s| format!("(f={:.2})", s)); - let debug_text = - activity.navnode_debug_text(navnode).unwrap_or(""); + if menu_bar.show_pathfinding_scores { + //TODO "{astar.scores[index]} ({astar.estimate_scores[index]}) (...)" + let score_text = astar + .scores() + .get(&navnode) + .map_or_else(String::new, |s| { + format!("g={:.2}", s) + }); + let estimate_score_text = astar + .estimate_scores() + .get(&navnode) + .map_or_else(String::new, |s| { + format!("(f={:.2})", s) + }); + let debug_text = + activity.navnode_debug_text(navnode).unwrap_or(""); - painter.paint_text( - pos, - egui::Align2::LEFT_BOTTOM, - &format!( - "{} {} {}", - score_text, estimate_score_text, debug_text - ), - egui::Color32::from_rgb(255, 255, 255), - ); + painter.paint_text( + pos, + egui::Align2::LEFT_BOTTOM, + &format!( + "{} {} {}", + score_text, estimate_score_text, debug_text + ), + egui::Color32::from_rgb(255, 255, 255), + ); + } } } } diff --git a/locales/en-US/main.ftl b/locales/en-US/main.ftl index 8018d57..338ee62 100644 --- a/locales/en-US/main.ftl +++ b/locales/en-US/main.ftl @@ -22,6 +22,7 @@ tr-menu-view = View tr-menu-view-zoom-to-fit = Zoom to Fit tr-menu-view-show-ratsnest = Show Ratsnest tr-menu-view-show-navmesh = Show Navmesh +tr-menu-view-show-pathfinding-scores = Show Pathfinding Scores tr-menu-view-show-topo-navmesh = Show Topological Navmesh tr-menu-view-show-bboxes = Show BBoxes tr-menu-view-show-origin-destination = Show Origin–Destination