OpenTTD Source 20241224-master-gf74b0cf984
rail_gui.cpp File Reference

File for dealing with rail construction user interface More...

#include "stdafx.h"
#include "gui.h"
#include "station_base.h"
#include "waypoint_base.h"
#include "window_gui.h"
#include "station_gui.h"
#include "terraform_gui.h"
#include "viewport_func.h"
#include "command_func.h"
#include "waypoint_func.h"
#include "newgrf_station.h"
#include "company_base.h"
#include "strings_func.h"
#include "window_func.h"
#include "sound_func.h"
#include "company_func.h"
#include "dropdown_type.h"
#include "dropdown_func.h"
#include "tunnelbridge.h"
#include "tilehighlight_func.h"
#include "spritecache.h"
#include "core/geometry_func.hpp"
#include "hotkeys.h"
#include "engine_base.h"
#include "vehicle_func.h"
#include "zoom_func.h"
#include "rail_gui.h"
#include "station_cmd.h"
#include "tunnelbridge_cmd.h"
#include "waypoint_cmd.h"
#include "rail_cmd.h"
#include "timer/timer.h"
#include "timer/timer_game_calendar.h"
#include "picker_gui.h"
#include "station_map.h"
#include "tunnelbridge_map.h"
#include "widgets/rail_widget.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  WaypointPickerSelection
 
struct  StationPickerSelection
 
struct  BuildRailToolbarWindow
 Rail toolbar management class. More...
 
class  StationPickerCallbacks
 
struct  BuildRailStationWindow
 
struct  BuildSignalWindow
 
struct  BuildRailDepotWindow
 
class  WaypointPickerCallbacks
 
struct  BuildRailWaypointWindow
 

Functions

static void HandleStationPlacement (TileIndex start, TileIndex end)
 
static void ShowBuildTrainDepotPicker (Window *parent)
 
static void ShowBuildWaypointPicker (Window *parent)
 
static WindowShowStationBuilder (Window *parent)
 Open station build window.
 
static void ShowSignalBuilder (Window *parent)
 Open the signal selection window.
 
static bool IsStationAvailable (const StationSpec *statspec)
 Check whether a station type can be build.
 
void CcPlaySound_CONSTRUCTION_RAIL (Commands, const CommandCost &result, TileIndex tile)
 
static void GenericPlaceRail (TileIndex tile, Track track)
 
static void PlaceExtraDepotRail (TileIndex tile, DiagDirection dir, Track track)
 Try to add an additional rail-track at the entrance of a depot.
 
void CcRailDepot (Commands, const CommandCost &result, TileIndex tile, RailType, DiagDirection dir)
 
static void PlaceRail_Waypoint (TileIndex tile)
 Place a rail waypoint.
 
void CcStation (Commands, const CommandCost &result, TileIndex tile)
 
static void PlaceRail_Station (TileIndex tile)
 Place a rail station.
 
static void GenericPlaceSignals (TileIndex tile)
 Build a new signal or edit/remove a present signal, use CmdBuildSingleSignal() or CmdRemoveSingleSignal() in rail_cmd.cpp.
 
static void PlaceRail_Bridge (TileIndex tile, Window *w)
 Start placing a rail bridge.
 
void CcBuildRailTunnel (Commands, const CommandCost &result, TileIndex tile)
 Command callback for building a tunnel.
 
static void ToggleRailButton_Remove (Window *w)
 Toggles state of the Remove button of Build rail toolbar.
 
static bool RailToolbar_CtrlChanged (Window *w)
 Updates the Remove button because of Ctrl state change.
 
static void BuildRailClick_Remove (Window *w)
 The "remove"-button click proc of the build-rail toolbar.
 
static void DoRailroadTrack (Track track)
 
static void HandleAutodirPlacement ()
 
static void HandleAutoSignalPlacement ()
 Build new signals or remove signals or (if only one tile marked) edit a signal.
 
WindowShowBuildRailToolbar (RailType railtype)
 Open the build rail toolbar window for a specific rail type.
 
static bool StationUsesDefaultType (const BaseStation *bst)
 Test if a station/waypoint uses the default graphics.
 
void InitializeRailGui ()
 Initialize rail building GUI settings.
 
void ReinitGuiAfterToggleElrail (bool disable)
 Re-initialize rail-build toolbar after toggling support for electric trains.
 
static void SetDefaultRailGui ()
 Set the initial (default) railtype to use.
 
void ResetSignalVariant (int32_t)
 Updates the current signal variant used in the signal GUI to the one adequate to current year.
 
void InitializeRailGUI ()
 Resets the rail GUI - sets default railtype to build and resets the signal GUI.
 
DropDownList GetRailTypeDropDownList (bool for_replacement, bool all_option)
 Create a drop down list for all the rail types of the local company.
 

Variables

static RailType _cur_railtype
 Rail type of the current build-rail toolbar.
 
static bool _remove_button_clicked
 Flag whether 'remove' toggle-button is currently enabled.
 
static DiagDirection _build_depot_direction
 Currently selected depot direction.
 
static bool _convert_signal_button
 convert signal button in the signal GUI pressed
 
static SignalVariant _cur_signal_variant
 set the signal variant (for signal GUI)
 
static SignalType _cur_signal_type
 set the signal type (for signal GUI)
 
static WaypointPickerSelection _waypoint_gui
 Settings of the waypoint picker.
 
static StationPickerSelection _station_gui
 Settings of the station picker.
 
static const Track _place_depot_extra_track [12]
 Additional pieces of track to add at the entrance of a depot.
 
static const DiagDirection _place_depot_extra_dir [12]
 Direction to check for existing track pieces.
 
static constexpr NWidgetPart _nested_build_rail_widgets []
 
static WindowDesc _build_rail_desc (WDP_ALIGN_TOOLBAR, "toolbar_rail", 0, 0, WC_BUILD_TOOLBAR, WC_NONE, WDF_CONSTRUCTION, _nested_build_rail_widgets, &BuildRailToolbarWindow::hotkeys)
 
static constexpr NWidgetPart _nested_station_builder_widgets []
 
static WindowDesc _station_builder_desc (WDP_AUTO, "build_station_rail", 0, 0, WC_BUILD_STATION, WC_BUILD_TOOLBAR, WDF_CONSTRUCTION, _nested_station_builder_widgets, &BuildRailStationWindow::hotkeys)
 High level window description of the station-build window (default & newGRF)
 
static constexpr NWidgetPart _nested_signal_builder_widgets []
 Nested widget definition of the build signal window.
 
static WindowDesc _signal_builder_desc (WDP_AUTO, nullptr, 0, 0, WC_BUILD_SIGNAL, WC_BUILD_TOOLBAR, WDF_CONSTRUCTION, _nested_signal_builder_widgets)
 Signal selection window description.
 
static constexpr NWidgetPart _nested_build_depot_widgets []
 Nested widget definition of the build rail depot window.
 
static WindowDesc _build_depot_desc (WDP_AUTO, nullptr, 0, 0, WC_BUILD_DEPOT, WC_BUILD_TOOLBAR, WDF_CONSTRUCTION, _nested_build_depot_widgets)
 
static constexpr NWidgetPart _nested_build_waypoint_widgets []
 Nested widget definition for the build NewGRF rail waypoint window.
 
static WindowDesc _build_waypoint_desc (WDP_AUTO, "build_waypoint", 0, 0, WC_BUILD_WAYPOINT, WC_BUILD_TOOLBAR, WDF_CONSTRUCTION, _nested_build_waypoint_widgets, &BuildRailWaypointWindow::hotkeys)
 
static IntervalTimer< TimerGameCalendar_check_reset_signal ({TimerGameCalendar::YEAR, TimerGameCalendar::Priority::NONE}, [](auto) { if(TimerGameCalendar::year !=_settings_client.gui.semaphore_build_before) return;ResetSignalVariant();})
 

Detailed Description

File for dealing with rail construction user interface

Definition in file rail_gui.cpp.

Function Documentation

◆ BuildRailClick_Remove()

◆ CcBuildRailTunnel()

