mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 07:25:47 +03:00
Handle the info panel rewind-sim case for #367. I'm increasingly happier
with how the async reactions to loading SandboxMode are.
This commit is contained in:
parent
81dae1e39c
commit
e7fb9b1a4a
@ -527,30 +527,35 @@ impl InfoPanel {
|
||||
let trip = *trip;
|
||||
let time = *time;
|
||||
let person = app.primary.sim.trip_to_person(trip);
|
||||
// When executed, this assumes the SandboxMode is the top of the stack. It'll
|
||||
// reopen the info panel, then launch the jump-to-time UI.
|
||||
let jump_to_time =
|
||||
Transition::ReplaceWithData(Box::new(move |state, ctx, app| {
|
||||
let mut sandbox = state.downcast::<SandboxMode>().ok().unwrap();
|
||||
|
||||
let mut actions = sandbox.contextual_actions();
|
||||
sandbox.controls.common.as_mut().unwrap().launch_info_panel(
|
||||
ctx,
|
||||
app,
|
||||
Tab::PersonTrips(person, OpenTrip::single(trip)),
|
||||
&mut actions,
|
||||
);
|
||||
|
||||
vec![sandbox, TimeWarpScreen::new(ctx, app, time, None)]
|
||||
}));
|
||||
|
||||
if time >= app.primary.sim.time() {
|
||||
return (false, Some(jump_to_time));
|
||||
}
|
||||
|
||||
// We need to first rewind the simulation
|
||||
(
|
||||
false,
|
||||
Some(Transition::ReplaceWithData(Box::new(
|
||||
move |mut state, ctx, app| {
|
||||
if time < app.primary.sim.time() {
|
||||
let gameplay =
|
||||
state.downcast::<SandboxMode>().ok().unwrap().gameplay_mode;
|
||||
state = ctx.loading_screen("rewind simulation", |ctx, _| {
|
||||
SandboxMode::new(ctx, app, gameplay)
|
||||
});
|
||||
}
|
||||
let mut sandbox = state.downcast::<SandboxMode>().ok().unwrap();
|
||||
|
||||
let mut actions = sandbox.contextual_actions();
|
||||
sandbox.controls.common.as_mut().unwrap().launch_info_panel(
|
||||
ctx,
|
||||
app,
|
||||
Tab::PersonTrips(person, OpenTrip::single(trip)),
|
||||
&mut actions,
|
||||
);
|
||||
|
||||
vec![sandbox, TimeWarpScreen::new(ctx, app, time, None)]
|
||||
},
|
||||
Some(Transition::Replace(SandboxMode::async_new(
|
||||
ctx,
|
||||
app,
|
||||
ctx_actions.gameplay_mode(),
|
||||
Box::new(move |_, _| vec![jump_to_time]),
|
||||
))),
|
||||
)
|
||||
} else if let Some(url) = action.strip_prefix("open ") {
|
||||
|
@ -63,13 +63,13 @@ impl SandboxMode {
|
||||
_: &mut EventCtx,
|
||||
app: &mut App,
|
||||
mode: GameplayMode,
|
||||
finalize: Box<dyn Fn(&mut EventCtx, &mut App) -> Vec<Transition>>,
|
||||
finalize: Box<dyn FnOnce(&mut EventCtx, &mut App) -> Vec<Transition>>,
|
||||
) -> Box<dyn State> {
|
||||
app.primary.clear_sim();
|
||||
Box::new(SandboxLoader {
|
||||
stage: Some(LoadStage::LoadingMap),
|
||||
mode,
|
||||
finalize,
|
||||
finalize: Some(finalize),
|
||||
})
|
||||
}
|
||||
|
||||
@ -518,7 +518,7 @@ struct SandboxLoader {
|
||||
// Always exists, just a way to avoid clones
|
||||
stage: Option<LoadStage>,
|
||||
mode: GameplayMode,
|
||||
finalize: Box<dyn Fn(&mut EventCtx, &mut App) -> Vec<Transition>>,
|
||||
finalize: Option<Box<dyn FnOnce(&mut EventCtx, &mut App) -> Vec<Transition>>>,
|
||||
}
|
||||
|
||||
impl State for SandboxLoader {
|
||||
@ -694,7 +694,7 @@ impl State for SandboxLoader {
|
||||
});
|
||||
|
||||
let mut transitions = vec![Transition::Replace(sandbox)];
|
||||
transitions.extend((self.finalize)(ctx, app));
|
||||
transitions.extend((self.finalize.take().unwrap())(ctx, app));
|
||||
return Transition::Multi(transitions);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user