From 11f89c0ee5320665bd429d0a89ed06687af465fb Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Tue, 4 Dec 2018 13:51:19 -0800 Subject: [PATCH] one key to toggle through priorities --- editor/src/plugins/traffic_signal_editor.rs | 38 ++++++++++++++------- map_model/src/traffic_signals.rs | 4 --- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/editor/src/plugins/traffic_signal_editor.rs b/editor/src/plugins/traffic_signal_editor.rs index 82ca2223f5..3a31e04d38 100644 --- a/editor/src/plugins/traffic_signal_editor.rs +++ b/editor/src/plugins/traffic_signal_editor.rs @@ -110,18 +110,32 @@ impl Plugin for TrafficSignalEditor { let mut signal = ctx.primary.map.get_traffic_signal(*i).clone(); { let cycle = &mut signal.cycles[*current_cycle]; - if cycle.get_priority(id) != TurnPriority::Stop - && input.key_pressed(Key::Backspace, "remove this turn from this cycle") - { - cycle.edit_turn(id, TurnPriority::Stop, &ctx.primary.map); - } else if cycle.could_be_priority_turn(id, &ctx.primary.map) && input - .key_pressed(Key::Space, "add this turn to this cycle as priority") - { - cycle.edit_turn(id, TurnPriority::Priority, &ctx.primary.map); - } else if cycle.could_be_yield_turn(id, &ctx.primary.map) && input - .key_pressed(Key::Y, "add this turn to this cycle as yield") - { - cycle.edit_turn(id, TurnPriority::Yield, &ctx.primary.map); + // Just one key to toggle between the 3 states + let next_priority = match cycle.get_priority(id) { + TurnPriority::Stop => { + if ctx.primary.map.get_t(id).turn_type == TurnType::Crosswalk { + if cycle.could_be_priority_turn(id, &ctx.primary.map) { + Some(TurnPriority::Priority) + } else { + None + } + } else { + Some(TurnPriority::Yield) + } + } + TurnPriority::Yield => { + if cycle.could_be_priority_turn(id, &ctx.primary.map) { + Some(TurnPriority::Priority) + } else { + Some(TurnPriority::Stop) + } + } + TurnPriority::Priority => Some(TurnPriority::Stop), + }; + if let Some(pri) = next_priority { + if input.key_pressed(Key::Space, &format!("make {:?} {:?}", id, pri)) { + cycle.edit_turn(id, pri, &ctx.primary.map); + } } } diff --git a/map_model/src/traffic_signals.rs b/map_model/src/traffic_signals.rs index 8326b8d26c..c681c332ec 100644 --- a/map_model/src/traffic_signals.rs +++ b/map_model/src/traffic_signals.rs @@ -87,10 +87,6 @@ impl Cycle { true } - pub fn could_be_yield_turn(&self, t: TurnID, map: &Map) -> bool { - !self.yield_turns.contains(&t) && map.get_t(t).turn_type != TurnType::Crosswalk - } - pub fn get_priority(&self, t: TurnID) -> TurnPriority { if self.priority_turns.contains(&t) { TurnPriority::Priority