mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-20 19:02:41 +01:00
Change: improve when to stops following vehicle (#12808)
- Changing zoom no longer stops following vehicle - Key scrolling while following a vehicle stops following - Autoscrolling while following a vehicle stops following - Main viewport can begin following a vehicle at any zoom
This commit is contained in:
@@ -2683,15 +2683,20 @@ static void HandleAutoscroll()
|
||||
y -= vp->top;
|
||||
|
||||
/* here allows scrolling in both x and y axis */
|
||||
/* If we succeed at scrolling in any direction, stop following a vehicle. */
|
||||
static const int SCROLLSPEED = 3;
|
||||
if (x - 15 < 0) {
|
||||
w->viewport->follow_vehicle = INVALID_VEHICLE;
|
||||
w->viewport->dest_scrollpos_x += ScaleByZoom((x - 15) * SCROLLSPEED, vp->zoom);
|
||||
} else if (15 - (vp->width - x) > 0) {
|
||||
w->viewport->follow_vehicle = INVALID_VEHICLE;
|
||||
w->viewport->dest_scrollpos_x += ScaleByZoom((15 - (vp->width - x)) * SCROLLSPEED, vp->zoom);
|
||||
}
|
||||
if (y - 15 < 0) {
|
||||
w->viewport->follow_vehicle = INVALID_VEHICLE;
|
||||
w->viewport->dest_scrollpos_y += ScaleByZoom((y - 15) * SCROLLSPEED, vp->zoom);
|
||||
} else if (15 - (vp->height - y) > 0) {
|
||||
w->viewport->follow_vehicle = INVALID_VEHICLE;
|
||||
w->viewport->dest_scrollpos_y += ScaleByZoom((15 - (vp->height - y)) * SCROLLSPEED, vp->zoom);
|
||||
}
|
||||
}
|
||||
@@ -2755,6 +2760,10 @@ static void HandleKeyScrolling()
|
||||
*/
|
||||
if (_dirkeys && !EditBoxInGlobalFocus()) {
|
||||
int factor = _shift_pressed ? 50 : 10;
|
||||
|
||||
/* Key scrolling stops following a vehicle. */
|
||||
GetMainWindow()->viewport->follow_vehicle = INVALID_VEHICLE;
|
||||
|
||||
ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user