mirror of https://codeberg.org/topola/topola.git
egui: add button to toggle showing navmesh
This commit is contained in:
parent
5161eecd49
commit
169ddf7d80
|
|
@ -16,6 +16,7 @@ use crate::{
|
|||
pub struct Top {
|
||||
pub is_placing_via: bool,
|
||||
pub show_ratsnest: bool,
|
||||
pub show_navmesh: bool,
|
||||
}
|
||||
|
||||
impl Top {
|
||||
|
|
@ -23,6 +24,7 @@ impl Top {
|
|||
Self {
|
||||
is_placing_via: false,
|
||||
show_ratsnest: false,
|
||||
show_navmesh: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -171,6 +173,7 @@ impl Top {
|
|||
ui.separator();
|
||||
|
||||
ui.toggle_value(&mut self.show_ratsnest, "Show Ratsnest");
|
||||
ui.toggle_value(&mut self.show_navmesh, "Show Navmesh");
|
||||
|
||||
ui.separator();
|
||||
|
||||
|
|
|
|||
|
|
@ -167,42 +167,44 @@ impl Viewport {
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(navmesh) = &shared_data.navmesh {
|
||||
for edge in navmesh.graph().edge_references() {
|
||||
let from = PrimitiveIndex::from(navmesh.graph().node_weight(edge.source()).unwrap().node)
|
||||
.primitive(board.layout().drawing())
|
||||
.shape()
|
||||
.center();
|
||||
let to = PrimitiveIndex::from(navmesh.graph().node_weight(edge.target()).unwrap().node)
|
||||
.primitive(board.layout().drawing())
|
||||
.shape()
|
||||
.center();
|
||||
if top.show_navmesh {
|
||||
if let Some(navmesh) = &shared_data.navmesh {
|
||||
for edge in navmesh.graph().edge_references() {
|
||||
let from = PrimitiveIndex::from(navmesh.graph().node_weight(edge.source()).unwrap().node)
|
||||
.primitive(board.layout().drawing())
|
||||
.shape()
|
||||
.center();
|
||||
let to = PrimitiveIndex::from(navmesh.graph().node_weight(edge.target()).unwrap().node)
|
||||
.primitive(board.layout().drawing())
|
||||
.shape()
|
||||
.center();
|
||||
|
||||
let stroke = 'blk: {
|
||||
if let (Some(source_pos), Some(target_pos)) = (
|
||||
shared_data
|
||||
.path
|
||||
.iter()
|
||||
.position(|node| *node == navmesh.graph().node_weight(edge.source()).unwrap().node),
|
||||
shared_data
|
||||
.path
|
||||
.iter()
|
||||
.position(|node| *node == navmesh.graph().node_weight(edge.target()).unwrap().node),
|
||||
) {
|
||||
if target_pos == source_pos + 1
|
||||
|| source_pos == target_pos + 1
|
||||
{
|
||||
break 'blk egui::Stroke::new(
|
||||
5.0,
|
||||
egui::Color32::from_rgb(250, 250, 0),
|
||||
);
|
||||
let stroke = 'blk: {
|
||||
if let (Some(source_pos), Some(target_pos)) = (
|
||||
shared_data
|
||||
.path
|
||||
.iter()
|
||||
.position(|node| *node == navmesh.graph().node_weight(edge.source()).unwrap().node),
|
||||
shared_data
|
||||
.path
|
||||
.iter()
|
||||
.position(|node| *node == navmesh.graph().node_weight(edge.target()).unwrap().node),
|
||||
) {
|
||||
if target_pos == source_pos + 1
|
||||
|| source_pos == target_pos + 1
|
||||
{
|
||||
break 'blk egui::Stroke::new(
|
||||
5.0,
|
||||
egui::Color32::from_rgb(250, 250, 0),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
egui::Stroke::new(1.0, egui::Color32::from_rgb(125, 125, 125))
|
||||
};
|
||||
egui::Stroke::new(1.0, egui::Color32::from_rgb(125, 125, 125))
|
||||
};
|
||||
|
||||
painter.paint_edge(from, to, stroke);
|
||||
painter.paint_edge(from, to, stroke);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -156,11 +156,6 @@ impl Navmesh {
|
|||
}
|
||||
|
||||
map.insert(trianvertex, navvertex);
|
||||
|
||||
/*// TODO: iterate over triangulation's edges instead of vertices.
|
||||
for edge in triangulation.edges(trianvertex) {
|
||||
graph.add_edge(edge.source(), edge.target(), &edge.weight());
|
||||
}*/
|
||||
}
|
||||
|
||||
for edge in triangulation.edge_references() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue