71static const StringID _start_replace_dropdown[] = {
72 STR_REPLACE_VEHICLES_NOW,
73 STR_REPLACE_VEHICLES_WHEN_OLD,
109 if (
rvi->railtype !=
this->sel_railtype)
return false;
138 if (
e->u.road.roadtype !=
this->sel_roadtype)
continue;
185 this->engines[
side].clear();
189 this->engines[
side].swap(list);
198 if (this->engines[0].NeedRebuild()) {
201 this->vscroll[0]->
SetCount(this->engines[0].size());
202 if (this->reset_sel_engine && this->sel_engine[0] ==
INVALID_ENGINE && !this->engines[0].empty()) {
203 this->sel_engine[0] = this->engines[0][0].engine_id;
207 if (this->engines[1].NeedRebuild() ||
e != this->sel_engine[0]) {
211 this->engines[1].clear();
213 this->vscroll[1]->
SetCount(this->engines[1].size());
215 if (this->reset_sel_engine && this->sel_engine[0] !=
INVALID_ENGINE) {
222 this->vscroll[1]->
SetCount(this->engines[1].size());
223 if (this->reset_sel_engine && this->sel_engine[1] !=
INVALID_ENGINE) {
225 for (
const auto &item : this->engines[1]) {
226 if (item.engine_id ==
this->sel_engine[1])
break;
236 this->reset_sel_engine =
false;
261 this->reset_sel_engine =
true;
270 this->replace_engines =
true;
273 this->reset_sel_engine =
true;
286 widget->
SetLowered(this->show_hidden_engines);
292 this->sel_group =
id_g;
301 d.height += padding.height;
309 size.height = (this->window_number <=
VEH_ROAD ? 8 : 4) *
resize.height;
323 d.width += padding.width;
324 d.height += padding.height;
332 d.width += padding.width;
333 d.height += padding.height;
341 d.width += padding.width;
342 d.height += padding.height;
349 for (
const RailType &
rt : _sorted_railtypes) {
352 d.width += padding.width;
353 d.height += padding.height;
360 for (
const RoadType &
rt : _sorted_roadtypes) {
363 d.width += padding.width;
364 d.height += padding.height;
372 d.width += padding.width;
373 d.height += padding.height;
385 switch (this->sel_group) {
475 if (this->engines[0].NeedRebuild() || this->engines[1].NeedRebuild()) this->
GenerateLists();
501 ted.FillDefaultCapacities(
e);
521 this->descending_sort_order ^=
true;
528 this->show_hidden_engines ^=
true;
552 ShowDropDownList(
this, GetRoadTypeDropDownList(RTTB_ROAD | RTTB_TRAM,
true,
true), this->sel_roadtype, widget);
595 const auto &item = *it;
623 this->reset_sel_engine =
true;
635 if (this->sort_criteria != index) {
636 this->sort_criteria = index;
645 if (
temp == this->sel_railtype)
return;
646 this->sel_railtype =
temp;
653 if (
temp == this->sel_roadtype)
return;
654 this->sel_roadtype =
temp;
660 this->replace_engines = index != 0;
662 this->reset_sel_engine =
true;
708static constexpr NWidgetPart _nested_replace_rail_vehicle_widgets[] = {
718 NWidget(
WWT_LABEL, COLOUR_GREY),
SetDataTip(STR_REPLACE_VEHICLE_VEHICLES_IN_USE, STR_REPLACE_VEHICLE_VEHICLES_IN_USE_TOOLTIP),
SetFill(1, 1),
SetMinimalTextLines(1,
WidgetDimensions::unscaled.framerect.Vertical()),
SetResize(1, 0),
721 NWidget(
WWT_LABEL, COLOUR_GREY),
SetDataTip(STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES, STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES_TOOLTIP),
SetFill(1, 1),
SetMinimalTextLines(1,
WidgetDimensions::unscaled.framerect.Vertical()),
SetResize(1, 0),
727 NWidget(
WWT_DROPDOWN, COLOUR_GREY,
WID_RV_RAIL_TYPE_DROPDOWN),
SetMinimalSize(136, 12),
SetDataTip(STR_JUST_STRING, STR_REPLACE_HELP_RAILTYPE),
SetFill(1, 0),
SetResize(1, 0),
744 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_RV_LEFT_MATRIX),
SetMinimalSize(216, 0),
SetFill(1, 1),
SetMatrixDataTip(1, 0, STR_REPLACE_HELP_LEFT_ARRAY),
SetResize(1, 1),
SetScrollbar(
WID_RV_LEFT_SCROLLBAR),
746 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_RV_RIGHT_MATRIX),
SetMinimalSize(216, 0),
SetFill(1, 1),
SetMatrixDataTip(1, 0, STR_REPLACE_HELP_RIGHT_ARRAY),
SetResize(1, 1),
SetScrollbar(
WID_RV_RIGHT_SCROLLBAR),
753 NWidget(
WWT_PUSHTXTBTN, COLOUR_GREY,
WID_RV_TRAIN_WAGONREMOVE_TOGGLE),
SetMinimalSize(138, 12),
SetDataTip(STR_REPLACE_REMOVE_WAGON, STR_REPLACE_REMOVE_WAGON_HELP),
SetFill(1, 0),
SetResize(1, 0),
766 WDP_AUTO,
"replace_vehicle_train", 500, 140,
769 _nested_replace_rail_vehicle_widgets
772static constexpr NWidgetPart _nested_replace_road_vehicle_widgets[] = {
782 NWidget(
WWT_LABEL, COLOUR_GREY),
SetDataTip(STR_REPLACE_VEHICLE_VEHICLES_IN_USE, STR_REPLACE_VEHICLE_VEHICLES_IN_USE_TOOLTIP),
SetFill(1, 1),
SetMinimalTextLines(1,
WidgetDimensions::unscaled.framerect.Vertical()),
SetResize(1, 0),
785 NWidget(
WWT_LABEL, COLOUR_GREY),
SetDataTip(STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES, STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES_TOOLTIP),
SetFill(1, 1),
SetMinimalTextLines(1,
WidgetDimensions::unscaled.framerect.Vertical()),
SetResize(1, 0),
790 NWidget(
WWT_DROPDOWN, COLOUR_GREY,
WID_RV_ROAD_TYPE_DROPDOWN),
SetMinimalSize(136, 12),
SetDataTip(STR_JUST_STRING, STR_REPLACE_HELP_ROADTYPE),
SetFill(1, 0),
SetResize(1, 0),
805 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_RV_LEFT_MATRIX),
SetMinimalSize(216, 0),
SetFill(1, 1),
SetMatrixDataTip(1, 0, STR_REPLACE_HELP_LEFT_ARRAY),
SetResize(1, 1),
SetScrollbar(
WID_RV_LEFT_SCROLLBAR),
807 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_RV_RIGHT_MATRIX),
SetMinimalSize(216, 0),
SetFill(1, 1),
SetMatrixDataTip(1, 0, STR_REPLACE_HELP_RIGHT_ARRAY),
SetResize(1, 1),
SetScrollbar(
WID_RV_RIGHT_SCROLLBAR),
824 WDP_AUTO,
"replace_vehicle_road", 500, 140,
827 _nested_replace_road_vehicle_widgets
830static constexpr NWidgetPart _nested_replace_vehicle_widgets[] = {
840 NWidget(
WWT_LABEL, COLOUR_GREY),
SetDataTip(STR_REPLACE_VEHICLE_VEHICLES_IN_USE, STR_REPLACE_VEHICLE_VEHICLES_IN_USE_TOOLTIP),
SetFill(1, 1),
SetMinimalTextLines(1,
WidgetDimensions::unscaled.framerect.Vertical()),
SetResize(1, 0),
843 NWidget(
WWT_LABEL, COLOUR_GREY),
SetDataTip(STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES, STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES_TOOLTIP),
SetFill(1, 1),
SetMinimalTextLines(1,
WidgetDimensions::unscaled.framerect.Vertical()),
SetResize(1, 0),
860 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_RV_LEFT_MATRIX),
SetMinimalSize(216, 0),
SetFill(1, 1),
SetMatrixDataTip(1, 0, STR_REPLACE_HELP_LEFT_ARRAY),
SetResize(1, 1),
SetScrollbar(
WID_RV_LEFT_SCROLLBAR),
862 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_RV_RIGHT_MATRIX),
SetMinimalSize(216, 0),
SetFill(1, 1),
SetMatrixDataTip(1, 0, STR_REPLACE_HELP_RIGHT_ARRAY),
SetResize(1, 1),
SetScrollbar(
WID_RV_RIGHT_SCROLLBAR),
871 NWidget(
WWT_PANEL, COLOUR_GREY,
WID_RV_INFO_TAB),
SetMinimalSize(167, 12),
SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB),
SetResize(1, 0),
EndContainer(),
878 WDP_AUTO,
"replace_vehicle", 456, 118,
881 _nested_replace_vehicle_widgets
892 switch (vehicletype) {
bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company)
Checks some basic properties whether autoreplace is allowed.
Command definitions related to autoreplace.
Functions related to autoreplacing.
bool EngineHasReplacementWhenOldForCompany(const Company *c, EngineID engine, GroupID group)
Check if a company has a replacement set up for the given engine when it gets old.
EngineID EngineReplacementForCompany(const Company *c, EngineID engine, GroupID group, bool *replace_when_old=nullptr)
Retrieve the engine replacement for the given company and original engine type.
bool EngineHasReplacementForCompany(const Company *c, EngineID engine, GroupID group)
Check if a company has a replacement set up for the given engine.
void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
Show the autoreplace configuration window for a particular group.
void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g)
Rebuild the left autoreplace list if an engine is removed or added.
void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type)
When an engine is made buildable or is removed from being buildable, add/remove it from the build/aut...
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
void GUIEngineListAddChildren(GUIEngineList &dst, const GUIEngineList &src, EngineID parent, uint8_t indent)
Add children to GUI engine list to build a hierarchical tree.
bool _engine_sort_last_order[]
Last set direction of the sort order, for each vehicle type.
uint GetEngineListHeight(VehicleType type)
Get the height of a single 'entry' in the engine lists.
const std::initializer_list< const StringID > _engine_sort_listing[]
Dropdown menu strings for the vehicle sort criteria.
uint8_t _engine_sort_last_criteria[]
Last set sort criteria, for each vehicle type.
int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number, TestedEngineDetails &te)
Draw the purchase info details of a vehicle at a given location.
EngList_SortTypeFunction *const _engine_sort_functions[][11]
Sort functions for the vehicle sort criteria, for each vehicle type.
void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selected, WidgetID button)
Display the dropdown for the vehicle sort criteria.
bool _engine_sort_direction
false = descending, true = ascending.
bool _engine_sort_show_hidden_engines[]
Last set 'show hidden engines' setting for each vehicle type.
void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, const Scrollbar &sb, EngineID selected_id, bool show_count, GroupID selected_group)
Engine drawing loop.
void RebuildDone()
Notify the sortlist that the rebuild is done.
void ForceRebuild()
Force that a rebuild is needed.
struct RailTypeInfo::@26 strings
Strings associated with the rail type.
StringID replace_text
Text used in the autoreplace GUI.
Window for the autoreplacing of vehicles.
void OnResize() override
Called after the window got resized.
bool GenerateReplaceRailList(EngineID e, bool draw_left, bool show_engines)
Figure out if an engine should be added to a list.
void OnDropdownSelect(WidgetID widget, int index) override
A dropdown option associated to this window has been selected.
GUIEngineList engines[2]
Left and right list of engines.
EngineID sel_engine[2]
Selected engine left and right.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void ReplaceClick_StartReplace(bool replace_when_old)
Handle click on the start replace button.
bool OnTooltip(Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
Event to display a custom tooltip.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
uint8_t sort_criteria
Criteria of sorting vehicles.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
RailType sel_railtype
Type of rail tracks selected. INVALID_RAILTYPE to show all.
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 SetStringParameters(WidgetID widget) const override
Initialize string parameters for a widget.
bool replace_engines
If true, engines are replaced, if false, wagons are replaced (only for trains).
bool reset_sel_engine
Also reset sel_engine while updating left and/or right and no valid engine selected.
void OnPaint() override
The window must be repainted.
bool show_hidden_engines
Whether to show the hidden engines.
void GenerateLists()
Generate the lists.
RoadType sel_roadtype
Type of road selected. INVALID_ROADTYPE to show all.
int details_height
Minimal needed height of the details panels, in text lines (found so far).
void GenerateReplaceVehList(bool draw_left)
Generate an engines list.
GroupID sel_group
Group selected to replace.
bool descending_sort_order
Order of sorting vehicles.
void OnRailRoadTypeChange()
Perform tasks after rail or road type is changed.
StringID replace_text
Text used in the autoreplace GUI.
struct RoadTypeInfo::@29 strings
Strings associated with the rail type.
Functions related to commands.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
void ShowDropDownMenu(Window *w, std::span< const StringID > strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
Show a drop down list.
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.
@ HasVariants
Set if engine has variants.
@ IsFolded
Set if display of variants should be folded (hidden).
@ Shaded
Set if engine should be masked.
void EngList_Sort(GUIEngineList &el, EngList_SortTypeFunction compare)
Sort all items using quick sort and given 'CompareItems' function.
Engine GUI functions, used by build_vehicle_gui and autoreplace_gui
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
uint16_t EngineID
Unique identification number of an engine.
uint64_t PackEngineNameDParam(EngineID engine_id, EngineNameContext context, uint32_t extra_data=0)
Combine an engine ID and a name context to an engine name dparam.
@ PurchaseList
Name is shown in the purchase list (including autoreplace window 'Available vehicles' panel).
@ RAILVEH_WAGON
simple wagon, not motorized
debug_inline constexpr bool HasFlag(const T x, const T y)
Checks if a value in a bitset enum is set.
fluid_settings_t * settings
FluidSynth settings handle.
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.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Dimension GetStringListBoundingBox(std::span< const StringID > list, FontSize fontsize)
Get maximum dimension of a list of strings.
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
bool _ctrl_pressed
Is Ctrl pressed?
@ SA_HOR_CENTER
Horizontally center the text.
@ FS_NORMAL
Index of the normal font in the font tables.
@ GF_REPLACE_WAGON_REMOVAL
If set, autoreplace will perform wagon removal on vehicles in this group.
uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e)
Get the number of engines with EngineID id_e in the group with GroupID id_g and its sub-groups.
Command definitions related to engine groups.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
uint16_t GroupID
Type for all group identifiers.
static const GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
static const GroupID ALL_GROUP
All vehicles are in this group.
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
void GuiShowTooltips(Window *parent, StringID str, TooltipCloseCondition close_tooltip, uint paramcount)
Shows a tooltip.
Functions for NewGRF engines.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
DropDownList GetRailTypeDropDownList(bool for_replacement, bool all_option)
Create a drop down list for all the rail types of the local company.
RailType
Enumeration for all possible railtypes.
@ INVALID_RAILTYPE
Flag for invalid railtype.
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Functions/types related to the road GUIs.
RoadType
The different roadtypes we support.
@ INVALID_ROADTYPE
flag for invalid roadtype
A number of safeguards to prevent using unsafe methods.
Command definitions related to settings.
Functions related to setting/changing the settings.
Definition of base types and functions in a cross-platform compatible way.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
TextDirection _current_text_dir
Text direction of the currently selected language.
Functions related to OTTD's strings.
@ TD_RTL
Text is written right-to-left by default.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
CompanySettings settings
settings specific for each company
bool renew_keep_length
sell some wagons if after autoreplace the train is longer than before
Dimensions (a width and height) of a rectangle in 2D.
static Pool::IterateWrapperFiltered< Engine, EngineTypeFilter > IterateType(VehicleType vt, size_t from=0)
Returns an iterable ensemble of all valid engines of the given type.
EngineDisplayFlags display_flags
NOSAVE client-side-only display flags for build engine list.
EngineID engine_id
Engine to display in build purchase list.
uint8_t flags
Group flags.
Coordinates of a point in 2D.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
static Titem * Get(size_t index)
Returns Titem with given index.
Information about a rail vehicle.
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Extra information about refitted cargo and capacity.
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.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
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.
Window * parent
Parent window.
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
ResizeInfo resize
Resize information.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
bool IsShaded() const
Is window shaded currently?
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
void HandleButtonClick(WidgetID widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
WindowNumber window_number
Window number within the window class.
Functions related to the vehicle's GUIs.
VehicleType
Available vehicle types.
@ VEH_ROAD
Road vehicle type.
@ VEH_TRAIN
Train vehicle type.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ SBS_DOWN
Sort ascending.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
@ WDP_AUTO
Find a place automatically.
@ WC_REPLACE_VEHICLE
Replace vehicle window; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ WC_BUILD_VEHICLE
Build vehicle; Window numbers: