fix route viewer when skipping fwd in time
@@ -12,9 +12,7 @@ pub enum RouteViewer {
}
impl RouteViewer {
- pub fn event(&mut self, ctx: &mut EventCtx, ui: &UI, menu: &mut ModalMenu) {
- match self {
- RouteViewer::Inactive => {
+ fn recalc(ui: &UI) -> RouteViewer {
if let Some(agent) = ui
.primary
.current_selection
@@ -22,36 +20,27 @@ impl RouteViewer {
.and_then(|id| id.agent_id())
{
if let Some(trace) = ui.primary.sim.trace_route(agent, &ui.primary.map, None) {
- *self = RouteViewer::Hovering(ui.primary.sim.time(), agent, trace);
+ return RouteViewer::Hovering(ui.primary.sim.time(), agent, trace);
}
}
+ RouteViewer::Inactive
}
- RouteViewer::Hovering(time, agent, _) => {
- // Argh, borrow checker.
- let mut agent = *agent;
+ pub fn event(&mut self, ctx: &mut EventCtx, ui: &UI, menu: &mut ModalMenu) {
+ match self {
+ RouteViewer::Inactive => {
+ *self = RouteViewer::recalc(ui);
+ }
+ RouteViewer::Hovering(time, agent, _) => {
if *time != ui.primary.sim.time()
- || ui.primary.current_selection != Some(ID::from_agent(agent))
+ || ui.primary.current_selection != Some(ID::from_agent(*agent))
{
- *self = RouteViewer::Inactive;
- if let Some(new_agent) = ui
- .primary
- .current_selection
- .as_ref()
- .and_then(|id| id.agent_id())
- {
- // Gross.
- agent = new_agent;
- if let Some(trace) =
- ui.primary.sim.trace_route(new_agent, &ui.primary.map, None)
- {
- *self = RouteViewer::Hovering(ui.primary.sim.time(), new_agent, trace);
- }
- }
+ *self = RouteViewer::recalc(ui);
}
+ if let RouteViewer::Hovering(_, agent, _) = self {
// If there's a current route, then there must be a trip.
- let trip = ui.primary.sim.agent_to_trip(agent).unwrap();
+ let trip = ui.primary.sim.agent_to_trip(*agent).unwrap();
if ctx
.input
.contextual_action(Key::R, format!("show {}'s route", agent))
@@ -59,6 +48,7 @@ impl RouteViewer {
*self = show_route(trip, ui);
}
}
+ }
RouteViewer::Active(time, trip, _) => {
// TODO Using the modal menu from parent is weird...
if menu.action("stop showing agent's route") {
