launch info panels more robustly for people

This commit is contained in:
Dustin Carlino 2020-04-08 17:56:36 -07:00
parent ef2a237c5d
commit 5ad78f62d3
6 changed files with 56 additions and 53 deletions

View File

@ -14,8 +14,8 @@ pub use self::warp::Warping;
use crate::app::App;
use crate::game::Transition;
use crate::helpers::{list_names, ID};
pub use crate::info::ContextualActions;
use crate::info::InfoPanel;
pub use crate::info::{ContextualActions, Tab};
use ezgui::{
hotkey, lctrl, Color, EventCtx, GeomBatch, GfxCtx, Key, Line, ScreenDims, ScreenPt,
ScreenRectangle, Text,
@ -55,7 +55,12 @@ impl CommonState {
if let Some(ref id) = app.primary.current_selection {
// TODO Also have a hotkey binding for this?
if app.per_obj.left_click(ctx, "show info") {
self.info_panel = Some(InfoPanel::launch(ctx, app, id.clone(), ctx_actions));
self.info_panel = Some(InfoPanel::new(
ctx,
app,
Tab::from_id(app, id.clone()),
ctx_actions,
));
return None;
}
}
@ -274,12 +279,12 @@ impl CommonState {
// Meant to be used for launching from other states
pub fn launch_info_panel(
&mut self,
id: ID,
ctx: &mut EventCtx,
app: &mut App,
tab: Tab,
ctx_actions: &mut dyn ContextualActions,
) {
self.info_panel = Some(InfoPanel::launch(ctx, app, id, ctx_actions));
self.info_panel = Some(InfoPanel::new(ctx, app, tab, ctx_actions));
}
pub fn info_panel_open(&self, app: &App) -> Option<ID> {

View File

@ -1,4 +1,5 @@
use crate::app::{App, PerMap};
use crate::common::Tab;
use crate::game::{State, Transition, WizardState};
use crate::helpers::ID;
use crate::sandbox::SandboxMode;
@ -65,9 +66,9 @@ impl State for Warping {
if let Some(ref mut s) = state.downcast_mut::<SandboxMode>() {
let mut actions = s.contextual_actions();
s.controls.common.as_mut().unwrap().launch_info_panel(
id,
ctx,
app,
Tab::from_id(app, id),
&mut actions,
);
}

View File

@ -72,7 +72,7 @@ pub enum Tab {
}
impl Tab {
fn from_id(app: &App, id: ID) -> Tab {
pub fn from_id(app: &App, id: ID) -> Tab {
match id {
ID::Road(_) => unreachable!(),
ID::Lane(l) => Tab::LaneInfo(l),
@ -162,16 +162,7 @@ pub struct Details {
}
impl InfoPanel {
pub fn launch(
ctx: &mut EventCtx,
app: &App,
id: ID,
ctx_actions: &mut dyn ContextualActions,
) -> InfoPanel {
InfoPanel::new(ctx, app, Tab::from_id(app, id), ctx_actions)
}
fn new(
pub fn new(
ctx: &mut EventCtx,
app: &App,
tab: Tab,
@ -409,20 +400,22 @@ impl InfoPanel {
time - Time::START_OF_DAY,
&mut timer,
);
if let Some(id) = app.primary.sim.trip_to_agent(trip).ok() {
let mut actions = new_mode.contextual_actions();
new_mode
.controls
.common
.as_mut()
.unwrap()
.launch_info_panel(
ID::from_agent(id),
ctx,
app,
&mut actions,
);
}
let mut actions = new_mode.contextual_actions();
new_mode
.controls
.common
.as_mut()
.unwrap()
.launch_info_panel(
ctx,
app,
Tab::PersonTrips(
app.primary.sim.trip_to_person(trip),
btreeset! { trip },
),
&mut actions,
);
Box::new(new_mode)
})
},

View File

@ -1,6 +1,6 @@
use crate::app::App;
use crate::common::Tab;
use crate::game::{msg, State, Transition};
use crate::helpers::ID;
use crate::helpers::{cmp_count_fewer, cmp_count_more, cmp_duration_shorter};
use crate::managed::{Callback, ManagedGUIState, WrappedComposite};
use crate::sandbox::SandboxMode;
@ -16,18 +16,18 @@ use sim::TripMode;
use std::collections::BTreeMap;
#[derive(PartialEq, Clone, Copy)]
pub enum Tab {
pub enum DashTab {
TripsSummary,
ParkingOverhead,
ExploreBusRoute,
}
// Oh the dashboards melted, but we still had the radio
pub fn make(ctx: &mut EventCtx, app: &App, tab: Tab) -> Box<dyn State> {
pub fn make(ctx: &mut EventCtx, app: &App, tab: DashTab) -> Box<dyn State> {
let tab_data = vec![
(Tab::TripsSummary, "Trips summary"),
(Tab::ParkingOverhead, "Parking overhead analysis"),
(Tab::ExploreBusRoute, "Explore a bus route"),
(DashTab::TripsSummary, "Trips summary"),
(DashTab::ParkingOverhead, "Parking overhead analysis"),
(DashTab::ExploreBusRoute, "Explore a bus route"),
];
let tabs = tab_data
@ -42,9 +42,9 @@ pub fn make(ctx: &mut EventCtx, app: &App, tab: Tab) -> Box<dyn State> {
.collect::<Vec<_>>();
let (content, cbs) = match tab {
Tab::TripsSummary => (trips_summary_prebaked(ctx, app), Vec::new()),
Tab::ParkingOverhead => (parking_overhead(ctx, app), Vec::new()),
Tab::ExploreBusRoute => pick_bus_route(ctx, app),
DashTab::TripsSummary => (trips_summary_prebaked(ctx, app), Vec::new()),
DashTab::ParkingOverhead => (parking_overhead(ctx, app), Vec::new()),
DashTab::ExploreBusRoute => pick_bus_route(ctx, app),
};
let mut c = WrappedComposite::new(
@ -346,10 +346,10 @@ fn pick_bus_route(ctx: &EventCtx, app: &App) -> (Widget, Vec<(String, Callback)>
let sandbox = state.downcast_mut::<SandboxMode>().unwrap();
let mut actions = sandbox.contextual_actions();
sandbox.controls.common.as_mut().unwrap().launch_info_panel(
// Arbitrarily use the first one
ID::Car(buses[0].0),
ctx,
app,
// Arbitrarily use the first one
Tab::BusStatus(buses[0].0),
&mut actions,
);
})))

View File

@ -1,4 +1,5 @@
use crate::app::App;
use crate::common::Tab;
use crate::game::Transition;
use crate::managed::{WrappedComposite, WrappedOutcome};
use crate::sandbox::gameplay::{challenge_controller, FinalScore, GameplayMode, GameplayState};
@ -6,6 +7,7 @@ use crate::sandbox::{SandboxControls, SandboxMode};
use ezgui::{Btn, EventCtx, GfxCtx};
use geom::{Duration, Time};
use sim::PersonID;
use std::collections::BTreeSet;
const GOAL: Duration = Duration::const_seconds(3.0 * 60.0);
@ -43,18 +45,20 @@ impl GameplayState for OptimizeCommute {
}
Some(WrappedOutcome::Clicked(x)) => match x.as_ref() {
"locate person" => {
let person = self.person;
return (
Some(Transition::KeepWithData(Box::new(|state, app, ctx| {
let mode = state.downcast_mut::<SandboxMode>().unwrap();
let mut actions = mode.contextual_actions();
mode.controls.common.as_mut().unwrap().launch_info_panel(
// TODO
crate::helpers::ID::Building(map_model::BuildingID(123)),
ctx,
app,
&mut actions,
);
}))),
Some(Transition::KeepWithData(Box::new(
move |state, app, ctx| {
let mode = state.downcast_mut::<SandboxMode>().unwrap();
let mut actions = mode.contextual_actions();
mode.controls.common.as_mut().unwrap().launch_info_panel(
ctx,
app,
Tab::PersonTrips(person, BTreeSet::new()),
&mut actions,
);
},
))),
false,
);
}

View File

@ -414,7 +414,7 @@ impl AgentMeter {
return Some(Transition::Push(dashboards::make(
ctx,
app,
dashboards::Tab::TripsSummary,
dashboards::DashTab::TripsSummary,
)));
}
"compare trips to baseline" => {