abstreet/editor/src/debug/objects.rs

70 lines
2.3 KiB
Rust
Raw Normal View History

2019-04-26 02:40:26 +03:00
use crate::objects::ID;
use crate::ui::UI;
use ezgui::{EventCtx, GfxCtx, Key, Text};
2019-04-26 02:40:26 +03:00
pub struct ObjectDebugger {
2018-12-08 01:25:16 +03:00
tooltip_key_held: bool,
2019-02-19 02:21:43 +03:00
debug_tooltip_key_held: bool,
selected: Option<ID>,
}
2019-04-26 02:40:26 +03:00
impl ObjectDebugger {
pub fn new() -> ObjectDebugger {
ObjectDebugger {
2018-12-08 01:25:16 +03:00
tooltip_key_held: false,
2019-02-19 02:21:43 +03:00
debug_tooltip_key_held: false,
selected: None,
}
}
2019-04-26 02:40:26 +03:00
pub fn event(&mut self, ctx: &mut EventCtx, ui: &UI) {
self.selected = ui.state.primary.current_selection;
2018-12-08 01:25:16 +03:00
if self.tooltip_key_held {
2018-12-17 20:51:31 +03:00
self.tooltip_key_held = !ctx.input.key_released(Key::LeftControl);
} else {
// 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.
self.tooltip_key_held = ctx
.input
2019-02-19 02:21:43 +03:00
.unimportant_key_pressed(Key::LeftControl, "hold to show tooltips");
}
if self.debug_tooltip_key_held {
self.debug_tooltip_key_held = !ctx.input.key_released(Key::RightControl);
} else {
self.debug_tooltip_key_held = ctx
.input
.unimportant_key_pressed(Key::RightControl, "hold to show debug tooltips");
}
if let Some(id) = self.selected {
2018-12-17 20:51:31 +03:00
if ctx.input.contextual_action(Key::D, "debug") {
2019-04-26 02:40:26 +03:00
id.debug(
&ui.state.primary.map,
&ui.state.primary.sim,
&ui.state.primary.draw_map,
);
}
}
}
2018-10-22 19:43:48 +03:00
2019-04-26 02:40:26 +03:00
pub fn draw(&self, g: &mut GfxCtx, ui: &UI) {
2018-12-08 01:25:16 +03:00
if self.tooltip_key_held {
if let Some(id) = self.selected {
2019-04-26 02:40:26 +03:00
let txt = id.tooltip_lines(g, &ui.state.primary);
g.draw_mouse_tooltip(&txt);
2018-10-22 19:43:48 +03:00
}
}
2019-02-19 02:21:43 +03:00
if self.debug_tooltip_key_held {
if let Some(pt) = g.canvas.get_cursor_in_map_space() {
2019-04-26 02:40:26 +03:00
if let Some(gps) = pt.to_gps(ui.state.primary.map.get_gps_bounds()) {
2019-02-19 02:21:43 +03:00
let mut txt = Text::new();
txt.add_line(format!("{}", pt));
txt.add_line(format!("{}", gps));
g.draw_mouse_tooltip(&txt);
2019-02-19 02:21:43 +03:00
}
}
}
2018-10-22 19:43:48 +03:00
}
}