◆ CcPlaySound_CONSTRUCTION_RAIL()

void CcPlaySound_CONSTRUCTION_RAIL ( Commands  ,
const CommandCost result,
TileIndex  tile 
)

Definition at line 94 of file rail_gui.cpp.

◆ CcRailDepot()

void CcRailDepot ( Commands  cmd,
const CommandCost result,
TileIndex  tile,
RailType  rt,
DiagDirection  dir 
)

Definition at line 140 of file rail_gui.cpp.

◆ CcStation()

void CcStation ( Commands  ,
const CommandCost result,
TileIndex  tile 
)

Definition at line 184 of file rail_gui.cpp.

◆ DoRailroadTrack()

static void DoRailroadTrack ( Track  track)
static

Definition at line 381 of file rail_gui.cpp.

◆ GenericPlaceRail()

static void GenericPlaceRail ( TileIndex  tile,
Track  track 
)
static

Definition at line 99 of file rail_gui.cpp.

◆ GenericPlaceSignals()

◆ GetRailTypeDropDownList()

DropDownList GetRailTypeDropDownList ( bool  for_replacement,
bool  all_option 
)

◆ HandleAutodirPlacement()

static void HandleAutodirPlacement ( )
static

Definition at line 392 of file rail_gui.cpp.

◆ HandleAutoSignalPlacement()

◆ HandleStationPlacement()

static void HandleStationPlacement ( TileIndex  start,
TileIndex  end 
)
static

Definition at line 932 of file rail_gui.cpp.

◆ InitializeRailGui()

◆ InitializeRailGUI()

void InitializeRailGUI ( )

Resets the rail GUI - sets default railtype to build and resets the signal GUI.

Definition at line 1996 of file rail_gui.cpp.

References _convert_signal_button, _cur_signal_type, _settings_client, GUISettings::default_signal_type, ClientSettings::gui, ResetSignalVariant(), and SetDefaultRailGui().

Referenced by AfterLoadGame().

◆ IsStationAvailable()

static bool IsStationAvailable ( const StationSpec statspec)
static

◆ PlaceExtraDepotRail()

static void PlaceExtraDepotRail ( TileIndex  tile,
DiagDirection  dir,
Track  track 
)
static

Try to add an additional rail-track at the entrance of a depot.

Parameters
tileTile to use for adding the rail-track
dirDirection to check for already present tracks
trackTrack to add
See also
CcRailDepot()

Definition at line 117 of file rail_gui.cpp.

References _cur_railtype, _settings_client, GUISettings::auto_remove_signals, DiagdirReachesTracks(), GetRailTileType(), GetTrackBits(), ClientSettings::gui, RAIL_TILE_DEPOT, and RAIL_TILE_SIGNALS.

◆ PlaceRail_Bridge()

static void PlaceRail_Bridge ( TileIndex  tile,
Window w 
)
static

Start placing a rail bridge.

Parameters
tilePosition of the first tile of the bridge.
wRail toolbar window.

Definition at line 291 of file rail_gui.cpp.

References DDSP_BUILD_BRIDGE, GetOtherTunnelBridgeEnd(), IsBridgeTile(), Window::OnPlaceMouseUp(), VPM_X_OR_Y, and VpStartPlaceSizing().

Referenced by BuildRailToolbarWindow::OnPlaceObject().

◆ PlaceRail_Station()

◆ PlaceRail_Waypoint()

static void PlaceRail_Waypoint ( TileIndex  tile)
static

◆ RailToolbar_CtrlChanged()

static bool RailToolbar_CtrlChanged ( Window w)
static

Updates the Remove button because of Ctrl state change.

Parameters
wwindow the button belongs to
Returns
true iff the remove button was changed

Definition at line 331 of file rail_gui.cpp.

References Window::IsWidgetDisabled(), Window::IsWidgetLowered(), ToggleRailButton_Remove(), WID_RAT_BUILD_NS, WID_RAT_BUILD_STATION, WID_RAT_BUILD_WAYPOINT, and WID_RAT_REMOVE.

Referenced by BuildRailToolbarWindow::OnClick(), and BuildRailToolbarWindow::OnCTRLStateChange().

