2018-06-22 21:01:44 +03:00
|
|
|
use abstutil;
|
2018-10-18 02:57:15 +03:00
|
|
|
//use cpuprofiler;
|
2019-02-09 22:50:39 +03:00
|
|
|
use crate::objects::{DrawCtx, RenderingHints, ID};
|
2019-02-03 00:59:22 +03:00
|
|
|
use crate::render::{draw_vehicle, AgentCache, DrawPedestrian, RenderOptions, Renderable};
|
2019-02-02 23:49:17 +03:00
|
|
|
use crate::state::UIState;
|
2018-12-17 05:03:46 +03:00
|
|
|
use ezgui::{
|
2019-02-02 09:41:32 +03:00
|
|
|
Canvas, Color, EventCtx, EventLoopMode, Folder, GfxCtx, Key, ModalMenu, Prerender, Text,
|
|
|
|
TopMenu, BOTTOM_LEFT, GUI,
|
2018-12-17 05:03:46 +03:00
|
|
|
};
|
2019-02-01 03:36:45 +03:00
|
|
|
use geom::{Bounds, Circle, Distance};
|
2018-08-10 23:28:34 +03:00
|
|
|
use kml;
|
2019-02-02 09:41:32 +03:00
|
|
|
use map_model::{BuildingID, LaneID, Traversable};
|
2018-12-06 22:05:11 +03:00
|
|
|
use serde_derive::{Deserialize, Serialize};
|
2018-12-20 22:02:34 +03:00
|
|
|
use std::collections::HashSet;
|
2018-03-13 18:04:21 +03:00
|
|
|
use std::process;
|
|
|
|
|
2018-12-14 01:26:12 +03:00
|
|
|
pub struct UI<S: UIState> {
|
|
|
|
state: S,
|
2018-09-13 08:43:58 +03:00
|
|
|
}
|
2018-03-13 18:04:21 +03:00
|
|
|
|
2018-12-14 01:26:12 +03:00
|
|
|
impl<S: UIState> GUI<RenderingHints> for UI<S> {
|
2019-02-01 03:43:09 +03:00
|
|
|
fn top_menu(&self, canvas: &Canvas) -> Option<TopMenu> {
|
2018-12-25 06:31:04 +03:00
|
|
|
let mut folders = Vec::new();
|
|
|
|
folders.push(Folder::new(
|
|
|
|
"File",
|
2018-12-27 04:16:43 +03:00
|
|
|
vec![
|
2019-02-03 02:41:35 +03:00
|
|
|
(Some(Key::Comma), "show log console"),
|
|
|
|
(Some(Key::L), "show legend"),
|
|
|
|
(Some(Key::Escape), "quit"),
|
2018-12-27 04:16:43 +03:00
|
|
|
],
|
2018-12-25 06:31:04 +03:00
|
|
|
));
|
|
|
|
if self.state.get_state().enable_debug_controls {
|
|
|
|
folders.push(Folder::new(
|
|
|
|
"Debug",
|
|
|
|
vec![
|
2019-02-03 02:41:35 +03:00
|
|
|
(None, "screenshot everything"),
|
|
|
|
(None, "find chokepoints"),
|
|
|
|
(None, "validate map geometry"),
|
|
|
|
(Some(Key::Num1), "show/hide buildings"),
|
|
|
|
(Some(Key::Num2), "show/hide intersections"),
|
|
|
|
(Some(Key::Num3), "show/hide lanes"),
|
|
|
|
(Some(Key::Num4), "show/hide parcels"),
|
|
|
|
(Some(Key::Num5), "show/hide areas"),
|
|
|
|
(Some(Key::Num6), "show OSM colors"),
|
|
|
|
(Some(Key::Num7), "show/hide extra shapes"),
|
|
|
|
(Some(Key::Num9), "show/hide all turn icons"),
|
|
|
|
(None, "show/hide geometry debug mode"),
|
2018-12-25 06:31:04 +03:00
|
|
|
],
|
|
|
|
));
|
|
|
|
}
|
|
|
|
folders.extend(vec![
|
|
|
|
Folder::new(
|
|
|
|
"Edit",
|
|
|
|
vec![
|
2019-02-03 02:41:35 +03:00
|
|
|
(Some(Key::B), "manage A/B tests"),
|
|
|
|
(None, "configure colors"),
|
|
|
|
(Some(Key::N), "manage neighborhoods"),
|
|
|
|
(Some(Key::Q), "manage map edits"),
|
|
|
|
(Some(Key::E), "edit roads"),
|
|
|
|
(Some(Key::W), "manage scenarios"),
|
2018-12-25 06:31:04 +03:00
|
|
|
],
|
|
|
|
),
|
|
|
|
Folder::new(
|
|
|
|
"Simulation",
|
|
|
|
vec![
|
2019-02-03 02:41:35 +03:00
|
|
|
(Some(Key::LeftBracket), "slow down sim"),
|
|
|
|
(Some(Key::RightBracket), "speed up sim"),
|
|
|
|
(Some(Key::O), "save sim state"),
|
|
|
|
(Some(Key::Y), "load previous sim state"),
|
|
|
|
(Some(Key::U), "load next sim state"),
|
|
|
|
(Some(Key::Space), "run/pause sim"),
|
|
|
|
(Some(Key::M), "run one step of sim"),
|
|
|
|
(Some(Key::Dot), "show/hide sim info sidepanel"),
|
|
|
|
(Some(Key::T), "start time traveling"),
|
|
|
|
(Some(Key::D), "diff all A/B trips"),
|
|
|
|
(Some(Key::S), "seed the sim with agents"),
|
|
|
|
(Some(Key::LeftAlt), "swap the primary/secondary sim"),
|
2018-12-25 06:31:04 +03:00
|
|
|
],
|
|
|
|
),
|
|
|
|
Folder::new(
|
|
|
|
"View",
|
|
|
|
vec![
|
2019-02-03 02:41:35 +03:00
|
|
|
(Some(Key::Z), "show neighborhood summaries"),
|
|
|
|
(Some(Key::Slash), "search for something"),
|
|
|
|
(Some(Key::A), "show lanes with active traffic"),
|
|
|
|
(Some(Key::J), "warp to an object"),
|
2018-12-25 06:31:04 +03:00
|
|
|
],
|
|
|
|
),
|
|
|
|
]);
|
2019-02-01 03:43:09 +03:00
|
|
|
Some(TopMenu::new(folders, canvas))
|
2018-12-17 05:03:46 +03:00
|
|
|
}
|
|
|
|
|
2018-12-17 23:33:44 +03:00
|
|
|
fn modal_menus() -> Vec<ModalMenu> {
|
|
|
|
vec![
|
|
|
|
ModalMenu::new(
|
|
|
|
"Traffic Signal Editor",
|
|
|
|
vec![
|
|
|
|
(Key::Enter, "quit"),
|
|
|
|
(Key::D, "change cycle duration"),
|
|
|
|
(Key::P, "choose a preset signal"),
|
|
|
|
(Key::K, "move current cycle up"),
|
|
|
|
(Key::J, "move current cycle down"),
|
2018-12-18 07:37:10 +03:00
|
|
|
(Key::UpArrow, "select previous cycle"),
|
|
|
|
(Key::DownArrow, "select next cycle"),
|
2018-12-17 23:33:44 +03:00
|
|
|
(Key::Backspace, "delete current cycle"),
|
|
|
|
(Key::N, "add a new empty cycle"),
|
|
|
|
(Key::M, "add a new pedestrian scramble cycle"),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
ModalMenu::new(
|
|
|
|
"Scenario Editor",
|
2018-12-18 03:10:09 +03:00
|
|
|
vec![(Key::S, "save"), (Key::E, "edit"), (Key::I, "instantiate")],
|
2018-12-17 23:33:44 +03:00
|
|
|
),
|
|
|
|
ModalMenu::new("Road Editor", vec![(Key::Enter, "quit")]),
|
|
|
|
ModalMenu::new(
|
|
|
|
"Color Picker",
|
2018-12-18 03:10:09 +03:00
|
|
|
vec![(Key::Backspace, "revert"), (Key::Enter, "finalize")],
|
2018-12-17 23:33:44 +03:00
|
|
|
),
|
|
|
|
ModalMenu::new(
|
|
|
|
"Stop Sign Editor",
|
|
|
|
vec![(Key::Enter, "quit"), (Key::R, "reset to default")],
|
|
|
|
),
|
|
|
|
ModalMenu::new("A/B Test Editor", vec![(Key::R, "run A/B test")]),
|
|
|
|
ModalMenu::new(
|
|
|
|
"Neighborhood Editor",
|
|
|
|
vec![
|
2018-12-18 03:48:55 +03:00
|
|
|
(Key::Enter, "save"),
|
|
|
|
(Key::Escape, "quit"),
|
2018-12-17 23:33:44 +03:00
|
|
|
(Key::X, "export as an Osmosis polygon filter"),
|
|
|
|
(Key::P, "add a new point"),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
ModalMenu::new(
|
|
|
|
"Time Traveler",
|
|
|
|
vec![
|
|
|
|
(Key::Enter, "quit"),
|
|
|
|
(Key::Comma, "rewind"),
|
|
|
|
(Key::Dot, "forwards"),
|
|
|
|
],
|
|
|
|
),
|
2019-02-07 05:16:32 +03:00
|
|
|
ModalMenu::new(
|
|
|
|
"Simple Model",
|
|
|
|
vec![
|
|
|
|
(Key::Enter, "quit"),
|
|
|
|
(Key::Comma, "rewind"),
|
|
|
|
(Key::Dot, "forwards"),
|
2019-02-08 05:16:18 +03:00
|
|
|
(Key::Space, "toggle forwards play"),
|
|
|
|
(Key::M, "toggle backwards play"),
|
2019-02-08 05:34:51 +03:00
|
|
|
(Key::T, "toggle tooltips"),
|
2019-02-07 05:16:32 +03:00
|
|
|
],
|
|
|
|
),
|
2018-12-17 23:33:44 +03:00
|
|
|
ModalMenu::new(
|
|
|
|
"Geometry Debugger",
|
|
|
|
vec![(Key::Enter, "quit"), (Key::N, "see next problem")],
|
|
|
|
),
|
2019-02-08 20:36:25 +03:00
|
|
|
ModalMenu::new("Original Roads", vec![(Key::Enter, "quit")]),
|
2018-12-17 23:33:44 +03:00
|
|
|
ModalMenu::new("OSM Classifier", vec![(Key::Num6, "quit")]),
|
|
|
|
ModalMenu::new(
|
|
|
|
"Floodfiller",
|
|
|
|
vec![
|
2018-12-18 03:10:09 +03:00
|
|
|
(Key::Enter, "quit"),
|
2018-12-17 23:33:44 +03:00
|
|
|
(Key::Space, "step forwards"),
|
|
|
|
(Key::Tab, "finish floodfilling"),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
ModalMenu::new("Chokepoints Debugger", vec![(Key::Enter, "quit")]),
|
|
|
|
ModalMenu::new("A/B Trip Explorer", vec![(Key::Enter, "quit")]),
|
|
|
|
ModalMenu::new("A/B All Trips Explorer", vec![(Key::Enter, "quit")]),
|
|
|
|
ModalMenu::new("Agent Follower", vec![(Key::F, "quit")]),
|
|
|
|
ModalMenu::new("Search", vec![(Key::Enter, "quit")]),
|
|
|
|
ModalMenu::new("Neighborhood Summaries", vec![(Key::Z, "quit")]),
|
|
|
|
ModalMenu::new(
|
|
|
|
"Agent Route Debugger",
|
2018-12-18 03:10:09 +03:00
|
|
|
vec![(Key::R, "quit"), (Key::L, "show route for all agents")],
|
2018-12-17 23:33:44 +03:00
|
|
|
),
|
|
|
|
ModalMenu::new("Active Traffic Visualizer", vec![(Key::A, "quit")]),
|
2018-12-24 19:13:59 +03:00
|
|
|
ModalMenu::new("Object Hider", vec![(Key::K, "unhide everything")]),
|
2018-12-27 04:16:43 +03:00
|
|
|
// TODO F1?
|
|
|
|
ModalMenu::new("Legend", vec![(Key::L, "quit")]),
|
2019-01-13 02:19:25 +03:00
|
|
|
ModalMenu::new(
|
|
|
|
"Polygon Debugger",
|
|
|
|
vec![
|
|
|
|
(Key::Enter, "quit"),
|
2019-01-15 22:49:34 +03:00
|
|
|
(Key::Dot, "next item"),
|
|
|
|
(Key::Comma, "prev item"),
|
2019-01-13 02:19:25 +03:00
|
|
|
],
|
|
|
|
),
|
2019-01-21 01:27:25 +03:00
|
|
|
ModalMenu::new("Agent Spawner", vec![(Key::Enter, "quit")]),
|
2018-12-17 23:33:44 +03:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2019-02-01 03:43:09 +03:00
|
|
|
fn event(&mut self, mut ctx: EventCtx) -> (EventLoopMode, RenderingHints) {
|
2018-12-13 01:01:36 +03:00
|
|
|
let mut hints = RenderingHints {
|
|
|
|
mode: EventLoopMode::InputOnly,
|
|
|
|
osd: Text::new(),
|
2018-12-20 22:02:34 +03:00
|
|
|
suppress_traffic_signal_details: None,
|
2018-12-13 01:01:36 +03:00
|
|
|
hide_turn_icons: HashSet::new(),
|
|
|
|
};
|
|
|
|
|
|
|
|
// First update the camera and handle zoom
|
2019-02-01 03:43:09 +03:00
|
|
|
let old_zoom = ctx.canvas.cam_zoom;
|
|
|
|
ctx.canvas.handle_event(ctx.input);
|
|
|
|
let new_zoom = ctx.canvas.cam_zoom;
|
2018-12-25 05:58:01 +03:00
|
|
|
self.state
|
|
|
|
.mut_state()
|
|
|
|
.layers
|
|
|
|
.handle_zoom(old_zoom, new_zoom);
|
2018-12-13 01:01:36 +03:00
|
|
|
|
|
|
|
// Always handle mouseover
|
2019-02-01 03:43:09 +03:00
|
|
|
if !ctx.canvas.is_dragging() && ctx.input.get_moved_mouse().is_some() {
|
|
|
|
self.state.mut_state().primary.current_selection = self.mouseover_something(&ctx);
|
2018-12-13 01:01:36 +03:00
|
|
|
}
|
2019-02-01 03:43:09 +03:00
|
|
|
if ctx.input.window_lost_cursor() {
|
2018-12-25 05:58:01 +03:00
|
|
|
self.state.mut_state().primary.current_selection = None;
|
2018-12-23 03:58:36 +03:00
|
|
|
}
|
2018-12-13 01:01:36 +03:00
|
|
|
|
2018-12-13 22:19:10 +03:00
|
|
|
let mut recalculate_current_selection = false;
|
2019-02-01 10:22:36 +03:00
|
|
|
self.state
|
|
|
|
.event(&mut ctx, &mut hints, &mut recalculate_current_selection);
|
2019-02-01 03:36:45 +03:00
|
|
|
if recalculate_current_selection {
|
2019-02-01 03:43:09 +03:00
|
|
|
self.state.mut_state().primary.current_selection = self.mouseover_something(&ctx);
|
2018-10-22 05:23:47 +03:00
|
|
|
}
|
2018-12-13 01:01:36 +03:00
|
|
|
|
|
|
|
// Can do this at any time.
|
2019-02-01 03:43:09 +03:00
|
|
|
if ctx.input.action_chosen("quit") {
|
|
|
|
self.before_quit(ctx.canvas);
|
2018-12-13 01:01:36 +03:00
|
|
|
process::exit(0);
|
|
|
|
}
|
|
|
|
|
2019-02-01 03:43:09 +03:00
|
|
|
ctx.input.populate_osd(&mut hints.osd);
|
2018-12-13 01:01:36 +03:00
|
|
|
|
2019-01-14 05:04:03 +03:00
|
|
|
// TODO a plugin should do this, even though it's such a tiny thing
|
2019-02-03 02:41:35 +03:00
|
|
|
if ctx.input.action_chosen("screenshot everything") {
|
2019-01-14 05:04:03 +03:00
|
|
|
let bounds = self.state.get_state().primary.map.get_bounds();
|
2019-01-15 01:36:46 +03:00
|
|
|
assert!(bounds.min_x == 0.0 && bounds.min_y == 0.0);
|
2019-01-14 05:04:03 +03:00
|
|
|
hints.mode = EventLoopMode::ScreenCaptureEverything {
|
2019-01-14 22:29:06 +03:00
|
|
|
zoom: 3.0,
|
2019-01-14 05:04:03 +03:00
|
|
|
max_x: bounds.max_x,
|
|
|
|
max_y: bounds.max_y,
|
|
|
|
};
|
2019-01-14 01:47:11 +03:00
|
|
|
}
|
|
|
|
|
2018-12-13 01:01:36 +03:00
|
|
|
(hints.mode, hints)
|
2018-09-13 08:43:58 +03:00
|
|
|
}
|
2018-09-13 03:39:53 +03:00
|
|
|
|
2019-01-14 22:16:55 +03:00
|
|
|
fn draw(&self, _: &mut GfxCtx, _: &RenderingHints) {}
|
2019-01-14 05:04:03 +03:00
|
|
|
|
2019-01-15 21:33:20 +03:00
|
|
|
fn new_draw(&self, g: &mut GfxCtx, hints: &RenderingHints, screencap: bool) -> Option<String> {
|
2019-02-02 09:41:32 +03:00
|
|
|
let state = self.state.get_state();
|
|
|
|
|
2019-02-01 10:22:36 +03:00
|
|
|
g.clear(
|
2019-02-02 09:41:32 +03:00
|
|
|
state
|
2019-02-01 10:22:36 +03:00
|
|
|
.cs
|
|
|
|
.get_def("map background", Color::rgb(242, 239, 233)),
|
|
|
|
);
|
2018-10-22 05:23:47 +03:00
|
|
|
|
2019-02-02 23:35:50 +03:00
|
|
|
let mut cache = state.primary.draw_map.agents.borrow_mut();
|
|
|
|
let objects =
|
2019-02-06 01:43:46 +03:00
|
|
|
self.get_renderables_back_to_front(g.get_screen_bounds(), &g.prerender, &mut cache);
|
2019-02-02 09:41:32 +03:00
|
|
|
|
2019-02-09 22:50:39 +03:00
|
|
|
let ctx = DrawCtx {
|
2019-02-02 09:41:32 +03:00
|
|
|
cs: &state.cs,
|
|
|
|
map: &state.primary.map,
|
|
|
|
draw_map: &state.primary.draw_map,
|
|
|
|
sim: &state.primary.sim,
|
2018-12-08 00:27:13 +03:00
|
|
|
hints: &hints,
|
|
|
|
};
|
2019-01-15 21:33:20 +03:00
|
|
|
let mut sample_intersection: Option<String> = None;
|
2019-02-02 23:35:50 +03:00
|
|
|
for obj in objects {
|
2019-02-01 03:43:09 +03:00
|
|
|
let opts = RenderOptions {
|
2019-02-02 09:41:32 +03:00
|
|
|
color: state.color_obj(obj.get_id(), &ctx),
|
|
|
|
debug_mode: state.layers.debug_mode.is_enabled(),
|
|
|
|
is_selected: state.primary.current_selection == Some(obj.get_id()),
|
2019-02-01 03:43:09 +03:00
|
|
|
// TODO If a ToggleableLayer is currently off, this won't affect it!
|
|
|
|
show_all_detail: screencap,
|
|
|
|
};
|
|
|
|
obj.draw(g, opts, &ctx);
|
2019-02-01 03:36:45 +03:00
|
|
|
|
2019-02-01 03:43:09 +03:00
|
|
|
if screencap && sample_intersection.is_none() {
|
|
|
|
if let ID::Intersection(id) = obj.get_id() {
|
|
|
|
sample_intersection = Some(format!("_i{}", id.0));
|
2019-01-15 21:33:20 +03:00
|
|
|
}
|
2019-02-01 03:43:09 +03:00
|
|
|
}
|
2019-02-02 09:41:32 +03:00
|
|
|
}
|
2019-01-14 22:16:55 +03:00
|
|
|
|
|
|
|
if !screencap {
|
|
|
|
self.state.draw(g, &ctx);
|
|
|
|
|
|
|
|
// Not happy about cloning, but probably will make the OSD a first-class ezgui concept
|
|
|
|
// soon, so meh
|
2019-01-25 03:19:02 +03:00
|
|
|
let mut osd = hints.osd.clone();
|
|
|
|
// TODO Only in some kind of debug mode
|
|
|
|
osd.add_line(format!(
|
|
|
|
"{} things uploaded, {} things drawn",
|
2019-02-06 01:43:46 +03:00
|
|
|
g.get_num_uploads(),
|
|
|
|
g.num_draw_calls,
|
2019-01-25 03:19:02 +03:00
|
|
|
));
|
2019-02-01 03:43:09 +03:00
|
|
|
g.draw_blocking_text(osd, BOTTOM_LEFT);
|
2019-01-14 22:16:55 +03:00
|
|
|
}
|
2019-01-15 21:33:20 +03:00
|
|
|
|
|
|
|
sample_intersection
|
2018-10-22 05:23:47 +03:00
|
|
|
}
|
2018-12-13 01:01:36 +03:00
|
|
|
|
2019-02-01 03:43:09 +03:00
|
|
|
fn dump_before_abort(&self, canvas: &Canvas) {
|
2018-12-25 05:58:01 +03:00
|
|
|
error!("********************************************************************************");
|
|
|
|
error!("UI broke! Primary sim:");
|
|
|
|
self.state.get_state().primary.sim.dump_before_abort();
|
|
|
|
if let Some((s, _)) = &self.state.get_state().secondary {
|
|
|
|
error!("Secondary sim:");
|
|
|
|
s.sim.dump_before_abort();
|
|
|
|
}
|
|
|
|
|
2019-02-01 03:43:09 +03:00
|
|
|
self.save_editor_state(canvas);
|
2018-12-13 01:01:36 +03:00
|
|
|
}
|
2018-12-17 22:32:52 +03:00
|
|
|
|
2019-02-01 03:43:09 +03:00
|
|
|
fn before_quit(&self, canvas: &Canvas) {
|
|
|
|
self.save_editor_state(canvas);
|
2019-02-01 10:22:36 +03:00
|
|
|
self.state.get_state().cs.save();
|
2018-12-17 22:32:52 +03:00
|
|
|
info!("Saved color_scheme");
|
|
|
|
//cpuprofiler::PROFILER.lock().unwrap().stop().unwrap();
|
|
|
|
}
|
2018-10-22 05:23:47 +03:00
|
|
|
}
|
|
|
|
|
2018-12-14 01:26:12 +03:00
|
|
|
impl<S: UIState> UI<S> {
|
2019-02-01 10:22:36 +03:00
|
|
|
pub fn new(state: S, canvas: &mut Canvas) -> UI<S> {
|
2018-12-25 06:14:45 +03:00
|
|
|
match abstutil::read_json::<EditorState>("../editor_state") {
|
2019-02-01 03:43:09 +03:00
|
|
|
Ok(ref loaded) if state.get_state().primary.map.get_name() == &loaded.map_name => {
|
2018-10-22 05:23:47 +03:00
|
|
|
info!("Loaded previous editor_state");
|
2019-02-01 03:43:09 +03:00
|
|
|
canvas.cam_x = loaded.cam_x;
|
|
|
|
canvas.cam_y = loaded.cam_y;
|
|
|
|
canvas.cam_zoom = loaded.cam_zoom;
|
2018-10-22 05:23:47 +03:00
|
|
|
}
|
|
|
|
_ => {
|
2018-11-26 22:37:19 +03:00
|
|
|
warn!("Couldn't load editor_state or it's for a different map, so just focusing on an arbitrary building");
|
2018-12-05 22:45:07 +03:00
|
|
|
let focus_pt = ID::Building(BuildingID(0))
|
2018-12-13 22:35:29 +03:00
|
|
|
.canonical_point(
|
2019-02-01 03:43:09 +03:00
|
|
|
&state.get_state().primary.map,
|
|
|
|
&state.get_state().primary.sim,
|
|
|
|
&state.get_state().primary.draw_map,
|
2018-12-13 22:35:29 +03:00
|
|
|
)
|
2018-12-05 22:45:07 +03:00
|
|
|
.or_else(|| {
|
|
|
|
ID::Lane(LaneID(0)).canonical_point(
|
2019-02-01 03:43:09 +03:00
|
|
|
&state.get_state().primary.map,
|
|
|
|
&state.get_state().primary.sim,
|
|
|
|
&state.get_state().primary.draw_map,
|
2018-12-05 22:45:07 +03:00
|
|
|
)
|
2018-12-06 21:05:42 +03:00
|
|
|
})
|
|
|
|
.expect("Can't get canonical_point of BuildingID(0) or Road(0)");
|
2019-02-01 03:43:09 +03:00
|
|
|
canvas.center_on_map_pt(focus_pt);
|
2018-10-22 05:23:47 +03:00
|
|
|
}
|
2018-10-08 22:55:42 +03:00
|
|
|
}
|
2018-10-22 05:22:16 +03:00
|
|
|
|
2019-02-01 10:22:36 +03:00
|
|
|
UI { state }
|
2018-10-22 05:23:47 +03:00
|
|
|
}
|
2018-10-21 22:18:25 +03:00
|
|
|
|
2019-02-01 03:43:09 +03:00
|
|
|
fn mouseover_something(&self, ctx: &EventCtx) -> Option<ID> {
|
|
|
|
let pt = ctx.canvas.get_cursor_in_map_space()?;
|
2019-01-22 01:04:07 +03:00
|
|
|
|
2019-02-02 23:35:50 +03:00
|
|
|
let mut cache = self.state.get_state().primary.draw_map.agents.borrow_mut();
|
|
|
|
let mut objects = self.get_renderables_back_to_front(
|
2019-02-01 03:36:45 +03:00
|
|
|
Circle::new(pt, Distance::meters(3.0)).get_bounds(),
|
2019-02-02 09:41:32 +03:00
|
|
|
ctx.prerender,
|
2019-02-02 23:35:50 +03:00
|
|
|
&mut cache,
|
2019-02-01 03:36:45 +03:00
|
|
|
);
|
2019-02-02 23:35:50 +03:00
|
|
|
objects.reverse();
|
2019-02-02 09:41:32 +03:00
|
|
|
|
2019-02-02 23:35:50 +03:00
|
|
|
for obj in objects {
|
2019-02-02 09:41:32 +03:00
|
|
|
// Don't mouseover parcels.
|
|
|
|
// TODO Might get fancier rules in the future, so we can't mouseover irrelevant things
|
|
|
|
// in intersection editor mode, for example.
|
|
|
|
match obj.get_id() {
|
|
|
|
ID::Parcel(_) => {}
|
|
|
|
_ => {
|
|
|
|
if obj.contains_pt(pt) {
|
|
|
|
return Some(obj.get_id());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
None
|
2018-12-25 05:58:01 +03:00
|
|
|
}
|
|
|
|
|
2019-02-01 03:43:09 +03:00
|
|
|
fn save_editor_state(&self, canvas: &Canvas) {
|
2018-11-02 00:00:14 +03:00
|
|
|
let state = EditorState {
|
2018-12-25 05:58:01 +03:00
|
|
|
map_name: self.state.get_state().primary.map.get_name().clone(),
|
2019-02-01 03:43:09 +03:00
|
|
|
cam_x: canvas.cam_x,
|
|
|
|
cam_y: canvas.cam_y,
|
|
|
|
cam_zoom: canvas.cam_zoom,
|
2018-11-02 00:00:14 +03:00
|
|
|
};
|
|
|
|
// TODO maybe make state line up with the map, so loading from a new map doesn't break
|
2018-12-25 06:14:45 +03:00
|
|
|
abstutil::write_json("../editor_state", &state).expect("Saving editor_state failed");
|
2018-11-02 00:00:14 +03:00
|
|
|
info!("Saved editor_state");
|
|
|
|
}
|
2019-02-02 09:41:32 +03:00
|
|
|
|
2019-02-02 23:49:17 +03:00
|
|
|
// TODO This could probably belong to DrawMap again, but it's annoying to plumb things that
|
|
|
|
// State does, like show_icons_for() and show().
|
2019-02-02 23:35:50 +03:00
|
|
|
fn get_renderables_back_to_front<'a>(
|
|
|
|
&'a self,
|
2019-02-02 09:41:32 +03:00
|
|
|
bounds: Bounds,
|
|
|
|
prerender: &Prerender,
|
2019-02-02 23:35:50 +03:00
|
|
|
agents: &'a mut AgentCache,
|
|
|
|
) -> Vec<Box<&'a Renderable>> {
|
2019-02-02 09:41:32 +03:00
|
|
|
let state = self.state.get_state();
|
|
|
|
let map = &state.primary.map;
|
|
|
|
let draw_map = &state.primary.draw_map;
|
|
|
|
|
|
|
|
let mut areas: Vec<Box<&Renderable>> = Vec::new();
|
|
|
|
let mut parcels: Vec<Box<&Renderable>> = Vec::new();
|
|
|
|
let mut lanes: Vec<Box<&Renderable>> = Vec::new();
|
|
|
|
let mut intersections: Vec<Box<&Renderable>> = Vec::new();
|
|
|
|
let mut buildings: Vec<Box<&Renderable>> = Vec::new();
|
|
|
|
let mut extra_shapes: Vec<Box<&Renderable>> = Vec::new();
|
|
|
|
let mut bus_stops: Vec<Box<&Renderable>> = Vec::new();
|
|
|
|
let mut turn_icons: Vec<Box<&Renderable>> = Vec::new();
|
|
|
|
let mut agents_on: Vec<Traversable> = Vec::new();
|
|
|
|
|
|
|
|
for id in draw_map.get_matching_objects(bounds) {
|
|
|
|
if !state.show(id) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
match id {
|
|
|
|
ID::Area(id) => areas.push(Box::new(draw_map.get_a(id))),
|
|
|
|
ID::Parcel(id) => parcels.push(Box::new(draw_map.get_p(id))),
|
|
|
|
ID::Lane(id) => {
|
|
|
|
lanes.push(Box::new(draw_map.get_l(id)));
|
|
|
|
if !state.show_icons_for(map.get_l(id).dst_i) {
|
|
|
|
agents_on.push(Traversable::Lane(id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ID::Intersection(id) => {
|
|
|
|
intersections.push(Box::new(draw_map.get_i(id)));
|
|
|
|
for t in &map.get_i(id).turns {
|
|
|
|
if state.show_icons_for(id) {
|
|
|
|
turn_icons.push(Box::new(draw_map.get_t(*t)));
|
|
|
|
} else {
|
|
|
|
agents_on.push(Traversable::Turn(*t));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// TODO front paths will get drawn over buildings, depending on quadtree order.
|
|
|
|
// probably just need to make them go around other buildings instead of having
|
|
|
|
// two passes through buildings.
|
|
|
|
ID::Building(id) => buildings.push(Box::new(draw_map.get_b(id))),
|
|
|
|
ID::ExtraShape(id) => extra_shapes.push(Box::new(draw_map.get_es(id))),
|
|
|
|
ID::BusStop(id) => bus_stops.push(Box::new(draw_map.get_bs(id))),
|
|
|
|
|
|
|
|
ID::Turn(_) | ID::Car(_) | ID::Pedestrian(_) | ID::Trip(_) => {
|
|
|
|
panic!("{:?} shouldn't be in the quadtree", id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// From background to foreground Z-order
|
|
|
|
let mut borrows: Vec<Box<&Renderable>> = Vec::new();
|
|
|
|
borrows.extend(areas);
|
|
|
|
borrows.extend(parcels);
|
|
|
|
borrows.extend(lanes);
|
|
|
|
borrows.extend(intersections);
|
|
|
|
borrows.extend(buildings);
|
|
|
|
borrows.extend(extra_shapes);
|
|
|
|
borrows.extend(bus_stops);
|
|
|
|
borrows.extend(turn_icons);
|
|
|
|
|
2019-02-02 23:35:50 +03:00
|
|
|
// Expand all of the Traversables into agents, populating the cache if needed.
|
2019-02-02 09:41:32 +03:00
|
|
|
{
|
2019-02-10 00:07:00 +03:00
|
|
|
let source = state.get_draw_agents();
|
|
|
|
let tick = source.tick();
|
2019-02-02 09:41:32 +03:00
|
|
|
|
|
|
|
for on in &agents_on {
|
|
|
|
if !agents.has(tick, *on) {
|
|
|
|
let mut list: Vec<Box<Renderable>> = Vec::new();
|
2019-02-10 00:07:00 +03:00
|
|
|
for c in source.get_draw_cars(*on, map).into_iter() {
|
2019-02-03 00:59:22 +03:00
|
|
|
list.push(draw_vehicle(c, map, prerender, &state.cs));
|
2019-02-02 09:41:32 +03:00
|
|
|
}
|
2019-02-10 00:07:00 +03:00
|
|
|
for p in source.get_draw_peds(*on, map).into_iter() {
|
2019-02-02 23:54:16 +03:00
|
|
|
list.push(Box::new(DrawPedestrian::new(p, map, prerender, &state.cs)));
|
2019-02-02 09:41:32 +03:00
|
|
|
}
|
|
|
|
agents.put(tick, *on, list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-02 23:35:50 +03:00
|
|
|
for on in agents_on {
|
|
|
|
for obj in agents.get(on) {
|
|
|
|
borrows.push(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a stable sort.
|
|
|
|
borrows.sort_by_key(|r| r.get_zorder());
|
|
|
|
|
|
|
|
borrows
|
2019-02-02 09:41:32 +03:00
|
|
|
}
|
2018-03-13 18:04:21 +03:00
|
|
|
}
|
2018-06-22 21:01:44 +03:00
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
|
|
pub struct EditorState {
|
2018-09-09 23:21:53 +03:00
|
|
|
pub map_name: String,
|
2018-06-22 21:01:44 +03:00
|
|
|
pub cam_x: f64,
|
|
|
|
pub cam_y: f64,
|
|
|
|
pub cam_zoom: f64,
|
|
|
|
}
|