From e754bf3a14952202042aa0259ef2b955da857ef3 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Thu, 25 Apr 2019 22:07:48 -0700 Subject: [PATCH] hider into debug mode --- editor/src/debug/mod.rs | 30 +++++++++++++- editor/src/plugins/debug/hider.rs | 65 ------------------------------- editor/src/plugins/debug/mod.rs | 1 - editor/src/state.rs | 24 +----------- editor/src/ui.rs | 2 +- 5 files changed, 31 insertions(+), 91 deletions(-) delete mode 100644 editor/src/plugins/debug/hider.rs diff --git a/editor/src/debug/mod.rs b/editor/src/debug/mod.rs index 86c7adeb46..5466c39731 100644 --- a/editor/src/debug/mod.rs +++ b/editor/src/debug/mod.rs @@ -16,6 +16,7 @@ pub struct DebugMode { show_original_roads: HashSet, connected_roads: connected_roads::ShowConnectedRoads, objects: objects::ObjectDebugger, + hidden: HashSet, } 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) } } diff --git a/editor/src/plugins/debug/hider.rs b/editor/src/plugins/debug/hider.rs deleted file mode 100644 index 06322ec503..0000000000 --- a/editor/src/plugins/debug/hider.rs +++ /dev/null @@ -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, -} - -impl Hider { - pub fn new(ctx: &mut PluginCtx) -> Option { - 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 { - 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 - } - } - } -} diff --git a/editor/src/plugins/debug/mod.rs b/editor/src/plugins/debug/mod.rs index 9944205fc1..759c25e770 100644 --- a/editor/src/plugins/debug/mod.rs +++ b/editor/src/plugins/debug/mod.rs @@ -1,2 +1 @@ -pub mod hider; pub mod layers; diff --git a/editor/src/state.rs b/editor/src/state.rs index 1d39a8f26f..9e7fb2eb17 100644 --- a/editor/src/state.rs +++ b/editor/src/state.rs @@ -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, - // When present, this either acts like exclusive blocking or like stackable modal. :\ search: Option, @@ -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( diff --git a/editor/src/ui.rs b/editor/src/ui.rs index e49c501d27..e486cb31d1 100644 --- a/editor/src/ui.rs +++ b/editor/src/ui.rs @@ -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(