# 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 "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 "table/strings.h"`
`#include "table/sprites.h"`

Go to the source code of this file.

## Data Structures
class | CompanyStationsWindow
| The list of stations per company. More...
struct | CargoData
struct | StationViewWindow
| The StationView window. 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::list< CargoData > | CargoDataList
## Enumerations
enum | StationListWidgets { SLW_CAPTION, SLW_LIST, SLW_SCROLLBAR, SLW_TRAIN, SLW_TRUCK, SLW_BUS, SLW_AIRPLANE, SLW_SHIP, SLW_FACILALL, SLW_NOCARGOWAITING, SLW_CARGOALL, SLW_SORTBY, SLW_SORTDROPBTN, SLW_CARGOSTART }
| Enum for CompanyStations, referring to _company_stations_widgets. More...
enum | JoinStationWidgets { JSW_WIDGET_CAPTION, JSW_PANEL, JSW_SCROLLBAR }
## Functions
static int | DrawCargoListText (uint32 cargo_mask, const Rect &r, StringID prefix)
| Draw a (multi)line of cargos seperated by commas, and prefixed with a string.
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).
void | CheckRedrawStationCoverage (const Window *w)
| Check whether we need to redraw the station coverage text.
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.
static NWidgetBase * | CargoWidgets (int *biggest_index)
| Make a horizontal row of cargo buttons, starting at widget SLW_CARGOSTART.
void | ShowCompanyStations (CompanyID company)
| Opens window with list of company's stations.
static void | DrawCargoIcons (CargoID i, uint waiting, int left, int right, int y)
| Draws icons of waiting cargo in the StationView window.
void | ShowStationViewWindow (StationID station)
| Opens StationViewWindow for given station.
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.
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.
template<class T >
static bool | StationJoinerNeeded (CommandContainer cmd, TileArea ta)
| Check whether we need to show the station selection window.
template<class T >
void | ShowSelectBaseStationIfNeeded (CommandContainer cmd, TileArea ta)
| Show the station selection window when needed.
void | ShowSelectStationIfNeeded (CommandContainer cmd, TileArea ta)
| Show the station selection window when needed.
void | ShowSelectWaypointIfNeeded (CommandContainer cmd, TileArea ta)
| Show the waypoint selection window when needed.
## Variables
static const NWidgetPart | _nested_company_stations_widgets []
static const WindowDesc | _company_stations_desc (WDP_AUTO, 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 const WindowDesc | _station_view_desc (WDP_AUTO, 249, 110, WC_STATION_VIEW, WC_NONE, WDF_UNCLICK_BUTTONS, _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 const WindowDesc | _select_station_desc (WDP_AUTO, 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

enum StationListWidgets

Enum for CompanyStations, referring to _company_stations_widgets.

Enumerator:

  SLW_CAPTION | Window caption.
  SLW_LIST | The main panel, list of stations.
  SLW_SCROLLBAR | Scrollbar next to the main panel.
  SLW_TRAIN | 'TRAIN' button - list only facilities where is a railroad station
  SLW_TRUCK | 'TRUCK' button - list only facilities where is a truck stop
  SLW_BUS | 'BUS' button - list only facilities where is a bus stop
  SLW_AIRPLANE | 'AIRPLANE' button - list only facilities where is an airport
  SLW_SHIP | 'SHIP' button - list only facilities where is a dock
  SLW_FACILALL | 'ALL' button - list all facilities
  SLW_NOCARGOWAITING | 'NO' button - list stations where no cargo is waiting
  SLW_CARGOALL | 'ALL' button - list all stations
  SLW_SORTBY | 'Sort by' button - reverse sort direction
  SLW_SORTDROPBTN | Dropdown button.
  SLW_CARGOSTART | Widget numbers used for list of cargo types (not present in _company_stations_widgets).

Definition at line 179 of file station_gui.cpp.

## Function Documentation

template<class T >

static bool AddNearbyStation | ( | TileIndex | tile,
|  | void * | user_data |
| ) |  |  | `[inline, static]`

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

Parameters:

  | tile | Tile just being checked
  | user_data | Pointer to TileArea context

Template Parameters:

  | T | the type of station to look for

Definition at line 1250 of file station_gui.cpp.

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

static NWidgetBase* CargoWidgets | ( | int * | biggest_index | ) | `[static]`

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

Parameters:

  | biggest_index | Pointer to store biggest used widget number of the buttons.

Returns:
  Horizontal row.

Definition at line 739 of file station_gui.cpp.

References NWidgetContainer::Add(), CargoSpec::Get(), CargoSpec::IsValid(), NWidgetCore::SetDataTip(), NWidgetResizeBase::SetFill(), NWidgetResizeBase::SetMinimalSize(), NWidgetResizeBase::SetResize(), SLW_CARGOSTART, WWT_EMPTY, and WWT_PANEL.

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:

  | w | the window to check.

Definition at line 118 of file station_gui.cpp.

References Window::SetDirty().

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

static void DrawCargoIcons | ( | CargoID | i,
|  | uint | waiting,
|  | int | left,
|  | int | right,
|  | int | y |
| ) |  |  | `[static]`

Draws icons of waiting cargo in the StationView window.

Parameters:

  | i | type of cargo
  | waiting | number of waiting units
  | left | left most coordinate to draw on
  | right | right most coordinate to draw on
  | y | y coordinate
  | width | the width of the view

Definition at line 854 of file station_gui.cpp.

References _dynlang, DrawSprite(), CargoSpec::Get(), CargoSpec::GetCargoIcon(), min(), TD_RTL, and DynamicLanguages::text_dir.

Referenced by StationViewWindow::DrawWaitingCargo().

static int DrawCargoListText | ( | uint32 | cargo_mask,
|  | const Rect & | r,
|  | StringID | prefix |
| ) |  |  | `[static]`

Draw a (multi)line of cargos seperated by commas, and prefixed with a string.

Parameters:

  | cargo_mask | Mask of cargos to include in the list.
  | r | Rectangle to draw the cargos in.
  | prefix | String to use as prefix for the list of cargos.

Returns:
  Bottom position of the last line used for drawing the cargos.

Definition at line 42 of file station_gui.cpp.

References DrawStringMultiLine(), endof, CargoSpec::Get(), HasBit(), lastof, NUM_CARGO, and SetDParamStr().

Referenced by StationViewWindow::DrawAcceptedCargo(), and 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:

  | left | x position where the string is to be drawn
  | right | the right most position to draw on
  | top | y position where the string is to be drawn
  | sct | which type of cargo is to be displayed (passengers/non-passengers)
  | rad | radius around selected tile(s) to be searched
  | supplies | if supplied cargos should be drawn, else accepted cargos

Returns:
  Returns the y value below the string that was drawn

Definition at line 84 of file station_gui.cpp.

References CC_PASSENGERS, DrawCargoListText(), GetAcceptanceAroundTiles(), GetProductionAroundTiles(), IsCargoInClass(), MapSize(), NUM_CARGO, SCT_ALL, SCT_NON_PASSENGERS_ONLY, SCT_PASSENGERS_ONLY, SetBit(), and TILE_SIZE.

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

template<class T >

static const T* FindStationsNearby | ( | TileArea | ta,
|  | bool | distant_join |
| ) |  |  | `[inline, 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:

  | ta | Base tile area of the to-be-built station
  | distant_join | Search for adjacent stations (false) or stations fully within station spread

Template Parameters:

  | T | the type of station to look for

Definition at line 1292 of file station_gui.cpp.

References _settings_game, SmallVector< T, S >::Append(), CircularTileSearch(), SmallVector< T, S >::Clear(), DIR_N, DistanceMax(), GetStationIndex(), TileArea::h, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, IsInsideBS(), BaseStation::IsInUse(), IsTileType(), MapSize(), max(), min(), MP_STATION, BaseStation::owner, TileAndStation::station, GameSettings::station, StationSettings::station_spread, TileAndStation::tile, TileArea::tile, TILE_ADD, TILE_ADDXY, TILE_AREA_LOOP, TileOffsByDir(), TileX(), TileY(), TileArea::w, and BaseStation::xy.

void ShowCompanyStations | ( | CompanyID | company | ) |

Opens window with list of company's stations.

Parameters:

  | company | whose stations' list show

Definition at line 810 of file station_gui.cpp.

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

Referenced by MainToolbarWindow::OnKeyPress().

template<class T >

void ShowSelectBaseStationIfNeeded | ( | CommandContainer | cmd,
|  | TileArea | ta |
| ) |  |  | `[inline]`

Show the station selection window when needed.

If not, build the station.

Parameters:

  | cmd | Command to build the station.
  | ta | Area to build the station in

Template Parameters:

  | the | class to find stations for

Definition at line 1515 of file station_gui.cpp.

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

void ShowSelectStationIfNeeded | ( | CommandContainer | cmd,
|  | TileArea | ta |
| ) |  |  |

Show the station selection window when needed.

If not, build the station.

Parameters:

  | cmd | Command to build the station.
  | ta | Area to build the station in

Definition at line 1531 of file station_gui.cpp.

void ShowSelectWaypointIfNeeded | ( | CommandContainer | cmd,
|  | TileArea | ta |
| ) |  |  |

Show the waypoint selection window when needed.

If not, build the waypoint.

Parameters:

  | cmd | Command to build the waypoint.
  | ta | Area to build the waypoint in

Definition at line 1541 of file station_gui.cpp.

Referenced by BuildRailToolbarWindow::OnPlaceMouseUp().

void ShowStationViewWindow | ( | StationID | station | ) |

Opens StationViewWindow for given station.

Parameters:

  | station | station which window should be opened

Definition at line 1228 of file station_gui.cpp.

template<class T >

static bool StationJoinerNeeded | ( | CommandContainer | cmd,
|  | TileArea | ta |
| ) |  |  | `[inline, static]`

Check whether we need to show the station selection window.

Parameters:

  | cmd | Command to build the station.
  | ta | Tile area of the to-be-built station

Template Parameters:

  | T | the type of station

Returns:
  whether we need to show the station selection window.

Definition at line 1479 of file station_gui.cpp.

References _ctrl_pressed, _settings_game, StationSettings::adjacent_stations, CommandContainer::cmd, CommandFlagsToDCFlags(), StationSettings::distant_join_stations, DoCommand(), CommandCost::Failed(), FindWindowById(), GetCommandFlags(), SmallVector< T, S >::Length(), GameSettings::station, and UpdateTileSelection().

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:

  | left | left most coordinate to draw the box at
  | right | right most coordinate to draw the box at
  | y | coordinate to draw the box at
  | type | Cargo type
  | amount | Cargo amount
  | rating | ratings 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 141 of file station_gui.cpp.

References CargoSpec::abbrev, DrawString(), FS_SMALL, CargoSpec::Get(), GetCharacterHeight(), GfxFillRect(), CargoSpec::IsValid(), and minu().

Referenced by CompanyStationsWindow::DrawWidget().

## Variable Documentation

const NWidgetPart _nested_select_station_widgets[]`[static]`

Initial value:

     {
      NWidget(NWID_HORIZONTAL),
        NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
        NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, JSW_WIDGET_CAPTION), SetDataTip(STR_JOIN_STATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
      EndContainer(),
      NWidget(NWID_HORIZONTAL),
        NWidget(WWT_PANEL, COLOUR_DARK_GREEN, JSW_PANEL), SetResize(1, 0), EndContainer(),
        NWidget(NWID_VERTICAL),
          NWidget(WWT_SCROLLBAR, COLOUR_DARK_GREEN, JSW_SCROLLBAR),
          NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
        EndContainer(),
      EndContainer(),
    }

Definition at line 1341 of file station_gui.cpp.

const NWidgetPart _nested_station_view_widgets[]`[static]`

Initial value:

     {
      NWidget(NWID_HORIZONTAL),
        NWidget(WWT_CLOSEBOX, COLOUR_GREY),
        NWidget(WWT_CAPTION, COLOUR_GREY, SVW_CAPTION), SetDataTip(STR_STATION_VIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
        NWidget(WWT_SHADEBOX, COLOUR_GREY),
        NWidget(WWT_STICKYBOX, COLOUR_GREY),
      EndContainer(),
      NWidget(NWID_HORIZONTAL),
        NWidget(WWT_PANEL, COLOUR_GREY, SVW_WAITING), SetMinimalSize(237, 52), SetResize(1, 10), EndContainer(),
        NWidget(WWT_SCROLLBAR, COLOUR_GREY, SVW_SCROLLBAR),
      EndContainer(),
      NWidget(WWT_PANEL, COLOUR_GREY, SVW_ACCEPTLIST), SetMinimalSize(249, 32), SetResize(1, 0), EndContainer(),
      NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
        NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SVW_LOCATION), SetMinimalSize(60, 12), SetResize(1, 0), SetFill(1, 1),
            SetDataTip(STR_BUTTON_LOCATION, STR_STATION_VIEW_CENTER_TOOLTIP),
        NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SVW_ACCEPTS), SetMinimalSize(61, 12), SetResize(1, 0), SetFill(1, 1),
            SetDataTip(STR_STATION_VIEW_RATINGS_BUTTON, STR_STATION_VIEW_RATINGS_TOOLTIP),
        NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SVW_RENAME), SetMinimalSize(60, 12), SetResize(1, 0), SetFill(1, 1),
            SetDataTip(STR_BUTTON_RENAME, STR_STATION_VIEW_RENAME_TOOLTIP),
        NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SVW_TRAINS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_TRAIN, STR_STATION_VIEW_SCHEDULED_TRAINS_TOOLTIP),
        NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SVW_ROADVEHS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_LORRY, STR_STATION_VIEW_SCHEDULED_ROAD_VEHICLES_TOOLTIP),
        NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SVW_PLANES),  SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_PLANE, STR_STATION_VIEW_SCHEDULED_AIRCRAFT_TOOLTIP),
        NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SVW_SHIPS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_SHIP, STR_STATION_VIEW_SCHEDULED_SHIPS_TOOLTIP),
        NWidget(WWT_RESIZEBOX, COLOUR_GREY),
      EndContainer(),
    }

Definition at line 817 of file station_gui.cpp.