optional modal menu keys

This commit is contained in:
Dustin Carlino 2019-05-01 16:14:57 -07:00
parent 3b6ecbf4af
commit bc3b883e2f
15 changed files with 95 additions and 81 deletions

View File

@ -41,14 +41,14 @@ impl ABTestMode {
menu: ModalMenu::new( menu: ModalMenu::new(
"A/B Test Mode", "A/B Test Mode",
vec![ vec![
(Key::Escape, "quit"), (Some(Key::Escape), "quit"),
(Key::LeftBracket, "slow down sim"), (Some(Key::LeftBracket), "slow down sim"),
(Key::RightBracket, "speed up sim"), (Some(Key::RightBracket), "speed up sim"),
(Key::Space, "run/pause sim"), (Some(Key::Space), "run/pause sim"),
(Key::M, "run one step of sim"), (Some(Key::M), "run one step of sim"),
(Key::S, "swap"), (Some(Key::S), "swap"),
(Key::D, "diff all trips"), (Some(Key::D), "diff all trips"),
(Key::B, "stop diffing trips"), (Some(Key::B), "stop diffing trips"),
], ],
ctx, ctx,
), ),

View File

@ -25,7 +25,10 @@ impl ABTestSetup {
*setup = ABTestSetup::Manage( *setup = ABTestSetup::Manage(
ModalMenu::new( ModalMenu::new(
&format!("A/B Test Editor for {}", ab_test.test_name), &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, ctx,
), ),
ab_test, ab_test,

View File

@ -31,7 +31,10 @@ impl ColorPicker {
ui.cs.get_modified(&name), ui.cs.get_modified(&name),
ModalMenu::new( ModalMenu::new(
&format!("Color Picker for {}", name), &format!("Color Picker for {}", name),
vec![(Key::Backspace, "revert"), (Key::Escape, "finalize")], vec![
(Some(Key::Backspace), "revert"),
(Some(Key::Escape), "finalize"),
],
ctx, ctx,
), ),
); );

View File

@ -63,21 +63,21 @@ impl DebugMode {
State::Exploring(ModalMenu::new( State::Exploring(ModalMenu::new(
"Debug Mode", "Debug Mode",
vec![ vec![
(Key::Escape, "quit"), (Some(Key::Escape), "quit"),
(Key::C, "show/hide chokepoints"), (Some(Key::C), "show/hide chokepoints"),
(Key::O, "clear original roads shown"), (Some(Key::O), "clear original roads shown"),
(Key::K, "unhide everything"), (Some(Key::K), "unhide everything"),
(Key::Num1, "show/hide buildings"), (Some(Key::Num1), "show/hide buildings"),
(Key::Num2, "show/hide intersections"), (Some(Key::Num2), "show/hide intersections"),
(Key::Num3, "show/hide lanes"), (Some(Key::Num3), "show/hide lanes"),
(Key::Num4, "show/hide areas"), (Some(Key::Num4), "show/hide areas"),
(Key::Num5, "show/hide extra shapes"), (Some(Key::Num5), "show/hide extra shapes"),
(Key::Num6, "show/hide geometry debug mode"), (Some(Key::Num6), "show/hide geometry debug mode"),
(Key::F1, "screenshot everything"), (None, "screenshot everything"),
(Key::Slash, "search OSM metadata"), (Some(Key::Slash), "search OSM metadata"),
(Key::M, "clear OSM search results"), (Some(Key::M), "clear OSM search results"),
(Key::S, "configure colors"), (Some(Key::S), "configure colors"),
(Key::N, "show/hide neighborhood summaries"), (Some(Key::N), "show/hide neighborhood summaries"),
], ],
ctx, ctx,
)) ))

View File

@ -23,11 +23,11 @@ impl PolygonDebugger {
let menu = ModalMenu::new( let menu = ModalMenu::new(
"Polygon Debugger", "Polygon Debugger",
vec![ vec![
(Key::Escape, "quit"), (Some(Key::Escape), "quit"),
(Key::Dot, "next item"), (Some(Key::Dot), "next item"),
(Key::Comma, "prev item"), (Some(Key::Comma), "prev item"),
(Key::F, "first item"), (Some(Key::F), "first item"),
(Key::L, "last item"), (Some(Key::L), "last item"),
], ],
ctx, ctx,
); );

View File

@ -29,9 +29,9 @@ impl EditMode {
ModalMenu::new( ModalMenu::new(
"Map Edit Mode", "Map Edit Mode",
vec![ vec![
(Key::Escape, "quit"), (Some(Key::Escape), "quit"),
(Key::S, "save edits"), (Some(Key::S), "save edits"),
(Key::L, "load different edits"), (Some(Key::L), "load different edits"),
], ],
ctx, ctx,
), ),
@ -107,7 +107,10 @@ impl EditMode {
id, id,
ModalMenu::new( ModalMenu::new(
"Stop Sign Editor", "Stop Sign Editor",
vec![(Key::Escape, "quit"), (Key::R, "reset to default")], vec![
(Some(Key::Escape), "quit"),
(Some(Key::R), "reset to default"),
],
ctx, ctx,
), ),
)); ));

View File

@ -27,16 +27,16 @@ impl TrafficSignalEditor {
let menu = ModalMenu::new( let menu = ModalMenu::new(
&format!("Traffic Signal Editor for {}", id), &format!("Traffic Signal Editor for {}", id),
vec![ vec![
(Key::Escape, "quit"), (Some(Key::Escape), "quit"),
(Key::D, "change cycle duration"), (Some(Key::D), "change cycle duration"),
(Key::P, "choose a preset signal"), (Some(Key::P), "choose a preset signal"),
(Key::K, "move current cycle up"), (Some(Key::K), "move current cycle up"),
(Key::J, "move current cycle down"), (Some(Key::J), "move current cycle down"),
(Key::UpArrow, "select previous cycle"), (Some(Key::UpArrow), "select previous cycle"),
(Key::DownArrow, "select next cycle"), (Some(Key::DownArrow), "select next cycle"),
(Key::Backspace, "delete current cycle"), (Some(Key::Backspace), "delete current cycle"),
(Key::N, "add a new empty cycle"), (Some(Key::N), "add a new empty cycle"),
(Key::M, "add a new pedestrian scramble cycle"), (Some(Key::M), "add a new pedestrian scramble cycle"),
], ],
ctx, ctx,
); );

View File

@ -22,9 +22,9 @@ impl MissionEditMode {
state: State::Exploring(ModalMenu::new( state: State::Exploring(ModalMenu::new(
"Mission Edit Mode", "Mission Edit Mode",
vec![ vec![
(Key::Escape, "quit"), (Some(Key::Escape), "quit"),
(Key::N, "manage neighborhoods"), (Some(Key::N), "manage neighborhoods"),
(Key::W, "manage scenarios"), (Some(Key::W), "manage scenarios"),
], ],
ctx, ctx,
)), )),

View File

@ -18,10 +18,10 @@ impl NeighborhoodEditor {
ModalMenu::new( ModalMenu::new(
&format!("Neighborhood Editor for {}", name), &format!("Neighborhood Editor for {}", name),
vec![ vec![
(Key::Escape, "quit"), (Some(Key::Escape), "quit"),
(Key::S, "save"), (Some(Key::S), "save"),
(Key::X, "export as an Osmosis polygon filter"), (Some(Key::X), "export as an Osmosis polygon filter"),
(Key::P, "add a new point"), (Some(Key::P), "add a new point"),
], ],
ctx, ctx,
) )

View File

@ -23,11 +23,11 @@ impl ScenarioEditor {
ModalMenu::new( ModalMenu::new(
&format!("Scenario Editor for {}", name), &format!("Scenario Editor for {}", name),
vec![ vec![
(Key::Escape, "quit"), (Some(Key::Escape), "quit"),
(Key::S, "save"), (Some(Key::S), "save"),
(Key::E, "edit"), (Some(Key::E), "edit"),
(Key::I, "instantiate"), (Some(Key::I), "instantiate"),
(Key::V, "visualize"), (Some(Key::V), "visualize"),
], ],
ctx, ctx,
) )

View File

@ -51,23 +51,23 @@ impl SandboxMode {
menu: ModalMenu::hacky_new( menu: ModalMenu::hacky_new(
"Sandbox Mode", "Sandbox Mode",
vec![ vec![
(Key::Escape, "quit"), (Some(Key::Escape), "quit"),
(Key::LeftBracket, "slow down sim"), (Some(Key::LeftBracket), "slow down sim"),
(Key::RightBracket, "speed up sim"), (Some(Key::RightBracket), "speed up sim"),
(Key::O, "save sim state"), (Some(Key::O), "save sim state"),
(Key::Y, "load previous sim state"), (Some(Key::Y), "load previous sim state"),
(Key::U, "load next sim state"), (Some(Key::U), "load next sim state"),
(Key::Space, "run/pause sim"), (Some(Key::Space), "run/pause sim"),
(Key::M, "run one step of sim"), (Some(Key::M), "run one step of sim"),
(Key::X, "reset sim"), (Some(Key::X), "reset sim"),
(Key::S, "seed the sim with agents"), (Some(Key::S), "seed the sim with agents"),
// TODO Strange to always have this. Really it's a case of stacked modal? // TODO Strange to always have this. Really it's a case of stacked modal?
(Key::F, "stop following agent"), (Some(Key::F), "stop following agent"),
(Key::R, "stop showing agent's route"), (Some(Key::R), "stop showing agent's route"),
// TODO This should probably be a debug thing instead // TODO This should probably be a debug thing instead
(Key::L, "show/hide route for all agents"), (Some(Key::L), "show/hide route for all agents"),
(Key::A, "show/hide active traffic"), (Some(Key::A), "show/hide active traffic"),
(Key::T, "start time traveling"), (Some(Key::T), "start time traveling"),
], ],
canvas, canvas,
), ),

View File

@ -34,7 +34,7 @@ impl AgentSpawner {
ui: &mut UI, ui: &mut UI,
sandbox_menu: &mut ModalMenu, sandbox_menu: &mut ModalMenu,
) -> Option<AgentSpawner> { ) -> 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; let map = &ui.primary.map;
match ui.primary.current_selection { match ui.primary.current_selection {
Some(ID::Building(id)) => { Some(ID::Building(id)) => {

View File

@ -35,9 +35,9 @@ impl TimeTravel {
menu: ModalMenu::hacky_new( menu: ModalMenu::hacky_new(
"Time Traveler", "Time Traveler",
vec![ vec![
(Key::Escape, "quit"), (Some(Key::Escape), "quit"),
(Key::Comma, "rewind"), (Some(Key::Comma), "rewind"),
(Key::Dot, "forwards"), (Some(Key::Dot), "forwards"),
], ],
canvas, canvas,
), ),

View File

@ -18,7 +18,7 @@ enum State {
impl TutorialMode { impl TutorialMode {
pub fn new(ctx: &EventCtx) -> TutorialMode { pub fn new(ctx: &EventCtx) -> TutorialMode {
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()), state: State::Part1(ctx.canvas.center_to_map_pt()),
} }
} }

View File

@ -2,22 +2,27 @@ use crate::widgets::{Menu, Position};
use crate::{Canvas, EventCtx, GfxCtx, InputResult, Key, ScreenPt, Text}; use crate::{Canvas, EventCtx, GfxCtx, InputResult, Key, ScreenPt, Text};
pub struct ModalMenu { pub struct ModalMenu {
menu: Menu<Key>, menu: Menu<()>,
chosen_action: Option<String>, chosen_action: Option<String>,
} }
impl ModalMenu { 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) ModalMenu::hacky_new(prompt_line, choices, ctx.canvas)
} }
// TODO Pass EventCtx when constructing the GUI? // 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( let mut menu = Menu::new(
Some(Text::prompt(prompt_line)), Some(Text::prompt(prompt_line)),
choices choices
.iter() .into_iter()
.map(|(key, action)| (Some(*key), action.to_string(), *key)) .map(|(key, action)| (key, action.to_string(), ()))
.collect(), .collect(),
false, false,
true, true,