greying out choices in scoreboard that have no trips

This commit is contained in:
Dustin Carlino 2019-09-11 12:51:07 -07:00
parent c8e3e9ce4b
commit 97361317ed
4 changed files with 31 additions and 12 deletions

View File

@ -28,6 +28,7 @@ pub struct Menu<T: Clone> {
icon_selected: bool,
}
// TODO Maybe reuse the public Choice from wizard
struct Choice<T: Clone> {
hotkey: Option<MultiKey>,
label: String,

View File

@ -409,9 +409,8 @@ impl<T: Clone> Choice<T> {
self
}
pub fn inactive(mut self) -> Choice<T> {
assert!(self.active);
self.active = false;
pub fn active(mut self, active: bool) -> Choice<T> {
self.active = active;
self
}
}

View File

@ -9,7 +9,7 @@ use ezgui::{
use geom::Duration;
use itertools::Itertools;
use sim::{FinishedTrips, TripID, TripMode};
use std::collections::BTreeMap;
use std::collections::{BTreeMap, BTreeSet};
pub struct Scoreboard {
menu: ModalMenu,
@ -119,11 +119,22 @@ fn browse_trips(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Tra
let mut wizard = wiz.wrap(ctx);
let mode = wizard
.choose("Browse which trips?", || {
let trips = CompareTrips::new(
ui.primary.sim.get_finished_trips(),
ui.secondary.as_ref().unwrap().sim.get_finished_trips(),
);
let modes = trips
.finished_trips
.iter()
.map(|(_, m, _, _)| *m)
.collect::<BTreeSet<TripMode>>();
vec![
Choice::new("walk", TripMode::Walk),
Choice::new("bike", TripMode::Bike),
Choice::new("transit", TripMode::Transit),
Choice::new("drive", TripMode::Drive),
Choice::new("walk", TripMode::Walk).active(modes.contains(&TripMode::Walk)),
Choice::new("bike", TripMode::Bike).active(modes.contains(&TripMode::Bike)),
Choice::new("transit", TripMode::Transit)
.active(modes.contains(&TripMode::Transit)),
Choice::new("drive", TripMode::Drive).active(modes.contains(&TripMode::Drive)),
]
})?
.1;

View File

@ -8,6 +8,7 @@ use ezgui::{
use geom::{Duration, DurationHistogram};
use itertools::Itertools;
use sim::{TripID, TripMode};
use std::collections::BTreeSet;
pub struct Scoreboard {
menu: ModalMenu,
@ -74,11 +75,18 @@ impl State for Scoreboard {
fn browse_trips(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Transition> {
let mut wizard = wiz.wrap(ctx);
let (_, mode) = wizard.choose("Browse which trips?", || {
let trips = ui.primary.sim.get_finished_trips();
let modes = trips
.finished_trips
.iter()
.map(|(_, m, _)| *m)
.collect::<BTreeSet<TripMode>>();
vec![
Choice::new("walk", TripMode::Walk),
Choice::new("bike", TripMode::Bike),
Choice::new("transit", TripMode::Transit),
Choice::new("drive", TripMode::Drive),
Choice::new("walk", TripMode::Walk).active(modes.contains(&TripMode::Walk)),
Choice::new("bike", TripMode::Bike).active(modes.contains(&TripMode::Bike)),
Choice::new("transit", TripMode::Transit).active(modes.contains(&TripMode::Transit)),
Choice::new("drive", TripMode::Drive).active(modes.contains(&TripMode::Drive)),
]
})?;
wizard.choose("Examine which trip?", || {