22#include "newgrf_badge_gui.h"
47#include "table/strings.h"
61static constexpr NWidgetPart _nested_build_vehicle_widgets[] = {
77 NWidget(
WWT_IMGBTN, COLOUR_GREY,
WID_BV_CONFIGURE_BADGES),
SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
SetResize(0, 0),
SetFill(0, 1),
SetSpriteTip(SPR_EXTRA_MENU, STR_BADGE_CONFIG_MENU_TOOLTIP),
80 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),
85 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_BV_LIST),
SetResize(1, 1),
SetFill(1, 0),
SetMatrixDataTip(1, 0),
SetScrollbar(
WID_BV_SCROLLBAR),
131 const auto r = va - vb;
139static EngineID _last_engine[2] = { EngineID::Invalid(), EngineID::Invalid() };
149 static std::string last_name[2] = { {}, {} };
178 const int r = va - vb;
195 int r = ClampTo<int32_t>(va - vb);
263 int r = ClampTo<int32_t>(va - vb);
299 double v_a = (double)p_a / (
double)r_a;
300 double v_b = (double)p_b / (
double)r_b;
342 int r = val_a - val_b;
403 uint16_t mail_a, mail_b;
491 STR_SORT_BY_ENGINE_ID,
493 STR_SORT_BY_MAX_SPEED,
495 STR_SORT_BY_TRACTIVE_EFFORT,
496 STR_SORT_BY_INTRO_DATE,
498 STR_SORT_BY_RUNNING_COST,
499 STR_SORT_BY_POWER_VS_RUNNING_COST,
500 STR_SORT_BY_RELIABILITY,
501 STR_SORT_BY_CARGO_CAPACITY,
504 STR_SORT_BY_ENGINE_ID,
506 STR_SORT_BY_MAX_SPEED,
508 STR_SORT_BY_TRACTIVE_EFFORT,
509 STR_SORT_BY_INTRO_DATE,
511 STR_SORT_BY_RUNNING_COST,
512 STR_SORT_BY_POWER_VS_RUNNING_COST,
513 STR_SORT_BY_RELIABILITY,
514 STR_SORT_BY_CARGO_CAPACITY,
517 STR_SORT_BY_ENGINE_ID,
519 STR_SORT_BY_MAX_SPEED,
520 STR_SORT_BY_INTRO_DATE,
522 STR_SORT_BY_RUNNING_COST,
523 STR_SORT_BY_RELIABILITY,
524 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,
559 if (cap[cargo] != 0) {
561 weight +=
CargoSpec::Get(cargo)->WeightOfNUnitsInTrain(cap[cargo]);
570static int DrawCargoCapacityInfo(
int left,
int right,
int y,
TestedEngineDetails &te,
bool refittable)
576 DrawString(left, right, y,
GetString(STR_PURCHASE_INFO_CAPACITY, cargo_type, te.
all_capacities[cargo_type], refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY));
612 if (rvi->running_cost_class != INVALID_PRICE) {
644 if (rvi->running_cost_class != INVALID_PRICE) {
711 if (ocean_speed == canal_speed) {
801 std::array<int32_t, 16> regs100;
803 if (callback ==
CALLBACK_FAILED || callback == 0x400)
return std::nullopt;
805 assert(grffile !=
nullptr);
806 if (callback == 0x40F) {
809 if (callback > 0x400) {
832void TestedEngineDetails::FillDefaultCapacities(
const Engine *e)
862 bool articulated_cargo =
false;
865 default: NOT_REACHED();
868 y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, &e->u.rail, te);
870 y = DrawRailEnginePurchaseInfo(left, right, y, engine_number, &e->u.rail, te);
872 articulated_cargo =
true;
876 y = DrawRoadVehPurchaseInfo(left, right, y, engine_number, te);
877 articulated_cargo =
true;
881 y = DrawShipPurchaseInfo(left, right, y, engine_number, refittable, te);
889 if (articulated_cargo) {
891 int new_y = DrawCargoCapacityInfo(left, right, y, te, refittable);
894 DrawString(left, right, y,
GetString(STR_PURCHASE_INFO_CAPACITY, INVALID_CARGO, 0, STR_EMPTY));
914 y = DrawBadgeNameList({left, y, right, INT16_MAX}, e->badges,
static_cast<GrfSpecFeature>(GSF_TRAINS + e->
type));
932 DrawBadgeColumn(r, column_group, badge_classes, e->badges,
static_cast<GrfSpecFeature>(GSF_TRAINS + e->
type), e->info.
base_intro, remap);
947 static const std::array<int8_t, VehicleType::VEH_COMPANY_END> sprite_y_offsets = { 0, 0, -1, -1 };
955 int sprite_width = sprite_left + sprite_right;
959 auto badge_column_widths = badge_classes.GetColumnWidths();
969 uint biggest_num_engines = 0;
970 for (
auto it = first; it != last; ++it) {
972 biggest_num_engines = std::max(biggest_num_engines, num_engines);
982 const int offset = (rtl ? -circle_width : circle_width) / 2;
985 for (
auto it = first; it != last; ++it) {
986 const auto &item = *it;
997 if (item.indent > 0) {
999 int tx = (rtl ? ir.right : ir.left) + offset;
1000 for (uint lvl = 1; lvl <= item.indent; ++lvl) {
1002 if (lvl < item.indent) tx += level_width;
1007 GfxDrawLine(tx, ycentre, tx + offset - (rtl ? -1 : 1), ycentre, linecolour,
WidgetDimensions::scaled.fullbevel.top);
1012 DrawSpriteIgnorePadding(is_folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, {fr.left, textr.top, fr.right, textr.bottom},
SA_CENTER);
1021 if (badge_column_widths.size() >= 1 && badge_column_widths[0] > 0) {
1023 DrawEngineBadgeColumn(br, 0, badge_classes, e, pal);
1024 tr = tr.
Indent(badge_column_widths[0], rtl);
1027 int sprite_x = tr.
WithWidth(sprite_width, rtl).left + sprite_left;
1032 if (badge_column_widths.size() >= 2 && badge_column_widths[1] > 0) {
1034 DrawEngineBadgeColumn(br, 1, badge_classes, e, pal);
1035 tr = tr.
Indent(badge_column_widths[1], rtl);
1049 DrawSpriteIgnorePadding(SPR_GROUP_REPLACE_ACTIVE, num_engines == 0 ?
PALETTE_CRASH : PAL_NONE, rr,
SA_CENTER);
1053 if (badge_column_widths.size() >= 3 && badge_column_widths[2] > 0) {
1055 DrawEngineBadgeColumn(br, 2, badge_classes, e, pal);
1056 tr = tr.
Indent(badge_column_widths[2], !rtl);
1060 StringID str = hidden ? STR_HIDDEN_ENGINE_NAME : STR_ENGINE_NAME;
1065 DrawString(tr.left, tr.right, textr.top + normal_text_y_offset,
GetString(str, engine_name), tc);
1080 uint32_t hidden_mask = 0;
1103 for (
const auto &item : src) {
1104 if (item.variant_id != parent || item.engine_id == parent)
continue;
1121 if (indent > 0 || dst.empty())
return;
1124 uint16_t level_mask = 0;
1125 for (
auto it = std::rbegin(dst); std::next(it) != std::rend(dst); ++it) {
1126 auto next_it = std::next(it);
1127 SB(level_mask, it->indent, 1, it->indent <= next_it->indent);
1128 next_it->level_mask = level_mask;
1162 void SetBuyVehicleText()
1170 widget->
SetStringTip(STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_BUTTON + this->vehicle_type, STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_TOOLTIP + this->vehicle_type);
1172 widget->
SetStringTip(STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + this->vehicle_type, STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_TOOLTIP + this->vehicle_type);
1178 this->vehicle_type = type;
1180 this->
window_number = this->listview_mode ? (int)type : tile.base();
1197 widget->
SetToolTip(STR_BUY_VEHICLE_TRAIN_LIST_TOOLTIP + type);
1200 widget->
SetToolTip(STR_BUY_VEHICLE_TRAIN_HIDE_SHOW_TOGGLE_TOOLTIP + type);
1203 widget->
SetStringTip(STR_BUY_VEHICLE_TRAIN_RENAME_BUTTON + type, STR_BUY_VEHICLE_TRAIN_RENAME_TOOLTIP + type);
1206 widget->
SetStringTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + type, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + type);
1207 widget->
SetLowered(this->show_hidden_engines);
1209 this->details_height = ((this->vehicle_type ==
VEH_TRAIN) ? 10 : 9);
1223 this->GenerateBuildList();
1226 EngineID engine = EngineID::Invalid();
1228 if (it != this->eng_list.end()) engine = it->engine_id;
1229 this->SelectEngine(engine);
1235 switch (this->vehicle_type) {
1236 default: NOT_REACHED();
1238 if (this->listview_mode) {
1246 if (this->listview_mode) {
1264 switch (cargo_type) {
1288 this->sel_engine = engine;
1289 this->SetBuyVehicleText();
1291 if (this->sel_engine == EngineID::Invalid())
return;
1295 if (!this->listview_mode) {
1298 if (ret.Succeeded()) {
1300 this->te.
capacity = refit_capacity;
1310 this->te.FillDefaultCapacities(e);
1323 if (0 == this->eng_list.size()) {
1324 this->SelectEngine(EngineID::Invalid());
1326 this->SelectEngine(this->eng_list[0].engine_id);
1357 std::vector<EngineID> variants;
1358 EngineID sel_id = EngineID::Invalid();
1359 size_t num_engines = 0;
1381 if (!
FilterByText(e) && !btf.Filter(e->badges))
continue;
1389 while (
parent != EngineID::Invalid()) {
1390 variants.push_back(
parent);
1394 if (eid == this->sel_engine) sel_id = eid;
1398 for (
const auto &variant : variants) {
1406 this->SelectEngine(sel_id);
1409 _last_engine[0] = _last_engine[1] = EngineID::Invalid();
1424 void GenerateBuildRoadVehList()
1426 EngineID sel_id = EngineID::Invalid();
1428 this->eng_list.clear();
1439 if (!
FilterByText(e) && !btf.Filter(e->badges))
continue;
1443 if (eid == this->sel_engine) sel_id = eid;
1445 this->SelectEngine(sel_id);
1449 void GenerateBuildShipList()
1451 EngineID sel_id = EngineID::Invalid();
1452 this->eng_list.clear();
1462 if (!
FilterByText(e) && !btf.Filter(e->badges))
continue;
1466 if (eid == this->sel_engine) sel_id = eid;
1468 this->SelectEngine(sel_id);
1472 void GenerateBuildAircraftList()
1474 EngineID sel_id = EngineID::Invalid();
1476 this->eng_list.clear();
1494 if (!
FilterByText(e) && !btf.Filter(e->badges))
continue;
1498 if (eid == this->sel_engine) sel_id = eid;
1501 this->SelectEngine(sel_id);
1505 void GenerateBuildList()
1512 this->eng_list.clear();
1516 switch (this->vehicle_type) {
1517 default: NOT_REACHED();
1519 this->GenerateBuildTrainList(list);
1524 this->GenerateBuildRoadVehList();
1527 this->GenerateBuildShipList();
1530 this->GenerateBuildAircraftList();
1537 std::vector<EngineID> variants;
1538 for (
const auto &item : this->eng_list) {
1540 while (
parent != EngineID::Invalid()) {
1541 variants.push_back(
parent);
1546 for (
const auto &variant : variants) {
1556 this->eng_list.swap(list);
1579 list.push_back(MakeDropDownListIconItem(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index()));
1587 static const auto separators = {STR_BADGE_CONFIG_PREVIEW, STR_BADGE_CONFIG_NAME};
1588 return BuildBadgeClassConfigurationList(this->badge_classes,
BADGE_COLUMNS, separators);
1594 if (sel_eng == EngineID::Invalid())
return;
1605 bool refresh =
false;
1607 while (
parent != EngineID::Invalid()) {
1624 this->descending_sort_order ^=
true;
1631 this->show_hidden_engines ^=
true;
1641 if (it != this->eng_list.end()) {
1642 const auto &item = *it;
1646 assert(item.
variant_id != EngineID::Invalid());
1656 this->SelectEngine(e);
1660 }
else if (click_count > 1 && !this->listview_mode) {
1675 ShowDropDownList(
this, this->BuildBadgeConfigurationList(), -1, widget, 0,
false,
true);
1679 const Engine *e = (this->sel_engine == EngineID::Invalid()) ?
nullptr :
Engine::Get(this->sel_engine);
1687 this->BuildVehicle();
1692 if (sel_eng != EngineID::Invalid()) {
1693 this->rename_engine = sel_eng;
1706 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1708 if (!gui_scope)
return;
1710 if (this->vehicle_type ==
VEH_ROAD &&
1712 this->sort_criteria > 7) {
1713 this->sort_criteria = 0;
1706 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override {
…}
1723 if (this->vehicle_type ==
VEH_TRAIN && !this->listview_mode) {
1727 if (this->vehicle_type ==
VEH_ROAD && !this->listview_mode) {
1731 return GetString((this->listview_mode ? STR_VEHICLE_LIST_AVAILABLE_TRAINS : STR_BUY_VEHICLE_TRAIN_ALL_CAPTION) + this->vehicle_type);
1740 const Engine *e = (this->sel_engine == EngineID::Invalid()) ?
nullptr :
Engine::Get(this->sel_engine);
1742 return GetString(STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + this->vehicle_type);
1744 return GetString(STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + this->vehicle_type);
1757 size.height = 3 *
resize.height;
1768 d.height += padding.height;
1779 if (this->badge_classes.GetClasses().empty()) size = {0, 0};
1785 size.width += padding.width;
1786 size.height += padding.height;
1792 size.width += padding.width;
1793 size.height += padding.height;
1822 this->GenerateBuildList();
1823 this->vscroll->
SetCount(this->eng_list.size());
1835 if (this->sel_engine != EngineID::Invalid()) {
1840 if (needed_height != this->details_height) {
1842 this->details_height = needed_height;
1851 if (!str.has_value())
return;
1860 if (this->sort_criteria != index) {
1861 this->sort_criteria = index;
1874 this->SelectEngine(this->sel_engine);
1879 bool reopen = HandleBadgeConfigurationDropDownClick(
static_cast<GrfSpecFeature>(GSF_TRAINS + this->vehicle_type),
BADGE_COLUMNS, index, click_result);
1884 ReplaceDropDownList(
this, this->BuildBadgeConfigurationList(), -1);
1922 static inline HotkeyList hotkeys{
"buildvehicle", {
1928 WDP_AUTO,
"build_vehicle", 240, 268,
1931 _nested_build_vehicle_widgets,
1932 &BuildVehicleWindow::hotkeys
1941 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 cargo)
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 & Reset()
Reset all bits.
constexpr Timpl & Flip(Tvalue_type value)
Flip 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.
StringID build_caption
Caption of the build vehicle GUI for this rail type.
struct RailTypeInfo::@23 strings
Strings associated with the rail type.
uint8_t acceleration_type
Acceleration type of this rail type.
struct RoadTypeInfo::@26 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.
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
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.
@ 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.
Functions related to NewGRF badges.
Functions related to NewGRF badge configuration.
@ 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, std::span< int32_t > regs100)
Evaluate a newgrf callback for vehicles.
Functions for NewGRF engines.
std::string GetGRFStringWithTextStack(const struct GRFFile *grffile, GRFStringID grfstringid, std::span< const int32_t > textstack)
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.
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.
static constexpr int BADGE_COLUMNS
Number of columns available for badges (0 = left of image, 1 = between image and name,...
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 OnDropdownSelect(WidgetID widget, int index, int click_result) override
A dropdown option associated to this window has been selected.
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.
EngineID variant_id
Engine variant ID. If set, will be treated specially in purchase lists.
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.
bool IsVariantHidden(CompanyID c) const
Check whether the engine variant chain is hidden in the GUI for the given company.
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.
bool IsHidden(CompanyID c) const
Check whether the engine is hidden in the GUI for the given company.
EngineID display_last_variant
NOSAVE client-side-only last variant selected.
Information about GRF, used in the game and (part of it) in savegames.
std::string 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.
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.
std::string_view 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.
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
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 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_DROPDOWN_MENU
Drop down menu; Window numbers:
@ 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.