diff --git a/game/src/devtools/osm_viewer.rs b/game/src/devtools/osm_viewer.rs index d1168d77b1..60bde41701 100644 --- a/game/src/devtools/osm_viewer.rs +++ b/game/src/devtools/osm_viewer.rs @@ -214,6 +214,14 @@ impl State for Viewer { if self.fixed_object_outline.is_none() && old_id != app.primary.current_selection { self.recalculate_top_panel(ctx, app); } + + let maybe_amenity = ctx + .canvas + .get_cursor_in_screen_space() + .and_then(|_| self.top_panel.currently_hovering().cloned()); + if let Some(ref mut b) = self.businesses { + b.hovering_on_amenity(ctx, app, maybe_amenity); + } } if ctx.canvas.get_cursor_in_map_space().is_some() && ctx.normal_left_click() { @@ -323,6 +331,9 @@ impl State for Viewer { } if let Some(ref b) = self.businesses { g.redraw(&b.highlight); + if let Some((_, ref d)) = b.hovering_on_amenity { + g.redraw(d); + } } } } @@ -331,6 +342,7 @@ struct BusinessSearch { counts: Counter, show: BTreeSet, highlight: Drawable, + hovering_on_amenity: Option<(String, Drawable)>, } impl BusinessSearch { @@ -346,6 +358,7 @@ impl BusinessSearch { counts, show, highlight: ctx.upload(GeomBatch::new()), + hovering_on_amenity: None, }; // Initialize highlight @@ -377,6 +390,33 @@ impl BusinessSearch { self.highlight = ctx.upload(batch); } + fn hovering_on_amenity(&mut self, ctx: &mut EventCtx, app: &App, amenity: Option) { + if amenity.is_none() { + self.hovering_on_amenity = None; + return; + } + + let amenity = amenity.unwrap(); + if self + .hovering_on_amenity + .as_ref() + .map(|(current, _)| current == &amenity) + .unwrap_or(false) + { + return; + } + + let mut batch = GeomBatch::new(); + if self.counts.get(amenity.clone()) > 0 { + for b in app.primary.map.all_buildings() { + if b.amenities.iter().any(|(_, a)| a == &amenity) { + batch.push(Color::BLUE, b.polygon.clone()); + } + } + } + self.hovering_on_amenity = Some((amenity, ctx.upload(batch))); + } + fn render(&self, ctx: &mut EventCtx) -> Widget { let mut col = Vec::new(); col.push(Btn::text_bg2("Hide business search").build_def(ctx, Key::Tab)); diff --git a/widgetry/src/widgets/checkbox.rs b/widgetry/src/widgets/checkbox.rs index 3a43c9005a..c468e4645f 100644 --- a/widgetry/src/widgets/checkbox.rs +++ b/widgetry/src/widgets/checkbox.rs @@ -5,7 +5,7 @@ use crate::{ pub struct Checkbox { pub(crate) enabled: bool, - btn: Button, + pub(crate) btn: Button, other_btn: Button, } diff --git a/widgetry/src/widgets/mod.rs b/widgetry/src/widgets/mod.rs index 9910a39f9f..9c5c4c9477 100644 --- a/widgetry/src/widgets/mod.rs +++ b/widgetry/src/widgets/mod.rs @@ -12,8 +12,9 @@ use geom::{Distance, Percent, Polygon}; use crate::widgets::containers::{Container, Nothing}; pub use crate::widgets::panel::Panel; use crate::{ - Button, Choice, Color, DeferDraw, DrawWithTooltips, Drawable, Dropdown, EventCtx, GeomBatch, - GfxCtx, JustDraw, Menu, RewriteColor, ScreenDims, ScreenPt, ScreenRectangle, Text, TextBox, + Button, Checkbox, Choice, Color, DeferDraw, DrawWithTooltips, Drawable, Dropdown, EventCtx, + GeomBatch, GfxCtx, JustDraw, Menu, RewriteColor, ScreenDims, ScreenPt, ScreenRectangle, Text, + TextBox, }; pub mod autocomplete; @@ -617,6 +618,10 @@ impl Widget { if btn.hovering { return Some(&btn.action); } + } else if let Some(checkbox) = self.widget.downcast_ref::() { + if checkbox.btn.hovering { + return Some(&checkbox.btn.action); + } } else if let Some(container) = self.widget.downcast_ref::() { for w in &container.members { if let Some(a) = w.currently_hovering() {