From 9366116c9b941acfe816113d9e8b64b4007b8eae Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Mon, 26 Jul 2021 12:50:20 -0700 Subject: [PATCH] Add a location button to the road / multi road editor. #718 --- game/src/edit/multiple_roads.rs | 40 ++++++++++++++++++++++++++------- game/src/edit/roads.rs | 16 ++++++++++++- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/game/src/edit/multiple_roads.rs b/game/src/edit/multiple_roads.rs index a2a1b33d1a..8d93df5145 100644 --- a/game/src/edit/multiple_roads.rs +++ b/game/src/edit/multiple_roads.rs @@ -14,6 +14,7 @@ use widgetry::{ use crate::app::App; use crate::app::Transition; +use crate::common::Warping; use crate::edit::apply_map_edits; pub struct SelectSegments { @@ -31,12 +32,14 @@ pub struct SelectSegments { impl SelectSegments { pub fn new_state( ctx: &mut EventCtx, - app: &App, + app: &mut App, base_road: RoadID, orig_state: EditRoad, new_state: EditRoad, base_edits: MapEdits, ) -> Box> { + app.primary.current_selection = None; + // Find all road segments matching the original state and name. base_road has already // changed to new_state, so no need to exclude it. let map = &app.primary.map; @@ -101,13 +104,23 @@ impl SelectSegments { Line("Apply changes to similar roads") .small_heading() .into_widget(ctx), - format!( - "{} / {} roads similar to #{} are selected", - self.current.len(), - self.candidates.len(), - self.base_road.0 - ) - .text_widget(ctx), + Widget::row(vec![ + format!( + "{} / {} roads similar to", + self.current.len(), + self.candidates.len(), + ) + .text_widget(ctx) + .centered_vert(), + ctx.style() + .btn_plain + .icon_text( + "system/assets/tools/location.svg", + format!("#{}", self.base_road.0), + ) + .build_widget(ctx, "jump to changed road"), + "are selected".text_widget(ctx).centered_vert(), + ]), // TODO Explain that this is only for lane configuration, NOT speed limit Widget::row(vec![ "Click to select/unselect".text_widget(ctx).centered_vert(), @@ -178,6 +191,17 @@ impl State for SelectSegments { "Cancel" => { return Transition::Pop; } + "jump to changed road" => { + return Transition::Push(Warping::new_state( + ctx, + app.primary + .canonical_point(ID::Road(self.base_road)) + .unwrap(), + Some(10.0), + Some(ID::Road(self.base_road)), + &mut app.primary, + )); + } _ => unreachable!(), } } diff --git a/game/src/edit/roads.rs b/game/src/edit/roads.rs index e24839b9d6..a5d9e4e107 100644 --- a/game/src/edit/roads.rs +++ b/game/src/edit/roads.rs @@ -13,6 +13,7 @@ use widgetry::{ }; use crate::app::{App, Transition}; +use crate::common::Warping; use crate::edit::zones::ZoneEditor; use crate::edit::{apply_map_edits, can_edit_lane, speed_limit_choices}; @@ -189,6 +190,15 @@ impl State for RoadEditor { self.current_lane = None; self.recalc_all_panels(ctx, app); } + "jump to road" => { + return Transition::Push(Warping::new_state( + ctx, + app.primary.canonical_point(ID::Road(self.r)).unwrap(), + Some(10.0), + Some(ID::Road(self.r)), + &mut app.primary, + )); + } "Apply to multiple road segments" => { return Transition::Push( crate::edit::multiple_roads::SelectSegments::new_state( @@ -375,7 +385,11 @@ fn make_top_panel( Panel::new_builder(Widget::col(vec![ Widget::row(vec![ - Line("Editing road").small_heading().into_widget(ctx), + Line(format!("Edit {}", r)).small_heading().into_widget(ctx), + ctx.style() + .btn_plain + .icon("system/assets/tools/location.svg") + .build_widget(ctx, "jump to road"), ctx.style() .btn_plain .text("+ Apply to multiple")