Skip to content

Commit

Permalink
Move the file management / proposal management stuff into an optional…
Browse files Browse the repository at this point in the history
… add-on to the top-bar. #951

Sliiightly untested.
  • Loading branch information
dabreegster committed Sep 6, 2022
1 parent 2712d89 commit 7427354
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 117 deletions.
2 changes: 2 additions & 0 deletions apps/ltn/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ pub struct Session {

// Shared in all modes
pub layers: crate::components::Layers,
pub manage_proposals: bool,
}

impl AppLike for App {
Expand Down Expand Up @@ -227,6 +228,7 @@ impl App {
show_walking_cycling_routes: false,

layers: crate::components::Layers::new(ctx),
manage_proposals: false,
};

let cs = ColorScheme::new(ctx, opts.color_scheme);
Expand Down
23 changes: 12 additions & 11 deletions apps/ltn/src/browse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ impl BrowseNeighbourhoods {
ctx,
&top_panel,
Widget::col(vec![
app.per_map.alt_proposals.to_widget(ctx, app),
Toggle::checkbox(ctx, "Advanced features", None, app.opts.dev),
advanced_panel(ctx, app),
]),
Expand All @@ -67,7 +66,13 @@ impl BrowseNeighbourhoods {

impl State<App> for BrowseNeighbourhoods {
fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition {
if let Some(t) = crate::components::TopPanel::event(ctx, app, &mut self.top_panel, help) {
if let Some(t) = crate::components::TopPanel::event(
ctx,
app,
&mut self.top_panel,
&crate::save::PreserveState::BrowseNeighbourhoods,
help,
) {
return t;
}
if let Some(t) = app
Expand Down Expand Up @@ -101,15 +106,7 @@ impl State<App> for BrowseNeighbourhoods {
});
return Transition::Replace(BrowseNeighbourhoods::new_state(ctx, app));
}
x => {
return crate::save::AltProposals::handle_action(
ctx,
app,
crate::save::PreserveState::BrowseNeighbourhoods,
x,
)
.unwrap();
}
_ => unreachable!(),
},
Outcome::Changed(x) => {
if x == "Advanced features" {
Expand Down Expand Up @@ -153,6 +150,10 @@ impl State<App> for BrowseNeighbourhoods {
app.per_map.draw_all_filters.draw(g);
app.per_map.draw_poi_icons.draw(g);
}

fn recreate(&mut self, ctx: &mut EventCtx, app: &mut App) -> Box<dyn State<App>> {
Self::new_state(ctx, app)
}
}

fn make_world(ctx: &mut EventCtx, app: &App) -> World<NeighbourhoodID> {
Expand Down
108 changes: 49 additions & 59 deletions apps/ltn/src/components/top_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use widgetry::tools::ChooseSomething;
use widgetry::tools::PopupMsg;
use widgetry::{
lctrl, Choice, Color, CornerRounding, EventCtx, HorizontalAlignment, Key, Line, Outcome, Panel,
PanelDims, VerticalAlignment, Widget,
PanelDims, Toggle, VerticalAlignment, Widget,
};

use crate::components::Mode;
Expand Down Expand Up @@ -60,57 +60,56 @@ impl TopPanel {
Some("Not supported here yet")
})
.build_def(ctx),
Toggle::checkbox(ctx, "Manage proposals", None, app.session.manage_proposals),
])
.centered_vert()
.padding(16)
.outline((5.0, Color::BLACK))
} else {
Widget::nothing()
};

Panel::new_builder(
let mut col = vec![Widget::row(vec![
map_gui::tools::home_btn(ctx),
Line(if consultation {
"East Bristol Liveable Neighbourhood"
} else {
"Low traffic neighbourhoods"
})
.small_heading()
.into_widget(ctx)
.centered_vert(),
ctx.style()
.btn_plain
.icon("system/assets/tools/info.svg")
.build_widget(ctx, "about this tool")
.centered_vert()
.hide(consultation),
map_gui::tools::change_map_btn(ctx, app)
.centered_vert()
.hide(consultation),
navbar,
Widget::row(vec![
map_gui::tools::home_btn(ctx),
Line(if consultation {
"East Bristol Liveable Neighbourhood"
} else {
"Low traffic neighbourhoods"
})
.small_heading()
.into_widget(ctx)
.centered_vert(),
ctx.style()
.btn_plain
.icon("system/assets/tools/info.svg")
.build_widget(ctx, "about this tool")
.centered_vert()
.hide(consultation),
map_gui::tools::change_map_btn(ctx, app)
.centered_vert()
.hide(consultation),
navbar,
Widget::row(vec![
ctx.style()
.btn_plain
.text("Export to GeoJSON")
.build_def(ctx)
.centered_vert()
.hide(consultation),
ctx.style()
.btn_plain
.icon("system/assets/tools/search.svg")
.hotkey(lctrl(Key::F))
.build_widget(ctx, "search")
.centered_vert(),
ctx.style()
.btn_plain
.icon("system/assets/tools/help.svg")
.build_widget(ctx, "help")
.centered_vert(),
])
.align_right(),
.icon("system/assets/tools/search.svg")
.hotkey(lctrl(Key::F))
.build_widget(ctx, "search")
.centered_vert(),
ctx.style()
.btn_plain
.icon("system/assets/tools/help.svg")
.build_widget(ctx, "help")
.centered_vert(),
])
.corner_rounding(CornerRounding::CornerRadii(CornerRadii {
.align_right(),
])];
// Switching proposals in impact mode is too complex to implement, so don't allow it
if app.session.manage_proposals && mode != Mode::Impact {
col.push(app.per_map.alt_proposals.to_widget(ctx, app));
}

Panel::new_builder(
Widget::col(col).corner_rounding(CornerRounding::CornerRadii(CornerRadii {
top_left: 0.0,
bottom_left: 0.0,
bottom_right: 0.0,
Expand All @@ -126,10 +125,11 @@ impl TopPanel {
ctx: &mut EventCtx,
app: &mut App,
panel: &mut Panel,
preserve_state: &crate::save::PreserveState,
help: F,
) -> Option<Transition> {
if let Outcome::Clicked(x) = panel.event(ctx) {
match x.as_ref() {
match panel.event(ctx) {
Outcome::Clicked(x) => match x.as_ref() {
"Home" => {
if app.per_map.consultation.is_none() {
Some(Transition::Clear(vec![
Expand All @@ -156,19 +156,6 @@ impl TopPanel {
)),
"help" => Some(Transition::Push(PopupMsg::new_state(ctx, "Help", help()))),
"about this tool" => Some(Transition::Push(super::about::About::new_state(ctx))),
"Export to GeoJSON" => {
let result = crate::export::write_geojson_file(ctx, app);
Some(Transition::Push(match result {
Ok(path) => PopupMsg::new_state(
ctx,
"LTNs exported",
vec![format!("Data exported to {}", path)],
),
Err(err) => {
PopupMsg::new_state(ctx, "Export failed", vec![err.to_string()])
}
}))
}
"Pick area" => Some(Transition::Replace(BrowseNeighbourhoods::new_state(
ctx, app,
))),
Expand All @@ -181,10 +168,13 @@ impl TopPanel {
crate::route_planner::RoutePlanner::new_state(ctx, app),
)),
"Predict impact" => Some(launch_impact(ctx, app)),
_ => unreachable!(),
x => crate::save::AltProposals::handle_action(ctx, app, preserve_state, x),
},
Outcome::Changed(_) => {
app.session.manage_proposals = panel.is_checked("Manage proposals");
Some(Transition::Recreate)
}
} else {
None
_ => None,
}
}
}
Expand Down
29 changes: 14 additions & 15 deletions apps/ltn/src/connectivity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub struct Viewer {
draw_under_roads_layer: Drawable,
highlight_cell: World<DummyID>,
edit: EditNeighbourhood,
// Expensive to calculate
preserve_state: crate::save::PreserveState,

show_error: Drawable,
}
Expand All @@ -43,6 +45,10 @@ impl Viewer {
draw_under_roads_layer: Drawable::empty(ctx),
highlight_cell: World::unbounded(),
edit: EditNeighbourhood::temporary(),
preserve_state: crate::save::PreserveState::Connectivity(
app.per_map.partitioning.all_blocks_in_neighbourhood(id),
),

show_error: Drawable::empty(ctx),
};
viewer.update(ctx, app);
Expand Down Expand Up @@ -110,7 +116,13 @@ impl Viewer {

impl State<App> for Viewer {
fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition {
if let Some(t) = crate::components::TopPanel::event(ctx, app, &mut self.top_panel, help) {
if let Some(t) = crate::components::TopPanel::event(
ctx,
app,
&mut self.top_panel,
&self.preserve_state,
help,
) {
return t;
}
if let Some(t) = app
Expand Down Expand Up @@ -165,8 +177,7 @@ impl State<App> for Viewer {
&self.neighbourhood,
&mut self.left_panel,
) {
// Fall through to AltProposals
EditOutcome::Nothing => {}
EditOutcome::Nothing => unreachable!(),
EditOutcome::UpdatePanelAndWorld => {
self.update(ctx, app);
return Transition::Keep;
Expand All @@ -175,18 +186,6 @@ impl State<App> for Viewer {
return t;
}
}

return crate::save::AltProposals::handle_action(
ctx,
app,
crate::save::PreserveState::Connectivity(
app.per_map
.partitioning
.all_blocks_in_neighbourhood(self.neighbourhood.id),
),
&x,
)
.unwrap();
}
Outcome::Changed(x) => match x.as_ref() {
"Advanced features" => {
Expand Down
5 changes: 1 addition & 4 deletions apps/ltn/src/edit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ impl EditNeighbourhood {
per_tab_contents: Widget,
) -> PanelBuilder {
let contents = Widget::col(vec![
app.per_map.alt_proposals.to_widget(ctx, app),
Line("Editing neighbourhood")
.small_heading()
.into_widget(ctx),
Line("Editing area").small_heading().into_widget(ctx),
if app.per_map.consultation.is_none() {
ctx.style()
.btn_outline
Expand Down
9 changes: 8 additions & 1 deletion apps/ltn/src/impact/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,14 @@ impl ShowResults {
}
impl State<App> for ShowResults {
fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition {
if let Some(t) = crate::components::TopPanel::event(ctx, app, &mut self.top_panel, help) {
// PreserveState doesn't matter
if let Some(t) = crate::components::TopPanel::event(
ctx,
app,
&mut self.top_panel,
&crate::save::PreserveState::Route,
help,
) {
return t;
}
if let Some(t) = app.session.layers.event(ctx, &app.cs, Mode::Impact) {
Expand Down
22 changes: 12 additions & 10 deletions apps/ltn/src/route_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ impl RoutePlanner {
let results_widget = self.recalculate_paths(ctx, app);

let contents = Widget::col(vec![
app.per_map.alt_proposals.to_widget(ctx, app),
Line("Plan a route").small_heading().into_widget(ctx),
Widget::col(vec![
self.files.get_panel_widget(ctx),
Expand Down Expand Up @@ -311,7 +310,13 @@ impl RoutePlanner {

impl State<App> for RoutePlanner {
fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition {
if let Some(t) = crate::components::TopPanel::event(ctx, app, &mut self.top_panel, help) {
if let Some(t) = crate::components::TopPanel::event(
ctx,
app,
&mut self.top_panel,
&crate::save::PreserveState::Route,
help,
) {
return t;
}
if let Some(t) = app.session.layers.event(ctx, &app.cs, Mode::RoutePlanner) {
Expand All @@ -327,14 +332,7 @@ impl State<App> for RoutePlanner {
}
return t;
}
if let Some(t) = crate::save::AltProposals::handle_action(
ctx,
app,
crate::save::PreserveState::Route,
x,
) {
return t;
}
unreachable!()
}

if let Outcome::Changed(ref x) = panel_outcome {
Expand Down Expand Up @@ -380,6 +378,10 @@ impl State<App> for RoutePlanner {
app.per_map.draw_all_filters.draw(g);
app.per_map.draw_poi_icons.draw(g);
}

fn recreate(&mut self, ctx: &mut EventCtx, app: &mut App) -> Box<dyn State<App>> {
Self::new_state(ctx, app)
}
}

fn help() -> Vec<&'static str> {
Expand Down
Loading

0 comments on commit 7427354

Please sign in to comment.