mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-27 15:03:20 +03:00
Restrict the LTN route planner to 2 waypoints. Too easy to accidentally click and add a third, and the route overlapping itself is a total mess.
This commit is contained in:
parent
e5ea25ec58
commit
696f010301
@ -46,7 +46,7 @@ impl RoutePlanner {
|
||||
let mut rp = RoutePlanner {
|
||||
top_panel: crate::common::app_top_panel(ctx, app),
|
||||
left_panel: Panel::empty(ctx),
|
||||
waypoints: InputWaypoints::new(app),
|
||||
waypoints: InputWaypoints::new_max_2(app),
|
||||
files: TripManagement::new(app),
|
||||
world: World::unbounded(),
|
||||
draw_routes: ToggleZoomed::empty(ctx),
|
||||
|
@ -13,6 +13,7 @@ use crate::AppLike;
|
||||
pub struct InputWaypoints {
|
||||
waypoints: Vec<Waypoint>,
|
||||
snap_to_endpts: FindClosest<TripEndpoint>,
|
||||
max_waypts: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
@ -26,6 +27,7 @@ struct Waypoint {
|
||||
}
|
||||
|
||||
impl InputWaypoints {
|
||||
/// Allows any number of waypoints
|
||||
pub fn new(app: &dyn AppLike) -> InputWaypoints {
|
||||
let map = app.map();
|
||||
let mut snap_to_endpts = FindClosest::new(map.get_bounds());
|
||||
@ -41,9 +43,18 @@ impl InputWaypoints {
|
||||
InputWaypoints {
|
||||
waypoints: Vec::new(),
|
||||
snap_to_endpts,
|
||||
max_waypts: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Only allow drawing routes with 2 waypoints. If a route is loaded with more than that, it
|
||||
/// can be modified.
|
||||
pub fn new_max_2(app: &dyn AppLike) -> Self {
|
||||
let mut i = Self::new(app);
|
||||
i.max_waypts = Some(2);
|
||||
i
|
||||
}
|
||||
|
||||
/// The caller should call `rebuild_world` after this
|
||||
pub fn overwrite(&mut self, app: &dyn AppLike, waypoints: Vec<TripEndpoint>) {
|
||||
self.waypoints.clear();
|
||||
@ -145,6 +156,9 @@ impl InputWaypoints {
|
||||
) -> bool {
|
||||
match world_outcome {
|
||||
WorldOutcome::ClickedFreeSpace(pt) => {
|
||||
if Some(self.waypoints.len()) == self.max_waypts {
|
||||
return false;
|
||||
}
|
||||
if let Some((at, _)) = self.snap_to_endpts.closest_pt(pt, Distance::meters(30.0)) {
|
||||
self.waypoints.push(Waypoint::new(app, at));
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user