OpenTTD Source 20260208-master-g43af8e94d0
station_gui.cpp File Reference

The GUI for stations. More...

#include "stdafx.h"
#include "debug.h"
#include "gui.h"
#include "textbuf_gui.h"
#include "company_func.h"
#include "command_func.h"
#include "vehicle_gui.h"
#include "cargotype.h"
#include "station_gui.h"
#include "strings_func.h"
#include "string_func.h"
#include "window_func.h"
#include "viewport_func.h"
#include "dropdown_type.h"
#include "dropdown_func.h"
#include "station_base.h"
#include "waypoint_base.h"
#include "tilehighlight_func.h"
#include "company_base.h"
#include "sortlist_type.h"
#include "core/geometry_func.hpp"
#include "vehiclelist.h"
#include "town.h"
#include "linkgraph/linkgraph.h"
#include "zoom_func.h"
#include "station_cmd.h"
#include "widgets/station_widget.h"
#include "widgets/misc_widget.h"
#include "table/strings.h"
#include "dropdown_common_type.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  StationTypeFilter
struct  GenericWaypointTypeFilter< ROAD, TILE_TYPE >
class  CompanyStationsWindow
 The list of stations per company. More...
struct  CompanyStationsWindow::FilterState
class  CargoSorter
class  CargoDataEntry
 A cargo data entry representing one possible row in the station view window's top part. More...
struct  StationViewWindow
 The StationView window. More...
struct  StationViewWindow::RowDisplay
 A row being displayed in the cargo view (as opposed to being "hidden" behind a plus sign). More...
struct  TileAndStation
 Struct containing TileIndex and StationID. More...
struct  SelectStationWindow< T >
 Window for selecting stations/waypoints to (distant) join to. More...

Typedefs

using RailWaypointTypeFilter = GenericWaypointTypeFilter<false, TileType::Railway>
using RoadWaypointTypeFilter = GenericWaypointTypeFilter<true, TileType::Road>
typedef GUIList< const Station *, const CargoTypes & > GUIStationList
typedef std::set< std::unique_ptr< CargoDataEntry >, CargoSorterCargoDataSet

Enumerations

enum  SortOrder : uint8_t { SO_DESCENDING , SO_ASCENDING }
enum class  CargoSortType : uint8_t {
  AsGrouping , Count , StationString , StationID ,
  CargoType
}
 Ways of sorting cargo in the UI. More...

Functions

int DrawStationCoverageAreaText (const Rect &r, StationCoverageType sct, int rad, bool supplies)
 Calculates and draws the accepted or supplied cargo around the selected tile(s).
template<typename T>
void FindStationsAroundSelection ()
 Find stations adjacent to the current tile highlight area, so that existing coverage area can be drawn.
void CheckRedrawStationCoverage (const Window *w)
 Check whether we need to redraw the station coverage text.
template<typename T>
void CheckRedrawWaypointCoverage ()
void CheckRedrawRailWaypointCoverage (const Window *)
void CheckRedrawRoadWaypointCoverage (const Window *)
static void StationsWndShowStationRating (int left, int right, int y, CargoType cargo, uint amount, uint8_t rating)
 Draw small boxes of cargo amount and ratings data at the given coordinates.
void ShowCompanyStations (CompanyID company)
 Opens window with list of company's stations.
void ShowStationViewWindow (StationID station)
 Opens StationViewWindow for given station.
template<class T>
static void AddNearbyStation (TileIndex tile, TileArea *ctx)
 Add station on this tile to _stations_nearby_list if it's fully within the station spread.
template<class T>
static void FindStationsNearby (TileArea ta, bool distant_join)
 Circulate around the to-be-built station to find stations we could join.
static bool StationJoinerNeeded (const StationPickerCmdProc &proc)
 Check whether we need to show the station selection window.
template<class T>
void ShowSelectBaseStationIfNeeded (TileArea ta, StationPickerCmdProc &&proc)
 Show the station selection window when needed.
void ShowSelectStationIfNeeded (TileArea ta, StationPickerCmdProc proc)
 Show the station selection window when needed.
void ShowSelectRailWaypointIfNeeded (TileArea ta, StationPickerCmdProc proc)
 Show the rail waypoint selection window when needed.
