From b7f09fb300827f324de5ea3b1f2e29572711e65d Mon Sep 17 00:00:00 2001 From: Nigel Lee Date: Wed, 20 Sep 2023 09:34:32 +0800 Subject: [PATCH 01/24] feat: add actions and transitions --- apps/game/src/sandbox/mod.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/game/src/sandbox/mod.rs b/apps/game/src/sandbox/mod.rs index fa0fb788cb..81c64be292 100644 --- a/apps/game/src/sandbox/mod.rs +++ b/apps/game/src/sandbox/mod.rs @@ -338,6 +338,7 @@ impl ContextualActions for Actions { } else { actions.push((Key::F, "add this building to favorites".to_string())); } + actions.push((Key::E, "edit the parking of this building".to_string())) } _ => {} } @@ -396,6 +397,12 @@ impl ContextualActions for Actions { app.primary.layer = Some(Box::new(ShowFavorites::new(ctx, app))); Transition::Keep } + (ID::Building(b), "edit the parking of this building") => { + Transition::Multi(vec![ + Transition::Push(EditMode::new_state(ctx, app, self.gameplay.clone())), + // TODO Building editor + ]) + } (_, "follow (run the simulation)") => { *close_panel = false; Transition::ModifyState(Box::new(|state, ctx, app| { From b50b9f8cb0bf9fbbdffff2d1a8b65a607c363396 Mon Sep 17 00:00:00 2001 From: Nigel Lee Date: Wed, 20 Sep 2023 09:45:28 +0800 Subject: [PATCH 02/24] feat: boilerplate for building editor --- apps/game/src/edit/buildings.rs | 32 ++++++++++++++++++++++++++++++++ apps/game/src/edit/mod.rs | 2 ++ apps/game/src/sandbox/mod.rs | 13 ++++++------- 3 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 apps/game/src/edit/buildings.rs diff --git a/apps/game/src/edit/buildings.rs b/apps/game/src/edit/buildings.rs new file mode 100644 index 0000000000..b5bf749279 --- /dev/null +++ b/apps/game/src/edit/buildings.rs @@ -0,0 +1,32 @@ +use map_model::BuildingID; +use widgetry::{EventCtx, State}; + +use crate::app::{App, Transition}; + +pub struct BuildingEditor { + +} + +impl BuildingEditor { + pub fn new_state(ctx: &mut EventCtx, app: &mut App, b: BuildingID) -> Box> { + BuildingEditor::create(ctx, app, b) + } + + fn create( + ctx: &mut EventCtx, + app: &mut App, + b: BuildingID, + ) -> Box> { + todo!() + } +} + +impl State for BuildingEditor { + fn event(&mut self, ctx: &mut EventCtx, shared_app_state: &mut App) -> Transition { + todo!() + } + + fn draw(&self, g: &mut widgetry::GfxCtx, shared_app_state: &App) { + todo!() + } +} \ No newline at end of file diff --git a/apps/game/src/edit/mod.rs b/apps/game/src/edit/mod.rs index 33b1824cfc..692b932fde 100644 --- a/apps/game/src/edit/mod.rs +++ b/apps/game/src/edit/mod.rs @@ -15,6 +15,7 @@ use widgetry::{ }; pub use self::roads::RoadEditor; +pub use self::buildings::BuildingEditor; pub use self::routes::RouteEditor; pub use self::stop_signs::StopSignEditor; pub use self::traffic_signals::TrafficSignalEditor; @@ -27,6 +28,7 @@ use crate::sandbox::{GameplayMode, SandboxMode, TimeWarpScreen}; mod crosswalks; mod multiple_roads; mod roads; +mod buildings; mod routes; mod stop_signs; mod traffic_signals; diff --git a/apps/game/src/sandbox/mod.rs b/apps/game/src/sandbox/mod.rs index 81c64be292..c26f50c178 100644 --- a/apps/game/src/sandbox/mod.rs +++ b/apps/game/src/sandbox/mod.rs @@ -21,7 +21,8 @@ use crate::app::{App, Transition}; use crate::common::{tool_panel, CommonState}; use crate::debug::DebugMode; use crate::edit::{ - can_edit_lane, EditMode, RoadEditor, SaveEdits, StopSignEditor, TrafficSignalEditor, + can_edit_lane, BuildingEditor, EditMode, RoadEditor, SaveEdits, StopSignEditor, + TrafficSignalEditor, }; use crate::info::ContextualActions; use crate::layer::favorites::{Favorites, ShowFavorites}; @@ -397,12 +398,10 @@ impl ContextualActions for Actions { app.primary.layer = Some(Box::new(ShowFavorites::new(ctx, app))); Transition::Keep } - (ID::Building(b), "edit the parking of this building") => { - Transition::Multi(vec![ - Transition::Push(EditMode::new_state(ctx, app, self.gameplay.clone())), - // TODO Building editor - ]) - } + (ID::Building(b), "edit the parking of this building") => Transition::Multi(vec![ + Transition::Push(EditMode::new_state(ctx, app, self.gameplay.clone())), + Transition::Push(BuildingEditor::new_state(ctx, app, b)), + ]), (_, "follow (run the simulation)") => { *close_panel = false; Transition::ModifyState(Box::new(|state, ctx, app| { From 1462e26f91cf053e900c67bee6ac221172e8c9e0 Mon Sep 17 00:00:00 2001 From: Nigel Lee Date: Wed, 20 Sep 2023 10:35:10 +0800 Subject: [PATCH 03/24] feat: add building editor --- apps/game/src/edit/buildings.rs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/apps/game/src/edit/buildings.rs b/apps/game/src/edit/buildings.rs index b5bf749279..bb1655f7b0 100644 --- a/apps/game/src/edit/buildings.rs +++ b/apps/game/src/edit/buildings.rs @@ -1,10 +1,15 @@ -use map_model::BuildingID; +use map_model::{BuildingID, EditCmd}; use widgetry::{EventCtx, State}; use crate::app::{App, Transition}; pub struct BuildingEditor { + b: BuildingID, + // Undo/redo management + num_edit_cmds_originally: usize, + redo_stack: Vec, + orig_building_state: EditBuilding, } impl BuildingEditor { @@ -12,13 +17,19 @@ impl BuildingEditor { BuildingEditor::create(ctx, app, b) } - fn create( - ctx: &mut EventCtx, - app: &mut App, - b: BuildingID, - ) -> Box> { - todo!() - } + fn create(ctx: &mut EventCtx, app: &mut App, b: BuildingID) -> Box> { + app.primary.current_selection = None; + + let mut editor = BuildingEditor { + b, + + num_edit_cmds_originally: app.primary.map.get_edits().commands.len(), + redo_stack: Vec::new(), + orig_building_state: app.primary.map.get_b_edit(b), // TODO + }; + // TODO recalc panels? + Box::new(editor) + } } impl State for BuildingEditor { @@ -29,4 +40,4 @@ impl State for BuildingEditor { fn draw(&self, g: &mut widgetry::GfxCtx, shared_app_state: &App) { todo!() } -} \ No newline at end of file +} From 28c7da7357ed6f69933401f9e323d030ce62cf37 Mon Sep 17 00:00:00 2001 From: Nigel Lee Date: Wed, 20 Sep 2023 10:35:37 +0800 Subject: [PATCH 04/24] feat: cmd_to_id --- apps/game/src/edit/mod.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/game/src/edit/mod.rs b/apps/game/src/edit/mod.rs index 692b932fde..5ef6c8b2d7 100644 --- a/apps/game/src/edit/mod.rs +++ b/apps/game/src/edit/mod.rs @@ -14,8 +14,8 @@ use widgetry::{ Menu, Outcome, Panel, State, Text, TextBox, TextExt, VerticalAlignment, Widget, }; -pub use self::roads::RoadEditor; pub use self::buildings::BuildingEditor; +pub use self::roads::RoadEditor; pub use self::routes::RouteEditor; pub use self::stop_signs::StopSignEditor; pub use self::traffic_signals::TrafficSignalEditor; @@ -25,10 +25,10 @@ use crate::common::{tool_panel, CommonState, Warping}; use crate::debug::DebugMode; use crate::sandbox::{GameplayMode, SandboxMode, TimeWarpScreen}; +mod buildings; mod crosswalks; mod multiple_roads; mod roads; -mod buildings; mod routes; mod stop_signs; mod traffic_signals; @@ -942,6 +942,7 @@ fn cmd_to_id(cmd: &EditCmd) -> Option { EditCmd::ChangeRoad { r, .. } => Some(ID::Road(*r)), EditCmd::ChangeIntersection { i, .. } => Some(ID::Intersection(*i)), EditCmd::ChangeRouteSchedule { .. } => None, + EditCmd::ChangeBuilding { b, .. } => Some(ID::Building(*b)), } } From 55f1714dd21bfa0735e741c50968e4a12685a6ee Mon Sep 17 00:00:00 2001 From: Nigel Lee Date: Wed, 20 Sep 2023 10:38:19 +0800 Subject: [PATCH 05/24] feat: edit building --- map_model/src/edits/mod.rs | 52 +++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/map_model/src/edits/mod.rs b/map_model/src/edits/mod.rs index 1c0b04a337..592bf1434e 100644 --- a/map_model/src/edits/mod.rs +++ b/map_model/src/edits/mod.rs @@ -13,9 +13,9 @@ use osm2streets::{get_lane_specs_ltr, RestrictionType}; pub use self::perma::PermanentMapEdits; use crate::{ - AccessRestrictions, ControlStopSign, ControlTrafficSignal, Crossing, DiagonalFilter, - IntersectionControl, IntersectionID, LaneID, LaneSpec, Map, MapConfig, ParkingLotID, Road, - RoadFilter, RoadID, TransitRouteID, TurnID, TurnType, + AccessRestrictions, BuildingID, ControlStopSign, ControlTrafficSignal, Crossing, + DiagonalFilter, IntersectionControl, IntersectionID, LaneID, LaneSpec, Map, MapConfig, + OffstreetParking, ParkingLotID, Road, RoadFilter, RoadID, TransitRouteID, TurnID, TurnType, }; mod apply; @@ -36,6 +36,7 @@ pub struct MapEdits { pub original_roads: BTreeMap, pub original_intersections: BTreeMap, pub changed_routes: BTreeSet, + pub original_buildings: BTreeMap, /// Some edits are included in the game by default, in data/system/proposals, as "community /// proposals." They require a description and may have a link to a write-up. @@ -60,6 +61,11 @@ pub enum EditCmd { old: Vec