Refactor a button to change maps

This commit is contained in:
Dustin Carlino 2021-09-27 12:16:01 -07:00
parent 46dd2d69fe
commit 2c6f218b22
10 changed files with 41 additions and 94 deletions

View File

@ -7,8 +7,7 @@
use abstutil::prettyprint_usize;
use geom::{Distance, Duration};
use map_gui::tools::{
draw_isochrone, nice_map_name, open_browser, CityPicker, ColorLegend, Navigator, PopupMsg,
URLManager,
draw_isochrone, open_browser, CityPicker, ColorLegend, Navigator, PopupMsg, URLManager,
};
use map_gui::ID;
use map_model::connectivity::WalkingOptions;
@ -288,15 +287,7 @@ fn build_panel(ctx: &mut EventCtx, app: &App, start: &Building, isochrone: &Isoc
.small_heading()
.into_widget(ctx)];
rows.push(
ctx.style()
.btn_popup_icon_text(
"system/assets/tools/map.svg",
nice_map_name(app.map.get_name()),
)
.hotkey(lctrl(Key::L))
.build_widget(ctx, "change map"),
);
rows.push(map_gui::tools::change_map_btn(ctx, app));
rows.push(
Text::from_all(vec![

View File

@ -4,11 +4,11 @@
use abstutil::Timer;
use geom::{LonLat, Percent};
use map_gui::colors::ColorSchemeChoice;
use map_gui::tools::{nice_map_name, ChooseSomething, CityPicker};
use map_gui::tools::{ChooseSomething, CityPicker};
use map_gui::AppLike;
use widgetry::{
lctrl, Choice, DrawBaselayer, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Panel,
State, TextExt, VerticalAlignment, Widget,
Choice, DrawBaselayer, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Panel, State,
VerticalAlignment, Widget,
};
use crate::app::{App, Transition};
@ -34,14 +34,7 @@ impl DevToolsMode {
Line("Internal dev tools").small_heading().into_widget(ctx),
ctx.style().btn_close_widget(ctx),
]),
Widget::row(vec![
"Change map:".text_widget(ctx),
ctx.style()
.btn_outline
.popup(nice_map_name(app.primary.map.get_name()))
.hotkey(lctrl(Key::L))
.build_widget(ctx, "change map"),
]),
map_gui::tools::change_map_btn(ctx, app),
Widget::custom_row(vec![
ctx.style()
.btn_outline

View File

@ -1,10 +1,10 @@
use std::collections::BTreeSet;
use map_gui::tools::{nice_map_name, CityPicker};
use map_gui::tools::CityPicker;
use map_gui::ID;
use widgetry::{
lctrl, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, Outcome,
Panel, State, TextExt, VerticalAlignment, Widget,
Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Line, Outcome, Panel, State,
TextExt, VerticalAlignment, Widget,
};
use super::{Neighborhood, Viewer};
@ -21,13 +21,7 @@ impl BrowseNeighborhoods {
let panel = Panel::new_builder(Widget::col(vec![
Widget::row(vec![
Line("LTN tool").small_heading().into_widget(ctx),
ctx.style()
.btn_popup_icon_text(
"system/assets/tools/map.svg",
nice_map_name(app.primary.map.get_name()),
)
.hotkey(lctrl(Key::L))
.build_widget(ctx, "change map")
map_gui::tools::change_map_btn(ctx, app)
.centered_vert()
.align_right(),
]),

View File

@ -1,12 +1,12 @@
use std::collections::BTreeSet;
use geom::{Distance, Line};
use map_gui::tools::{nice_map_name, CityPicker, ColorDiscrete};
use map_gui::tools::{CityPicker, ColorDiscrete};
use map_gui::ID;
use map_model::{IntersectionID, Map, Road, RoadID};
use widgetry::{
lctrl, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, Outcome,
Panel, State, Text, TextExt, VerticalAlignment, Widget,
Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Panel,
State, Text, TextExt, VerticalAlignment, Widget,
};
use crate::app::{App, Transition};
@ -51,13 +51,7 @@ impl Viewer {
let panel = Panel::new_builder(Widget::col(vec![
Widget::row(vec![
Line("LTN tool").small_heading().into_widget(ctx),
ctx.style()
.btn_popup_icon_text(
"system/assets/tools/map.svg",
nice_map_name(app.primary.map.get_name()),
)
.hotkey(lctrl(Key::L))
.build_widget(ctx, "change map")
map_gui::tools::change_map_btn(ctx, app)
.centered_vert()
.align_right(),
]),

View File

@ -7,9 +7,7 @@ use rand::Rng;
use abstutil::Timer;
use geom::{Distance, Duration};
use map_gui::tools::{
grey_out_map, nice_map_name, open_browser, CityPicker, PopupMsg, PromptInput, URLManager,
};
use map_gui::tools::{grey_out_map, open_browser, CityPicker, PopupMsg, PromptInput, URLManager};
use map_gui::ID;
use map_model::{IntersectionID, Position};
use sim::{IndividTrip, PersonSpec, Scenario, TripEndpoint, TripMode, TripPurpose};
@ -130,14 +128,7 @@ impl GameplayState for Freeform {
.small_heading()
.into_widget(ctx)
.margin_right(18),
ctx.style()
.btn_popup_icon_text(
"system/assets/tools/map.svg",
nice_map_name(app.primary.map.get_name()),
)
.hotkey(lctrl(Key::L))
.build_widget(ctx, "change map")
.margin_right(8),
map_gui::tools::change_map_btn(ctx, app).margin_right(8),
ctx.style()
.btn_popup_icon_text("system/assets/tools/calendar.svg", "none")
.hotkey(Key::S)

View File

@ -4,9 +4,7 @@ use maplit::btreeset;
use abstutil::prettyprint_usize;
use geom::{Duration, Time};
use map_gui::tools::{
grey_out_map, nice_map_name, ChooseSomething, CityPicker, PopupMsg, URLManager,
};
use map_gui::tools::{grey_out_map, ChooseSomething, CityPicker, PopupMsg, URLManager};
use sim::{ScenarioModifier, SlidingWindow, TripMode};
use widgetry::{
lctrl, Choice, Color, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, LinePlot, Outcome,
@ -182,14 +180,7 @@ impl GameplayState for PlayScenario {
.small_heading()
.into_widget(ctx)
.margin_right(18),
ctx.style()
.btn_popup_icon_text(
"system/assets/tools/map.svg",
nice_map_name(app.primary.map.get_name()),
)
.hotkey(lctrl(Key::L))
.build_widget(ctx, "change map")
.margin_right(8),
map_gui::tools::change_map_btn(ctx, app).margin_right(8),
ctx.style()
.btn_popup_icon_text("system/assets/tools/calendar.svg", &self.scenario_name)
.hotkey(Key::S)

View File

@ -8,10 +8,10 @@ mod quick_sketch;
mod route;
mod share;
use map_gui::tools::{grey_out_map, nice_map_name, open_browser, CityPicker};
use map_gui::tools::{grey_out_map, open_browser, CityPicker};
use widgetry::{
lctrl, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Panel, SimpleState, State, Text,
TextExt, VerticalAlignment, Widget,
EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Panel, SimpleState, State, Text, TextExt,
VerticalAlignment, Widget,
};
pub use self::explore::ExploreMap;
@ -47,13 +47,7 @@ impl Tab {
.image_path("system/assets/pregame/logo.svg")
.image_dims(50.0)
.build_widget(ctx, "about A/B Street"),
ctx.style()
.btn_popup_icon_text(
"system/assets/tools/map.svg",
nice_map_name(app.primary.map.get_name()),
)
.hotkey(lctrl(Key::L))
.build_widget(ctx, "change map")
map_gui::tools::change_map_btn(ctx, app)
.centered_vert()
.align_right(),
])];

View File

@ -2,7 +2,7 @@
use abstio::MapName;
use geom::Polygon;
use widgetry::{GfxCtx, Line, Text};
use widgetry::{lctrl, EventCtx, GfxCtx, Key, Line, Text, Widget};
pub use self::camera::{CameraState, DefaultMap};
pub use self::city_picker::CityPicker;
@ -296,3 +296,14 @@ pub fn find_exe(cmd: &str) -> String {
}
panic!("Couldn't find the {} executable", cmd);
}
/// A button to change maps, with default keybindings
pub fn change_map_btn(ctx: &EventCtx, app: &dyn AppLike) -> Widget {
ctx.style()
.btn_popup_icon_text(
"system/assets/tools/map.svg",
nice_map_name(app.map().get_name()),
)
.hotkey(lctrl(Key::L))
.build_widget(ctx, "change map")
}

View File

@ -5,8 +5,8 @@ use geom::ArrowCap;
use map_gui::options::OptionsPanel;
use map_gui::render::{DrawOptions, BIG_ARROW_THICKNESS};
use map_gui::tools::{
nice_map_name, open_browser, CityPicker, Minimap, MinimapControls, Navigator, PopupMsg,
TurnExplorer, URLManager,
open_browser, CityPicker, Minimap, MinimapControls, Navigator, PopupMsg, TurnExplorer,
URLManager,
};
use map_gui::{SimpleApp, ID};
use map_model::osm;
@ -57,13 +57,7 @@ impl Viewer {
Line("OpenStreetMap viewer")
.small_heading()
.into_widget(ctx),
ctx.style()
.btn_popup_icon_text(
"system/assets/tools/map.svg",
nice_map_name(app.map.get_name()),
)
.hotkey(lctrl(Key::L))
.build_widget(ctx, "change map"),
map_gui::tools::change_map_btn(ctx, app),
Widget::row(vec![
ctx.style()
.btn_plain

View File

@ -4,13 +4,13 @@ use anyhow::Result;
use abstutil::{prettyprint_usize, Timer};
use geom::{Distance, FindClosest, PolyLine, Polygon};
use map_gui::tools::{nice_map_name, open_browser, CityPicker, ColorLegend, PopupMsg};
use map_gui::tools::{open_browser, CityPicker, ColorLegend, PopupMsg};
use map_gui::{SimpleApp, ID};
use map_model::{osm, RoadID};
use osm::WayID;
use widgetry::{
lctrl, Choice, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line,
Menu, Outcome, Panel, State, Text, TextExt, Toggle, Transition, VerticalAlignment, Widget,
Choice, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, Menu,
Outcome, Panel, State, Text, TextExt, Toggle, Transition, VerticalAlignment, Widget,
};
type App = SimpleApp<()>;
@ -124,13 +124,7 @@ impl ParkingMapper {
show,
panel: Panel::new_builder(Widget::col(vec![
Line("Parking mapper").small_heading().into_widget(ctx),
ctx.style()
.btn_popup_icon_text(
"system/assets/tools/map.svg",
nice_map_name(app.map.get_name()),
)
.hotkey(lctrl(Key::L))
.build_widget(ctx, "change map"),
map_gui::tools::change_map_btn(ctx, app),
format!(
"{} / {} ways done (you've mapped {})",
prettyprint_usize(done.len()),