mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-28 08:53:26 +03:00
connected roads plugin
This commit is contained in:
parent
30411b66c3
commit
6447657ad8
@ -1,12 +1,12 @@
|
||||
use crate::objects::{DrawCtx, ID};
|
||||
use crate::plugins::{AmbientPlugin, PluginCtx};
|
||||
use ezgui::{Color, Key};
|
||||
use crate::objects::ID;
|
||||
use crate::ui::UI;
|
||||
use ezgui::{EventCtx, Key};
|
||||
use map_model::LaneID;
|
||||
use std::collections::HashSet;
|
||||
|
||||
pub struct ShowConnectedRoads {
|
||||
key_held: bool,
|
||||
lanes: HashSet<LaneID>,
|
||||
pub lanes: HashSet<LaneID>,
|
||||
}
|
||||
|
||||
impl ShowConnectedRoads {
|
||||
@ -16,10 +16,8 @@ impl ShowConnectedRoads {
|
||||
lanes: HashSet::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AmbientPlugin for ShowConnectedRoads {
|
||||
fn ambient_event(&mut self, ctx: &mut PluginCtx) {
|
||||
pub fn event(&mut self, ctx: &mut EventCtx, ui: &UI) {
|
||||
if self.key_held {
|
||||
self.key_held = !ctx.input.key_released(Key::RightAlt);
|
||||
} else {
|
||||
@ -33,20 +31,12 @@ impl AmbientPlugin for ShowConnectedRoads {
|
||||
|
||||
self.lanes.clear();
|
||||
if self.key_held {
|
||||
if let Some(ID::Intersection(i)) = ctx.primary.current_selection {
|
||||
for r in &ctx.primary.map.get_i(i).roads {
|
||||
self.lanes.extend(ctx.primary.map.get_r(*r).all_lanes());
|
||||
if let Some(ID::Intersection(i)) = ui.state.primary.current_selection {
|
||||
for r in &ui.state.primary.map.get_i(i).roads {
|
||||
self.lanes
|
||||
.extend(ui.state.primary.map.get_r(*r).all_lanes());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn color_for(&self, obj: ID, ctx: &DrawCtx) -> Option<Color> {
|
||||
if let ID::Lane(id) = obj {
|
||||
if self.lanes.contains(&id) {
|
||||
return Some(ctx.cs.get("something associated with something else"));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
mod chokepoints;
|
||||
mod connected_roads;
|
||||
mod polygons;
|
||||
|
||||
use crate::game::{GameState, Mode};
|
||||
@ -11,6 +12,7 @@ pub struct DebugMode {
|
||||
state: State,
|
||||
chokepoints: Option<chokepoints::ChokepointsFinder>,
|
||||
show_original_roads: HashSet<RoadID>,
|
||||
connected_roads: connected_roads::ShowConnectedRoads,
|
||||
}
|
||||
|
||||
enum State {
|
||||
@ -24,6 +26,7 @@ impl DebugMode {
|
||||
state: State::Exploring,
|
||||
chokepoints: None,
|
||||
show_original_roads: HashSet::new(),
|
||||
connected_roads: connected_roads::ShowConnectedRoads::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,6 +89,7 @@ impl DebugMode {
|
||||
mode.show_original_roads.insert(id);
|
||||
}
|
||||
}
|
||||
mode.connected_roads.event(ctx, &state.ui);
|
||||
|
||||
if let Some(debugger) = polygons::PolygonDebugger::new(ctx, &state.ui) {
|
||||
mode.state = State::Polygons(debugger);
|
||||
@ -119,6 +123,16 @@ impl DebugMode {
|
||||
color_overrides.insert(ID::Intersection(*i), color);
|
||||
}
|
||||
}
|
||||
for l in &mode.connected_roads.lanes {
|
||||
color_overrides.insert(
|
||||
ID::Lane(*l),
|
||||
state
|
||||
.ui
|
||||
.state
|
||||
.cs
|
||||
.get("something associated with something else"),
|
||||
);
|
||||
}
|
||||
state
|
||||
.ui
|
||||
.new_draw(g, None, color_overrides, &state.ui.state.primary.sim);
|
||||
|
@ -1,4 +1,3 @@
|
||||
pub mod connected_roads;
|
||||
pub mod debug_objects;
|
||||
pub mod hider;
|
||||
pub mod layers;
|
||||
|
@ -391,8 +391,6 @@ impl PluginsPerMap {
|
||||
if enable_debug_controls {
|
||||
p.ambient_plugins
|
||||
.push(Box::new(debug::debug_objects::DebugObjectsState::new()));
|
||||
p.ambient_plugins
|
||||
.push(Box::new(debug::connected_roads::ShowConnectedRoads::new()));
|
||||
}
|
||||
p
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user