From f8d81a92c66fadec343536549233eb33e26d955a Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Thu, 25 Apr 2019 16:56:38 -0700 Subject: [PATCH] plumbing a ShowObjects trait to UI stuff, will use for hider and layers --- editor/src/debug/mod.rs | 13 ++++++-- editor/src/edit/mod.rs | 51 ++++++++++++++++++++---------- editor/src/edit/traffic_signals.rs | 14 +++++--- editor/src/sandbox/mod.rs | 31 ++++++++++++------ editor/src/sandbox/spawner.rs | 10 ++++-- editor/src/state.rs | 22 +------------ editor/src/ui.rs | 40 +++++++++++++++++------ 7 files changed, 114 insertions(+), 67 deletions(-) diff --git a/editor/src/debug/mod.rs b/editor/src/debug/mod.rs index c88e6fbfab..86c7adeb46 100644 --- a/editor/src/debug/mod.rs +++ b/editor/src/debug/mod.rs @@ -5,6 +5,7 @@ mod polygons; use crate::game::{GameState, Mode}; use crate::objects::ID; +use crate::ui::ShowObject; use ezgui::{Color, EventCtx, EventLoopMode, GfxCtx, Key, Text, Wizard}; use map_model::RoadID; use std::collections::{HashMap, HashSet}; @@ -42,7 +43,7 @@ impl DebugMode { state.ui.state.primary.current_selection = state .ui - .handle_mouseover(ctx, None, &state.ui.state.primary.sim); + .handle_mouseover(ctx, None, &state.ui.state.primary.sim, mode); let mut txt = Text::new(); txt.add_styled_line( @@ -139,7 +140,7 @@ impl DebugMode { } state .ui - .new_draw(g, None, color_overrides, &state.ui.state.primary.sim); + .new_draw(g, None, color_overrides, &state.ui.state.primary.sim, mode); for id in &mode.show_original_roads { let r = state.ui.state.primary.map.get_r(*id); @@ -172,7 +173,7 @@ impl DebugMode { State::Polygons(ref debugger) => { state .ui - .new_draw(g, None, HashMap::new(), &state.ui.state.primary.sim); + .new_draw(g, None, HashMap::new(), &state.ui.state.primary.sim, mode); debugger.draw(g, &state.ui); } }, @@ -180,3 +181,9 @@ impl DebugMode { } } } + +impl ShowObject for DebugMode { + fn show(&self, obj: ID) -> bool { + false + } +} diff --git a/editor/src/edit/mod.rs b/editor/src/edit/mod.rs index 09778ec172..fc628191fb 100644 --- a/editor/src/edit/mod.rs +++ b/editor/src/edit/mod.rs @@ -5,6 +5,7 @@ use crate::objects::{DrawCtx, ID}; use crate::plugins::load_edits; use crate::render::{DrawLane, DrawMap, DrawTurn, RenderOptions, Renderable, MIN_ZOOM_FOR_DETAIL}; use crate::state::UIState; +use crate::ui::ShowEverything; use abstutil::Timer; use ezgui::{Color, EventCtx, EventLoopMode, GfxCtx, Key, Text, Wizard, WrappedWizard}; use map_model::{ @@ -60,10 +61,12 @@ impl EditMode { // the effects of it. Or eventually, the Option itself will live in here // directly. // TODO Only mouseover lanes and intersections? - state.ui.state.primary.current_selection = - state - .ui - .handle_mouseover(ctx, None, &state.ui.state.primary.sim); + state.ui.state.primary.current_selection = state.ui.handle_mouseover( + ctx, + None, + &state.ui.state.primary.sim, + &ShowEverything {}, + ); if let Some(ID::Lane(id)) = state.ui.state.primary.current_selection { let lane = state.ui.state.primary.map.get_l(id); @@ -131,10 +134,12 @@ impl EditMode { } } Mode::Edit(EditMode::EditingStopSign(i)) => { - state.ui.state.primary.current_selection = - state - .ui - .handle_mouseover(ctx, Some(i), &state.ui.state.primary.sim); + state.ui.state.primary.current_selection = state.ui.handle_mouseover( + ctx, + Some(i), + &state.ui.state.primary.sim, + &ShowEverything {}, + ); ctx.input.set_mode_with_prompt( "Stop Sign Editor", @@ -197,9 +202,13 @@ impl EditMode { match state.mode { Mode::Edit(EditMode::ViewingDiffs) => { - state - .ui - .new_draw(g, None, override_color, &state.ui.state.primary.sim); + state.ui.new_draw( + g, + None, + override_color, + &state.ui.state.primary.sim, + &ShowEverything {}, + ); // TODO Similar to drawing areas with traffic or not -- would be convenient to just // supply a set of things to highlight and have something else take care of drawing @@ -243,9 +252,13 @@ impl EditMode { } Mode::Edit(EditMode::Saving(ref wizard)) | Mode::Edit(EditMode::Loading(ref wizard)) => { - state - .ui - .new_draw(g, None, override_color, &state.ui.state.primary.sim); + state.ui.new_draw( + g, + None, + override_color, + &state.ui.state.primary.sim, + &ShowEverything {}, + ); // TODO Still draw the diffs, yo wizard.draw(g); @@ -275,9 +288,13 @@ impl EditMode { }, ); } - state - .ui - .new_draw(g, Some(i), override_color, &state.ui.state.primary.sim); + state.ui.new_draw( + g, + Some(i), + override_color, + &state.ui.state.primary.sim, + &ShowEverything {}, + ); } Mode::Edit(EditMode::EditingTrafficSignal(ref editor)) => { editor.draw(g, state); diff --git a/editor/src/edit/traffic_signals.rs b/editor/src/edit/traffic_signals.rs index 50fde0185e..ebfff2ba25 100644 --- a/editor/src/edit/traffic_signals.rs +++ b/editor/src/edit/traffic_signals.rs @@ -2,7 +2,7 @@ use crate::edit::apply_map_edits; use crate::game::GameState; use crate::objects::{DrawCtx, ID}; use crate::render::{draw_signal_cycle, draw_signal_diagram, DrawTurn}; -use crate::ui::UI; +use crate::ui::{ShowEverything, UI}; use abstutil::Timer; use ezgui::{Color, EventCtx, GfxCtx, Key, ScreenPt, Wizard, WrappedWizard}; use geom::Duration; @@ -47,7 +47,7 @@ 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); + ui.handle_mouseover(ctx, Some(self.i), &ui.state.primary.sim, &ShowEverything {}); ctx.input.set_mode_with_prompt( "Traffic Signal Editor", @@ -256,9 +256,13 @@ impl TrafficSignalEditor { }, ); } - state - .ui - .new_draw(g, Some(self.i), override_color, &state.ui.state.primary.sim); + state.ui.new_draw( + g, + Some(self.i), + override_color, + &state.ui.state.primary.sim, + &ShowEverything {}, + ); let ctx = DrawCtx { cs: &state.ui.state.cs, diff --git a/editor/src/sandbox/mod.rs b/editor/src/sandbox/mod.rs index e94641d575..1bb422929c 100644 --- a/editor/src/sandbox/mod.rs +++ b/editor/src/sandbox/mod.rs @@ -4,6 +4,7 @@ mod spawner; mod time_travel; use crate::game::{GameState, Mode}; +use crate::ui::ShowEverything; use abstutil::elapsed_seconds; use ezgui::{Color, EventCtx, EventLoopMode, GfxCtx, Key, Text, Wizard}; use geom::Duration; @@ -49,10 +50,12 @@ impl SandboxMode { match state.mode { Mode::Sandbox(ref mut mode) => { ctx.canvas.handle_event(ctx.input); - state.ui.state.primary.current_selection = - state - .ui - .handle_mouseover(ctx, None, &state.ui.state.primary.sim); + state.ui.state.primary.current_selection = state.ui.handle_mouseover( + ctx, + None, + &state.ui.state.primary.sim, + &ShowEverything {}, + ); if let State::Spawning(ref mut spawner) = mode.state { if spawner.event(ctx, &mut state.ui) { @@ -298,14 +301,22 @@ impl SandboxMode { spawner.draw(g, &state.ui); } State::TimeTraveling => { - state - .ui - .new_draw(g, None, HashMap::new(), &mode.time_travel); + state.ui.new_draw( + g, + None, + HashMap::new(), + &mode.time_travel, + &ShowEverything {}, + ); } _ => { - state - .ui - .new_draw(g, None, HashMap::new(), &state.ui.state.primary.sim); + state.ui.new_draw( + g, + None, + HashMap::new(), + &state.ui.state.primary.sim, + &ShowEverything {}, + ); mode.route_viewer.draw(g, &state.ui); mode.show_activity.draw(g, &state.ui); } diff --git a/editor/src/sandbox/spawner.rs b/editor/src/sandbox/spawner.rs index d12d964afd..d10be65f59 100644 --- a/editor/src/sandbox/spawner.rs +++ b/editor/src/sandbox/spawner.rs @@ -1,5 +1,5 @@ use crate::objects::ID; -use crate::ui::UI; +use crate::ui::{ShowEverything, UI}; use abstutil::Timer; use ezgui::{EventCtx, GfxCtx, Key}; use geom::PolyLine; @@ -235,7 +235,13 @@ impl AgentSpawner { }; let mut override_color = HashMap::new(); override_color.insert(src, ui.state.cs.get("selected")); - ui.new_draw(g, None, override_color, &ui.state.primary.sim); + ui.new_draw( + g, + None, + override_color, + &ui.state.primary.sim, + &ShowEverything {}, + ); if let Some((_, Some(ref trace))) = self.maybe_goal { g.draw_polygon( diff --git a/editor/src/state.rs b/editor/src/state.rs index ea495120ac..1d39a8f26f 100644 --- a/editor/src/state.rs +++ b/editor/src/state.rs @@ -9,7 +9,7 @@ use abstutil::{MeasureMemory, Timer}; use ezgui::EventCtx; use ezgui::{Color, GfxCtx, Prerender}; use geom::Duration; -use map_model::{IntersectionID, Map}; +use map_model::Map; use sim::{Sim, SimFlags}; use structopt::StructOpt; @@ -108,26 +108,6 @@ impl UIState { None } - pub fn show_icons_for(&self, id: IntersectionID) -> bool { - self.layers.show_all_turn_icons || { - // TODO This sounds like some old hack, probably remove this? - if let Some(ID::Turn(t)) = self.primary.current_selection { - t.parent == id - } else { - false - } - } - } - - pub fn show(&self, obj: ID) -> bool { - if let Some(ref p) = self.primary_plugins.hider { - if !p.show(obj) { - return false; - } - } - self.layers.show(obj) - } - pub fn event( &mut self, event_ctx: &mut EventCtx, diff --git a/editor/src/ui.rs b/editor/src/ui.rs index 45b5286f25..e49c501d27 100644 --- a/editor/src/ui.rs +++ b/editor/src/ui.rs @@ -188,7 +188,13 @@ impl GUI for UI { } fn draw(&self, g: &mut GfxCtx) { - self.new_draw(g, None, HashMap::new(), &self.state.primary.sim) + self.new_draw( + g, + None, + HashMap::new(), + &self.state.primary.sim, + &ShowEverything {}, + ) } fn dump_before_abort(&self, canvas: &Canvas) { @@ -270,14 +276,14 @@ impl UI { // Always handle mouseover self.state.primary.current_selection = - self.handle_mouseover(ctx, None, &self.state.primary.sim); + self.handle_mouseover(ctx, None, &self.state.primary.sim, &ShowEverything {}); 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); + self.mouseover_something(&ctx, None, &self.state.primary.sim, &ShowEverything {}); } ctx.input.populate_osd(&mut self.hints.osd); @@ -314,6 +320,7 @@ impl UI { show_turn_icons_for: Option, override_color: HashMap, source: &GetDrawAgents, + show_objs: &ShowObject, ) { let ctx = DrawCtx { cs: &self.state.cs, @@ -364,6 +371,7 @@ impl UI { &mut cache, show_turn_icons_for, source, + show_objs, ); let mut drawn_all_buildings = false; @@ -437,9 +445,10 @@ impl UI { ctx: &mut EventCtx, show_turn_icons_for: Option, source: &GetDrawAgents, + show_objs: &ShowObject, ) -> Option { if !ctx.canvas.is_dragging() && ctx.input.get_moved_mouse().is_some() { - return self.mouseover_something(&ctx, show_turn_icons_for, source); + return self.mouseover_something(&ctx, show_turn_icons_for, source, show_objs); } if ctx.input.window_lost_cursor() { return None; @@ -452,6 +461,7 @@ impl UI { ctx: &EventCtx, show_turn_icons_for: Option, source: &GetDrawAgents, + show_objs: &ShowObject, ) -> Option { // Unzoomed mode. Ignore when debugging areas. if ctx.canvas.cam_zoom < MIN_ZOOM_FOR_DETAIL @@ -469,6 +479,7 @@ impl UI { &mut cache, show_turn_icons_for, source, + show_objs, ); objects.reverse(); @@ -512,6 +523,7 @@ impl UI { agents: &'a mut AgentCache, show_turn_icons_for: Option, source: &GetDrawAgents, + show_objs: &ShowObject, ) -> Vec> { let map = &self.state.primary.map; let draw_map = &self.state.primary.draw_map; @@ -527,7 +539,7 @@ impl UI { let mut agents_on: Vec = Vec::new(); for id in draw_map.get_matching_objects(bounds) { - if !self.state.show(id) { + if !show_objs.show(id) { continue; } match id { @@ -535,9 +547,7 @@ impl UI { ID::Lane(id) => { lanes.push(Box::new(draw_map.get_l(id))); let lane = map.get_l(id); - if self.state.show_icons_for(lane.dst_i) - || show_turn_icons_for == Some(lane.dst_i) - { + if show_turn_icons_for == Some(lane.dst_i) { for (t, _) in map.get_next_turns_and_lanes(id, lane.dst_i) { turn_icons.push(Box::new(draw_map.get_t(t.id))); } @@ -555,7 +565,7 @@ impl UI { ID::Intersection(id) => { intersections.push(Box::new(draw_map.get_i(id))); for t in &map.get_i(id).turns { - if !self.state.show_icons_for(id) && show_turn_icons_for != Some(id) { + if show_turn_icons_for != Some(id) { agents_on.push(Traversable::Turn(*t)); } } @@ -632,3 +642,15 @@ fn fill_to_boundary_polygon(poly: Polygon) -> Polygon { //PolyLine::make_polygons_for_boundary(poly.points().clone(), Distance::meters(0.5)) poly } + +pub trait ShowObject { + fn show(&self, obj: ID) -> bool; +} + +pub struct ShowEverything {} + +impl ShowObject for ShowEverything { + fn show(&self, _: ID) -> bool { + true + } +}