mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-28 08:53:26 +03:00
original road plugin to debug mode
This commit is contained in:
parent
4df4a0931e
commit
43628c280e
@ -2,12 +2,14 @@ mod chokepoints;
|
||||
|
||||
use crate::game::{GameState, Mode};
|
||||
use crate::objects::ID;
|
||||
use ezgui::{Color, EventCtx, EventLoopMode, GfxCtx, Text, Wizard};
|
||||
use std::collections::HashMap;
|
||||
use ezgui::{Color, EventCtx, EventLoopMode, GfxCtx, Key, Text, Wizard};
|
||||
use map_model::RoadID;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
pub struct DebugMode {
|
||||
state: State,
|
||||
chokepoints: Option<chokepoints::ChokepointsFinder>,
|
||||
show_original_roads: HashSet<RoadID>,
|
||||
}
|
||||
|
||||
enum State {
|
||||
@ -19,6 +21,7 @@ impl DebugMode {
|
||||
DebugMode {
|
||||
state: State::Exploring,
|
||||
chokepoints: None,
|
||||
show_original_roads: HashSet::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,6 +39,12 @@ impl DebugMode {
|
||||
if mode.chokepoints.is_some() {
|
||||
txt.add_line("Showing chokepoints".to_string());
|
||||
}
|
||||
if !mode.show_original_roads.is_empty() {
|
||||
txt.add_line(format!(
|
||||
"Showing {} original roads",
|
||||
mode.show_original_roads.len()
|
||||
));
|
||||
}
|
||||
ctx.input
|
||||
.set_mode_with_new_prompt("Debug Mode", txt, ctx.canvas);
|
||||
if ctx.input.modal_action("quit") {
|
||||
@ -53,6 +62,21 @@ impl DebugMode {
|
||||
));
|
||||
}
|
||||
}
|
||||
if !mode.show_original_roads.is_empty() {
|
||||
if ctx.input.modal_action("clear original roads shown") {
|
||||
mode.show_original_roads.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ID::Lane(l)) = state.ui.state.primary.current_selection {
|
||||
let id = state.ui.state.primary.map.get_l(l).parent;
|
||||
if ctx
|
||||
.input
|
||||
.contextual_action(Key::V, &format!("show original geometry of {:?}", id))
|
||||
{
|
||||
mode.show_original_roads.insert(id);
|
||||
}
|
||||
}
|
||||
|
||||
EventLoopMode::InputOnly
|
||||
}
|
||||
@ -74,10 +98,35 @@ impl DebugMode {
|
||||
color_overrides.insert(ID::Intersection(*i), color);
|
||||
}
|
||||
}
|
||||
|
||||
state
|
||||
.ui
|
||||
.new_draw(g, None, color_overrides, &state.ui.state.primary.sim);
|
||||
|
||||
for id in &mode.show_original_roads {
|
||||
let r = state.ui.state.primary.map.get_r(*id);
|
||||
if let Some(pair) = r.get_center_for_side(true) {
|
||||
let (pl, width) = pair.unwrap();
|
||||
g.draw_polygon(
|
||||
state
|
||||
.ui
|
||||
.state
|
||||
.cs
|
||||
.get_def("original road forwards", Color::RED.alpha(0.5)),
|
||||
&pl.make_polygons(width),
|
||||
);
|
||||
}
|
||||
if let Some(pair) = r.get_center_for_side(false) {
|
||||
let (pl, width) = pair.unwrap();
|
||||
g.draw_polygon(
|
||||
state
|
||||
.ui
|
||||
.state
|
||||
.cs
|
||||
.get_def("original road backwards", Color::BLUE.alpha(0.5)),
|
||||
&pl.make_polygons(width),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => unreachable!(),
|
||||
|
@ -3,4 +3,3 @@ pub mod debug_objects;
|
||||
pub mod debug_polygon;
|
||||
pub mod hider;
|
||||
pub mod layers;
|
||||
pub mod orig_roads;
|
||||
|
@ -1,70 +0,0 @@
|
||||
use crate::objects::{DrawCtx, ID};
|
||||
use crate::plugins::{NonblockingPlugin, PluginCtx};
|
||||
use ezgui::{Color, GfxCtx, Key};
|
||||
use map_model::RoadID;
|
||||
use std::collections::HashSet;
|
||||
|
||||
pub struct ShowOriginalRoads {
|
||||
roads: HashSet<RoadID>,
|
||||
}
|
||||
|
||||
impl ShowOriginalRoads {
|
||||
pub fn new(ctx: &mut PluginCtx) -> Option<ShowOriginalRoads> {
|
||||
if let Some(id) = show_road(ctx) {
|
||||
let mut roads = HashSet::new();
|
||||
roads.insert(id);
|
||||
return Some(ShowOriginalRoads { roads });
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl NonblockingPlugin for ShowOriginalRoads {
|
||||
fn nonblocking_event(&mut self, ctx: &mut PluginCtx) -> bool {
|
||||
ctx.input.set_mode("Original Roads", &ctx.canvas);
|
||||
|
||||
if ctx.input.modal_action("quit") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if let Some(id) = show_road(ctx) {
|
||||
self.roads.insert(id);
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, ctx: &DrawCtx) {
|
||||
for id in &self.roads {
|
||||
let r = ctx.map.get_r(*id);
|
||||
if let Some(pair) = r.get_center_for_side(true) {
|
||||
let (pl, width) = pair.unwrap();
|
||||
g.draw_polygon(
|
||||
ctx.cs
|
||||
.get_def("original road forwards", Color::RED.alpha(0.5)),
|
||||
&pl.make_polygons(width),
|
||||
);
|
||||
}
|
||||
if let Some(pair) = r.get_center_for_side(false) {
|
||||
let (pl, width) = pair.unwrap();
|
||||
g.draw_polygon(
|
||||
ctx.cs
|
||||
.get_def("original road backwards", Color::BLUE.alpha(0.5)),
|
||||
&pl.make_polygons(width),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn show_road(ctx: &mut PluginCtx) -> Option<RoadID> {
|
||||
if let Some(ID::Lane(l)) = ctx.primary.current_selection {
|
||||
let id = ctx.primary.map.get_l(l).parent;
|
||||
if ctx
|
||||
.input
|
||||
.contextual_action(Key::V, &format!("show original geometry of {:?}", id))
|
||||
{
|
||||
return Some(id);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
@ -280,21 +280,6 @@ impl UIState {
|
||||
self.primary_plugins.hider = Some(p);
|
||||
}
|
||||
}
|
||||
if self.primary_plugins.orig_roads.is_some() {
|
||||
if !self
|
||||
.primary_plugins
|
||||
.orig_roads
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.nonblocking_event(&mut ctx)
|
||||
{
|
||||
self.primary_plugins.orig_roads = None;
|
||||
}
|
||||
} else if self.enable_debug_controls {
|
||||
if let Some(p) = debug::orig_roads::ShowOriginalRoads::new(&mut ctx) {
|
||||
self.primary_plugins.orig_roads = Some(p);
|
||||
}
|
||||
}
|
||||
|
||||
// Ambient plugins
|
||||
for p in self.primary_plugins.ambient_plugins.iter_mut() {
|
||||
@ -325,9 +310,6 @@ impl UIState {
|
||||
if let Some(ref p) = self.legend {
|
||||
p.draw(g, ctx);
|
||||
}
|
||||
if let Some(ref p) = self.primary_plugins.orig_roads {
|
||||
p.draw(g, ctx);
|
||||
}
|
||||
// Hider doesn't draw
|
||||
|
||||
// Layers doesn't draw
|
||||
@ -383,7 +365,6 @@ pub struct PluginsPerMap {
|
||||
// These are stackable modal plugins. They can all coexist, and they don't block other modal
|
||||
// plugins or ambient plugins.
|
||||
hider: Option<debug::hider::Hider>,
|
||||
orig_roads: Option<debug::orig_roads::ShowOriginalRoads>,
|
||||
|
||||
// When present, this either acts like exclusive blocking or like stackable modal. :\
|
||||
search: Option<view::search::SearchState>,
|
||||
@ -400,7 +381,6 @@ impl PluginsPerMap {
|
||||
) -> PluginsPerMap {
|
||||
let mut p = PluginsPerMap {
|
||||
hider: None,
|
||||
orig_roads: None,
|
||||
search: None,
|
||||
ambient_plugins: vec![
|
||||
Box::new(view::neighborhood_summary::NeighborhoodSummary::new(
|
||||
|
@ -95,7 +95,6 @@ impl GUI for UI {
|
||||
(Key::P, "add a new point"),
|
||||
],
|
||||
),
|
||||
ModalMenu::new("Original Roads", vec![(Key::Enter, "quit")]),
|
||||
ModalMenu::new("A/B Trip Explorer", vec![(Key::Enter, "quit")]),
|
||||
ModalMenu::new("A/B All Trips Explorer", vec![(Key::Enter, "quit")]),
|
||||
ModalMenu::new("Search", vec![(Key::Enter, "quit")]),
|
||||
@ -174,7 +173,11 @@ impl GUI for UI {
|
||||
),
|
||||
ModalMenu::new(
|
||||
"Debug Mode",
|
||||
vec![(Key::Escape, "quit"), (Key::C, "show/hide chokepoints")],
|
||||
vec![
|
||||
(Key::Escape, "quit"),
|
||||
(Key::C, "show/hide chokepoints"),
|
||||
(Key::O, "clear original roads shown"),
|
||||
],
|
||||
),
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user