From d1127072613e9ff0960eb28adaff61f508eeeb86 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Tue, 18 Feb 2020 15:15:31 -0800 Subject: [PATCH] more info about trips to/from bldgs and intersections [rebuild] --- game/src/common/info.rs | 12 +-- game/src/sandbox/gameplay/freeform.rs | 7 +- sim/src/trips.rs | 103 +++++++++++++------------- 3 files changed, 62 insertions(+), 60 deletions(-) diff --git a/game/src/common/info.rs b/game/src/common/info.rs index c8c0913c22..94a1212246 100644 --- a/game/src/common/info.rs +++ b/game/src/common/info.rs @@ -396,10 +396,10 @@ fn info_for(id: ID, ctx: &EventCtx, ui: &UI) -> Vec { txt.add(Line(format!("- {}", r))); } - let cnt = sim.count_trips_involving_border(id); - if cnt.nonzero() { + let trip_lines = sim.count_trips_involving_border(id).describe(); + if !trip_lines.is_empty() { txt.add(Line("")); - for line in cnt.describe() { + for line in trip_lines { txt.add(Line(line)); } } @@ -477,10 +477,10 @@ fn info_for(id: ID, ctx: &EventCtx, ui: &UI) -> Vec { } let mut txt = Text::new(); - let cnt = sim.count_trips_involving_bldg(id); - if cnt.nonzero() { + let trip_lines = sim.count_trips_involving_bldg(id).describe(); + if !trip_lines.is_empty() { txt.add(Line("")); - for line in cnt.describe() { + for line in trip_lines { txt.add(Line(line)); } } diff --git a/game/src/sandbox/gameplay/freeform.rs b/game/src/sandbox/gameplay/freeform.rs index 8cfc4fc219..6634e59720 100644 --- a/game/src/sandbox/gameplay/freeform.rs +++ b/game/src/sandbox/gameplay/freeform.rs @@ -64,12 +64,13 @@ impl GameplayState for Freeform { if let Some(ID::Intersection(i)) = ui.primary.current_selection { if self.spawn_pts.contains(&i) { - let cnt = ui.primary.sim.count_trips_involving_border(i); 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)); } - g.draw_mouse_tooltip(txt); + if !txt.is_empty() { + g.draw_mouse_tooltip(txt); + } } } } diff --git a/sim/src/trips.rs b/sim/src/trips.rs index 864c9a6235..373fccd7ad 100644 --- a/sim/src/trips.rs +++ b/sim/src/trips.rs @@ -541,37 +541,37 @@ impl TripManager { } fn count_trips(&self, start: TripStart, end: TripEnd, now: Time) -> TripCount { let mut cnt = TripCount { - from_aborted: 0, - from_in_progress: 0, - from_completed: 0, - from_unstarted: 0, - to_aborted: 0, - to_in_progress: 0, - to_completed: 0, - to_unstarted: 0, + from_aborted: Vec::new(), + from_in_progress: Vec::new(), + from_completed: Vec::new(), + from_unstarted: Vec::new(), + to_aborted: Vec::new(), + to_in_progress: Vec::new(), + to_completed: Vec::new(), + to_unstarted: Vec::new(), }; for trip in &self.trips { if trip.start == start { if trip.aborted { - cnt.from_aborted += 1; + cnt.from_aborted.push(trip.id); } else if trip.finished_at.is_some() { - cnt.from_completed += 1; + cnt.from_completed.push(trip.id); } else if now >= trip.spawned_at { - cnt.from_in_progress += 1; + cnt.from_in_progress.push(trip.id); } else { - cnt.from_unstarted += 1; + cnt.from_unstarted.push(trip.id); } } // One trip might could towards both! if trip.end == end { if trip.aborted { - cnt.to_aborted += 1; + cnt.to_aborted.push(trip.id); } else if trip.finished_at.is_some() { - cnt.to_completed += 1; + cnt.to_completed.push(trip.id); } else if now >= trip.spawned_at { - cnt.to_in_progress += 1; + cnt.to_in_progress.push(trip.id); } else { - cnt.to_unstarted += 1; + cnt.to_unstarted.push(trip.id); } } } @@ -759,48 +759,49 @@ impl TripResult { } } +// TODO Misnomer now pub struct TripCount { - pub from_aborted: usize, - pub from_in_progress: usize, - pub from_completed: usize, - pub from_unstarted: usize, - pub to_aborted: usize, - pub to_in_progress: usize, - pub to_completed: usize, - pub to_unstarted: usize, + pub from_aborted: Vec, + pub from_in_progress: Vec, + pub from_completed: Vec, + pub from_unstarted: Vec, + pub to_aborted: Vec, + pub to_in_progress: Vec, + pub to_completed: Vec, + pub to_unstarted: Vec, } 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 { - vec![ - format!( - "Aborted trips: {} from here, {} to here", - self.from_aborted, self.to_aborted - ), - format!( + let mut lines = Vec::new(); + if !self.from_completed.is_empty() || !self.to_completed.is_empty() { + lines.push(format!( "Finished trips: {} from here, {} to here", - self.from_completed, self.to_completed - ), - format!( + self.from_completed.len(), + self.to_completed.len() + )); + } + if !self.from_in_progress.is_empty() || !self.to_in_progress.is_empty() { + lines.push(format!( "In-progress trips: {} from here, {} to here", - self.from_in_progress, self.to_in_progress - ), - format!( + self.from_in_progress.len(), + self.to_in_progress.len() + )); + } + if !self.from_unstarted.is_empty() || !self.to_unstarted.is_empty() { + lines.push(format!( "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 } }