mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 03:35:51 +03:00
Refactor internal panel management of road selector UI
This commit is contained in:
parent
bba48ec654
commit
e917cb7772
@ -28,21 +28,18 @@ impl RoadEditor {
|
|||||||
pub fn new(ctx: &mut EventCtx, app: &mut App, r: RoadID) -> Box<dyn State<App>> {
|
pub fn new(ctx: &mut EventCtx, app: &mut App, r: RoadID) -> Box<dyn State<App>> {
|
||||||
app.primary.current_selection = None;
|
app.primary.current_selection = None;
|
||||||
|
|
||||||
let num_edit_cmds_originally = app.primary.map.get_edits().commands.len();
|
let mut editor = RoadEditor {
|
||||||
let top_panel = make_top_panel(ctx, app, num_edit_cmds_originally, true);
|
|
||||||
let current_lane = None;
|
|
||||||
let main_panel = make_main_panel(ctx, app, app.primary.map.get_r(r), current_lane);
|
|
||||||
let highlight_selection = highlight_current_selection(ctx, app, r, current_lane);
|
|
||||||
Box::new(RoadEditor {
|
|
||||||
r,
|
r,
|
||||||
current_lane,
|
current_lane: None,
|
||||||
top_panel,
|
top_panel: Panel::empty(ctx),
|
||||||
main_panel,
|
main_panel: Panel::empty(ctx),
|
||||||
highlight_selection,
|
highlight_selection: (None, Drawable::empty(ctx)),
|
||||||
|
|
||||||
num_edit_cmds_originally,
|
num_edit_cmds_originally: app.primary.map.get_edits().commands.len(),
|
||||||
redo_stack: Vec::new(),
|
redo_stack: Vec::new(),
|
||||||
})
|
};
|
||||||
|
editor.recalc_all_panels(ctx, app);
|
||||||
|
Box::new(editor)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn modify_current_lane<F: Fn(&mut EditRoad, usize)>(
|
fn modify_current_lane<F: Fn(&mut EditRoad, usize)>(
|
||||||
@ -71,6 +68,10 @@ impl RoadEditor {
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
self.recalc_all_panels(ctx, app);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn recalc_all_panels(&mut self, ctx: &mut EventCtx, app: &App) {
|
||||||
self.main_panel =
|
self.main_panel =
|
||||||
make_main_panel(ctx, app, app.primary.map.get_r(self.r), self.current_lane);
|
make_main_panel(ctx, app, app.primary.map.get_r(self.r), self.current_lane);
|
||||||
self.highlight_selection = highlight_current_selection(ctx, app, self.r, self.current_lane);
|
self.highlight_selection = highlight_current_selection(ctx, app, self.r, self.current_lane);
|
||||||
@ -98,16 +99,7 @@ impl State<App> for RoadEditor {
|
|||||||
apply_map_edits(ctx, app, edits);
|
apply_map_edits(ctx, app, edits);
|
||||||
|
|
||||||
self.current_lane = None;
|
self.current_lane = None;
|
||||||
self.main_panel =
|
self.recalc_all_panels(ctx, app);
|
||||||
make_main_panel(ctx, app, app.primary.map.get_r(self.r), self.current_lane);
|
|
||||||
self.highlight_selection =
|
|
||||||
highlight_current_selection(ctx, app, self.r, self.current_lane);
|
|
||||||
self.top_panel = make_top_panel(
|
|
||||||
ctx,
|
|
||||||
app,
|
|
||||||
self.num_edit_cmds_originally,
|
|
||||||
self.redo_stack.is_empty(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
"redo" => {
|
"redo" => {
|
||||||
let mut edits = app.primary.map.get_edits().clone();
|
let mut edits = app.primary.map.get_edits().clone();
|
||||||
@ -115,16 +107,7 @@ impl State<App> for RoadEditor {
|
|||||||
apply_map_edits(ctx, app, edits);
|
apply_map_edits(ctx, app, edits);
|
||||||
|
|
||||||
self.current_lane = None;
|
self.current_lane = None;
|
||||||
self.main_panel =
|
self.recalc_all_panels(ctx, app);
|
||||||
make_main_panel(ctx, app, app.primary.map.get_r(self.r), self.current_lane);
|
|
||||||
self.highlight_selection =
|
|
||||||
highlight_current_selection(ctx, app, self.r, self.current_lane);
|
|
||||||
self.top_panel = make_top_panel(
|
|
||||||
ctx,
|
|
||||||
app,
|
|
||||||
self.num_edit_cmds_originally,
|
|
||||||
self.redo_stack.is_empty(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
},
|
},
|
||||||
@ -135,10 +118,7 @@ impl State<App> for RoadEditor {
|
|||||||
Outcome::Clicked(x) => {
|
Outcome::Clicked(x) => {
|
||||||
if let Some(idx) = x.strip_prefix("modify Lane #") {
|
if let Some(idx) = x.strip_prefix("modify Lane #") {
|
||||||
self.current_lane = Some(LaneID(idx.parse().unwrap()));
|
self.current_lane = Some(LaneID(idx.parse().unwrap()));
|
||||||
self.main_panel =
|
self.recalc_all_panels(ctx, app);
|
||||||
make_main_panel(ctx, app, app.primary.map.get_r(self.r), self.current_lane);
|
|
||||||
self.highlight_selection =
|
|
||||||
highlight_current_selection(ctx, app, self.r, self.current_lane);
|
|
||||||
} else if x == "delete lane" {
|
} else if x == "delete lane" {
|
||||||
self.modify_current_lane(ctx, app, None, |new, idx| {
|
self.modify_current_lane(ctx, app, None, |new, idx| {
|
||||||
new.lanes_ltr.remove(idx);
|
new.lanes_ltr.remove(idx);
|
||||||
@ -179,16 +159,7 @@ impl State<App> for RoadEditor {
|
|||||||
assert!(self.current_lane.is_none());
|
assert!(self.current_lane.is_none());
|
||||||
self.current_lane =
|
self.current_lane =
|
||||||
Some(app.primary.map.get_r(self.r).lanes_ltr().last().unwrap().0);
|
Some(app.primary.map.get_r(self.r).lanes_ltr().last().unwrap().0);
|
||||||
self.main_panel =
|
self.recalc_all_panels(ctx, app);
|
||||||
make_main_panel(ctx, app, app.primary.map.get_r(self.r), self.current_lane);
|
|
||||||
self.highlight_selection =
|
|
||||||
highlight_current_selection(ctx, app, self.r, self.current_lane);
|
|
||||||
self.top_panel = make_top_panel(
|
|
||||||
ctx,
|
|
||||||
app,
|
|
||||||
self.num_edit_cmds_originally,
|
|
||||||
self.redo_stack.is_empty(),
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
@ -206,14 +177,7 @@ impl State<App> for RoadEditor {
|
|||||||
self.redo_stack.clear();
|
self.redo_stack.clear();
|
||||||
|
|
||||||
// Lane IDs don't change
|
// Lane IDs don't change
|
||||||
self.main_panel =
|
self.recalc_all_panels(ctx, app);
|
||||||
make_main_panel(ctx, app, app.primary.map.get_r(self.r), self.current_lane);
|
|
||||||
self.top_panel = make_top_panel(
|
|
||||||
ctx,
|
|
||||||
app,
|
|
||||||
self.num_edit_cmds_originally,
|
|
||||||
self.redo_stack.is_empty(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
"width" => {
|
"width" => {
|
||||||
let width = self.main_panel.dropdown_value("width");
|
let width = self.main_panel.dropdown_value("width");
|
||||||
@ -242,18 +206,12 @@ impl State<App> for RoadEditor {
|
|||||||
// TODO Update the main panel to show which lane icon we're hovering on
|
// TODO Update the main panel to show which lane icon we're hovering on
|
||||||
if ctx.normal_left_click() {
|
if ctx.normal_left_click() {
|
||||||
self.current_lane = Some(l);
|
self.current_lane = Some(l);
|
||||||
self.main_panel =
|
self.recalc_all_panels(ctx, app);
|
||||||
make_main_panel(ctx, app, app.primary.map.get_r(self.r), self.current_lane);
|
|
||||||
self.highlight_selection =
|
|
||||||
highlight_current_selection(ctx, app, self.r, self.current_lane);
|
|
||||||
}
|
}
|
||||||
} else if self.current_lane.is_some() && ctx.normal_left_click() {
|
} else if self.current_lane.is_some() && ctx.normal_left_click() {
|
||||||
// Deselect the current lane
|
// Deselect the current lane
|
||||||
self.current_lane = None;
|
self.current_lane = None;
|
||||||
self.main_panel =
|
self.recalc_all_panels(ctx, app);
|
||||||
make_main_panel(ctx, app, app.primary.map.get_r(self.r), self.current_lane);
|
|
||||||
self.highlight_selection =
|
|
||||||
highlight_current_selection(ctx, app, self.r, self.current_lane);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let mut highlight = self.current_lane;
|
let mut highlight = self.current_lane;
|
||||||
|
Loading…
Reference in New Issue
Block a user