45#include "table/strings.h"
59static constexpr NWidgetPart _nested_build_vehicle_widgets[] = {
77 NWidget(
WWT_EDITBOX, COLOUR_GREY,
WID_BV_FILTER),
SetResize(1, 0),
SetFill(1, 0),
SetPadding(2),
SetStringTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
82 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_BV_LIST),
SetResize(1, 1),
SetFill(1, 0),
SetMatrixDataTip(1, 0),
SetScrollbar(
WID_BV_SCROLLBAR),
128 const auto r = va - vb;
136static EngineID _last_engine[2] = { EngineID::Invalid(), EngineID::Invalid() };
146 static std::string last_name[2] = { {}, {} };
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,
501 STR_SORT_BY_ENGINE_ID,
503 STR_SORT_BY_MAX_SPEED,
505 STR_SORT_BY_TRACTIVE_EFFORT,
506 STR_SORT_BY_INTRO_DATE,
508 STR_SORT_BY_RUNNING_COST,
509 STR_SORT_BY_POWER_VS_RUNNING_COST,
510 STR_SORT_BY_RELIABILITY,
511 STR_SORT_BY_CARGO_CAPACITY,
514 STR_SORT_BY_ENGINE_ID,
516 STR_SORT_BY_MAX_SPEED,
517 STR_SORT_BY_INTRO_DATE,
519 STR_SORT_BY_RUNNING_COST,
520 STR_SORT_BY_RELIABILITY,
521 STR_SORT_BY_CARGO_CAPACITY,
524 STR_SORT_BY_ENGINE_ID,
526 STR_SORT_BY_MAX_SPEED,
527 STR_SORT_BY_INTRO_DATE,
529 STR_SORT_BY_RUNNING_COST,
530 STR_SORT_BY_RELIABILITY,
531 STR_SORT_BY_CARGO_CAPACITY,
567static int DrawCargoCapacityInfo(
int left,
int right,
int y,
TestedEngineDetails &te,
bool refittable)
573 DrawString(left, right, y,
GetString(STR_PURCHASE_INFO_CAPACITY, cargo_type, te.
all_capacities[cargo_type], refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY));
609 if (rvi->running_cost_class != INVALID_PRICE) {
641 if (rvi->running_cost_class != INVALID_PRICE) {
708 if (ocean_speed == canal_speed) {
799 if (callback ==
CALLBACK_FAILED || callback == 0x400)
return std::nullopt;
801 assert(grffile !=
nullptr);
802 if (callback > 0x400) {
825void TestedEngineDetails::FillDefaultCapacities(
const Engine *e)
855 bool articulated_cargo =
false;
858 default: NOT_REACHED();
861 y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, &e->u.rail, te);
863 y = DrawRailEnginePurchaseInfo(left, right, y, engine_number, &e->u.rail, te);
865 articulated_cargo =
true;
869 y = DrawRoadVehPurchaseInfo(left, right, y, engine_number, te);
870 articulated_cargo =
true;
874 y = DrawShipPurchaseInfo(left, right, y, engine_number, refittable, te);
882 if (articulated_cargo) {
884 int new_y = DrawCargoCapacityInfo(left, right, y, te, refittable);
887 DrawString(left, right, y,
GetString(STR_PURCHASE_INFO_CAPACITY, INVALID_CARGO, 0, STR_EMPTY));
940 static const std::array<int8_t, VehicleType::VEH_COMPANY_END> sprite_y_offsets = { 0, 0, -1, -1 };
948 int sprite_width = sprite_left + sprite_right;
952 auto badge_column_widths = badge_classes.GetColumnWidths();
962 uint biggest_num_engines = 0;
963 for (
auto it = first; it != last; ++it) {
965 biggest_num_engines = std::max(biggest_num_engines, num_engines);
975 const int offset = (rtl ? -circle_width : circle_width) / 2;
978 for (
auto it = first; it != last; ++it) {
979 const auto &item = *it;
990 if (item.indent > 0) {
992 int tx = (rtl ? ir.right : ir.left) + offset;
993 for (uint lvl = 1; lvl <= item.indent; ++lvl) {
995 if (lvl < item.indent) tx += level_width;
1000 GfxDrawLine(tx, ycentre, tx + offset - (rtl ? -1 : 1), ycentre, linecolour,
WidgetDimensions::scaled.fullbevel.top);
1005 DrawSpriteIgnorePadding(is_folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, {fr.left, textr.top, fr.right, textr.bottom},
SA_CENTER);
1014 if (badge_column_widths.size() >= 1 && badge_column_widths[0] > 0) {
1016 DrawEngineBadgeColumn(br, 0, badge_classes, e, pal);
1017 tr = tr.
Indent(badge_column_widths[0], rtl);
1020 int sprite_x = tr.
WithWidth(sprite_width, rtl).left + sprite_left;
1025 if (badge_column_widths.size() >= 2 && badge_column_widths[1] > 0) {
1027 DrawEngineBadgeColumn(br, 1, badge_classes, e, pal);
1028 tr = tr.
Indent(badge_column_widths[1], rtl);
1042 DrawSpriteIgnorePadding(SPR_GROUP_REPLACE_ACTIVE, num_engines == 0 ?
PALETTE_CRASH : PAL_NONE, rr,
SA_CENTER);
1046 if (badge_column_widths.size() >= 3 && badge_column_widths[2] > 0) {
1048 DrawEngineBadgeColumn(br, 2, badge_classes, e, pal);
1049 tr = tr.
Indent(badge_column_widths[2], !rtl);
1053 StringID str = hidden ? STR_HIDDEN_ENGINE_NAME : STR_ENGINE_NAME;
1058 DrawString(tr.left, tr.right, textr.top + normal_text_y_offset,
GetString(str, engine_name), tc);
1073 uint32_t hidden_mask = 0;
1096 for (
const auto &item : src) {
1097 if (item.variant_id != parent || item.engine_id == parent)
continue;
1114 if (indent > 0 || dst.empty())
return;
1117 uint16_t level_mask = 0;
1118 for (
auto it = std::rbegin(dst); std::next(it) != std::rend(dst); ++it) {
1119 auto next_it = std::next(it);
1120 SB(level_mask, it->indent, 1, it->indent <= next_it->indent);
1121 next_it->level_mask = level_mask;
1153 void SetBuyVehicleText()
1169 this->vehicle_type = type;
1198 widget->
SetLowered(this->show_hidden_engines);
1200 this->details_height = ((this->vehicle_type ==
VEH_TRAIN) ? 10 : 9);
1214 this->GenerateBuildList();
1217 EngineID engine = EngineID::Invalid();
1219 if (it != this->eng_list.end()) engine = it->engine_id;
1220 this->SelectEngine(engine);
1226 switch (this->vehicle_type) {
1227 default: NOT_REACHED();
1229 if (this->listview_mode) {
1237 if (this->listview_mode) {
1255 switch (cargo_type) {
1279 this->sel_engine = engine;
1280 this->SetBuyVehicleText();
1282 if (this->sel_engine == EngineID::Invalid())
return;
1286 if (!this->listview_mode) {
1289 if (
ret.Succeeded()) {
1290 this->te.
cost =
ret.GetCost() -
e->GetCost();
1301 this->te.FillDefaultCapacities(
e);
1314 if (0 == this->eng_list.size()) {
1315 this->SelectEngine(EngineID::Invalid());
1317 this->SelectEngine(this->eng_list[0].engine_id);
1350 size_t num_engines = 0;
1361 if (!this->show_hidden_engines &&
e->IsVariantHidden(
_local_company))
continue;
1374 list.emplace_back(
eid,
e->info.variant_id,
e->display_flags, 0);
1380 while (
parent != EngineID::Invalid()) {
1397 this->SelectEngine(
sel_id);
1400 _last_engine[0] = _last_engine[1] = EngineID::Invalid();
1415 void GenerateBuildRoadVehList()
1419 this->eng_list.clear();
1424 if (!this->show_hidden_engines &&
e->IsVariantHidden(
_local_company))
continue;
1432 this->eng_list.emplace_back(
eid,
e->info.variant_id,
e->display_flags, 0);
1436 this->SelectEngine(
sel_id);
1440 void GenerateBuildShipList()
1443 this->eng_list.clear();
1448 if (!this->show_hidden_engines &&
e->IsVariantHidden(
_local_company))
continue;
1455 this->eng_list.emplace_back(
eid,
e->info.variant_id,
e->display_flags, 0);
1459 this->SelectEngine(
sel_id);
1463 void GenerateBuildAircraftList()
1467 this->eng_list.clear();
1478 if (!this->show_hidden_engines &&
e->IsVariantHidden(
_local_company))
continue;
1487 this->eng_list.emplace_back(
eid,
e->info.variant_id,
e->display_flags, 0);
1492 this->SelectEngine(
sel_id);
1496 void GenerateBuildList()
1503 this->eng_list.clear();
1507 switch (this->vehicle_type) {
1508 default: NOT_REACHED();
1510 this->GenerateBuildTrainList(list);
1515 this->GenerateBuildRoadVehList();
1518 this->GenerateBuildShipList();
1521 this->GenerateBuildAircraftList();
1529 for (
const auto &item :
this->eng_list) {
1531 while (
parent != EngineID::Invalid()) {
1547 this->eng_list.swap(list);
1570 list.push_back(MakeDropDownListIconItem(
d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index()));
1579 if (sel_eng == EngineID::Invalid())
return;
1592 while (
parent != EngineID::Invalid()) {
1609 this->descending_sort_order ^=
true;
1616 this->show_hidden_engines ^=
true;
1626 if (it != this->eng_list.end()) {
1627 const auto &item = *it;
1641 this->SelectEngine(
e);
1645 }
else if (
click_count > 1 && !this->listview_mode) {
1660 const Engine *
e = (this->sel_engine == EngineID::Invalid()) ?
nullptr :
Engine::Get(this->sel_engine);
1668 this->BuildVehicle();
1673 if (sel_eng != EngineID::Invalid()) {
1674 this->rename_engine =
sel_eng;
1691 if (this->vehicle_type ==
VEH_ROAD &&
1693 this->sort_criteria > 7) {
1694 this->sort_criteria = 0;
1704 if (this->vehicle_type ==
VEH_TRAIN && !this->listview_mode) {
1708 if (this->vehicle_type ==
VEH_ROAD && !this->listview_mode) {
1721 const Engine *
e = (this->sel_engine == EngineID::Invalid()) ?
nullptr :
Engine::Get(this->sel_engine);
1738 size.height = 3 *
resize.height;
1749 d.height += padding.height;
1761 size.width += padding.width;
1762 size.height += padding.height;
1768 size.width += padding.width;
1769 size.height += padding.height;
1798 this->GenerateBuildList();
1799 this->vscroll->
SetCount(this->eng_list.size());
1811 if (this->sel_engine != EngineID::Invalid()) {
1827 if (!str.has_value())
return;
1836 if (this->sort_criteria != index) {
1837 this->sort_criteria = index;
1850 this->SelectEngine(this->sel_engine);
1885 static inline HotkeyList hotkeys{
"buildvehicle", {
1891 WDP_AUTO,
"build_vehicle", 240, 268,
1894 _nested_build_vehicle_widgets,
1895 &BuildVehicleWindow::hotkeys
1904 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.
static CargoType _engine_sort_last_cargo_criteria[]
Last set filter criteria, for each vehicle type.
void GUIEngineListAddChildren(GUIEngineList &dst, const GUIEngineList &src, EngineID parent, uint8_t indent)
Add children to GUI engine list to build a hierarchical tree.
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 bool TrainEnginesThenWagonsSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of train engines by engine / wagon.
void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, const Scrollbar &sb, EngineID selected_id, bool show_count, GroupID selected_group, const GUIBadgeClasses &badge_classes)
Engine drawing loop.
static bool CargoAndEngineFilter(const GUIEngineListItem *item, const CargoType cargo_type)
Filters vehicles by cargo and engine (in case of rail vehicle).
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.
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 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.
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
bool IsValidCargoType(CargoType t)
Test whether cargo type is not INVALID_CARGO.
static const CargoType 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.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Flip(Tvalue_type value)
Flip the value-th bit.
constexpr Timpl & Reset(Tvalue_type value)
Reset the value-th bit.
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 *, CargoType) 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::@24 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::@27 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.
@ QueryCost
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.
@ 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'.
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).
@ Generic
No specific context available.
@ AutoreplaceVehicleInUse
Name is show in the autoreplace window 'Vehicles in use' panel.
@ RAILVEH_WAGON
simple wagon, not motorized
@ RAILVEH_MULTIHEAD
indicates a combination of two locomotives
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?
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.
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
@ FS_SMALL
Index of the small font in the font tables.
@ FS_NORMAL
Index of the normal font in the font tables.
@ 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.
uint32_t PaletteID
The number of the palette.
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)
static constexpr GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
Hotkey related functions.
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
constexpr uint ToPercent16(uint i)
Converts a "fract" value 0..65535 to "percent" value 0..100.
void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
static constexpr CargoType CF_NONE
Show only items which do not carry cargo (e.g. train engines)
static constexpr CargoType CF_ENGINES
Show only engines (for rail vehicles only)
static constexpr CargoType CF_ANY
Show all items independent of carried cargo (i.e. no filtering)
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.
int DrawBadgeNameList(Rect r, std::span< const BadgeID > badges, GrfSpecFeature)
Draw names for a list of badge labels.
void DrawBadgeColumn(Rect r, int column_group, const GUIBadgeClasses &badge_classes, std::span< const BadgeID > badges, GrfSpecFeature feature, std::optional< TimerGameCalendar::Date > introduction_date, PaletteID remap)
Draw a badge column group.
Functions related to NewGRF badges.
@ 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.
std::string GetGRFStringWithTextStack(const struct GRFFile *grffile, GRFStringID grfstringid, uint8_t num_entries)
Format a GRF string using the text ref stack for parameters.
Header of Action 04 "universal holder" structure and functions.
static constexpr GRFStringID GRFSTR_MISC_GRF_TEXT
Miscellaneous GRF text range.
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.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
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.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
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.
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.
CargoType cargo_filter_criteria
Selected cargo filter.
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.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
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 EngineID::Invalid()
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 type.
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.
TimerGameCalendar::Date base_intro
Basic date of engine introduction (without random parts).
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.
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.
CargoType 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.
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 variant_id
Variant group of the engine.
EngineID engine_id
Engine to display in build purchase list.
uint8_t indent
Display indentation level.
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.
static Titem * Get(auto index)
Returns Titem with given index.
Tindex index
Index of this pool item.
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.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
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(std::string_view 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.
CargoType cargo
Cargo type.
CargoArray all_capacities
Capacities for all cargoes.
uint16_t mail_capacity
Mail capacity if available.
uint capacity
Cargo capacity.
const char * GetText() const
Get the current text.
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.
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
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.
@ EnableDefault
enable the 'Default' button ("\0" is returned)
@ LengthIsInChars
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.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
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, CargoType, 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_INVALID
Non-existing type of vehicle.
@ 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.
@ Construction
This window is used for construction; close it whenever changing company.
@ SBS_DOWN
Sort ascending.
@ 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.