mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-25 11:44:25 +03:00
simplify toggleable layer; dont need to repeat key names
This commit is contained in:
parent
b55e0ae263
commit
7eb279a978
@ -111,22 +111,20 @@ impl UI {
|
||||
turn_colors,
|
||||
sim_ctrl,
|
||||
|
||||
show_lanes: ToggleableLayer::new("lanes", Key::D3, "3", Some(MIN_ZOOM_FOR_LANES)),
|
||||
show_buildings: ToggleableLayer::new("buildings", Key::D1, "1", Some(0.0)),
|
||||
show_lanes: ToggleableLayer::new("lanes", Key::D3, Some(MIN_ZOOM_FOR_LANES)),
|
||||
show_buildings: ToggleableLayer::new("buildings", Key::D1, Some(0.0)),
|
||||
show_intersections: ToggleableLayer::new(
|
||||
"intersections",
|
||||
Key::D2,
|
||||
"2",
|
||||
Some(MIN_ZOOM_FOR_LANES),
|
||||
),
|
||||
show_parcels: ToggleableLayer::new("parcels", Key::D4, "4", Some(MIN_ZOOM_FOR_PARCELS)),
|
||||
show_parcels: ToggleableLayer::new("parcels", Key::D4, Some(MIN_ZOOM_FOR_PARCELS)),
|
||||
show_extra_shapes: ToggleableLayer::new(
|
||||
"extra KML shapes",
|
||||
Key::D7,
|
||||
"7",
|
||||
Some(MIN_ZOOM_FOR_LANES),
|
||||
),
|
||||
debug_mode: ToggleableLayer::new("debug mode", Key::G, "G", None),
|
||||
debug_mode: ToggleableLayer::new("debug mode", Key::G, None),
|
||||
|
||||
current_selection_state: SelectionState::Empty,
|
||||
hider: Hider::new(),
|
||||
|
@ -94,7 +94,6 @@ impl<'a> GfxCtx<'a> {
|
||||
pub struct ToggleableLayer {
|
||||
layer_name: String,
|
||||
key: Key,
|
||||
key_name: String,
|
||||
// If None, never automatically enable at a certain zoom level.
|
||||
min_zoom: Option<f64>,
|
||||
|
||||
@ -102,17 +101,11 @@ pub struct ToggleableLayer {
|
||||
}
|
||||
|
||||
impl ToggleableLayer {
|
||||
pub fn new(
|
||||
layer_name: &str,
|
||||
key: Key,
|
||||
key_name: &str,
|
||||
min_zoom: Option<f64>,
|
||||
) -> ToggleableLayer {
|
||||
pub fn new(layer_name: &str, key: Key, min_zoom: Option<f64>) -> ToggleableLayer {
|
||||
ToggleableLayer {
|
||||
key,
|
||||
min_zoom,
|
||||
layer_name: String::from(layer_name),
|
||||
key_name: String::from(key_name),
|
||||
enabled: false,
|
||||
}
|
||||
}
|
||||
@ -134,7 +127,11 @@ impl ToggleableLayer {
|
||||
pub fn handle_event(&mut self, input: &mut input::UserInput) -> bool {
|
||||
if input.unimportant_key_pressed(
|
||||
self.key,
|
||||
&format!("Press {} to toggle {}", self.key_name, self.layer_name),
|
||||
&format!(
|
||||
"Press {} to toggle {}",
|
||||
keys::describe_key(self.key),
|
||||
self.layer_name
|
||||
),
|
||||
) {
|
||||
self.enabled = !self.enabled;
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user