◆ ReinitGuiAfterToggleElrail()

void ReinitGuiAfterToggleElrail ( bool  disable)

Re-initialize rail-build toolbar after toggling support for electric trains.

Parameters
disableBoolean whether electric trains are disabled (removed from the game)

Definition at line 1908 of file rail_gui.cpp.

References _cur_railtype, FindWindowById(), MarkWholeScreenDirty(), BuildRailToolbarWindow::ModifyRailType(), RAILTYPE_ELECTRIC, RAILTYPE_RAIL, TRANSPORT_RAIL, and WC_BUILD_TOOLBAR.

◆ ResetSignalVariant()

void ResetSignalVariant ( int32_t  )

◆ SetDefaultRailGui()

◆ ShowBuildRailToolbar()

Window * ShowBuildRailToolbar ( RailType  railtype)

Open the build rail toolbar window for a specific rail type.

If the terraform toolbar is linked to the toolbar, that window is also opened.

Parameters
railtypeRail type to open the window for
Returns
newly opened rail toolbar, or nullptr if the toolbar could not be opened.

Definition at line 918 of file rail_gui.cpp.

References _cur_railtype, _local_company, _remove_button_clicked, CloseWindowByClass(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), ValParamRailType(), and WC_BUILD_TOOLBAR.

Referenced by MenuClickBuildRail(), MainToolbarWindow::OnHotkey(), and BuildRailToolbarWindow::RailToolbarGlobalHotkeys().

◆ ShowBuildTrainDepotPicker()

static void ShowBuildTrainDepotPicker ( Window parent)
static

Definition at line 1774 of file rail_gui.cpp.

◆ ShowBuildWaypointPicker()

static void ShowBuildWaypointPicker ( Window parent)
static

Definition at line 1886 of file rail_gui.cpp.

◆ ShowSignalBuilder()

static void ShowSignalBuilder ( Window parent)
static

Open the signal selection window.

Definition at line 1696 of file rail_gui.cpp.

References _signal_builder_desc.

Referenced by BuildRailToolbarWindow::OnClick().

◆ ShowStationBuilder()

static Window * ShowStationBuilder ( Window parent)
static

Open station build window.

Definition at line 1439 of file rail_gui.cpp.

References _station_builder_desc.

Referenced by BuildRailStationWindow::BuildRailStationGlobalHotkeys(), and BuildRailToolbarWindow::OnClick().

◆ StationUsesDefaultType()

static bool StationUsesDefaultType ( const BaseStation bst)
static

Test if a station/waypoint uses the default graphics.

Parameters
bstStation to test.
Returns
true if at least one of its rail station tiles uses the default graphics.

Definition at line 960 of file rail_gui.cpp.

References GetCustomStationSpecIndex(), HasStationRail(), BaseStation::TileBelongsToRailStation(), and BaseStation::train_station.

Referenced by StationPickerCallbacks::FillUsedItems(), and WaypointPickerCallbacks::FillUsedItems().

◆ ToggleRailButton_Remove()

static void ToggleRailButton_Remove ( Window w)
static

Toggles state of the Remove button of Build rail toolbar.

Parameters
wwindow the button belongs to

Definition at line 317 of file rail_gui.cpp.

References _remove_button_clicked, CloseWindowById(), Window::IsWidgetLowered(), Window::SetWidgetDirty(), Window::ToggleWidgetLoweredState(), WC_SELECT_STATION, and WID_RAT_REMOVE.

Referenced by BuildRailClick_Remove(), BuildSignalWindow::OnClick(), and RailToolbar_CtrlChanged().

Variable Documentation

◆ _build_depot_direction

DiagDirection _build_depot_direction
static

Currently selected depot direction.

Definition at line 55 of file rail_gui.cpp.

Referenced by InitializeRailGui(), BuildRailDepotWindow::OnClick(), and BuildRailToolbarWindow::OnPlaceObject().

◆ _convert_signal_button

bool _convert_signal_button
static

◆ _cur_railtype

◆ _cur_signal_type

SignalType _cur_signal_type
static

