diff --git a/game/src/common/colors.rs b/game/src/common/colors.rs index 82db5de836..8100c5ab32 100644 --- a/game/src/common/colors.rs +++ b/game/src/common/colors.rs @@ -141,12 +141,8 @@ pub struct ColorLegend { } impl ColorLegend { - pub fn new(ctx: &mut EventCtx, header: Text, rows: Vec<(&str, Color)>) -> ColorLegend { - let mut col = vec![ManagedWidget::row(vec![ - ManagedWidget::draw_text(ctx, header), - crate::managed::Composite::text_button(ctx, "X", None).align_right(), - ])]; - + pub fn rows(ctx: &mut EventCtx, rows: Vec<(&str, Color)>) -> Vec { + let mut col = Vec::new(); let radius = 15.0; for (label, color) in rows { col.push(ManagedWidget::row(vec![ @@ -161,6 +157,15 @@ impl ColorLegend { ManagedWidget::draw_text(ctx, Text::from(Line(label))), ])); } + col + } + + pub fn new(ctx: &mut EventCtx, header: Text, rows: Vec<(&str, Color)>) -> ColorLegend { + let mut col = vec![ManagedWidget::row(vec![ + ManagedWidget::draw_text(ctx, header), + crate::managed::Composite::text_button(ctx, "X", None).align_right(), + ])]; + col.extend(ColorLegend::rows(ctx, rows)); ColorLegend { composite: Composite::new(ManagedWidget::col(col).bg(Color::grey(0.4))) .aligned(HorizontalAlignment::Right, VerticalAlignment::Center) diff --git a/game/src/sandbox/overlays.rs b/game/src/sandbox/overlays.rs index 05dc77756d..5030592fe9 100644 --- a/game/src/sandbox/overlays.rs +++ b/game/src/sandbox/overlays.rs @@ -1,13 +1,15 @@ -use crate::common::{ColorLegend, Colorer, ColorerBuilder}; +use crate::common::{ColorLegend, Colorer, ColorerBuilder, Warping}; use crate::game::Transition; +use crate::helpers::ID; use crate::managed::{ManagedGUIState, Outcome}; use crate::sandbox::bus_explorer::ShowBusRoute; use crate::sandbox::SandboxMode; use crate::ui::UI; use abstutil::{prettyprint_usize, Counter}; use ezgui::{ - hotkey, Button, Color, Composite, Drawable, EventCtx, GeomBatch, GfxCtx, Histogram, - HorizontalAlignment, Key, Line, ManagedWidget, RewriteColor, Text, VerticalAlignment, + hotkey, Button, Color, Composite, Drawable, EventCtx, EventLoopMode, GeomBatch, GfxCtx, + Histogram, HorizontalAlignment, Key, Line, ManagedWidget, RewriteColor, Text, + VerticalAlignment, }; use geom::{Distance, Duration, PolyLine, Time}; use map_model::IntersectionID; @@ -28,7 +30,7 @@ pub enum Overlays { BusRoute(ShowBusRoute), BusDelaysOverTime(Composite), BusPassengers(crate::managed::Composite), - IntersectionDemand(Time, IntersectionID, Drawable, ColorLegend), + IntersectionDemand(Time, IntersectionID, Drawable, Composite), } impl Overlays { @@ -72,11 +74,28 @@ impl Overlays { Some(Outcome::Clicked(_)) => unreachable!(), None => {} }, - Overlays::IntersectionDemand(_, _, _, ref mut legend) => { - if legend.event(ctx) { - *self = Overlays::Inactive; - } - } + Overlays::IntersectionDemand(_, i, _, ref mut c) => match c.event(ctx) { + Some(ezgui::Outcome::Clicked(x)) => match x.as_ref() { + "intersection demand" => { + let id = ID::Intersection(*i); + return Some(Transition::PushWithMode( + Warping::new( + ctx, + id.canonical_point(&ui.primary).unwrap(), + Some(10.0), + Some(id.clone()), + &mut ui.primary, + ), + EventLoopMode::Animation, + )); + } + "X" => { + *self = Overlays::Inactive; + } + _ => unreachable!(), + }, + None => {} + }, Overlays::FinishedTripsHistogram(_, ref mut c) => match c.event(ctx) { Some(ezgui::Outcome::Clicked(x)) => match x.as_ref() { "X" => { @@ -506,16 +525,20 @@ impl Overlays { ); } - // TODO Say which intersection. Click to warp to it. + let mut col = vec![ManagedWidget::row(vec![ + // TODO Say which intersection? And have a location icon to jump to it + crate::managed::Composite::text_button(ctx, "intersection demand", None), + crate::managed::Composite::text_button(ctx, "X", None).align_right(), + ])]; + col.extend(ColorLegend::rows(ctx, vec![("current demand", Color::RED)])); + Overlays::IntersectionDemand( ui.primary.sim.time(), i, batch.upload(ctx), - ColorLegend::new( - ctx, - Text::from(Line("intersection demand")), - vec![("demand", Color::RED)], - ), + Composite::new(ManagedWidget::col(col).bg(Color::grey(0.4))) + .aligned(HorizontalAlignment::Right, VerticalAlignment::Center) + .build(ctx), ) } }