2018-12-17 01:08:14 +03:00
|
|
|
use crate::objects::{Ctx, ID};
|
2018-12-06 21:18:20 +03:00
|
|
|
use crate::plugins::{Plugin, PluginCtx};
|
2018-12-16 05:27:43 +03:00
|
|
|
use ezgui::{Color, GfxCtx, Key, Text, TEXT_FG_COLOR};
|
2018-12-14 22:07:35 +03:00
|
|
|
use std::collections::BTreeMap;
|
2018-09-13 19:59:49 +03:00
|
|
|
|
2018-12-06 07:00:58 +03:00
|
|
|
pub struct DebugObjectsState {
|
2018-12-08 01:25:16 +03:00
|
|
|
tooltip_key_held: bool,
|
2018-12-06 07:00:58 +03:00
|
|
|
selected: Option<ID>,
|
2018-12-08 01:25:16 +03:00
|
|
|
|
|
|
|
tooltip_key: Key,
|
|
|
|
debug_key: Key,
|
2018-09-13 19:59:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl DebugObjectsState {
|
2018-12-08 01:25:16 +03:00
|
|
|
pub fn new(tooltip_key: Key, debug_key: Key) -> DebugObjectsState {
|
2018-12-06 07:00:58 +03:00
|
|
|
DebugObjectsState {
|
2018-12-08 01:25:16 +03:00
|
|
|
tooltip_key_held: false,
|
2018-12-06 07:00:58 +03:00
|
|
|
selected: None,
|
2018-12-08 01:25:16 +03:00
|
|
|
tooltip_key,
|
|
|
|
debug_key,
|
2018-12-06 07:00:58 +03:00
|
|
|
}
|
2018-09-13 19:59:49 +03:00
|
|
|
}
|
2018-10-22 06:28:51 +03:00
|
|
|
}
|
|
|
|
|
2018-10-22 19:06:02 +03:00
|
|
|
impl Plugin for DebugObjectsState {
|
2018-12-06 07:00:58 +03:00
|
|
|
fn ambient_event(&mut self, ctx: &mut PluginCtx) {
|
|
|
|
self.selected = ctx.primary.current_selection;
|
2018-12-08 01:25:16 +03:00
|
|
|
if self.tooltip_key_held {
|
|
|
|
self.tooltip_key_held = !ctx.input.key_released(self.tooltip_key);
|
2018-09-13 19:59:49 +03:00
|
|
|
} else {
|
2018-12-06 07:00:58 +03:00
|
|
|
// TODO Can't really display an OSD action if we're not currently selecting something.
|
|
|
|
// Could only activate sometimes, but that seems a bit harder to use.
|
2018-12-17 01:08:14 +03:00
|
|
|
self.tooltip_key_held = ctx
|
|
|
|
.input
|
|
|
|
.unimportant_key_pressed(self.tooltip_key, "hold Ctrl to show tooltips");
|
2018-12-06 07:00:58 +03:00
|
|
|
}
|
2018-09-13 19:59:49 +03:00
|
|
|
|
2018-12-06 07:00:58 +03:00
|
|
|
if let Some(id) = self.selected {
|
2018-12-15 02:10:33 +03:00
|
|
|
if ctx.input.contextual_action(self.debug_key, "debug") {
|
2018-12-06 07:00:58 +03:00
|
|
|
id.debug(
|
|
|
|
&ctx.primary.map,
|
|
|
|
&mut ctx.primary.sim,
|
|
|
|
&ctx.primary.draw_map,
|
|
|
|
);
|
2018-09-13 19:59:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-22 19:43:48 +03:00
|
|
|
|
2018-12-13 04:08:15 +03:00
|
|
|
fn draw(&self, g: &mut GfxCtx, ctx: &Ctx) {
|
2018-12-08 01:25:16 +03:00
|
|
|
if self.tooltip_key_held {
|
2018-12-06 07:00:58 +03:00
|
|
|
if let Some(id) = self.selected {
|
|
|
|
ctx.canvas.draw_mouse_tooltip(g, tooltip_lines(id, ctx));
|
2018-10-22 19:43:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-13 19:59:49 +03:00
|
|
|
}
|
2018-11-20 21:51:12 +03:00
|
|
|
|
2018-12-06 07:00:58 +03:00
|
|
|
fn tooltip_lines(obj: ID, ctx: &Ctx) -> Text {
|
|
|
|
let (map, sim, draw_map) = (&ctx.map, &ctx.sim, &ctx.draw_map);
|
2018-11-20 21:51:12 +03:00
|
|
|
let mut txt = Text::new();
|
|
|
|
match obj {
|
|
|
|
ID::Lane(id) => {
|
|
|
|
let l = map.get_l(id);
|
|
|
|
let r = map.get_r(l.parent);
|
|
|
|
let i1 = map.get_source_intersection(id);
|
|
|
|
let i2 = map.get_destination_intersection(id);
|
|
|
|
|
2018-12-14 22:07:35 +03:00
|
|
|
txt.add_line(format!("{} is ", l.id,));
|
|
|
|
txt.append(
|
2018-12-14 22:13:05 +03:00
|
|
|
r.osm_tags
|
|
|
|
.get("name")
|
|
|
|
.unwrap_or(&"???".to_string())
|
|
|
|
.to_string(),
|
2018-12-14 22:07:35 +03:00
|
|
|
Color::BLUE,
|
|
|
|
None,
|
|
|
|
);
|
2018-11-20 21:51:12 +03:00
|
|
|
txt.add_line(format!("From OSM way {}", r.osm_way_id));
|
|
|
|
txt.add_line(format!("Parent {} points to {}", r.id, r.dst_i));
|
|
|
|
txt.add_line(format!(
|
|
|
|
"Lane goes from {} to {}",
|
|
|
|
i1.elevation, i2.elevation
|
|
|
|
));
|
2018-11-28 22:56:20 +03:00
|
|
|
txt.add_line(format!(
|
|
|
|
"Lane is {} long, parent {} is {} long",
|
|
|
|
l.length(),
|
|
|
|
r.id,
|
|
|
|
r.center_pts.length()
|
|
|
|
));
|
2018-12-14 22:07:35 +03:00
|
|
|
styled_kv(&mut txt, &r.osm_tags);
|
2018-11-26 19:48:19 +03:00
|
|
|
if l.is_parking() {
|
|
|
|
txt.add_line(format!("Has {} parking spots", l.number_parking_spots()));
|
|
|
|
}
|
2018-11-20 21:51:12 +03:00
|
|
|
}
|
|
|
|
ID::Intersection(id) => {
|
|
|
|
txt.add_line(id.to_string());
|
|
|
|
txt.add_line(format!("Roads: {:?}", map.get_i(id).roads));
|
|
|
|
}
|
|
|
|
ID::Turn(id) => {
|
2018-12-02 01:38:42 +03:00
|
|
|
let t = map.get_t(id);
|
2018-11-20 21:51:12 +03:00
|
|
|
txt.add_line(format!("{}", id));
|
2018-12-02 02:44:27 +03:00
|
|
|
txt.add_line(format!("{:?}", t.turn_type));
|
2018-11-20 21:51:12 +03:00
|
|
|
}
|
|
|
|
ID::Building(id) => {
|
|
|
|
let b = map.get_b(id);
|
|
|
|
txt.add_line(format!(
|
|
|
|
"Building #{:?} (from OSM way {})",
|
|
|
|
id, b.osm_way_id
|
|
|
|
));
|
2018-12-14 22:07:35 +03:00
|
|
|
styled_kv(&mut txt, &b.osm_tags);
|
2018-11-20 21:51:12 +03:00
|
|
|
}
|
|
|
|
ID::Car(id) => {
|
|
|
|
for line in sim.car_tooltip(id) {
|
2018-12-10 02:16:32 +03:00
|
|
|
txt.add_wrapped_line(&ctx.canvas, line);
|
2018-11-20 21:51:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ID::Pedestrian(id) => {
|
|
|
|
for line in sim.ped_tooltip(id) {
|
2018-12-10 02:16:32 +03:00
|
|
|
txt.add_wrapped_line(&ctx.canvas, line);
|
2018-11-20 21:51:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ID::ExtraShape(id) => {
|
2018-12-14 22:07:35 +03:00
|
|
|
styled_kv(&mut txt, &draw_map.get_es(id).attributes);
|
2018-11-20 21:51:12 +03:00
|
|
|
}
|
|
|
|
ID::Parcel(id) => {
|
|
|
|
txt.add_line(id.to_string());
|
|
|
|
}
|
|
|
|
ID::BusStop(id) => {
|
|
|
|
txt.add_line(id.to_string());
|
2018-11-27 00:56:35 +03:00
|
|
|
for r in map.get_all_bus_routes() {
|
|
|
|
if r.stops.contains(&id) {
|
|
|
|
txt.add_line(format!("- Route {}", r.name));
|
|
|
|
}
|
|
|
|
}
|
2018-11-20 21:51:12 +03:00
|
|
|
}
|
|
|
|
ID::Area(id) => {
|
|
|
|
let a = map.get_a(id);
|
|
|
|
txt.add_line(format!("{} (from OSM way {})", id, a.osm_way_id));
|
2018-12-14 22:07:35 +03:00
|
|
|
styled_kv(&mut txt, &a.osm_tags);
|
2018-11-20 21:51:12 +03:00
|
|
|
}
|
|
|
|
ID::Trip(_) => {}
|
|
|
|
};
|
|
|
|
txt
|
|
|
|
}
|
2018-12-14 22:07:35 +03:00
|
|
|
|
|
|
|
fn styled_kv(txt: &mut Text, tags: &BTreeMap<String, String>) {
|
|
|
|
for (k, v) in tags {
|
|
|
|
txt.add_styled_line(k.to_string(), Color::RED, None);
|
|
|
|
txt.append(" = ".to_string(), TEXT_FG_COLOR, None);
|
|
|
|
txt.append(v.to_string(), Color::BLUE, None);
|
|
|
|
}
|
|
|
|
}
|