make the all-walk conversion idempotent, and some other bugfixes to the

editor
This commit is contained in:
Dustin Carlino 2020-01-24 15:30:32 -08:00
parent 09b0c47f3c
commit 4f60d6cb77
2 changed files with 31 additions and 14 deletions

View File

@ -94,7 +94,9 @@ impl State for TrafficSignalEditor {
self.redo_stack.clear();
self.top_panel = make_top_panel(true, false, ctx);
change_traffic_signal(new_signal, ui, ctx);
self.change_phase(0, ui, ctx);
// Don't use change_phase; it tries to preserve scroll
self.current_phase = 0;
self.composite = make_diagram(self.i, self.current_phase, ui, ctx);
return Transition::Keep;
}
x if x == "Use preset" => {
@ -102,12 +104,13 @@ impl State for TrafficSignalEditor {
}
x if x == "Make all-walk" => {
let mut new_signal = orig_signal.clone();
new_signal.convert_to_ped_scramble(&ui.primary.map);
self.command_stack.push(orig_signal.clone());
self.redo_stack.clear();
self.top_panel = make_top_panel(true, false, ctx);
change_traffic_signal(new_signal, ui, ctx);
self.change_phase(0, ui, ctx);
if new_signal.convert_to_ped_scramble(&ui.primary.map) {
self.command_stack.push(orig_signal.clone());
self.redo_stack.clear();
self.top_panel = make_top_panel(true, false, ctx);
change_traffic_signal(new_signal, ui, ctx);
self.change_phase(0, ui, ctx);
}
return Transition::Keep;
}
x if x.starts_with("change duration of #") => {
@ -227,6 +230,7 @@ impl State for TrafficSignalEditor {
self.redo_stack.clear();
self.top_panel = make_top_panel(true, false, ctx);
change_traffic_signal(new_signal, ui, ctx);
self.change_phase(self.current_phase, ui, ctx);
return Transition::Keep;
}
}

View File

@ -449,10 +449,26 @@ impl ControlTrafficSignal {
ts.validate().ok()
}
pub fn convert_to_ped_scramble(&mut self, map: &Map) {
// Returns true if this did anything
pub fn convert_to_ped_scramble(&mut self, map: &Map) -> bool {
let orig = self.clone();
let mut all_walk_phase = Phase::new();
for g in self.turn_groups.values() {
if g.turn_type == TurnType::Crosswalk {
all_walk_phase.edit_group(g, TurnPriority::Protected, &self.turn_groups, map);
}
}
// Remove Crosswalk groups from existing phases.
let mut replaced = std::mem::replace(&mut self.phases, Vec::new());
let mut has_all_walk = false;
for phase in replaced.iter_mut() {
if !has_all_walk && phase == &all_walk_phase {
has_all_walk = true;
continue;
}
// Crosswalks are only in protected_groups.
retain_btreeset(&mut phase.protected_groups, |g| {
self.turn_groups[g].turn_type != TurnType::Crosswalk
@ -472,13 +488,10 @@ impl ControlTrafficSignal {
}
self.phases = replaced;
let mut phase = Phase::new();
for g in self.turn_groups.values() {
if g.turn_type == TurnType::Crosswalk {
phase.edit_group(g, TurnPriority::Protected, &self.turn_groups, map);
}
if !has_all_walk {
self.phases.push(all_walk_phase);
}
self.phases.push(phase);
self != &orig
}
}