* Scrolls the viewport in a window to a given location. * @param x Desired x location of the map to scroll to (world coordinate). * @param y Desired y location of the map to scroll to (world coordinate). * @param z Desired z location of the map to scroll to (world coordinate). Use \c -1 to scroll to the height of the map at the \a x, \a y location. * @param w %Window co
| 2544 | * @return Destination of the viewport was changed (to activate other actions when the viewport is already at the desired position). |
| 2545 | */ |
| 2546 | bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant) |
| 2547 | { |
| 2548 | /* The slope cannot be acquired outside of the map, so make sure we are always within the map. */ |
| 2549 | if (z == -1) { |
| 2550 | if ( x >= 0 && x <= (int)Map::SizeX() * (int)TILE_SIZE - 1 |
| 2551 | && y >= 0 && y <= (int)Map::SizeY() * (int)TILE_SIZE - 1) { |
| 2552 | z = GetSlopePixelZ(x, y); |
| 2553 | } else { |
| 2554 | z = TileHeightOutsideMap(x / (int)TILE_SIZE, y / (int)TILE_SIZE); |
| 2555 | } |
| 2556 | } |
| 2557 | |
| 2558 | Point pt = MapXYZToViewport(*w->viewport, x, y, z); |
| 2559 | w->viewport->CancelFollow(*w); |
| 2560 | |
| 2561 | if (w->viewport->dest_scrollpos_x == pt.x && w->viewport->dest_scrollpos_y == pt.y) return false; |
| 2562 | |
| 2563 | if (instant) { |
| 2564 | w->viewport->scrollpos_x = pt.x; |
| 2565 | w->viewport->scrollpos_y = pt.y; |
| 2566 | RebuildViewportOverlay(w); |
| 2567 | } |
| 2568 | |
| 2569 | w->viewport->dest_scrollpos_x = pt.x; |
| 2570 | w->viewport->dest_scrollpos_y = pt.y; |
| 2571 | return true; |
| 2572 | } |
| 2573 | |
| 2574 | /** |
| 2575 | * Scrolls the viewport in a window to a given location. |
no test coverage detected