mirror of
https://github.com/a-b-street/abstreet.git
synced 2025-01-03 12:03:30 +03:00
remove the last traces of override_colors!
This commit is contained in:
parent
0b528c1eff
commit
041b28ad2a
@ -1,41 +0,0 @@
|
||||
use crate::helpers::ID;
|
||||
use crate::ui::UI;
|
||||
use ezgui::{EventCtx, Key};
|
||||
use map_model::LaneID;
|
||||
use std::collections::HashSet;
|
||||
|
||||
pub struct ShowConnectedRoads {
|
||||
key_held: bool,
|
||||
pub lanes: HashSet<LaneID>,
|
||||
}
|
||||
|
||||
impl ShowConnectedRoads {
|
||||
pub fn new() -> ShowConnectedRoads {
|
||||
ShowConnectedRoads {
|
||||
key_held: false,
|
||||
lanes: HashSet::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn event(&mut self, ctx: &mut EventCtx, ui: &UI) {
|
||||
if self.key_held {
|
||||
self.key_held = !ctx.input.key_released(Key::RightAlt);
|
||||
} else {
|
||||
// TODO Can't really display an OSD action if we're not currently selecting something.
|
||||
// Could only activate sometimes, but that seems a bit harder to use.
|
||||
self.key_held = ctx.input.unimportant_key_pressed(
|
||||
Key::RightAlt,
|
||||
"hold right Alt to show roads connected to intersection",
|
||||
);
|
||||
}
|
||||
|
||||
self.lanes.clear();
|
||||
if self.key_held {
|
||||
if let Some(ID::Intersection(i)) = ui.primary.current_selection {
|
||||
for r in &ui.primary.map.get_i(i).roads {
|
||||
self.lanes.extend(ui.primary.map.get_r(*r).all_lanes());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
mod connected_roads;
|
||||
mod floodfill;
|
||||
mod objects;
|
||||
mod polygons;
|
||||
@ -8,7 +7,6 @@ use crate::common::{tool_panel, CommonState};
|
||||
use crate::game::{msg, State, Transition, WizardState};
|
||||
use crate::helpers::ID;
|
||||
use crate::managed::{WrappedComposite, WrappedOutcome};
|
||||
use crate::render::MIN_ZOOM_FOR_DETAIL;
|
||||
use crate::ui::{ShowLayers, ShowObject, UI};
|
||||
use ezgui::{
|
||||
hotkey, Color, Drawable, EventCtx, EventLoopMode, GeomBatch, GfxCtx, Key, Line, ModalMenu,
|
||||
@ -22,7 +20,6 @@ pub struct DebugMode {
|
||||
menu: ModalMenu,
|
||||
common: CommonState,
|
||||
tool_panel: WrappedComposite,
|
||||
connected_roads: connected_roads::ShowConnectedRoads,
|
||||
objects: objects::ObjectDebugger,
|
||||
hidden: HashSet<ID>,
|
||||
layers: ShowLayers,
|
||||
@ -54,7 +51,6 @@ impl DebugMode {
|
||||
),
|
||||
common: CommonState::new(),
|
||||
tool_panel: tool_panel(ctx),
|
||||
connected_roads: connected_roads::ShowConnectedRoads::new(),
|
||||
objects: objects::ObjectDebugger::new(),
|
||||
hidden: HashSet::new(),
|
||||
layers: ShowLayers::new(),
|
||||
@ -79,8 +75,7 @@ impl State for DebugMode {
|
||||
if let Some(ref results) = self.search_results {
|
||||
txt.add(Line(format!(
|
||||
"Search for {} has {} results",
|
||||
results.query,
|
||||
results.ids.len()
|
||||
results.query, results.num_matches
|
||||
)));
|
||||
}
|
||||
if let routes::AllRoutesViewer::Active(_, ref traces) = self.all_routes {
|
||||
@ -191,7 +186,6 @@ impl State for DebugMode {
|
||||
));
|
||||
}
|
||||
}
|
||||
self.connected_roads.event(ctx, ui);
|
||||
self.objects.event(ctx, ui);
|
||||
|
||||
if let Some(debugger) = polygons::PolygonDebugger::new(ctx, ui) {
|
||||
@ -278,26 +272,10 @@ impl State for DebugMode {
|
||||
let mut opts = self.common.draw_options(ui);
|
||||
opts.label_buildings = self.layers.show_labels;
|
||||
opts.label_roads = self.layers.show_labels;
|
||||
for l in &self.connected_roads.lanes {
|
||||
opts.override_colors.insert(
|
||||
ID::Lane(*l),
|
||||
ui.cs.get("something associated with something else"),
|
||||
);
|
||||
}
|
||||
if g.canvas.cam_zoom >= MIN_ZOOM_FOR_DETAIL {
|
||||
if let Some(ref results) = self.search_results {
|
||||
for id in &results.ids {
|
||||
opts.override_colors
|
||||
.insert(id.clone(), ui.cs.get("search result"));
|
||||
}
|
||||
}
|
||||
}
|
||||
ui.draw(g, opts, &ui.primary.sim, self);
|
||||
|
||||
if g.canvas.cam_zoom < MIN_ZOOM_FOR_DETAIL {
|
||||
if let Some(ref results) = self.search_results {
|
||||
g.redraw(&results.unzoomed);
|
||||
}
|
||||
if let Some(ref results) = self.search_results {
|
||||
g.redraw(&results.draw);
|
||||
}
|
||||
|
||||
self.objects.draw(g, ui);
|
||||
@ -334,9 +312,10 @@ impl ShowObject for DebugMode {
|
||||
|
||||
fn search_osm(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Transition> {
|
||||
let filter = wiz.wrap(ctx).input_string("Search for what?")?;
|
||||
let mut ids = HashSet::new();
|
||||
let mut num_matches = 0;
|
||||
let mut batch = GeomBatch::new();
|
||||
|
||||
// TODO Case insensitive
|
||||
let map = &ui.primary.map;
|
||||
let color = ui.cs.get_def("search result", Color::RED);
|
||||
for r in map.all_roads() {
|
||||
@ -344,9 +323,7 @@ fn search_osm(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Trans
|
||||
.iter()
|
||||
.any(|(k, v)| format!("{} = {}", k, v).contains(&filter))
|
||||
{
|
||||
for l in r.all_lanes() {
|
||||
ids.insert(ID::Lane(l));
|
||||
}
|
||||
num_matches += 1;
|
||||
batch.push(color, r.get_thick_polygon().unwrap());
|
||||
}
|
||||
}
|
||||
@ -355,7 +332,7 @@ fn search_osm(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Trans
|
||||
.iter()
|
||||
.any(|(k, v)| format!("{} = {}", k, v).contains(&filter))
|
||||
{
|
||||
ids.insert(ID::Building(b.id));
|
||||
num_matches += 1;
|
||||
batch.push(color, b.polygon.clone());
|
||||
}
|
||||
}
|
||||
@ -364,15 +341,15 @@ fn search_osm(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Trans
|
||||
.iter()
|
||||
.any(|(k, v)| format!("{} = {}", k, v).contains(&filter))
|
||||
{
|
||||
ids.insert(ID::Area(a.id));
|
||||
num_matches += 1;
|
||||
batch.push(color, a.polygon.clone());
|
||||
}
|
||||
}
|
||||
|
||||
let results = SearchResults {
|
||||
query: filter,
|
||||
ids,
|
||||
unzoomed: batch.upload(ctx),
|
||||
num_matches,
|
||||
draw: batch.upload(ctx),
|
||||
};
|
||||
|
||||
Some(Transition::PopWithData(Box::new(|state, _, _| {
|
||||
@ -382,8 +359,8 @@ fn search_osm(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Trans
|
||||
|
||||
struct SearchResults {
|
||||
query: String,
|
||||
ids: HashSet<ID>,
|
||||
unzoomed: Drawable,
|
||||
num_matches: usize,
|
||||
draw: Drawable,
|
||||
}
|
||||
|
||||
fn load_savestate(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Transition> {
|
||||
|
@ -25,11 +25,7 @@ impl Renderable for DrawArea {
|
||||
ID::Area(self.id)
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, opts: &DrawOptions, ctx: &DrawCtx) {
|
||||
if let Some(color) = opts.color(self.get_id()) {
|
||||
g.draw_polygon(color, &ctx.map.get_a(self.id).polygon);
|
||||
}
|
||||
}
|
||||
fn draw(&self, _: &mut GfxCtx, _: &DrawOptions, _: &DrawCtx) {}
|
||||
|
||||
fn get_outline(&self, map: &Map) -> Polygon {
|
||||
// Since areas are so big, don't just draw the outline
|
||||
|
@ -97,12 +97,8 @@ impl Renderable for DrawBike {
|
||||
ID::Car(self.id)
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, opts: &DrawOptions, _: &DrawCtx) {
|
||||
if let Some(color) = opts.color(self.get_id()) {
|
||||
g.draw_circle(color, &self.body_circle);
|
||||
} else {
|
||||
g.redraw(&self.draw_default);
|
||||
}
|
||||
fn draw(&self, g: &mut GfxCtx, _: &DrawOptions, _: &DrawCtx) {
|
||||
g.redraw(&self.draw_default);
|
||||
}
|
||||
|
||||
fn get_outline(&self, _: &Map) -> Polygon {
|
||||
|
@ -72,10 +72,7 @@ impl Renderable for DrawBuilding {
|
||||
ID::Building(self.id)
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, opts: &DrawOptions, ctx: &DrawCtx) {
|
||||
if let Some(color) = opts.color(self.get_id()) {
|
||||
g.draw_polygon(color, &ctx.map.get_b(self.id).polygon);
|
||||
}
|
||||
fn draw(&self, g: &mut GfxCtx, opts: &DrawOptions, _: &DrawCtx) {
|
||||
if opts.label_buildings {
|
||||
if let Some(ref txt) = self.label {
|
||||
g.draw_text_at_mapspace(txt, self.label_pos);
|
||||
|
@ -64,12 +64,8 @@ impl Renderable for DrawBusStop {
|
||||
ID::BusStop(self.id)
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, opts: &DrawOptions, _ctx: &DrawCtx) {
|
||||
if let Some(color) = opts.color(self.get_id()) {
|
||||
g.draw_polygon(color, &self.polygon);
|
||||
} else {
|
||||
g.redraw(&self.draw_default);
|
||||
}
|
||||
fn draw(&self, g: &mut GfxCtx, _: &DrawOptions, _: &DrawCtx) {
|
||||
g.redraw(&self.draw_default);
|
||||
}
|
||||
|
||||
fn get_outline(&self, _: &Map) -> Polygon {
|
||||
|
@ -127,12 +127,8 @@ impl Renderable for DrawCar {
|
||||
ID::Car(self.id)
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, opts: &DrawOptions, _: &DrawCtx) {
|
||||
if let Some(color) = opts.color(self.get_id()) {
|
||||
g.draw_polygon(color, &self.body_polygon);
|
||||
} else {
|
||||
g.redraw(&self.draw_default);
|
||||
}
|
||||
fn draw(&self, g: &mut GfxCtx, _: &DrawOptions, _: &DrawCtx) {
|
||||
g.redraw(&self.draw_default);
|
||||
|
||||
if let Some(ref txt) = self.label {
|
||||
// TODO Would rotation make any sense? Or at least adjust position/size while turning.
|
||||
|
@ -83,12 +83,8 @@ impl Renderable for DrawExtraShape {
|
||||
ID::ExtraShape(self.id)
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, opts: &DrawOptions, _: &DrawCtx) {
|
||||
if let Some(color) = opts.color(self.get_id()) {
|
||||
g.draw_polygon(color, &self.polygon);
|
||||
} else {
|
||||
g.redraw(&self.draw_default);
|
||||
}
|
||||
fn draw(&self, g: &mut GfxCtx, _: &DrawOptions, _: &DrawCtx) {
|
||||
g.redraw(&self.draw_default);
|
||||
}
|
||||
|
||||
fn get_outline(&self, _: &Map) -> Polygon {
|
||||
|
@ -121,43 +121,38 @@ impl Renderable for DrawIntersection {
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, opts: &DrawOptions, ctx: &DrawCtx) {
|
||||
if let Some(color) = opts.color(self.get_id()) {
|
||||
// Don't draw the sidewalk corners
|
||||
g.draw_polygon(color, &ctx.map.get_i(self.id).polygon);
|
||||
} else {
|
||||
g.redraw(&self.draw_default);
|
||||
g.redraw(&self.draw_default);
|
||||
|
||||
if self.intersection_type == IntersectionType::TrafficSignal
|
||||
&& opts.suppress_traffic_signal_details != Some(self.id)
|
||||
{
|
||||
let signal = ctx.map.get_traffic_signal(self.id);
|
||||
let mut maybe_redraw = self.draw_traffic_signal.borrow_mut();
|
||||
let recalc = maybe_redraw
|
||||
.as_ref()
|
||||
.map(|(t, _, _, _)| *t != ctx.sim.time())
|
||||
.unwrap_or(true);
|
||||
if recalc {
|
||||
let (idx, phase, t) = signal.current_phase_and_remaining_time(ctx.sim.time());
|
||||
let mut batch = GeomBatch::new();
|
||||
draw_signal_phase(
|
||||
phase,
|
||||
self.id,
|
||||
Some(t),
|
||||
&mut batch,
|
||||
ctx,
|
||||
ctx.opts.traffic_signal_style.clone(),
|
||||
);
|
||||
*maybe_redraw = Some((
|
||||
ctx.sim.time(),
|
||||
g.prerender.upload(batch),
|
||||
Text::from(Line(format!("{}", idx + 1)).roboto()),
|
||||
ctx.map.get_i(self.id).polygon.center(),
|
||||
));
|
||||
}
|
||||
let (_, batch, txt, pt) = maybe_redraw.as_ref().unwrap();
|
||||
g.redraw(batch);
|
||||
g.draw_text_at_mapspace(txt, *pt);
|
||||
if self.intersection_type == IntersectionType::TrafficSignal
|
||||
&& opts.suppress_traffic_signal_details != Some(self.id)
|
||||
{
|
||||
let signal = ctx.map.get_traffic_signal(self.id);
|
||||
let mut maybe_redraw = self.draw_traffic_signal.borrow_mut();
|
||||
let recalc = maybe_redraw
|
||||
.as_ref()
|
||||
.map(|(t, _, _, _)| *t != ctx.sim.time())
|
||||
.unwrap_or(true);
|
||||
if recalc {
|
||||
let (idx, phase, t) = signal.current_phase_and_remaining_time(ctx.sim.time());
|
||||
let mut batch = GeomBatch::new();
|
||||
draw_signal_phase(
|
||||
phase,
|
||||
self.id,
|
||||
Some(t),
|
||||
&mut batch,
|
||||
ctx,
|
||||
ctx.opts.traffic_signal_style.clone(),
|
||||
);
|
||||
*maybe_redraw = Some((
|
||||
ctx.sim.time(),
|
||||
g.prerender.upload(batch),
|
||||
Text::from(Line(format!("{}", idx + 1)).roboto()),
|
||||
ctx.map.get_i(self.id).polygon.center(),
|
||||
));
|
||||
}
|
||||
let (_, batch, txt, pt) = maybe_redraw.as_ref().unwrap();
|
||||
g.redraw(batch);
|
||||
g.draw_text_at_mapspace(txt, *pt);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,12 +161,8 @@ impl Renderable for DrawLane {
|
||||
ID::Lane(self.id)
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, opts: &DrawOptions, _: &DrawCtx) {
|
||||
if let Some(color) = opts.color(self.get_id()) {
|
||||
g.draw_polygon(color, &self.polygon);
|
||||
} else {
|
||||
g.redraw(&self.draw_default);
|
||||
}
|
||||
fn draw(&self, g: &mut GfxCtx, _: &DrawOptions, _: &DrawCtx) {
|
||||
g.redraw(&self.draw_default);
|
||||
}
|
||||
|
||||
fn get_outline(&self, map: &Map) -> Polygon {
|
||||
|
@ -24,11 +24,10 @@ use crate::render::pedestrian::{DrawPedCrowd, DrawPedestrian};
|
||||
pub use crate::render::road::DrawRoad;
|
||||
pub use crate::render::traffic_signal::draw_signal_phase;
|
||||
pub use crate::render::turn::{DrawTurn, DrawTurnGroup};
|
||||
use ezgui::{Color, GfxCtx, Prerender};
|
||||
use ezgui::{GfxCtx, Prerender};
|
||||
use geom::{Distance, PolyLine, Polygon, Pt2D, EPSILON_DIST};
|
||||
use map_model::{IntersectionID, Map};
|
||||
use sim::{DrawCarInput, Sim, VehicleType};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub const MIN_ZOOM_FOR_DETAIL: f64 = 2.5;
|
||||
|
||||
@ -99,7 +98,6 @@ pub struct DrawCtx<'a> {
|
||||
// DrawOptions.
|
||||
#[derive(Clone)]
|
||||
pub struct DrawOptions {
|
||||
pub override_colors: HashMap<ID, Color>,
|
||||
pub suppress_traffic_signal_details: Option<IntersectionID>,
|
||||
pub label_buildings: bool,
|
||||
pub label_roads: bool,
|
||||
@ -108,14 +106,9 @@ pub struct DrawOptions {
|
||||
impl DrawOptions {
|
||||
pub fn new() -> DrawOptions {
|
||||
DrawOptions {
|
||||
override_colors: HashMap::new(),
|
||||
suppress_traffic_signal_details: None,
|
||||
label_buildings: false,
|
||||
label_roads: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn color(&self, id: ID) -> Option<Color> {
|
||||
self.override_colors.get(&id).cloned()
|
||||
}
|
||||
}
|
||||
|
@ -156,12 +156,8 @@ impl Renderable for DrawPedestrian {
|
||||
ID::Pedestrian(self.id)
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, opts: &DrawOptions, _: &DrawCtx) {
|
||||
if let Some(color) = opts.color(self.get_id()) {
|
||||
g.draw_circle(color, &self.body_circle);
|
||||
} else {
|
||||
g.redraw(&self.draw_default);
|
||||
}
|
||||
fn draw(&self, g: &mut GfxCtx, _: &DrawOptions, _: &DrawCtx) {
|
||||
g.redraw(&self.draw_default);
|
||||
}
|
||||
|
||||
fn get_outline(&self, _: &Map) -> Polygon {
|
||||
@ -240,12 +236,8 @@ impl Renderable for DrawPedCrowd {
|
||||
ID::PedCrowd(self.members.clone())
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, opts: &DrawOptions, _: &DrawCtx) {
|
||||
if let Some(color) = opts.color(self.get_id()) {
|
||||
g.draw_polygon(color, &self.blob);
|
||||
} else {
|
||||
g.redraw(&self.draw_default);
|
||||
}
|
||||
fn draw(&self, g: &mut GfxCtx, _: &DrawOptions, _: &DrawCtx) {
|
||||
g.redraw(&self.draw_default);
|
||||
g.draw_text_at_mapspace(&self.label, self.blob.center());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user