game/ungap/
explore.rs

1use geom::{ArrowCap, Distance, PolyLine};
2use widgetry::tools::URLManager;
3use widgetry::{Color, EventCtx, GfxCtx, Outcome, Panel, State, TextExt, Widget};
4
5use crate::app::{App, Transition};
6use crate::ungap::{Layers, Tab, TakeLayers};
7
8pub struct ExploreMap {
9    top_panel: Panel,
10    layers: Layers,
11}
12
13impl TakeLayers for ExploreMap {
14    fn take_layers(self) -> Layers {
15        self.layers
16    }
17}
18
19impl ExploreMap {
20    pub fn new_state(ctx: &mut EventCtx, app: &mut App, layers: Layers) -> Box<dyn State<App>> {
21        app.opts.show_building_driveways = false;
22
23        map_gui::tools::update_url_map_name(app);
24
25        Box::new(ExploreMap {
26            top_panel: Tab::Explore.make_left_panel(
27                ctx,
28                app,
29                Widget::col(vec![
30                    "Zoom in to see detailed lane information".text_widget(ctx),
31                    Widget::row(vec![
32                        "To explore elevation data,"
33                            .text_widget(ctx)
34                            .centered_vert(),
35                        ctx.style()
36                            .btn_plain
37                            .icon_text("system/assets/tools/layers.svg", "Show more layers")
38                            .build_def(ctx),
39                    ]),
40                ]),
41            ),
42            layers,
43        })
44    }
45}
46
47impl State<App> for ExploreMap {
48    fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition {
49        if ctx.canvas_movement() {
50            URLManager::update_url_cam(ctx, app.primary.map.get_gps_bounds());
51        }
52
53        if let Outcome::Clicked(x) = self.top_panel.event(ctx) {
54            match x.as_ref() {
55                "Show more layers" => {
56                    self.layers.show_panel(ctx, app);
57                }
58                x => {
59                    return Tab::Explore
60                        .handle_action::<ExploreMap>(ctx, app, x)
61                        .unwrap();
62                }
63            }
64        }
65
66        if let Some(t) = self.layers.event(ctx, app) {
67            return t;
68        }
69
70        Transition::Keep
71    }
72
73    fn draw(&self, g: &mut GfxCtx, app: &App) {
74        self.top_panel.draw(g);
75        self.layers.draw(g, app);
76
77        if self.top_panel.currently_hovering() == Some(&"Show more layers".to_string()) {
78            g.fork_screenspace();
79            if let Ok(pl) = PolyLine::new(vec![
80                self.top_panel.center_of("Show more layers").to_pt(),
81                self.layers.layer_icon_pos().to_pt(),
82            ]) {
83                g.draw_polygon(
84                    Color::RED,
85                    pl.make_arrow(Distance::meters(20.0), ArrowCap::Triangle),
86                );
87            }
88            g.unfork();
89        }
90    }
91}