Skip to content

Commit

Permalink
Improve intersection merging workflow by hiding popup msg for success…
Browse files Browse the repository at this point in the history
…ful imports #654
  • Loading branch information
dabreegster committed Jul 11, 2021
1 parent 2224dcc commit e750048
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion game/src/debug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ fn draw_arterial_crosswalks(ctx: &mut EventCtx, app: &App) -> Drawable {
fn reimport_map(ctx: &mut EventCtx, app: &App) -> Box<dyn State<App>> {
RunCommand::new_state(
ctx,
app,
false,
vec![
find_exe("importer"),
"--map".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion game/src/sandbox/gameplay/freeform/importers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn import_grid2demand(ctx: &mut EventCtx) -> Transition {
if let Ok(Some(path)) = maybe_path {
Transition::Replace(RunCommand::new_state(
ctx,
app,
true,
vec![
find_exe("import_grid2demand"),
format!("--map={}", app.primary.map.get_name().path()),
Expand Down
15 changes: 10 additions & 5 deletions map_gui/src/tools/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct RunCommand<A: AppLike> {
max_capacity: usize,
started: Instant,
last_drawn: Instant,
show_success_popup: bool,
// Wrapped in an Option just to make calling from event() work. The bool is success, and the
// strings are the last lines of output.
on_load: Option<Box<dyn FnOnce(&mut EventCtx, &mut A, bool, Vec<String>) -> Transition<A>>>,
Expand All @@ -28,7 +29,7 @@ pub struct RunCommand<A: AppLike> {
impl<A: AppLike + 'static> RunCommand<A> {
pub fn new_state(
ctx: &mut EventCtx,
_: &A,
show_success_popup: bool,
args: Vec<String>,
on_load: Box<dyn FnOnce(&mut EventCtx, &mut A, bool, Vec<String>) -> Transition<A>>,
) -> Box<dyn State<A>> {
Expand Down Expand Up @@ -57,6 +58,7 @@ impl<A: AppLike + 'static> RunCommand<A> {
max_capacity,
started: Instant::now(),
last_drawn: Instant::now(),
show_success_popup,
on_load: Some(on_load),
})
}
Expand Down Expand Up @@ -150,15 +152,18 @@ impl<A: AppLike + 'static> State<A> for RunCommand<A> {
if !success {
lines.push(format!("Command failed: {:?}", status));
}
return Transition::Multi(vec![
let mut transitions = vec![
Transition::Pop,
(self.on_load.take().unwrap())(ctx, app, success, lines.clone()),
Transition::Push(PopupMsg::new_state(
];
if !success || self.show_success_popup {
transitions.push(Transition::Push(PopupMsg::new_state(
ctx,
if success { "Success!" } else { "Failure!" },
lines,
)),
]);
)));
}
return Transition::Multi(transitions);
}

Transition::Keep
Expand Down
4 changes: 2 additions & 2 deletions map_gui/src/tools/importer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl<A: AppLike + 'static> ImportCity<A> {
}

impl<A: AppLike + 'static> State<A> for ImportCity<A> {
fn event(&mut self, ctx: &mut EventCtx, app: &mut A) -> Transition<A> {
fn event(&mut self, ctx: &mut EventCtx, _: &mut A) -> Transition<A> {
match self.panel.event(ctx) {
Outcome::Clicked(x) => match x.as_ref() {
"close" => Transition::Pop,
Expand All @@ -106,7 +106,7 @@ impl<A: AppLike + 'static> State<A> for ImportCity<A> {
match grab_geojson_from_clipboard() {
Ok(()) => Transition::Push(crate::tools::RunCommand::new_state(
ctx,
app,
true,
args,
Box::new(|_, _, success, mut lines| {
if success {
Expand Down

0 comments on commit e750048

Please sign in to comment.