void ShowSelectRoadWaypointIfNeeded (TileArea ta, StationPickerCmdProc proc)
 Show the road waypoint selection window when needed.

Variables

static constexpr std::initializer_list< NWidgetPart_nested_company_stations_widgets
static WindowDesc _company_stations_desc (WDP_AUTO, "list_stations", 358, 162, WC_STATION_LIST, WC_NONE, {}, _nested_company_stations_widgets)
static constexpr std::initializer_list< NWidgetPart_nested_station_view_widgets
static WindowDesc _station_view_desc (WDP_AUTO, "view_station", 249, 117, WC_STATION_VIEW, WC_NONE, {}, _nested_station_view_widgets)
static std::vector< TileAndStation_deleted_stations_nearby
static std::vector< StationID > _stations_nearby_list
static constexpr std::initializer_list< NWidgetPart_nested_select_station_widgets
static WindowDesc _select_station_desc (WDP_AUTO, "build_station_join", 200, 180, WC_SELECT_STATION, WC_NONE, WindowDefaultFlag::Construction, _nested_select_station_widgets)

Detailed Description

The GUI for stations.

Definition in file station_gui.cpp.

Typedef Documentation

◆ CargoDataSet

typedef std::set<std::unique_ptr<CargoDataEntry>, CargoSorter> CargoDataSet

Definition at line 890 of file station_gui.cpp.

◆ GUIStationList

typedef GUIList<const Station*, const CargoTypes &> GUIStationList

Definition at line 256 of file station_gui.cpp.

◆ RailWaypointTypeFilter

using RailWaypointTypeFilter = GenericWaypointTypeFilter<false, TileType::Railway>

Definition at line 66 of file station_gui.cpp.

◆ RoadWaypointTypeFilter

using RoadWaypointTypeFilter = GenericWaypointTypeFilter<true, TileType::Road>

Definition at line 67 of file station_gui.cpp.

Enumeration Type Documentation

◆ CargoSortType

enum class CargoSortType : uint8_t
strong

Ways of sorting cargo in the UI.

Enumerator
AsGrouping 

by the same principle the entries are being grouped

Count 

by amount of cargo

StationString 

by station name

StationID 

by station id

CargoType 

by cargo type

Definition at line 862 of file station_gui.cpp.

◆ SortOrder

enum SortOrder : uint8_t

Definition at line 854 of file station_gui.cpp.

Function Documentation

◆ AddNearbyStation()

template<class T>
void AddNearbyStation ( TileIndex tile,
TileArea * ctx )
static

Add station on this tile to _stations_nearby_list if it's fully within the station spread.

Parameters
tileTile just being checked
ctxPointer to TileArea context
Template Parameters
Tthe station filter type

Definition at line 2198 of file station_gui.cpp.

References _local_company, GetStationIndex(), OrthogonalTileArea::h, IsTileType(), BaseStation::owner, BaseStation::rect, Station, CommandCost::Succeeded(), OrthogonalTileArea::tile, and OrthogonalTileArea::w.

Referenced by FindStationsNearby().

◆ CheckRedrawRailWaypointCoverage()

void CheckRedrawRailWaypointCoverage ( const Window * w)

Definition at line 197 of file station_gui.cpp.

◆ CheckRedrawRoadWaypointCoverage()

void CheckRedrawRoadWaypointCoverage ( const Window * w)

Definition at line 202 of file station_gui.cpp.

◆ CheckRedrawStationCoverage()

void CheckRedrawStationCoverage ( const Window * w)

Check whether we need to redraw the station coverage text.

If it is needed actually make the window for redrawing.

Parameters
wthe window to check.

Definition at line 159 of file station_gui.cpp.

References _ctrl_pressed, _settings_client, FindStationsAroundSelection(), HT_RECT, and Window::SetDirty().

Referenced by BuildAirportWindow::OnRealtimeTick(), BuildDocksStationWindow::OnRealtimeTick(), BuildRailStationWindow::OnRealtimeTick(), and BuildRoadStationWindow::OnRealtimeTick().

◆ CheckRedrawWaypointCoverage()

template<typename T>
void CheckRedrawWaypointCoverage ( )

