mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-29 04:35:51 +03:00
show colored bldgs unzoomed too for scenario viz
This commit is contained in:
parent
8a05e59865
commit
5e78a58f64
116
editor/src/common/colors.rs
Normal file
116
editor/src/common/colors.rs
Normal file
@ -0,0 +1,116 @@
|
||||
use crate::helpers::ID;
|
||||
use crate::render::{DrawOptions, MIN_ZOOM_FOR_DETAIL};
|
||||
use crate::ui::{ShowEverything, UI};
|
||||
use ezgui::{Color, Drawable, EventCtx, GeomBatch, GfxCtx};
|
||||
use map_model::{BuildingID, LaneID, Map, RoadID};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct RoadColorerBuilder {
|
||||
prioritized_colors: Vec<Color>,
|
||||
zoomed_override_colors: HashMap<ID, Color>,
|
||||
roads: HashMap<RoadID, Color>,
|
||||
}
|
||||
|
||||
pub struct RoadColorer {
|
||||
zoomed_override_colors: HashMap<ID, Color>,
|
||||
unzoomed: Drawable,
|
||||
}
|
||||
|
||||
impl RoadColorer {
|
||||
pub fn draw(&self, g: &mut GfxCtx, ui: &UI) {
|
||||
let mut opts = DrawOptions::new();
|
||||
if g.canvas.cam_zoom < MIN_ZOOM_FOR_DETAIL {
|
||||
ui.draw(g, opts, &ui.primary.sim, &ShowEverything::new());
|
||||
g.redraw(&self.unzoomed);
|
||||
} else {
|
||||
opts.override_colors = self.zoomed_override_colors.clone();
|
||||
ui.draw(g, opts, &ui.primary.sim, &ShowEverything::new());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RoadColorerBuilder {
|
||||
// Colors listed earlier override those listed later. This is used in unzoomed mode, when one
|
||||
// road has lanes of different colors.
|
||||
pub fn new(prioritized_colors: Vec<Color>) -> RoadColorerBuilder {
|
||||
RoadColorerBuilder {
|
||||
prioritized_colors,
|
||||
zoomed_override_colors: HashMap::new(),
|
||||
roads: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add(&mut self, l: LaneID, color: Color, map: &Map) {
|
||||
self.zoomed_override_colors.insert(ID::Lane(l), color);
|
||||
let r = map.get_parent(l).id;
|
||||
if let Some(existing) = self.roads.get(&r) {
|
||||
if self.prioritized_colors.iter().position(|c| *c == color)
|
||||
< self.prioritized_colors.iter().position(|c| c == existing)
|
||||
{
|
||||
self.roads.insert(r, color);
|
||||
}
|
||||
} else {
|
||||
self.roads.insert(r, color);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn build(self, ctx: &mut EventCtx, map: &Map) -> RoadColorer {
|
||||
let mut batch = GeomBatch::new();
|
||||
for (r, color) in self.roads {
|
||||
batch.push(color, map.get_r(r).get_thick_polygon().unwrap());
|
||||
}
|
||||
RoadColorer {
|
||||
zoomed_override_colors: self.zoomed_override_colors,
|
||||
unzoomed: ctx.prerender.upload(batch),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BuildingColorerBuilder {
|
||||
zoomed_override_colors: HashMap<ID, Color>,
|
||||
}
|
||||
|
||||
pub struct BuildingColorer {
|
||||
zoomed_override_colors: HashMap<ID, Color>,
|
||||
unzoomed: Drawable,
|
||||
}
|
||||
|
||||
impl BuildingColorer {
|
||||
pub fn draw(&self, g: &mut GfxCtx, ui: &UI) {
|
||||
let mut opts = DrawOptions::new();
|
||||
if g.canvas.cam_zoom < MIN_ZOOM_FOR_DETAIL {
|
||||
ui.draw(g, opts, &ui.primary.sim, &ShowEverything::new());
|
||||
g.redraw(&self.unzoomed);
|
||||
} else {
|
||||
opts.override_colors = self.zoomed_override_colors.clone();
|
||||
ui.draw(g, opts, &ui.primary.sim, &ShowEverything::new());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BuildingColorerBuilder {
|
||||
pub fn new() -> BuildingColorerBuilder {
|
||||
BuildingColorerBuilder {
|
||||
zoomed_override_colors: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add(&mut self, b: BuildingID, color: Color) {
|
||||
self.zoomed_override_colors.insert(ID::Building(b), color);
|
||||
}
|
||||
|
||||
pub fn build(self, ctx: &mut EventCtx, map: &Map) -> BuildingColorer {
|
||||
let mut batch = GeomBatch::new();
|
||||
for (id, color) in &self.zoomed_override_colors {
|
||||
if let ID::Building(b) = id {
|
||||
batch.push(*color, map.get_b(*b).polygon.clone());
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
BuildingColorer {
|
||||
zoomed_override_colors: self.zoomed_override_colors,
|
||||
unzoomed: ctx.prerender.upload(batch),
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
mod agent;
|
||||
mod associated;
|
||||
mod colors;
|
||||
mod navigate;
|
||||
mod route_explorer;
|
||||
mod route_viewer;
|
||||
@ -11,6 +12,7 @@ mod turn_cycler;
|
||||
mod warp;
|
||||
|
||||
pub use self::agent::AgentTools;
|
||||
pub use self::colors::{BuildingColorer, BuildingColorerBuilder, RoadColorer, RoadColorerBuilder};
|
||||
pub use self::route_explorer::RouteExplorer;
|
||||
pub use self::speed::SpeedControls;
|
||||
pub use self::time::time_controls;
|
||||
|
@ -1,11 +1,11 @@
|
||||
use crate::common::{RoadColorer, RoadColorerBuilder};
|
||||
use crate::game::{State, Transition};
|
||||
use crate::helpers::ID;
|
||||
use crate::render::{DrawOptions, MIN_ZOOM_FOR_DETAIL};
|
||||
use crate::ui::{ShowEverything, UI};
|
||||
use ezgui::{hotkey, Color, Drawable, EventCtx, GeomBatch, GfxCtx, Key, ModalMenu, Text};
|
||||
use map_model::{LaneID, Map, RoadID};
|
||||
use crate::ui::UI;
|
||||
use ezgui::{hotkey, Color, EventCtx, GfxCtx, Key, ModalMenu, Text};
|
||||
use map_model::{LaneID, Map};
|
||||
use petgraph::graphmap::DiGraphMap;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::collections::HashSet;
|
||||
|
||||
pub struct Floodfiller {
|
||||
menu: ModalMenu,
|
||||
@ -129,65 +129,3 @@ fn find_reachable_from(start: LaneID, map: &Map) -> HashSet<LaneID> {
|
||||
}
|
||||
visited
|
||||
}
|
||||
|
||||
// TODO Useful elsewhere?
|
||||
struct RoadColorerBuilder {
|
||||
prioritized_colors: Vec<Color>,
|
||||
zoomed_override_colors: HashMap<ID, Color>,
|
||||
roads: HashMap<RoadID, Color>,
|
||||
}
|
||||
|
||||
struct RoadColorer {
|
||||
zoomed_override_colors: HashMap<ID, Color>,
|
||||
unzoomed: Drawable,
|
||||
}
|
||||
|
||||
impl RoadColorer {
|
||||
fn draw(&self, g: &mut GfxCtx, ui: &UI) {
|
||||
let mut opts = DrawOptions::new();
|
||||
if g.canvas.cam_zoom < MIN_ZOOM_FOR_DETAIL {
|
||||
ui.draw(g, opts, &ui.primary.sim, &ShowEverything::new());
|
||||
g.redraw(&self.unzoomed);
|
||||
} else {
|
||||
opts.override_colors = self.zoomed_override_colors.clone();
|
||||
ui.draw(g, opts, &ui.primary.sim, &ShowEverything::new());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RoadColorerBuilder {
|
||||
// Colors listed earlier override those listed later. This is used in unzoomed mode, when one
|
||||
// road has lanes of different colors.
|
||||
fn new(prioritized_colors: Vec<Color>) -> RoadColorerBuilder {
|
||||
RoadColorerBuilder {
|
||||
prioritized_colors,
|
||||
zoomed_override_colors: HashMap::new(),
|
||||
roads: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn add(&mut self, l: LaneID, color: Color, map: &Map) {
|
||||
self.zoomed_override_colors.insert(ID::Lane(l), color);
|
||||
let r = map.get_parent(l).id;
|
||||
if let Some(existing) = self.roads.get(&r) {
|
||||
if self.prioritized_colors.iter().position(|c| *c == color)
|
||||
< self.prioritized_colors.iter().position(|c| c == existing)
|
||||
{
|
||||
self.roads.insert(r, color);
|
||||
}
|
||||
} else {
|
||||
self.roads.insert(r, color);
|
||||
}
|
||||
}
|
||||
|
||||
fn build(self, ctx: &mut EventCtx, map: &Map) -> RoadColorer {
|
||||
let mut batch = GeomBatch::new();
|
||||
for (r, color) in self.roads {
|
||||
batch.push(color, map.get_r(r).get_thick_polygon().unwrap());
|
||||
}
|
||||
RoadColorer {
|
||||
zoomed_override_colors: self.zoomed_override_colors,
|
||||
unzoomed: ctx.prerender.upload(batch),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
use crate::common::{CommonState, Warping};
|
||||
use crate::common::{BuildingColorer, BuildingColorerBuilder, CommonState, Warping};
|
||||
use crate::game::{State, Transition, WizardState};
|
||||
use crate::helpers::ID;
|
||||
use crate::mission::pick_time_range;
|
||||
use crate::sandbox::SandboxMode;
|
||||
use crate::ui::{ShowEverything, UI};
|
||||
use crate::ui::UI;
|
||||
use abstutil::{prettyprint_usize, MultiMap, WeightedUsizeChoice};
|
||||
use ezgui::{
|
||||
hotkey, Color, EventCtx, EventLoopMode, GfxCtx, Key, ModalMenu, Text, Wizard, WrappedWizard,
|
||||
@ -28,7 +28,7 @@ pub struct ScenarioManager {
|
||||
cars_needed_per_bldg: HashMap<BuildingID, CarCount>,
|
||||
total_cars_needed: CarCount,
|
||||
total_parking_spots: usize,
|
||||
override_colors: HashMap<ID, Color>,
|
||||
bldg_colors: BuildingColorer,
|
||||
}
|
||||
|
||||
impl ScenarioManager {
|
||||
@ -40,14 +40,14 @@ impl ScenarioManager {
|
||||
cars_needed_per_bldg.insert(b.id, CarCount::new());
|
||||
}
|
||||
let mut total_cars_needed = CarCount::new();
|
||||
let mut override_colors = HashMap::new();
|
||||
let mut bldg_colors = BuildingColorerBuilder::new();
|
||||
for (idx, trip) in scenario.individ_trips.iter().enumerate() {
|
||||
// trips_from_bldg
|
||||
match trip {
|
||||
SpawnTrip::CarAppearing { ref start_bldg, .. } => {
|
||||
if let Some(b) = start_bldg {
|
||||
trips_from_bldg.insert(*b, idx);
|
||||
override_colors.insert(ID::Building(*b), Color::BLUE);
|
||||
bldg_colors.add(*b, Color::BLUE);
|
||||
}
|
||||
}
|
||||
SpawnTrip::UsingBike(_, ref spot, _)
|
||||
@ -55,7 +55,7 @@ impl ScenarioManager {
|
||||
| SpawnTrip::UsingTransit(_, ref spot, _, _, _, _) => {
|
||||
if let SidewalkPOI::Building(b) = spot.connection {
|
||||
trips_from_bldg.insert(b, idx);
|
||||
override_colors.insert(ID::Building(b), Color::BLUE);
|
||||
bldg_colors.add(b, Color::BLUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -65,14 +65,14 @@ impl ScenarioManager {
|
||||
SpawnTrip::CarAppearing { ref goal, .. } | SpawnTrip::UsingBike(_, _, ref goal) => {
|
||||
if let DrivingGoal::ParkNear(b) = goal {
|
||||
trips_to_bldg.insert(*b, idx);
|
||||
override_colors.insert(ID::Building(*b), Color::BLUE);
|
||||
bldg_colors.add(*b, Color::BLUE);
|
||||
}
|
||||
}
|
||||
SpawnTrip::JustWalking(_, _, ref spot)
|
||||
| SpawnTrip::UsingTransit(_, _, ref spot, _, _, _) => {
|
||||
if let SidewalkPOI::Building(b) = spot.connection {
|
||||
trips_to_bldg.insert(b, idx);
|
||||
override_colors.insert(ID::Building(b), Color::BLUE);
|
||||
bldg_colors.add(b, Color::BLUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -136,7 +136,7 @@ impl ScenarioManager {
|
||||
cars_needed_per_bldg,
|
||||
total_cars_needed,
|
||||
total_parking_spots: free_parking_spots.len(),
|
||||
override_colors,
|
||||
bldg_colors: bldg_colors.build(ctx, &ui.primary.map),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -210,10 +210,8 @@ impl State for ScenarioManager {
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, ui: &UI) {
|
||||
let mut opts = self.common.draw_options(ui);
|
||||
// TODO expensive!
|
||||
opts.override_colors.extend(self.override_colors.clone());
|
||||
ui.draw(g, opts, &ui.primary.sim, &ShowEverything::new());
|
||||
// TODO Let common contribute draw_options...
|
||||
self.bldg_colors.draw(g, ui);
|
||||
|
||||
self.menu.draw(g);
|
||||
// TODO Weird to not draw common (turn cycler), but we want the custom OSD...
|
||||
|
Loading…
Reference in New Issue
Block a user