OpenTTD
Data Structures | Functions | Variables
rail_gui.cpp File Reference

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

#include "stdafx.h"
#include "gui.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 "date_func.h"
#include "sound_func.h"
#include "company_func.h"
#include "widgets/dropdown_type.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_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  RailStationGUISettings
 
struct  BuildRailToolbarWindow
 Rail toolbar management class. More...
 
struct  BuildRailStationWindow
 
struct  BuildSignalWindow
 
struct  BuildRailDepotWindow
 
struct  BuildRailWaypointWindow
 

Functions

static void HandleStationPlacement (TileIndex start, TileIndex end)
 
static void ShowBuildTrainDepotPicker (Window *parent)
 
static void ShowBuildWaypointPicker (Window *parent)
 
static void ShowStationBuilder (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_SPLAT_RAIL (const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
static void GenericPlaceRail (TileIndex tile, int cmd)
 
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 (const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
static void PlaceRail_Waypoint (TileIndex tile)
 Place a rail waypoint. More...
 
void CcStation (const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
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 (const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 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 (int mode)
 
static void HandleAutodirPlacement ()
 
static void HandleAutoSignalPlacement ()
 Build new signals or remove signals or (if only one tile marked) edit a signal. More...
 
static EventState RailToolbarGlobalHotkeys (int hotkey)
 Handler for global hotkeys of the BuildRailToolbarWindow. More...
 
WindowShowBuildRailToolbar (RailType railtype)
 Open the build rail toolbar window for a specific rail type. 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.
 
bool ResetSignalVariant (int32 p)
 Updates the current signal variant used in the signal GUI to the one adequate to current year. More...
 
void InitializeRailGUI ()
 Resets the rail GUI - sets default railtype to build and resets the signal GUI.
 
DropDownListGetRailTypeDropDownList (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 byte _waypoint_count = 1
 Number of waypoint types.
 
static byte _cur_waypoint_type
 Currently selected waypoint type.
 
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 const SignalType _default_signal_type [] = {SIGTYPE_NORMAL, SIGTYPE_PBS, SIGTYPE_PBS_ONEWAY}
 
static RailStationGUISettings _railstation
 Settings of the station builder GUI.
 
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...
 
const uint16 _railtoolbar_autorail_keys [] = {'5', 'A' | WKC_GLOBAL_HOTKEY, 0}
 
static Hotkey railtoolbar_hotkeys []
 
static const 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, lengthof(_nested_build_rail_widgets), &BuildRailToolbarWindow::hotkeys)
 
static const NWidgetPart _nested_station_builder_widgets []
 
static WindowDesc _station_builder_desc (WDP_AUTO, "build_station_rail", 350, 0, WC_BUILD_STATION, WC_BUILD_TOOLBAR, WDF_CONSTRUCTION, _nested_station_builder_widgets, lengthof(_nested_station_builder_widgets))
 High level window description of the station-build window (default & newGRF)
 
static const NWidgetPart _nested_signal_builder_widgets []
 Nested widget definition of the build signal window.
 
static WindowDesc _signal_builder_desc (WDP_AUTO, "build_signal", 0, 0, WC_BUILD_SIGNAL, WC_BUILD_TOOLBAR, WDF_CONSTRUCTION, _nested_signal_builder_widgets, lengthof(_nested_signal_builder_widgets))
 Signal selection window description.
 
static const NWidgetPart _nested_build_depot_widgets []
 Nested widget definition of the build rail depot window. More...
 
static WindowDesc _build_depot_desc (WDP_AUTO, NULL, 0, 0, WC_BUILD_DEPOT, WC_BUILD_TOOLBAR, WDF_CONSTRUCTION, _nested_build_depot_widgets, lengthof(_nested_build_depot_widgets))
 
static const 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, lengthof(_nested_build_waypoint_widgets))
 

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 324 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 212 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 1988 of file rail_gui.cpp.

References RAILTYPES_NONE.

Referenced by ReplaceVehicleWindow::OnClick().

◆ 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 380 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 79 of file rail_gui.cpp.

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

Referenced by BuildRailWaypointWindow::DrawWidget(), and BuildRailWaypointWindow::OnClick().

◆ 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 110 of file rail_gui.cpp.

References _cur_railtype, CMD_BUILD_SINGLE_RAIL, DiagdirReachesTracks(), DoCommandP(), GetRailTileType(), GetTrackBits(), and RAIL_TILE_NORMAL.

◆ 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 263 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 186 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 154 of file rail_gui.cpp.

References _remove_button_clicked, AXIS_X, DDSP_BUILD_STATION, DDSP_REMOVE_STATION, GetAxisForNewWaypoint(), 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 303 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().

◆ RailToolbarGlobalHotkeys()

static EventState RailToolbarGlobalHotkeys ( int  hotkey)
static

Handler for global hotkeys of the BuildRailToolbarWindow.

Parameters
hotkeyHotkey
Returns
ES_HANDLED if hotkey was accepted.

Definition at line 779 of file rail_gui.cpp.

◆ 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 1891 of file rail_gui.cpp.

◆ ResetSignalVariant()

bool ResetSignalVariant ( int32  p)

Updates the current signal variant used in the signal GUI to the one adequate to current year.

Parameters
pneeded to be called when a setting changes
Returns
success, needed for settings

Definition at line 1953 of file rail_gui.cpp.

References _cur_signal_type, _cur_signal_variant, _cur_year, _settings_client, FindWindowById(), ClientSettings::gui, Window::RaiseWidget(), GUISettings::semaphore_build_before, Window::SetDirty(), SIG_ELECTRIC, SIG_SEMAPHORE, WC_BUILD_SIGNAL, WID_BS_ELECTRIC_NORM, and WID_BS_SEMAPHORE_NORM.

Referenced by ClickChangeDateCheat().

◆ 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 NULL if the toolbar could not be opened.

Definition at line 867 of file rail_gui.cpp.

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

◆ 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 289 of file rail_gui.cpp.

References _remove_button_clicked, DeleteWindowById(), 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

const NWidgetPart _nested_build_depot_widgets[]
static
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_PANEL, COLOUR_GREY, WID_BRAD_DEPOT_NW), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP),
NWidget(WWT_PANEL, COLOUR_GREY, WID_BRAD_DEPOT_SW), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP),
NWidget(WWT_PANEL, COLOUR_GREY, WID_BRAD_DEPOT_NE), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP),
NWidget(WWT_PANEL, COLOUR_GREY, WID_BRAD_DEPOT_SE), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP),
}
Build a depot with the entrance in the south east.
Definition: rail_widget.h:103
Build a depot with the entrance in the north west.
Definition: rail_widget.h:105
Horizontal container.
Definition: widget_type.h:75
Close box (at top-left of a window)
Definition: widget_type.h:69
Build a depot with the entrance in the north east.
Definition: rail_widget.h:102
Build a depot with the entrance in the south west.
Definition: rail_widget.h:104
Invisible widget that takes some space.
Definition: widget_type.h:79
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:947
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
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:983
Horizontal container that doesn&#39;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 1738 of file rail_gui.cpp.