Definition at line 179 of file station_gui.cpp.

◆ DrawStationCoverageAreaText()

int DrawStationCoverageAreaText ( const Rect & r,
StationCoverageType sct,
int rad,
bool supplies )

Calculates and draws the accepted or supplied cargo around the selected tile(s).

Parameters
rRect where the string is to be drawn.
sctwhich type of cargo is to be displayed (passengers/non-passengers)
radradius around selected tile(s) to be searched
suppliesif supplied cargoes should be drawn, else accepted cargoes
Returns
Returns the y value below the string that was drawn

Definition at line 77 of file station_gui.cpp.

References DrawStringMultiLine(), GetAcceptanceAroundTiles(), GetProductionAroundTiles(), GetString(), HT_RECT, IsCargoInClass(), NUM_CARGO, Passengers, Rect, SCT_ALL, SCT_NON_PASSENGERS_ONLY, SCT_PASSENGERS_ONLY, SetBit(), Map::Size(), TILE_SIZE, and TileVirtXY().

Referenced by BuildAirportWindow::OnPaint(), BuildDocksStationWindow::OnPaint(), BuildRailStationWindow::OnPaint(), and BuildRoadStationWindow::OnPaint().

◆ FindStationsAroundSelection()

template<typename T>
void FindStationsAroundSelection ( )

Find stations adjacent to the current tile highlight area, so that existing coverage area can be drawn.

Definition at line 108 of file station_gui.cpp.

References _ctrl_pressed, _local_company, GetTileOwner(), OrthogonalTileArea::h, IsTileType(), Map::MaxX(), Map::MaxY(), Station, OrthogonalTileArea::tile, TILE_SIZE, TileVirtXY(), TileX(), TileXY(), TileY(), and OrthogonalTileArea::w.

Referenced by CheckRedrawStationCoverage().

◆ FindStationsNearby()

template<class T>
void FindStationsNearby ( TileArea ta,
bool distant_join )
static

Circulate around the to-be-built station to find stations we could join.

Make sure that only stations are returned where joining wouldn't exceed station spread and are our own station.

Parameters
taBase tile area of the to-be-built station
distant_joinSearch for adjacent stations (false) or stations fully within station spread
Template Parameters
Tthe station filter type, for stations to look for

Definition at line 2236 of file station_gui.cpp.

References _local_company, _settings_game, AddNearbyStation(), DIR_N, DistanceMax(), OrthogonalTileArea::h, IsInsideBS(), OrthogonalTileArea::tile, TileAddByDir(), TileAddXY(), TileX(), TileY(), and OrthogonalTileArea::w.

Referenced by SelectStationWindow< T >::OnInvalidateData(), and ShowSelectBaseStationIfNeeded().

◆ ShowCompanyStations()

void ShowCompanyStations ( CompanyID company)

Opens window with list of company's stations.

Parameters
companywhose stations' list show

Definition at line 808 of file station_gui.cpp.

References AllocateWindowDescFront().

Referenced by MenuClickStations(), and MainToolbarWindow::OnHotkey().

◆ ShowSelectBaseStationIfNeeded()

template<class T>
void ShowSelectBaseStationIfNeeded ( TileArea ta,
StationPickerCmdProc && proc )

Show the station selection window when needed.

If not, build the station.

Parameters
taArea to build the station in
procCallback to check whether we can build.
Template Parameters
Tthe class to find stations for

Definition at line 2458 of file station_gui.cpp.

References _settings_client, FindStationsNearby(), ResetObjectToPlace(), and StationJoinerNeeded().

Referenced by ShowSelectRailWaypointIfNeeded(), ShowSelectRoadWaypointIfNeeded(), and ShowSelectStationIfNeeded().

◆ ShowSelectRailWaypointIfNeeded()

void ShowSelectRailWaypointIfNeeded ( TileArea ta,
StationPickerCmdProc proc )

Show the rail waypoint selection window when needed.

If not, build the waypoint.

Parameters
taArea to build the waypoint in
procFunction called to execute the build command.

Definition at line 2484 of file station_gui.cpp.

References ShowSelectBaseStationIfNeeded().

Referenced by BuildRailToolbarWindow::OnPlaceMouseUp().

