Merge 1.10.0-beta1

This commit is contained in:
dP
2019-11-01 16:08:44 +03:00
parent 4bf7002873
commit ceea4c88be
920 changed files with 26309 additions and 16944 deletions

View File

@@ -85,9 +85,9 @@ static void ShowSignalBuilder(Window *parent);
*/
static bool IsStationAvailable(const StationSpec *statspec)
{
if (statspec == NULL || !HasBit(statspec->callback_mask, CBM_STATION_AVAIL)) return true;
if (statspec == nullptr || !HasBit(statspec->callback_mask, CBM_STATION_AVAIL)) return true;
uint16 cb_res = GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE);
uint16 cb_res = GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, nullptr, INVALID_TILE);
if (cb_res == CALLBACK_FAILED) return true;
return Convert8bitBooleanCallback(statspec->grf_prop.grffile, CBID_STATION_AVAILABILITY, cb_res);
@@ -248,7 +248,7 @@ static void GenericPlaceSignals(TileIndex tile)
/* various bitstuffed elements for CmdBuildSingleSignal() */
uint32 p1 = track;
if (w != NULL) {
if (w != nullptr) {
/* signal GUI is used */
SB(p1, 3, 1, _ctrl_pressed);
SB(p1, 4, 1, _cur_signal_variant);
@@ -264,7 +264,7 @@ static void GenericPlaceSignals(TileIndex tile)
}
DoCommandP(tile, p1, 0, CMD_BUILD_SIGNALS |
CMD_MSG((w != NULL && _convert_signal_button) ? STR_ERROR_SIGNAL_CAN_T_CONVERT_SIGNALS_HERE : STR_ERROR_CAN_T_BUILD_SIGNALS_HERE),
CMD_MSG((w != nullptr && _convert_signal_button) ? STR_ERROR_SIGNAL_CAN_T_CONVERT_SIGNALS_HERE : STR_ERROR_CAN_T_BUILD_SIGNALS_HERE),
CcPlaySound_SPLAT_RAIL);
}
}
@@ -426,7 +426,7 @@ static void HandleAutoSignalPlacement()
const Window *w = FindWindowById(WC_BUILD_SIGNAL, 0);
if (w != NULL) {
if (w != nullptr) {
/* signal GUI is used */
SB(p2, 3, 1, 0);
SB(p2, 4, 1, _cur_signal_variant);
@@ -537,6 +537,7 @@ struct BuildRailToolbarWindow : Window {
~BuildRailToolbarWindow()
{
if (this->IsWidgetLowered(WID_RAT_BUILD_STATION)) SetViewportCatchmentStation(nullptr, true);
if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false);
}
@@ -545,7 +546,7 @@ struct BuildRailToolbarWindow : Window {
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
@@ -614,7 +615,7 @@ struct BuildRailToolbarWindow : Window {
}
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
if (widget == WID_RAT_CAPTION) {
const RailtypeInfo *rti = GetRailTypeInfo(this->railtype);
@@ -637,7 +638,7 @@ struct BuildRailToolbarWindow : Window {
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
if (widget < WID_RAT_BUILD_NS) return;
bool remove_on_ctrl = true; /* do not check ctrl for hotkeys */
@@ -778,7 +779,7 @@ struct BuildRailToolbarWindow : Window {
if (_ctrl_pressed && remove_on_ctrl) RailToolbar_CtrlChanged(this);
}
virtual EventState OnHotkey(int hotkey)
EventState OnHotkey(int hotkey) override
{
// EventState es;
MarkTileDirtyByTile(TileVirtXY(_thd.pos.x, _thd.pos.y)); // redraw tile selection
@@ -800,7 +801,7 @@ struct BuildRailToolbarWindow : Window {
return Window::OnHotkey(hotkey);
}
virtual void OnPlaceObject(Point pt, TileIndex tile)
void OnPlaceObject(Point pt, TileIndex tile) override
{
DiagDirection ddir;
switch (this->last_user_action) {
@@ -869,15 +870,15 @@ struct BuildRailToolbarWindow : Window {
}
}
virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) override
{
/* no dragging if you have pressed the convert button */
if (FindWindowById(WC_BUILD_SIGNAL, 0) != NULL && _convert_signal_button && this->IsWidgetLowered(WID_RAT_BUILD_SIGNALS)) return;
if (FindWindowById(WC_BUILD_SIGNAL, 0) != nullptr && _convert_signal_button && this->IsWidgetLowered(WID_RAT_BUILD_SIGNALS)) return;
VpSelectTilesWithMethod(pt.x, pt.y, select_method);
}
virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) override
{
if (pt.x != -1) {
switch (select_proc) {
@@ -930,8 +931,10 @@ struct BuildRailToolbarWindow : Window {
}
}
virtual void OnPlaceObjectAbort()
void OnPlaceObjectAbort() override
{
if (this->IsWidgetLowered(WID_RAT_BUILD_STATION)) SetViewportCatchmentStation(nullptr, true);
this->RaiseButtons();
this->DisableWidget(WID_RAT_REMOVE);
this->SetWidgetDirty(WID_RAT_REMOVE);
@@ -944,13 +947,13 @@ struct BuildRailToolbarWindow : Window {
DeleteWindowByClass(WC_BUILD_BRIDGE);
}
virtual void OnPlacePresize(Point pt, TileIndex tile)
void OnPlacePresize(Point pt, TileIndex tile) override
{
DoCommand(tile, _cur_railtype | (TRANSPORT_RAIL << 8), 0, DC_AUTO, CMD_BUILD_TUNNEL);
VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile);
}
virtual EventState OnCTRLStateChange()
EventState OnCTRLStateChange() override
{
/* do not toggle Remove button by Ctrl when placing station */
if (!this->IsWidgetLowered(WID_RAT_BUILD_STATION) && !this->IsWidgetLowered(WID_RAT_BUILD_WAYPOINT) && RailToolbar_CtrlChanged(this)) return ES_HANDLED;
@@ -970,7 +973,7 @@ static EventState RailToolbarGlobalHotkeys(int hotkey)
if (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(VEH_TRAIN)) return ES_NOT_HANDLED;
extern RailType _last_built_railtype;
Window *w = ShowBuildRailToolbar(_last_built_railtype);
if (w == NULL) return ES_NOT_HANDLED;
if (w == nullptr) return ES_NOT_HANDLED;
return w->OnHotkey(hotkey);
}
@@ -1059,12 +1062,12 @@ static WindowDesc _build_rail_desc(
* If the terraform toolbar is linked to the toolbar, that window is also opened.
*
* @param railtype Rail type to open the window for
* @return newly opened rail toolbar, or NULL if the toolbar could not be opened.
* @return newly opened rail toolbar, or nullptr if the toolbar could not be opened.
*/
Window *ShowBuildRailToolbar(RailType railtype)
{
if (!Company::IsValidID(_local_company)) return NULL;
if (!ValParamRailtype(railtype)) return NULL;
if (!Company::IsValidID(_local_company)) return nullptr;
if (!ValParamRailtype(railtype)) return nullptr;
DeleteWindowByClass(WC_BUILD_TOOLBAR);
_cur_railtype = railtype;
@@ -1104,7 +1107,7 @@ private:
*/
void CheckSelectedSize(const StationSpec *statspec)
{
if (statspec == NULL || _settings_client.gui.station_dragdrop) return;
if (statspec == nullptr || _settings_client.gui.station_dragdrop) return;
/* If current number of tracks is not allowed, make it as big as possible */
if (HasBit(statspec->disallowed_platforms, _settings_client.gui.station_numtracks - 1)) {
@@ -1134,7 +1137,7 @@ public:
BuildRailStationWindow(WindowDesc *desc, Window *parent, bool newstation) : PickerWindowBase(desc, parent)
{
this->coverage_height = 2 * FONT_HEIGHT_NORMAL + 3 * WD_PAR_VSEP_NORMAL;
this->vscroll = NULL;
this->vscroll = nullptr;
_railstation.newstations = newstation;
this->CreateNestedTree();
@@ -1167,7 +1170,7 @@ public:
* type is 'selected'. */
_railstation.station_class = STAT_CLASS_DFLT;
_railstation.station_type = 0;
this->vscroll2 = NULL;
this->vscroll2 = nullptr;
}
if (newstation) {
_railstation.station_count = StationClass::Get(_railstation.station_class)->GetSpecCount();
@@ -1193,10 +1196,10 @@ public:
DeleteWindowById(WC_SELECT_STATION, 0);
}
virtual void OnPaint()
void OnPaint() override
{
bool newstations = _railstation.newstations;
const StationSpec *statspec = newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : NULL;
const StationSpec *statspec = newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : nullptr;
if (_settings_client.gui.station_dragdrop) {
SetTileSelectSize(1, 1);
@@ -1215,7 +1218,7 @@ public:
for (uint bits = 0; bits < 7; bits++) {
bool disable = bits >= _settings_game.station.station_spread;
if (statspec == NULL) {
if (statspec == nullptr) {
this->SetWidgetDisabledState(bits + WID_BRAS_PLATFORM_NUM_1, disable);
this->SetWidgetDisabledState(bits + WID_BRAS_PLATFORM_LEN_1, disable);
} else {
@@ -1226,6 +1229,7 @@ public:
this->DrawWidgets();
if (this->IsShaded()) return;
/* 'Accepts' and 'Supplies' texts. */
NWidgetBase *cov = this->GetWidget<NWidgetBase>(WID_BRAS_COVERAGE_TEXTS);
int top = cov->pos_y + WD_PAR_VSEP_NORMAL;
@@ -1243,7 +1247,7 @@ public:
}
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_BRAS_NEWST_LIST: {
@@ -1274,7 +1278,7 @@ public:
StationClass *stclass = StationClass::Get(statclass);
for (uint16 j = 0; j < stclass->GetSpecCount(); j++) {
const StationSpec *statspec = stclass->GetSpec(j);
SetDParam(0, (statspec != NULL && statspec->name != 0) ? statspec->name : STR_STATION_CLASS_DFLT);
SetDParam(0, (statspec != nullptr && statspec->name != 0) ? statspec->name : STR_STATION_CLASS_DFLT);
d = maxdim(d, GetStringBoundingBox(str));
}
}
@@ -1300,7 +1304,7 @@ public:
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
DrawPixelInfo tmp_dpi;
@@ -1374,22 +1378,22 @@ public:
}
}
virtual void OnResize()
void OnResize() override
{
if (this->vscroll != NULL) { // New stations available.
if (this->vscroll != nullptr) { // New stations available.
this->vscroll->SetCapacityFromWidget(this, WID_BRAS_NEWST_LIST);
}
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
if (widget == WID_BRAS_SHOW_NEWST_TYPE) {
const StationSpec *statspec = StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type);
SetDParam(0, (statspec != NULL && statspec->name != 0) ? statspec->name : STR_STATION_CLASS_DFLT);
SetDParam(0, (statspec != nullptr && statspec->name != 0) ? statspec->name : STR_STATION_CLASS_DFLT);
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (GB(widget, 0, 16)) {
case WID_BRAS_PLATFORM_DIR_X:
@@ -1417,8 +1421,8 @@ public:
_settings_client.gui.station_dragdrop = false;
const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : NULL;
if (statspec != NULL && HasBit(statspec->disallowed_lengths, _settings_client.gui.station_platlength - 1)) {
const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : nullptr;
if (statspec != nullptr && HasBit(statspec->disallowed_lengths, _settings_client.gui.station_platlength - 1)) {
/* The previously selected number of platforms in invalid */
for (uint i = 0; i < 7; i++) {
if (!HasBit(statspec->disallowed_lengths, i)) {
@@ -1452,8 +1456,8 @@ public:
_settings_client.gui.station_dragdrop = false;
const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : NULL;
if (statspec != NULL && HasBit(statspec->disallowed_platforms, _settings_client.gui.station_numtracks - 1)) {
const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : nullptr;
if (statspec != nullptr && HasBit(statspec->disallowed_platforms, _settings_client.gui.station_numtracks - 1)) {
/* The previously selected number of tracks in invalid */
for (uint i = 0; i < 7; i++) {
if (!HasBit(statspec->disallowed_platforms, i)) {
@@ -1478,8 +1482,8 @@ public:
this->ToggleWidgetLoweredState(WID_BRAS_PLATFORM_DRAG_N_DROP);
/* get the first allowed length/number of platforms */
const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : NULL;
if (statspec != NULL && HasBit(statspec->disallowed_lengths, _settings_client.gui.station_platlength - 1)) {
const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : nullptr;
if (statspec != nullptr && HasBit(statspec->disallowed_lengths, _settings_client.gui.station_platlength - 1)) {
for (uint i = 0; i < 7; i++) {
if (!HasBit(statspec->disallowed_lengths, i)) {
this->RaiseWidget(_settings_client.gui.station_platlength + WID_BRAS_PLATFORM_LEN_BEGIN);
@@ -1488,7 +1492,7 @@ public:
}
}
}
if (statspec != NULL && HasBit(statspec->disallowed_platforms, _settings_client.gui.station_numtracks - 1)) {
if (statspec != nullptr && HasBit(statspec->disallowed_platforms, _settings_client.gui.station_numtracks - 1)) {
for (uint i = 0; i < 7; i++) {
if (!HasBit(statspec->disallowed_platforms, i)) {
this->RaiseWidget(_settings_client.gui.station_numtracks + WID_BRAS_PLATFORM_NUM_BEGIN);
@@ -1565,7 +1569,7 @@ public:
}
}
virtual void OnRealtimeTick(uint delta_ms)
void OnRealtimeTick(uint delta_ms) override
{
CheckRedrawStationCoverage(this);
}
@@ -1575,6 +1579,7 @@ static const NWidgetPart _nested_station_builder_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_RAIL_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_BRAS_SHOW_NEWST_DEFSIZE),
NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
EndContainer(),
@@ -1718,7 +1723,7 @@ public:
_convert_signal_button = false;
}
virtual void OnInit()
void OnInit() override
{
/* Calculate maximum signal sprite size. */
this->sig_sprite_size.width = 0;
@@ -1738,7 +1743,7 @@ public:
}
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
if (widget == WID_BS_DRAG_SIGNALS_DENSITY_LABEL) {
/* Two digits for signals density. */
@@ -1749,7 +1754,7 @@ public:
}
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_BS_DRAG_SIGNALS_DENSITY_LABEL:
@@ -1758,7 +1763,7 @@ public:
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
if (IsInsideMM(widget, WID_BS_SEMAPHORE_NORM, WID_BS_ELECTRIC_PBS_OWAY + 1)) {
/* Extract signal from widget number. */
@@ -1770,7 +1775,7 @@ public:
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_BS_SEMAPHORE_NORM:
@@ -1793,7 +1798,7 @@ public:
/* If 'remove' button of rail build toolbar is active, disable it. */
if (_remove_button_clicked) {
Window *w = FindWindowById(WC_BUILD_TOOLBAR, TRANSPORT_RAIL);
if (w != NULL) ToggleRailButton_Remove(w);
if (w != nullptr) ToggleRailButton_Remove(w);
}
break;
@@ -1827,7 +1832,7 @@ public:
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
this->LowerWidget((_cur_signal_variant == SIG_ELECTRIC ? WID_BS_ELECTRIC_NORM : WID_BS_SEMAPHORE_NORM) + _cur_signal_type);
@@ -1899,7 +1904,7 @@ struct BuildRailDepotWindow : public PickerWindowBase {
this->LowerWidget(_build_depot_direction + WID_BRAD_DEPOT_NE);
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_BRAD_DEPOT_NE:
@@ -1916,14 +1921,14 @@ struct BuildRailDepotWindow : public PickerWindowBase {
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
if (!IsInsideMM(widget, WID_BRAD_DEPOT_NE, WID_BRAD_DEPOT_NW + 1)) return;
DrawTrainDepotSprite(r.left + 1 + ScaleGUITrad(31), r.bottom - ScaleGUITrad(31), widget - WID_BRAD_DEPOT_NE + DIAGDIR_NE, _cur_railtype);
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_BRAD_DEPOT_NE:
@@ -1979,7 +1984,7 @@ static const NWidgetPart _nested_build_depot_widgets[] = {
};
static WindowDesc _build_depot_desc(
WDP_AUTO, NULL, 0, 0,
WDP_AUTO, nullptr, 0, 0,
WC_BUILD_DEPOT, WC_BUILD_TOOLBAR,
WDF_CONSTRUCTION,
_nested_build_depot_widgets, lengthof(_nested_build_depot_widgets)
@@ -2004,7 +2009,7 @@ struct BuildRailWaypointWindow : PickerWindowBase {
matrix->SetClicked(_cur_waypoint_type);
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_BRW_WAYPOINT_MATRIX:
@@ -2023,7 +2028,7 @@ struct BuildRailWaypointWindow : PickerWindowBase {
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (GB(widget, 0, 16)) {
case WID_BRW_WAYPOINT: {
@@ -2038,7 +2043,7 @@ struct BuildRailWaypointWindow : PickerWindowBase {
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (GB(widget, 0, 16)) {
case WID_BRW_WAYPOINT: {
@@ -2107,7 +2112,7 @@ void ReinitGuiAfterToggleElrail(bool disable)
if (disable && _last_built_railtype == RAILTYPE_ELECTRIC) {
_last_built_railtype = _cur_railtype = RAILTYPE_RAIL;
BuildRailToolbarWindow *w = dynamic_cast<BuildRailToolbarWindow *>(FindWindowById(WC_BUILD_TOOLBAR, TRANSPORT_RAIL));
if (w != NULL) w->ModifyRailType(_cur_railtype);
if (w != nullptr) w->ModifyRailType(_cur_railtype);
}
MarkWholeScreenDirty();
}
@@ -2154,7 +2159,7 @@ static void SetDefaultRailGui()
_last_built_railtype = _cur_railtype = rt;
BuildRailToolbarWindow *w = dynamic_cast<BuildRailToolbarWindow *>(FindWindowById(WC_BUILD_TOOLBAR, TRANSPORT_RAIL));
if (w != NULL) w->ModifyRailType(_cur_railtype);
if (w != nullptr) w->ModifyRailType(_cur_railtype);
}
/**
@@ -2169,7 +2174,7 @@ bool ResetSignalVariant(int32 p)
if (new_variant != _cur_signal_variant) {
Window *w = FindWindowById(WC_BUILD_SIGNAL, 0);
if (w != NULL) {
if (w != nullptr) {
w->SetDirty();
w->RaiseWidget((_cur_signal_variant == SIG_ELECTRIC ? WID_BS_ELECTRIC_NORM : WID_BS_SEMAPHORE_NORM) + _cur_signal_type);
}
@@ -2198,30 +2203,39 @@ void InitializeRailGUI()
* @param all_option Whether to add an 'all types' item.
* @return The populated and sorted #DropDownList.
*/
DropDownList *GetRailTypeDropDownList(bool for_replacement, bool all_option)
DropDownList GetRailTypeDropDownList(bool for_replacement, bool all_option)
{
RailTypes used_railtypes = RAILTYPES_NONE;
/* Find the used railtypes. */
Engine *e;
FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue;
used_railtypes |= GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes;
}
/* Get the date introduced railtypes as well. */
used_railtypes = AddDateIntroducedRailTypes(used_railtypes, MAX_DAY);
RailTypes used_railtypes;
RailTypes avail_railtypes;
const Company *c = Company::Get(_local_company);
DropDownList *list = new DropDownList();
if (all_option) {
DropDownListStringItem *item = new DropDownListStringItem(STR_REPLACE_ALL_RAILTYPE, INVALID_RAILTYPE, false);
*list->Append() = item;
/* Find the used railtypes. */
if (for_replacement) {
avail_railtypes = GetCompanyRailtypes(c->index, false);
used_railtypes = GetRailTypes(false);
} else {
avail_railtypes = c->avail_railtypes;
used_railtypes = GetRailTypes(true);
}
DropDownList list;
if (all_option) {
list.emplace_back(new DropDownListStringItem(STR_REPLACE_ALL_RAILTYPE, INVALID_RAILTYPE, false));
}
Dimension d = { 0, 0 };
RailType rt;
/* Get largest icon size, to ensure text is aligned on each menu item. */
if (!for_replacement) {
FOR_ALL_SORTED_RAILTYPES(rt) {
if (!HasBit(used_railtypes, rt)) continue;
const RailtypeInfo *rti = GetRailTypeInfo(rt);
d = maxdim(d, GetSpriteSize(rti->gui_sprites.build_x_rail));
}
}
FOR_ALL_SORTED_RAILTYPES(rt) {
/* If it's not used ever, don't show it to the user. */
if (!HasBit(used_railtypes, rt)) continue;
@@ -2229,10 +2243,23 @@ DropDownList *GetRailTypeDropDownList(bool for_replacement, bool all_option)
const RailtypeInfo *rti = GetRailTypeInfo(rt);
StringID str = for_replacement ? rti->strings.replace_text : (rti->max_speed > 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY : STR_JUST_STRING);
DropDownListParamStringItem *item = new DropDownListParamStringItem(str, rt, !HasBit(c->avail_railtypes, rt));
DropDownListParamStringItem *item;
if (for_replacement) {
item = new DropDownListParamStringItem(str, rt, !HasBit(avail_railtypes, rt));
} else {
DropDownListIconItem *iconitem = new DropDownListIconItem(rti->gui_sprites.build_x_rail, PAL_NONE, str, rt, !HasBit(avail_railtypes, rt));
iconitem->SetDimension(d);
item = iconitem;
}
item->SetParam(0, rti->strings.menu_text);
item->SetParam(1, rti->max_speed);
*list->Append() = item;
list.emplace_back(item);
}
if (list.size() == 0) {
/* Empty dropdowns are not allowed */
list.emplace_back(new DropDownListStringItem(STR_NONE, INVALID_RAILTYPE, true));
}
return list;
}