OpenTTD
Data Structures | Typedefs | Enumerations | Functions | Variables
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 "widgets/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 "widgets/station_widget.h"
#include "table/strings.h"
#include <set>
#include <vector>
#include "safeguards.h"

Go to the source code of this file.

Data Structures

class  CompanyStationsWindow
 The list of stations per company. More...
 
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

typedef GUIList< const Station * > GUIStationList
 
typedef std::set< CargoDataEntry *, CargoSorterCargoDataSet
 

Enumerations

enum  SortOrder { SO_DESCENDING, SO_ASCENDING }
 
enum  CargoSortType {
  ST_AS_GROUPING, ST_COUNT, ST_STATION_STRING, ST_STATION_ID,
  ST_CARGO_ID
}
 

Functions

int DrawStationCoverageAreaText (int left, int right, int top, StationCoverageType sct, int rad, bool supplies)
 Calculates and draws the accepted or supplied cargo around the selected tile(s) More...
 
void CheckRedrawStationCoverage (const Window *w)
 Check whether we need to redraw the station coverage text. More...
 
static void StationsWndShowStationRating (int left, int right, int y, CargoID type, uint amount, byte rating)
 Draw small boxes of cargo amount and ratings data at the given coordinates. More...
 
static NWidgetBaseCargoWidgets (int *biggest_index)
 Make a horizontal row of cargo buttons, starting at widget WID_STL_CARGOSTART. More...
 
void ShowCompanyStations (CompanyID company)
 Opens window with list of company's stations. More...
 
static void DrawCargoIcons (CargoID i, uint waiting, int left, int right, int y)
 Draws icons of waiting cargo in the StationView window. More...
 
void ShowStationViewWindow (StationID station)
 Opens StationViewWindow for given station. More...
 
template<class T >
static bool AddNearbyStation (TileIndex tile, void *user_data)
 Add station on this tile to _stations_nearby_list if it's fully within the station spread. More...
 
template<class T >
static const T * FindStationsNearby (TileArea ta, bool distant_join)
 Circulate around the to-be-built station to find stations we could join. More...
 
template<class T >
static bool StationJoinerNeeded (const CommandContainer &cmd, TileArea ta)
 Check whether we need to show the station selection window. More...
 
template<class T >
void ShowSelectBaseStationIfNeeded (const CommandContainer &cmd, TileArea ta)
 Show the station selection window when needed. More...
 
void ShowSelectStationIfNeeded (const CommandContainer &cmd, TileArea ta)
 Show the station selection window when needed. More...
 
void ShowSelectWaypointIfNeeded (const CommandContainer &cmd, TileArea ta)
 Show the waypoint selection window when needed. More...
 

Variables

static const NWidgetPart _nested_company_stations_widgets []
 
static WindowDesc _company_stations_desc (WDP_AUTO, "list_stations", 358, 162, WC_STATION_LIST, WC_NONE, 0, _nested_company_stations_widgets, lengthof(_nested_company_stations_widgets))
 
static const NWidgetPart _nested_station_view_widgets []
 
static WindowDesc _station_view_desc (WDP_AUTO, "view_station", 249, 117, WC_STATION_VIEW, WC_NONE, 0, _nested_station_view_widgets, lengthof(_nested_station_view_widgets))
 
static SmallVector< TileAndStation, 8 > _deleted_stations_nearby
 
static SmallVector< StationID, 8 > _stations_nearby_list
 
static const NWidgetPart _nested_select_station_widgets []
 
static WindowDesc _select_station_desc (WDP_AUTO, "build_station_join", 200, 180, WC_SELECT_STATION, WC_NONE, WDF_CONSTRUCTION, _nested_select_station_widgets, lengthof(_nested_select_station_widgets))
 

Detailed Description

The GUI for stations.

Definition in file station_gui.cpp.

Enumeration Type Documentation

◆ CargoSortType

Enumerator
ST_AS_GROUPING 

by the same principle the entries are being grouped

ST_COUNT 

by amount of cargo

ST_STATION_STRING 

by station name

ST_STATION_ID 

by station id

ST_CARGO_ID 

by cargo id

Definition at line 829 of file station_gui.cpp.

Function Documentation

◆ AddNearbyStation()

template<class T >
static bool AddNearbyStation ( TileIndex  tile,
void *  user_data 
)
static

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

Parameters
tileTile just being checked
user_dataPointer to TileArea context
Template Parameters
Tthe type of station to look for

Definition at line 2132 of file station_gui.cpp.

References SmallVector< T, S >::Append(), SmallVector< T, S >::Erase(), SmallVector< T, S >::Get(), GetStationIndex(), IsTileType(), SmallVector< T, S >::Length(), MP_STATION, and TileAndStation::tile.

◆ CargoWidgets()

