Skip to content

Commit

Permalink
Consistently follow rules for whether a lane can be edited. #597
Browse files Browse the repository at this point in the history
Allow sidewalks, shoulders, and center turn lanes to be edited now.
Still don't touch service roads or light rail.
  • Loading branch information
dabreegster committed Jul 16, 2021
1 parent 062f38a commit ff310af
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
14 changes: 5 additions & 9 deletions game/src/edit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -166,7 +166,7 @@ impl State<App> 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()
Expand Down Expand Up @@ -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<Speed>) -> Vec<Choice<Speed>> {
Expand Down
7 changes: 5 additions & 2 deletions game/src/edit/roads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -297,7 +297,10 @@ impl State<App> 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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions game/src/sandbox/gameplay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl GameplayMode {
}
}

pub fn can_edit_lanes(&self) -> bool {
pub fn can_edit_roads(&self) -> bool {
!matches!(self, GameplayMode::FixTrafficSignals)
}

Expand All @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion game/src/sandbox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
Expand Down

0 comments on commit ff310af

Please sign in to comment.