cleanup: collapse the old separated modal menu groups

This commit is contained in:
Dustin Carlino 2019-10-29 15:37:19 -07:00
parent c2fd82328a
commit aae6d6d998
26 changed files with 99 additions and 137 deletions

View File

@ -4,8 +4,6 @@ use crate::{
layout, text, EventCtx, GfxCtx, Line, MultiKey, ScreenDims, ScreenPt, ScreenRectangle, Text, layout, text, EventCtx, GfxCtx, Line, MultiKey, ScreenDims, ScreenPt, ScreenRectangle, Text,
}; };
// TODO No separators
pub struct ModalMenu { pub struct ModalMenu {
title: String, title: String,
info: Text, info: Text,
@ -38,25 +36,21 @@ struct Choice {
impl ModalMenu { impl ModalMenu {
pub fn new<S: Into<String>>( pub fn new<S: Into<String>>(
title: S, title: S,
raw_choice_groups: Vec<Vec<(Option<MultiKey>, &str)>>, raw_choices: Vec<(Option<MultiKey>, &str)>,
ctx: &EventCtx, ctx: &EventCtx,
) -> ModalMenu { ) -> ModalMenu {
let mut choices = Vec::new();
for group in raw_choice_groups {
for (hotkey, label) in group {
choices.push(Choice {
hotkey,
label: label.to_string(),
active: false,
});
}
}
let mut m = ModalMenu { let mut m = ModalMenu {
title: title.into(), title: title.into(),
info: Text::new(), info: Text::new(),
chosen_action: None, chosen_action: None,
choices, choices: raw_choices
.into_iter()
.map(|(hotkey, label)| Choice {
hotkey,
label: label.to_string(),
active: false,
})
.collect(),
hovering_idx: None, hovering_idx: None,
standalone_layout: Some(layout::ContainerOrientation::TopRight), standalone_layout: Some(layout::ContainerOrientation::TopRight),

View File

@ -236,7 +236,7 @@ impl<T> ItemSlider<T> {
items: Vec<(T, Text)>, items: Vec<(T, Text)>,
menu_title: &str, menu_title: &str,
noun: &str, noun: &str,
other_choices: Vec<Vec<(Option<MultiKey>, &str)>>, other_choices: Vec<(Option<MultiKey>, &str)>,
ctx: &mut EventCtx, ctx: &mut EventCtx,
) -> ItemSlider<T> { ) -> ItemSlider<T> {
// Lifetime funniness... // Lifetime funniness...
@ -246,7 +246,7 @@ impl<T> ItemSlider<T> {
let next = format!("next {}", noun); let next = format!("next {}", noun);
let first = format!("first {}", noun); let first = format!("first {}", noun);
let last = format!("last {}", noun); let last = format!("last {}", noun);
choices.push(vec![ choices.extend(vec![
(hotkey(Key::LeftArrow), prev.as_str()), (hotkey(Key::LeftArrow), prev.as_str()),
(hotkey(Key::RightArrow), next.as_str()), (hotkey(Key::RightArrow), next.as_str()),
(hotkey(Key::Comma), first.as_str()), (hotkey(Key::Comma), first.as_str()),
@ -347,7 +347,7 @@ impl<T> WarpingItemSlider<T> {
.collect(), .collect(),
menu_title, menu_title,
noun, noun,
vec![vec![(hotkey(Key::Escape), "quit")]], vec![(hotkey(Key::Escape), "quit")],
ctx, ctx,
), ),
} }

View File

@ -37,13 +37,13 @@ impl ABTestMode {
ABTestMode { ABTestMode {
menu: ModalMenu::new( menu: ModalMenu::new(
"A/B Test Mode", "A/B Test Mode",
vec![vec![ vec![
(hotkey(Key::S), "swap"), (hotkey(Key::S), "swap"),
(hotkey(Key::D), "diff all trips"), (hotkey(Key::D), "diff all trips"),
(hotkey(Key::A), "stop diffing trips"), (hotkey(Key::A), "stop diffing trips"),
(hotkey(Key::O), "save state"), (hotkey(Key::O), "save state"),
// TODO load arbitrary savestate // TODO load arbitrary savestate
]], ],
ctx, ctx,
), ),
general_tools: MenuUnderButton::new( general_tools: MenuUnderButton::new(

View File

@ -20,10 +20,10 @@ impl Scoreboard {
pub fn new(ctx: &mut EventCtx, primary: &PerMapUI, secondary: &PerMapUI) -> Scoreboard { pub fn new(ctx: &mut EventCtx, primary: &PerMapUI, secondary: &PerMapUI) -> Scoreboard {
let menu = ModalMenu::new( let menu = ModalMenu::new(
"Scoreboard", "Scoreboard",
vec![vec![ vec![
(hotkey(Key::Escape), "quit"), (hotkey(Key::Escape), "quit"),
(hotkey(Key::B), "browse trips"), (hotkey(Key::B), "browse trips"),
]], ],
ctx, ctx,
); );
let t1 = primary.sim.get_finished_trips(); let t1 = primary.sim.get_finished_trips();

View File

@ -61,11 +61,11 @@ fn pick_ab_test(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Tra
let mut menu = ModalMenu::new( let mut menu = ModalMenu::new(
"A/B Test Editor", "A/B Test Editor",
vec![vec![ vec![
(hotkey(Key::Escape), "quit"), (hotkey(Key::Escape), "quit"),
(hotkey(Key::R), "run A/B test"), (hotkey(Key::R), "run A/B test"),
(hotkey(Key::L), "load savestate"), (hotkey(Key::L), "load savestate"),
]], ],
ctx, ctx,
); );
let mut txt = Text::new(); let mut txt = Text::new();

View File

@ -14,7 +14,7 @@ impl InfoPanel {
pub fn new(id: ID, ui: &UI, ctx: &EventCtx) -> InfoPanel { pub fn new(id: ID, ui: &UI, ctx: &EventCtx) -> InfoPanel {
InfoPanel { InfoPanel {
txt: info_for(id, ui, ctx), txt: info_for(id, ui, ctx),
menu: ModalMenu::new("Info Panel", vec![vec![(hotkey(Key::Escape), "quit")]], ctx), menu: ModalMenu::new("Info Panel", vec![(hotkey(Key::Escape), "quit")], ctx),
} }
} }
} }

View File

@ -30,11 +30,11 @@ impl SpeedControls {
let mut menu = ModalMenu::new( let mut menu = ModalMenu::new(
"Speed", "Speed",
vec![vec![ vec![
(hotkey(Key::Space), "resume"), (hotkey(Key::Space), "resume"),
(hotkey(Key::LeftBracket), "slow down"), (hotkey(Key::LeftBracket), "slow down"),
(hotkey(Key::RightBracket), "speed up"), (hotkey(Key::RightBracket), "speed up"),
]], ],
ctx, ctx,
); );
if step_controls { if step_controls {

View File

@ -47,11 +47,9 @@ impl TurnCyclerState {
menu: ModalMenu::new( menu: ModalMenu::new(
"Traffic Signal Diagram", "Traffic Signal Diagram",
vec![ vec![
vec![ (hotkey(Key::UpArrow), "select previous phase"),
(hotkey(Key::UpArrow), "select previous phase"), (hotkey(Key::DownArrow), "select next phase"),
(hotkey(Key::DownArrow), "select next phase"), (hotkey(Key::Escape), "quit"),
],
vec![(hotkey(Key::Escape), "quit")],
], ],
ctx, ctx,
), ),

View File

@ -24,10 +24,10 @@ fn pick_color(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Trans
original: ui.cs.get_modified(&name), original: ui.cs.get_modified(&name),
menu: ModalMenu::new( menu: ModalMenu::new(
&format!("Color Picker for {}", name), &format!("Color Picker for {}", name),
vec![vec![ vec![
(hotkey(Key::Backspace), "revert"), (hotkey(Key::Backspace), "revert"),
(hotkey(Key::Escape), "finalize"), (hotkey(Key::Escape), "finalize"),
]], ],
ctx, ctx,
), ),
}))) })))

View File

@ -84,7 +84,7 @@ impl Floodfiller {
); );
} }
let mut menu = ModalMenu::new(title, vec![vec![(hotkey(Key::Escape), "quit")]], ctx); let mut menu = ModalMenu::new(title, vec![(hotkey(Key::Escape), "quit")], ctx);
menu.set_info( menu.set_info(
ctx, ctx,
Text::from(Line(format!("{} unreachable lanes", num_unreachable))), Text::from(Line(format!("{} unreachable lanes", num_unreachable))),

View File

@ -39,24 +39,20 @@ impl DebugMode {
menu: ModalMenu::new( menu: ModalMenu::new(
"Debug Mode", "Debug Mode",
vec![ vec![
vec![ (hotkey(Key::Num1), "hide buildings"),
(hotkey(Key::Num1), "hide buildings"), (hotkey(Key::Num2), "hide intersections"),
(hotkey(Key::Num2), "hide intersections"), (hotkey(Key::Num3), "hide lanes"),
(hotkey(Key::Num3), "hide lanes"), (hotkey(Key::Num4), "hide areas"),
(hotkey(Key::Num4), "hide areas"), (hotkey(Key::Num5), "hide extra shapes"),
(hotkey(Key::Num5), "hide extra shapes"), (hotkey(Key::Num6), "show geometry debug mode"),
(hotkey(Key::Num6), "show geometry debug mode"), (hotkey(Key::Num7), "show labels"),
(hotkey(Key::Num7), "show labels"), (hotkey(Key::N), "show neighborhood summaries"),
(hotkey(Key::N), "show neighborhood summaries"), (hotkey(Key::R), "show route for all agents"),
(hotkey(Key::R), "show route for all agents"), (None, "show strongly-connected component roads"),
(None, "show strongly-connected component roads"), (None, "screenshot everything"),
], (hotkey(Key::Slash), "search OSM metadata"),
vec![ (hotkey(Key::S), "configure colors"),
(None, "screenshot everything"), (hotkey(Key::E), "explore a bus route"),
(hotkey(Key::Slash), "search OSM metadata"),
(hotkey(Key::S), "configure colors"),
(hotkey(Key::E), "explore a bus route"),
],
], ],
ctx, ctx,
), ),

View File

@ -36,10 +36,10 @@ impl EditMode {
common: CommonState::new(ctx), common: CommonState::new(ctx),
menu: ModalMenu::new( menu: ModalMenu::new(
"Map Edit Mode", "Map Edit Mode",
vec![vec![ vec![
(hotkey(Key::S), "save edits"), (hotkey(Key::S), "save edits"),
(hotkey(Key::L), "load different edits"), (hotkey(Key::L), "load different edits"),
]], ],
ctx, ctx,
), ),
general_tools: MenuUnderButton::new( general_tools: MenuUnderButton::new(

View File

@ -36,10 +36,10 @@ impl StopSignEditor {
StopSignEditor { StopSignEditor {
menu: ModalMenu::new( menu: ModalMenu::new(
"Stop Sign Editor", "Stop Sign Editor",
vec![vec![ vec![
(hotkey(Key::Escape), "quit"), (hotkey(Key::Escape), "quit"),
(hotkey(Key::R), "reset to default"), (hotkey(Key::R), "reset to default"),
]], ],
ctx, ctx,
), ),
id, id,

View File

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

View File

@ -64,15 +64,13 @@ impl TripsVisualizer {
let mut menu = ModalMenu::new( let mut menu = ModalMenu::new(
"Trips Visualizer", "Trips Visualizer",
vec![ vec![
vec![ (hotkey(Key::Dot), "forwards 10 seconds"),
(hotkey(Key::Dot), "forwards 10 seconds"), (hotkey(Key::RightArrow), "forwards 30 minutes"),
(hotkey(Key::RightArrow), "forwards 30 minutes"), (hotkey(Key::Comma), "backwards 10 seconds"),
(hotkey(Key::Comma), "backwards 10 seconds"), (hotkey(Key::LeftArrow), "backwards 30 minutes"),
(hotkey(Key::LeftArrow), "backwards 30 minutes"), (hotkey(Key::F), "goto start of day"),
(hotkey(Key::F), "goto start of day"), (hotkey(Key::L), "goto end of day"),
(hotkey(Key::L), "goto end of day"), (hotkey(Key::Escape), "quit"),
],
vec![(hotkey(Key::Escape), "quit")],
], ],
ctx, ctx,
); );

View File

@ -45,15 +45,11 @@ impl DataVisualizer {
menu: ModalMenu::new( menu: ModalMenu::new(
"Data Visualizer", "Data Visualizer",
vec![ vec![
vec![ (hotkey(Key::Escape), "quit"),
(hotkey(Key::Escape), "quit"), (hotkey(Key::Space), "toggle table/bar chart"),
(hotkey(Key::Space), "toggle table/bar chart"), (hotkey(Key::Num1), "household vehicles"),
], (hotkey(Key::Num2), "commute times"),
vec![ (hotkey(Key::Num3), "commute modes"),
(hotkey(Key::Num1), "household vehicles"),
(hotkey(Key::Num2), "commute times"),
(hotkey(Key::Num3), "commute modes"),
],
], ],
ctx, ctx,
), ),

View File

@ -48,7 +48,7 @@ impl TripsVisualizer {
trips, trips,
"Trips Visualizer", "Trips Visualizer",
"trip", "trip",
vec![vec![(hotkey(Key::Escape), "quit")]], vec![(hotkey(Key::Escape), "quit")],
ctx, ctx,
), ),
bldgs, bldgs,

View File

@ -25,17 +25,13 @@ impl MissionEditMode {
menu: ModalMenu::new( menu: ModalMenu::new(
"Mission Edit Mode", "Mission Edit Mode",
vec![ vec![
vec![ (hotkey(Key::D), "visualize population data"),
(hotkey(Key::D), "visualize population data"), (hotkey(Key::T), "visualize individual PSRC trips"),
(hotkey(Key::T), "visualize individual PSRC trips"), (hotkey(Key::A), "visualize all PSRC trips"),
(hotkey(Key::A), "visualize all PSRC trips"), (hotkey(Key::N), "manage neighborhoods"),
], (hotkey(Key::W), "load scenario"),
vec![ (None, "create new scenario"),
(hotkey(Key::N), "manage neighborhoods"), (hotkey(Key::Escape), "quit"),
(hotkey(Key::W), "load scenario"),
(None, "create new scenario"),
],
vec![(hotkey(Key::Escape), "quit")],
], ],
ctx, ctx,
), ),

View File

@ -27,12 +27,12 @@ impl State for NeighborhoodPicker {
return Transition::Push(Box::new(NeighborhoodEditor { return Transition::Push(Box::new(NeighborhoodEditor {
menu: ModalMenu::new( menu: ModalMenu::new(
&format!("Neighborhood Editor for {}", n.name), &format!("Neighborhood Editor for {}", n.name),
vec![vec![ vec![
(hotkey(Key::Escape), "quit"), (hotkey(Key::Escape), "quit"),
(hotkey(Key::S), "save"), (hotkey(Key::S), "save"),
(hotkey(Key::X), "export as an Osmosis polygon filter"), (hotkey(Key::X), "export as an Osmosis polygon filter"),
(hotkey(Key::P), "add a new point"), (hotkey(Key::P), "add a new point"),
]], ],
ctx, ctx,
), ),
neighborhood: n, neighborhood: n,

View File

@ -116,11 +116,11 @@ impl ScenarioManager {
ScenarioManager { ScenarioManager {
menu: ModalMenu::new( menu: ModalMenu::new(
"Scenario Editor", "Scenario Editor",
vec![vec![ vec![
(hotkey(Key::S), "save"), (hotkey(Key::S), "save"),
(hotkey(Key::E), "edit"), (hotkey(Key::E), "edit"),
(hotkey(Key::R), "instantiate"), (hotkey(Key::R), "instantiate"),
]], ],
ctx, ctx,
), ),
general_tools: MenuUnderButton::new( general_tools: MenuUnderButton::new(

View File

@ -66,15 +66,13 @@ impl SandboxMode {
menu: ModalMenu::new( menu: ModalMenu::new(
"Sandbox Mode", "Sandbox Mode",
vec![ vec![
vec![ (hotkey(Key::O), "save sim state"),
(hotkey(Key::O), "save sim state"), (hotkey(Key::Y), "load previous sim state"),
(hotkey(Key::Y), "load previous sim state"), (hotkey(Key::U), "load next sim state"),
(hotkey(Key::U), "load next sim state"), (None, "pick a savestate to load"),
(None, "pick a savestate to load"), (hotkey(Key::X), "reset sim"),
(hotkey(Key::X), "reset sim"), (hotkey(Key::S), "start a scenario"),
(hotkey(Key::S), "start a scenario"), (hotkey(Key::T), "start time traveling"),
],
vec![(hotkey(Key::T), "start time traveling")],
], ],
ctx, ctx,
), ),

View File

@ -19,10 +19,10 @@ impl Scoreboard {
pub fn new(ctx: &mut EventCtx, ui: &UI) -> Scoreboard { pub fn new(ctx: &mut EventCtx, ui: &UI) -> Scoreboard {
let menu = ModalMenu::new( let menu = ModalMenu::new(
"Scoreboard", "Scoreboard",
vec![vec![ vec![
(hotkey(Key::Escape), "quit"), (hotkey(Key::Escape), "quit"),
(hotkey(Key::B), "browse trips"), (hotkey(Key::B), "browse trips"),
]], ],
ctx, ctx,
); );
let t = ui.primary.sim.get_finished_trips(); let t = ui.primary.sim.get_finished_trips();

View File

@ -39,11 +39,7 @@ impl AgentSpawner {
ui: &mut UI, ui: &mut UI,
sandbox_menu: &mut ModalMenu, sandbox_menu: &mut ModalMenu,
) -> Option<Box<dyn State>> { ) -> Option<Box<dyn State>> {
let menu = ModalMenu::new( let menu = ModalMenu::new("Agent Spawner", vec![(hotkey(Key::Escape), "quit")], ctx);
"Agent Spawner",
vec![vec![(hotkey(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

@ -46,7 +46,7 @@ impl InactiveTimeTravel {
items, items,
"Time Traveler", "Time Traveler",
"moment", "moment",
vec![vec![(hotkey(Key::Escape), "quit")]], vec![(hotkey(Key::Escape), "quit")],
ctx, ctx,
), ),
})) }))

View File

@ -14,7 +14,7 @@ impl TutorialMode {
ui.primary.reset_sim(); ui.primary.reset_sim();
TutorialMode { TutorialMode {
menu: ModalMenu::new("Tutorial", vec![vec![(hotkey(Key::Escape), "quit")]], ctx), menu: ModalMenu::new("Tutorial", vec![(hotkey(Key::Escape), "quit")], ctx),
orig_center: ctx.canvas.center_to_map_pt(), orig_center: ctx.canvas.center_to_map_pt(),
} }
} }
@ -32,11 +32,7 @@ impl State for TutorialMode {
if ctx.input.key_pressed(Key::Enter, "next step of tutorial") { if ctx.input.key_pressed(Key::Enter, "next step of tutorial") {
return Transition::Replace(Box::new(Part2 { return Transition::Replace(Box::new(Part2 {
orig_cam_zoom: ctx.canvas.cam_zoom, orig_cam_zoom: ctx.canvas.cam_zoom,
menu: ModalMenu::new( menu: ModalMenu::new("Tutorial", vec![(hotkey(Key::Escape), "quit")], ctx),
"Tutorial",
vec![vec![(hotkey(Key::Escape), "quit")]],
ctx,
),
})); }));
} }
} }

View File

@ -80,7 +80,7 @@ impl UI {
state: State::viewing(), state: State::viewing(),
menu: ModalMenu::new( menu: ModalMenu::new(
"Map Editor", "Map Editor",
vec![vec![ vec![
(hotkey(Key::Escape), "quit"), (hotkey(Key::Escape), "quit"),
(hotkey(Key::S), "save raw map"), (hotkey(Key::S), "save raw map"),
(hotkey(Key::F), "save map fixes"), (hotkey(Key::F), "save map fixes"),
@ -89,7 +89,7 @@ impl UI {
(hotkey(Key::G), "preview all intersections"), (hotkey(Key::G), "preview all intersections"),
(None, "find overlapping intersections"), (None, "find overlapping intersections"),
(hotkey(Key::Z), "find short roads"), (hotkey(Key::Z), "find short roads"),
]], ],
ctx, ctx,
), ),
sidebar: Text::new(), sidebar: Text::new(),