avoid typos in action_chosen

This commit is contained in:
Dustin Carlino 2018-12-17 10:09:59 -08:00
parent e64c44da33
commit 21c61e4a60
16 changed files with 42 additions and 45 deletions

View File

@ -15,7 +15,7 @@ pub struct ChokepointsFinder {
impl ChokepointsFinder {
pub fn new(ctx: &mut PluginCtx) -> Option<ChokepointsFinder> {
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

View File

@ -17,7 +17,7 @@ pub struct Validator {
impl Validator {
pub fn new(ctx: &mut PluginCtx) -> Option<Validator> {
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

View File

@ -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),
}
}

View File

@ -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

View File

@ -17,7 +17,7 @@ pub enum DrawNeighborhoodState {
impl DrawNeighborhoodState {
pub fn new(ctx: &mut PluginCtx) -> Option<DrawNeighborhoodState> {
if ctx.input.action_chosen("start drawing a neighborhood") {
if ctx.input.action_chosen("manage neighborhoods") {
return Some(DrawNeighborhoodState::PickNeighborhood(Wizard::new()));
}
None

View File

@ -7,8 +7,7 @@ pub struct RoadEditor {}
impl RoadEditor {
pub fn new(ctx: &mut PluginCtx) -> Option<RoadEditor> {
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

View File

@ -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 {

View File

@ -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;

View File

@ -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);
}
}

View File

@ -9,7 +9,7 @@ pub enum SearchState {
impl SearchState {
pub fn new(ctx: &mut PluginCtx) -> Option<SearchState> {
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,

View File

@ -19,10 +19,7 @@ pub enum WarpState {
impl WarpState {
pub fn new(ctx: &mut PluginCtx) -> Option<WarpState> {
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,

View File

@ -40,11 +40,11 @@ impl<S: UIState> GUI<RenderingHints> for UI<S> {
(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(

View File

@ -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<TopMenu>,
pub(crate) chosen_action: Option<String>,
}
@ -57,7 +58,7 @@ impl UserInput {
pub(crate) fn new(
event: Event,
context_menu: ContextMenu,
top_menu: &mut Option<TopMenu>,
mut top_menu: Option<TopMenu>,
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
}

View File

@ -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<f64>,
@ -156,9 +155,8 @@ pub struct ToggleableLayer {
}
impl ToggleableLayer {
pub fn new(layer_name: &str, key: Key, min_zoom: Option<f64>) -> ToggleableLayer {
pub fn new(layer_name: &str, min_zoom: Option<f64>) -> 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;
}

View File

@ -87,7 +87,7 @@ pub fn run<T, G: GUI<T>>(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<T, G: GUI<T>>(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",

View File

@ -6,6 +6,7 @@ use std::collections::HashSet;
pub struct TopMenu {
folders: Vec<Folder>,
pub(crate) valid_actions: HashSet<String>,
txt: Text,
@ -52,6 +53,7 @@ impl TopMenu {
TopMenu {
folders,
valid_actions: actions,
txt,
highlighted: None,
submenu: None,