mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-29 01:13:53 +03:00
kind of messy impl for showing a route just by hovering
This commit is contained in:
parent
834384fb10
commit
49ec5a312e
@ -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<AgentID> {
|
||||
match *self {
|
||||
ID::Car(id) => Some(AgentID::Car(id)),
|
||||
|
@ -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<PolyLine>),
|
||||
DebugAllRoutes(Duration, Vec<PolyLine>),
|
||||
}
|
||||
@ -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)),
|
||||
|
Loading…
Reference in New Issue
Block a user