52#include "table/strings.h"
79static void ShowBuildTrainDepotPicker(
Window *parent);
80static void ShowBuildWaypointPicker(
Window *parent);
106 Command<Commands::RemoveRail>::Post(STR_ERROR_CAN_T_REMOVE_RAILROAD_TRACK, CcPlaySound_CONSTRUCTION_RAIL,
109 Command<Commands::BuildRail>::Post(STR_ERROR_CAN_T_BUILD_RAILROAD_TRACK, CcPlaySound_CONSTRUCTION_RAIL,
146 if (result.
Failed())
return;
184 Command<Commands::BuildRailWaypoint>::Post(STR_ERROR_CAN_T_BUILD_RAIL_WAYPOINT , tile,
AXIS_X, 1, 1,
STAT_CLASS_WAYP, 0, StationID::Invalid(),
false);
190 if (result.
Failed())
return;
205 VpSetPlaceSizingLimit(-1);
220 auto proc = [=](
bool test, StationID to_join) ->
bool {
224 return Command<Commands::BuildRailStation>::Post(STR_ERROR_CAN_T_BUILD_RAILROAD_STATION, CcStation, tile, rt, params.
axis, numtracks, platlength, params.
sel_class, params.
sel_type, to_join, adjacent);
252 Command<Commands::RemoveSignal>::Post(STR_ERROR_CAN_T_REMOVE_SIGNALS_FROM, CcPlaySound_CONSTRUCTION_RAIL, tile, track);
263 cycle_end = SIGTYPE_LAST;
266 if (cur_signal_on_tile <= SIGTYPE_LAST_NOPBS) {
269 cycle_end = SIGTYPE_LAST_NOPBS;
273 cycle_end = SIGTYPE_LAST;
279 Command<Commands::BuildSignal>::Post(
_convert_signal_button ? STR_ERROR_SIGNAL_CAN_T_CONVERT_SIGNALS_HERE : STR_ERROR_CAN_T_BUILD_SIGNALS_HERE, CcPlaySound_CONSTRUCTION_RAIL,
280 tile, track,
_cur_signal_type,
_cur_signal_variant,
_convert_signal_button,
false,
_ctrl_pressed, cycle_start, cycle_end, 0, 0);
283 Command<Commands::BuildSignal>::Post(STR_ERROR_CAN_T_BUILD_SIGNALS_HERE, CcPlaySound_CONSTRUCTION_RAIL,
284 tile, track,
_settings_client.gui.default_signal_type, sigvar,
false,
false,
_ctrl_pressed, cycle_start, cycle_end, 0, 0);
369 VpSetPlaceSizingLimit(-1);
385static void DoRailroadTrack(
Track track)
388 Command<Commands::RemoveRailLong>::Post(STR_ERROR_CAN_T_REMOVE_RAILROAD_TRACK, CcPlaySound_CONSTRUCTION_RAIL,
391 Command<Commands::BuildRailLong>::Post(STR_ERROR_CAN_T_BUILD_RAILROAD_TRACK, CcPlaySound_CONSTRUCTION_RAIL,
396static void HandleAutodirPlacement()
400 if (_thd.drawstyle &
HT_RAIL) {
401 GenericPlaceRail(
TileVirtXY(_thd.selend.x, _thd.selend.y), trackstat);
405 DoRailroadTrack(trackstat);
426 Command<Commands::RemoveSignalLong>::Post(STR_ERROR_CAN_T_REMOVE_SIGNALS_FROM, CcPlaySound_CONSTRUCTION_RAIL,
432 Command<Commands::BuildSignalLong>::Post(STR_ERROR_CAN_T_BUILD_SIGNALS_HERE, CcPlaySound_CONSTRUCTION_RAIL,
433 TileVirtXY(_thd.selstart.x, _thd.selstart.y),
TileVirtXY(_thd.selend.x, _thd.selend.y), track, sigtype, sigvar,
false,
_ctrl_pressed, !
_settings_client.gui.drag_signals_fixed_distance,
_settings_client.gui.drag_signals_density);
453 void Close([[maybe_unused]]
int data = 0)
override
469 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
471 if (!gui_scope)
return;
493 if (can_build)
return false;
525 void UpdateRemoveWidgetStatus(
WidgetID clicked_widget)
527 switch (clicked_widget) {
589 default: NOT_REACHED();
614 default: NOT_REACHED();
631 this->last_user_action = widget;
637 ShowBuildTrainDepotPicker(
this);
643 ShowBuildWaypointPicker(
this);
661 this->UpdateRemoveWidgetStatus(widget);
674 switch (this->last_user_action) {
727 default: NOT_REACHED();
747 switch (select_proc) {
748 default: NOT_REACHED();
755 HandleAutodirPlacement();
767 Command<Commands::ConvertRail>::Post(STR_ERROR_CAN_T_CONVERT_RAIL, CcPlaySound_CONSTRUCTION_RAIL, end_tile, start_tile,
_cur_railtype,
_ctrl_pressed);
776 Command<Commands::RemoveFromRailStation>::Post(STR_ERROR_CAN_T_REMOVE_PART_OF_STATION, CcPlaySound_CONSTRUCTION_RAIL, end_tile, start_tile, keep_rail);
778 HandleStationPlacement(start_tile, end_tile);
784 Command<Commands::RemoveFromRailWaypoint>::Post(STR_ERROR_CAN_T_REMOVE_RAIL_WAYPOINT , CcPlaySound_CONSTRUCTION_RAIL, end_tile, start_tile, keep_rail);
790 auto proc = [=](
bool test, StationID to_join) ->
bool {
794 return Command<Commands::BuildRailWaypoint>::Post(STR_ERROR_CAN_T_BUILD_RAIL_WAYPOINT , CcPlaySound_CONSTRUCTION_RAIL, ta.
tile, axis, ta.
w, ta.
h,
_waypoint_gui.sel_class,
_waypoint_gui.sel_type, to_join, adjacent);
877 static inline HotkeyList hotkeys{
"railtoolbar", {
899static constexpr std::initializer_list<NWidgetPart> _nested_build_rail_widgets = {
944 _nested_build_rail_widgets,
945 &BuildRailToolbarWindow::hotkeys
974 uint numtracks = ta.w;
975 uint platlength = ta.h;
983 auto proc = [=](
bool test, StationID to_join) ->
bool {
987 return Command<Commands::BuildRailStation>::Post(STR_ERROR_CAN_T_BUILD_RAILROAD_STATION, CcStation, ta.tile, rt, params.
axis, numtracks, platlength, params.
sel_class, params.
sel_type, to_join, adjacent);
1007class StationPickerCallbacks :
public PickerCallbacksNewGRFClass<StationClass> {
1009 StationPickerCallbacks() : PickerCallbacksNewGRFClass<StationClass>(
"fav_stations") {}
1011 GrfSpecFeature GetFeature()
const override {
return GSF_STATIONS; }
1021 for (
const auto *spec : cls.Specs()) {
1022 if (spec !=
nullptr)
return true;
1038 const auto *sc = GetClass(
id);
1048 const auto *spec = this->GetSpec(cls_id,
id);
1049 return (spec ==
nullptr) ? STR_STATION_CLASS_DFLT_STATION : spec->name;
1054 const auto *spec = this->GetSpec(cls_id,
id);
1055 if (spec ==
nullptr)
return {};
1056 return spec->badges;
1064 void DrawType(
int x,
int y,
int cls_id,
int id)
const override
1073 bool default_added =
false;
1078 default_added =
true;
1080 for (
const auto &sm : st->speclist) {
1081 if (sm.spec ==
nullptr)
continue;
1082 items.insert({sm.grfid, sm.localidx, sm.spec->class_index, sm.spec->index});
1091struct BuildRailStationWindow :
public PickerWindow {
1132 this->ConstructWindow();
1150 void Close([[maybe_unused]]
int data = 0)
override
1156 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1183 if (
_settings_client.gui.station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
1185 for (uint bits = 0; bits < 7; bits++) {
1187 if (statspec ==
nullptr) {
1201 const int bottom = r.bottom;
1203 if (statspec !=
nullptr) r.top =
DrawBadgeNameList(r, statspec->badges, GSF_STATIONS);
1209 if (r.top > bottom) {
1210 this->coverage_height += r.top - bottom;
1225 size.height = this->coverage_height;
1302 for (uint i = 0; i < 7; i++) {
1335 for (uint i = 0; i < 7; i++) {
1360 for (uint i = 0; i < 7; i++) {
1369 for (uint i = 0; i < 7; i++) {
1421 static inline HotkeyList hotkeys{
"buildrailstation", {
1426static constexpr std::initializer_list<NWidgetPart> _nested_station_builder_widgets = {
1481 WDP_AUTO,
"build_station_rail", 0, 0,
1484 _nested_station_builder_widgets,
1485 &BuildRailStationWindow::hotkeys
1494struct BuildSignalWindow :
public PickerWindowBase {
1509 int x =
CentreBounds(ir.left, ir.right, sprite_size.width - offset.
x) - offset.
x;
1534 void Close([[maybe_unused]]
int data = 0)
override
1543 this->sig_sprite_size.width = 0;
1544 this->sig_sprite_size.height = 0;
1545 this->sig_sprite_bottom_offset = 0;
1547 for (uint type =
SIGTYPE_BLOCK; type < SIGTYPE_END; type++) {
1549 for (uint lowered = 0; lowered < 2; lowered++) {
1552 this->sig_sprite_bottom_offset = std::max<int>(this->sig_sprite_bottom_offset, sprite_size.height);
1553 this->sig_sprite_size.width = std::max<int>(this->sig_sprite_size.width, sprite_size.width - offset.
x);
1554 this->sig_sprite_size.height = std::max<int>(this->sig_sprite_size.height, sprite_size.height - offset.
y);
1566 size.width = std::max(size.width, this->sig_sprite_size.width + padding.width);
1567 size.height = std::max(size.height, this->sig_sprite_size.height + padding.height);
1656 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1658 if (!gui_scope)
return;
1749struct BuildRailDepotWindow :
public PickerWindowBase {
1822static void ShowBuildTrainDepotPicker(
Window *parent)
1827class WaypointPickerCallbacks :
public PickerCallbacksNewGRFClass<StationClass> {
1829 WaypointPickerCallbacks() : PickerCallbacksNewGRFClass<StationClass>(
"fav_waypoints") {}
1831 GrfSpecFeature GetFeature()
const override {
return GSF_STATIONS; }
1841 for (
const auto *spec : cls.Specs()) {
1842 if (spec !=
nullptr)
return true;
1859 const auto *sc = GetClass(
id);
1869 const auto *spec = this->GetSpec(cls_id,
id);
1870 return (spec ==
nullptr) ? STR_STATION_CLASS_WAYP_WAYPOINT : spec->name;
1875 const auto *spec = this->GetSpec(cls_id,
id);
1876 if (spec ==
nullptr)
return {};
1877 return spec->badges;
1885 void DrawType(
int x,
int y,
int cls_id,
int id)
const override
1892 bool default_added =
false;
1897 default_added =
true;
1899 for (
const auto &sm : wp->speclist) {
1900 if (sm.spec ==
nullptr)
continue;
1901 items.insert({sm.grfid, sm.localidx, sm.spec->class_index, sm.spec->index});
1910struct BuildRailWaypointWindow :
public PickerWindow {
1913 this->ConstructWindow();
1916 static inline HotkeyList hotkeys{
"buildrailwaypoint", {
1940 &BuildRailWaypointWindow::hotkeys
1943static void ShowBuildWaypointPicker(
Window *parent)
1945 if (!WaypointPickerCallbacks::instance.IsActive())
return;
1984 std::array<uint, RAILTYPE_END> count{};
1992 rt =
static_cast<RailType>(std::distance(std::begin(count), std::ranges::max_element(count)));
1993 if (count[rt] > 0)
break;
2001 [](
RailType r) { return HasRailTypeAvail(_local_company, r); });
2008 [](
RailType r){ return HasRailTypeAvail(_local_company, r); });
2073 if (for_replacement) {
2084 list.push_back(MakeDropDownListStringItem(STR_REPLACE_ALL_RAILTYPE,
INVALID_RAILTYPE));
2089 if (!for_replacement) {
2090 used_railtypes.
Reset(_railtypes_hidden_mask);
2092 if (!used_railtypes.
Test(rt))
continue;
2099 auto badge_class_list = std::make_shared<GUIBadgeClasses>(GSF_RAILTYPES);
2103 if (!used_railtypes.
Test(rt))
continue;
2107 if (for_replacement) {
2113 list.push_back(MakeDropDownListBadgeIconItem(badge_class_list, rti->badges, GSF_RAILTYPES, rti->
introduction_date,
RailBuildCost(rt), d, rti->
gui_sprites.
build_x_rail, PAL_NONE, std::move(str), rt, !avail_railtypes.
Test(rt)));
2119 list.push_back(MakeDropDownListStringItem(STR_NONE,
INVALID_RAILTYPE,
true));
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, uint8_t road_rail_type)
Prepare the data for the build a bridge window.
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Reset()
Reset all bits.
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
bool Failed() const
Did this command fail?
An interval timer will fire every interval, and will continue to fire until it is deleted.
static std::span< NewGRFClass< StationSpec, StationClassID, Tmax > const > Classes()
static NewGRFClass * Get(StationClassID class_index)
const Tspec * GetSpec(uint index) const
Get a spec from the class at a given index.
Base class for windows opened from a toolbar.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
static constexpr int PREVIEW_WIDTH
Width of each preview button.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
static constexpr int PREVIEW_HEIGHT
Height of each preview button.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
static constexpr int PREVIEW_LEFT
Offset from left edge to draw preview.
static constexpr int PREVIEW_BOTTOM
Offset from bottom edge to draw preview.
@ PCWHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnInit() override
Notification that the nested widget tree gets initialized.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
This struct contains all the info that is needed to draw and construct tracks.
uint16_t max_speed
Maximum speed for vehicles travelling on this rail type.
SpriteID build_tunnel
button for building a tunnel
CursorID rail_swne
Cursor for building rail in X direction.
SpriteID convert_rail
button for converting rail
struct RailTypeInfo::@157247141350136173143103254227157213063052244122 strings
Strings associated with the rail type.
CursorID convert
Cursor for converting track.
CursorID depot
Cursor for building a depot.
TimerGameCalendar::Date introduction_date
Introduction date.
CursorID rail_nwse
Cursor for building rail in Y direction.
SpriteID build_x_rail
button for building single rail in X direction
CursorID rail_ew
Cursor for building rail in E-W direction.
SpriteID auto_rail
button for the autorail construction
CursorID autorail
Cursor for autorail tool.
StringID menu_text
Name of this rail type in the main toolbar dropdown.
StringID toolbar_caption
Caption in the construction toolbar GUI for this rail type.
struct RailTypeInfo::@047376261311064105134233254254216006075341230376 gui_sprites
struct containing the sprites for the rail GUI.
SpriteID signals[SIGTYPE_END][2][2]
signal GUI sprites (type, variant, state)
SpriteID build_ew_rail
button for building single rail in E-W direction
SpriteID build_y_rail
button for building single rail in Y direction
StringID replace_text
Text used in the autoreplace GUI.
SpriteID build_depot
button for building depots
SpriteID build_ns_rail
button for building single rail in N-S direction
CursorID rail_ns
Cursor for building rail in N-S direction.
SpriteID tunnel
tunnel sprites base
struct RailTypeInfo::@057010233226120022371265166156055202241326366156 cursor
Cursors associated with the rail type.
bool IsActive() const override
Should picker class/type selection be enabled?
StringID GetCollectionTooltip() const override
Get the tooltip string for the collection list.
bool HasClassChoice() const override
Are there multiple classes to chose from?
std::span< const BadgeID > GetTypeBadges(int cls_id, int id) const override
Get the item of a type.
StringID GetTypeName(int cls_id, int id) const override
Get the item of a type.
StringID GetClassTooltip() const override
Get the tooltip string for the class list.
void SetSelectedType(int id) const override
Set the selected type.
void DrawType(int x, int y, int cls_id, int id) const override
Draw preview image of an item.
StringID GetClassName(int id) const override
Get the name of a class.
StringID GetTypeTooltip() const override
Get the tooltip string for the type grid.
int GetSelectedClass() const override
Get the index of the selected class.
void SetSelectedClass(int id) const override
Set the selected class.
bool IsTypeAvailable(int cls_id, int id) const override
Test if an item is currently buildable.
int GetSelectedType() const override
Get the selected type.
void FillUsedItems(std::set< PickerItem > &items) override
Fill a set with all items that are used by the current player.
Wrapper class to abstract away the way the tiles are stored.
static Year year
Current year, starting at 0.
int GetSelectedType() const override
Get the selected type.
void SetSelectedClass(int id) const override
Set the selected class.
StringID GetTypeTooltip() const override
Get the tooltip string for the type grid.
void DrawType(int x, int y, int cls_id, int id) const override
Draw preview image of an item.
StringID GetCollectionTooltip() const override
Get the tooltip string for the collection list.
bool IsTypeAvailable(int cls_id, int id) const override
Test if an item is currently buildable.
std::span< const BadgeID > GetTypeBadges(int cls_id, int id) const override
Get the item of a type.
int GetSelectedClass() const override
Get the index of the selected class.
StringID GetTypeName(int cls_id, int id) const override
Get the item of a type.
bool IsActive() const override
Should picker class/type selection be enabled?
void SetSelectedType(int id) const override
Set the selected type.
StringID GetClassName(int id) const override
Get the name of a class.
StringID GetClassTooltip() const override
Get the tooltip string for the class list.
void FillUsedItems(std::set< PickerItem > &items) override
Fill a set with all items that are used by the current player.
bool HasClassChoice() const override
Are there multiple classes to chose from?
CommandFlags GetCommandFlags(Commands cmd)
Get the command flags associated with the given command.
Functions related to commands.
static constexpr DoCommandFlags CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
@ Auto
don't allow building on structures
Commands
List of commands.
Definition of stuff that is very close to a company, like the company struct itself.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
static constexpr CompanyID COMPANY_SPECTATOR
The client is spectating.
bool IsValidAxis(Axis d)
Checks if an integer value is a valid Axis.
Axis
Allow incrementing of DiagDirDiff variables.
DiagDirection
Enumeration for diagonal directions.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Functions related to the drop down widget.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
bool _ctrl_pressed
Is Ctrl pressed?
void SetCursor(CursorID icon, PaletteID pal)
Assign an animation or a non-animated sprite to the cursor.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
uint8_t GetDigitWidth(FontSize size)
Return the maximum width of single digit.
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
@ FS_NORMAL
Index of the normal font in the font tables.
uint32_t CursorID
The number of the cursor (sprite).
@ WKC_R_BRACKET
] Right square bracket
@ WKC_L_BRACKET
[ Left square bracket
@ WKC_GLOBAL_HOTKEY
Fake keycode bit to indicate global hotkeys.
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
GUI functions that shouldn't be here.
Hotkey related functions.
std::tuple< size_t, size_t > GetListIndexStep(SpecialListHotkeys hotkey, const ListType &list, const ItemType ¤t_item)
Gets the first index in the list for given hotkey and the step to look for another if first is invali...
SpecialListHotkeys
Indexes for special hotkeys to navigate in lists.
@ NextItem
Hotkey to select next item in the list.
@ FirstItem
Hotkey to select first item in the list.
@ LastItem
Hotkey to select last item in the list.
@ PreviousItem
Hotkey to select previous item in the list.
bool IsSpecialHotkey(const int &hotkey)
Checks if hotkey index is special or not.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
#define Point
Macro that prevents name conflicts between included headers.
bool HandlePlacePushButton(Window *w, WidgetID widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
void GuiShowTooltips(Window *parent, EncodedString &&text, TooltipCloseCondition close_tooltip)
Shows a tooltip.
Functions related to NewGRF badges.
int DrawBadgeNameList(Rect r, std::span< const BadgeID > badges, GrfSpecFeature)
Draw names for a list of badge labels.
GUI functions related to NewGRF badges.
@ Avail
Availability of station in construction window.
@ CBID_STATION_AVAILABILITY
Determine whether a newstation should be made available to build.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
Converts a callback result into a boolean.
bool IsWaypointClass(const RoadStopClass &cls)
Test if a RoadStopClass is the waypoint class.
bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
Draw representation of a station tile for GUI purposes.
Header file for NewGRF stations.
@ STAT_CLASS_DFLT
Default station class.
@ STAT_CLASS_WAYP
Waypoint class.
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.
RailTypes GetCompanyRailTypes(CompanyID company, bool introduces)
Get the rail types the given company can build.
bool HasRailTypeAvail(const CompanyID company, const RailType railtype)
Finds out if a company has a certain buildable railtype available.
RailTypes GetRailTypes(bool introduces)
Get list of rail types, regardless of company availability.
bool ValParamRailType(const RailType rail)
Validate functions for rail building.
Money RailBuildCost(RailType railtype)
Returns the cost of building the specified railtype.
std::vector< RailType > _sorted_railtypes
Sorted list of rail types.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Command definitions for rail.
static constexpr std::initializer_list< NWidgetPart > _nested_signal_builder_widgets
Nested widget definition of the build signal window.
Window * ShowBuildRailToolbar(RailType railtype)
Open the build rail toolbar window for a specific rail type.
static bool RailToolbar_CtrlChanged(Window *w)
Updates the Remove button because of Ctrl state change.
void ResetSignalVariant(int32_t)
Updates the current signal variant used in the signal GUI to the one adequate to current year.
static void PlaceRail_Waypoint(TileIndex tile)
Place a rail waypoint.
static void SetDefaultRailGui()
Set the initial (default) railtype to use.
static RailType _cur_railtype
Rail type of the current build-rail toolbar.
static void HandleAutoSignalPlacement()
Build new signals or remove signals or (if only one tile marked) edit a signal.
static SignalVariant _cur_signal_variant
set the signal variant (for signal GUI)
static void PlaceExtraDepotRail(TileIndex tile, DiagDirection dir, Track track)
Try to add an additional rail-track at the entrance of a depot.
static void PlaceRail_Bridge(TileIndex tile, Window *w)
Start placing a rail bridge.
static void PlaceRail_Station(TileIndex tile)
Place a rail station.
static StationPickerSelection _station_gui
Settings of the station picker.
static SignalType _cur_signal_type
set the signal type (for signal GUI)
static void ToggleRailButton_Remove(Window *w)
Toggles state of the Remove button of Build rail toolbar.
DropDownList GetRailTypeDropDownList(bool for_replacement, bool all_option)
Create a drop down list for all the rail types of the local company.
void CcBuildRailTunnel(Commands, const CommandCost &result, TileIndex tile)
Command callback for building a tunnel.
static WindowDesc _station_builder_desc(WDP_AUTO, "build_station_rail", 0, 0, WC_BUILD_STATION, WC_BUILD_TOOLBAR, WindowDefaultFlag::Construction, _nested_station_builder_widgets, &BuildRailStationWindow::hotkeys)
High level window description of the station-build window (default & newGRF).
static void BuildRailClick_Remove(Window *w)
The "remove"-button click proc of the build-rail toolbar.
static WindowDesc _signal_builder_desc(WDP_AUTO, {}, 0, 0, WC_BUILD_SIGNAL, WC_BUILD_TOOLBAR, WindowDefaultFlag::Construction, _nested_signal_builder_widgets)
Signal selection window description.
static constexpr std::initializer_list< NWidgetPart > _nested_build_depot_widgets
Nested widget definition of the build rail depot window.
static bool IsStationAvailable(const StationSpec *statspec)
Check whether a station type can be build.
static Window * ShowStationBuilder(Window *parent)
Open station build window.
static bool StationUsesDefaultType(const BaseStation *bst)
Test if a station/waypoint uses the default graphics.
static const Track _place_depot_extra_track[12]
Additional pieces of track to add at the entrance of a depot.
static DiagDirection _build_depot_direction
Currently selected depot direction.
void InitializeRailGui()
Initialize rail building GUI settings.
static void ShowSignalBuilder(Window *parent)
Open the signal selection window.
static constexpr std::initializer_list< NWidgetPart > _nested_build_waypoint_widgets
Nested widget definition for the build NewGRF rail waypoint window.
static bool _remove_button_clicked
Flag whether 'remove' toggle-button is currently enabled.
void ReinitGuiAfterToggleElrail(bool disable)
Re-initialize rail-build toolbar after toggling support for electric trains.
static const DiagDirection _place_depot_extra_dir[12]
Direction to check for existing track pieces.
void InitializeRailGUI()
Resets the rail GUI - sets default railtype to build and resets the signal GUI.
static bool _convert_signal_button
convert signal button in the signal GUI pressed
static void GenericPlaceSignals(TileIndex tile)
Build a new signal or edit/remove a present signal, use CmdBuildSingleSignal() or CmdRemoveSingleSign...
static WaypointPickerSelection _waypoint_gui
Settings of the waypoint picker.
@ SIGNAL_GUI_ALL
Show all signals, including block and presignals.
@ SIGNAL_CYCLE_ALL
Cycle through all signals visible to the player.
static RailTileType GetRailTileType(Tile t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
TrackBits GetTrackBits(Tile tile)
Gets the track bits of the given tile.
static bool IsPlainRailTile(Tile t)
Checks whether the tile is a rail tile or rail tile with signals.
@ Depot
Depot (one entrance).
@ Signals
Normal rail tile with signals.
bool HasSignalOnTrack(Tile tile, Track track)
Checks for the presence of signals (either way) on the given track on the given rail tile.
static bool IsRailDepotTile(Tile t)
Is this tile rail tile and a rail depot?
EnumBitSet< RailType, uint64_t > RailTypes
Allow incrementing of Track variables.
RailType
Enumeration for all possible railtypes.
@ RAILTYPE_BEGIN
Used for iterations.
@ INVALID_RAILTYPE
Flag for invalid railtype.
@ RAILTYPE_ELECTRIC
Electric rails.
@ RAILTYPE_RAIL
Standard non-electric rails.
bool IsLevelCrossingTile(Tile t)
Return whether a tile is a level crossing tile.
@ INVALID_ROADTYPE
flag for invalid roadtype
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
ClientSettings _settings_client
The current settings for this game.
SignalType
Type of signal, i.e.
@ SIGTYPE_PBS
normal pbs signal
@ SIGTYPE_BLOCK
block signal
SignalVariant
Variant of the signal, i.e.
@ SIG_SEMAPHORE
Old-fashioned semaphore signal.
@ SIG_ELECTRIC
Light signal.
void SndClickBeep()
Play a beep sound for a click event if enabled in settings.
Functions related to sound.
@ SND_20_CONSTRUCTION_RAIL
30 == 0x1E Construction: rail infrastructure
static const CursorID ANIMCURSOR_BUILDSIGNALS
1292 - 1293 - build signal
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
Base classes/functions for stations.
Command definitions related to stations.
void ShowSelectStationIfNeeded(TileArea ta, StationPickerCmdProc proc)
Show the station selection window when needed.
void ShowSelectRailWaypointIfNeeded(TileArea ta, StationPickerCmdProc proc)
Show the rail waypoint selection window when needed.
int DrawStationCoverageAreaText(const Rect &r, 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.
Contains enums and function declarations connected with stations GUI.
@ SCT_ALL
Draw all cargoes.
Maps accessors for stations.
bool HasStationTileRail(Tile t)
Has this station tile a rail?
uint GetCustomStationSpecIndex(Tile t)
Get the custom station spec for this tile.
bool HasStationRail(Tile t)
Has this station tile a rail?
static constexpr uint CA_TRAIN
Catchment for train stations with "modified catchment" enabled.
@ Rail
Railways/train station.
static constexpr uint CA_UNMODIFIED
Catchment for all stations with "modified catchment" disabled.
Definition of base types and functions in a cross-platform compatible way.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Functions related to OTTD's strings.
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames).
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Base class for all station-ish types.
TileArea train_station
Tile area the train 'station' part covers.
virtual bool TileBelongsToRailStation(TileIndex tile) const =0
Check whether a specific tile belongs to this station.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnRealtimeTick(uint delta_ms) override
Called periodically.
void OnPaint() override
The window must be repainted.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
static EventState BuildRailStationGlobalHotkeys(int hotkey)
Handler for global hotkeys of the BuildRailStationWindow.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
uint coverage_height
Height of the coverage texts.
void CheckSelectedSize(const StationSpec *statspec)
Verify whether the currently selected station size is allowed after selecting a new station class/typ...
void OnInit() override
Notification that the nested widget tree gets initialized.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Dimension sig_sprite_size
Maximum size of signal GUI sprites.
void DrawSignalSprite(const Rect &r, SpriteID image) const
Draw dynamic a signal-sprite in a button in the signal GUI.
void SetSignalUIMode()
Show or hide buttons for non-path signals in the signal GUI.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnInit() override
Notification that the nested widget tree gets initialized.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
int sig_sprite_bottom_offset
Maximum extent of signal GUI sprite from reference point towards bottom.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
RailTypes avail_railtypes
Rail types available to this company.
Dimensions (a width and height) of a rectangle in 2D.
Data about how and where to blit pixels.
const struct GRFFile * grffile
grf file that introduced this entity
List of hotkeys for a window.
All data for a single hotkey.
static IterateWrapper Iterate()
Returns an iterable ensemble of all Tiles.
uint16_t w
The width of the area.
TileIndex tile
The base tile of the area.
uint16_t h
The height of the area.
static Company * Get(auto index)
static bool IsValidID(auto index)
Specification of a rectangle with absolute coordinates of all edges.
int Width() const
Get width of Rect.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
int Height() const
Get height of Rect.
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
StationClassID sel_class
Selected station class.
uint16_t sel_type
Selected station type within the class.
Axis axis
Selected orientation of the station.
uint8_t disallowed_lengths
Bitmask of platform lengths available for the station.
uint8_t disallowed_platforms
Bitmask of number of platforms available for the station.
CargoGRFFileProps grf_prop
Link to NewGRF.
StationCallbackMasks callback_mask
Bitmask of station callbacks that have to be called.
StationClassID sel_class
Selected station class.
uint16_t sel_type
Selected station type within the class.
Representation of a waypoint.
High level window description.
Data structure for an opened window.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
void DrawWidgets() const
Paint all widgets of a window.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing).
Window * parent
Parent window.
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
ResizeInfo resize
Resize information.
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
bool IsShaded() const
Is window shaded currently?
virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
The user has dragged over the map when the tile highlight mode has been set.
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
void ToggleWidgetLoweredState(WidgetID widget_index)
Invert the lowered/raised status of a widget.
WindowNumber window_number
Window number within the window class.
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
bool IsValidTile(Tile tile)
Checks if a tile is valid.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
@ TunnelBridge
Tunnel entry/exit and bridge heads.
@ Railway
A tile with railway.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void VpSetPresizeRange(TileIndex from, TileIndex to)
Highlights all tiles between a set of two tiles.
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
highlighting tiles while only going over them with the mouse
HighLightStyle
Highlighting draw styles.
@ HT_LINE
used for autorail highlighting (longer stretches), lower bits: direction
@ HT_DIR_HL
horizontal lower
@ HT_DIAGONAL
Also allow 'diagonal rectangles'. Only usable in combination with HT_RECT or HT_POINT.
@ HT_RECT
rectangle (stations, depots, ...)
@ HT_DIR_MASK
masks the drag-direction
@ HT_RAIL
autorail (one piece), lower bits: direction
@ HT_DRAG_MASK
Mask for the tile drag-type modes.
@ HT_SPECIAL
special mode used for highlighting while dragging (and for tunnels/docks)
Definition of Interval and OneShot timers.
Definition of the game-calendar-timer.
bool IsValidTrack(Track track)
Checks if a Track is valid.
Track FindFirstTrack(TrackBits tracks)
Returns first Track from TrackBits or INVALID_TRACK.
TrackBits DiagdirReachesTracks(DiagDirection diagdir)
Returns all tracks that can be reached when entering a tile from a given (diagonal) direction.
TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
TrackBits
Allow incrementing of Track variables.
@ TRACK_BIT_UPPER
Upper track.
@ TRACK_BIT_LEFT
Left track.
@ TRACK_BIT_HORZ
Upper and lower track.
@ TRACK_BIT_LOWER
Lower track.
@ TRACK_BIT_RIGHT
Right track.
@ TRACK_BIT_VERT
Left and right track.
Track
These are used to specify a single track.
@ TRACK_Y
Track along the y-axis (north-west to south-east).
@ TRACK_LOWER
Track in the lower corner of the tile (south).
@ TRACK_LEFT
Track in the left corner of the tile (west).
@ TRACK_RIGHT
Track in the right corner of the tile (east).
@ TRACK_X
Track along the x-axis (north-east to south-west).
@ TRACK_UPPER
Track in the upper corner of the tile (north).
@ TRANSPORT_RAIL
Transport by train.
Header file for things common for tunnels and bridges.
TileIndex _build_tunnel_endtile
The end of a tunnel; as hidden return from the tunnel build command for GUI purposes.
Command definitions related to tunnels and bridges.
Functions that have tunnels and bridges in common.
TransportType GetTunnelBridgeTransportType(Tile t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
TileIndex GetOtherTunnelBridgeEnd(Tile t)
Determines type of the wormhole and returns its other end.
bool CanBuildVehicleInfrastructure(VehicleType type, uint8_t subtype)
Check whether we can build infrastructure for the given vehicle type.
Functions related to vehicles.
@ VEH_TRAIN
Train vehicle type.
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
void SetViewportCatchmentWaypoint(const Waypoint *wp, bool sel)
Select or deselect waypoint for coverage area highlight.
void SetRedErrorSquare(TileIndex tile)
Set a tile to display a red error square.
void SetViewportCatchmentStation(const Station *st, bool sel)
Select or deselect station for coverage area highlight.
Functions related to (drawing on) viewports.
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects).
@ VPM_FIX_Y
drag only in Y axis
@ VPM_Y_LIMITED
Drag only in Y axis with limited size.
@ VPM_X_AND_Y_LIMITED
area of land of limited size
@ VPM_FIX_VERTICAL
drag only in vertical direction
@ VPM_X_LIMITED
Drag only in X axis with limited size.
@ VPM_X_AND_Y
area of land in X and Y directions
@ VPM_FIX_HORIZONTAL
drag only in horizontal direction
@ VPM_FIX_X
drag only in X axis
@ VPM_SIGNALDIRS
similar to VMP_RAILDIRS, but with different cursor
@ VPM_X_OR_Y
drag in X or Y direction
@ VPM_RAILDIRS
all rail directions
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
@ DDSP_CONVERT_RAIL
Rail conversion.
@ DDSP_DEMOLISH_AREA
Clear area.
@ DDSP_BUILD_SIGNALS
Signal placement.
@ DDSP_REMOVE_STATION
Station removal.
@ DDSP_BUILD_STATION
Station placement.
@ DDSP_BUILD_BRIDGE
Bridge placement.
@ DDSP_PLACE_RAIL
Rail placement.
void DrawWaypointSprite(int x, int y, StationClassID station_class, uint16_t station_type, RailType railtype)
Draw a waypoint.
@ WPF_ROAD
This is a road waypoint.
Axis GetAxisForNewRailWaypoint(TileIndex tile)
Get the axis for a new rail waypoint.
Command definitions related to waypoints.
Functions related to waypoints.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Point AlignInitialConstructionToolbar(int window_width)
Compute the position of the construction toolbars.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting).
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ Construction
This window is used for construction; close it whenever changing company.
@ WDP_AUTO
Find a place automatically.
@ WDP_MANUAL
Manually align the window (so no automatic location finding).
@ WN_GAME_OPTIONS_GAME_SETTINGS
Game settings.
EventState
State of handling an event.
@ ES_HANDLED
The passed event is handled.
@ ES_NOT_HANDLED
The passed event is not handled.
static constexpr WidgetID INVALID_WIDGET
An invalid widget index.
@ WC_BUILD_STATION
Build station; Window numbers:
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ WC_SCEN_LAND_GEN
Landscape generation (in Scenario Editor); Window numbers:
@ WC_SELECT_STATION
Select station (when joining stations); Window numbers:
@ WC_BUILD_SIGNAL
Build signal toolbar; Window numbers:
@ WC_BUILD_DEPOT
Build depot; Window numbers:
@ WC_GAME_OPTIONS
Game options window; Window numbers:
@ WC_BUILD_WAYPOINT
Build waypoint; Window numbers:
@ WC_BUILD_BRIDGE
Build bridge; Window numbers:
Functions related to zooming.
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.