|
OpenTTD Source
14.0-beta1
|
Go to the documentation of this file.
43 #include "table/strings.h"
57 static constexpr
NWidgetPart _nested_build_vehicle_widgets[] = {
75 NWidget(
WWT_EDITBOX, COLOUR_GREY,
WID_BV_FILTER),
SetResize(1, 0),
SetFill(1, 0),
SetPadding(2),
SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
80 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_BV_LIST),
SetResize(1, 1),
SetFill(1, 0),
SetMatrixDataTip(1, 0, STR_NULL),
SetScrollbar(
WID_BV_SCROLLBAR),
126 const auto r = va - vb;
144 static std::string last_name[2] = { {}, {} };
149 last_name[0] =
GetString(STR_ENGINE_NAME);
155 last_name[1] =
GetString(STR_ENGINE_NAME);
175 const int r = va - vb;
192 int r = ClampTo<int32_t>(va - vb);
260 int r = ClampTo<int32_t>(va - vb);
296 double v_a = (double)p_a / (
double)r_a;
297 double v_b = (double)p_b / (
double)r_b;
339 int r = val_a - val_b;
400 uint16_t mail_a, mail_b;
488 STR_SORT_BY_ENGINE_ID,
490 STR_SORT_BY_MAX_SPEED,
492 STR_SORT_BY_TRACTIVE_EFFORT,
493 STR_SORT_BY_INTRO_DATE,
495 STR_SORT_BY_RUNNING_COST,
496 STR_SORT_BY_POWER_VS_RUNNING_COST,
497 STR_SORT_BY_RELIABILITY,
498 STR_SORT_BY_CARGO_CAPACITY,
502 STR_SORT_BY_ENGINE_ID,
504 STR_SORT_BY_MAX_SPEED,
506 STR_SORT_BY_TRACTIVE_EFFORT,
507 STR_SORT_BY_INTRO_DATE,
509 STR_SORT_BY_RUNNING_COST,
510 STR_SORT_BY_POWER_VS_RUNNING_COST,
511 STR_SORT_BY_RELIABILITY,
512 STR_SORT_BY_CARGO_CAPACITY,
516 STR_SORT_BY_ENGINE_ID,
518 STR_SORT_BY_MAX_SPEED,
519 STR_SORT_BY_INTRO_DATE,
521 STR_SORT_BY_RUNNING_COST,
522 STR_SORT_BY_RELIABILITY,
523 STR_SORT_BY_CARGO_CAPACITY,
527 STR_SORT_BY_ENGINE_ID,
529 STR_SORT_BY_MAX_SPEED,
530 STR_SORT_BY_INTRO_DATE,
532 STR_SORT_BY_RUNNING_COST,
533 STR_SORT_BY_RELIABILITY,
534 STR_SORT_BY_CARGO_CAPACITY,
571 static int DrawCargoCapacityInfo(
int left,
int right,
int y,
TestedEngineDetails &te,
bool refittable)
579 SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
580 DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
596 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
599 DrawString(left, right, y, STR_PURCHASE_INFO_COST);
607 DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
615 DrawString(left, right, y, STR_PURCHASE_INFO_SPEED);
621 if (rvi->running_cost_class != INVALID_PRICE) {
640 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_WEIGHT);
644 DrawString(left, right, y, STR_PURCHASE_INFO_COST_WEIGHT);
651 DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_POWER);
657 DrawString(left, right, y, STR_PURCHASE_INFO_MAX_TE);
662 if (rvi->running_cost_class != INVALID_PRICE) {
672 DrawString(left, right, y, STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT);
689 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
692 DrawString(left, right, y, STR_PURCHASE_INFO_COST);
700 DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
706 DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_POWER);
711 DrawString(left, right, y, STR_PURCHASE_INFO_MAX_TE);
719 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
723 DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
746 if (ocean_speed == canal_speed) {
751 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
755 DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
762 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
765 DrawString(left, right, y, STR_PURCHASE_INFO_COST);
770 DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_OCEAN);
774 DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_CANAL);
781 SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
782 DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
811 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
815 DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
825 DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_CAPACITY);
831 SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
832 DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
843 DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_TYPE);
850 DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_RANGE);
866 if (callback ==
CALLBACK_FAILED || callback == 0x400)
return std::nullopt;
868 assert(grffile !=
nullptr);
869 if (callback > 0x400) {
895 void TestedEngineDetails::FillDefaultCapacities(
const Engine *e)
921 bool articulated_cargo =
false;
924 default: NOT_REACHED();
927 y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, &e->u.rail, te);
929 y = DrawRailEnginePurchaseInfo(left, right, y, engine_number, &e->u.rail, te);
931 articulated_cargo =
true;
935 y = DrawRoadVehPurchaseInfo(left, right, y, engine_number, te);
936 articulated_cargo =
true;
940 y = DrawShipPurchaseInfo(left, right, y, engine_number, refittable, te);
948 if (articulated_cargo) {
950 int new_y = DrawCargoCapacityInfo(left, right, y, te, refittable);
955 DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
967 DrawString(left, right, y, STR_PURCHASE_INFO_DESIGNED_LIFE);
972 DrawString(left, right, y, STR_PURCHASE_INFO_RELIABILITY);
1005 static const int sprite_y_offsets[] = { -1, -1, -2, -2 };
1008 assert(max <= eng_list.size());
1014 int sprite_width = sprite_left + sprite_right;
1022 int count_width = 0;
1026 uint biggest_num_engines = 0;
1027 for (
auto i = min; i < max; i++) {
1028 const auto &item = eng_list[i];
1030 biggest_num_engines = std::max(biggest_num_engines, num_engines);
1044 int replace_icon_y_offset = (ir.
Height() - replace_icon.height) / 2;
1047 for (; min < max; min++, y += step_size) {
1048 const auto &item = eng_list[min];
1058 StringID str = hidden ? STR_HIDDEN_ENGINE_NAME : STR_ENGINE_NAME;
1068 DrawString(itr.left, itr.right, y + normal_text_y_offset, str, tc);
1078 DrawSpriteIgnorePadding(is_folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, {fr.left, y, fr.right, y + ir.
Height() - 1},
SA_CENTER);
1084 bool continues = (min + 1U) < eng_list.size() && eng_list[min + 1].indent == item.indent;
1100 uint32_t hidden_mask = 0;
1141 void SetBuyVehicleText()
1159 for (
const auto &item : source) {
1160 if (item.variant_id !=
parent || item.engine_id ==
parent)
continue;
1173 AddChildren(source, item.engine_id, indent + 1);
1180 this->vehicle_type = type;
1182 this->
window_number = this->listview_mode ? (int)type : tile.base();
1201 widget->
tool_tip = STR_BUY_VEHICLE_TRAIN_LIST_TOOLTIP + type;
1204 widget->
tool_tip = STR_BUY_VEHICLE_TRAIN_HIDE_SHOW_TOGGLE_TOOLTIP + type;
1207 widget->
widget_data = STR_BUY_VEHICLE_TRAIN_RENAME_BUTTON + type;
1208 widget->
tool_tip = STR_BUY_VEHICLE_TRAIN_RENAME_TOOLTIP + type;
1211 widget->
widget_data = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + type;
1212 widget->
tool_tip = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + type;
1213 widget->
SetLowered(this->show_hidden_engines);
1215 this->details_height = ((this->vehicle_type ==
VEH_TRAIN) ? 10 : 9);
1229 this->GenerateBuildList();
1233 auto it = std::find_if(this->eng_list.begin(), this->eng_list.end(), [&](
GUIEngineListItem &item){ return (item.flags & EngineDisplayFlags::Shaded) == EngineDisplayFlags::None; });
1234 if (it != this->eng_list.end()) engine = it->engine_id;
1235 this->SelectEngine(engine);
1241 switch (this->vehicle_type) {
1242 default: NOT_REACHED();
1244 if (this->listview_mode) {
1252 if (this->listview_mode) {
1294 this->sel_engine = engine;
1295 this->SetBuyVehicleText();
1301 if (!this->listview_mode) {
1304 if (ret.Succeeded()) {
1306 this->te.
capacity = refit_capacity;
1316 this->te.FillDefaultCapacities(e);
1327 this->eng_list.
Filter(this->cargo_filter_criteria);
1328 if (0 == this->eng_list.size()) {
1330 }
else if (std::find(this->eng_list.begin(), this->eng_list.end(), this->sel_engine) == this->eng_list.end()) {
1331 this->SelectEngine(this->eng_list[0].engine_id);
1346 if (this->string_filter.
IsEmpty())
return true;
1355 if (text) this->string_filter.
AddLine(*text);
1357 return this->string_filter.
GetState();
1363 std::vector<EngineID> variants;
1365 size_t num_engines = 0;
1394 variants.push_back(
parent);
1398 if (eid == this->sel_engine) sel_id = eid;
1402 for (
const auto &variant : variants) {
1403 if (std::find(list.begin(), list.end(), variant) == list.end()) {
1410 this->SelectEngine(sel_id);
1428 void GenerateBuildRoadVehList()
1432 this->eng_list.clear();
1445 if (eid == this->sel_engine) sel_id = eid;
1447 this->SelectEngine(sel_id);
1451 void GenerateBuildShipList()
1454 this->eng_list.clear();
1466 if (eid == this->sel_engine) sel_id = eid;
1468 this->SelectEngine(sel_id);
1472 void GenerateBuildAircraftList()
1476 this->eng_list.clear();
1496 if (eid == this->sel_engine) sel_id = eid;
1499 this->SelectEngine(sel_id);
1503 void GenerateBuildList()
1510 this->eng_list.clear();
1514 switch (this->vehicle_type) {
1515 default: NOT_REACHED();
1517 this->GenerateBuildTrainList(list);
1519 this->eng_list.shrink_to_fit();
1523 this->GenerateBuildRoadVehList();
1526 this->GenerateBuildShipList();
1529 this->GenerateBuildAircraftList();
1536 std::vector<EngineID> variants;
1537 for (
const auto &item : this->eng_list) {
1540 variants.push_back(
parent);
1545 for (
const auto &variant : variants) {
1546 if (std::find(this->eng_list.begin(), this->eng_list.end(), variant) == this->eng_list.end()) {
1555 this->eng_list.swap(list);
1557 this->eng_list.shrink_to_fit();
1558 this->eng_list.RebuildDone();
1579 list.push_back(std::make_unique<DropDownListIconItem>(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index(),
false));
1585 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
1589 this->descending_sort_order ^=
true;
1591 this->eng_list.ForceRebuild();
1596 this->show_hidden_engines ^=
true;
1598 this->eng_list.ForceRebuild();
1606 if (it != this->eng_list.end()) {
1607 const auto &item = *it;
1621 this->SelectEngine(e);
1625 }
else if (click_count > 1 && !this->listview_mode) {
1636 ShowDropDownList(
this, this->BuildCargoDropDownList(), this->cargo_filter_criteria, widget);
1659 bool refresh =
false;
1679 this->rename_engine = sel_eng;
1693 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1695 if (!gui_scope)
return;
1697 if (this->vehicle_type ==
VEH_ROAD &&
1699 this->sort_criteria > 7) {
1700 this->sort_criteria = 0;
1703 this->eng_list.ForceRebuild();
1706 void SetStringParameters(
WidgetID widget)
const override
1710 if (this->vehicle_type ==
VEH_TRAIN && !this->listview_mode) {
1713 }
else if (this->vehicle_type ==
VEH_ROAD && !this->listview_mode) {
1717 SetDParam(0, (this->listview_mode ? STR_VEHICLE_LIST_AVAILABLE_TRAINS : STR_BUY_VEHICLE_TRAIN_ALL_CAPTION) + this->vehicle_type);
1726 SetDParam(0, this->GetCargoFilterLabel(this->cargo_filter_criteria));
1732 SetDParam(0, STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + this->vehicle_type);
1734 SetDParam(0, STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + this->vehicle_type);
1746 size->height = 3 *
resize->height;
1757 d.height += padding.height;
1758 *size =
maxdim(*size, d);
1769 size->width += padding.width;
1770 size->height += padding.height;
1776 size->width += padding.width;
1777 size->height += padding.height;
1782 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
1791 static_cast<uint16_t
>(std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->eng_list.size())),
1806 this->GenerateBuildList();
1807 this->vscroll->
SetCount(this->eng_list.size());
1824 if (needed_height != this->details_height) {
1826 this->details_height = needed_height;
1833 void OnQueryTextFinished(
char *str)
override
1835 if (str ==
nullptr)
return;
1840 void OnDropdownSelect(
WidgetID widget,
int index)
override
1844 if (this->sort_criteria != index) {
1845 this->sort_criteria = index;
1847 this->eng_list.ForceRebuild();
1852 if (this->cargo_filter_criteria != index) {
1853 this->cargo_filter_criteria = index;
1857 this->eng_list.ForceRebuild();
1858 this->SelectEngine(this->sel_engine);
1870 void OnEditboxChanged(
WidgetID wid)
override
1893 static inline HotkeyList hotkeys{
"buildvehicle", {
1898 static WindowDesc _build_vehicle_desc(__FILE__, __LINE__,
1899 WDP_AUTO,
"build_vehicle", 240, 268,
1902 std::begin(_nested_build_vehicle_widgets), std::end(_nested_build_vehicle_widgets),
1903 &BuildVehicleWindow::hotkeys
1912 uint num = (tile ==
INVALID_TILE) ? (
int)type : tile.base();
@ VEH_AIRCRAFT
Aircraft vehicle type.
EngList_SortTypeFunction *const _engine_sort_functions[][11]
Sort functions for the vehicle sort criteria, for each vehicle type.
@ ES_HANDLED
The passed event is handled.
void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selected, WidgetID button)
Display the dropdown for the vehicle sort criteria.
@ TC_FORCED
Ignore colour changes from strings.
CargoTypes _standard_cargo_mask
Bitmask of real cargo types available.
uint16_t pow_wag_power
Extra power applied to consist if wagon should be powered.
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
void OnPaint() override
The window must be repainted.
bool IsVariantHidden(CompanyID c) const
Check whether the engine variant chain is hidden in the GUI for the given company.
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-...
static bool EngineNumberSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by engineID.
byte pow_wag_weight
Extra weight applied to consist if wagon should be powered.
static Pool::IterateWrapperFiltered< Engine, EngineTypeFilter > IterateType(VehicleType vt, size_t from=0)
Returns an iterable ensemble of all valid engines of the given type.
@ HasVariants
Set if engine has variants.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
uint16_t mail_capacity
Mail capacity if available.
int Height() const
Get height of Rect.
static Titem * Get(size_t index)
Returns Titem with given index.
TestedEngineDetails te
Tested cost and capacity after refit.
List of hotkeys for a window.
void SetFocusedWindow(Window *w)
Set the window that has the focus.
bool show_newgrf_name
Show the name of the NewGRF in the build vehicle window.
Dimensions (a width and height) of a rectangle in 2D.
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
static std::optional< std::string > GetNewGRFAdditionalText(EngineID engine)
Try to get the NewGRF engine additional text callback as an optional std::string.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
CargoArray all_capacities
Capacities for all cargoes.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
void SetFilterState(bool state)
Enable or disable the filter.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
VehicleType vehicle_type
Type of vehicles shown in the window.
bool IsEmpty() const
Check whether any filter words were entered.
uint GetDisplayDefaultCapacity(uint16_t *mail_capacity=nullptr) const
Determines the default cargo capacity of an engine for display purposes.
CargoID cargo_filter_criteria
Selected cargo filter.
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
void SetFilterTerm(const char *str)
Set the term to filter on.
bool EngList_SortTypeFunction(const GUIEngineListItem &, const GUIEngineListItem &)
argument type for EngList_Sort.
bool _engine_sort_last_order[]
Last set direction of the sort order, for each vehicle type.
uint GetCount() const
Get the amount of cargos that have an amount.
@ IsFolded
Set if display of variants should be folded (hidden).
uint GetTotalCapacityOfArticulatedParts(EngineID engine)
Get the capacity of an engine with articulated parts.
bool _engine_sort_direction
false = descending, true = ascending.
TimerGameCalendar::Date GetLifeLengthInDays() const
Returns the vehicle's (not model's!) life length in days.
static constexpr CargoID CF_ENGINES
Show only engines (for rail vehicles only)
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
bool _network_server
network-server is active
CargoArray GetCapacityOfArticulatedParts(EngineID engine)
Get the capacity of the parts of a given engine.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
uint GetDisplayMaxTractiveEffort() const
Returns the tractive effort of the engine for display purposes.
Tindex index
Index of this pool item.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
@ EIT_PURCHASE
Vehicle drawn in purchase list, autoreplace gui, ...
void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32_t *values)
Start using the TTDP compatible string code parsing.
Class for storing amounts of cargo.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Money GetRunningCost() const
Return how much the running costs of this engine are.
static bool AircraftRangeSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of aircraft by range.
This struct contains all the info that is needed to draw and construct tracks.
bool wagon_speed_limits
enable wagon speed limits
bool _ctrl_pressed
Is Ctrl pressed?
static bool EngineTractiveEffortSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by tractive effort.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
ClientSettings _settings_client
The current settings for this game.
bool FilterByText(const Engine *e)
Filter by name and NewGRF extra text.
Specification of a cargo type.
uint extend_right
Extend of the cell to the right.
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
GRFConfig * GetGRFConfig(uint32_t grfid, uint32_t mask)
Retrieve a NewGRF from the current config by its grfid.
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
bool descending_sort_order
Sort direction,.
static bool RoadVehEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of road vehicles by capacity.
@ SA_RIGHT
Right align the text (must be a single bit).
void FilterEngineList()
Filter the engine list against the currently selected cargo filter.
@ VEH_ROAD
Road vehicle type.
@ Generic
No specific context available.
struct RailTypeInfo::@26 strings
Strings associated with the rail type.
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
CompanyMask company_hidden
Bit for each company whether the engine is normally hidden in the build gui for that company.
RoadType roadtype
Road type.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
uint32_t GetGRFID() const
Retrieve the GRF ID of the NewGRF the engine is tied to.
PaletteID GetEnginePalette(EngineID engine_type, CompanyID company)
Get the colour map for an engine.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
VehicleCellSize GetVehicleImageCellSize(VehicleType type, EngineImageType image_type)
Get the GUI cell size for a vehicle image.
bool _engine_sort_show_hidden_engines[]
Last set 'show hidden engines' setting for each vehicle type.
static bool EngineIntroDateSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by introduction date.
@ INVALID_ROADTYPE
flag for invalid roadtype
@ BVHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
bool NeedRebuild() const
Check if a rebuild is needed.
Data stored about a string that can be modified in the GUI.
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
uint capacity
Cargo capacity.
char *const buf
buffer in which text is saved
@ QSF_LEN_IN_CHARS
the length of the string is counted in characters
@ CBID_VEHICLE_ADDITIONAL_TEXT
This callback is called from vehicle purchase lists.
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
void CcBuildWagon(Commands cmd, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray, TileIndex tile, EngineID, bool, CargoID, ClientID)
Callback for building wagons.
bool HasPowerOnRoad(RoadType enginetype, RoadType tiletype)
Checks if an engine of the given RoadType got power on a tile with a given RoadType.
bool show_hidden_engines
State of the 'show hidden engines' button.
High level window description.
static bool EnginePowerVsRunningCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by running costs.
uint8_t train_acceleration_model
realistic acceleration for trains
EngineID display_last_variant
NOSAVE client-side-only last variant selected.
uint GetDisplayMaxSpeed() const
Returns max speed of the engine for display purposes.
std::span< const CargoSpec * > _sorted_standard_cargo_specs
Standard cargo specifications sorted alphabetically by name.
Information about a rail vehicle.
const StringID _engine_sort_listing[][12]
Dropdown menu strings for the vehicle sort criteria.
bool EngineHasReplacementForCompany(const Company *c, EngineID engine, GroupID group)
Check if a company has a replacement set up for the given engine.
@ WDP_AUTO
Find a place automatically.
RailType
Enumeration for all possible railtypes.
ResizeInfo resize
Resize information.
CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ors the refit_masks of all articulated parts.
Information about GRF, used in the game and (part of it) in savegames.
@ FS_NORMAL
Index of the normal font in the font tables.
static bool EngineCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by purchase cost.
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
bool listview_mode
If set, only display the available vehicles and do not show a 'build' button.
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.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
TimerGameCalendar::Date intro_date
Date of introduction of the engine.
@ FS_SMALL
Index of the small font in the font tables.
@ ES_NOT_HANDLED
The passed event is not handled.
static constexpr CargoID CF_NONE
Show only items which do not carry cargo (e.g. train engines)
static const uint MAX_LENGTH_ENGINE_NAME_CHARS
The maximum length of an engine name in characters including '\0'.
void CcBuildPrimaryVehicle(Commands, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray)
This is the Callback method after the construction attempt of a primary vehicle.
EngineDisplayFlags display_flags
NOSAVE client-side-only display flags for build engine list.
@ WC_REPLACE_VEHICLE
Replace vehicle window; Window numbers:
static constexpr Year DateToYear(Date date)
Calculate the year of a given date.
@ Shaded
Set if engine should be masked.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
uint GetDisplayWeight() const
Returns the weight of the engine for display purposes.
Window * parent
Parent window.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
static bool ShipEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of ships by capacity.
static YearMonthDay ConvertDateToYMD(Date date)
Converts a Date to a Year, Month & Day.
static int DrawAircraftPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable, TestedEngineDetails &te)
Draw aircraft specific details in the buy window.
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
EngineID rename_engine
Engine being renamed.
WindowFlags flags
Window flags.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
@ AutoreplaceVehicleInUse
Name is show in the autoreplace window 'Vehicles in use' panel.
static const GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
Extra information about refitted cargo and capacity.
@ TC_NO_SHADE
Do not add shading to this text colour.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
bool _networking
are we in networking mode?
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Coordinates of a point in 2D.
int details_height
Minimal needed height of the details panels, in text lines (found so far).
void ShowDropDownMenu(Window *w, 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.
StringID GetGRFStringID(uint32_t grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
Money GetCost() const
Return how much a new engine costs.
byte sort_criteria
Current sort criterium.
byte _engine_sort_last_criteria[]
Last set sort criteria, for each vehicle type.
WindowNumber window_number
Window number within the window class.
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
VehicleType
Available vehicle types.
bool FilterSingleEngine(EngineID eid)
Filter a single engine.
uint16_t reliability
Current reliability of the engine.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
bool IsArticulatedVehicleRefittable(EngineID engine)
Checks whether any of the articulated parts is refittable.
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
StringFilter string_filter
Filter for vehicle name.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
@ RAILVEH_WAGON
simple wagon, not motorized
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
EngineID engine_id
Engine to display in build purchase list.
void EngList_Sort(GUIEngineList &el, EngList_SortTypeFunction compare)
Sort all items using quick sort and given 'CompareItems' function.
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
uint8_t roadveh_acceleration_model
realistic acceleration for road vehicles
void ForceRebuild()
Force that a rebuild is needed.
static bool EngineReliabilitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by reliability.
constexpr uint ToPercent16(uint i)
Converts a "fract" value 0..65535 to "percent" value 0..100.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
static CargoID _engine_sort_last_cargo_criteria[]
Last set filter criteria, for each vehicle type.
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
@ SBS_DOWN
Sort ascending.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
CompanyID _current_company
Company currently doing an action.
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
static bool TrainEnginesThenWagonsSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of train engines by engine / wagon.
static bool EnginePowerSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by power.
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close)
Show a drop down list.
static bool TrainEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of train engines by capacity.
static bool EngineRunningCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by running costs.
bool IsHidden(CompanyID c) const
Check whether the engine is hidden in the GUI for the given company.
bool IsShaded() const
Is window shaded currently?
static const uint MAX_LENGTH_VEHICLE_NAME_CHARS
The maximum length of a vehicle name in characters including '\0'.
EngineDisplayFlags
Flags used client-side in the purchase/autorenew engine list.
static bool CDECL CargoAndEngineFilter(const GUIEngineListItem *item, const CargoID cid)
Filters vehicles by cargo and engine (in case of rail vehicle).
@ WC_BUILD_VEHICLE
Build vehicle; Window numbers:
uint GetPower() const
Returns the power of the engine for display and sorting purposes.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
RoadType roadtype
Road type to show, or INVALID_ROADTYPE.
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...
GUI for building vehicles.
@ RAILVEH_MULTIHEAD
indicates a combination of two locomotives
void ResetState()
Reset the matching state to process a new item.
EngineID variant_id
Engine variant ID. If set, will be treated specially in purchase lists.
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
EventState
State of handling an event.
bool GetState() const
Get the matching state of the current item.
void EngList_SortPartial(GUIEngineList &el, EngList_SortTypeFunction compare, size_t begin, size_t num_items)
Sort selected range of items (on indices @ <begin, begin+num_items-1>)
RoadType
The different roadtypes we support.
StringID name
Name of this type of cargo.
RailType railtype
Railtype, mangled if elrail is disabled.
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
BuildVehicleHotkeys
Enum referring to the Hotkeys in the build vehicle window.
uint16_t GroupID
Type for all group identifiers.
@ INVALID_CLIENT_ID
Client is not part of anything.
RailType railtype
Rail type to show, or INVALID_RAILTYPE.
struct RoadTypeInfo::@29 strings
Strings associated with the rail type.
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.
uint ShowRefitOptionsList(int left, int right, int y, EngineID engine)
Display list of cargo types of the engine, for the purchase information window.
EngineID sel_engine
Currently selected engine, or INVALID_ENGINE.
static const int ACTION_CLEAR
Clear editbox.
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
void OnInit() override
Notification that the nested widget tree gets initialized.
void SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
@ SA_CENTER
Center both horizontally and vertically.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
int width
width of the window (number of pixels to the right in x direction)
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
QueryString vehicle_editbox
Filter editbox.
void RebuildDone()
Notify the sortlist that the rebuild is done.
bool CDECL FilterFunction(const GUIEngineListItem *, CargoID)
Signature of filter function.
static bool AircraftEngineCargoSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of aircraft by cargo.
byte CargoID
Cargo slots to indicate a cargo type within a game.
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.
void OnResize() override
Called after the window got resized.
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
static bool EngineNameSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by name.
void UpdateFilterByTile()
Set the filter type according to the depot type.
VehicleSettings vehicle
options for vehicles
uint16_t EngineID
Unique identification number of an engine.
static uint ShowAdditionalText(int left, int right, int y, EngineID engine)
Display additional text from NewGRF in the purchase information window.
Data structure for an opened window.
@ VEH_TRAIN
Train vehicle type.
void DrawWidgets() const
Paint all widgets of a window.
static bool EngineSpeedSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by speed.
@ DC_QUERY_COST
query cost only, don't build.
Dimension GetDropDownListDimension(const DropDownList &list)
Determine width and height required to fully display a DropDownList.
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
bool HasPowerOnRail(RailType enginetype, RailType tiletype)
Checks if an engine of the given RailType got power on a tile with a given RailType.
bool CanVehicleUseStation(EngineID engine_type, const Station *st)
Can this station be used by the given engine type?
uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
@ VEH_SHIP
Ship vehicle type.
Specification of a rectangle with absolute coordinates of all edges.
StringID build_caption
Caption of the build vehicle GUI for this rail type.
uint8_t acceleration_type
Acceleration type of this rail type.
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
StringID build_caption
Caption of the build vehicle GUI for this rail type.
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
uint ApplyWaterClassSpeedFrac(uint raw_speed, bool is_ocean) const
Apply ocean/canal speed fraction to a velocity.
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.
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
Check if an engine is buildable.
uint GetEngineListHeight(VehicleType type)
Get the height of a single 'entry' in the engine lists.
StringID GetAircraftTypeText() const
Get the name of the aircraft type for display purposes.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, uint16_t min, uint16_t max, EngineID selected_id, bool show_count, GroupID selected_group)
Engine drawing loop.
Dimension GetLargestCargoIconSize()
Get dimensions of largest cargo icon.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
Draw an engine.
uint extend_left
Extend of the cell to the left.
static constexpr CargoID CF_ANY
Show all items independent of carried cargo (i.e. no filtering)
union BuildVehicleWindow::@0 filter
Filter to apply.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Dynamic data of a loaded NewGRF.
GUISettings gui
settings related to the GUI
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
uint16_t GetRange() const
Get the range of an aircraft type.
void SetCargoFilterArray()
Populate the filter list and set the cargo filter criteria.
const char * GetName() const
Get the name of this grf.
@ PurchaseList
Name is shown in the purchase list (including autoreplace window 'Available vehicles' panel).
All data for a single hotkey.
@ INVALID_RAILTYPE
Flag for invalid railtype.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.