44#include "table/strings.h"
58static constexpr NWidgetPart _nested_build_vehicle_widgets[] = {
76 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),
81 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_BV_LIST),
SetResize(1, 1),
SetFill(1, 0),
SetMatrixDataTip(1, 0, STR_NULL),
SetScrollbar(
WID_BV_SCROLLBAR),
127 const auto r = va - vb;
145 static std::string last_name[2] = { {}, {} };
150 last_name[0] =
GetString(STR_ENGINE_NAME);
156 last_name[1] =
GetString(STR_ENGINE_NAME);
176 const int r = va - vb;
193 int r = ClampTo<int32_t>(va - vb);
261 int r = ClampTo<int32_t>(va - vb);
297 double v_a = (double)p_a / (
double)r_a;
298 double v_b = (double)p_b / (
double)r_b;
340 int r = val_a - val_b;
401 uint16_t mail_a, mail_b;
489 STR_SORT_BY_ENGINE_ID,
491 STR_SORT_BY_MAX_SPEED,
493 STR_SORT_BY_TRACTIVE_EFFORT,
494 STR_SORT_BY_INTRO_DATE,
496 STR_SORT_BY_RUNNING_COST,
497 STR_SORT_BY_POWER_VS_RUNNING_COST,
498 STR_SORT_BY_RELIABILITY,
499 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,
515 STR_SORT_BY_ENGINE_ID,
517 STR_SORT_BY_MAX_SPEED,
518 STR_SORT_BY_INTRO_DATE,
520 STR_SORT_BY_RUNNING_COST,
521 STR_SORT_BY_RELIABILITY,
522 STR_SORT_BY_CARGO_CAPACITY,
525 STR_SORT_BY_ENGINE_ID,
527 STR_SORT_BY_MAX_SPEED,
528 STR_SORT_BY_INTRO_DATE,
530 STR_SORT_BY_RUNNING_COST,
531 STR_SORT_BY_RELIABILITY,
532 STR_SORT_BY_CARGO_CAPACITY,
568static int DrawCargoCapacityInfo(
int left,
int right,
int y,
TestedEngineDetails &te,
bool refittable)
576 SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
577 DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
593 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
596 DrawString(left, right, y, STR_PURCHASE_INFO_COST);
604 DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
612 DrawString(left, right, y, STR_PURCHASE_INFO_SPEED);
618 if (rvi->running_cost_class != INVALID_PRICE) {
637 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_WEIGHT);
641 DrawString(left, right, y, STR_PURCHASE_INFO_COST_WEIGHT);
648 DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_POWER);
654 DrawString(left, right, y, STR_PURCHASE_INFO_MAX_TE);
659 if (rvi->running_cost_class != INVALID_PRICE) {
669 DrawString(left, right, y, STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT);
686 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
689 DrawString(left, right, y, STR_PURCHASE_INFO_COST);
697 DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
703 DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_POWER);
708 DrawString(left, right, y, STR_PURCHASE_INFO_MAX_TE);
716 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
720 DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
743 if (ocean_speed == canal_speed) {
748 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
752 DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
759 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
762 DrawString(left, right, y, STR_PURCHASE_INFO_COST);
767 DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_OCEAN);
771 DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_CANAL);
778 SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
779 DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
808 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
812 DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
820 SetDParam(2, GetCargoIDByLabel(CT_MAIL));
822 DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_CAPACITY);
828 SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
829 DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
840 DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_TYPE);
847 DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_RANGE);
863 if (callback ==
CALLBACK_FAILED || callback == 0x400)
return std::nullopt;
865 assert(grffile !=
nullptr);
866 if (callback > 0x400) {
892void TestedEngineDetails::FillDefaultCapacities(
const Engine *e)
922 bool articulated_cargo =
false;
925 default: NOT_REACHED();
928 y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, &e->u.rail, te);
930 y = DrawRailEnginePurchaseInfo(left, right, y, engine_number, &e->u.rail, te);
932 articulated_cargo =
true;
936 y = DrawRoadVehPurchaseInfo(left, right, y, engine_number, te);
937 articulated_cargo =
true;
941 y = DrawShipPurchaseInfo(left, right, y, engine_number, refittable, te);
949 if (articulated_cargo) {
951 int new_y = DrawCargoCapacityInfo(left, right, y, te, refittable);
956 DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
968 DrawString(left, right, y, STR_PURCHASE_INFO_DESIGNED_LIFE);
973 DrawString(left, right, y, STR_PURCHASE_INFO_RELIABILITY);
1005 static const int sprite_y_offsets[] = { -1, -1, -2, -2 };
1013 int sprite_width = sprite_left + sprite_right;
1021 int count_width = 0;
1025 uint biggest_num_engines = 0;
1026 for (
auto it = first; it != last; ++it) {
1028 biggest_num_engines = std::max(biggest_num_engines, num_engines);
1042 int replace_icon_y_offset = (ir.
Height() - replace_icon.height) / 2;
1044 const int offset = (rtl ? -circle_width : circle_width) / 2;
1048 for (
auto it = first; it != last; ++it) {
1049 const auto &item = *it;
1055 if (item.indent > 0) {
1057 int tx = (rtl ? ir.right : ir.left) + offset;
1059 for (uint lvl = 1; lvl <= item.indent; ++lvl) {
1061 if (lvl < item.indent) tx += level_width;
1066 GfxDrawLine(tx, ycentre, tx + offset - (rtl ? -1 : 1), ycentre, linecolour,
WidgetDimensions::scaled.fullbevel.top);
1074 StringID str = hidden ? STR_HIDDEN_ENGINE_NAME : STR_ENGINE_NAME;
1084 DrawString(itr.left, itr.right, y + normal_text_y_offset, str, tc);
1094 DrawSpriteIgnorePadding(is_folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, {fr.left, y, fr.right, y + ir.
Height() - 1},
SA_CENTER);
1109 uint32_t hidden_mask = 0;
1132 for (
const auto &item : src) {
1133 if (item.variant_id != parent || item.engine_id == parent)
continue;
1150 if (indent > 0 || dst.empty())
return;
1153 uint16_t level_mask = 0;
1154 for (
auto it = std::rbegin(dst); std::next(it) != std::rend(dst); ++it) {
1155 auto next_it = std::next(it);
1156 SB(level_mask, it->indent, 1, it->indent <= next_it->indent);
1157 next_it->level_mask = level_mask;
1188 void SetBuyVehicleText()
1206 this->vehicle_type = type;
1239 widget->
SetLowered(this->show_hidden_engines);
1241 this->details_height = ((this->vehicle_type ==
VEH_TRAIN) ? 10 : 9);
1255 this->GenerateBuildList();
1260 if (it != this->eng_list.end()) engine = it->engine_id;
1261 this->SelectEngine(engine);
1267 switch (this->vehicle_type) {
1268 default: NOT_REACHED();
1270 if (this->listview_mode) {
1278 if (this->listview_mode) {
1320 this->sel_engine = engine;
1321 this->SetBuyVehicleText();
1327 if (!this->listview_mode) {
1330 if (
ret.Succeeded()) {
1331 this->te.
cost =
ret.GetCost() -
e->GetCost();
1342 this->te.FillDefaultCapacities(
e);
1353 this->eng_list.
Filter(this->cargo_filter_criteria);
1354 if (0 == this->eng_list.size()) {
1357 this->SelectEngine(this->eng_list[0].engine_id);
1372 if (this->string_filter.
IsEmpty())
return true;
1381 if (text) this->string_filter.
AddLine(*text);
1383 return this->string_filter.
GetState();
1391 size_t num_engines = 0;
1400 if (!this->show_hidden_engines &&
e->IsVariantHidden(
_local_company))
continue;
1413 list.emplace_back(
eid,
e->info.variant_id,
e->display_flags, 0);
1436 this->SelectEngine(
sel_id);
1454 void GenerateBuildRoadVehList()
1458 this->eng_list.clear();
1461 if (!this->show_hidden_engines &&
e->IsVariantHidden(
_local_company))
continue;
1469 this->eng_list.emplace_back(
eid,
e->info.variant_id,
e->display_flags, 0);
1473 this->SelectEngine(
sel_id);
1477 void GenerateBuildShipList()
1480 this->eng_list.clear();
1483 if (!this->show_hidden_engines &&
e->IsVariantHidden(
_local_company))
continue;
1490 this->eng_list.emplace_back(
eid,
e->info.variant_id,
e->display_flags, 0);
1494 this->SelectEngine(
sel_id);
1498 void GenerateBuildAircraftList()
1502 this->eng_list.clear();
1511 if (!this->show_hidden_engines &&
e->IsVariantHidden(
_local_company))
continue;
1520 this->eng_list.emplace_back(
eid,
e->info.variant_id,
e->display_flags, 0);
1525 this->SelectEngine(
sel_id);
1529 void GenerateBuildList()
1536 this->eng_list.clear();
1540 switch (this->vehicle_type) {
1541 default: NOT_REACHED();
1543 this->GenerateBuildTrainList(list);
1548 this->GenerateBuildRoadVehList();
1551 this->GenerateBuildShipList();
1554 this->GenerateBuildAircraftList();
1562 for (
const auto &item :
this->eng_list) {
1580 this->eng_list.swap(list);
1603 list.push_back(MakeDropDownListIconItem(
d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index()));
1642 this->descending_sort_order ^=
true;
1649 this->show_hidden_engines ^=
true;
1659 if (it != this->eng_list.end()) {
1660 const auto &item = *it;
1674 this->SelectEngine(
e);
1678 }
else if (
click_count > 1 && !this->listview_mode) {
1689 ShowDropDownList(
this, this->BuildCargoDropDownList(), this->cargo_filter_criteria, widget);
1701 this->BuildVehicle();
1707 this->rename_engine =
sel_eng;
1725 if (this->vehicle_type ==
VEH_ROAD &&
1727 this->sort_criteria > 7) {
1728 this->sort_criteria = 0;
1738 if (this->vehicle_type ==
VEH_TRAIN && !this->listview_mode) {
1741 }
else if (this->vehicle_type ==
VEH_ROAD && !this->listview_mode) {
1754 SetDParam(0, this->GetCargoFilterLabel(this->cargo_filter_criteria));
1774 size.height = 3 *
resize.height;
1785 d.height += padding.height;
1797 size.width += padding.width;
1798 size.height += padding.height;
1804 size.width += padding.width;
1805 size.height += padding.height;
1833 this->GenerateBuildList();
1834 this->vscroll->
SetCount(this->eng_list.size());
1862 if (!str.has_value())
return;
1871 if (this->sort_criteria != index) {
1872 this->sort_criteria = index;
1879 if (this->cargo_filter_criteria != index) {
1880 this->cargo_filter_criteria = index;
1885 this->SelectEngine(this->sel_engine);
1920 static inline HotkeyList hotkeys{
"buildvehicle", {
1926 WDP_AUTO,
"build_vehicle", 240, 268,
1929 _nested_build_vehicle_widgets,
1930 &BuildVehicleWindow::hotkeys
1939 uint num = (tile ==
INVALID_TILE) ? (
int)type : tile.base();
CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ors the refit_masks of all articulated parts.
CargoArray GetCapacityOfArticulatedParts(EngineID engine)
Get the capacity of the parts of a given engine.
bool IsArticulatedVehicleRefittable(EngineID engine)
Checks whether any of the articulated parts is refittable.
Functions related to articulated vehicles.
Functions related to autoreplacing.
bool EngineHasReplacementForCompany(const Company *c, EngineID engine, GroupID group)
Check if a company has a replacement set up for the given engine.
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
static bool EngineIntroDateSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by introduction date.
static bool EngineCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by purchase cost.
void GUIEngineListAddChildren(GUIEngineList &dst, const GUIEngineList &src, EngineID parent, uint8_t indent)
Add children to GUI engine list to build a hierarchical tree.
static bool TrainEnginesThenWagonsSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of train engines by engine / wagon.
BuildVehicleHotkeys
Enum referring to the Hotkeys in the build vehicle window.
@ BVHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
static std::optional< std::string > GetNewGRFAdditionalText(EngineID engine)
Try to get the NewGRF engine additional text callback as an optional std::string.
static bool AircraftEngineCargoSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of aircraft by cargo.
bool _engine_sort_last_order[]
Last set direction of the sort order, for each vehicle type.
static bool EngineNumberSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by engineID.
static bool CargoAndEngineFilter(const GUIEngineListItem *item, const CargoID cid)
Filters vehicles by cargo and engine (in case of rail vehicle).
uint GetEngineListHeight(VehicleType type)
Get the height of a single 'entry' in the engine lists.
static bool TrainEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of train engines by capacity.
static int DrawAircraftPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable, TestedEngineDetails &te)
Draw aircraft specific details in the buy window.
static bool EnginePowerVsRunningCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by running costs.
static bool EngineReliabilitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by reliability.
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.
static bool ShipEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of ships by capacity.
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.
static bool EngineTractiveEffortSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by tractive effort.
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.
static uint ShowAdditionalText(int left, int right, int y, EngineID engine)
Display additional text from NewGRF in the purchase information window.
static bool EngineSpeedSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by speed.
bool _engine_sort_direction
false = descending, true = ascending.
static bool EngineNameSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by name.
static bool EnginePowerSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by power.
static bool EngineRunningCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by running costs.
static bool AircraftRangeSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of aircraft by range.
static CargoID _engine_sort_last_cargo_criteria[]
Last set filter criteria, for each vehicle type.
static bool RoadVehEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of road vehicles by capacity.
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.
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
Dimension GetLargestCargoIconSize()
Get dimensions of largest cargo icon.
std::span< const CargoSpec * > _sorted_standard_cargo_specs
Standard cargo specifications sorted alphabetically by name.
CargoTypes _standard_cargo_mask
Bitmask of real cargo types available.
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
Types/functions related to cargoes.
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
void RebuildDone()
Notify the sortlist that the rebuild is done.
void SetFilterState(bool state)
Enable or disable the filter.
bool(const GUIEngineListItem *, CargoID) FilterFunction
Signature of filter function.
void SetFilterFuncs(std::span< FilterFunction *const > n_funcs)
Hand the filter function pointers to the GUIList.
bool NeedRebuild() const
Check if a rebuild is needed.
void ForceRebuild()
Force that a rebuild is needed.
This struct contains all the info that is needed to draw and construct tracks.
struct RailTypeInfo::@26 strings
Strings associated with the rail type.
StringID build_caption
Caption of the build vehicle GUI for this rail type.
uint8_t acceleration_type
Acceleration type of this rail type.
struct RoadTypeInfo::@29 strings
Strings associated with the rail type.
StringID build_caption
Caption of the build vehicle GUI for this rail type.
static YearMonthDay ConvertDateToYMD(Date date)
Converts a Date to a Year, Month & Day.
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
static constexpr Year DateToYear(Date date)
Calculate the year of a given date.
Functions related to commands.
@ DC_QUERY_COST
query cost only, don't build.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
VehicleCellSize GetVehicleImageCellSize(VehicleType type, EngineImageType image_type)
Get the GUI cell size for a vehicle image.
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.
Dimension GetDropDownListDimension(const DropDownList &list)
Determine width and height required to fully display a DropDownList.
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.
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
Check if an engine is buildable.
EngineDisplayFlags
Flags used client-side in the purchase/autorenew engine list.
@ HasVariants
Set if engine has variants.
@ IsFolded
Set if display of variants should be folded (hidden).
@ Shaded
Set if engine should be masked.
Command definitions related to engines.
Functions related to engines.
uint GetTotalCapacityOfArticulatedParts(EngineID engine)
Get the capacity of an engine with articulated parts.
void EngList_Sort(GUIEngineList &el, EngList_SortTypeFunction compare)
Sort all items using quick sort and given 'CompareItems' function.
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>)
void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
Draw an engine.
Engine GUI functions, used by build_vehicle_gui and autoreplace_gui
bool EngList_SortTypeFunction(const GUIEngineListItem &, const GUIEngineListItem &)
argument type for EngList_Sort.
static const uint MAX_LENGTH_ENGINE_NAME_CHARS
The maximum length of an engine name in characters including '\0'.
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.
@ AutoreplaceVehicleInUse
Name is show in the autoreplace window 'Vehicles in use' panel.
@ Generic
No specific context available.
@ PurchaseList
Name is shown in the purchase list (including autoreplace window 'Available vehicles' panel).
@ RAILVEH_WAGON
simple wagon, not motorized
@ RAILVEH_MULTIHEAD
indicates a combination of two locomotives
debug_inline constexpr bool HasFlag(const T x, const T y)
Checks if a value in a bitset enum is set.
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 GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
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?
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
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.
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
@ SA_RIGHT
Right align the text (must be a single bit).
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
@ SA_CENTER
Center both horizontally and vertically.
@ FS_SMALL
Index of the small font in the font tables.
@ FS_NORMAL
Index of the normal font in the font tables.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
@ TC_FORCED
Ignore colour changes from strings.
@ TC_NO_SHADE
Do not add shading to this text colour.
Base class for groups and group functions.
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.
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.
Hotkey related functions.
constexpr uint ToPercent16(uint i)
Converts a "fract" value 0..65535 to "percent" value 0..100.
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
static constexpr CargoID CF_NONE
Show only items which do not carry cargo (e.g. train engines)
static constexpr CargoID CF_ANY
Show all items independent of carried cargo (i.e. no filtering)
static constexpr CargoID CF_ENGINES
Show only engines (for rail vehicles only)
bool _networking
are we in networking mode?
bool _network_server
network-server is active
Basic functions/variables used all over the place.
@ INVALID_CLIENT_ID
Client is not part of anything.
@ CBID_VEHICLE_ADDITIONAL_TEXT
This callback is called from vehicle purchase lists.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
GRFConfig * GetGRFConfig(uint32_t grfid, uint32_t mask)
Retrieve a NewGRF from the current config by its grfid.
uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Functions for NewGRF engines.
void StartTextRefStackUsage(const GRFFile *grffile, uint8_t numEntries, const uint32_t *values)
Start using the TTDP compatible string code parsing.
StringID GetGRFStringID(uint32_t grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
Header of Action 04 "universal holder" structure and functions.
uint8_t GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
Base for the GUIs that have an edit box in them.
bool HasPowerOnRail(RailType enginetype, RailType tiletype)
Checks if an engine of the given RailType got power on a tile with a given RailType.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
RailType
Enumeration for all possible railtypes.
@ INVALID_RAILTYPE
Flag for invalid railtype.
bool HasPowerOnRoad(RoadType enginetype, RoadType tiletype)
Checks if an engine of the given RoadType got power on a tile with a given RoadType.
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
RoadType
The different roadtypes we support.
@ 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.
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Base classes/functions for stations.
Definition of base types and functions in a cross-platform compatible way.
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Functions related to low-level strings.
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Searching and filtering using a stringterm.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
TextDirection _current_text_dir
Text direction of the currently selected language.
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.
@ TD_RTL
Text is written right-to-left by default.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
static BaseStation * GetByTile(TileIndex tile)
Get the base station belonging to a specific tile.
GUI for building vehicles.
CargoID cargo_filter_criteria
Selected cargo filter.
void SetStringParameters(WidgetID widget) const override
Initialize string parameters for a widget.
void OnDropdownSelect(WidgetID widget, int index) override
A dropdown option associated to this window has been selected.
VehicleType vehicle_type
Type of vehicles shown in the window.
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.
bool FilterByText(const Engine *e)
Filter by name and NewGRF extra text.
void UpdateFilterByTile()
Set the filter type according to the depot type.
bool descending_sort_order
Sort direction,.
bool listview_mode
If set, only display the available vehicles and do not show a 'build' button.
void SetCargoFilterArray()
Populate the filter list and set the cargo filter criteria.
RailType railtype
Rail type to show, or INVALID_RAILTYPE.
void OnPaint() override
The window must be repainted.
int details_height
Minimal needed height of the details panels, in text lines (found so far).
QueryString vehicle_editbox
Filter editbox.
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
union BuildVehicleWindow::@0 filter
Filter to apply.
void OnResize() override
Called after the window got resized.
bool show_hidden_engines
State of the 'show hidden engines' button.
void FilterEngineList()
Filter the engine list against the currently selected cargo filter.
EngineID rename_engine
Engine being renamed.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
TestedEngineDetails te
Tested cost and capacity after refit.
void OnEditboxChanged(WidgetID wid) override
The text in an editbox has been edited.
StringFilter string_filter
Filter for vehicle name.
uint8_t sort_criteria
Current sort criterium.
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.
bool FilterSingleEngine(EngineID eid)
Filter a single engine.
EngineID sel_engine
Currently selected engine, or INVALID_ENGINE.
RoadType roadtype
Road type to show, or INVALID_ROADTYPE.
void OnInit() override
Notification that the nested widget tree gets initialized.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
Class for storing amounts of cargo.
uint GetCount() const
Get the amount of cargos that have an amount.
Specification of a cargo type.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
StringID name
Name of this type of cargo.
GUISettings gui
settings related to the GUI
Dimensions (a width and height) of a rectangle in 2D.
StringID GetAircraftTypeText() const
Get the name of the aircraft type for display purposes.
uint GetPower() const
Returns the power of the engine for display and sorting purposes.
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
uint16_t GetRange() const
Get the range of an aircraft type.
uint32_t GetGRFID() const
Retrieve the GRF ID of the NewGRF the engine is tied to.
Money GetCost() const
Return how much a new engine costs.
TimerGameCalendar::Date intro_date
Date of introduction of the engine.
uint GetDisplayMaxSpeed() const
Returns max speed of the engine for display purposes.
EngineDisplayFlags display_flags
NOSAVE client-side-only display flags for build engine list.
uint GetDisplayWeight() const
Returns the weight of the engine for display purposes.
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
TimerGameCalendar::Date GetLifeLengthInDays() const
Returns the vehicle's (not model's!) life length in days.
uint GetDisplayDefaultCapacity(uint16_t *mail_capacity=nullptr) const
Determines the default cargo capacity of an engine for display purposes.
CompanyMask company_hidden
Bit for each company whether the engine is normally hidden in the build gui for that company.
Money GetRunningCost() const
Return how much the running costs of this engine are.
uint16_t reliability
Current reliability of the engine.
uint GetDisplayMaxTractiveEffort() const
Returns the tractive effort of the engine for display purposes.
EngineID display_last_variant
NOSAVE client-side-only last variant selected.
Information about GRF, used in the game and (part of it) in savegames.
const char * GetName() const
Get the name of this grf.
Dynamic data of a loaded NewGRF.
EngineDisplayFlags flags
Flags for toggling/drawing (un)folded status and controlling indentation.
EngineID engine_id
Engine to display in build purchase list.
bool show_newgrf_name
Show the name of the NewGRF in the build vehicle window.
VehicleSettings vehicle
options for vehicles
List of hotkeys for a window.
All data for a single hotkey.
Coordinates of a point in 2D.
Tindex index
Index of this pool item.
static Titem * Get(size_t index)
Returns Titem with given index.
Data stored about a string that can be modified in the GUI.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
static const int ACTION_CLEAR
Clear editbox.
Information about a rail vehicle.
uint16_t pow_wag_power
Extra power applied to consist if wagon should be powered.
RailType railtype
Railtype, mangled if elrail is disabled.
uint8_t pow_wag_weight
Extra weight applied to consist if wagon should be powered.
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.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
int Height() const
Get height of Rect.
RoadType roadtype
Road type.
uint ApplyWaterClassSpeedFrac(uint raw_speed, bool is_ocean) const
Apply ocean/canal speed fraction to a velocity.
bool IsEmpty() const
Check whether any filter words were entered.
void SetFilterTerm(const char *str)
Set the term to filter on.
void ResetState()
Reset the matching state to process a new item.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
bool GetState() const
Get the matching state of the current item.
Extra information about refitted cargo and capacity.
CargoArray all_capacities
Capacities for all cargoes.
uint16_t mail_capacity
Mail capacity if available.
uint capacity
Cargo capacity.
char *const buf
buffer in which text is saved
uint extend_left
Extend of the cell to the left.
uint extend_right
Extend of the cell to the right.
uint8_t roadveh_acceleration_model
realistic acceleration for road vehicles
uint8_t train_acceleration_model
realistic acceleration for trains
bool wagon_speed_limits
enable wagon speed limits
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.
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
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 DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
ResizeInfo resize
Resize information.
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
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.
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.
int width
width of the window (number of pixels to the right in x direction)
WindowNumber window_number
Window number within the window class.
Stuff related to the text buffer GUI.
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
@ QSF_LEN_IN_CHARS
the length of the string is counted in characters
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition of the game-calendar-timer.
Command definitions related to trains.
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.
PaletteID GetEnginePalette(EngineID engine_type, CompanyID company)
Get the colour map for an engine.
bool CanVehicleUseStation(EngineID engine_type, const Station *st)
Can this station be used by the given engine type?
Command definitions for vehicles.
void CcBuildPrimaryVehicle(Commands cmd, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray)
This is the Callback method after the construction attempt of a primary vehicle.
Functions related to vehicles.
bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
uint ShowRefitOptionsList(int left, int right, int y, EngineID engine)
Display list of cargo types of the engine, for the purchase information window.
Functions related to the vehicle's GUIs.
@ EIT_PURCHASE
Vehicle drawn in purchase list, autoreplace gui, ...
VehicleType
Available vehicle types.
@ VEH_ROAD
Road vehicle type.
@ VEH_AIRCRAFT
Aircraft vehicle type.
@ VEH_SHIP
Ship vehicle type.
@ VEH_TRAIN
Train vehicle type.
static const uint MAX_LENGTH_VEHICLE_NAME_CHARS
The maximum length of a vehicle name in characters including '\0'.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
void SetFocusedWindow(Window *w)
Set the window that has the focus.
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.
@ SBS_DOWN
Sort ascending.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
@ WDP_AUTO
Find a place automatically.
EventState
State of handling an event.
@ ES_HANDLED
The passed event is handled.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WC_REPLACE_VEHICLE
Replace vehicle window; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ WC_BUILD_VEHICLE
Build vehicle; Window numbers:
Functions related to zooming.
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.