From 8f285be4febcd896127dbd383656c972c9bdcb64 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Fri, 13 Mar 2020 18:41:49 -0700 Subject: [PATCH] jump from agent or trip to person, and from person to building and trips --- game/src/common/info.rs | 115 +++++++++++++++++++++++++++++++++++++--- sim/src/lib.rs | 2 +- sim/src/sim.rs | 14 ++++- sim/src/trips.rs | 8 +++ 4 files changed, 130 insertions(+), 9 deletions(-) diff --git a/game/src/common/info.rs b/game/src/common/info.rs index 3b18463915..f032c47ced 100644 --- a/game/src/common/info.rs +++ b/game/src/common/info.rs @@ -13,10 +13,10 @@ use ezgui::{ VerticalAlignment, }; use geom::{Angle, Circle, Distance, Duration, Polygon, Pt2D, Statistic, Time}; -use map_model::{IntersectionID, IntersectionType}; +use map_model::{BuildingID, IntersectionID, IntersectionType}; use sim::{ - AgentID, Analytics, CarID, PersonID, TripEnd, TripID, TripMode, TripPhaseType, TripResult, - TripStart, VehicleType, + AgentID, Analytics, CarID, PersonID, PersonState, TripEnd, TripID, TripMode, TripPhaseType, + TripResult, TripStart, VehicleType, }; use std::collections::{BTreeMap, BTreeSet, HashMap}; @@ -307,7 +307,7 @@ impl InfoPanel { } else if action == "follow agent" { maybe_speed.unwrap().resume_realtime(ctx); (false, None) - } else if action == "examine trip phase" { + } else if let Some(_) = strip_prefix_usize(&action, "examine trip phase ") { // Don't do anything! Just using buttons for convenient tooltips. (false, None) } else if let Some(id) = self @@ -334,6 +334,19 @@ impl InfoPanel { maybe_speed, ); return (false, None); + } else if let Some(idx) = strip_prefix_usize(&action, "examine Trip #") { + *self = + InfoPanel::new(ID::Trip(TripID(idx)), ctx, app, Vec::new(), maybe_speed); + return (false, None); + } else if let Some(idx) = strip_prefix_usize(&action, "examine Building #") { + *self = InfoPanel::new( + ID::Building(BuildingID(idx)), + ctx, + app, + Vec::new(), + maybe_speed, + ); + return (false, None); } else { app.primary.current_selection = Some(self.id.clone()); (true, Some(Transition::ApplyObjectAction(action))) @@ -827,7 +840,75 @@ fn info_for( } rows.extend(action_btns); - // TODO Info about their schedule, current status + let person = app.primary.sim.get_person(id); + + // TODO Point out where the person is now, relative to schedule... + rows.push(match person.state { + PersonState::Inside(b) => ManagedWidget::btn(Button::text_bg( + Text::from(Line(format!( + "Currently inside {}", + map.get_b(b).just_address(map) + ))), + colors::SECTION_BG, + colors::HOVERING, + None, + // TODO not the best tooltip, but easy to parse :( + &format!("examine Building #{}", b.0), + ctx, + )), + PersonState::Trip(t) => ManagedWidget::draw_text( + ctx, + Text::from(Line(format!("Currently doing Trip #{}", t.0))), + ), + PersonState::OffMap => ManagedWidget::draw_text( + ctx, + Text::from(Line("Currently outside the map boundaries")), + ), + PersonState::Limbo => ManagedWidget::draw_text( + ctx, + Text::from(Line( + "Currently in limbo -- they broke out of the Matrix! Woops. (A bug \ + occurred)", + )), + ), + }); + + rows.push(ManagedWidget::draw_text( + ctx, + Text::from(Line("Schedule").roboto_bold()), + )); + for t in &person.trips { + // TODO Still maybe unsafe? Check if trip has actually started or not + // TODO Say where the trip goes, no matter what? + let start_time = app.primary.sim.trip_start_time(*t); + if app.primary.sim.time() < start_time { + rows.push(ManagedWidget::draw_text( + ctx, + Text::from(Line(format!( + "{}: Trip #{} will start", + start_time.ampm_tostring(), + t.0 + ))), + )); + } else { + rows.push(ManagedWidget::row(vec![ + ManagedWidget::draw_text( + ctx, + Text::from(Line(format!("{}: ", start_time.ampm_tostring(),))), + ), + ManagedWidget::btn(Button::text_bg( + Text::from(Line(format!("Trip #{}", t.0))), + colors::SECTION_BG, + colors::HOVERING, + None, + &format!("examine Trip #{}", t.0), + ctx, + )) + .margin(5), + ])); + } + } + // TODO All the colorful side info } }; @@ -1170,8 +1251,15 @@ fn trip_details( timeline.push( ManagedWidget::btn( - Button::new(ctx, normal, hovered, None, "examine trip phase", rect) - .change_tooltip(txt), + Button::new( + ctx, + normal, + hovered, + None, + &format!("examine trip phase {}", idx + 1), + rect, + ) + .change_tooltip(txt), ) .centered_vert(), ); @@ -1207,6 +1295,19 @@ fn trip_details( .evenly_spaced() .margin_above(25)]; col.extend(make_table(ctx, table)); + if let Some(p) = app.primary.sim.trip_to_person(trip) { + col.push( + ManagedWidget::btn(Button::text_bg( + Text::from(Line(format!("Trip by Person #{}", p.0))), + colors::SECTION_BG, + colors::HOVERING, + None, + &format!("examine Person #{}", p.0), + ctx, + )) + .margin(5), + ); + } ( ManagedWidget::col(col), diff --git a/sim/src/lib.rs b/sim/src/lib.rs index b1c46715c5..d250de0dfd 100644 --- a/sim/src/lib.rs +++ b/sim/src/lib.rs @@ -22,7 +22,7 @@ pub(crate) use self::router::{ActionAtEnd, Router}; pub(crate) use self::scheduler::{Command, Scheduler}; pub use self::sim::{Sim, SimOptions}; pub(crate) use self::transit::TransitSimState; -pub use self::trips::{PersonState, TripCount, TripResult}; +pub use self::trips::{Person, PersonState, TripCount, TripResult}; pub use self::trips::{TripEnd, TripMode, TripStart}; pub(crate) use self::trips::{TripLeg, TripManager}; pub use crate::render::{ diff --git a/sim/src/sim.rs b/sim/src/sim.rs index 67acad365d..d885f0baf1 100644 --- a/sim/src/sim.rs +++ b/sim/src/sim.rs @@ -1,7 +1,7 @@ use crate::{ AgentID, AgentMetadata, Analytics, CarID, Command, CreateCar, DrawCarInput, DrawPedCrowdInput, DrawPedestrianInput, DrivingGoal, DrivingSimState, Event, GetDrawAgents, IntersectionSimState, - ParkedCar, ParkingSimState, ParkingSpot, PedestrianID, PersonID, PersonState, Router, + ParkedCar, ParkingSimState, ParkingSpot, PedestrianID, Person, PersonID, PersonState, Router, Scheduler, SidewalkPOI, SidewalkSpot, TransitSimState, TripCount, TripEnd, TripID, TripLeg, TripManager, TripMode, TripPhaseType, TripPositions, TripResult, TripSpawner, TripSpec, TripStart, UnzoomedAgent, VehicleSpec, VehicleType, WalkingSimState, BUS_LENGTH, @@ -966,6 +966,18 @@ impl Sim { self.trips.trip_endpoints(id) } + pub fn trip_to_person(&self, id: TripID) -> Option { + self.trips.trip_to_person(id) + } + + pub fn get_person(&self, id: PersonID) -> &Person { + self.trips.get_person(id) + } + + pub fn trip_start_time(&self, id: TripID) -> Time { + self.trips.trip_start_time(id) + } + pub fn lookup_car_id(&self, idx: usize) -> Option { for vt in &[VehicleType::Car, VehicleType::Bike, VehicleType::Bus] { let id = CarID(idx, *vt); diff --git a/sim/src/trips.rs b/sim/src/trips.rs index 3e349d1a35..3656b13960 100644 --- a/sim/src/trips.rs +++ b/sim/src/trips.rs @@ -660,6 +660,14 @@ impl TripManager { pub fn get_person(&self, p: PersonID) -> &Person { &self.people[p.0] } + + pub fn trip_to_person(&self, id: TripID) -> Option { + self.trips[id.0].person + } + + pub fn trip_start_time(&self, id: TripID) -> Time { + self.trips[id.0].spawned_at + } } #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]