mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-25 11:44:25 +03:00
plumbing a ShowObjects trait to UI stuff, will use for hider and layers
This commit is contained in:
parent
1e267c9d5d
commit
f8d81a92c6
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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<ID> 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);
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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(
|
||||
|
@ -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,
|
||||
|
@ -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<IntersectionID>,
|
||||
override_color: HashMap<ID, Color>,
|
||||
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<IntersectionID>,
|
||||
source: &GetDrawAgents,
|
||||
show_objs: &ShowObject,
|
||||
) -> Option<ID> {
|
||||
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<IntersectionID>,
|
||||
source: &GetDrawAgents,
|
||||
show_objs: &ShowObject,
|
||||
) -> Option<ID> {
|
||||
// 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<IntersectionID>,
|
||||
source: &GetDrawAgents,
|
||||
show_objs: &ShowObject,
|
||||
) -> Vec<Box<&'a Renderable>> {
|
||||
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<Traversable> = 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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user