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,
};
// TODO No separators
pub struct ModalMenu {
title: String,
info: Text,
@ -38,25 +36,21 @@ struct Choice {
impl ModalMenu {
pub fn new<S: Into<String>>(
title: S,
raw_choice_groups: Vec<Vec<(Option<MultiKey>, &str)>>,
raw_choices: Vec<(Option<MultiKey>, &str)>,
ctx: &EventCtx,
) -> 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 {
title: title.into(),
info: Text::new(),
chosen_action: None,
choices,
choices: raw_choices
.into_iter()
.map(|(hotkey, label)| Choice {
hotkey,
label: label.to_string(),
active: false,
})
.collect(),
hovering_idx: None,
standalone_layout: Some(layout::ContainerOrientation::TopRight),

View File

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

View File

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

View File

@ -20,10 +20,10 @@ impl Scoreboard {
pub fn new(ctx: &mut EventCtx, primary: &PerMapUI, secondary: &PerMapUI) -> Scoreboard {
let menu = ModalMenu::new(
"Scoreboard",
vec![vec![
vec![
(hotkey(Key::Escape), "quit"),
(hotkey(Key::B), "browse trips"),
]],
],
ctx,
);
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(
"A/B Test Editor",
vec![vec![
vec![
(hotkey(Key::Escape), "quit"),
(hotkey(Key::R), "run A/B test"),
(hotkey(Key::L), "load savestate"),
]],
],
ctx,
);
let mut txt = Text::new();

View File

@ -14,7 +14,7 @@ impl InfoPanel {
pub fn new(id: ID, ui: &UI, ctx: &EventCtx) -> InfoPanel {
InfoPanel {
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(
"Speed",
vec![vec![
vec![
(hotkey(Key::Space), "resume"),
(hotkey(Key::LeftBracket), "slow down"),
(hotkey(Key::RightBracket), "speed up"),
]],
],
ctx,
);
if step_controls {

View File

@ -47,11 +47,9 @@ impl TurnCyclerState {
menu: ModalMenu::new(
"Traffic Signal Diagram",
vec![
vec![
(hotkey(Key::UpArrow), "select previous phase"),
(hotkey(Key::DownArrow), "select next phase"),
],
vec![(hotkey(Key::Escape), "quit")],
(hotkey(Key::UpArrow), "select previous phase"),
(hotkey(Key::DownArrow), "select next phase"),
(hotkey(Key::Escape), "quit"),
],
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),
menu: ModalMenu::new(
&format!("Color Picker for {}", name),
vec![vec![
vec![
(hotkey(Key::Backspace), "revert"),
(hotkey(Key::Escape), "finalize"),
]],
],
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(
ctx,
Text::from(Line(format!("{} unreachable lanes", num_unreachable))),

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -39,11 +39,7 @@ impl AgentSpawner {
ui: &mut UI,
sandbox_menu: &mut ModalMenu,
) -> Option<Box<dyn State>> {
let menu = ModalMenu::new(
"Agent Spawner",
vec![vec![(hotkey(Key::Escape), "quit")]],
ctx,
);
let menu = ModalMenu::new("Agent Spawner", vec![(hotkey(Key::Escape), "quit")], ctx);
let map = &ui.primary.map;
match ui.primary.current_selection {
Some(ID::Building(id)) => {

View File

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

View File

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

View File

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