mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 20:29:04 +03:00
unifying tooltip handling a bit
This commit is contained in:
parent
dba3893ee5
commit
67ef04b3c2
@ -1001,6 +1001,7 @@ Alright, replan yet again.
|
||||
|
||||
- load water/parks and stuff
|
||||
- deal with overlapping keys that still kinda happen (sim ctrl, escape game)
|
||||
- and missing keys, like no tooltip for turns, since they're only shown in editors now
|
||||
- bug: do need to recalculate current_selection whenever anything potentially changes camera, like follow
|
||||
- consider merging control map into map
|
||||
- see how hard it is to render textures onto cars or something
|
||||
|
@ -3,7 +3,7 @@ use control::ControlMap;
|
||||
use ezgui::Canvas;
|
||||
use kml::ExtraShapeID;
|
||||
use map_model::{AreaID, BuildingID, BusStopID, IntersectionID, LaneID, Map, ParcelID, TurnID};
|
||||
use render::{DrawMap, Renderable};
|
||||
use render::DrawMap;
|
||||
use sim::{CarID, PedestrianID, Sim};
|
||||
|
||||
#[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)]
|
||||
@ -53,19 +53,11 @@ impl ID {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Renderable has tooltip_lines... decide what goes where
|
||||
pub fn tooltip_lines(&self, map: &Map, draw_map: &DrawMap, sim: &Sim) -> Vec<String> {
|
||||
match *self {
|
||||
ID::Lane(id) => draw_map.get_l(id).tooltip_lines(map),
|
||||
ID::Building(id) => draw_map.get_b(id).tooltip_lines(map),
|
||||
ID::Car(id) => sim.car_tooltip(id),
|
||||
ID::Pedestrian(id) => sim.ped_tooltip(id),
|
||||
ID::Intersection(id) => vec![format!("{}", id)],
|
||||
ID::Turn(id) => map.get_t(id).tooltip_lines(map),
|
||||
ID::ExtraShape(id) => draw_map.get_es(id).tooltip_lines(map),
|
||||
ID::BusStop(id) => draw_map.get_bs(id).tooltip_lines(map),
|
||||
ID::Parcel(id) => vec![format!("{}", id)],
|
||||
ID::Area(id) => vec![format!("{}", id)],
|
||||
x => draw_map.get_obj(x).tooltip_lines(map),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -175,6 +175,20 @@ impl DrawMap {
|
||||
self.turns.insert(id, draw_turn);
|
||||
}
|
||||
|
||||
pub fn get_obj(&self, id: ID) -> Box<&Renderable> {
|
||||
match id {
|
||||
ID::Lane(id) => Box::new(self.get_l(id)),
|
||||
ID::Building(id) => Box::new(self.get_b(id)),
|
||||
ID::Intersection(id) => Box::new(self.get_i(id)),
|
||||
ID::Turn(id) => Box::new(self.get_t(id)),
|
||||
ID::ExtraShape(id) => Box::new(self.get_es(id)),
|
||||
ID::BusStop(id) => Box::new(self.get_bs(id)),
|
||||
ID::Parcel(id) => Box::new(self.get_p(id)),
|
||||
ID::Area(id) => Box::new(self.get_a(id)),
|
||||
ID::Car(_) | ID::Pedestrian(_) => panic!("get_obj doesn't work for dynamic {:?}", id),
|
||||
}
|
||||
}
|
||||
|
||||
// The alt to these is implementing std::ops::Index, but that's way more verbose!
|
||||
pub fn get_l(&self, id: LaneID) -> &DrawLane {
|
||||
&self.lanes[id.0]
|
||||
|
@ -99,7 +99,10 @@ impl Renderable for DrawTurn {
|
||||
geometry::point_in_circle(&self.icon_circle, pt)
|
||||
}
|
||||
|
||||
fn tooltip_lines(&self, _map: &Map) -> Vec<String> {
|
||||
vec![self.id.to_string()]
|
||||
fn tooltip_lines(&self, map: &Map) -> Vec<String> {
|
||||
vec![
|
||||
format!("{}", self.id),
|
||||
format!("Angle {}", map.get_t(self.id).turn_angle(map)),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ impl Turn {
|
||||
|
||||
// TODO all the stuff based on turn angle is a bit... wrong, especially for sidewalks. :\
|
||||
// also, make sure right/left/straight are disjoint... and maybe cover all turns. return an enum from one method.
|
||||
fn turn_angle(&self, map: &Map) -> Angle {
|
||||
pub fn turn_angle(&self, map: &Map) -> Angle {
|
||||
let lane_angle = map.get_l(self.src).end_line(self.parent).angle();
|
||||
self.line.angle() - lane_angle
|
||||
}
|
||||
@ -85,11 +85,4 @@ impl Turn {
|
||||
let a = self.turn_angle(map).normalized_degrees();
|
||||
a <= 20.0 || a >= 320.0
|
||||
}
|
||||
|
||||
pub fn tooltip_lines(&self, map: &Map) -> Vec<String> {
|
||||
vec![
|
||||
format!("{}", self.id),
|
||||
format!("Angle {}", self.turn_angle(map)),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user