mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-29 12:43:38 +03:00
reset edits when leaving sandbox mode
This commit is contained in:
parent
c0fea0811f
commit
c7fbaaf7e1
@ -5,16 +5,19 @@ mod score;
|
|||||||
|
|
||||||
use crate::common::{time_controls, AgentTools, CommonState, SpeedControls};
|
use crate::common::{time_controls, AgentTools, CommonState, SpeedControls};
|
||||||
use crate::debug::DebugMode;
|
use crate::debug::DebugMode;
|
||||||
|
use crate::edit::apply_map_edits;
|
||||||
use crate::edit::EditMode;
|
use crate::edit::EditMode;
|
||||||
use crate::game::{msg, State, Transition, WizardState};
|
use crate::game::{msg, State, Transition, WizardState};
|
||||||
use crate::helpers::ID;
|
use crate::helpers::ID;
|
||||||
use crate::ui::{ShowEverything, UI};
|
use crate::ui::{ShowEverything, UI};
|
||||||
|
use abstutil::Timer;
|
||||||
use ezgui::{
|
use ezgui::{
|
||||||
hotkey, layout, lctrl, Choice, EventCtx, EventLoopMode, GfxCtx, Key, Line, MenuUnderButton,
|
hotkey, layout, lctrl, Choice, EventCtx, EventLoopMode, GfxCtx, Key, Line, MenuUnderButton,
|
||||||
ModalMenu, Text, Wizard,
|
ModalMenu, Text, Wizard,
|
||||||
};
|
};
|
||||||
pub use gameplay::GameplayMode;
|
pub use gameplay::GameplayMode;
|
||||||
use geom::Duration;
|
use geom::Duration;
|
||||||
|
use map_model::MapEdits;
|
||||||
use sim::Sim;
|
use sim::Sim;
|
||||||
|
|
||||||
pub struct SandboxMode {
|
pub struct SandboxMode {
|
||||||
@ -163,13 +166,29 @@ impl State for SandboxMode {
|
|||||||
choices
|
choices
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
|
let map_name = ui.primary.map.get_name().to_string();
|
||||||
match resp.as_str() {
|
match resp.as_str() {
|
||||||
"save edits and quit" => {
|
"save edits and quit" => {
|
||||||
ui.primary.map.save_edits();
|
ui.primary.map.save_edits();
|
||||||
|
// Always reset edits if we just saved edits.
|
||||||
|
apply_map_edits(&mut ui.primary, &ui.cs, ctx, MapEdits::new(map_name));
|
||||||
|
ui.primary.map.mark_edits_fresh();
|
||||||
|
ui.primary
|
||||||
|
.map
|
||||||
|
.recalculate_pathfinding_after_edits(&mut Timer::new("reset edits"));
|
||||||
ui.primary.clear_sim();
|
ui.primary.clear_sim();
|
||||||
Some(Transition::PopTwice)
|
Some(Transition::PopTwice)
|
||||||
}
|
}
|
||||||
"quit challenge" => {
|
"quit challenge" => {
|
||||||
|
if !ui.primary.map.get_edits().is_empty() {
|
||||||
|
apply_map_edits(&mut ui.primary, &ui.cs, ctx, MapEdits::new(map_name));
|
||||||
|
ui.primary.map.mark_edits_fresh();
|
||||||
|
ui.primary
|
||||||
|
.map
|
||||||
|
.recalculate_pathfinding_after_edits(&mut Timer::new(
|
||||||
|
"reset edits",
|
||||||
|
));
|
||||||
|
}
|
||||||
ui.primary.clear_sim();
|
ui.primary.clear_sim();
|
||||||
Some(Transition::PopTwice)
|
Some(Transition::PopTwice)
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,10 @@ impl MapEdits {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.edits_name == "no_edits" && self.commands.is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn load(map_name: &str, edits_name: &str, timer: &mut Timer) -> MapEdits {
|
pub fn load(map_name: &str, edits_name: &str, timer: &mut Timer) -> MapEdits {
|
||||||
if edits_name == "no_edits" {
|
if edits_name == "no_edits" {
|
||||||
return MapEdits::new(map_name.to_string());
|
return MapEdits::new(map_name.to_string());
|
||||||
|
Loading…
Reference in New Issue
Block a user