mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-29 17:34:58 +03:00
prep for ID::PedCrowd... make ID not be Copy
This commit is contained in:
parent
caddf69dcc
commit
0379ceae11
@ -151,7 +151,12 @@ impl State for ABTestMode {
|
||||
&mut ui.primary,
|
||||
ui.secondary.as_mut().unwrap(),
|
||||
));
|
||||
} else if let Some(agent) = ui.primary.current_selection.and_then(|id| id.agent_id()) {
|
||||
} else if let Some(agent) = ui
|
||||
.primary
|
||||
.current_selection
|
||||
.as_ref()
|
||||
.and_then(|id| id.agent_id())
|
||||
{
|
||||
if let Some(trip) = ui.primary.sim.agent_to_trip(agent) {
|
||||
if ctx
|
||||
.input
|
||||
|
@ -28,7 +28,12 @@ impl AgentTools {
|
||||
|
||||
pub fn event(&mut self, ctx: &mut EventCtx, ui: &UI, menu: &mut ModalMenu) {
|
||||
if self.following.is_none() {
|
||||
if let Some(agent) = ui.primary.current_selection.and_then(|id| id.agent_id()) {
|
||||
if let Some(agent) = ui
|
||||
.primary
|
||||
.current_selection
|
||||
.as_ref()
|
||||
.and_then(|id| id.agent_id())
|
||||
{
|
||||
if let Some(trip) = ui.primary.sim.agent_to_trip(agent) {
|
||||
if ctx
|
||||
.input
|
||||
|
@ -19,7 +19,7 @@ pub enum ShowAssociatedState {
|
||||
|
||||
impl ShowAssociatedState {
|
||||
pub fn event(&mut self, ui: &UI) {
|
||||
let selected = ui.primary.current_selection;
|
||||
let selected = ui.primary.current_selection.clone();
|
||||
let sim = &ui.primary.sim;
|
||||
|
||||
// Reset to Inactive when appropriate
|
||||
|
@ -96,10 +96,10 @@ impl CommonState {
|
||||
batch.draw(g);
|
||||
}
|
||||
|
||||
CommonState::draw_osd(g, ui, ui.primary.current_selection);
|
||||
CommonState::draw_osd(g, ui, &ui.primary.current_selection);
|
||||
}
|
||||
|
||||
pub fn draw_osd(g: &mut GfxCtx, ui: &UI, id: Option<ID>) {
|
||||
pub fn draw_osd(g: &mut GfxCtx, ui: &UI, id: &Option<ID>) {
|
||||
let map = &ui.primary.map;
|
||||
let id_color = ui.cs.get_def("OSD ID color", Color::RED);
|
||||
let name_color = ui.cs.get_def("OSD name color", Color::CYAN);
|
||||
@ -111,16 +111,16 @@ impl CommonState {
|
||||
Some(ID::Lane(l)) => {
|
||||
osd.append(format!("{}", l), Some(id_color));
|
||||
osd.append(" is ".to_string(), None);
|
||||
osd.append(map.get_parent(l).get_name(), Some(name_color));
|
||||
osd.append(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(map.get_b(b).get_name(), Some(name_color));
|
||||
osd.append(map.get_b(*b).get_name(), Some(name_color));
|
||||
}
|
||||
Some(ID::Turn(t)) => {
|
||||
osd.append(
|
||||
format!("TurnID({})", map.get_t(t).lookup_idx),
|
||||
format!("TurnID({})", map.get_t(*t).lookup_idx),
|
||||
Some(id_color),
|
||||
);
|
||||
osd.append(" between ".to_string(), None);
|
||||
@ -133,7 +133,7 @@ impl CommonState {
|
||||
osd.append(" of ".to_string(), None);
|
||||
|
||||
let mut road_names = BTreeSet::new();
|
||||
for r in &map.get_i(i).roads {
|
||||
for r in &map.get_i(*i).roads {
|
||||
road_names.insert(map.get_r(*r).get_name());
|
||||
}
|
||||
let len = road_names.len();
|
||||
@ -146,7 +146,7 @@ impl CommonState {
|
||||
}
|
||||
Some(ID::Car(c)) => {
|
||||
osd.append(format!("{}", c), Some(id_color));
|
||||
if let Some(r) = ui.primary.sim.bus_route_id(c) {
|
||||
if let Some(r) = ui.primary.sim.bus_route_id(*c) {
|
||||
osd.append(" serving ".to_string(), None);
|
||||
osd.append(map.get_br(r).name.to_string(), Some(name_color));
|
||||
}
|
||||
@ -155,7 +155,7 @@ impl CommonState {
|
||||
osd.append(format!("{}", bs), Some(id_color));
|
||||
osd.append(" serving ".to_string(), None);
|
||||
|
||||
let routes = map.get_routes_serving_stop(bs);
|
||||
let routes = map.get_routes_serving_stop(*bs);
|
||||
let len = routes.len();
|
||||
for (idx, n) in routes.into_iter().enumerate() {
|
||||
osd.append(n.name.clone(), Some(name_color));
|
||||
|
@ -15,7 +15,11 @@ pub struct RouteExplorer {
|
||||
impl RouteExplorer {
|
||||
pub fn new(ctx: &mut EventCtx, ui: &UI) -> Option<RouteExplorer> {
|
||||
let (agent, path) = if true {
|
||||
let agent = ui.primary.current_selection.and_then(|id| id.agent_id())?;
|
||||
let agent = ui
|
||||
.primary
|
||||
.current_selection
|
||||
.as_ref()
|
||||
.and_then(|id| id.agent_id())?;
|
||||
(agent, ui.primary.sim.get_path(agent)?.clone())
|
||||
} else {
|
||||
use map_model::{LaneID, PathRequest, Position};
|
||||
@ -96,6 +100,6 @@ impl State for RouteExplorer {
|
||||
}
|
||||
}
|
||||
self.slider.draw(g);
|
||||
CommonState::draw_osd(g, ui, ui.primary.current_selection);
|
||||
CommonState::draw_osd(g, ui, &ui.primary.current_selection);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,12 @@ impl RouteViewer {
|
||||
pub fn event(&mut self, ctx: &mut EventCtx, ui: &UI, menu: &mut ModalMenu) {
|
||||
match self {
|
||||
RouteViewer::Inactive => {
|
||||
if let Some(agent) = ui.primary.current_selection.and_then(|id| id.agent_id()) {
|
||||
if let Some(agent) = ui
|
||||
.primary
|
||||
.current_selection
|
||||
.as_ref()
|
||||
.and_then(|id| id.agent_id())
|
||||
{
|
||||
if let Some(trace) = ui.primary.sim.trace_route(agent, &ui.primary.map, None) {
|
||||
*self = RouteViewer::Hovering(ui.primary.sim.time(), agent, trace);
|
||||
}
|
||||
@ -29,8 +34,11 @@ impl RouteViewer {
|
||||
|| ui.primary.current_selection != Some(ID::from_agent(agent))
|
||||
{
|
||||
*self = RouteViewer::Inactive;
|
||||
if let Some(new_agent) =
|
||||
ui.primary.current_selection.and_then(|id| id.agent_id())
|
||||
if let Some(new_agent) = ui
|
||||
.primary
|
||||
.current_selection
|
||||
.as_ref()
|
||||
.and_then(|id| id.agent_id())
|
||||
{
|
||||
// Gross.
|
||||
agent = new_agent;
|
||||
|
@ -15,7 +15,11 @@ pub struct TripExplorer {
|
||||
impl TripExplorer {
|
||||
pub fn new(ctx: &mut EventCtx, ui: &UI) -> Option<TripExplorer> {
|
||||
let map = &ui.primary.map;
|
||||
let agent = ui.primary.current_selection.and_then(|id| id.agent_id())?;
|
||||
let agent = ui
|
||||
.primary
|
||||
.current_selection
|
||||
.as_ref()
|
||||
.and_then(|id| id.agent_id())?;
|
||||
let trip = ui.primary.sim.agent_to_trip(agent)?;
|
||||
let status = ui.primary.sim.trip_status(trip)?;
|
||||
if !ctx.input.contextual_action(Key::T, "explore trip") {
|
||||
@ -77,7 +81,7 @@ impl State for TripExplorer {
|
||||
|
||||
if let Some((evmode, done_warping)) = self.slider.event(ctx) {
|
||||
if done_warping {
|
||||
ui.primary.current_selection = Some(*self.slider.get().1);
|
||||
ui.primary.current_selection = Some(self.slider.get().1.clone());
|
||||
}
|
||||
Transition::KeepWithMode(evmode)
|
||||
} else {
|
||||
@ -87,6 +91,6 @@ impl State for TripExplorer {
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, ui: &UI) {
|
||||
self.slider.draw(g);
|
||||
CommonState::draw_osd(g, ui, ui.primary.current_selection);
|
||||
CommonState::draw_osd(g, ui, &ui.primary.current_selection);
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ impl State for Warping {
|
||||
if let Some(evmode) = self.warper.event(ctx) {
|
||||
Transition::KeepWithMode(evmode)
|
||||
} else {
|
||||
ui.primary.current_selection = self.id;
|
||||
ui.primary.current_selection = self.id.clone();
|
||||
Transition::Pop
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ impl State for BusRouteExplorer {
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, ui: &UI) {
|
||||
self.slider.draw(g);
|
||||
CommonState::draw_osd(g, ui, ui.primary.current_selection);
|
||||
CommonState::draw_osd(g, ui, &ui.primary.current_selection);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,7 +178,7 @@ impl State for DebugMode {
|
||||
}
|
||||
match ui.primary.current_selection {
|
||||
Some(ID::Lane(_)) | Some(ID::Intersection(_)) | Some(ID::ExtraShape(_)) => {
|
||||
let id = ui.primary.current_selection.unwrap();
|
||||
let id = ui.primary.current_selection.clone().unwrap();
|
||||
if ctx
|
||||
.input
|
||||
.contextual_action(Key::H, &format!("hide {:?}", id))
|
||||
@ -311,7 +311,8 @@ impl State for DebugMode {
|
||||
if g.canvas.cam_zoom >= MIN_ZOOM_FOR_DETAIL {
|
||||
if let Some(ref results) = self.search_results {
|
||||
for id in &results.ids {
|
||||
opts.override_colors.insert(*id, ui.cs.get("search result"));
|
||||
opts.override_colors
|
||||
.insert(id.clone(), ui.cs.get("search result"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -360,8 +361,8 @@ impl State for DebugMode {
|
||||
}
|
||||
|
||||
impl ShowObject for DebugMode {
|
||||
fn show(&self, obj: ID) -> bool {
|
||||
if self.hidden.contains(&obj) {
|
||||
fn show(&self, obj: &ID) -> bool {
|
||||
if self.hidden.contains(obj) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ impl ObjectDebugger {
|
||||
}
|
||||
|
||||
pub fn event(&mut self, ctx: &mut EventCtx, ui: &UI) {
|
||||
self.selected = ui.primary.current_selection;
|
||||
self.selected = ui.primary.current_selection.clone();
|
||||
if self.tooltip_key_held {
|
||||
self.tooltip_key_held = !ctx.input.key_released(Key::LeftControl);
|
||||
} else {
|
||||
@ -42,17 +42,22 @@ impl ObjectDebugger {
|
||||
.unimportant_key_pressed(Key::RightControl, "hold to show debug tooltips");
|
||||
}
|
||||
|
||||
if let Some(id) = self.selected {
|
||||
if let Some(ref id) = self.selected {
|
||||
if ctx.input.contextual_action(Key::D, "debug") {
|
||||
dump_debug(id, &ui.primary.map, &ui.primary.sim, &ui.primary.draw_map);
|
||||
dump_debug(
|
||||
id.clone(),
|
||||
&ui.primary.map,
|
||||
&ui.primary.sim,
|
||||
&ui.primary.draw_map,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw(&self, g: &mut GfxCtx, ui: &UI) {
|
||||
if self.tooltip_key_held {
|
||||
if let Some(id) = self.selected {
|
||||
let txt = tooltip_lines(id, g, &ui.primary);
|
||||
if let Some(ref id) = self.selected {
|
||||
let txt = tooltip_lines(id.clone(), g, &ui.primary);
|
||||
g.draw_mouse_tooltip(&txt);
|
||||
}
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ impl State for StopSignEditor {
|
||||
);
|
||||
CommonState::draw_custom_osd(g, osd);
|
||||
} else {
|
||||
CommonState::draw_osd(g, ui, None);
|
||||
CommonState::draw_osd(g, ui, &None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -250,9 +250,9 @@ impl State for TrafficSignalEditor {
|
||||
|
||||
self.menu.draw(g);
|
||||
if let Some(t) = self.icon_selected {
|
||||
CommonState::draw_osd(g, ui, Some(ID::Turn(t)));
|
||||
CommonState::draw_osd(g, ui, &Some(ID::Turn(t)));
|
||||
} else {
|
||||
CommonState::draw_osd(g, ui, None);
|
||||
CommonState::draw_osd(g, ui, &None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ use sim::{AgentID, CarID, GetDrawAgents, PedestrianID, TripID};
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::io::Error;
|
||||
|
||||
#[derive(Clone, Copy, Hash, PartialEq, Eq, Debug, PartialOrd, Ord)]
|
||||
#[derive(Clone, Hash, PartialEq, Eq, Debug, PartialOrd, Ord)]
|
||||
pub enum ID {
|
||||
Road(RoadID),
|
||||
Lane(LaneID),
|
||||
|
@ -189,6 +189,6 @@ impl State for TripsVisualizer {
|
||||
self.time_slider
|
||||
.draw(g, Some(Text::from_line(format!("At {}", time))));
|
||||
self.speed.draw(g);
|
||||
CommonState::draw_osd(g, ui, ui.primary.current_selection);
|
||||
CommonState::draw_osd(g, ui, &ui.primary.current_selection);
|
||||
}
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ impl State for DataVisualizer {
|
||||
osd.append(name.clone(), Some(ui.cs.get("OSD name color")));
|
||||
CommonState::draw_custom_osd(g, osd);
|
||||
} else {
|
||||
CommonState::draw_osd(g, ui, None);
|
||||
CommonState::draw_osd(g, ui, &None);
|
||||
}
|
||||
|
||||
if let Some(ref name) = self.current_tract {
|
||||
|
@ -125,7 +125,7 @@ impl State for TripsVisualizer {
|
||||
}
|
||||
CommonState::draw_custom_osd(g, osd);
|
||||
} else {
|
||||
CommonState::draw_osd(g, ui, ui.primary.current_selection);
|
||||
CommonState::draw_osd(g, ui, &ui.primary.current_selection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -320,7 +320,7 @@ impl DrawMap {
|
||||
pub fn get_matching_objects(&self, bounds: Bounds) -> Vec<ID> {
|
||||
let mut results: Vec<ID> = Vec::new();
|
||||
for &(id, _, _) in &self.quadtree.query(bounds.as_bbox()) {
|
||||
results.push(*id);
|
||||
results.push(id.clone());
|
||||
}
|
||||
results
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ impl State for AgentSpawner {
|
||||
}
|
||||
|
||||
self.menu.draw(g);
|
||||
CommonState::draw_osd(g, ui, ui.primary.current_selection);
|
||||
CommonState::draw_osd(g, ui, &ui.primary.current_selection);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ impl UI {
|
||||
|
||||
if layers.show_extra_shapes {
|
||||
for es in &self.primary.draw_map.extra_shapes {
|
||||
if show_objs.show(es.get_id()) {
|
||||
if show_objs.show(&es.get_id()) {
|
||||
es.draw(g, &opts, &ctx);
|
||||
}
|
||||
}
|
||||
@ -275,7 +275,7 @@ impl UI {
|
||||
let mut agents_on: Vec<Traversable> = Vec::new();
|
||||
|
||||
for id in draw_map.get_matching_objects(bounds) {
|
||||
if !show_objs.show(id) {
|
||||
if !show_objs.show(&id) {
|
||||
continue;
|
||||
}
|
||||
match id {
|
||||
@ -400,7 +400,7 @@ impl ShowLayers {
|
||||
}
|
||||
|
||||
pub trait ShowObject {
|
||||
fn show(&self, obj: ID) -> bool;
|
||||
fn show(&self, obj: &ID) -> bool;
|
||||
fn layers(&self) -> &ShowLayers;
|
||||
}
|
||||
|
||||
@ -417,7 +417,7 @@ impl ShowEverything {
|
||||
}
|
||||
|
||||
impl ShowObject for ShowEverything {
|
||||
fn show(&self, _: ID) -> bool {
|
||||
fn show(&self, _: &ID) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user