mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-29 01:13:53 +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::objects::ID;
|
||||||
use crate::plugins::{AmbientPlugin, PluginCtx};
|
use crate::ui::UI;
|
||||||
use ezgui::{Color, Key};
|
use ezgui::{EventCtx, Key};
|
||||||
use map_model::LaneID;
|
use map_model::LaneID;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
pub struct ShowConnectedRoads {
|
pub struct ShowConnectedRoads {
|
||||||
key_held: bool,
|
key_held: bool,
|
||||||
lanes: HashSet<LaneID>,
|
pub lanes: HashSet<LaneID>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShowConnectedRoads {
|
impl ShowConnectedRoads {
|
||||||
@ -16,10 +16,8 @@ impl ShowConnectedRoads {
|
|||||||
lanes: HashSet::new(),
|
lanes: HashSet::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl AmbientPlugin for ShowConnectedRoads {
|
pub fn event(&mut self, ctx: &mut EventCtx, ui: &UI) {
|
||||||
fn ambient_event(&mut self, ctx: &mut PluginCtx) {
|
|
||||||
if self.key_held {
|
if self.key_held {
|
||||||
self.key_held = !ctx.input.key_released(Key::RightAlt);
|
self.key_held = !ctx.input.key_released(Key::RightAlt);
|
||||||
} else {
|
} else {
|
||||||
@ -33,20 +31,12 @@ impl AmbientPlugin for ShowConnectedRoads {
|
|||||||
|
|
||||||
self.lanes.clear();
|
self.lanes.clear();
|
||||||
if self.key_held {
|
if self.key_held {
|
||||||
if let Some(ID::Intersection(i)) = ctx.primary.current_selection {
|
if let Some(ID::Intersection(i)) = ui.state.primary.current_selection {
|
||||||
for r in &ctx.primary.map.get_i(i).roads {
|
for r in &ui.state.primary.map.get_i(i).roads {
|
||||||
self.lanes.extend(ctx.primary.map.get_r(*r).all_lanes());
|
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 chokepoints;
|
||||||
|
mod connected_roads;
|
||||||
mod polygons;
|
mod polygons;
|
||||||
|
|
||||||
use crate::game::{GameState, Mode};
|
use crate::game::{GameState, Mode};
|
||||||
@ -11,6 +12,7 @@ pub struct DebugMode {
|
|||||||
state: State,
|
state: State,
|
||||||
chokepoints: Option<chokepoints::ChokepointsFinder>,
|
chokepoints: Option<chokepoints::ChokepointsFinder>,
|
||||||
show_original_roads: HashSet<RoadID>,
|
show_original_roads: HashSet<RoadID>,
|
||||||
|
connected_roads: connected_roads::ShowConnectedRoads,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum State {
|
enum State {
|
||||||
@ -24,6 +26,7 @@ impl DebugMode {
|
|||||||
state: State::Exploring,
|
state: State::Exploring,
|
||||||
chokepoints: None,
|
chokepoints: None,
|
||||||
show_original_roads: HashSet::new(),
|
show_original_roads: HashSet::new(),
|
||||||
|
connected_roads: connected_roads::ShowConnectedRoads::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,6 +89,7 @@ impl DebugMode {
|
|||||||
mode.show_original_roads.insert(id);
|
mode.show_original_roads.insert(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mode.connected_roads.event(ctx, &state.ui);
|
||||||
|
|
||||||
if let Some(debugger) = polygons::PolygonDebugger::new(ctx, &state.ui) {
|
if let Some(debugger) = polygons::PolygonDebugger::new(ctx, &state.ui) {
|
||||||
mode.state = State::Polygons(debugger);
|
mode.state = State::Polygons(debugger);
|
||||||
@ -119,6 +123,16 @@ impl DebugMode {
|
|||||||
color_overrides.insert(ID::Intersection(*i), color);
|
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
|
state
|
||||||
.ui
|
.ui
|
||||||
.new_draw(g, None, color_overrides, &state.ui.state.primary.sim);
|
.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 debug_objects;
|
||||||
pub mod hider;
|
pub mod hider;
|
||||||
pub mod layers;
|
pub mod layers;
|
||||||
|
@ -391,8 +391,6 @@ impl PluginsPerMap {
|
|||||||
if enable_debug_controls {
|
if enable_debug_controls {
|
||||||
p.ambient_plugins
|
p.ambient_plugins
|
||||||
.push(Box::new(debug::debug_objects::DebugObjectsState::new()));
|
.push(Box::new(debug::debug_objects::DebugObjectsState::new()));
|
||||||
p.ambient_plugins
|
|
||||||
.push(Box::new(debug::connected_roads::ShowConnectedRoads::new()));
|
|
||||||
}
|
}
|
||||||
p
|
p
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user