mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 07:25:47 +03:00
start a really basic OSD
This commit is contained in:
parent
08e1d3f353
commit
4b4e6f17a0
@ -7,7 +7,9 @@ use crate::helpers::ID;
|
||||
use crate::render::DrawOptions;
|
||||
use crate::ui::UI;
|
||||
use abstutil::elapsed_seconds;
|
||||
use ezgui::{EventCtx, EventLoopMode, GfxCtx, Key};
|
||||
use ezgui::{
|
||||
Color, EventCtx, EventLoopMode, GfxCtx, HorizontalAlignment, Key, Text, VerticalAlignment,
|
||||
};
|
||||
use geom::{Line, Pt2D};
|
||||
use std::time::Instant;
|
||||
|
||||
@ -71,6 +73,34 @@ impl CommonState {
|
||||
navigate.draw(g);
|
||||
}
|
||||
self.turn_cycler.draw(g, ui);
|
||||
|
||||
let id_color = ui.cs.get_def("OSD ID color", Color::RED);
|
||||
let name_color = ui.cs.get_def("OSD name color", Color::CYAN);
|
||||
let mut osd = Text::new();
|
||||
match ui.primary.current_selection {
|
||||
None => {
|
||||
osd.append("...".to_string(), None);
|
||||
}
|
||||
Some(ID::Lane(l)) => {
|
||||
osd.append(format!("{}", l), Some(id_color));
|
||||
osd.append(" is ".to_string(), None);
|
||||
osd.append(ui.primary.map.get_parent(l).get_name(), Some(name_color));
|
||||
}
|
||||
Some(ID::Building(b)) => {
|
||||
osd.append(format!("{}", b), Some(id_color));
|
||||
osd.append(" is ".to_string(), None);
|
||||
osd.append(ui.primary.map.get_b(b).get_name(), Some(name_color));
|
||||
}
|
||||
// TODO Intersections, cars, pedestrians...
|
||||
Some(id) => {
|
||||
osd.append(format!("{:?}", id), Some(id_color));
|
||||
}
|
||||
}
|
||||
// TODO Grab hotkeys from the context menu
|
||||
g.draw_blocking_text(
|
||||
&osd,
|
||||
(HorizontalAlignment::FillScreen, VerticalAlignment::Bottom),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn draw_options(&self, ui: &UI) -> DrawOptions {
|
||||
|
@ -188,6 +188,7 @@ pub enum HorizontalAlignment {
|
||||
Left,
|
||||
Center,
|
||||
Right,
|
||||
FillScreen,
|
||||
}
|
||||
|
||||
pub enum VerticalAlignment {
|
||||
|
@ -153,11 +153,15 @@ impl<'a> GfxCtx<'a> {
|
||||
if txt.is_empty() {
|
||||
return;
|
||||
}
|
||||
let (width, height) = self.text_dims(&txt);
|
||||
let (mut width, height) = self.text_dims(&txt);
|
||||
let x1 = match horiz {
|
||||
HorizontalAlignment::Left => 0.0,
|
||||
HorizontalAlignment::Center => (self.canvas.window_width - width) / 2.0,
|
||||
HorizontalAlignment::Right => self.canvas.window_width - width,
|
||||
HorizontalAlignment::FillScreen => {
|
||||
width = self.canvas.window_width;
|
||||
0.0
|
||||
}
|
||||
};
|
||||
let y1 = match vert {
|
||||
VerticalAlignment::Top => 0.0,
|
||||
|
@ -50,4 +50,18 @@ impl Building {
|
||||
pub fn sidewalk(&self) -> LaneID {
|
||||
self.front_path.sidewalk.lane()
|
||||
}
|
||||
|
||||
pub fn get_name(&self) -> String {
|
||||
self.osm_tags
|
||||
.get("name")
|
||||
.map(|s| s.to_string())
|
||||
.or_else(|| {
|
||||
self.osm_tags.get("addr:housenumber").and_then(|num| {
|
||||
self.osm_tags
|
||||
.get("addr:street")
|
||||
.map(|street| format!("{} {}", num, street))
|
||||
})
|
||||
})
|
||||
.unwrap_or("???".to_string())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user