◆ ShowSelectRoadWaypointIfNeeded()

void ShowSelectRoadWaypointIfNeeded ( TileArea ta,
StationPickerCmdProc proc )

Show the road waypoint selection window when needed.

If not, build the waypoint.

Parameters
taArea to build the waypoint in
procFunction called to execute the build command.

Definition at line 2494 of file station_gui.cpp.

References ShowSelectBaseStationIfNeeded().

Referenced by BuildRoadToolbarWindow::OnPlaceMouseUp().

◆ ShowSelectStationIfNeeded()

void ShowSelectStationIfNeeded ( TileArea ta,
StationPickerCmdProc proc )

Show the station selection window when needed.

If not, build the station.

Parameters
taArea to build the station in
procFunction called to execute the build command.

Definition at line 2474 of file station_gui.cpp.

References ShowSelectBaseStationIfNeeded().

Referenced by BuildDocksToolbarWindow::OnPlaceObject(), PlaceAirport(), PlaceRail_Station(), and PlaceRoadStop().

◆ ShowStationViewWindow()

void ShowStationViewWindow ( StationID station)

Opens StationViewWindow for given station.

Parameters
stationstation which window should be opened

Definition at line 2176 of file station_gui.cpp.

References AllocateWindowDescFront().

◆ StationJoinerNeeded()

bool StationJoinerNeeded ( const StationPickerCmdProc & proc)
static

Check whether we need to show the station selection window.

Parameters
procCallback to check whether we can build.
Returns
whether we need to show the station selection window.

Definition at line 2430 of file station_gui.cpp.

References _ctrl_pressed, _settings_game, Window::Close(), FindWindowById(), UpdateTileSelection(), and WC_SELECT_STATION.

Referenced by ShowSelectBaseStationIfNeeded().

◆ StationsWndShowStationRating()

void StationsWndShowStationRating ( int left,
int right,
int y,
CargoType cargo,
uint amount,
uint8_t rating )
static

Draw small boxes of cargo amount and ratings data at the given coordinates.

If amount exceeds 576 units, it is shown 'full', same goes for the rating: at above 90% orso (224) it is also 'full'

Parameters
leftleft most coordinate to draw the box at
rightright most coordinate to draw the box at
ycoordinate to draw the box at
cargoCargo type
amountCargo amount
ratingratings data for that particular cargo

< number of units to show station as 'full'

< rating needed so it is shown as 'full'

Definition at line 219 of file station_gui.cpp.

References CargoSpec::abbrev, DrawString(), FS_SMALL, CargoSpec::Get(), GetCharacterHeight(), GetContrastColour(), GfxFillRect(), CargoSpec::IsValid(), PC_GREEN, PC_RED, SA_CENTER, and ScaleGUITrad().

Referenced by CompanyStationsWindow::DrawWidget().

Variable Documentation

◆ _deleted_stations_nearby

std::vector<TileAndStation> _deleted_stations_nearby
static

Definition at line 2187 of file station_gui.cpp.

◆ _nested_company_stations_widgets

std::initializer_list<NWidgetPart> _nested_company_stations_widgets
staticconstexpr

Definition at line 763 of file station_gui.cpp.

◆ _nested_select_station_widgets

std::initializer_list<NWidgetPart> _nested_select_station_widgets
staticconstexpr
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_JS_CAPTION), SetStringTip(STR_JOIN_STATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_JS_PANEL), SetResize(1, 0), SetScrollbar(WID_JS_SCROLLBAR), EndContainer(),
NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_JS_SCROLLBAR),
NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
}
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
@ WWT_CAPTION
Window caption (window title between closebox and stickybox).
Definition widget_type.h:52
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
@ WWT_CLOSEBOX
Close box (at top-left of a window).
Definition widget_type.h:60
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window).
Definition widget_type.h:59
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX).
Definition widget_type.h:56

Definition at line 2276 of file station_gui.cpp.

◆ _nested_station_view_widgets

std::initializer_list<NWidgetPart> _nested_station_view_widgets
staticconstexpr

Definition at line 815 of file station_gui.cpp.

◆ _stations_nearby_list

std::vector<StationID> _stations_nearby_list
static

Definition at line 2188 of file station_gui.cpp.