OpenTTD Source  20241121-master-g67a0fccfad
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. More...
 
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. More...
 
void CcRailDepot (Commands, const CommandCost &result, TileIndex tile, RailType, DiagDirection dir)
 
static void PlaceRail_Waypoint (TileIndex tile)
 Place a rail waypoint. More...
 
void CcStation (Commands, const CommandCost &result, TileIndex tile)
 
static void PlaceRail_Station (TileIndex tile)
 Place a rail station. More...
 
static void GenericPlaceSignals (TileIndex tile)
 Build a new signal or edit/remove a present signal, use CmdBuildSingleSignal() or CmdRemoveSingleSignal() in rail_cmd.cpp. More...
 
static void PlaceRail_Bridge (TileIndex tile, Window *w)
 Start placing a rail bridge. More...
 
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. More...
 
static bool RailToolbar_CtrlChanged (Window *w)
 Updates the Remove button because of Ctrl state change. More...
 
static void BuildRailClick_Remove (Window *w)
 The "remove"-button click proc of the build-rail toolbar. More...
 
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. More...
 
WindowShowBuildRailToolbar (RailType railtype)
 Open the build rail toolbar window for a specific rail type. More...
 
static bool StationUsesDefaultType (const BaseStation *bst)
 Test if a station/waypoint uses the default graphics. More...
 
void InitializeRailGui ()
 Initialize rail building GUI settings.
 
void ReinitGuiAfterToggleElrail (bool disable)
 Re-initialize rail-build toolbar after toggling support for electric trains. More...
 
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. More...
 

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. More...
 
static const DiagDirection _place_depot_extra_dir [12]
 Direction to check for existing track pieces. More...
 
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. More...
 
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. More...
 
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()

static void BuildRailClick_Remove ( Window w)
static

The "remove"-button click proc of the build-rail toolbar.

Parameters
wBuild-rail toolbar window
See also
BuildRailToolbarWindow::OnClick()

Definition at line 352 of file rail_gui.cpp.

References _settings_client, SoundSettings::click_beep, Window::IsWidgetDisabled(), ClientSettings::sound, ToggleRailButton_Remove(), and WID_RAT_REMOVE.

◆ GenericPlaceSignals()

static void GenericPlaceSignals ( TileIndex  tile)
static

Build a new signal or edit/remove a present signal, use CmdBuildSingleSignal() or CmdRemoveSingleSignal() in rail_cmd.cpp.

Parameters
tileThe tile where the signal will build or edit

Definition at line 233 of file rail_gui.cpp.

References GetTileTrackStatus(), TRACK_BIT_VERT, TrackStatusToTrackBits(), and TRANSPORT_RAIL.

◆ GetRailTypeDropDownList()

DropDownList GetRailTypeDropDownList ( bool  for_replacement,
bool  all_option 
)

Create a drop down list for all the rail types of the local company.

Parameters
for_replacementWhether this list is for the replacement window.
all_optionWhether to add an 'all types' item.
Returns
The populated and sorted DropDownList.

Definition at line 2011 of file rail_gui.cpp.

References _local_company, Company::avail_railtypes, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), GetCompanyRailTypes(), GetRailTypes(), and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index.

◆ HandleAutoSignalPlacement()

static void HandleAutoSignalPlacement ( )
static

Build new signals or remove signals or (if only one tile marked) edit a signal.

If one tile marked abort and use GenericPlaceSignals() else use CmdBuildSingleSignal() or CmdRemoveSingleSignal() in rail_cmd.cpp to build many signals

Definition at line 410 of file rail_gui.cpp.

References GB().

◆ IsStationAvailable()

static bool IsStationAvailable ( const StationSpec statspec)
static

Check whether a station type can be build.

Returns
true if building is allowed.

Definition at line 84 of file rail_gui.cpp.

References StationSpec::callback_mask, CBM_STATION_AVAIL, and HasBit().

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

◆ 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().

◆ PlaceRail_Station()

static void PlaceRail_Station ( TileIndex  tile)
static

Place a rail station.

Parameters
tilePosition to place or start dragging a station.

Definition at line 197 of file rail_gui.cpp.

References _remove_button_clicked, DDSP_REMOVE_STATION, VPM_X_AND_Y_LIMITED, and VpStartPlaceSizing().

◆ PlaceRail_Waypoint()

static void PlaceRail_Waypoint ( TileIndex  tile)
static

Place a rail waypoint.

Parameters
tilePosition to start dragging a waypoint.

Definition at line 165 of file rail_gui.cpp.

References _remove_button_clicked, AXIS_X, DDSP_BUILD_STATION, DDSP_REMOVE_STATION, GetAxisForNewRailWaypoint(), IsValidAxis(), VPM_X_AND_Y, VPM_X_LIMITED, VPM_Y_LIMITED, and VpStartPlaceSizing().

◆ 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::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.

◆ 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.

◆ 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(), and RailToolbar_CtrlChanged().

Variable Documentation

◆ _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:67
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1260
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.
Definition: widget_type.h:1228
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1202
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1309
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1191
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.
Definition: widget_type.h:1272
@ 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_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.
Definition: widget_type.h:1330
std::unique_ptr< NWidgetBase > MakePickerTypeWidgets()
Create nested widgets for the type picker widgets.
Definition: picker_gui.cpp:646
std::unique_ptr< NWidgetBase > MakePickerClassWidgets()
Create nested widgets for the class picker widgets.
Definition: picker_gui.cpp:623
@ 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.

◆ _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.