From e5486e587b6ab2c8c347425a5182991da8ce8fdf Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Wed, 7 Aug 2019 15:42:50 -0700 Subject: [PATCH] renaming wizard things --- editor/src/abtest/score.rs | 4 ++-- editor/src/abtest/setup.rs | 10 ++++----- editor/src/common/shortcuts.rs | 2 +- editor/src/debug/bus_explorer.rs | 2 +- editor/src/debug/color_picker.rs | 2 +- editor/src/edit/mod.rs | 8 ++++---- editor/src/edit/traffic_signals.rs | 2 +- editor/src/mission/mod.rs | 8 +++----- editor/src/mission/neighborhood.rs | 4 ++-- editor/src/mission/scenario.rs | 6 +++--- editor/src/sandbox/mod.rs | 8 +++----- editor/src/sandbox/score.rs | 4 ++-- editor/src/sandbox/spawner.rs | 20 +++++++++--------- editor/src/splash_screen.rs | 28 ++++++++++++------------- ezgui/src/widgets/wizard.rs | 33 +++++++----------------------- 15 files changed, 59 insertions(+), 82 deletions(-) diff --git a/editor/src/abtest/score.rs b/editor/src/abtest/score.rs index a72f71a345..e983a38158 100644 --- a/editor/src/abtest/score.rs +++ b/editor/src/abtest/score.rs @@ -105,7 +105,7 @@ impl State for Scoreboard { fn browse_trips(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option { let mut wizard = wiz.wrap(ctx); let mode = wizard - .choose_something_no_keys("Browse which trips?", || { + .choose_something("Browse which trips?", || { vec![ ("walk".to_string(), TripMode::Walk), ("bike".to_string(), TripMode::Bike), @@ -114,7 +114,7 @@ fn browse_trips(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option Option Option { - wizard.choose_actual_string(query, || { + wizard.choose_string(query, || { abstutil::list_all_objects(abstutil::SCENARIOS, map_name) }) } fn choose_edits(map_name: &str, wizard: &mut WrappedWizard, query: &str) -> Option { - wizard.choose_actual_string(query, || { + wizard.choose_string(query, || { let mut list = abstutil::list_all_objects("edits", map_name); list.push("no_edits".to_string()); list @@ -247,7 +247,7 @@ fn choose_edits(map_name: &str, wizard: &mut WrappedWizard, query: &str) -> Opti fn pick_savestate(test: &ABTest, wizard: &mut WrappedWizard) -> Option { let path = abstutil::path1(&test.map_name, abstutil::AB_TEST_SAVES, &test.test_name); - wizard.choose_actual_string("Load which savestate?", || { + wizard.choose_string("Load which savestate?", || { abstutil::list_dir(std::path::Path::new(&path)) }) } diff --git a/editor/src/common/shortcuts.rs b/editor/src/common/shortcuts.rs index 10a28117c2..5ab6ce102a 100644 --- a/editor/src/common/shortcuts.rs +++ b/editor/src/common/shortcuts.rs @@ -60,7 +60,7 @@ fn choose_shortcut( shortcuts: Vec, ui: &UI, ) -> Option { - let (_, mut s) = wizard.new_choose_something("Jump to which shortcut?", || { + let (_, mut s) = wizard.choose_something_hotkeys("Jump to which shortcut?", || { // TODO Handle >9 // TODO Allow deleting let keys = vec![ diff --git a/editor/src/debug/bus_explorer.rs b/editor/src/debug/bus_explorer.rs index c0be73199c..d85c408a25 100644 --- a/editor/src/debug/bus_explorer.rs +++ b/editor/src/debug/bus_explorer.rs @@ -112,7 +112,7 @@ impl State for BusRoutePicker { if let Some((_, id)) = self.wizard .wrap(ctx) - .choose_something_no_keys("Explore which bus route?", || { + .choose_something("Explore which bus route?", || { choices .into_iter() .map(|id| (ui.primary.map.get_br(id).name.clone(), id)) diff --git a/editor/src/debug/color_picker.rs b/editor/src/debug/color_picker.rs index 1a97dc7135..8e5181b4e7 100644 --- a/editor/src/debug/color_picker.rs +++ b/editor/src/debug/color_picker.rs @@ -18,7 +18,7 @@ impl ColorChooser { fn pick_color(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option { let name = wiz .wrap(ctx) - .choose_actual_string("Change which color?", || ui.cs.color_names())?; + .choose_string("Change which color?", || ui.cs.color_names())?; Some(Transition::Replace(Box::new(ColorChanger { name: name.clone(), original: ui.cs.get_modified(&name), diff --git a/editor/src/edit/mod.rs b/editor/src/edit/mod.rs index d5d94ce203..c2c83d0957 100644 --- a/editor/src/edit/mod.rs +++ b/editor/src/edit/mod.rs @@ -302,7 +302,7 @@ fn save_edits(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option Option Option { - let (_, from) = wizard.choose_something_no_keys("Change all lanes of type...", || { + let (_, from) = wizard.choose_something("Change all lanes of type...", || { vec![ ("driving".to_string(), LaneType::Driving), ("parking".to_string(), LaneType::Parking), @@ -507,7 +507,7 @@ fn bulk_edit(r: RoadID, wizard: &mut WrappedWizard, map: &Map) -> Option Option { wizard - .choose_something_no_keys("Use which preset for this intersection?", || { + .choose_something("Use which preset for this intersection?", || { ControlTrafficSignal::get_possible_policies(map, id) }) .map(|(_, ts)| ts) diff --git a/editor/src/mission/mod.rs b/editor/src/mission/mod.rs index 859187525e..93273c7abd 100644 --- a/editor/src/mission/mod.rs +++ b/editor/src/mission/mod.rs @@ -113,11 +113,9 @@ fn convert_trips_to_scenario( fn load_scenario(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option { let map_name = ui.primary.map.get_name().to_string(); - let s = wiz - .wrap(ctx) - .choose_actual_string("Load which scenario?", || { - abstutil::list_all_objects(abstutil::SCENARIOS, &map_name) - })?; + let s = wiz.wrap(ctx).choose_string("Load which scenario?", || { + abstutil::list_all_objects(abstutil::SCENARIOS, &map_name) + })?; let scenario = abstutil::read_binary( &abstutil::path1_bin(&map_name, abstutil::SCENARIOS, &s), &mut Timer::throwaway(), diff --git a/editor/src/mission/neighborhood.rs b/editor/src/mission/neighborhood.rs index 4edfe772c9..579ce16a50 100644 --- a/editor/src/mission/neighborhood.rs +++ b/editor/src/mission/neighborhood.rs @@ -170,7 +170,7 @@ impl State for NeighborhoodEditor { fn pick_neighborhood(map: &Map, mut wizard: WrappedWizard) -> Option { let load_existing = "Load existing neighborhood"; let create_new = "Create new neighborhood"; - if wizard.choose_string( + if wizard.choose_str( "What neighborhood to edit?", vec![load_existing, create_new], )? == load_existing @@ -192,7 +192,7 @@ fn load_neighborhood_builder( query: &str, ) -> Option { wizard - .choose_something_no_keys(query, || { + .choose_something(query, || { abstutil::load_all_objects(abstutil::NEIGHBORHOODS, &map.get_name()) }) .map(|(_, n)| n) diff --git a/editor/src/mission/scenario.rs b/editor/src/mission/scenario.rs index 7cd48c245d..01177774b8 100644 --- a/editor/src/mission/scenario.rs +++ b/editor/src/mission/scenario.rs @@ -105,7 +105,7 @@ fn edit_scenario(map: &Map, scenario: &mut Scenario, mut wizard: WrappedWizard) let spawn_border = "Spawn agents from a border"; let randomize = "Randomly spawn stuff from/to every neighborhood"; match wizard - .choose_string( + .choose_str( "What kind of edit?", vec![seed_parked, spawn, spawn_border, randomize], )? @@ -188,7 +188,7 @@ fn edit_scenario(map: &Map, scenario: &mut Scenario, mut wizard: WrappedWizard) fn choose_neighborhood(map: &Map, wizard: &mut WrappedWizard, query: &str) -> Option { // Load the full object, since we usually visualize the neighborhood when menuing over it wizard - .choose_something_no_keys(query, || { + .choose_something(query, || { Neighborhood::load_all(map.get_name(), map.get_gps_bounds()) }) .map(|(n, _)| n) @@ -218,7 +218,7 @@ fn choose_origin_destination( ) -> Option { let neighborhood = "Neighborhood"; let border = "Border intersection"; - if wizard.choose_string(query, vec![neighborhood, border])? == neighborhood { + if wizard.choose_str(query, vec![neighborhood, border])? == neighborhood { choose_neighborhood(map, wizard, query).map(OriginDestination::Neighborhood) } else { choose_intersection(wizard, query).map(OriginDestination::Border) diff --git a/editor/src/sandbox/mod.rs b/editor/src/sandbox/mod.rs index e9177253e4..cc0ad7b6a5 100644 --- a/editor/src/sandbox/mod.rs +++ b/editor/src/sandbox/mod.rs @@ -211,11 +211,9 @@ impl State for SandboxMode { fn load_savestate(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option { let path = ui.primary.sim.save_dir(); - let ss = wiz - .wrap(ctx) - .choose_actual_string("Load which savestate?", || { - abstutil::list_dir(std::path::Path::new(&path)) - })?; + let ss = wiz.wrap(ctx).choose_string("Load which savestate?", || { + abstutil::list_dir(std::path::Path::new(&path)) + })?; ctx.loading_screen("load savestate", |ctx, mut timer| { ui.primary.sim = Sim::load_savestate(ss, &mut timer).expect("Can't load savestate"); diff --git a/editor/src/sandbox/score.rs b/editor/src/sandbox/score.rs index 69da8e0a12..a95a287e4c 100644 --- a/editor/src/sandbox/score.rs +++ b/editor/src/sandbox/score.rs @@ -68,7 +68,7 @@ impl State for Scoreboard { fn browse_trips(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option { let mut wizard = wiz.wrap(ctx); - let (_, mode) = wizard.choose_something_no_keys("Browse which trips?", || { + let (_, mode) = wizard.choose_something("Browse which trips?", || { vec![ ("walk".to_string(), TripMode::Walk), ("bike".to_string(), TripMode::Bike), @@ -76,7 +76,7 @@ fn browse_trips(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option = trips .finished_trips diff --git a/editor/src/sandbox/spawner.rs b/editor/src/sandbox/spawner.rs index 0485bc82ac..0301377056 100644 --- a/editor/src/sandbox/spawner.rs +++ b/editor/src/sandbox/spawner.rs @@ -364,16 +364,16 @@ fn instantiate_scenario(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Op }; let map = &ui.primary.map; - let scenario_name = - wiz.wrap(ctx) - .choose_actual_string("Instantiate which scenario?", || { - let mut list = vec![builtin.clone(), "just buses".to_string()]; - list.extend(abstutil::list_all_objects( - abstutil::SCENARIOS, - map.get_name(), - )); - list - })?; + let scenario_name = wiz + .wrap(ctx) + .choose_string("Instantiate which scenario?", || { + let mut list = vec![builtin.clone(), "just buses".to_string()]; + list.extend(abstutil::list_all_objects( + abstutil::SCENARIOS, + map.get_name(), + )); + list + })?; let scenario = if scenario_name == builtin { if let Some(n) = num_agents { diff --git a/editor/src/splash_screen.rs b/editor/src/splash_screen.rs index 93f4ac95cf..c977580834 100644 --- a/editor/src/splash_screen.rs +++ b/editor/src/splash_screen.rs @@ -141,25 +141,25 @@ fn splash_screen( // TODO No hotkey for quit because it's just the normal menu escape? match wizard - .choose_string_hotkeys( - "Welcome to A/B Street!", + .choose_something_hotkeys("Welcome to A/B Street!", || { vec![ - (hotkey(Key::S), sandbox), - (hotkey(Key::L), load_map), - (hotkey(Key::E), edit), - (hotkey(Key::T), tutorial), - (hotkey(Key::D), debug), - (hotkey(Key::M), mission), - (hotkey(Key::A), abtest), - (None, about), - (None, quit), - ], - )? + (hotkey(Key::S), sandbox.to_string(), ()), + (hotkey(Key::L), load_map.to_string(), ()), + (hotkey(Key::E), edit.to_string(), ()), + (hotkey(Key::T), tutorial.to_string(), ()), + (hotkey(Key::D), debug.to_string(), ()), + (hotkey(Key::M), mission.to_string(), ()), + (hotkey(Key::A), abtest.to_string(), ()), + (None, about.to_string(), ()), + (None, quit.to_string(), ()), + ] + })? + .0 .as_str() { x if x == sandbox => Some(Transition::Push(Box::new(SandboxMode::new(ctx)))), x if x == load_map => { - if let Some(name) = wizard.choose_actual_string("Load which map?", || { + if let Some(name) = wizard.choose_string("Load which map?", || { let current_map = ui.primary.map.get_name(); abstutil::list_all_objects("maps", "") .into_iter() diff --git a/ezgui/src/widgets/wizard.rs b/ezgui/src/widgets/wizard.rs index fbcdaac554..cc679e22e1 100644 --- a/ezgui/src/widgets/wizard.rs +++ b/ezgui/src/widgets/wizard.rs @@ -234,7 +234,7 @@ impl<'a, 'b> WrappedWizard<'a, 'b> { ) } - pub fn new_choose_something< + pub fn choose_something_hotkeys< R: 'static + Clone + Cloneable, F: FnOnce() -> Vec<(Option, String, R)>, >( @@ -324,16 +324,12 @@ impl<'a, 'b> WrappedWizard<'a, 'b> { } } - // TODO rename choose_something and choose_something_hotkeys - pub fn choose_something_no_keys< - R: 'static + Clone + Cloneable, - F: FnOnce() -> Vec<(String, R)>, - >( + pub fn choose_something Vec<(String, R)>>( &mut self, query: &str, choices_generator: F, ) -> Option<(String, R)> { - self.new_choose_something(query, || { + self.choose_something_hotkeys(query, || { choices_generator() .into_iter() .map(|(s, data)| (None, s, data)) @@ -341,9 +337,8 @@ impl<'a, 'b> WrappedWizard<'a, 'b> { }) } - // TODO rename choose_str - pub fn choose_string(&mut self, query: &str, choices: Vec<&str>) -> Option { - self.new_choose_something(query, || { + pub fn choose_str(&mut self, query: &str, choices: Vec<&str>) -> Option { + self.choose_something_hotkeys(query, || { choices .into_iter() .map(|s| (None, s.to_string(), ())) @@ -352,12 +347,12 @@ impl<'a, 'b> WrappedWizard<'a, 'b> { .map(|(s, _)| s) } - pub fn choose_actual_string Vec>( + pub fn choose_string Vec>( &mut self, query: &str, choices_generator: F, ) -> Option { - self.new_choose_something(query, || { + self.choose_something_hotkeys(query, || { choices_generator() .into_iter() .map(|s| (None, s, ())) @@ -366,20 +361,6 @@ impl<'a, 'b> WrappedWizard<'a, 'b> { .map(|(s, _)| s) } - pub fn choose_string_hotkeys( - &mut self, - query: &str, - choices: Vec<(Option, &str)>, - ) -> Option { - self.new_choose_something(query, || { - choices - .into_iter() - .map(|(key, s)| (key, s.to_string(), ())) - .collect() - }) - .map(|(s, _)| s) - } - pub fn aborted(&self) -> bool { self.wizard.aborted() }