more info about trips to/from bldgs and intersections [rebuild]

This commit is contained in:
Dustin Carlino 2020-02-18 15:15:31 -08:00
parent f71c1d521e
commit d112707261
3 changed files with 62 additions and 60 deletions

View File

@ -396,10 +396,10 @@ fn info_for(id: ID, ctx: &EventCtx, ui: &UI) -> Vec<ManagedWidget> {
txt.add(Line(format!("- {}", r))); txt.add(Line(format!("- {}", r)));
} }
let cnt = sim.count_trips_involving_border(id); let trip_lines = sim.count_trips_involving_border(id).describe();
if cnt.nonzero() { if !trip_lines.is_empty() {
txt.add(Line("")); txt.add(Line(""));
for line in cnt.describe() { for line in trip_lines {
txt.add(Line(line)); txt.add(Line(line));
} }
} }
@ -477,10 +477,10 @@ fn info_for(id: ID, ctx: &EventCtx, ui: &UI) -> Vec<ManagedWidget> {
} }
let mut txt = Text::new(); let mut txt = Text::new();
let cnt = sim.count_trips_involving_bldg(id); let trip_lines = sim.count_trips_involving_bldg(id).describe();
if cnt.nonzero() { if !trip_lines.is_empty() {
txt.add(Line("")); txt.add(Line(""));
for line in cnt.describe() { for line in trip_lines {
txt.add(Line(line)); txt.add(Line(line));
} }
} }

View File

@ -64,16 +64,17 @@ impl GameplayState for Freeform {
if let Some(ID::Intersection(i)) = ui.primary.current_selection { if let Some(ID::Intersection(i)) = ui.primary.current_selection {
if self.spawn_pts.contains(&i) { if self.spawn_pts.contains(&i) {
let cnt = ui.primary.sim.count_trips_involving_border(i);
let mut txt = Text::new().with_bg(); let mut txt = Text::new().with_bg();
for line in cnt.describe() { for line in ui.primary.sim.count_trips_involving_border(i).describe() {
txt.add(Line(line)); txt.add(Line(line));
} }
if !txt.is_empty() {
g.draw_mouse_tooltip(txt); g.draw_mouse_tooltip(txt);
} }
} }
} }
} }
}
pub fn freeform_controller( pub fn freeform_controller(
ctx: &mut EventCtx, ctx: &mut EventCtx,

View File

@ -541,37 +541,37 @@ impl TripManager {
} }
fn count_trips(&self, start: TripStart, end: TripEnd, now: Time) -> TripCount { fn count_trips(&self, start: TripStart, end: TripEnd, now: Time) -> TripCount {
let mut cnt = TripCount { let mut cnt = TripCount {
from_aborted: 0, from_aborted: Vec::new(),
from_in_progress: 0, from_in_progress: Vec::new(),
from_completed: 0, from_completed: Vec::new(),
from_unstarted: 0, from_unstarted: Vec::new(),
to_aborted: 0, to_aborted: Vec::new(),
to_in_progress: 0, to_in_progress: Vec::new(),
to_completed: 0, to_completed: Vec::new(),
to_unstarted: 0, to_unstarted: Vec::new(),
}; };
for trip in &self.trips { for trip in &self.trips {
if trip.start == start { if trip.start == start {
if trip.aborted { if trip.aborted {
cnt.from_aborted += 1; cnt.from_aborted.push(trip.id);
} else if trip.finished_at.is_some() { } else if trip.finished_at.is_some() {
cnt.from_completed += 1; cnt.from_completed.push(trip.id);
} else if now >= trip.spawned_at { } else if now >= trip.spawned_at {
cnt.from_in_progress += 1; cnt.from_in_progress.push(trip.id);
} else { } else {
cnt.from_unstarted += 1; cnt.from_unstarted.push(trip.id);
} }
} }
// One trip might could towards both! // One trip might could towards both!
if trip.end == end { if trip.end == end {
if trip.aborted { if trip.aborted {
cnt.to_aborted += 1; cnt.to_aborted.push(trip.id);
} else if trip.finished_at.is_some() { } else if trip.finished_at.is_some() {
cnt.to_completed += 1; cnt.to_completed.push(trip.id);
} else if now >= trip.spawned_at { } else if now >= trip.spawned_at {
cnt.to_in_progress += 1; cnt.to_in_progress.push(trip.id);
} else { } else {
cnt.to_unstarted += 1; cnt.to_unstarted.push(trip.id);
} }
} }
} }
@ -759,48 +759,49 @@ impl<T> TripResult<T> {
} }
} }
// TODO Misnomer now
pub struct TripCount { pub struct TripCount {
pub from_aborted: usize, pub from_aborted: Vec<TripID>,
pub from_in_progress: usize, pub from_in_progress: Vec<TripID>,
pub from_completed: usize, pub from_completed: Vec<TripID>,
pub from_unstarted: usize, pub from_unstarted: Vec<TripID>,
pub to_aborted: usize, pub to_aborted: Vec<TripID>,
pub to_in_progress: usize, pub to_in_progress: Vec<TripID>,
pub to_completed: usize, pub to_completed: Vec<TripID>,
pub to_unstarted: usize, pub to_unstarted: Vec<TripID>,
} }
impl TripCount { impl TripCount {
pub fn nonzero(&self) -> bool {
self.from_aborted
+ self.from_in_progress
+ self.from_completed
+ self.from_unstarted
+ self.to_aborted
+ self.to_in_progress
+ self.to_completed
+ self.to_unstarted
> 0
}
pub fn describe(&self) -> Vec<String> { pub fn describe(&self) -> Vec<String> {
vec![ let mut lines = Vec::new();
format!( if !self.from_completed.is_empty() || !self.to_completed.is_empty() {
"Aborted trips: {} from here, {} to here", lines.push(format!(
self.from_aborted, self.to_aborted
),
format!(
"Finished trips: {} from here, {} to here", "Finished trips: {} from here, {} to here",
self.from_completed, self.to_completed self.from_completed.len(),
), self.to_completed.len()
format!( ));
}
if !self.from_in_progress.is_empty() || !self.to_in_progress.is_empty() {
lines.push(format!(
"In-progress trips: {} from here, {} to here", "In-progress trips: {} from here, {} to here",
self.from_in_progress, self.to_in_progress self.from_in_progress.len(),
), self.to_in_progress.len()
format!( ));
}
if !self.from_unstarted.is_empty() || !self.to_unstarted.is_empty() {
lines.push(format!(
"Future trips: {} from here, {} to here", "Future trips: {} from here, {} to here",
self.from_unstarted, self.to_unstarted self.from_unstarted.len(),
), self.to_unstarted.len()
] ));
}
if !self.from_aborted.is_empty() || !self.to_aborted.is_empty() {
lines.push(format!(
"Aborted trips: {} from here, {} to here",
self.from_aborted.len(),
self.to_aborted.len()
));
}
lines
} }
} }