mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-28 08:53:26 +03:00
moving toggleable layers into debug mode
This commit is contained in:
parent
e754bf3a14
commit
cedc7ede10
@ -5,7 +5,7 @@ mod polygons;
|
||||
|
||||
use crate::game::{GameState, Mode};
|
||||
use crate::objects::ID;
|
||||
use crate::ui::ShowObject;
|
||||
use crate::ui::{ShowLayers, ShowObject};
|
||||
use ezgui::{Color, EventCtx, EventLoopMode, GfxCtx, Key, Text, Wizard};
|
||||
use map_model::RoadID;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
@ -17,6 +17,7 @@ pub struct DebugMode {
|
||||
connected_roads: connected_roads::ShowConnectedRoads,
|
||||
objects: objects::ObjectDebugger,
|
||||
hidden: HashSet<ID>,
|
||||
layers: ShowLayers,
|
||||
}
|
||||
|
||||
enum State {
|
||||
@ -33,6 +34,7 @@ impl DebugMode {
|
||||
connected_roads: connected_roads::ShowConnectedRoads::new(),
|
||||
objects: objects::ObjectDebugger::new(),
|
||||
hidden: HashSet::new(),
|
||||
layers: ShowLayers::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,6 +130,21 @@ impl DebugMode {
|
||||
mode.state = State::Polygons(debugger);
|
||||
}
|
||||
|
||||
// TODO recalc current selection...
|
||||
if ctx.input.modal_action("show/hide buildings") {
|
||||
mode.layers.show_buildings = !mode.layers.show_buildings;
|
||||
} else if ctx.input.modal_action("show/hide intersections") {
|
||||
mode.layers.show_intersections = !mode.layers.show_intersections;
|
||||
} else if ctx.input.modal_action("show/hide lanes") {
|
||||
mode.layers.show_lanes = !mode.layers.show_lanes;
|
||||
} else if ctx.input.modal_action("show/hide areas") {
|
||||
mode.layers.show_areas = !mode.layers.show_areas;
|
||||
} else if ctx.input.modal_action("show/hide extra shapes") {
|
||||
mode.layers.show_extra_shapes = !mode.layers.show_extra_shapes;
|
||||
} else if ctx.input.modal_action("show/hide geometry debug mode") {
|
||||
mode.layers.geom_debug_mode = !mode.layers.geom_debug_mode;
|
||||
}
|
||||
|
||||
EventLoopMode::InputOnly
|
||||
}
|
||||
State::Polygons(ref mut debugger) => {
|
||||
@ -212,6 +229,21 @@ impl DebugMode {
|
||||
|
||||
impl ShowObject for DebugMode {
|
||||
fn show(&self, obj: ID) -> bool {
|
||||
!self.hidden.contains(&obj)
|
||||
if self.hidden.contains(&obj) {
|
||||
return false;
|
||||
}
|
||||
|
||||
match obj {
|
||||
ID::Road(_) | ID::Lane(_) => self.layers.show_lanes,
|
||||
ID::Building(_) => self.layers.show_buildings,
|
||||
ID::Intersection(_) => self.layers.show_intersections,
|
||||
ID::ExtraShape(_) => self.layers.show_extra_shapes,
|
||||
ID::Area(_) => self.layers.show_areas,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
fn layers(&self) -> &ShowLayers {
|
||||
&self.layers
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ impl EditMode {
|
||||
ctx,
|
||||
None,
|
||||
&state.ui.state.primary.sim,
|
||||
&ShowEverything {},
|
||||
&ShowEverything::new(),
|
||||
);
|
||||
|
||||
if let Some(ID::Lane(id)) = state.ui.state.primary.current_selection {
|
||||
@ -138,7 +138,7 @@ impl EditMode {
|
||||
ctx,
|
||||
Some(i),
|
||||
&state.ui.state.primary.sim,
|
||||
&ShowEverything {},
|
||||
&ShowEverything::new(),
|
||||
);
|
||||
|
||||
ctx.input.set_mode_with_prompt(
|
||||
@ -207,7 +207,7 @@ impl EditMode {
|
||||
None,
|
||||
override_color,
|
||||
&state.ui.state.primary.sim,
|
||||
&ShowEverything {},
|
||||
&ShowEverything::new(),
|
||||
);
|
||||
|
||||
// TODO Similar to drawing areas with traffic or not -- would be convenient to just
|
||||
@ -257,7 +257,7 @@ impl EditMode {
|
||||
None,
|
||||
override_color,
|
||||
&state.ui.state.primary.sim,
|
||||
&ShowEverything {},
|
||||
&ShowEverything::new(),
|
||||
);
|
||||
|
||||
// TODO Still draw the diffs, yo
|
||||
@ -293,7 +293,7 @@ impl EditMode {
|
||||
Some(i),
|
||||
override_color,
|
||||
&state.ui.state.primary.sim,
|
||||
&ShowEverything {},
|
||||
&ShowEverything::new(),
|
||||
);
|
||||
}
|
||||
Mode::Edit(EditMode::EditingTrafficSignal(ref editor)) => {
|
||||
|
@ -46,8 +46,12 @@ impl TrafficSignalEditor {
|
||||
|
||||
// Returns true if the editor is done and we should go back to main edit mode.
|
||||
pub fn event(&mut self, ctx: &mut EventCtx, ui: &mut UI) -> bool {
|
||||
ui.state.primary.current_selection =
|
||||
ui.handle_mouseover(ctx, Some(self.i), &ui.state.primary.sim, &ShowEverything {});
|
||||
ui.state.primary.current_selection = ui.handle_mouseover(
|
||||
ctx,
|
||||
Some(self.i),
|
||||
&ui.state.primary.sim,
|
||||
&ShowEverything::new(),
|
||||
);
|
||||
|
||||
ctx.input.set_mode_with_prompt(
|
||||
"Traffic Signal Editor",
|
||||
@ -261,7 +265,7 @@ impl TrafficSignalEditor {
|
||||
Some(self.i),
|
||||
override_color,
|
||||
&state.ui.state.primary.sim,
|
||||
&ShowEverything {},
|
||||
&ShowEverything::new(),
|
||||
);
|
||||
|
||||
let ctx = DrawCtx {
|
||||
|
@ -1,63 +0,0 @@
|
||||
use crate::objects::ID;
|
||||
use crate::plugins::{AmbientPlugin, PluginCtx};
|
||||
|
||||
pub struct ToggleableLayers {
|
||||
pub show_buildings: bool,
|
||||
pub show_intersections: bool,
|
||||
pub show_lanes: bool,
|
||||
pub show_areas: bool,
|
||||
pub show_extra_shapes: bool,
|
||||
pub show_all_turn_icons: bool,
|
||||
pub debug_mode: bool,
|
||||
}
|
||||
|
||||
impl ToggleableLayers {
|
||||
pub fn new() -> ToggleableLayers {
|
||||
ToggleableLayers {
|
||||
show_buildings: true,
|
||||
show_intersections: true,
|
||||
show_lanes: true,
|
||||
show_areas: true,
|
||||
show_extra_shapes: true,
|
||||
show_all_turn_icons: false,
|
||||
debug_mode: false,
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Probably don't need this later
|
||||
pub fn show(&self, id: ID) -> bool {
|
||||
match id {
|
||||
ID::Road(_) | ID::Lane(_) => self.show_lanes,
|
||||
ID::Building(_) => self.show_buildings,
|
||||
ID::Intersection(_) => self.show_intersections,
|
||||
ID::ExtraShape(_) => self.show_extra_shapes,
|
||||
ID::Area(_) => self.show_areas,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AmbientPlugin for ToggleableLayers {
|
||||
fn ambient_event(&mut self, ctx: &mut PluginCtx) {
|
||||
if ctx.input.action_chosen("show/hide buildings") {
|
||||
self.show_buildings = !self.show_buildings;
|
||||
} else if ctx.input.action_chosen("show/hide intersections") {
|
||||
self.show_intersections = !self.show_intersections;
|
||||
} else if ctx.input.action_chosen("show/hide lanes") {
|
||||
self.show_lanes = !self.show_lanes;
|
||||
} else if ctx.input.action_chosen("show/hide areas") {
|
||||
self.show_areas = !self.show_areas;
|
||||
} else if ctx.input.action_chosen("show/hide extra shapes") {
|
||||
self.show_extra_shapes = !self.show_extra_shapes;
|
||||
} else if ctx.input.action_chosen("show/hide all turn icons") {
|
||||
self.show_all_turn_icons = !self.show_all_turn_icons;
|
||||
} else if ctx.input.action_chosen("show/hide geometry debug mode") {
|
||||
self.debug_mode = !self.debug_mode;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
*ctx.recalculate_current_selection = true;
|
||||
ctx.primary.current_selection = None;
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
pub mod layers;
|
@ -1,4 +1,3 @@
|
||||
pub mod debug;
|
||||
pub mod edit;
|
||||
pub mod sim;
|
||||
pub mod view;
|
||||
|
@ -54,7 +54,7 @@ impl SandboxMode {
|
||||
ctx,
|
||||
None,
|
||||
&state.ui.state.primary.sim,
|
||||
&ShowEverything {},
|
||||
&ShowEverything::new(),
|
||||
);
|
||||
|
||||
if let State::Spawning(ref mut spawner) = mode.state {
|
||||
@ -306,7 +306,7 @@ impl SandboxMode {
|
||||
None,
|
||||
HashMap::new(),
|
||||
&mode.time_travel,
|
||||
&ShowEverything {},
|
||||
&ShowEverything::new(),
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
@ -315,7 +315,7 @@ impl SandboxMode {
|
||||
None,
|
||||
HashMap::new(),
|
||||
&state.ui.state.primary.sim,
|
||||
&ShowEverything {},
|
||||
&ShowEverything::new(),
|
||||
);
|
||||
mode.route_viewer.draw(g, &state.ui);
|
||||
mode.show_activity.draw(g, &state.ui);
|
||||
|
@ -240,7 +240,7 @@ impl AgentSpawner {
|
||||
None,
|
||||
override_color,
|
||||
&ui.state.primary.sim,
|
||||
&ShowEverything {},
|
||||
&ShowEverything::new(),
|
||||
);
|
||||
|
||||
if let Some((_, Some(ref trace))) = self.maybe_goal {
|
||||
|
@ -1,9 +1,7 @@
|
||||
use crate::colors::ColorScheme;
|
||||
use crate::objects::{DrawCtx, RenderingHints, ID};
|
||||
use crate::plugins;
|
||||
use crate::plugins::{
|
||||
debug, edit, view, AmbientPlugin, BlockingPlugin, NonblockingPlugin, PluginCtx,
|
||||
};
|
||||
use crate::plugins::{edit, view, AmbientPlugin, BlockingPlugin, NonblockingPlugin, PluginCtx};
|
||||
use crate::render::DrawMap;
|
||||
use abstutil::{MeasureMemory, Timer};
|
||||
use ezgui::EventCtx;
|
||||
@ -60,9 +58,6 @@ pub struct UIState {
|
||||
// plugins or ambient plugins.
|
||||
pub legend: Option<plugins::view::legend::Legend>,
|
||||
|
||||
// Ambient plugins always exist, and they never block anything.
|
||||
pub layers: debug::layers::ToggleableLayers,
|
||||
|
||||
pub enable_debug_controls: bool,
|
||||
|
||||
pub cs: ColorScheme,
|
||||
@ -80,7 +75,6 @@ impl UIState {
|
||||
exclusive_blocking_plugin: None,
|
||||
exclusive_nonblocking_plugin: None,
|
||||
legend: None,
|
||||
layers: debug::layers::ToggleableLayers::new(),
|
||||
enable_debug_controls,
|
||||
cs,
|
||||
}
|
||||
@ -98,7 +92,7 @@ impl UIState {
|
||||
|
||||
// The exclusive_nonblocking_plugins don't color_obj.
|
||||
|
||||
// legend and layers don't color_obj.
|
||||
// legend doesn't color_obj.
|
||||
for p in &self.primary_plugins.ambient_plugins {
|
||||
if let Some(c) = p.color_for(id, ctx) {
|
||||
return Some(c);
|
||||
@ -241,9 +235,6 @@ impl UIState {
|
||||
for p in self.primary_plugins.ambient_plugins.iter_mut() {
|
||||
p.ambient_event(&mut ctx);
|
||||
}
|
||||
if self.enable_debug_controls {
|
||||
self.layers.ambient_event(&mut ctx);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw(&self, g: &mut GfxCtx, ctx: &DrawCtx) {
|
||||
@ -267,7 +258,6 @@ impl UIState {
|
||||
p.draw(g, ctx);
|
||||
}
|
||||
|
||||
// Layers doesn't draw
|
||||
for p in &self.primary_plugins.ambient_plugins {
|
||||
p.draw(g, ctx);
|
||||
}
|
||||
|
@ -36,13 +36,6 @@ impl GUI for UI {
|
||||
vec![
|
||||
(None, "screenshot everything"),
|
||||
(Some(Key::F1), "screenshot just this"),
|
||||
(Some(Key::Num1), "show/hide buildings"),
|
||||
(Some(Key::Num2), "show/hide intersections"),
|
||||
(Some(Key::Num3), "show/hide lanes"),
|
||||
(Some(Key::Num5), "show/hide areas"),
|
||||
(Some(Key::Num7), "show/hide extra shapes"),
|
||||
(Some(Key::Num9), "show/hide all turn icons"),
|
||||
(None, "show/hide geometry debug mode"),
|
||||
],
|
||||
));
|
||||
}
|
||||
@ -167,6 +160,12 @@ impl GUI for UI {
|
||||
(Key::C, "show/hide chokepoints"),
|
||||
(Key::O, "clear original roads shown"),
|
||||
(Key::K, "unhide everything"),
|
||||
(Key::Num1, "show/hide buildings"),
|
||||
(Key::Num2, "show/hide intersections"),
|
||||
(Key::Num3, "show/hide lanes"),
|
||||
(Key::Num4, "show/hide areas"),
|
||||
(Key::Num5, "show/hide extra shapes"),
|
||||
(Key::Num6, "show/hide geometry debug mode"),
|
||||
],
|
||||
),
|
||||
ModalMenu::new(
|
||||
@ -193,7 +192,7 @@ impl GUI for UI {
|
||||
None,
|
||||
HashMap::new(),
|
||||
&self.state.primary.sim,
|
||||
&ShowEverything {},
|
||||
&ShowEverything::new(),
|
||||
)
|
||||
}
|
||||
|
||||
@ -276,14 +275,18 @@ impl UI {
|
||||
|
||||
// Always handle mouseover
|
||||
self.state.primary.current_selection =
|
||||
self.handle_mouseover(ctx, None, &self.state.primary.sim, &ShowEverything {});
|
||||
self.handle_mouseover(ctx, None, &self.state.primary.sim, &ShowEverything::new());
|
||||
|
||||
let mut recalculate_current_selection = false;
|
||||
self.state
|
||||
.event(ctx, &mut self.hints, &mut recalculate_current_selection);
|
||||
if recalculate_current_selection {
|
||||
self.state.primary.current_selection =
|
||||
self.mouseover_something(&ctx, None, &self.state.primary.sim, &ShowEverything {});
|
||||
self.state.primary.current_selection = self.mouseover_something(
|
||||
&ctx,
|
||||
None,
|
||||
&self.state.primary.sim,
|
||||
&ShowEverything::new(),
|
||||
);
|
||||
}
|
||||
|
||||
ctx.input.populate_osd(&mut self.hints.osd);
|
||||
@ -336,16 +339,17 @@ impl UI {
|
||||
|
||||
if g.canvas.cam_zoom < MIN_ZOOM_FOR_DETAIL && !g.is_screencap() {
|
||||
// Unzoomed mode
|
||||
if self.state.layers.show_areas {
|
||||
let layers = show_objs.layers();
|
||||
if layers.show_areas {
|
||||
g.redraw(&self.state.primary.draw_map.draw_all_areas);
|
||||
}
|
||||
if self.state.layers.show_lanes {
|
||||
if layers.show_lanes {
|
||||
g.redraw(&self.state.primary.draw_map.draw_all_thick_roads);
|
||||
}
|
||||
if self.state.layers.show_intersections {
|
||||
if layers.show_intersections {
|
||||
g.redraw(&self.state.primary.draw_map.draw_all_unzoomed_intersections);
|
||||
}
|
||||
if self.state.layers.show_buildings {
|
||||
if layers.show_buildings {
|
||||
g.redraw(&self.state.primary.draw_map.draw_all_buildings);
|
||||
}
|
||||
|
||||
@ -398,7 +402,7 @@ impl UI {
|
||||
.get(&obj.get_id())
|
||||
.cloned()
|
||||
.or_else(|| self.state.color_obj(obj.get_id(), &ctx)),
|
||||
debug_mode: self.state.layers.debug_mode,
|
||||
debug_mode: show_objs.layers().geom_debug_mode,
|
||||
};
|
||||
obj.draw(g, opts, &ctx);
|
||||
|
||||
@ -643,14 +647,51 @@ fn fill_to_boundary_polygon(poly: Polygon) -> Polygon {
|
||||
poly
|
||||
}
|
||||
|
||||
pub trait ShowObject {
|
||||
fn show(&self, obj: ID) -> bool;
|
||||
pub struct ShowLayers {
|
||||
pub show_buildings: bool,
|
||||
pub show_intersections: bool,
|
||||
pub show_lanes: bool,
|
||||
pub show_areas: bool,
|
||||
pub show_extra_shapes: bool,
|
||||
pub geom_debug_mode: bool,
|
||||
}
|
||||
|
||||
pub struct ShowEverything {}
|
||||
impl ShowLayers {
|
||||
pub fn new() -> ShowLayers {
|
||||
ShowLayers {
|
||||
show_buildings: true,
|
||||
show_intersections: true,
|
||||
show_lanes: true,
|
||||
show_areas: true,
|
||||
show_extra_shapes: true,
|
||||
geom_debug_mode: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ShowObject {
|
||||
fn show(&self, obj: ID) -> bool;
|
||||
fn layers(&self) -> &ShowLayers;
|
||||
}
|
||||
|
||||
pub struct ShowEverything {
|
||||
layers: ShowLayers,
|
||||
}
|
||||
|
||||
impl ShowEverything {
|
||||
pub fn new() -> ShowEverything {
|
||||
ShowEverything {
|
||||
layers: ShowLayers::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ShowObject for ShowEverything {
|
||||
fn show(&self, _: ID) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn layers(&self) -> &ShowLayers {
|
||||
&self.layers
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user