2019-04-26 02:40:26 +03:00
|
|
|
use crate::objects::ID;
|
|
|
|
use crate::ui::UI;
|
|
|
|
use ezgui::{EventCtx, GfxCtx, Key, Text};
|
2018-09-13 19:59:49 +03:00
|
|
|
|
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,
|
2018-12-06 07:00:58 +03:00
|
|
|
selected: Option<ID>,
|
2018-09-13 19:59:49 +03:00
|
|
|
}
|
|
|
|
|
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,
|
2018-12-06 07:00:58 +03:00
|
|
|
selected: None,
|
|
|
|
}
|
2018-09-13 19:59:49 +03:00
|
|
|
}
|
2018-10-22 06:28:51 +03:00
|
|
|
|
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);
|
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
|
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");
|
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-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-09-13 19:59:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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 {
|
2018-12-06 07:00:58 +03:00
|
|
|
if let Some(id) = self.selected {
|
2019-04-26 02:40:26 +03:00
|
|
|
let txt = id.tooltip_lines(g, &ui.state.primary);
|
2019-04-22 23:19:36 +03:00
|
|
|
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));
|
2019-04-22 23:19:36 +03:00
|
|
|
g.draw_mouse_tooltip(&txt);
|
2019-02-19 02:21:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-22 19:43:48 +03:00
|
|
|
}
|
2018-09-13 19:59:49 +03:00
|
|
|
}
|