get EditMode underneath route editor properly

This commit is contained in:
Dustin Carlino 2020-08-04 15:23:45 -07:00
parent 6f3be4463b
commit c7e0b56776
9 changed files with 25 additions and 39 deletions

View File

@ -53,13 +53,13 @@ pub struct EditMode {
}
impl EditMode {
pub fn new(ctx: &mut EventCtx, app: &mut App, mode: GameplayMode) -> EditMode {
pub fn new(ctx: &mut EventCtx, app: &mut App, mode: GameplayMode) -> Box<dyn State> {
let orig_dirty = app.primary.dirty_from_edits;
assert!(app.suspended_sim.is_none());
app.suspended_sim = Some(app.primary.clear_sim());
let edits = app.primary.map.get_edits();
let layer = crate::layer::map::Static::edits(ctx, app);
EditMode {
Box::new(EditMode {
tool_panel: tool_panel(ctx),
top_center: make_topcenter(ctx, app, &mode),
changelist: make_changelist(ctx, app),
@ -69,7 +69,7 @@ impl EditMode {
changelist_key: (edits.edits_name.clone(), edits.commands.len()),
unzoomed: layer.unzoomed,
zoomed: layer.zoomed,
}
})
}
fn quit(&self, ctx: &mut EventCtx, app: &mut App) -> Transition {

View File

@ -67,15 +67,6 @@ impl State for RouteEditor {
});
apply_map_edits(ctx, app, edits);
// TODO Hacks because we don't have an EditMode underneath us yet
app.primary.dirty_from_edits = true;
ctx.loading_screen("apply edits", |_, mut timer| {
app.primary
.map
.recalculate_pathfinding_after_edits(&mut timer);
});
// TODO Ah and actually we need to reset the sim and everything.
return Transition::Pop;
}
_ => unreachable!(),

View File

@ -9,10 +9,10 @@ mod trip;
use crate::app::App;
use crate::common::Warping;
use crate::edit::RouteEditor;
use crate::edit::{EditMode, RouteEditor};
use crate::game::Transition;
use crate::helpers::{color_for_agent_type, copy_to_clipboard, hotkey_btn, ID};
use crate::sandbox::{SandboxMode, TimeWarpScreen};
use crate::sandbox::{GameplayMode, SandboxMode, TimeWarpScreen};
use ezgui::{
hotkey, Btn, Checkbox, Color, Composite, Drawable, EventCtx, GeomBatch, GfxCtx,
HorizontalAlignment, Key, Line, LinePlot, Outcome, PlotOptions, Series, TextExt,
@ -555,14 +555,12 @@ impl InfoPanel {
}
return (false, None);
} else if let Some(x) = action.strip_prefix("edit BusRoute #") {
// TODO Push EditMode too for consistency, but how to get at GameplayMode?
return (
false,
Some(Transition::Push(RouteEditor::new(
ctx,
app,
BusRouteID(x.parse::<usize>().unwrap()),
))),
Some(Transition::PushTwice(
EditMode::new(ctx, app, ctx_actions.gameplay_mode()),
RouteEditor::new(ctx, app, BusRouteID(x.parse::<usize>().unwrap())),
)),
);
} else {
let mut close_panel = true;
@ -700,6 +698,9 @@ pub trait ContextualActions {
// Slightly weird way to plumb in extra info, but...
fn is_paused(&self) -> bool;
fn gameplay_mode(&self) -> GameplayMode {
unreachable!()
}
}
#[derive(Clone, PartialEq)]

View File

@ -169,11 +169,7 @@ impl GameplayState for OptimizeCommute {
match self.top_center.event(ctx) {
Outcome::Clicked(x) => match x.as_ref() {
"edit map" => {
return Some(Transition::Push(Box::new(EditMode::new(
ctx,
app,
self.mode.clone(),
))));
return Some(Transition::Push(EditMode::new(ctx, app, self.mode.clone())));
}
"instructions" => {
let contents = (cutscene_task(&self.mode))(ctx);

View File

@ -193,11 +193,7 @@ impl GameplayState for FixTrafficSignals {
match self.top_center.event(ctx) {
Outcome::Clicked(x) => match x.as_ref() {
"edit map" => {
return Some(Transition::Push(Box::new(EditMode::new(
ctx,
app,
self.mode.clone(),
))));
return Some(Transition::Push(EditMode::new(ctx, app, self.mode.clone())));
}
"instructions" => {
let contents = cutscene_pt1_task(ctx);

View File

@ -63,11 +63,11 @@ impl GameplayState for Freeform {
self.top_center.rect_of("change traffic").clone(),
"none".to_string(),
))),
"edit map" => Some(Transition::Push(Box::new(EditMode::new(
"edit map" => Some(Transition::Push(EditMode::new(
ctx,
app,
GameplayMode::Freeform(abstutil::path_map(app.primary.map.get_name())),
)))),
))),
"Start a new trip" => Some(Transition::Push(AgentSpawner::new(ctx, None))),
_ => unreachable!(),
},

View File

@ -74,7 +74,7 @@ impl GameplayState for PlayScenario {
self.top_center.rect_of("change traffic").clone(),
self.scenario_name.clone(),
))),
"edit map" => Some(Transition::Push(Box::new(EditMode::new(
"edit map" => Some(Transition::Push(EditMode::new(
ctx,
app,
GameplayMode::PlayScenario(
@ -82,7 +82,7 @@ impl GameplayState for PlayScenario {
self.scenario_name.clone(),
self.modifiers.clone(),
),
)))),
))),
"edit traffic patterns" => Some(Transition::Push(EditScenarioModifiers::new(
ctx,
self.scenario_name.clone(),

View File

@ -123,7 +123,7 @@ impl Tutorial {
// TODO Ideally this would be an inactive button in message states
if self.msg_panel.is_none() {
let mode = GameplayMode::Tutorial(tut.current);
return Some(Transition::Push(Box::new(EditMode::new(ctx, app, mode))));
return Some(Transition::Push(EditMode::new(ctx, app, mode)));
}
}
_ => unreachable!(),

View File

@ -447,11 +447,11 @@ impl ContextualActions for Actions {
Transition::Push(ShowTrafficSignal::new(ctx, app, i))
}
(ID::Intersection(i), "edit traffic signal") => Transition::PushTwice(
Box::new(EditMode::new(ctx, app, self.gameplay.clone())),
EditMode::new(ctx, app, self.gameplay.clone()),
Box::new(TrafficSignalEditor::new(ctx, app, i, self.gameplay.clone())),
),
(ID::Intersection(i), "edit stop sign") => Transition::PushTwice(
Box::new(EditMode::new(ctx, app, self.gameplay.clone())),
EditMode::new(ctx, app, self.gameplay.clone()),
Box::new(StopSignEditor::new(ctx, app, i, self.gameplay.clone())),
),
(ID::Intersection(i), "explore uber-turns") => {
@ -461,7 +461,7 @@ impl ContextualActions for Actions {
Transition::Push(TurnExplorer::new(ctx, app, l))
}
(ID::Lane(l), "edit lane") => Transition::PushTwice(
Box::new(EditMode::new(ctx, app, self.gameplay.clone())),
EditMode::new(ctx, app, self.gameplay.clone()),
Box::new(LaneEditor::new(ctx, app, l, self.gameplay.clone())),
),
(ID::Building(b), "explore isochrone from here") => {
@ -490,8 +490,10 @@ impl ContextualActions for Actions {
.execute(ctx, app, id, action.to_string(), close_panel),
}
}
fn is_paused(&self) -> bool {
self.is_paused
}
fn gameplay_mode(&self) -> GameplayMode {
self.gameplay.clone()
}
}