mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +03:00
optional modal menu keys
This commit is contained in:
parent
3b6ecbf4af
commit
bc3b883e2f
@ -41,14 +41,14 @@ impl ABTestMode {
|
||||
menu: ModalMenu::new(
|
||||
"A/B Test Mode",
|
||||
vec![
|
||||
(Key::Escape, "quit"),
|
||||
(Key::LeftBracket, "slow down sim"),
|
||||
(Key::RightBracket, "speed up sim"),
|
||||
(Key::Space, "run/pause sim"),
|
||||
(Key::M, "run one step of sim"),
|
||||
(Key::S, "swap"),
|
||||
(Key::D, "diff all trips"),
|
||||
(Key::B, "stop diffing trips"),
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::LeftBracket), "slow down sim"),
|
||||
(Some(Key::RightBracket), "speed up sim"),
|
||||
(Some(Key::Space), "run/pause sim"),
|
||||
(Some(Key::M), "run one step of sim"),
|
||||
(Some(Key::S), "swap"),
|
||||
(Some(Key::D), "diff all trips"),
|
||||
(Some(Key::B), "stop diffing trips"),
|
||||
],
|
||||
ctx,
|
||||
),
|
||||
|
@ -25,7 +25,10 @@ impl ABTestSetup {
|
||||
*setup = ABTestSetup::Manage(
|
||||
ModalMenu::new(
|
||||
&format!("A/B Test Editor for {}", ab_test.test_name),
|
||||
vec![(Key::Escape, "quit"), (Key::R, "run A/B test")],
|
||||
vec![
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::R), "run A/B test"),
|
||||
],
|
||||
ctx,
|
||||
),
|
||||
ab_test,
|
||||
|
@ -31,7 +31,10 @@ impl ColorPicker {
|
||||
ui.cs.get_modified(&name),
|
||||
ModalMenu::new(
|
||||
&format!("Color Picker for {}", name),
|
||||
vec![(Key::Backspace, "revert"), (Key::Escape, "finalize")],
|
||||
vec![
|
||||
(Some(Key::Backspace), "revert"),
|
||||
(Some(Key::Escape), "finalize"),
|
||||
],
|
||||
ctx,
|
||||
),
|
||||
);
|
||||
|
@ -63,21 +63,21 @@ impl DebugMode {
|
||||
State::Exploring(ModalMenu::new(
|
||||
"Debug Mode",
|
||||
vec![
|
||||
(Key::Escape, "quit"),
|
||||
(Key::C, "show/hide chokepoints"),
|
||||
(Key::O, "clear original roads shown"),
|
||||
(Key::K, "unhide everything"),
|
||||
(Key::Num1, "show/hide buildings"),
|
||||
(Key::Num2, "show/hide intersections"),
|
||||
(Key::Num3, "show/hide lanes"),
|
||||
(Key::Num4, "show/hide areas"),
|
||||
(Key::Num5, "show/hide extra shapes"),
|
||||
(Key::Num6, "show/hide geometry debug mode"),
|
||||
(Key::F1, "screenshot everything"),
|
||||
(Key::Slash, "search OSM metadata"),
|
||||
(Key::M, "clear OSM search results"),
|
||||
(Key::S, "configure colors"),
|
||||
(Key::N, "show/hide neighborhood summaries"),
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::C), "show/hide chokepoints"),
|
||||
(Some(Key::O), "clear original roads shown"),
|
||||
(Some(Key::K), "unhide everything"),
|
||||
(Some(Key::Num1), "show/hide buildings"),
|
||||
(Some(Key::Num2), "show/hide intersections"),
|
||||
(Some(Key::Num3), "show/hide lanes"),
|
||||
(Some(Key::Num4), "show/hide areas"),
|
||||
(Some(Key::Num5), "show/hide extra shapes"),
|
||||
(Some(Key::Num6), "show/hide geometry debug mode"),
|
||||
(None, "screenshot everything"),
|
||||
(Some(Key::Slash), "search OSM metadata"),
|
||||
(Some(Key::M), "clear OSM search results"),
|
||||
(Some(Key::S), "configure colors"),
|
||||
(Some(Key::N), "show/hide neighborhood summaries"),
|
||||
],
|
||||
ctx,
|
||||
))
|
||||
|
@ -23,11 +23,11 @@ impl PolygonDebugger {
|
||||
let menu = ModalMenu::new(
|
||||
"Polygon Debugger",
|
||||
vec![
|
||||
(Key::Escape, "quit"),
|
||||
(Key::Dot, "next item"),
|
||||
(Key::Comma, "prev item"),
|
||||
(Key::F, "first item"),
|
||||
(Key::L, "last item"),
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::Dot), "next item"),
|
||||
(Some(Key::Comma), "prev item"),
|
||||
(Some(Key::F), "first item"),
|
||||
(Some(Key::L), "last item"),
|
||||
],
|
||||
ctx,
|
||||
);
|
||||
|
@ -29,9 +29,9 @@ impl EditMode {
|
||||
ModalMenu::new(
|
||||
"Map Edit Mode",
|
||||
vec![
|
||||
(Key::Escape, "quit"),
|
||||
(Key::S, "save edits"),
|
||||
(Key::L, "load different edits"),
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::S), "save edits"),
|
||||
(Some(Key::L), "load different edits"),
|
||||
],
|
||||
ctx,
|
||||
),
|
||||
@ -107,7 +107,10 @@ impl EditMode {
|
||||
id,
|
||||
ModalMenu::new(
|
||||
"Stop Sign Editor",
|
||||
vec![(Key::Escape, "quit"), (Key::R, "reset to default")],
|
||||
vec![
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::R), "reset to default"),
|
||||
],
|
||||
ctx,
|
||||
),
|
||||
));
|
||||
|
@ -27,16 +27,16 @@ impl TrafficSignalEditor {
|
||||
let menu = ModalMenu::new(
|
||||
&format!("Traffic Signal Editor for {}", id),
|
||||
vec![
|
||||
(Key::Escape, "quit"),
|
||||
(Key::D, "change cycle duration"),
|
||||
(Key::P, "choose a preset signal"),
|
||||
(Key::K, "move current cycle up"),
|
||||
(Key::J, "move current cycle down"),
|
||||
(Key::UpArrow, "select previous cycle"),
|
||||
(Key::DownArrow, "select next cycle"),
|
||||
(Key::Backspace, "delete current cycle"),
|
||||
(Key::N, "add a new empty cycle"),
|
||||
(Key::M, "add a new pedestrian scramble cycle"),
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::D), "change cycle duration"),
|
||||
(Some(Key::P), "choose a preset signal"),
|
||||
(Some(Key::K), "move current cycle up"),
|
||||
(Some(Key::J), "move current cycle down"),
|
||||
(Some(Key::UpArrow), "select previous cycle"),
|
||||
(Some(Key::DownArrow), "select next cycle"),
|
||||
(Some(Key::Backspace), "delete current cycle"),
|
||||
(Some(Key::N), "add a new empty cycle"),
|
||||
(Some(Key::M), "add a new pedestrian scramble cycle"),
|
||||
],
|
||||
ctx,
|
||||
);
|
||||
|
@ -22,9 +22,9 @@ impl MissionEditMode {
|
||||
state: State::Exploring(ModalMenu::new(
|
||||
"Mission Edit Mode",
|
||||
vec![
|
||||
(Key::Escape, "quit"),
|
||||
(Key::N, "manage neighborhoods"),
|
||||
(Key::W, "manage scenarios"),
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::N), "manage neighborhoods"),
|
||||
(Some(Key::W), "manage scenarios"),
|
||||
],
|
||||
ctx,
|
||||
)),
|
||||
|
@ -18,10 +18,10 @@ impl NeighborhoodEditor {
|
||||
ModalMenu::new(
|
||||
&format!("Neighborhood Editor for {}", name),
|
||||
vec![
|
||||
(Key::Escape, "quit"),
|
||||
(Key::S, "save"),
|
||||
(Key::X, "export as an Osmosis polygon filter"),
|
||||
(Key::P, "add a new point"),
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::S), "save"),
|
||||
(Some(Key::X), "export as an Osmosis polygon filter"),
|
||||
(Some(Key::P), "add a new point"),
|
||||
],
|
||||
ctx,
|
||||
)
|
||||
|
@ -23,11 +23,11 @@ impl ScenarioEditor {
|
||||
ModalMenu::new(
|
||||
&format!("Scenario Editor for {}", name),
|
||||
vec![
|
||||
(Key::Escape, "quit"),
|
||||
(Key::S, "save"),
|
||||
(Key::E, "edit"),
|
||||
(Key::I, "instantiate"),
|
||||
(Key::V, "visualize"),
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::S), "save"),
|
||||
(Some(Key::E), "edit"),
|
||||
(Some(Key::I), "instantiate"),
|
||||
(Some(Key::V), "visualize"),
|
||||
],
|
||||
ctx,
|
||||
)
|
||||
|
@ -51,23 +51,23 @@ impl SandboxMode {
|
||||
menu: ModalMenu::hacky_new(
|
||||
"Sandbox Mode",
|
||||
vec![
|
||||
(Key::Escape, "quit"),
|
||||
(Key::LeftBracket, "slow down sim"),
|
||||
(Key::RightBracket, "speed up sim"),
|
||||
(Key::O, "save sim state"),
|
||||
(Key::Y, "load previous sim state"),
|
||||
(Key::U, "load next sim state"),
|
||||
(Key::Space, "run/pause sim"),
|
||||
(Key::M, "run one step of sim"),
|
||||
(Key::X, "reset sim"),
|
||||
(Key::S, "seed the sim with agents"),
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::LeftBracket), "slow down sim"),
|
||||
(Some(Key::RightBracket), "speed up sim"),
|
||||
(Some(Key::O), "save sim state"),
|
||||
(Some(Key::Y), "load previous sim state"),
|
||||
(Some(Key::U), "load next sim state"),
|
||||
(Some(Key::Space), "run/pause sim"),
|
||||
(Some(Key::M), "run one step of sim"),
|
||||
(Some(Key::X), "reset sim"),
|
||||
(Some(Key::S), "seed the sim with agents"),
|
||||
// TODO Strange to always have this. Really it's a case of stacked modal?
|
||||
(Key::F, "stop following agent"),
|
||||
(Key::R, "stop showing agent's route"),
|
||||
(Some(Key::F), "stop following agent"),
|
||||
(Some(Key::R), "stop showing agent's route"),
|
||||
// TODO This should probably be a debug thing instead
|
||||
(Key::L, "show/hide route for all agents"),
|
||||
(Key::A, "show/hide active traffic"),
|
||||
(Key::T, "start time traveling"),
|
||||
(Some(Key::L), "show/hide route for all agents"),
|
||||
(Some(Key::A), "show/hide active traffic"),
|
||||
(Some(Key::T), "start time traveling"),
|
||||
],
|
||||
canvas,
|
||||
),
|
||||
|
@ -34,7 +34,7 @@ impl AgentSpawner {
|
||||
ui: &mut UI,
|
||||
sandbox_menu: &mut ModalMenu,
|
||||
) -> Option<AgentSpawner> {
|
||||
let menu = ModalMenu::new("Agent Spawner", vec![(Key::Escape, "quit")], ctx);
|
||||
let menu = ModalMenu::new("Agent Spawner", vec![(Some(Key::Escape), "quit")], ctx);
|
||||
let map = &ui.primary.map;
|
||||
match ui.primary.current_selection {
|
||||
Some(ID::Building(id)) => {
|
||||
|
@ -35,9 +35,9 @@ impl TimeTravel {
|
||||
menu: ModalMenu::hacky_new(
|
||||
"Time Traveler",
|
||||
vec![
|
||||
(Key::Escape, "quit"),
|
||||
(Key::Comma, "rewind"),
|
||||
(Key::Dot, "forwards"),
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::Comma), "rewind"),
|
||||
(Some(Key::Dot), "forwards"),
|
||||
],
|
||||
canvas,
|
||||
),
|
||||
|
@ -18,7 +18,7 @@ enum State {
|
||||
impl TutorialMode {
|
||||
pub fn new(ctx: &EventCtx) -> TutorialMode {
|
||||
TutorialMode {
|
||||
menu: ModalMenu::new("Tutorial", vec![(Key::Escape, "quit")], ctx),
|
||||
menu: ModalMenu::new("Tutorial", vec![(Some(Key::Escape), "quit")], ctx),
|
||||
state: State::Part1(ctx.canvas.center_to_map_pt()),
|
||||
}
|
||||
}
|
||||
|
@ -2,22 +2,27 @@ use crate::widgets::{Menu, Position};
|
||||
use crate::{Canvas, EventCtx, GfxCtx, InputResult, Key, ScreenPt, Text};
|
||||
|
||||
pub struct ModalMenu {
|
||||
menu: Menu<Key>,
|
||||
menu: Menu<()>,
|
||||
chosen_action: Option<String>,
|
||||
}
|
||||
|
||||
impl ModalMenu {
|
||||
pub fn new(prompt_line: &str, choices: Vec<(Key, &str)>, ctx: &EventCtx) -> ModalMenu {
|
||||
pub fn new(prompt_line: &str, choices: Vec<(Option<Key>, &str)>, ctx: &EventCtx) -> ModalMenu {
|
||||
ModalMenu::hacky_new(prompt_line, choices, ctx.canvas)
|
||||
}
|
||||
|
||||
// TODO Pass EventCtx when constructing the GUI?
|
||||
pub fn hacky_new(prompt_line: &str, choices: Vec<(Key, &str)>, canvas: &Canvas) -> ModalMenu {
|
||||
pub fn hacky_new(
|
||||
prompt_line: &str,
|
||||
choices: Vec<(Option<Key>, &str)>,
|
||||
canvas: &Canvas,
|
||||
) -> ModalMenu {
|
||||
// TODO Detect duplicate choices... maybe in Menu
|
||||
let mut menu = Menu::new(
|
||||
Some(Text::prompt(prompt_line)),
|
||||
choices
|
||||
.iter()
|
||||
.map(|(key, action)| (Some(*key), action.to_string(), *key))
|
||||
.into_iter()
|
||||
.map(|(key, action)| (key, action.to_string(), ()))
|
||||
.collect(),
|
||||
false,
|
||||
true,
|
||||
|
Loading…
Reference in New Issue
Block a user