◆ _nested_build_waypoint_widgets

const NWidgetPart _nested_build_waypoint_widgets[]
static
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_DEFSIZEBOX, COLOUR_DARK_GREEN),
NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BRW_WAYPOINT), SetMinimalSize(66, 60), SetDataTip(0x0, STR_WAYPOINT_GRAPHICS_TOOLTIP), SetScrollbar(WID_BRW_SCROLL), EndContainer(),
NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_BRW_SCROLL),
NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
}
Matrix container.
Definition: widget_type.h:78
Horizontal container.
Definition: widget_type.h:75
Matrix with waypoints.
Definition: rail_widget.h:110
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
A single waypoint.
Definition: rail_widget.h:111
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
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:947
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
Scrollbar for the matrix.
Definition: rail_widget.h:112
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
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1076

Nested widget definition for the build NewGRF rail waypoint window.

Definition at line 1850 of file rail_gui.cpp.

◆ _place_depot_extra_dir

const DiagDirection _place_depot_extra_dir[12]
static
Initial value:

Direction to check for existing track pieces.

Definition at line 126 of file rail_gui.cpp.

◆ _place_depot_extra_track

const Track _place_depot_extra_track[12]
static
Initial value:
= {
}
Track in the left corner of the tile (west)
Definition: track_type.h:27
Track along the y-axis (north-west to south-east)
Definition: track_type.h:24
Track in the right corner of the tile (east)
Definition: track_type.h:28
Track in the lower corner of the tile (south)
Definition: track_type.h:26
Track along the x-axis (north-east to south-west)
Definition: track_type.h:23
Track in the upper corner of the tile (north)
Definition: track_type.h:25

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

Definition at line 119 of file rail_gui.cpp.

◆ railtoolbar_hotkeys

Hotkey railtoolbar_hotkeys[]
static
Initial value:
= {
Hotkey('1', "build_ns", WID_RAT_BUILD_NS),
Hotkey('2', "build_x", WID_RAT_BUILD_X),
Hotkey('3', "build_ew", WID_RAT_BUILD_EW),
Hotkey('4', "build_y", WID_RAT_BUILD_Y),
Hotkey(_railtoolbar_autorail_keys, "autorail", WID_RAT_AUTORAIL),
Hotkey('6', "demolish", WID_RAT_DEMOLISH),
Hotkey('7', "depot", WID_RAT_BUILD_DEPOT),
Hotkey('8', "waypoint", WID_RAT_BUILD_WAYPOINT),
Hotkey('9', "station", WID_RAT_BUILD_STATION),
Hotkey('S', "signal", WID_RAT_BUILD_SIGNALS),
Hotkey('B', "bridge", WID_RAT_BUILD_BRIDGE),
Hotkey('T', "tunnel", WID_RAT_BUILD_TUNNEL),
Hotkey('R', "remove", WID_RAT_REMOVE),
Hotkey('C', "convert", WID_RAT_CONVERT_RAIL),
HOTKEY_LIST_END
}
Build rail along the game grid Y axis.
Definition: rail_widget.h:22
All data for a single hotkey.
Definition: hotkeys.h:24
Build a station.
Definition: rail_widget.h:27
Build a bridge.
Definition: rail_widget.h:29
Build a depot.
Definition: rail_widget.h:25
Build signals.
Definition: rail_widget.h:28
Build rail along the game view X axis.
Definition: rail_widget.h:21
Build a tunnel.
Definition: rail_widget.h:30
Build rail along the game grid X axis.
Definition: rail_widget.h:20
Build rail along the game view Y axis.
Definition: rail_widget.h:19
Build a waypoint.
Definition: rail_widget.h:26
Autorail tool.
Definition: rail_widget.h:23
Convert other rail to this type.
Definition: rail_widget.h:32
Bulldozer to remove rail.
Definition: rail_widget.h:31
Destroy something with dynamite!
Definition: rail_widget.h:24

Definition at line 790 of file rail_gui.cpp.