From ff310af3d10cf83e4ba8c8fec04d42d8e6e4318e Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Thu, 15 Jul 2021 18:21:49 -0700 Subject: [PATCH] Consistently follow rules for whether a lane can be edited. #597 Allow sidewalks, shoulders, and center turn lanes to be edited now. Still don't touch service roads or light rail. --- game/src/edit/mod.rs | 14 +++++--------- game/src/edit/roads.rs | 7 +++++-- game/src/sandbox/gameplay/mod.rs | 4 ++-- game/src/sandbox/mod.rs | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/game/src/edit/mod.rs b/game/src/edit/mod.rs index a6f6f06fb5..8d65960d58 100644 --- a/game/src/edit/mod.rs +++ b/game/src/edit/mod.rs @@ -6,7 +6,7 @@ use map_gui::options::OptionsPanel; use map_gui::render::DrawMap; use map_gui::tools::{grey_out_map, ChooseSomething, ColorLegend, PopupMsg}; use map_gui::ID; -use map_model::{EditCmd, IntersectionID, LaneID, LaneType, MapEdits}; +use map_model::{EditCmd, IntersectionID, LaneID, MapEdits}; use widgetry::{ lctrl, Choice, Color, ControlState, Drawable, EventCtx, GfxCtx, HorizontalAlignment, Image, Key, Line, Menu, Outcome, Panel, State, Text, TextBox, TextExt, VerticalAlignment, Widget, @@ -166,7 +166,7 @@ impl State for EditMode { if ctx.redo_mouseover() { app.primary.current_selection = app.mouseover_unzoomed_roads_and_intersections(ctx); if match app.primary.current_selection { - Some(ID::Lane(l)) => !can_edit_lane(&self.mode, l, app), + Some(ID::Lane(l)) => !self.mode.can_edit_roads() || !can_edit_lane(app, l), Some(ID::Intersection(i)) => { !self.mode.can_edit_stop_signs() && app.primary.map.maybe_get_stop_sign(i).is_some() @@ -732,13 +732,9 @@ pub fn apply_map_edits(ctx: &mut EventCtx, app: &mut App, edits: MapEdits) { app.primary.map.save_edits(); } -pub fn can_edit_lane(mode: &GameplayMode, l: LaneID, app: &App) -> bool { - let l = app.primary.map.get_l(l); - mode.can_edit_lanes() - && !l.is_walkable() - && l.lane_type != LaneType::SharedLeftTurn - && !l.is_light_rail() - && !app.primary.map.get_parent(l.id).is_service() +pub fn can_edit_lane(app: &App, l: LaneID) -> bool { + let map = &app.primary.map; + !map.get_l(l).is_light_rail() && !map.get_parent(l).is_service() } pub fn speed_limit_choices(app: &App, preset: Option) -> Vec> { diff --git a/game/src/edit/roads.rs b/game/src/edit/roads.rs index 61db3127da..4e938c76e3 100644 --- a/game/src/edit/roads.rs +++ b/game/src/edit/roads.rs @@ -14,7 +14,7 @@ use widgetry::{ use crate::app::{App, Transition}; use crate::edit::zones::ZoneEditor; -use crate::edit::{apply_map_edits, speed_limit_choices}; +use crate::edit::{apply_map_edits, can_edit_lane, speed_limit_choices}; pub struct RoadEditor { r: RoadID, @@ -297,7 +297,10 @@ impl State for RoadEditor { if ctx.canvas.get_cursor_in_map_space().is_some() { if ctx.redo_mouseover() { app.recalculate_current_selection(ctx); - if !matches!(app.primary.current_selection, Some(ID::Lane(_))) { + if match app.primary.current_selection { + Some(ID::Lane(l)) => !can_edit_lane(app, l), + _ => true, + } { app.primary.current_selection = None; } } diff --git a/game/src/sandbox/gameplay/mod.rs b/game/src/sandbox/gameplay/mod.rs index d5a07c9c17..9257f58bf6 100644 --- a/game/src/sandbox/gameplay/mod.rs +++ b/game/src/sandbox/gameplay/mod.rs @@ -161,7 +161,7 @@ impl GameplayMode { } } - pub fn can_edit_lanes(&self) -> bool { + pub fn can_edit_roads(&self) -> bool { !matches!(self, GameplayMode::FixTrafficSignals) } @@ -177,7 +177,7 @@ impl GameplayMode { for cmd in &edits.commands { match cmd { EditCmd::ChangeRoad { .. } => { - if !self.can_edit_lanes() { + if !self.can_edit_roads() { return false; } } diff --git a/game/src/sandbox/mod.rs b/game/src/sandbox/mod.rs index 4c1d40dc0e..0d09beefcf 100644 --- a/game/src/sandbox/mod.rs +++ b/game/src/sandbox/mod.rs @@ -323,7 +323,7 @@ impl ContextualActions for Actions { if !app.primary.map.get_turns_from_lane(l).is_empty() { actions.push((Key::Z, "explore turns from this lane".to_string())); } - if can_edit_lane(&self.gameplay, l, app) { + if self.gameplay.can_edit_roads() && can_edit_lane(app, l) { actions.push((Key::E, "edit lane".to_string())); } }