diff --git a/Cargo.lock b/Cargo.lock index b0bb8c25c9..aafaae0f34 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1333,7 +1333,6 @@ dependencies = [ "popdat", "rand", "rand_xorshift", - "rfd", "serde", "serde_json", "sim", @@ -2303,6 +2302,7 @@ dependencies = [ "js-sys", "log", "map_model", + "rfd", "serde", "sim", "subprocess", diff --git a/game/Cargo.toml b/game/Cargo.toml index 80d35002d4..ef67748573 100644 --- a/game/Cargo.toml +++ b/game/Cargo.toml @@ -43,7 +43,6 @@ petname = "1.1.0" popdat = { path = "../popdat" } rand = "0.8.3" rand_xorshift = "0.3.0" -rfd = "0.2.2" serde = "1.0.123" serde_json = "1.0.61" svg_face = "0.1.3" diff --git a/game/src/app.rs b/game/src/app.rs index 7b38a4af82..fdef2e967b 100644 --- a/game/src/app.rs +++ b/game/src/app.rs @@ -764,6 +764,7 @@ pub struct SessionState { pub tutorial: Option, pub high_scores: BTreeMap>, pub info_panel_tab: BTreeMap<&'static str, &'static str>, + pub last_gmns_timing_csv: Option, } impl SessionState { @@ -778,6 +779,7 @@ impl SessionState { "person" => "trips", "bus" => "status", }, + last_gmns_timing_csv: None, } } } diff --git a/game/src/devtools/kml.rs b/game/src/devtools/kml.rs index ae454b50a7..8ff9221162 100644 --- a/game/src/devtools/kml.rs +++ b/game/src/devtools/kml.rs @@ -8,8 +8,7 @@ use abstutil::{prettyprint_usize, Parallelism, Timer}; use geom::{Circle, Distance, PolyLine, Polygon, Pt2D, Ring}; use kml::{ExtraShape, ExtraShapes}; use map_gui::colors::ColorScheme; -use map_gui::load::FutureLoader; -use map_gui::tools::PopupMsg; +use map_gui::tools::{FilePicker, PopupMsg}; use map_model::BuildingID; use widgetry::{ lctrl, Choice, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, @@ -403,24 +402,9 @@ fn make_query(app: &App, objects: &[Object], query: &str) -> (GeomBatch, usize) } fn pick_file(ctx: &mut EventCtx, app: &App) -> Transition { - let (_, outer_progress_rx) = futures_channel::mpsc::channel(1); - let (_, inner_progress_rx) = futures_channel::mpsc::channel(1); - let start_dir = app.primary.map.get_city_name().input_path(""); - Transition::Push(FutureLoader::>::new_state( + Transition::Push(FilePicker::new_state( ctx, - Box::pin(async move { - let result = rfd::AsyncFileDialog::new() - .set_directory(&start_dir) - .pick_file() - .await - .map(|x| x.path().display().to_string()); - let wrap: Box Option> = - Box::new(move |_: &App| result); - Ok(wrap) - }), - outer_progress_rx, - inner_progress_rx, - "Waiting for a file to be chosen", + Some(app.primary.map.get_city_name().input_path("")), Box::new(|ctx, app, maybe_path| { if let Ok(Some(path)) = maybe_path { Transition::Multi(vec![ diff --git a/game/src/sandbox/gameplay/freeform/grid2demand.rs b/game/src/sandbox/gameplay/freeform/grid2demand.rs index b5475506af..fe5df24d12 100644 --- a/game/src/sandbox/gameplay/freeform/grid2demand.rs +++ b/game/src/sandbox/gameplay/freeform/grid2demand.rs @@ -1,30 +1,16 @@ // TODO This doesn't really belong in gameplay/freeform -use map_gui::load::FutureLoader; -use map_gui::tools::{find_exe, RunCommand}; +use map_gui::tools::{find_exe, FilePicker, RunCommand}; use widgetry::EventCtx; -use crate::app::{App, Transition}; +use crate::app::Transition; use crate::sandbox::gameplay::GameplayMode; use crate::sandbox::SandboxMode; pub fn import(ctx: &mut EventCtx) -> Transition { - let (_, outer_progress_rx) = futures_channel::mpsc::channel(1); - let (_, inner_progress_rx) = futures_channel::mpsc::channel(1); - Transition::Push(FutureLoader::>::new_state( + Transition::Push(FilePicker::new_state( ctx, - Box::pin(async { - let result = rfd::AsyncFileDialog::new() - .pick_file() - .await - .map(|x| x.path().display().to_string()); - let wrap: Box Option> = - Box::new(move |_: &App| result); - Ok(wrap) - }), - outer_progress_rx, - inner_progress_rx, - "Waiting for a file to be chosen", + None, Box::new(|ctx, app, maybe_path| { if let Ok(Some(path)) = maybe_path { Transition::Replace(RunCommand::new_state( diff --git a/map_gui/Cargo.toml b/map_gui/Cargo.toml index 5d69503a70..41f1c5e0e2 100644 --- a/map_gui/Cargo.toml +++ b/map_gui/Cargo.toml @@ -27,6 +27,7 @@ instant = "0.1.7" js-sys = { version = "0.3.47", optional = true } log = "0.4.14" map_model = { path = "../map_model" } +rfd = "0.2.2" serde = "1.0.123" sim = { path = "../sim" } subprocess = { git = "https://github.com/hniksic/rust-subprocess", optional = true } diff --git a/map_gui/src/tools/mod.rs b/map_gui/src/tools/mod.rs index fce598c4d5..d0dbf3b14f 100644 --- a/map_gui/src/tools/mod.rs +++ b/map_gui/src/tools/mod.rs @@ -12,7 +12,7 @@ pub use self::icons::{goal_marker, start_marker}; pub use self::minimap::{Minimap, MinimapControls}; pub use self::navigate::Navigator; pub use self::turn_explorer::TurnExplorer; -pub use self::ui::{ChooseSomething, PopupMsg, PromptInput}; +pub use self::ui::{ChooseSomething, FilePicker, PopupMsg, PromptInput}; pub use self::url::URLManager; use crate::AppLike; diff --git a/map_gui/src/tools/ui.rs b/map_gui/src/tools/ui.rs index 98546fed34..8a56b1d566 100644 --- a/map_gui/src/tools/ui.rs +++ b/map_gui/src/tools/ui.rs @@ -1,10 +1,13 @@ //! Generic UI tools. Some of this should perhaps be lifted to widgetry. +use anyhow::Result; + use widgetry::{ hotkeys, Choice, DrawBaselayer, Drawable, EventCtx, GfxCtx, Key, Line, Menu, Outcome, Panel, State, Text, TextBox, Transition, Widget, }; +use crate::load::FutureLoader; use crate::tools::grey_out_map; use crate::AppLike; @@ -209,3 +212,36 @@ impl State for PopupMsg { } } } + +pub struct FilePicker; + +impl FilePicker { + pub fn new_state( + ctx: &mut EventCtx, + start_dir: Option, + on_load: Box>) -> Transition>, + ) -> Box> { + let (_, outer_progress_rx) = futures_channel::mpsc::channel(1); + let (_, inner_progress_rx) = futures_channel::mpsc::channel(1); + FutureLoader::>::new_state( + ctx, + Box::pin(async move { + let mut builder = rfd::AsyncFileDialog::new(); + if let Some(dir) = start_dir { + builder = builder.set_directory(&dir); + } + let result = builder + .pick_file() + .await + .map(|x| x.path().display().to_string()); + let wrap: Box Option> = + Box::new(move |_: &A| result); + Ok(wrap) + }), + outer_progress_rx, + inner_progress_rx, + "Waiting for a file to be chosen", + on_load, + ) + } +}