mirror of
https://github.com/a-b-street/abstreet.git
synced 2025-01-02 03:18:55 +03:00
renaming wizard things
This commit is contained in:
parent
8c7116af97
commit
e5486e587b
@ -105,7 +105,7 @@ 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_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<Tra
|
||||
]
|
||||
})?
|
||||
.1;
|
||||
wizard.choose_something_no_keys("Examine which trip?", || {
|
||||
wizard.choose_something("Examine which trip?", || {
|
||||
let trips = CompareTrips::new(
|
||||
ui.primary.sim.get_finished_trips(),
|
||||
ui.secondary.as_ref().unwrap().sim.get_finished_trips(),
|
||||
|
@ -21,11 +21,11 @@ fn pick_ab_test(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Tra
|
||||
let load_existing = "Load existing A/B test";
|
||||
let create_new = "Create new A/B test";
|
||||
let ab_test = if wizard
|
||||
.choose_string("What A/B test to manage?", vec![load_existing, create_new])?
|
||||
.choose_str("What A/B test to manage?", vec![load_existing, create_new])?
|
||||
== load_existing
|
||||
{
|
||||
wizard
|
||||
.choose_something_no_keys("Load which A/B test?", || {
|
||||
.choose_something("Load which A/B test?", || {
|
||||
abstutil::load_all_objects(abstutil::AB_TESTS, ui.primary.map.get_name())
|
||||
})?
|
||||
.1
|
||||
@ -232,13 +232,13 @@ fn launch_savestate(test: &ABTest, ss_path: String, ui: &mut UI, ctx: &mut Event
|
||||
}
|
||||
|
||||
fn choose_scenario(map_name: &str, wizard: &mut WrappedWizard, query: &str) -> Option<String> {
|
||||
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<String> {
|
||||
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<String> {
|
||||
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))
|
||||
})
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ fn choose_shortcut(
|
||||
shortcuts: Vec<Shortcut>,
|
||||
ui: &UI,
|
||||
) -> Option<Shortcut> {
|
||||
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![
|
||||
|
@ -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))
|
||||
|
@ -18,7 +18,7 @@ impl ColorChooser {
|
||||
fn pick_color(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Transition> {
|
||||
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),
|
||||
|
@ -302,7 +302,7 @@ fn save_edits(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Trans
|
||||
let save = "save edits";
|
||||
let cancel = "cancel";
|
||||
if wizard
|
||||
.choose_string("Overwrite edits?", vec![save, cancel])?
|
||||
.choose_str("Overwrite edits?", vec![save, cancel])?
|
||||
.as_str()
|
||||
== save
|
||||
{
|
||||
@ -322,7 +322,7 @@ fn load_edits(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Trans
|
||||
|
||||
// TODO Exclude current
|
||||
let map_name = map.get_name().to_string();
|
||||
let (_, new_edits) = wizard.choose_something_no_keys("Load which map edits?", || {
|
||||
let (_, new_edits) = wizard.choose_something("Load which map edits?", || {
|
||||
let mut list = abstutil::load_all_objects("edits", &map_name);
|
||||
list.push(("no_edits".to_string(), MapEdits::new(map_name.clone())));
|
||||
list
|
||||
@ -499,7 +499,7 @@ impl State for BulkEditLanes {
|
||||
}
|
||||
|
||||
fn bulk_edit(r: RoadID, wizard: &mut WrappedWizard, map: &Map) -> Option<MapEdits> {
|
||||
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<MapEdit
|
||||
("bus".to_string(), LaneType::Bus),
|
||||
]
|
||||
})?;
|
||||
let (_, to) = wizard.choose_something_no_keys("Change to all lanes of type...", || {
|
||||
let (_, to) = wizard.choose_something("Change to all lanes of type...", || {
|
||||
vec![
|
||||
("driving".to_string(), LaneType::Driving),
|
||||
("parking".to_string(), LaneType::Parking),
|
||||
|
@ -267,7 +267,7 @@ fn choose_preset(
|
||||
mut wizard: WrappedWizard,
|
||||
) -> Option<ControlTrafficSignal> {
|
||||
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)
|
||||
|
@ -113,11 +113,9 @@ fn convert_trips_to_scenario(
|
||||
|
||||
fn load_scenario(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Transition> {
|
||||
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(),
|
||||
|
@ -170,7 +170,7 @@ impl State for NeighborhoodEditor {
|
||||
fn pick_neighborhood(map: &Map, mut wizard: WrappedWizard) -> Option<NeighborhoodBuilder> {
|
||||
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<NeighborhoodBuilder> {
|
||||
wizard
|
||||
.choose_something_no_keys(query, || {
|
||||
.choose_something(query, || {
|
||||
abstutil::load_all_objects(abstutil::NEIGHBORHOODS, &map.get_name())
|
||||
})
|
||||
.map(|(_, n)| n)
|
||||
|
@ -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<String> {
|
||||
// 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<OriginDestination> {
|
||||
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)
|
||||
|
@ -211,11 +211,9 @@ impl State for SandboxMode {
|
||||
fn load_savestate(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Transition> {
|
||||
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");
|
||||
|
@ -68,7 +68,7 @@ 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_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<Tra
|
||||
("drive".to_string(), TripMode::Drive),
|
||||
]
|
||||
})?;
|
||||
wizard.new_choose_something("Examine which trip?", || {
|
||||
wizard.choose_something_hotkeys("Examine which trip?", || {
|
||||
let trips = ui.primary.sim.get_finished_trips();
|
||||
let mut filtered: Vec<&(TripID, TripMode, Duration)> = trips
|
||||
.finished_trips
|
||||
|
@ -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 {
|
||||
|
@ -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()
|
||||
|
@ -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<MultiKey>, 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<R: 'static + Clone + Cloneable, F: FnOnce() -> 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<String> {
|
||||
self.new_choose_something(query, || {
|
||||
pub fn choose_str(&mut self, query: &str, choices: Vec<&str>) -> Option<String> {
|
||||
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<F: Fn() -> Vec<String>>(
|
||||
pub fn choose_string<F: Fn() -> Vec<String>>(
|
||||
&mut self,
|
||||
query: &str,
|
||||
choices_generator: F,
|
||||
) -> Option<String> {
|
||||
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<MultiKey>, &str)>,
|
||||
) -> Option<String> {
|
||||
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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user