static NWidgetBase* CargoWidgets ( int *  biggest_index)
static

Make a horizontal row of cargo buttons, starting at widget WID_STL_CARGOSTART.

Parameters
biggest_indexPointer to store biggest used widget number of the buttons.
Returns
Horizontal row.

Definition at line 687 of file station_gui.cpp.

References _sorted_standard_cargo_specs_size, and WWT_PANEL.

◆ 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 88 of file station_gui.cpp.

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

◆ DrawCargoIcons()

static void DrawCargoIcons ( CargoID  i,
uint  waiting,
int  left,
int  right,
int  y 
)
static

Draws icons of waiting cargo in the StationView window.

Parameters
itype of cargo
waitingnumber of waiting units
leftleft most coordinate to draw on
rightright most coordinate to draw on
yy coordinate
widththe width of the view

Definition at line 807 of file station_gui.cpp.

◆ DrawStationCoverageAreaText()

int DrawStationCoverageAreaText ( int  left,
int  right,
int  top,
StationCoverageType  sct,
int  rad,
bool  supplies 
)

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

Parameters
leftx position where the string is to be drawn
rightthe right most position to draw on
topy position 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 56 of file station_gui.cpp.

References TileVirtXY().

◆ FindStationsNearby()

template<class T >
static const T* 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 type of station to look for

Definition at line 2174 of file station_gui.cpp.

◆ ShowCompanyStations()

void ShowCompanyStations ( CompanyID  company)

Opens window with list of company's stations.

Parameters
companywhose stations' list show

Definition at line 750 of file station_gui.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID().

Referenced by MenuClickStations().

◆ ShowSelectBaseStationIfNeeded()

template<class T >
void ShowSelectBaseStationIfNeeded ( const CommandContainer cmd,
TileArea  ta 
)

Show the station selection window when needed.

If not, build the station.

Parameters
cmdCommand to build the station.
taArea to build the station in
Template Parameters
theclass to find stations for

Definition at line 2393 of file station_gui.cpp.

References _settings_client, ClientSettings::gui, GUISettings::persistent_buildingtools, and ResetObjectToPlace().

◆ ShowSelectStationIfNeeded()

void ShowSelectStationIfNeeded ( const CommandContainer cmd,
TileArea  ta 
)

Show the station selection window when needed.

If not, build the station.

Parameters
cmdCommand to build the station.
taArea to build the station in

Definition at line 2408 of file station_gui.cpp.

◆ ShowSelectWaypointIfNeeded()

void ShowSelectWaypointIfNeeded ( const CommandContainer cmd,
TileArea  ta 
)

Show the waypoint selection window when needed.

If not, build the waypoint.

Parameters
cmdCommand to build the waypoint.
taArea to build the waypoint in

Definition at line 2418 of file station_gui.cpp.

◆ ShowStationViewWindow()

void ShowStationViewWindow ( StationID  station)

Opens StationViewWindow for given station.

Parameters
stationstation which window should be opened

Definition at line 2110 of file station_gui.cpp.

◆ StationJoinerNeeded()

template<class T >
static bool StationJoinerNeeded ( const CommandContainer cmd,
TileArea  ta 
)
static

Check whether we need to show the station selection window.

Parameters
cmdCommand to build the station.
taTile area of the to-be-built station
Template Parameters
Tthe type of station
Returns
whether we need to show the station selection window.

Definition at line 2359 of file station_gui.cpp.

References _ctrl_pressed, _settings_game, CommandContainer::cmd, CommandFlagsToDCFlags(), StationSettings::distant_join_stations, DoCommand(), CommandCost::Failed(), FindWindowById(), GetCommandFlags(), GameSettings::station, UpdateTileSelection(), and WC_SELECT_STATION.

◆ StationsWndShowStationRating()

static void StationsWndShowStationRating ( int  left,
int  right,
int  y,
CargoID  type,
uint  amount,
byte  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
typeCargo type
amountCargo amount
ratingratings data for that particular cargo
Note
Each cargo-bar is 16 pixels wide and 6 pixels high
Each rating 14 pixels wide and 1 pixel high and is 1 pixel below the cargo-bar

< number of units to show station as 'full'

< rating needed so it is shown as 'full'

Definition at line 111 of file station_gui.cpp.

Variable Documentation

◆ _nested_select_station_widgets

const NWidgetPart _nested_select_station_widgets[]
static
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_JS_CAPTION), SetDataTip(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),
}
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:930
Horizontal container.
Definition: widget_type.h:75
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
Close box (at top-left of a window)
Definition: widget_type.h:69
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:65
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
Simple depressed panel.
Definition: widget_type.h:50
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1114
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
Vertical container.
Definition: widget_type.h:77
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:999
Vertical scrollbar.
Definition: widget_type.h:84
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1095

Definition at line 2217 of file station_gui.cpp.