Save/restore camera state per map in all map_gui apps too.

This commit is contained in:
Dustin Carlino 2020-11-24 11:53:50 -08:00
parent 61cd74767a
commit 314f01496e
2 changed files with 11 additions and 3 deletions

View File

@ -270,7 +270,6 @@ pub fn maybe_exit_sandbox(ctx: &mut EventCtx) -> Transition {
return Transition::Pop;
}
ctx.canvas.save_camera_state(app.primary.map.get_name());
if app.primary.map.unsaved_edits() {
return Transition::Multi(vec![
Transition::Push(Box::new(BackToMainMenu)),

View File

@ -2,7 +2,7 @@ use abstutil::{CmdArgs, Timer};
use geom::{Circle, Distance, Duration, Pt2D, Time};
use map_model::{IntersectionID, Map};
use sim::Sim;
use widgetry::{EventCtx, GfxCtx, SharedAppState, State, Transition, Warper};
use widgetry::{Canvas, EventCtx, GfxCtx, SharedAppState, State, Transition, Warper};
use crate::colors::ColorScheme;
use crate::options::Options;
@ -32,7 +32,7 @@ impl SimpleApp {
let cs = ColorScheme::new(ctx, opts.color_scheme);
let map = Map::new(map_path, &mut timer);
let draw_map = DrawMap::new(ctx, &map, &opts, &cs, timer);
// TODO Should we refactor the whole camera state / initial focusing thing?
ctx.canvas.load_camera_state(map.get_name());
SimpleApp {
map,
draw_map,
@ -221,6 +221,7 @@ impl AppLike for SimpleApp {
ctx.canvas.save_camera_state(self.map().get_name());
self.map = map;
self.draw_map = DrawMap::new(ctx, &self.map, &self.opts, &self.cs, timer);
ctx.canvas.load_camera_state(self.map.get_name());
}
fn draw_with_opts(&self, g: &mut GfxCtx, opts: DrawOptions) {
@ -261,6 +262,14 @@ impl SharedAppState for SimpleApp {
fn draw_default(&self, g: &mut GfxCtx) {
self.draw_with_opts(g, DrawOptions::new());
}
fn dump_before_abort(&self, canvas: &Canvas) {
canvas.save_camera_state(&self.map.get_name());
}
fn before_quit(&self, canvas: &Canvas) {
canvas.save_camera_state(&self.map.get_name());
}
}
struct SimpleWarper {