2019-04-26 02:02:40 +03:00
|
|
|
mod chokepoints;
|
2019-04-26 20:46:41 +03:00
|
|
|
mod color_picker;
|
2019-04-26 02:35:09 +03:00
|
|
|
mod connected_roads;
|
2019-04-27 23:58:36 +03:00
|
|
|
mod neighborhood_summary;
|
2019-04-26 02:40:26 +03:00
|
|
|
mod objects;
|
2019-04-26 02:24:10 +03:00
|
|
|
mod polygons;
|
2019-04-26 02:02:40 +03:00
|
|
|
|
2019-04-26 01:50:16 +03:00
|
|
|
use crate::game::{GameState, Mode};
|
2019-04-26 02:02:40 +03:00
|
|
|
use crate::objects::ID;
|
2019-04-27 23:58:36 +03:00
|
|
|
use crate::ui::{ShowLayers, ShowObject, UI};
|
|
|
|
use abstutil::Timer;
|
2019-04-26 20:46:41 +03:00
|
|
|
use ezgui::{
|
|
|
|
Color, EventCtx, EventLoopMode, GfxCtx, InputResult, Key, ScrollingMenu, Text, TextBox, Wizard,
|
|
|
|
};
|
2019-04-26 02:16:21 +03:00
|
|
|
use map_model::RoadID;
|
|
|
|
use std::collections::{HashMap, HashSet};
|
2019-04-26 01:50:16 +03:00
|
|
|
|
|
|
|
pub struct DebugMode {
|
|
|
|
state: State,
|
2019-04-26 02:02:40 +03:00
|
|
|
chokepoints: Option<chokepoints::ChokepointsFinder>,
|
2019-04-26 02:16:21 +03:00
|
|
|
show_original_roads: HashSet<RoadID>,
|
2019-04-26 02:35:09 +03:00
|
|
|
connected_roads: connected_roads::ShowConnectedRoads,
|
2019-04-26 02:40:26 +03:00
|
|
|
objects: objects::ObjectDebugger,
|
2019-04-26 08:07:48 +03:00
|
|
|
hidden: HashSet<ID>,
|
2019-04-26 08:19:54 +03:00
|
|
|
layers: ShowLayers,
|
2019-04-26 20:21:05 +03:00
|
|
|
search_results: Option<(String, HashSet<ID>)>,
|
2019-04-27 23:58:36 +03:00
|
|
|
neighborhood_summary: neighborhood_summary::NeighborhoodSummary,
|
2019-04-26 01:50:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
enum State {
|
|
|
|
Exploring,
|
2019-04-26 02:24:10 +03:00
|
|
|
Polygons(polygons::PolygonDebugger),
|
2019-04-26 20:21:05 +03:00
|
|
|
SearchOSM(TextBox),
|
2019-04-26 20:46:41 +03:00
|
|
|
Colors(color_picker::ColorPicker),
|
2019-04-26 01:50:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl DebugMode {
|
2019-04-27 23:58:36 +03:00
|
|
|
pub fn new(ctx: &mut EventCtx, ui: &UI) -> DebugMode {
|
2019-04-26 01:50:16 +03:00
|
|
|
DebugMode {
|
|
|
|
state: State::Exploring,
|
2019-04-26 02:02:40 +03:00
|
|
|
chokepoints: None,
|
2019-04-26 02:16:21 +03:00
|
|
|
show_original_roads: HashSet::new(),
|
2019-04-26 02:35:09 +03:00
|
|
|
connected_roads: connected_roads::ShowConnectedRoads::new(),
|
2019-04-26 02:40:26 +03:00
|
|
|
objects: objects::ObjectDebugger::new(),
|
2019-04-26 08:07:48 +03:00
|
|
|
hidden: HashSet::new(),
|
2019-04-26 08:19:54 +03:00
|
|
|
layers: ShowLayers::new(),
|
2019-04-26 20:21:05 +03:00
|
|
|
search_results: None,
|
2019-04-27 23:58:36 +03:00
|
|
|
neighborhood_summary: neighborhood_summary::NeighborhoodSummary::new(
|
|
|
|
&ui.state.primary.map,
|
|
|
|
&ui.state.primary.draw_map,
|
|
|
|
ctx.prerender,
|
|
|
|
&mut Timer::new("set up DebugMode"),
|
|
|
|
),
|
2019-04-26 01:50:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn event(state: &mut GameState, ctx: &mut EventCtx) -> EventLoopMode {
|
|
|
|
match state.mode {
|
|
|
|
Mode::Debug(ref mut mode) => {
|
2019-04-26 02:24:10 +03:00
|
|
|
match mode.state {
|
|
|
|
State::Exploring => {
|
|
|
|
ctx.canvas.handle_event(ctx.input);
|
2019-04-27 22:02:32 +03:00
|
|
|
state.ui.state.primary.current_selection = state.ui.handle_mouseover(
|
|
|
|
ctx,
|
|
|
|
None,
|
|
|
|
&state.ui.state.primary.sim,
|
|
|
|
mode,
|
|
|
|
true,
|
|
|
|
);
|
2019-04-26 01:50:16 +03:00
|
|
|
|
2019-04-26 02:24:10 +03:00
|
|
|
let mut txt = Text::new();
|
|
|
|
txt.add_styled_line(
|
|
|
|
"Debug Mode".to_string(),
|
|
|
|
None,
|
|
|
|
Some(Color::BLUE),
|
|
|
|
None,
|
|
|
|
);
|
|
|
|
if mode.chokepoints.is_some() {
|
|
|
|
txt.add_line("Showing chokepoints".to_string());
|
|
|
|
}
|
|
|
|
if !mode.show_original_roads.is_empty() {
|
|
|
|
txt.add_line(format!(
|
|
|
|
"Showing {} original roads",
|
|
|
|
mode.show_original_roads.len()
|
|
|
|
));
|
|
|
|
}
|
2019-04-26 08:07:48 +03:00
|
|
|
if !mode.hidden.is_empty() {
|
|
|
|
txt.add_line(format!("Hiding {} things", mode.hidden.len()));
|
|
|
|
}
|
2019-04-26 20:21:05 +03:00
|
|
|
if let Some((ref search, ref results)) = mode.search_results {
|
|
|
|
txt.add_line(format!(
|
|
|
|
"Search for {} has {} results",
|
|
|
|
search,
|
|
|
|
results.len()
|
|
|
|
));
|
|
|
|
}
|
2019-04-27 23:58:36 +03:00
|
|
|
if mode.neighborhood_summary.active {
|
|
|
|
txt.add_line("Showing neighborhood summaries".to_string());
|
|
|
|
}
|
2019-04-26 02:24:10 +03:00
|
|
|
ctx.input
|
|
|
|
.set_mode_with_new_prompt("Debug Mode", txt, ctx.canvas);
|
|
|
|
if ctx.input.modal_action("quit") {
|
|
|
|
state.mode = Mode::SplashScreen(Wizard::new(), None);
|
|
|
|
return EventLoopMode::InputOnly;
|
|
|
|
}
|
2019-04-26 02:02:40 +03:00
|
|
|
|
2019-04-26 02:24:10 +03:00
|
|
|
if ctx.input.modal_action("show/hide chokepoints") {
|
|
|
|
if mode.chokepoints.is_some() {
|
|
|
|
mode.chokepoints = None;
|
|
|
|
} else {
|
|
|
|
// TODO Nothing will actually exist. ;)
|
|
|
|
mode.chokepoints = Some(chokepoints::ChokepointsFinder::new(
|
|
|
|
&state.ui.state.primary.sim,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !mode.show_original_roads.is_empty() {
|
|
|
|
if ctx.input.modal_action("clear original roads shown") {
|
|
|
|
mode.show_original_roads.clear();
|
|
|
|
}
|
|
|
|
}
|
2019-04-26 08:07:48 +03:00
|
|
|
if !mode.hidden.is_empty() {
|
|
|
|
if ctx.input.modal_action("unhide everything") {
|
|
|
|
mode.hidden.clear();
|
|
|
|
// TODO recalculate current_selection
|
|
|
|
}
|
|
|
|
}
|
|
|
|
match state.ui.state.primary.current_selection {
|
|
|
|
Some(ID::Lane(_))
|
|
|
|
| Some(ID::Intersection(_))
|
|
|
|
| Some(ID::ExtraShape(_)) => {
|
|
|
|
let id = state.ui.state.primary.current_selection.unwrap();
|
|
|
|
if ctx
|
|
|
|
.input
|
|
|
|
.contextual_action(Key::H, &format!("hide {:?}", id))
|
|
|
|
{
|
|
|
|
println!("Hiding {:?}", id);
|
|
|
|
//*ctx.recalculate_current_selection = true;
|
|
|
|
state.ui.state.primary.current_selection = None;
|
|
|
|
mode.hidden.insert(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
2019-04-26 02:24:10 +03:00
|
|
|
|
|
|
|
if let Some(ID::Lane(l)) = state.ui.state.primary.current_selection {
|
|
|
|
let id = state.ui.state.primary.map.get_l(l).parent;
|
|
|
|
if ctx.input.contextual_action(
|
|
|
|
Key::V,
|
|
|
|
&format!("show original geometry of {:?}", id),
|
|
|
|
) {
|
|
|
|
mode.show_original_roads.insert(id);
|
|
|
|
}
|
|
|
|
}
|
2019-04-26 02:35:09 +03:00
|
|
|
mode.connected_roads.event(ctx, &state.ui);
|
2019-04-26 02:40:26 +03:00
|
|
|
mode.objects.event(ctx, &state.ui);
|
2019-04-27 23:58:36 +03:00
|
|
|
mode.neighborhood_summary.event(ctx, &state.ui);
|
2019-04-26 02:24:10 +03:00
|
|
|
|
|
|
|
if let Some(debugger) = polygons::PolygonDebugger::new(ctx, &state.ui) {
|
|
|
|
mode.state = State::Polygons(debugger);
|
|
|
|
}
|
2019-04-26 02:16:21 +03:00
|
|
|
|
2019-04-26 08:19:54 +03:00
|
|
|
// TODO recalc current selection...
|
|
|
|
if ctx.input.modal_action("show/hide buildings") {
|
|
|
|
mode.layers.show_buildings = !mode.layers.show_buildings;
|
|
|
|
} else if ctx.input.modal_action("show/hide intersections") {
|
|
|
|
mode.layers.show_intersections = !mode.layers.show_intersections;
|
|
|
|
} else if ctx.input.modal_action("show/hide lanes") {
|
|
|
|
mode.layers.show_lanes = !mode.layers.show_lanes;
|
|
|
|
} else if ctx.input.modal_action("show/hide areas") {
|
|
|
|
mode.layers.show_areas = !mode.layers.show_areas;
|
|
|
|
} else if ctx.input.modal_action("show/hide extra shapes") {
|
|
|
|
mode.layers.show_extra_shapes = !mode.layers.show_extra_shapes;
|
|
|
|
} else if ctx.input.modal_action("show/hide geometry debug mode") {
|
|
|
|
mode.layers.geom_debug_mode = !mode.layers.geom_debug_mode;
|
|
|
|
}
|
|
|
|
|
2019-04-26 20:15:25 +03:00
|
|
|
if ctx.input.modal_action("screenshot everything") {
|
|
|
|
let bounds = state.ui.state.primary.map.get_bounds();
|
|
|
|
assert!(bounds.min_x == 0.0 && bounds.min_y == 0.0);
|
|
|
|
return EventLoopMode::ScreenCaptureEverything {
|
|
|
|
dir: format!(
|
|
|
|
"../data/screenshots/pending_{}",
|
|
|
|
state.ui.state.primary.map.get_name()
|
|
|
|
),
|
|
|
|
zoom: 3.0,
|
|
|
|
max_x: bounds.max_x,
|
|
|
|
max_y: bounds.max_y,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-04-26 20:21:05 +03:00
|
|
|
if mode.search_results.is_some() {
|
|
|
|
if ctx.input.modal_action("clear OSM search results") {
|
|
|
|
mode.search_results = None;
|
|
|
|
}
|
|
|
|
} else if ctx.input.modal_action("search OSM metadata") {
|
|
|
|
mode.state = State::SearchOSM(TextBox::new("Search for what?", None));
|
2019-04-26 20:46:41 +03:00
|
|
|
} else if ctx.input.modal_action("configure colors") {
|
|
|
|
mode.state = State::Colors(color_picker::ColorPicker::Choosing(
|
|
|
|
ScrollingMenu::new(
|
|
|
|
"Pick a color to change",
|
|
|
|
state.ui.state.cs.color_names(),
|
|
|
|
),
|
|
|
|
));
|
2019-04-26 20:21:05 +03:00
|
|
|
}
|
|
|
|
|
2019-04-26 02:24:10 +03:00
|
|
|
EventLoopMode::InputOnly
|
|
|
|
}
|
|
|
|
State::Polygons(ref mut debugger) => {
|
|
|
|
if debugger.event(ctx) {
|
|
|
|
mode.state = State::Exploring;
|
|
|
|
}
|
|
|
|
EventLoopMode::InputOnly
|
2019-04-26 02:16:21 +03:00
|
|
|
}
|
2019-04-26 20:21:05 +03:00
|
|
|
State::SearchOSM(ref mut tb) => {
|
|
|
|
match tb.event(&mut ctx.input) {
|
|
|
|
InputResult::Canceled => {
|
|
|
|
mode.state = State::Exploring;
|
|
|
|
}
|
|
|
|
InputResult::Done(filter, _) => {
|
|
|
|
mode.state = State::Exploring;
|
|
|
|
|
|
|
|
let mut ids = HashSet::new();
|
|
|
|
let map = &state.ui.state.primary.map;
|
|
|
|
for r in map.all_roads() {
|
|
|
|
if r.osm_tags
|
|
|
|
.iter()
|
|
|
|
.any(|(k, v)| format!("{} = {}", k, v).contains(&filter))
|
|
|
|
{
|
|
|
|
for l in r.all_lanes() {
|
|
|
|
ids.insert(ID::Lane(l));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for b in map.all_buildings() {
|
|
|
|
if b.osm_tags
|
|
|
|
.iter()
|
|
|
|
.any(|(k, v)| format!("{} = {}", k, v).contains(&filter))
|
|
|
|
{
|
|
|
|
ids.insert(ID::Building(b.id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mode.search_results = Some((filter, ids));
|
|
|
|
}
|
|
|
|
InputResult::StillActive => {}
|
|
|
|
}
|
|
|
|
EventLoopMode::InputOnly
|
|
|
|
}
|
2019-04-26 20:46:41 +03:00
|
|
|
State::Colors(ref mut picker) => {
|
|
|
|
if picker.event(ctx, &mut state.ui) {
|
|
|
|
mode.state = State::Exploring;
|
|
|
|
}
|
|
|
|
EventLoopMode::InputOnly
|
|
|
|
}
|
2019-04-26 02:16:21 +03:00
|
|
|
}
|
2019-04-26 01:50:16 +03:00
|
|
|
}
|
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn draw(state: &GameState, g: &mut GfxCtx) {
|
|
|
|
match state.mode {
|
|
|
|
Mode::Debug(ref mode) => match mode.state {
|
|
|
|
State::Exploring => {
|
2019-04-26 02:02:40 +03:00
|
|
|
let mut color_overrides = HashMap::new();
|
|
|
|
if let Some(ref chokepoints) = mode.chokepoints {
|
|
|
|
let color = state.ui.state.cs.get_def("chokepoint", Color::RED);
|
|
|
|
for l in &chokepoints.lanes {
|
|
|
|
color_overrides.insert(ID::Lane(*l), color);
|
|
|
|
}
|
|
|
|
for i in &chokepoints.intersections {
|
|
|
|
color_overrides.insert(ID::Intersection(*i), color);
|
|
|
|
}
|
|
|
|
}
|
2019-04-26 02:35:09 +03:00
|
|
|
for l in &mode.connected_roads.lanes {
|
|
|
|
color_overrides.insert(
|
|
|
|
ID::Lane(*l),
|
|
|
|
state
|
|
|
|
.ui
|
|
|
|
.state
|
|
|
|
.cs
|
|
|
|
.get("something associated with something else"),
|
|
|
|
);
|
|
|
|
}
|
2019-04-26 20:21:05 +03:00
|
|
|
if let Some((_, ref results)) = mode.search_results {
|
|
|
|
for id in results {
|
|
|
|
color_overrides.insert(
|
|
|
|
*id,
|
|
|
|
state.ui.state.cs.get_def("search result", Color::RED),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-04-26 01:50:16 +03:00
|
|
|
state
|
|
|
|
.ui
|
2019-04-26 02:56:38 +03:00
|
|
|
.new_draw(g, None, color_overrides, &state.ui.state.primary.sim, mode);
|
2019-04-26 02:16:21 +03:00
|
|
|
|
|
|
|
for id in &mode.show_original_roads {
|
|
|
|
let r = state.ui.state.primary.map.get_r(*id);
|
|
|
|
if let Some(pair) = r.get_center_for_side(true) {
|
|
|
|
let (pl, width) = pair.unwrap();
|
|
|
|
g.draw_polygon(
|
|
|
|
state
|
|
|
|
.ui
|
|
|
|
.state
|
|
|
|
.cs
|
|
|
|
.get_def("original road forwards", Color::RED.alpha(0.5)),
|
|
|
|
&pl.make_polygons(width),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if let Some(pair) = r.get_center_for_side(false) {
|
|
|
|
let (pl, width) = pair.unwrap();
|
|
|
|
g.draw_polygon(
|
|
|
|
state
|
|
|
|
.ui
|
|
|
|
.state
|
|
|
|
.cs
|
|
|
|
.get_def("original road backwards", Color::BLUE.alpha(0.5)),
|
|
|
|
&pl.make_polygons(width),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-04-26 02:40:26 +03:00
|
|
|
|
|
|
|
mode.objects.draw(g, &state.ui);
|
2019-04-27 23:58:36 +03:00
|
|
|
mode.neighborhood_summary.draw(g);
|
2019-04-26 01:50:16 +03:00
|
|
|
}
|
2019-04-26 02:24:10 +03:00
|
|
|
State::Polygons(ref debugger) => {
|
|
|
|
state
|
|
|
|
.ui
|
2019-04-26 02:56:38 +03:00
|
|
|
.new_draw(g, None, HashMap::new(), &state.ui.state.primary.sim, mode);
|
2019-04-26 02:24:10 +03:00
|
|
|
debugger.draw(g, &state.ui);
|
|
|
|
}
|
2019-04-26 20:21:05 +03:00
|
|
|
State::SearchOSM(ref tb) => {
|
2019-04-26 20:46:41 +03:00
|
|
|
state
|
|
|
|
.ui
|
|
|
|
.new_draw(g, None, HashMap::new(), &state.ui.state.primary.sim, mode);
|
2019-04-26 20:21:05 +03:00
|
|
|
tb.draw(g);
|
|
|
|
}
|
2019-04-26 20:46:41 +03:00
|
|
|
State::Colors(ref picker) => {
|
|
|
|
state
|
|
|
|
.ui
|
|
|
|
.new_draw(g, None, HashMap::new(), &state.ui.state.primary.sim, mode);
|
|
|
|
picker.draw(g);
|
|
|
|
}
|
2019-04-26 01:50:16 +03:00
|
|
|
},
|
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-26 02:56:38 +03:00
|
|
|
|
|
|
|
impl ShowObject for DebugMode {
|
|
|
|
fn show(&self, obj: ID) -> bool {
|
2019-04-26 08:19:54 +03:00
|
|
|
if self.hidden.contains(&obj) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
match obj {
|
|
|
|
ID::Road(_) | ID::Lane(_) => self.layers.show_lanes,
|
|
|
|
ID::Building(_) => self.layers.show_buildings,
|
|
|
|
ID::Intersection(_) => self.layers.show_intersections,
|
|
|
|
ID::ExtraShape(_) => self.layers.show_extra_shapes,
|
|
|
|
ID::Area(_) => self.layers.show_areas,
|
|
|
|
_ => true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn layers(&self) -> &ShowLayers {
|
|
|
|
&self.layers
|
2019-04-26 02:56:38 +03:00
|
|
|
}
|
|
|
|
}
|