From 21c61e4a60b915e4ac4eb249ff6a9c44739a9296 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Mon, 17 Dec 2018 10:09:59 -0800 Subject: [PATCH] avoid typos in action_chosen --- editor/src/plugins/debug/chokepoints.rs | 2 +- editor/src/plugins/debug/geom_validation.rs | 2 +- editor/src/plugins/debug/layers.rs | 24 +++++++------------ editor/src/plugins/debug/steep.rs | 7 +----- editor/src/plugins/edit/draw_neighborhoods.rs | 2 +- editor/src/plugins/edit/road_editor.rs | 3 +-- editor/src/plugins/logs.rs | 2 +- editor/src/plugins/sim/controls.rs | 6 ++--- editor/src/plugins/sim/show_score.rs | 2 +- editor/src/plugins/view/search.rs | 2 +- editor/src/plugins/view/warp.rs | 5 +--- editor/src/ui.rs | 4 ++-- ezgui/src/input.rs | 15 +++++++++++- ezgui/src/lib.rs | 6 ++--- ezgui/src/runner.rs | 3 ++- ezgui/src/top_menu.rs | 2 ++ 16 files changed, 42 insertions(+), 45 deletions(-) diff --git a/editor/src/plugins/debug/chokepoints.rs b/editor/src/plugins/debug/chokepoints.rs index 01595444fd..4408409a18 100644 --- a/editor/src/plugins/debug/chokepoints.rs +++ b/editor/src/plugins/debug/chokepoints.rs @@ -15,7 +15,7 @@ pub struct ChokepointsFinder { impl ChokepointsFinder { pub fn new(ctx: &mut PluginCtx) -> Option { - if ctx.input.action_chosen("find chokepoints of current sim") { + if ctx.input.action_chosen("find chokepoints") { return Some(find_chokepoints(&ctx.primary.sim)); } None diff --git a/editor/src/plugins/debug/geom_validation.rs b/editor/src/plugins/debug/geom_validation.rs index fcfd76a5c3..4607508c19 100644 --- a/editor/src/plugins/debug/geom_validation.rs +++ b/editor/src/plugins/debug/geom_validation.rs @@ -17,7 +17,7 @@ pub struct Validator { impl Validator { pub fn new(ctx: &mut PluginCtx) -> Option { - if ctx.input.action_chosen("Validate map geometry") { + if ctx.input.action_chosen("validate map geometry") { return Some(Validator::start(&ctx.primary.draw_map)); } None diff --git a/editor/src/plugins/debug/layers.rs b/editor/src/plugins/debug/layers.rs index 1f091a5637..38ca3775be 100644 --- a/editor/src/plugins/debug/layers.rs +++ b/editor/src/plugins/debug/layers.rs @@ -1,5 +1,5 @@ use crate::objects::ID; -use ezgui::{Key, ToggleableLayer, UserInput}; +use ezgui::{ToggleableLayer, UserInput}; // TODO ideally these would be tuned kind of dynamically based on rendering speed const MIN_ZOOM_FOR_LANES: f64 = 0.15; @@ -18,21 +18,13 @@ pub struct ToggleableLayers { impl ToggleableLayers { pub fn new() -> ToggleableLayers { ToggleableLayers { - show_lanes: ToggleableLayer::new("lanes", Key::Num3, Some(MIN_ZOOM_FOR_LANES)), - show_buildings: ToggleableLayer::new("buildings", Key::Num1, Some(0.0)), - show_intersections: ToggleableLayer::new( - "intersections", - Key::Num2, - Some(MIN_ZOOM_FOR_LANES), - ), - show_parcels: ToggleableLayer::new("parcels", Key::Num4, Some(MIN_ZOOM_FOR_PARCE)), - show_extra_shapes: ToggleableLayer::new( - "extra KML shapes", - Key::Num7, - Some(MIN_ZOOM_FOR_LANES), - ), - show_all_turn_icons: ToggleableLayer::new("turn icons", Key::Num9, None), - debug_mode: ToggleableLayer::new("debug mode", Key::G, None), + show_lanes: ToggleableLayer::new("lanes", Some(MIN_ZOOM_FOR_LANES)), + show_buildings: ToggleableLayer::new("buildings", Some(0.0)), + show_intersections: ToggleableLayer::new("intersections", Some(MIN_ZOOM_FOR_LANES)), + show_parcels: ToggleableLayer::new("parcels", Some(MIN_ZOOM_FOR_PARCE)), + show_extra_shapes: ToggleableLayer::new("extra shapes", Some(MIN_ZOOM_FOR_LANES)), + show_all_turn_icons: ToggleableLayer::new("all turn icons", None), + debug_mode: ToggleableLayer::new("geometry debug mode", None), } } diff --git a/editor/src/plugins/debug/steep.rs b/editor/src/plugins/debug/steep.rs index 94ff4e6873..0e3c55e409 100644 --- a/editor/src/plugins/debug/steep.rs +++ b/editor/src/plugins/debug/steep.rs @@ -38,12 +38,7 @@ impl SteepnessVisualizer { impl Plugin for SteepnessVisualizer { fn blocking_event(&mut self, ctx: &mut PluginCtx) -> bool { - let msg = if self.active { - "stop showing steepness" - } else { - "visualize steepness" - }; - if ctx.input.action_chosen(msg) { + if ctx.input.action_chosen("show/hide road steepness") { self.active = !self.active; } self.active diff --git a/editor/src/plugins/edit/draw_neighborhoods.rs b/editor/src/plugins/edit/draw_neighborhoods.rs index 21af5e11f8..739de49b0a 100644 --- a/editor/src/plugins/edit/draw_neighborhoods.rs +++ b/editor/src/plugins/edit/draw_neighborhoods.rs @@ -17,7 +17,7 @@ pub enum DrawNeighborhoodState { impl DrawNeighborhoodState { pub fn new(ctx: &mut PluginCtx) -> Option { - if ctx.input.action_chosen("start drawing a neighborhood") { + if ctx.input.action_chosen("manage neighborhoods") { return Some(DrawNeighborhoodState::PickNeighborhood(Wizard::new())); } None diff --git a/editor/src/plugins/edit/road_editor.rs b/editor/src/plugins/edit/road_editor.rs index 594926b5e9..4984432d79 100644 --- a/editor/src/plugins/edit/road_editor.rs +++ b/editor/src/plugins/edit/road_editor.rs @@ -7,8 +7,7 @@ pub struct RoadEditor {} impl RoadEditor { pub fn new(ctx: &mut PluginCtx) -> Option { - if ctx.primary.current_selection.is_none() && ctx.input.action_chosen("Start editing roads") - { + if ctx.primary.current_selection.is_none() && ctx.input.action_chosen("edit roads") { return Some(RoadEditor {}); } None diff --git a/editor/src/plugins/logs.rs b/editor/src/plugins/logs.rs index e39c39e86e..ea3d292edc 100644 --- a/editor/src/plugins/logs.rs +++ b/editor/src/plugins/logs.rs @@ -31,7 +31,7 @@ impl DisplayLogs { impl Plugin for DisplayLogs { fn blocking_event(&mut self, ctx: &mut PluginCtx) -> bool { if !self.active { - if ctx.input.action_chosen("show logs") { + if ctx.input.action_chosen("show log console") { self.active = true; return true; } else { diff --git a/editor/src/plugins/sim/controls.rs b/editor/src/plugins/sim/controls.rs index a01abb0b85..719bcbb39d 100644 --- a/editor/src/plugins/sim/controls.rs +++ b/editor/src/plugins/sim/controls.rs @@ -121,13 +121,13 @@ impl Plugin for SimControls { *ctx.recalculate_current_selection = true; } - if ctx.input.action_chosen("run sim") { + if ctx.input.action_chosen("run/pause sim") { self.state = State::Running { last_step: Instant::now(), benchmark: ctx.primary.sim.start_benchmark(), speed: "running".to_string(), }; - } else if ctx.input.action_chosen("run one step") { + } else if ctx.input.action_chosen("run one step of sim") { let tick = ctx.primary.sim.time; let events = ctx.primary.sim.step(&ctx.primary.map); self.primary_events = Some((tick, events)); @@ -143,7 +143,7 @@ impl Plugin for SimControls { ref mut benchmark, ref mut speed, } => { - if ctx.input.action_chosen("pause sim") { + if ctx.input.action_chosen("run/pause sim") { self.state = State::Paused; } else { ctx.hints.mode = EventLoopMode::Animation; diff --git a/editor/src/plugins/sim/show_score.rs b/editor/src/plugins/sim/show_score.rs index 5ef368e529..2415878e18 100644 --- a/editor/src/plugins/sim/show_score.rs +++ b/editor/src/plugins/sim/show_score.rs @@ -18,7 +18,7 @@ impl Plugin for ShowScoreState { fn ambient_event(&mut self, ctx: &mut PluginCtx) { match self { ShowScoreState::Inactive => { - if ctx.input.action_chosen("Show the sim info sidepanel") { + if ctx.input.action_chosen("show sim info sidepanel") { *self = panel(ctx); } } diff --git a/editor/src/plugins/view/search.rs b/editor/src/plugins/view/search.rs index 907f2ace49..82cd0c6f19 100644 --- a/editor/src/plugins/view/search.rs +++ b/editor/src/plugins/view/search.rs @@ -9,7 +9,7 @@ pub enum SearchState { impl SearchState { pub fn new(ctx: &mut PluginCtx) -> Option { - if ctx.input.action_chosen("start searching") { + if ctx.input.action_chosen("search for something") { return Some(SearchState::EnteringSearch(TextBox::new( "Search for what?", None, diff --git a/editor/src/plugins/view/warp.rs b/editor/src/plugins/view/warp.rs index 43c027f67f..ce4fe11ea1 100644 --- a/editor/src/plugins/view/warp.rs +++ b/editor/src/plugins/view/warp.rs @@ -19,10 +19,7 @@ pub enum WarpState { impl WarpState { pub fn new(ctx: &mut PluginCtx) -> Option { - if ctx - .input - .action_chosen("start searching for something to warp to") - { + if ctx.input.action_chosen("warp to an object") { return Some(WarpState::EnteringSearch(TextBox::new( "Warp to what?", None, diff --git a/editor/src/ui.rs b/editor/src/ui.rs index a714cae826..4fc77b5d6b 100644 --- a/editor/src/ui.rs +++ b/editor/src/ui.rs @@ -40,11 +40,11 @@ impl GUI for UI { (Key::Num2, "show/hide intersections"), (Key::Num3, "show/hide lanes"), (Key::Num4, "show/hide parcels"), - (Key::Num5, "visualize road steepness"), + (Key::Num5, "show/hide road steepness"), (Key::Num6, "show OSM colors"), (Key::Num7, "show/hide extra shapes"), (Key::Num9, "show/hide all turn icons"), - (Key::G, "toggle geometry debug mode"), + (Key::G, "show/hide geometry debug mode"), ], ), Folder::new( diff --git a/ezgui/src/input.rs b/ezgui/src/input.rs index b97f0bbc07..182bcb2489 100644 --- a/ezgui/src/input.rs +++ b/ezgui/src/input.rs @@ -18,6 +18,7 @@ pub struct UserInput { // TODO This is hacky, but if we consume_event in things like get_moved_mouse, then canvas // dragging and UI mouseover become mutex. :\ pub(crate) context_menu: ContextMenu, + pub(crate) top_menu: Option, pub(crate) chosen_action: Option, } @@ -57,7 +58,7 @@ impl UserInput { pub(crate) fn new( event: Event, context_menu: ContextMenu, - top_menu: &mut Option, + mut top_menu: Option, canvas: &Canvas, ) -> UserInput { let mut input = UserInput { @@ -66,6 +67,8 @@ impl UserInput { unimportant_actions: Vec::new(), important_actions: Vec::new(), context_menu, + // Don't move it in yet! + top_menu: None, reserved_keys: HashMap::new(), chosen_action: None, }; @@ -112,6 +115,7 @@ impl UserInput { } } } + input.top_menu = top_menu; input } @@ -245,6 +249,15 @@ impl UserInput { self.chosen_action = None; return true; } + if !self + .top_menu + .as_ref() + .map(|m| m.valid_actions.contains(action)) + .unwrap_or(false) + { + // TODO Panic + println!("action_chosen(\"{}\") doesn't match the TopMenu!", action); + } false } diff --git a/ezgui/src/lib.rs b/ezgui/src/lib.rs index c435f40b1c..15735d47aa 100644 --- a/ezgui/src/lib.rs +++ b/ezgui/src/lib.rs @@ -148,7 +148,6 @@ impl<'a> GfxCtx<'a> { pub struct ToggleableLayer { layer_name: String, - key: Key, // If None, never automatically enable at a certain zoom level. min_zoom: Option, @@ -156,9 +155,8 @@ pub struct ToggleableLayer { } impl ToggleableLayer { - pub fn new(layer_name: &str, key: Key, min_zoom: Option) -> ToggleableLayer { + pub fn new(layer_name: &str, min_zoom: Option) -> ToggleableLayer { ToggleableLayer { - key, min_zoom, layer_name: layer_name.to_string(), enabled: false, @@ -181,7 +179,7 @@ impl ToggleableLayer { // True if there was a change pub fn event(&mut self, input: &mut input::UserInput) -> bool { - if input.unimportant_key_pressed(self.key, &format!("toggle {}", self.layer_name)) { + if input.action_chosen(&format!("show/hide {}", self.layer_name)) { self.enabled = !self.enabled; return true; } diff --git a/ezgui/src/runner.rs b/ezgui/src/runner.rs index 957bb62a49..4d4c244557 100644 --- a/ezgui/src/runner.rs +++ b/ezgui/src/runner.rs @@ -87,7 +87,7 @@ pub fn run>(mut gui: G, window_title: &str, initial_width: u32, ini let mut input = UserInput::new( Event::from_piston_event(ev), context_menu, - &mut top_menu, + top_menu, gui.get_mut_canvas(), ); let (new_event_mode, data) = @@ -100,6 +100,7 @@ pub fn run>(mut gui: G, window_title: &str, initial_width: u32, ini }; last_data = Some(data); context_menu = input.context_menu.maybe_build(gui.get_mut_canvas()); + top_menu = input.top_menu; if let Some(action) = input.chosen_action { panic!( "\"{}\" chosen from the top menu, but nothing consumed it", diff --git a/ezgui/src/top_menu.rs b/ezgui/src/top_menu.rs index 15cff2e9b3..a2ec5e4c36 100644 --- a/ezgui/src/top_menu.rs +++ b/ezgui/src/top_menu.rs @@ -6,6 +6,7 @@ use std::collections::HashSet; pub struct TopMenu { folders: Vec, + pub(crate) valid_actions: HashSet, txt: Text, @@ -52,6 +53,7 @@ impl TopMenu { TopMenu { folders, + valid_actions: actions, txt, highlighted: None, submenu: None,