mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-28 08:53:26 +03:00
hider into debug mode
This commit is contained in:
parent
f8d81a92c6
commit
e754bf3a14
@ -16,6 +16,7 @@ pub struct DebugMode {
|
||||
show_original_roads: HashSet<RoadID>,
|
||||
connected_roads: connected_roads::ShowConnectedRoads,
|
||||
objects: objects::ObjectDebugger,
|
||||
hidden: HashSet<ID>,
|
||||
}
|
||||
|
||||
enum State {
|
||||
@ -31,6 +32,7 @@ impl DebugMode {
|
||||
show_original_roads: HashSet::new(),
|
||||
connected_roads: connected_roads::ShowConnectedRoads::new(),
|
||||
objects: objects::ObjectDebugger::new(),
|
||||
hidden: HashSet::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,6 +63,9 @@ impl DebugMode {
|
||||
mode.show_original_roads.len()
|
||||
));
|
||||
}
|
||||
if !mode.hidden.is_empty() {
|
||||
txt.add_line(format!("Hiding {} things", mode.hidden.len()));
|
||||
}
|
||||
ctx.input
|
||||
.set_mode_with_new_prompt("Debug Mode", txt, ctx.canvas);
|
||||
if ctx.input.modal_action("quit") {
|
||||
@ -83,6 +88,29 @@ impl DebugMode {
|
||||
mode.show_original_roads.clear();
|
||||
}
|
||||
}
|
||||
if !mode.hidden.is_empty() {
|
||||
if ctx.input.modal_action("unhide everything") {
|
||||
mode.hidden.clear();
|
||||
// TODO recalculate current_selection
|
||||
}
|
||||
}
|
||||
match state.ui.state.primary.current_selection {
|
||||
Some(ID::Lane(_))
|
||||
| Some(ID::Intersection(_))
|
||||
| Some(ID::ExtraShape(_)) => {
|
||||
let id = state.ui.state.primary.current_selection.unwrap();
|
||||
if ctx
|
||||
.input
|
||||
.contextual_action(Key::H, &format!("hide {:?}", id))
|
||||
{
|
||||
println!("Hiding {:?}", id);
|
||||
//*ctx.recalculate_current_selection = true;
|
||||
state.ui.state.primary.current_selection = None;
|
||||
mode.hidden.insert(id);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if let Some(ID::Lane(l)) = state.ui.state.primary.current_selection {
|
||||
let id = state.ui.state.primary.map.get_l(l).parent;
|
||||
@ -184,6 +212,6 @@ impl DebugMode {
|
||||
|
||||
impl ShowObject for DebugMode {
|
||||
fn show(&self, obj: ID) -> bool {
|
||||
false
|
||||
!self.hidden.contains(&obj)
|
||||
}
|
||||
}
|
||||
|
@ -1,65 +0,0 @@
|
||||
use crate::objects::ID;
|
||||
use crate::plugins::{NonblockingPlugin, PluginCtx};
|
||||
use ezgui::Key;
|
||||
use std::collections::HashSet;
|
||||
|
||||
pub struct Hider {
|
||||
items: HashSet<ID>,
|
||||
}
|
||||
|
||||
impl Hider {
|
||||
pub fn new(ctx: &mut PluginCtx) -> Option<Hider> {
|
||||
if let Some(id) = hide_something(ctx) {
|
||||
let mut items = HashSet::new();
|
||||
items.insert(id);
|
||||
return Some(Hider { items });
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn show(&self, id: ID) -> bool {
|
||||
!self.items.contains(&id)
|
||||
}
|
||||
}
|
||||
|
||||
impl NonblockingPlugin for Hider {
|
||||
fn nonblocking_event(&mut self, ctx: &mut PluginCtx) -> bool {
|
||||
// TODO Add non-prompt lines listing how much stuff is hidden. And if the numbers
|
||||
// align, "and a partridge in a pear tree..."
|
||||
ctx.input.set_mode("Object Hider", &ctx.canvas);
|
||||
|
||||
if ctx.input.modal_action("unhide everything") {
|
||||
println!("Unhiding {} things", self.items.len());
|
||||
*ctx.recalculate_current_selection = true;
|
||||
ctx.primary.current_selection = None;
|
||||
return false;
|
||||
}
|
||||
|
||||
if let Some(id) = hide_something(ctx) {
|
||||
self.items.insert(id);
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
fn hide_something(ctx: &mut PluginCtx) -> Option<ID> {
|
||||
match ctx.primary.current_selection {
|
||||
// No real use case for hiding moving stuff
|
||||
Some(ID::Car(_)) | Some(ID::Pedestrian(_)) | None => None,
|
||||
// Can't hide stuff drawn in a batch
|
||||
Some(ID::Building(_)) | Some(ID::Road(_)) | Some(ID::Area(_)) => None,
|
||||
Some(id) => {
|
||||
if ctx
|
||||
.input
|
||||
.contextual_action(Key::H, &format!("hide {:?}", id))
|
||||
{
|
||||
println!("Hiding {:?}", id);
|
||||
*ctx.recalculate_current_selection = true;
|
||||
ctx.primary.current_selection = None;
|
||||
Some(id)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,2 +1 @@
|
||||
pub mod hider;
|
||||
pub mod layers;
|
||||
|
@ -98,7 +98,7 @@ impl UIState {
|
||||
|
||||
// The exclusive_nonblocking_plugins don't color_obj.
|
||||
|
||||
// legend, hider, and layers don't color_obj.
|
||||
// legend and layers don't color_obj.
|
||||
for p in &self.primary_plugins.ambient_plugins {
|
||||
if let Some(c) = p.color_for(id, ctx) {
|
||||
return Some(c);
|
||||
@ -237,22 +237,6 @@ impl UIState {
|
||||
}
|
||||
}
|
||||
|
||||
if self.primary_plugins.hider.is_some() {
|
||||
if !self
|
||||
.primary_plugins
|
||||
.hider
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.nonblocking_event(&mut ctx)
|
||||
{
|
||||
self.primary_plugins.hider = None;
|
||||
}
|
||||
} else if self.enable_debug_controls {
|
||||
if let Some(p) = debug::hider::Hider::new(&mut ctx) {
|
||||
self.primary_plugins.hider = Some(p);
|
||||
}
|
||||
}
|
||||
|
||||
// Ambient plugins
|
||||
for p in self.primary_plugins.ambient_plugins.iter_mut() {
|
||||
p.ambient_event(&mut ctx);
|
||||
@ -282,7 +266,6 @@ impl UIState {
|
||||
if let Some(ref p) = self.legend {
|
||||
p.draw(g, ctx);
|
||||
}
|
||||
// Hider doesn't draw
|
||||
|
||||
// Layers doesn't draw
|
||||
for p in &self.primary_plugins.ambient_plugins {
|
||||
@ -329,10 +312,6 @@ impl PerMapUI {
|
||||
|
||||
// Anything that holds onto any kind of ID has to live here!
|
||||
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>,
|
||||
|
||||
// When present, this either acts like exclusive blocking or like stackable modal. :\
|
||||
search: Option<view::search::SearchState>,
|
||||
|
||||
@ -342,7 +321,6 @@ pub struct PluginsPerMap {
|
||||
impl PluginsPerMap {
|
||||
pub fn new(state: &PerMapUI, prerender: &Prerender, timer: &mut Timer) -> PluginsPerMap {
|
||||
PluginsPerMap {
|
||||
hider: None,
|
||||
search: None,
|
||||
ambient_plugins: vec![
|
||||
Box::new(view::neighborhood_summary::NeighborhoodSummary::new(
|
||||
|
@ -99,7 +99,6 @@ impl GUI for UI {
|
||||
ModalMenu::new("A/B All Trips Explorer", vec![(Key::Enter, "quit")]),
|
||||
ModalMenu::new("Search", vec![(Key::Enter, "quit")]),
|
||||
ModalMenu::new("Neighborhood Summaries", vec![(Key::Enter, "quit")]),
|
||||
ModalMenu::new("Object Hider", vec![(Key::K, "unhide everything")]),
|
||||
// TODO F1?
|
||||
ModalMenu::new("Legend", vec![(Key::L, "quit")]),
|
||||
// The new exciting things!
|
||||
@ -167,6 +166,7 @@ impl GUI for UI {
|
||||
(Key::Escape, "quit"),
|
||||
(Key::C, "show/hide chokepoints"),
|
||||
(Key::O, "clear original roads shown"),
|
||||
(Key::K, "unhide everything"),
|
||||
],
|
||||
),
|
||||
ModalMenu::new(
|
||||
|
Loading…
Reference in New Issue
Block a user