mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r21020) -Add: Use center of waypoint in waypoint gui, if available.
This commit is contained in:
parent
cccbc8f418
commit
83094e5e58
|
@ -1886,6 +1886,18 @@ bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scrolls the viewport in a window to a given location.
|
||||||
|
* @param tile Desired tile to center on.
|
||||||
|
* @param w %Window containing the viewport.
|
||||||
|
* @param instant Jump to the location instead of slowly moving to it.
|
||||||
|
* @return Destination of the viewport was changed (to activate other actions when the viewport is already at the desired position).
|
||||||
|
*/
|
||||||
|
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant)
|
||||||
|
{
|
||||||
|
return ScrollWindowTo(TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE, -1, w, instant);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scrolls the viewport of the main window to a given location.
|
* Scrolls the viewport of the main window to a given location.
|
||||||
* @param tile Desired tile to center on.
|
* @param tile Desired tile to center on.
|
||||||
|
|
|
@ -64,6 +64,7 @@ void SetTileSelectBigSize(int ox, int oy, int sx, int sy);
|
||||||
|
|
||||||
void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom);
|
void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom);
|
||||||
|
|
||||||
|
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant = false);
|
||||||
bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant = false);
|
bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant = false);
|
||||||
|
|
||||||
bool ScrollMainWindowToTile(TileIndex tile, bool instant = false);
|
bool ScrollMainWindowToTile(TileIndex tile, bool instant = false);
|
||||||
|
|
|
@ -34,10 +34,20 @@ enum WaypointWindowWidgets {
|
||||||
WAYPVW_SHOW_VEHICLES,
|
WAYPVW_SHOW_VEHICLES,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** GUI for accessing waypoints and buoys. */
|
||||||
struct WaypointWindow : Window {
|
struct WaypointWindow : Window {
|
||||||
private:
|
private:
|
||||||
VehicleType vt;
|
VehicleType vt; ///< Vehicle type using the waypoint.
|
||||||
Waypoint *wp;
|
Waypoint *wp; ///< Waypoint displayed by the window.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the center tile of the waypoint.
|
||||||
|
* @return The center tile if the waypoint exists, otherwise the tile with the waypoint name.
|
||||||
|
*/
|
||||||
|
TileIndex GetCenterTile() const
|
||||||
|
{
|
||||||
|
return this->wp->IsInUse() ? this->wp->train_station.GetCenterTile() : this->wp->xy;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WaypointWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
|
WaypointWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
|
||||||
|
@ -57,7 +67,7 @@ public:
|
||||||
this->flags4 |= WF_DISABLE_VP_SCROLL;
|
this->flags4 |= WF_DISABLE_VP_SCROLL;
|
||||||
|
|
||||||
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WAYPVW_VIEWPORT);
|
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WAYPVW_VIEWPORT);
|
||||||
nvp->InitializeViewport(this, this->wp->xy, ZOOM_LVL_MIN);
|
nvp->InitializeViewport(this, this->GetCenterTile(), ZOOM_LVL_MIN);
|
||||||
|
|
||||||
this->OnInvalidateData(0);
|
this->OnInvalidateData(0);
|
||||||
}
|
}
|
||||||
|
@ -84,9 +94,9 @@ public:
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
case WAYPVW_CENTERVIEW: // scroll to location
|
case WAYPVW_CENTERVIEW: // scroll to location
|
||||||
if (_ctrl_pressed) {
|
if (_ctrl_pressed) {
|
||||||
ShowExtraViewPortWindow(this->wp->xy);
|
ShowExtraViewPortWindow(this->GetCenterTile());
|
||||||
} else {
|
} else {
|
||||||
ScrollMainWindowToTile(this->wp->xy);
|
ScrollMainWindowToTile(this->GetCenterTile());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -108,9 +118,7 @@ public:
|
||||||
/* Disable the widget for waypoints with no use */
|
/* Disable the widget for waypoints with no use */
|
||||||
this->SetWidgetDisabledState(WAYPVW_SHOW_VEHICLES, !this->wp->IsInUse());
|
this->SetWidgetDisabledState(WAYPVW_SHOW_VEHICLES, !this->wp->IsInUse());
|
||||||
|
|
||||||
int x = TileX(this->wp->xy) * TILE_SIZE;
|
ScrollWindowToTile(this->GetCenterTile(), this, true);
|
||||||
int y = TileY(this->wp->xy) * TILE_SIZE;
|
|
||||||
ScrollWindowTo(x, y, -1, this, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnResize()
|
virtual void OnResize()
|
||||||
|
|
Loading…
Reference in New Issue