mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-29 17:34:58 +03:00
fix up overlays, part 1:
- dont show most of them when zoomed in - change the layers icon when one is active
This commit is contained in:
parent
3aacb06fa5
commit
d22b26d66b
@ -200,7 +200,15 @@ pub struct Btn {}
|
||||
|
||||
impl Btn {
|
||||
pub fn svg<I: Into<String>>(path: I, hover: RewriteColor) -> BtnBuilder {
|
||||
BtnBuilder::SVG(path.into(), hover, None)
|
||||
BtnBuilder::SVG(path.into(), RewriteColor::NoOp, hover, None)
|
||||
}
|
||||
pub fn svg_def<I: Into<String>>(path: I) -> BtnBuilder {
|
||||
BtnBuilder::SVG(
|
||||
path.into(),
|
||||
RewriteColor::NoOp,
|
||||
RewriteColor::ChangeAll(Color::ORANGE),
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
// Same as WrappedComposite::text_button
|
||||
@ -256,7 +264,7 @@ impl Btn {
|
||||
}
|
||||
|
||||
pub enum BtnBuilder {
|
||||
SVG(String, RewriteColor, Option<Text>),
|
||||
SVG(String, RewriteColor, RewriteColor, Option<Text>),
|
||||
TextFG(String, Option<Text>),
|
||||
TextBG {
|
||||
label: String,
|
||||
@ -272,7 +280,7 @@ pub enum BtnBuilder {
|
||||
impl BtnBuilder {
|
||||
pub fn tooltip(mut self, tooltip: Text) -> BtnBuilder {
|
||||
match self {
|
||||
BtnBuilder::SVG(_, _, ref mut t)
|
||||
BtnBuilder::SVG(_, _, _, ref mut t)
|
||||
| BtnBuilder::TextFG(_, ref mut t)
|
||||
| BtnBuilder::Custom(_, _, _, ref mut t) => {
|
||||
assert!(t.is_none());
|
||||
@ -289,6 +297,20 @@ impl BtnBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn normal_color(mut self, rewrite: RewriteColor) -> BtnBuilder {
|
||||
match self {
|
||||
BtnBuilder::SVG(_, ref mut normal, _, _) => {
|
||||
match normal {
|
||||
RewriteColor::NoOp => {}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
*normal = rewrite;
|
||||
self
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn build<I: Into<String>>(
|
||||
self,
|
||||
ctx: &EventCtx,
|
||||
@ -296,11 +318,12 @@ impl BtnBuilder {
|
||||
key: Option<MultiKey>,
|
||||
) -> ManagedWidget {
|
||||
match self {
|
||||
BtnBuilder::SVG(path, hover, maybe_t) => {
|
||||
let (normal, bounds) = GeomBatch::from_svg(ctx, path, RewriteColor::NoOp);
|
||||
BtnBuilder::SVG(path, rewrite_normal, rewrite_hover, maybe_t) => {
|
||||
let (mut normal, bounds) = GeomBatch::from_svg(ctx, path, RewriteColor::NoOp);
|
||||
|
||||
let mut hovered = normal.clone();
|
||||
hovered.rewrite_color(hover);
|
||||
normal.rewrite_color(rewrite_normal);
|
||||
hovered.rewrite_color(rewrite_hover);
|
||||
|
||||
let mut btn = Button::new(
|
||||
ctx,
|
||||
@ -373,7 +396,7 @@ impl BtnBuilder {
|
||||
// Use the text as the action
|
||||
pub fn build_def(self, ctx: &EventCtx, hotkey: Option<MultiKey>) -> ManagedWidget {
|
||||
match self {
|
||||
BtnBuilder::SVG(_, _, _) => panic!("Can't use build_def on an SVG button"),
|
||||
BtnBuilder::SVG(_, _, _, _) => panic!("Can't use build_def on an SVG button"),
|
||||
BtnBuilder::Custom(_, _, _, _) => panic!("Can't use build_def on a custom button"),
|
||||
BtnBuilder::TextFG(ref label, _) | BtnBuilder::TextBG { ref label, .. } => {
|
||||
let copy = label.clone();
|
||||
|
@ -21,7 +21,7 @@ pub struct ColorerBuilder {
|
||||
}
|
||||
|
||||
pub struct Colorer {
|
||||
zoomed: Drawable,
|
||||
pub zoomed: Drawable,
|
||||
pub unzoomed: Drawable,
|
||||
pub legend: Composite,
|
||||
}
|
||||
|
@ -15,7 +15,9 @@ use geom::{Circle, Distance, Polygon, Pt2D, Ring};
|
||||
pub struct Minimap {
|
||||
dragging: bool,
|
||||
pub(crate) composite: Composite,
|
||||
// Update panel when other things change
|
||||
zoomed: bool,
|
||||
overlay: bool,
|
||||
|
||||
// [0, 3], with 0 meaning the most unzoomed
|
||||
zoom_lvl: usize,
|
||||
@ -35,6 +37,7 @@ impl Minimap {
|
||||
dragging: false,
|
||||
composite: make_minimap_panel(ctx, app, 0),
|
||||
zoomed: ctx.canvas.cam_zoom >= MIN_ZOOM_FOR_DETAIL,
|
||||
overlay: app.overlay.is_empty(),
|
||||
|
||||
zoom_lvl: 0,
|
||||
base_zoom,
|
||||
@ -53,8 +56,10 @@ impl Minimap {
|
||||
|
||||
pub fn event(&mut self, app: &mut App, ctx: &mut EventCtx) -> Option<Transition> {
|
||||
let zoomed = ctx.canvas.cam_zoom >= MIN_ZOOM_FOR_DETAIL;
|
||||
if zoomed != self.zoomed {
|
||||
let overlay = app.overlay.is_empty();
|
||||
if zoomed != self.zoomed || overlay != self.overlay {
|
||||
self.zoomed = zoomed;
|
||||
self.overlay = overlay;
|
||||
self.composite = make_minimap_panel(ctx, app, self.zoom_lvl);
|
||||
}
|
||||
|
||||
@ -366,13 +371,14 @@ fn make_viz_panel(ctx: &mut EventCtx, app: &App) -> ManagedWidget {
|
||||
)
|
||||
.margin(10)
|
||||
},
|
||||
WrappedComposite::svg_button(
|
||||
ctx,
|
||||
"../data/system/assets/tools/layers.svg",
|
||||
"change overlay",
|
||||
hotkey(Key::L),
|
||||
)
|
||||
.margin(10),
|
||||
Btn::svg_def("../data/system/assets/tools/layers.svg")
|
||||
.normal_color(if app.overlay.is_empty() {
|
||||
RewriteColor::NoOp
|
||||
} else {
|
||||
RewriteColor::ChangeAll(Color::BLUE)
|
||||
})
|
||||
.build(ctx, "change overlay", hotkey(Key::L))
|
||||
.margin(10),
|
||||
])
|
||||
.centered()];
|
||||
for (label, color, enabled) in &app.agent_cs.rows {
|
||||
|
@ -5,6 +5,7 @@ use crate::game::Transition;
|
||||
use crate::helpers::rotating_color_map;
|
||||
use crate::helpers::ID;
|
||||
use crate::managed::{ManagedGUIState, WrappedComposite, WrappedOutcome};
|
||||
use crate::render::MIN_ZOOM_FOR_DETAIL;
|
||||
use abstutil::{prettyprint_usize, Counter};
|
||||
use ezgui::{
|
||||
hotkey, Btn, Button, Color, Composite, Drawable, EventCtx, GeomBatch, GfxCtx, Histogram,
|
||||
@ -36,6 +37,13 @@ pub enum Overlays {
|
||||
}
|
||||
|
||||
impl Overlays {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
match self {
|
||||
Overlays::Inactive => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
// Since Overlays is embedded in UI, we have to do this slight trick
|
||||
pub fn update(ctx: &mut EventCtx, app: &mut App, minimap: &Composite) -> Option<Transition> {
|
||||
let now = app.primary.sim.time();
|
||||
@ -195,12 +203,18 @@ impl Overlays {
|
||||
| Overlays::TrafficJams(_, ref heatmap)
|
||||
| Overlays::CumulativeThroughput(_, ref heatmap)
|
||||
| Overlays::Edits(ref heatmap) => {
|
||||
heatmap.draw(g);
|
||||
if g.canvas.cam_zoom < MIN_ZOOM_FOR_DETAIL {
|
||||
heatmap.draw(g);
|
||||
}
|
||||
}
|
||||
Overlays::Elevation(ref heatmap, ref draw) => {
|
||||
heatmap.draw(g);
|
||||
g.redraw(draw);
|
||||
// TODO Maybe this is still useful when zoomed in
|
||||
if g.canvas.cam_zoom < MIN_ZOOM_FOR_DETAIL {
|
||||
heatmap.draw(g);
|
||||
g.redraw(draw);
|
||||
}
|
||||
}
|
||||
// All of these shouldn't care about zoom
|
||||
Overlays::TripsHistogram(_, ref composite)
|
||||
| Overlays::BusDelaysOverTime(_, _, ref composite) => {
|
||||
composite.draw(g);
|
||||
|
@ -269,8 +269,13 @@ fn challenge_controller(
|
||||
|
||||
let mut rows = vec![ManagedWidget::row(vec![
|
||||
Line(title).size(26).draw(ctx).margin(5),
|
||||
WrappedComposite::svg_button(ctx, "../data/system/assets/tools/info.svg", "instructions", None)
|
||||
.margin(5),
|
||||
WrappedComposite::svg_button(
|
||||
ctx,
|
||||
"../data/system/assets/tools/info.svg",
|
||||
"instructions",
|
||||
None,
|
||||
)
|
||||
.margin(5),
|
||||
ManagedWidget::draw_batch(
|
||||
ctx,
|
||||
GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(2.0, 50.0))]),
|
||||
|
Loading…
Reference in New Issue
Block a user