mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-24 23:15:24 +03:00
Start a native-only UI to run the one-step importer. #523
This commit is contained in:
parent
ac297f75c4
commit
607ccd0e78
@ -10,7 +10,7 @@ use widgetry::{
|
||||
|
||||
use crate::load::{FileLoader, MapLoader};
|
||||
use crate::render::DrawArea;
|
||||
use crate::tools::{grey_out_map, nice_country_name, nice_map_name, open_browser};
|
||||
use crate::tools::{grey_out_map, nice_country_name, nice_map_name};
|
||||
use crate::AppLike;
|
||||
|
||||
/// Lets the player switch maps.
|
||||
@ -159,12 +159,14 @@ impl<A: AppLike + 'static> CityPicker<A> {
|
||||
Widget::col(this_city).centered_vert(),
|
||||
]),
|
||||
Widget::custom_row(vec![
|
||||
"Don't see the city you want?"
|
||||
"Don't see the place you want?"
|
||||
.text_widget(ctx)
|
||||
.centered_vert(),
|
||||
ctx.style()
|
||||
.btn_plain
|
||||
.btn()
|
||||
// TODO On web, this is a link, so it's styled appropriately. Use a
|
||||
// different style on native?
|
||||
.label_styled_text(
|
||||
Text::from(
|
||||
Line("Import a new city into A/B Street")
|
||||
@ -218,7 +220,16 @@ impl<A: AppLike + 'static> State<A> for CityPicker<A> {
|
||||
));
|
||||
}
|
||||
"import new city" => {
|
||||
open_browser("https://a-b-street.github.io/docs/howto/new_city.html");
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
crate::tools::open_browser(
|
||||
"https://a-b-street.github.io/docs/howto/new_city.html",
|
||||
);
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
return Transition::Push(crate::tools::importer::ImportCity::new(ctx, app));
|
||||
}
|
||||
}
|
||||
"Download more cities" => {
|
||||
let _ = "just stop this from counting as an attribute on an expression";
|
||||
|
72
map_gui/src/tools/importer.rs
Normal file
72
map_gui/src/tools/importer.rs
Normal file
@ -0,0 +1,72 @@
|
||||
use widgetry::{EventCtx, Line, Panel, SimpleState, State, TextExt, Toggle, Transition, Widget};
|
||||
|
||||
use crate::tools::open_browser;
|
||||
use crate::AppLike;
|
||||
|
||||
pub struct ImportCity;
|
||||
|
||||
impl ImportCity {
|
||||
pub fn new<A: AppLike + 'static>(ctx: &mut EventCtx, _: &A) -> Box<dyn State<A>> {
|
||||
let panel = Panel::new(Widget::col(vec![
|
||||
Widget::row(vec![
|
||||
Line("Import a new city").small_heading().into_widget(ctx),
|
||||
ctx.style().btn_close_widget(ctx),
|
||||
]),
|
||||
Widget::row(vec![
|
||||
"Step 1)".text_widget(ctx),
|
||||
ctx.style()
|
||||
.btn_solid_primary
|
||||
.text("Go to geojson.io")
|
||||
.build_def(ctx),
|
||||
]),
|
||||
"Step 2) Draw a polygon boundary where you want to import".text_widget(ctx),
|
||||
"Step 3) Copy the JSON text on the right into your clipboard".text_widget(ctx),
|
||||
Widget::row(vec![
|
||||
"Step 4)".text_widget(ctx),
|
||||
Toggle::choice(
|
||||
ctx,
|
||||
"driving side",
|
||||
"drive on the right",
|
||||
"left",
|
||||
None,
|
||||
true,
|
||||
),
|
||||
]),
|
||||
Widget::row(vec![
|
||||
"Step 5)".text_widget(ctx),
|
||||
ctx.style()
|
||||
.btn_solid_primary
|
||||
.text("Import the area from your clipboard")
|
||||
.build_def(ctx),
|
||||
]),
|
||||
ctx.style()
|
||||
.btn_outline
|
||||
.text("Alternate instructions")
|
||||
.build_def(ctx),
|
||||
]))
|
||||
.build(ctx);
|
||||
SimpleState::new(panel, Box::new(ImportCity))
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: AppLike + 'static> SimpleState<A> for ImportCity {
|
||||
fn on_click(&mut self, ctx: &mut EventCtx, _: &mut A, x: &str, panel: &Panel) -> Transition<A> {
|
||||
match x {
|
||||
"close" => Transition::Pop,
|
||||
"Alternate instructions" => {
|
||||
open_browser("https://a-b-street.github.io/docs/howto/new_city.html");
|
||||
Transition::Keep
|
||||
}
|
||||
"Go to geojson.io" => {
|
||||
open_browser("http://geojson.io");
|
||||
Transition::Keep
|
||||
}
|
||||
"Import the area from your clipboard" => {
|
||||
let drive_on_left = !panel.is_checked("driving side");
|
||||
println!("drive on left? {}", drive_on_left);
|
||||
Transition::Keep
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
@ -22,6 +22,8 @@ mod camera;
|
||||
mod city_picker;
|
||||
mod colors;
|
||||
mod heatmap;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
mod importer;
|
||||
mod minimap;
|
||||
mod navigate;
|
||||
mod turn_explorer;
|
||||
|
Loading…
Reference in New Issue
Block a user