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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
use abstutil::Timer;
use geom::{LonLat, Percent};
use map_gui::colors::ColorSchemeChoice;
use map_gui::tools::{ChooseSomething, CityPicker};
use map_gui::AppLike;
use widgetry::{
Choice, DrawBaselayer, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Panel, State,
VerticalAlignment, Widget,
};
use crate::app::{App, Transition};
mod collisions;
mod destinations;
pub mod kml;
mod polygon;
mod scenario;
mod story;
pub struct DevToolsMode {
panel: Panel,
}
impl DevToolsMode {
pub fn new_state(ctx: &mut EventCtx, app: &mut App) -> Box<dyn State<App>> {
app.change_color_scheme(ctx, ColorSchemeChoice::DayMode);
Box::new(DevToolsMode {
panel: Panel::new_builder(Widget::col(vec![
Widget::row(vec![
Line("Internal dev tools").small_heading().into_widget(ctx),
ctx.style().btn_close_widget(ctx),
]),
map_gui::tools::change_map_btn(ctx, app),
Widget::custom_row(vec![
ctx.style()
.btn_outline
.text("edit a polygon")
.hotkey(Key::E)
.build_def(ctx),
ctx.style()
.btn_outline
.text("draw a polygon")
.hotkey(Key::P)
.build_def(ctx),
ctx.style()
.btn_outline
.text("load scenario")
.hotkey(Key::W)
.build_def(ctx),
ctx.style()
.btn_outline
.text("view KML")
.hotkey(Key::K)
.build_def(ctx),
ctx.style()
.btn_outline
.text("story maps")
.hotkey(Key::S)
.build_def(ctx),
if abstio::file_exists(
app.primary.map.get_city_name().input_path("collisions.bin"),
) {
ctx.style()
.btn_outline
.text("collisions")
.hotkey(Key::C)
.build_def(ctx)
} else {
Widget::nothing()
},
])
.flex_wrap(ctx, Percent::int(60)),
]))
.aligned(HorizontalAlignment::Center, VerticalAlignment::Top)
.build(ctx),
})
}
}
impl State<App> for DevToolsMode {
fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition {
if let Outcome::Clicked(x) = self.panel.event(ctx) {
match x.as_ref() {
"close" => {
return Transition::Pop;
}
"edit a polygon" => {
return Transition::Push(ChooseSomething::new_state(
ctx,
"Choose a polygon",
abstio::list_dir(abstio::path(format!(
"../importer/config/{}/{}",
app.primary.map.get_city_name().country,
app.primary.map.get_city_name().city
)))
.into_iter()
.filter(|path| path.ends_with(".poly"))
.map(|path| Choice::new(abstutil::basename(&path), path))
.collect(),
Box::new(|path, ctx, app| match LonLat::read_osmosis_polygon(&path) {
Ok(pts) => Transition::Replace(polygon::PolygonEditor::new_state(
ctx,
app,
abstutil::basename(path),
pts,
)),
Err(err) => {
println!("Bad polygon {}: {}", path, err);
Transition::Pop
}
}),
));
}
"draw a polygon" => {
return Transition::Push(polygon::PolygonEditor::new_state(
ctx,
app,
"name goes here".to_string(),
Vec::new(),
));
}
"load scenario" => {
return Transition::Push(ChooseSomething::new_state(
ctx,
"Choose a scenario",
Choice::strings(abstio::list_all_objects(abstio::path_all_scenarios(
app.primary.map.get_name(),
))),
Box::new(|s, ctx, app| {
let scenario = abstio::read_binary(
abstio::path_scenario(app.primary.map.get_name(), &s),
&mut Timer::throwaway(),
);
Transition::Replace(scenario::ScenarioManager::new_state(
scenario, ctx, app,
))
}),
));
}
"view KML" => {
return Transition::Push(kml::ViewKML::new_state(ctx, app, None));
}
"story maps" => {
return Transition::Push(story::StoryMapEditor::new_state(ctx, app));
}
"collisions" => {
return Transition::Push(collisions::CollisionsViewer::new_state(ctx, app));
}
"change map" => {
return Transition::Push(CityPicker::new_state(
ctx,
app,
Box::new(|ctx, app| {
Transition::Multi(vec![
Transition::Pop,
Transition::Replace(DevToolsMode::new_state(ctx, app)),
])
}),
));
}
_ => unreachable!(),
}
}
Transition::Keep
}
fn draw_baselayer(&self) -> DrawBaselayer {
DrawBaselayer::Custom
}
fn draw(&self, g: &mut GfxCtx, app: &App) {
g.clear(app.cs.dialog_bg);
self.panel.draw(g);
}
}