support un-closing an intersection. prevent closing borders.

This commit is contained in:
Dustin Carlino 2019-11-17 11:35:37 -08:00
parent 05ba77ba9b
commit b670299b89
4 changed files with 49 additions and 28 deletions

View File

@ -237,7 +237,7 @@ impl LaneEditor {
.contextual_action(Key::Space, &self.brushes[self.construction_idx].label)
{
let it = ui.primary.map.get_i(i).intersection_type;
if it != IntersectionType::Construction {
if it != IntersectionType::Construction && it != IntersectionType::Border {
let mut edits = ui.primary.map.get_edits().clone();
edits
.commands

View File

@ -17,7 +17,7 @@ use ezgui::{
hotkey, lctrl, Choice, Color, EventCtx, EventLoopMode, GfxCtx, Key, Line, MenuUnderButton,
ModalMenu, Text, Wizard,
};
use map_model::{IntersectionID, LaneID, MapEdits, TurnID, TurnType};
use map_model::{EditCmd, IntersectionID, LaneID, MapEdits, TurnID, TurnType};
use std::collections::{BTreeSet, HashMap};
pub struct EditMode {
@ -184,15 +184,14 @@ impl State for EditMode {
apply_map_edits(&mut ui.primary, &ui.cs, ctx, new_edits);
}*/
}
/*if orig_edits
.intersections_under_construction
.contains_key(&id)
&& ctx.input.contextual_action(Key::R, "revert")
if ui.primary.map.get_i(id).is_closed() && ctx.input.contextual_action(Key::R, "revert")
{
let mut new_edits = orig_edits.clone();
new_edits.intersections_under_construction.remove(&id);
apply_map_edits(&mut ui.primary, &ui.cs, ctx, new_edits);
}*/
let mut edits = ui.primary.map.get_edits().clone();
edits
.commands
.push(EditCmd::UncloseIntersection(id, edits.original_it(id)));
apply_map_edits(&mut ui.primary, &ui.cs, ctx, edits);
}
}
Transition::Keep

View File

@ -33,6 +33,7 @@ pub enum EditCmd {
id: IntersectionID,
orig_it: IntersectionType,
},
UncloseIntersection(IntersectionID, IntersectionType),
}
pub struct EditEffects {
@ -72,6 +73,17 @@ impl MapEdits {
abstutil::save_json_object(abstutil::EDITS, &self.map_name, &self.edits_name, self);
self.dirty = false;
}
pub fn original_it(&self, i: IntersectionID) -> IntersectionType {
for cmd in &self.commands {
if let EditCmd::CloseIntersection { id, orig_it } = cmd {
if *id == i {
return *orig_it;
}
}
}
panic!("{} isn't closed", i);
}
}
impl EditEffects {

View File

@ -1137,6 +1137,28 @@ impl EditCmd {
recalculate_turns(*id, map, effects, timer);
true
}
EditCmd::UncloseIntersection(id, orig_it) => {
let id = *id;
let orig_it = *orig_it;
if map.intersections[id.0].intersection_type == orig_it {
return false;
}
map.intersections[id.0].intersection_type = orig_it;
recalculate_turns(id, map, effects, timer);
match orig_it {
IntersectionType::StopSign => {
map.stop_signs.insert(id, ControlStopSign::new(map, id));
}
IntersectionType::TrafficSignal => {
map.traffic_signals
.insert(id, ControlTrafficSignal::new(map, id, timer));
}
IntersectionType::Border | IntersectionType::Construction => unreachable!(),
}
effects.changed_intersections.insert(id);
true
}
}
}
@ -1170,25 +1192,13 @@ impl EditCmd {
.apply(effects, map, timer)
}
EditCmd::CloseIntersection { id, orig_it } => {
if map.intersections[id.0].intersection_type == *orig_it {
return false;
}
map.intersections[id.0].intersection_type = *orig_it;
recalculate_turns(*id, map, effects, timer);
match *orig_it {
IntersectionType::StopSign => {
map.stop_signs.insert(*id, ControlStopSign::new(map, *id));
}
IntersectionType::TrafficSignal => {
map.traffic_signals
.insert(*id, ControlTrafficSignal::new(map, *id, timer));
}
IntersectionType::Border | IntersectionType::Construction => unreachable!(),
}
effects.changed_intersections.insert(*id);
true
EditCmd::UncloseIntersection(*id, *orig_it).apply(effects, map, timer)
}
EditCmd::UncloseIntersection(id, orig_it) => EditCmd::CloseIntersection {
id: *id,
orig_it: *orig_it,
}
.apply(effects, map, timer),
}
}
}