◆ _cur_signal_variant

SignalVariant _cur_signal_variant
static

set the signal variant (for signal GUI)

Definition at line 57 of file rail_gui.cpp.

Referenced by GenericPlaceSignals(), HandleAutoSignalPlacement(), BuildSignalWindow::OnClick(), BuildSignalWindow::OnInvalidateData(), and ResetSignalVariant().

◆ _nested_build_depot_widgets

constexpr NWidgetPart _nested_build_depot_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_BUILD_DEPOT_TRAIN_ORIENTATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAD_DEPOT_NW), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAD_DEPOT_SW), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAD_DEPOT_NE), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAD_DEPOT_SE), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP),
}
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:96
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart SetPIPRatio(uint8_t ratio_pre, uint8_t ratio_inter, uint8_t ratio_post)
Widget part function for setting a pre/inter/post ratio.
@ WID_BRAD_DEPOT_SE
Build a depot with the entrance in the south east.
Definition rail_widget.h:95
@ WID_BRAD_DEPOT_NE
Build a depot with the entrance in the north east.
Definition rail_widget.h:94
@ WID_BRAD_DEPOT_SW
Build a depot with the entrance in the south west.
Definition rail_widget.h:96
@ WID_BRAD_DEPOT_NW
Build a depot with the entrance in the north west.
Definition rail_widget.h:97
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:75
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:55
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:50
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:61
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:77
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:69
@ NWID_HORIZONTAL_LTR
Horizontal container that doesn't change the order of the widgets for RTL languages.
Definition widget_type.h:76

Nested widget definition of the build rail depot window.

Definition at line 1748 of file rail_gui.cpp.

◆ _nested_build_rail_widgets

constexpr NWidgetPart _nested_build_rail_widgets[]
staticconstexpr

Definition at line 860 of file rail_gui.cpp.

◆ _nested_build_waypoint_widgets

constexpr NWidgetPart _nested_build_waypoint_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WAYPOINT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
}
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
std::unique_ptr< NWidgetBase > MakePickerClassWidgets()
Create nested widgets for the class picker widgets.
std::unique_ptr< NWidgetBase > MakePickerTypeWidgets()
Create nested widgets for the type picker widgets.
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:64
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition widget_type.h:65

Nested widget definition for the build NewGRF rail waypoint window.

Definition at line 1865 of file rail_gui.cpp.

◆ _nested_signal_builder_widgets

constexpr NWidgetPart _nested_signal_builder_widgets[]
staticconstexpr

Nested widget definition of the build signal window.

Definition at line 1620 of file rail_gui.cpp.

◆ _nested_station_builder_widgets

constexpr NWidgetPart _nested_station_builder_widgets[]
staticconstexpr

Definition at line 1376 of file rail_gui.cpp.

◆ _place_depot_extra_dir

const DiagDirection _place_depot_extra_dir[12]
static
Initial value:
= {
}
@ DIAGDIR_NE
Northeast, upper right on your monitor.
@ DIAGDIR_NW
Northwest.
@ DIAGDIR_SE
Southeast.
@ DIAGDIR_SW
Southwest.

Direction to check for existing track pieces.

Definition at line 134 of file rail_gui.cpp.

◆ _place_depot_extra_track

const Track _place_depot_extra_track[12]
static
Initial value:
= {
}
@ TRACK_Y
Track along the y-axis (north-west to south-east)
Definition track_type.h:22
@ TRACK_LOWER
Track in the lower corner of the tile (south)
Definition track_type.h:24
@ TRACK_LEFT
Track in the left corner of the tile (west)
Definition track_type.h:25
@ TRACK_RIGHT
Track in the right corner of the tile (east)
Definition track_type.h:26
@ TRACK_X
Track along the x-axis (north-east to south-west)
Definition track_type.h:21
@ TRACK_UPPER
Track in the upper corner of the tile (north)
Definition track_type.h:23

Additional pieces of track to add at the entrance of a depot.

Definition at line 127 of file rail_gui.cpp.

◆ _remove_button_clicked

◆ _station_gui

◆ _waypoint_gui