mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 17:37:22 +03:00
convert object hider into a modal menu
This commit is contained in:
parent
567ded85de
commit
d989e2fb09
@ -1,5 +1,6 @@
|
||||
use crate::objects::ID;
|
||||
use ezgui::{Key, UserInput};
|
||||
use crate::plugins::PluginCtx;
|
||||
use ezgui::Key;
|
||||
use std::collections::HashSet;
|
||||
|
||||
pub struct Hider {
|
||||
@ -17,21 +18,31 @@ impl Hider {
|
||||
!self.items.contains(&id)
|
||||
}
|
||||
|
||||
pub fn event(&mut self, input: &mut UserInput, selected: Option<ID>) -> bool {
|
||||
if input.action_chosen("unhide everything") {
|
||||
info!("Unhiding {} things", self.items.len());
|
||||
self.items.clear();
|
||||
return true;
|
||||
// Weird, true here means selection state changed.
|
||||
pub fn event(&mut self, ctx: &mut PluginCtx) -> bool {
|
||||
if !self.items.is_empty() {
|
||||
// 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") {
|
||||
info!("Unhiding {} things", self.items.len());
|
||||
self.items.clear();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
let item = match selected {
|
||||
let item = match ctx.primary.current_selection {
|
||||
// No real use case for hiding moving stuff
|
||||
Some(ID::Car(_)) | Some(ID::Pedestrian(_)) | None => {
|
||||
return false;
|
||||
}
|
||||
Some(id) => id,
|
||||
};
|
||||
if input.contextual_action(Key::H, &format!("hide {:?}", item)) {
|
||||
if ctx
|
||||
.input
|
||||
.contextual_action(Key::H, &format!("hide {:?}", item))
|
||||
{
|
||||
self.items.insert(item);
|
||||
info!("Hiding {:?}", item);
|
||||
return true;
|
||||
|
@ -41,9 +41,7 @@ impl Plugin for DebugMode {
|
||||
fn blocking_event(&mut self, ctx: &mut PluginCtx) -> bool {
|
||||
// Always run ambient plugins. If either returns true, the selection state could have
|
||||
// changed.
|
||||
if self.hider.event(ctx.input, ctx.primary.current_selection)
|
||||
|| self.layers.event(ctx.input)
|
||||
{
|
||||
if self.hider.event(ctx) || self.layers.event(ctx.input) {
|
||||
*ctx.recalculate_current_selection = true;
|
||||
ctx.primary.current_selection = None;
|
||||
}
|
||||
|
@ -36,7 +36,6 @@ impl<S: UIState> GUI<RenderingHints> for UI<S> {
|
||||
vec![
|
||||
(Key::C, "find chokepoints"),
|
||||
(Key::I, "validate map geometry"),
|
||||
(Key::K, "unhide everything"),
|
||||
(Key::Num1, "show/hide buildings"),
|
||||
(Key::Num2, "show/hide intersections"),
|
||||
(Key::Num3, "show/hide lanes"),
|
||||
@ -162,6 +161,7 @@ impl<S: UIState> GUI<RenderingHints> for UI<S> {
|
||||
vec![(Key::R, "quit"), (Key::L, "show route for all agents")],
|
||||
),
|
||||
ModalMenu::new("Active Traffic Visualizer", vec![(Key::A, "quit")]),
|
||||
ModalMenu::new("Object Hider", vec![(Key::K, "unhide everything")]),
|
||||
]
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user