diff options
-rw-r--r-- | src/vehicle_gui.cpp | 13 | ||||
-rw-r--r-- | src/window.cpp | 7 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index aac92f30c..e19086556 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -2086,9 +2086,16 @@ static void VehicleViewWndProc(Window *w, WindowEvent *e) DoCommandP(v->tile, v->index, 0, NULL, _vehicle_command_translation_table[VCT_CMD_START_STOP][v->type]); break; - case VVW_WIDGET_CENTER_MAIN_VIEH: /* center main view */ - ScrollMainWindowTo(v->x_pos, v->y_pos); - break; + case VVW_WIDGET_CENTER_MAIN_VIEH: {/* center main view */ + const Window *mainwindow = FindWindowById(WC_MAIN_WINDOW, 0); + /* code to allow the main window to 'follow' the vehicle if the ctrl key is pressed */ + if (_ctrl_pressed && mainwindow->viewport->zoom == ZOOM_LVL_NORMAL) { + WP(mainwindow, vp_d).follow_vehicle = v->index; + } else { + ScrollMainWindowTo(v->x_pos, v->y_pos); + } + } break; + case VVW_WIDGET_GOTO_DEPOT: /* goto hangar */ DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0, NULL, _vehicle_command_translation_table[VCT_CMD_GOTO_DEPOT][v->type]); diff --git a/src/window.cpp b/src/window.cpp index 82458879b..44dc9ae2a 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1466,6 +1466,13 @@ static bool HandleViewportScroll() w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y); + if (WP(w, vp_d).follow_vehicle != INVALID_VEHICLE && w == FindWindowById(WC_MAIN_WINDOW, 0)) { + /* If the main window is following a vehicle, then first let go of it! */ + const Vehicle *veh = GetVehicle(WP(w, vp_d).follow_vehicle); + ScrollMainWindowTo(veh->x_pos, veh->y_pos, true); /* This also resets follow_vehicle */ + return true; + } + if (!(_right_button_down || scrollwheel_scrolling) || w == NULL) { _cursor.fix_at = false; _scrolling_viewport = false; |