highlight the road after warping to it

This commit is contained in:
Dustin Carlino 2018-07-03 14:47:33 -07:00
parent f1024792e4
commit 2f8d1e8150
2 changed files with 18 additions and 4 deletions

View File

@ -5,6 +5,7 @@ use map_model::Map;
use map_model::RoadID;
use piston::input::Key;
use piston::window::Size;
use plugins::selection::SelectionState;
use std::usize;
pub enum WarpState {
@ -19,6 +20,7 @@ impl WarpState {
map: &Map,
canvas: &mut Canvas,
window_size: &Size,
selection_state: &mut SelectionState,
) -> WarpState {
match self {
WarpState::Empty => {
@ -34,7 +36,7 @@ impl WarpState {
WarpState::EnteringSearch(mut tb) => {
if tb.event(input.use_event_directly()) {
input.consume_event();
warp(tb.line, map, canvas, window_size);
warp(tb.line, map, canvas, window_size, selection_state);
WarpState::Empty
} else {
input.consume_event();
@ -53,13 +55,20 @@ impl WarpState {
}
}
fn warp(line: String, map: &Map, canvas: &mut Canvas, window_size: &Size) {
fn warp(
line: String,
map: &Map,
canvas: &mut Canvas,
window_size: &Size,
selection_state: &mut SelectionState,
) {
match usize::from_str_radix(&line, 10) {
Ok(idx) => {
let id = RoadID(idx);
println!("Warping to {}", id);
let pt = map.get_r(id).first_pt();
canvas.center_on_map_pt(pt.x(), pt.y(), window_size);
*selection_state = SelectionState::SelectedRoad(id, None);
}
Err(_) => {
println!("{} isn't a valid ID", line);

View File

@ -375,8 +375,13 @@ impl gui::GUI for UI {
}
self.current_search_state = self.current_search_state.event(input);
self.warp = self.warp
.event(input, &self.map, &mut self.canvas, window_size);
self.warp = self.warp.event(
input,
&self.map,
&mut self.canvas,
window_size,
&mut self.current_selection_state,
);
if !edit_mode && self.sim_ctrl.event(input, &self.map, &self.control_map) {
event_loop_mode = event_loop_mode.merge(animation::EventLoopMode::Animation);