diff --git a/editor/src/objects.rs b/editor/src/objects.rs index f239ba2927..a70badd570 100644 --- a/editor/src/objects.rs +++ b/editor/src/objects.rs @@ -26,6 +26,13 @@ pub enum ID { } impl ID { + pub fn from_agent(id: AgentID) -> ID { + match id { + AgentID::Car(id) => ID::Car(id), + AgentID::Pedestrian(id) => ID::Pedestrian(id), + } + } + pub fn agent_id(&self) -> Option { match *self { ID::Car(id) => Some(AgentID::Car(id)), diff --git a/editor/src/plugins/view/show_route.rs b/editor/src/plugins/view/show_route.rs index 1f9763bdda..37949d3ca3 100644 --- a/editor/src/plugins/view/show_route.rs +++ b/editor/src/plugins/view/show_route.rs @@ -1,12 +1,13 @@ -use crate::objects::DrawCtx; +use crate::objects::{DrawCtx, ID}; use crate::plugins::{AmbientPlugin, PluginCtx}; use ezgui::{Color, GfxCtx, Key}; use geom::{Duration, PolyLine}; use map_model::LANE_THICKNESS; -use sim::TripID; +use sim::{AgentID, TripID}; pub enum ShowRouteState { Inactive, + Hovering(Duration, AgentID, PolyLine), Active(Duration, TripID, Option), DebugAllRoutes(Duration, Vec), } @@ -28,10 +29,35 @@ impl AmbientPlugin for ShowRouteState { .contextual_action(Key::R, &format!("show {}'s route", agent)) { *self = show_route(trip, ctx); + return; } } + + if let Some(trace) = ctx.primary.sim.trace_route(agent, &ctx.primary.map, None) + { + *self = ShowRouteState::Hovering(ctx.primary.sim.time(), agent, trace); + } }; } + ShowRouteState::Hovering(time, agent, _) => { + if *time != ctx.primary.sim.time() + || ctx.primary.current_selection != Some(ID::from_agent(*agent)) + { + *self = ShowRouteState::Inactive; + if let Some(new_agent) = + ctx.primary.current_selection.and_then(|id| id.agent_id()) + { + if let Some(trace) = + ctx.primary + .sim + .trace_route(new_agent, &ctx.primary.map, None) + { + *self = + ShowRouteState::Hovering(ctx.primary.sim.time(), new_agent, trace); + } + } + } + } ShowRouteState::Active(time, trip, _) => { ctx.input.set_mode_with_prompt( "Agent Route Debugger", @@ -63,6 +89,12 @@ impl AmbientPlugin for ShowRouteState { fn draw(&self, g: &mut GfxCtx, ctx: &DrawCtx) { match self { + ShowRouteState::Hovering(_, _, ref trace) => { + g.draw_polygon( + ctx.cs.get("route").alpha(0.5), + &trace.make_polygons(LANE_THICKNESS), + ); + } ShowRouteState::Active(_, _, Some(ref trace)) => { g.draw_polygon( ctx.cs.get_def("route", Color::RED.alpha(0.8)),