1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
use std::collections::BTreeMap;

use map_gui::tools::{grey_out_map, nice_map_name, open_browser, PopupMsg};
use widgetry::{
    lctrl, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Panel, SimpleState,
    StyledButtons, Text, TextExt, VerticalAlignment, Widget,
};

use crate::app::{App, Transition};
use crate::edit::EditMode;
use crate::info::Tab;
use crate::sandbox::gameplay::freeform::ChangeScenario;
use crate::sandbox::gameplay::{GameplayMode, GameplayState};
use crate::sandbox::{Actions, SandboxControls};

pub struct Blog {
    top_center: Panel,
}

impl Blog {
    pub fn new(ctx: &mut EventCtx) -> Box<dyn GameplayState> {
        Box::new(Blog {
            top_center: Panel::empty(ctx),
        })
    }
}

impl GameplayState for Blog {
    fn event(
        &mut self,
        ctx: &mut EventCtx,
        app: &mut App,
        controls: &mut SandboxControls,
        actions: &mut Actions,
    ) -> Option<Transition> {
        match self.top_center.event(ctx) {
            Outcome::Clicked(x) => match x.as_ref() {
                // TODO This'll bring us out of this GameplayMode.
                "change scenario" => Some(Transition::Push(ChangeScenario::new(ctx, app, "none"))),
                "edit map" => Some(Transition::Push(EditMode::new(
                    ctx,
                    app,
                    GameplayMode::Freeform(app.primary.map.get_name().clone()),
                ))),
                "about A/B Street" => {
                    let panel = Panel::new(Widget::col(vec![
                        Widget::row(vec![
                            Line("About A/B Street").small_heading().draw(ctx),
                            ctx.style().btn_close_widget(ctx),
                        ]),
                        Line("Created by Dustin Carlino, Yuwen Li, & Michael Kirk")
                            .small()
                            .draw(ctx),
                        Text::from(Line(
                            "A/B Street is a traffic simulation game based on OpenStreetMap. You \
                             can modify roads and intersections, measure the effects on different \
                             groups, and advocate for your proposal.",
                        ))
                        .wrap_to_pct(ctx, 50)
                        .draw(ctx),
                        "This is a simplified version. Check out the full version below."
                            .draw_text(ctx),
                        ctx.style()
                            .btn_outline_light_text("abstreet.org")
                            .build_def(ctx),
                    ]))
                    .build(ctx);
                    Some(Transition::Push(SimpleState::new(panel, Box::new(About))))
                }
                "follow someone" => {
                    // Just find the first active non-bus person
                    if let Some(person) = app
                        .primary
                        .sim
                        .active_agents()
                        .into_iter()
                        .filter_map(|a| app.primary.sim.agent_to_person(a))
                        .next()
                    {
                        controls.common.as_mut().unwrap().launch_info_panel(
                            ctx,
                            app,
                            Tab::PersonTrips(person, BTreeMap::new()),
                            actions,
                        );
                        None
                    } else {
                        return Some(Transition::Push(PopupMsg::new(
                            ctx,
                            "Nobody's around...",
                            vec!["There are no active trips right now"],
                        )));
                    }
                }
                "bike network" => {
                    app.primary.layer =
                        Some(Box::new(crate::layer::map::BikeNetwork::new(ctx, app)));
                    None
                }
                _ => unreachable!(),
            },
            _ => None,
        }
    }

    fn draw(&self, g: &mut GfxCtx, _: &App) {
        self.top_center.draw(g);
    }

    fn recreate_panels(&mut self, ctx: &mut EventCtx, app: &App) {
        let col = Widget::col(vec![
            Widget::row(vec![
                ctx.style()
                    .btn_plain_light()
                    .image_path("system/assets/pregame/logo.svg")
                    .image_dims(50.0)
                    .build_widget(ctx, "about A/B Street")
                    .centered_vert(),
                Line(nice_map_name(app.primary.map.get_name()))
                    .small_heading()
                    .draw(ctx),
                Widget::vert_separator(ctx, 50.0),
                ctx.style()
                    .btn_light_popup_icon_text("system/assets/tools/calendar.svg", "none")
                    .hotkey(Key::S)
                    .build_widget(ctx, "change scenario"),
                ctx.style()
                    .btn_outline_light_icon_text("system/assets/tools/pencil.svg", "Edit map")
                    .hotkey(lctrl(Key::E))
                    .build_widget(ctx, "edit map"),
            ])
            .centered(),
            Widget::row(vec![
                ctx.style()
                    .btn_plain_light_icon_text("system/assets/tools/location.svg", "Follow someone")
                    .build_widget(ctx, "follow someone"),
                ctx.style()
                    .btn_plain_light_icon_text("system/assets/meters/bike.svg", "Bike network")
                    .build_widget(ctx, "bike network"),
            ]),
        ]);

        self.top_center = Panel::new(col)
            .aligned(HorizontalAlignment::Center, VerticalAlignment::Top)
            .build(ctx);
    }

    fn has_tool_panel(&self) -> bool {
        // Get rid of the home button, which would allow escaping to the title screen
        false
    }
}

struct About;

impl SimpleState<App> for About {
    fn on_click(&mut self, _: &mut EventCtx, _: &mut App, x: &str, _: &Panel) -> Transition {
        if x == "close" {
            return Transition::Pop;
        } else if x == "abstreet.org" {
            open_browser("https://abstreet.org");
        }
        Transition::Keep
    }

    fn draw(&self, g: &mut GfxCtx, app: &App) {
        grey_out_map(g, app);
    }
}