OpenTTD Source: src/build_vehicle_gui.cpp Source File

OpenTTD Source 15.0-RC2

build_vehicle_gui.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#include "stdafx.h"
11#include "engine_base.h"
12#include "engine_func.h"
13#include "station_base.h"
14#include "network/network.h"
15#include "articulated_vehicles.h"
16#include "textbuf_gui.h"
17#include "command_func.h"
18#include "company_func.h"
19#include "vehicle_gui.h"
20#include "newgrf_badge.h"
21#include "newgrf_badge_config.h"
22#include "newgrf_badge_gui.h"
23#include "newgrf_engine.h"
24#include "newgrf_text.h"
25#include "group.h"
26#include "string_func.h"
27#include "strings_func.h"
28#include "window_func.h"
29#include "timer/timer_game_calendar.h"
30#include "vehicle_func.h"
31#include "dropdown_type.h"
32#include "dropdown_func.h"
33#include "engine_gui.h"
34#include "cargotype.h"
35#include "core/geometry_func.hpp"
36#include "autoreplace_func.h"
37#include "engine_cmd.h"
38#include "train_cmd.h"
39#include "vehicle_cmd.h"
40#include "zoom_func.h"
41#include "querystring_gui.h"
42#include "stringfilter_type.h"
43#include "hotkeys.h"
44
45#include "widgets/build_vehicle_widget.h"
46
47#include "table/strings.h"
48
49#include "safeguards.h"
50
56uint GetEngineListHeight(VehicleType type)
57{
58 return std::max<uint>(GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.matrix.Vertical(), GetVehicleImageCellSize(type, EIT_PURCHASE).height);
59}
60
61static constexpr std::initializer_list<NWidgetPart> _nested_build_vehicle_widgets = {
62 NWidget(NWID_HORIZONTAL),
63 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
64 NWidget(WWT_CAPTION, COLOUR_GREY, WID_BV_CAPTION), SetTextStyle(TC_WHITE),
65 NWidget(WWT_SHADEBOX, COLOUR_GREY),
66 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
67 NWidget(WWT_STICKYBOX, COLOUR_GREY),
68 EndContainer(),
69 NWidget(NWID_VERTICAL),
70 NWidget(NWID_HORIZONTAL),
71 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_SORT_ASCENDING_DESCENDING), SetStringTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
72 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 0), SetToolTip(STR_TOOLTIP_SORT_CRITERIA),
73 EndContainer(),
74 NWidget(NWID_HORIZONTAL),
75 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BV_SHOW_HIDDEN_ENGINES),
76 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_CARGO_FILTER_DROPDOWN), SetResize(1, 0), SetFill(1, 0), SetToolTip(STR_TOOLTIP_FILTER_CRITERIA),
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),
78 EndContainer(),
79 NWidget(WWT_PANEL, COLOUR_GREY),
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),
81 EndContainer(),
82 NWidget(NWID_VERTICAL, NWidContainerFlag{}, WID_BV_BADGE_FILTER),
83 EndContainer(),
84 EndContainer(),
85 /* Vehicle list. */
86 NWidget(NWID_HORIZONTAL),
87 NWidget(WWT_MATRIX, COLOUR_GREY, WID_BV_LIST), SetResize(1, 1), SetFill(1, 0), SetMatrixDataTip(1, 0), SetScrollbar(WID_BV_SCROLLBAR),
88 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_BV_SCROLLBAR),
89 EndContainer(),
90 /* Panel with details. */
91 NWidget(WWT_PANEL, COLOUR_GREY, WID_BV_PANEL), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
92 /* Build/rename buttons, resize button. */
93 NWidget(NWID_HORIZONTAL),
94 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_BV_BUILD_SEL),
95 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_BUILD), SetResize(1, 0), SetFill(1, 0),
96 EndContainer(),
97 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_SHOW_HIDE), SetResize(1, 0), SetFill(1, 0),
98 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_RENAME), SetResize(1, 0), SetFill(1, 0),
99 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
100 EndContainer(),
101};
102
103
104 bool _engine_sort_direction;
105uint8_t _engine_sort_last_criteria[] = {0, 0, 0, 0};
106 bool _engine_sort_last_order[] = {false, false, false, false};
107 bool _engine_sort_show_hidden_engines[] = {false, false, false, false};
108 static CargoType _engine_sort_last_cargo_criteria[] = {CargoFilterCriteria::CF_ANY, CargoFilterCriteria::CF_ANY, CargoFilterCriteria::CF_ANY, CargoFilterCriteria::CF_ANY};
109
116 static bool EngineNumberSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
117{
118 int r = Engine::Get(a.engine_id)->list_position - Engine::Get(b.engine_id)->list_position;
119
120 return _engine_sort_direction ? r > 0 : r < 0;
121}
122
129 static bool EngineIntroDateSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
130{
131 const auto va = Engine::Get(a.engine_id)->intro_date;
132 const auto vb = Engine::Get(b.engine_id)->intro_date;
133 const auto r = va - vb;
134
135 /* Use EngineID to sort instead since we want consistent sorting */
136 if (r == 0) return EngineNumberSorter(a, b);
137 return _engine_sort_direction ? r > 0 : r < 0;
138}
139
140/* cached values for EngineNameSorter to spare many GetString() calls */
141static EngineID _last_engine[2] = { EngineID::Invalid(), EngineID::Invalid() };
142
149 static bool EngineNameSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
150{
151 static std::string last_name[2] = { {}, {} };
152
153 if (a.engine_id != _last_engine[0]) {
154 _last_engine[0] = a.engine_id;
155 last_name[0] = GetString(STR_ENGINE_NAME, PackEngineNameDParam(a.engine_id, EngineNameContext::PurchaseList));
156 }
157
158 if (b.engine_id != _last_engine[1]) {
159 _last_engine[1] = b.engine_id;
160 last_name[1] = GetString(STR_ENGINE_NAME, PackEngineNameDParam(b.engine_id, EngineNameContext::PurchaseList));
161 }
162
163 int r = StrNaturalCompare(last_name[0], last_name[1]); // Sort by name (natural sorting).
164
165 /* Use EngineID to sort instead since we want consistent sorting */
166 if (r == 0) return EngineNumberSorter(a, b);
167 return _engine_sort_direction ? r > 0 : r < 0;
168}
169
176 static bool EngineReliabilitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
177{
178 const int va = Engine::Get(a.engine_id)->reliability;
179 const int vb = Engine::Get(b.engine_id)->reliability;
180 const int r = va - vb;
181
182 /* Use EngineID to sort instead since we want consistent sorting */
183 if (r == 0) return EngineNumberSorter(a, b);
184 return _engine_sort_direction ? r > 0 : r < 0;
185}
186
193 static bool EngineCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
194{
195 Money va = Engine::Get(a.engine_id)->GetCost();
196 Money vb = Engine::Get(b.engine_id)->GetCost();
197 int r = ClampTo<int32_t>(va - vb);
198
199 /* Use EngineID to sort instead since we want consistent sorting */
200 if (r == 0) return EngineNumberSorter(a, b);
201 return _engine_sort_direction ? r > 0 : r < 0;
202}
203
210 static bool EngineSpeedSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
211{
212 int va = Engine::Get(a.engine_id)->GetDisplayMaxSpeed();
213 int vb = Engine::Get(b.engine_id)->GetDisplayMaxSpeed();
214 int r = va - vb;
215
216 /* Use EngineID to sort instead since we want consistent sorting */
217 if (r == 0) return EngineNumberSorter(a, b);
218 return _engine_sort_direction ? r > 0 : r < 0;
219}
220
227 static bool EnginePowerSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
228{
229 int va = Engine::Get(a.engine_id)->GetPower();
230 int vb = Engine::Get(b.engine_id)->GetPower();
231 int r = va - vb;
232
233 /* Use EngineID to sort instead since we want consistent sorting */
234 if (r == 0) return EngineNumberSorter(a, b);
235 return _engine_sort_direction ? r > 0 : r < 0;
236}
237
244 static bool EngineTractiveEffortSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
245{
246 int va = Engine::Get(a.engine_id)->GetDisplayMaxTractiveEffort();
247 int vb = Engine::Get(b.engine_id)->GetDisplayMaxTractiveEffort();
248 int r = va - vb;
249
250 /* Use EngineID to sort instead since we want consistent sorting */
251 if (r == 0) return EngineNumberSorter(a, b);
252 return _engine_sort_direction ? r > 0 : r < 0;
253}
254
261 static bool EngineRunningCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
262{
263 Money va = Engine::Get(a.engine_id)->GetRunningCost();
264 Money vb = Engine::Get(b.engine_id)->GetRunningCost();
265 int r = ClampTo<int32_t>(va - vb);
266
267 /* Use EngineID to sort instead since we want consistent sorting */
268 if (r == 0) return EngineNumberSorter(a, b);
269 return _engine_sort_direction ? r > 0 : r < 0;
270}
271
278 static bool EnginePowerVsRunningCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
279{
280 const Engine *e_a = Engine::Get(a.engine_id);
281 const Engine *e_b = Engine::Get(b.engine_id);
282 uint p_a = e_a->GetPower();
283 uint p_b = e_b->GetPower();
284 Money r_a = e_a->GetRunningCost();
285 Money r_b = e_b->GetRunningCost();
286 /* Check if running cost is zero in one or both engines.
287 * If only one of them is zero then that one has higher value,
288 * else if both have zero cost then compare powers. */
289 if (r_a == 0) {
290 if (r_b == 0) {
291 /* If it is ambiguous which to return go with their ID */
292 if (p_a == p_b) return EngineNumberSorter(a, b);
293 return _engine_sort_direction != (p_a < p_b);
294 }
295 return !_engine_sort_direction;
296 }
297 if (r_b == 0) return _engine_sort_direction;
298 /* Using double for more precision when comparing close values.
299 * This shouldn't have any major effects in performance nor in keeping
300 * the game in sync between players since it's used in GUI only in client side */
301 double v_a = (double)p_a / (double)r_a;
302 double v_b = (double)p_b / (double)r_b;
303 /* Use EngineID to sort if both have same power/running cost,
304 * since we want consistent sorting.
305 * Also if both have no power then sort with reverse of running cost to simulate
306 * previous sorting behaviour for wagons. */
307 if (v_a == 0 && v_b == 0) return EngineRunningCostSorter(b, a);
308 if (v_a == v_b) return EngineNumberSorter(a, b);
309 return _engine_sort_direction != (v_a < v_b);
310}
311
312/* Train sorting functions */
313
320 static bool TrainEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
321{
322 const RailVehicleInfo *rvi_a = RailVehInfo(a.engine_id);
323 const RailVehicleInfo *rvi_b = RailVehInfo(b.engine_id);
324
325 int va = GetTotalCapacityOfArticulatedParts(a.engine_id) * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
326 int vb = GetTotalCapacityOfArticulatedParts(b.engine_id) * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
327 int r = va - vb;
328
329 /* Use EngineID to sort instead since we want consistent sorting */
330 if (r == 0) return EngineNumberSorter(a, b);
331 return _engine_sort_direction ? r > 0 : r < 0;
332}
333
340 static bool TrainEnginesThenWagonsSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
341{
342 int val_a = (RailVehInfo(a.engine_id)->railveh_type == RAILVEH_WAGON ? 1 : 0);
343 int val_b = (RailVehInfo(b.engine_id)->railveh_type == RAILVEH_WAGON ? 1 : 0);
344 int r = val_a - val_b;
345
346 /* Use EngineID to sort instead since we want consistent sorting */
347 if (r == 0) return EngineNumberSorter(a, b);
348 return _engine_sort_direction ? r > 0 : r < 0;
349}
350
351/* Road vehicle sorting functions */
352
359 static bool RoadVehEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
360{
361 int va = GetTotalCapacityOfArticulatedParts(a.engine_id);
362 int vb = GetTotalCapacityOfArticulatedParts(b.engine_id);
363 int r = va - vb;
364
365 /* Use EngineID to sort instead since we want consistent sorting */
366 if (r == 0) return EngineNumberSorter(a, b);
367 return _engine_sort_direction ? r > 0 : r < 0;
368}
369
370/* Ship vehicle sorting functions */
371
378 static bool ShipEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
379{
380 const Engine *e_a = Engine::Get(a.engine_id);
381 const Engine *e_b = Engine::Get(b.engine_id);
382
383 int va = e_a->GetDisplayDefaultCapacity();
384 int vb = e_b->GetDisplayDefaultCapacity();
385 int r = va - vb;
386
387 /* Use EngineID to sort instead since we want consistent sorting */
388 if (r == 0) return EngineNumberSorter(a, b);
389 return _engine_sort_direction ? r > 0 : r < 0;
390}
391
392/* Aircraft sorting functions */
393
400 static bool AircraftEngineCargoSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
401{
402 const Engine *e_a = Engine::Get(a.engine_id);
403 const Engine *e_b = Engine::Get(b.engine_id);
404
405 uint16_t mail_a, mail_b;
406 int va = e_a->GetDisplayDefaultCapacity(&mail_a);
407 int vb = e_b->GetDisplayDefaultCapacity(&mail_b);
408 int r = va - vb;
409
410 if (r == 0) {
411 /* The planes have the same passenger capacity. Check mail capacity instead */
412 r = mail_a - mail_b;
413
414 if (r == 0) {
415 /* Use EngineID to sort instead since we want consistent sorting */
416 return EngineNumberSorter(a, b);
417 }
418 }
419 return _engine_sort_direction ? r > 0 : r < 0;
420}
421
428 static bool AircraftRangeSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
429{
430 uint16_t r_a = Engine::Get(a.engine_id)->GetRange();
431 uint16_t r_b = Engine::Get(b.engine_id)->GetRange();
432
433 int r = r_a - r_b;
434
435 /* Use EngineID to sort instead since we want consistent sorting */
436 if (r == 0) return EngineNumberSorter(a, b);
437 return _engine_sort_direction ? r > 0 : r < 0;
438}
439
441 EngList_SortTypeFunction * const _engine_sort_functions[][11] = {{
442 /* Trains */
443 &EngineNumberSorter,
444 &EngineCostSorter,
445 &EngineSpeedSorter,
446 &EnginePowerSorter,
447 &EngineTractiveEffortSorter,
448 &EngineIntroDateSorter,
449 &EngineNameSorter,
450 &EngineRunningCostSorter,
451 &EnginePowerVsRunningCostSorter,
452 &EngineReliabilitySorter,
453 &TrainEngineCapacitySorter,
454}, {
455 /* Road vehicles */
456 &EngineNumberSorter,
457 &EngineCostSorter,
458 &EngineSpeedSorter,
459 &EnginePowerSorter,
460 &EngineTractiveEffortSorter,
461 &EngineIntroDateSorter,
462 &EngineNameSorter,
463 &EngineRunningCostSorter,
464 &EnginePowerVsRunningCostSorter,
465 &EngineReliabilitySorter,
466 &RoadVehEngineCapacitySorter,
467}, {
468 /* Ships */
469 &EngineNumberSorter,
470 &EngineCostSorter,
471 &EngineSpeedSorter,
472 &EngineIntroDateSorter,
473 &EngineNameSorter,
474 &EngineRunningCostSorter,
475 &EngineReliabilitySorter,
476 &ShipEngineCapacitySorter,
477}, {
478 /* Aircraft */
479 &EngineNumberSorter,
480 &EngineCostSorter,
481 &EngineSpeedSorter,
482 &EngineIntroDateSorter,
483 &EngineNameSorter,
484 &EngineRunningCostSorter,
485 &EngineReliabilitySorter,
486 &AircraftEngineCargoSorter,
487 &AircraftRangeSorter,
488}};
489
491 const std::initializer_list<const StringID> _engine_sort_listing[] = {{
492 /* Trains */
493 STR_SORT_BY_ENGINE_ID,
494 STR_SORT_BY_COST,
495 STR_SORT_BY_MAX_SPEED,
496 STR_SORT_BY_POWER,
497 STR_SORT_BY_TRACTIVE_EFFORT,
498 STR_SORT_BY_INTRO_DATE,
499 STR_SORT_BY_NAME,
500 STR_SORT_BY_RUNNING_COST,
501 STR_SORT_BY_POWER_VS_RUNNING_COST,
502 STR_SORT_BY_RELIABILITY,
503 STR_SORT_BY_CARGO_CAPACITY,
504}, {
505 /* Road vehicles */
506 STR_SORT_BY_ENGINE_ID,
507 STR_SORT_BY_COST,
508 STR_SORT_BY_MAX_SPEED,
509 STR_SORT_BY_POWER,
510 STR_SORT_BY_TRACTIVE_EFFORT,
511 STR_SORT_BY_INTRO_DATE,
512 STR_SORT_BY_NAME,
513 STR_SORT_BY_RUNNING_COST,
514 STR_SORT_BY_POWER_VS_RUNNING_COST,
515 STR_SORT_BY_RELIABILITY,
516 STR_SORT_BY_CARGO_CAPACITY,
517}, {
518 /* Ships */
519 STR_SORT_BY_ENGINE_ID,
520 STR_SORT_BY_COST,
521 STR_SORT_BY_MAX_SPEED,
522 STR_SORT_BY_INTRO_DATE,
523 STR_SORT_BY_NAME,
524 STR_SORT_BY_RUNNING_COST,
525 STR_SORT_BY_RELIABILITY,
526 STR_SORT_BY_CARGO_CAPACITY,
527}, {
528 /* Aircraft */
529 STR_SORT_BY_ENGINE_ID,
530 STR_SORT_BY_COST,
531 STR_SORT_BY_MAX_SPEED,
532 STR_SORT_BY_INTRO_DATE,
533 STR_SORT_BY_NAME,
534 STR_SORT_BY_RUNNING_COST,
535 STR_SORT_BY_RELIABILITY,
536 STR_SORT_BY_CARGO_CAPACITY,
537 STR_SORT_BY_RANGE,
538}};
539
541 static bool CargoAndEngineFilter(const GUIEngineListItem *item, const CargoType cargo_type)
542{
543 if (cargo_type == CargoFilterCriteria::CF_ANY) {
544 return true;
545 } else if (cargo_type == CargoFilterCriteria::CF_ENGINES) {
546 return Engine::Get(item->engine_id)->GetPower() != 0;
547 } else {
548 CargoTypes refit_mask = GetUnionOfArticulatedRefitMasks(item->engine_id, true) & _standard_cargo_mask;
549 return (cargo_type == CargoFilterCriteria::CF_NONE ? refit_mask == 0 : HasBit(refit_mask, cargo_type));
550 }
551}
552
553static GUIEngineList::FilterFunction * const _engine_filter_funcs[] = {
554 &CargoAndEngineFilter,
555};
556
557static uint GetCargoWeight(const CargoArray &cap, VehicleType vtype)
558{
559 uint weight = 0;
560 for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
561 if (cap[cargo] != 0) {
562 if (vtype == VEH_TRAIN) {
563 weight += CargoSpec::Get(cargo)->WeightOfNUnitsInTrain(cap[cargo]);
564 } else {
565 weight += CargoSpec::Get(cargo)->WeightOfNUnits(cap[cargo]);
566 }
567 }
568 }
569 return weight;
570}
571
572static int DrawCargoCapacityInfo(int left, int right, int y, TestedEngineDetails &te, bool refittable)
573{
574 for (const CargoSpec *cs : _sorted_cargo_specs) {
575 CargoType cargo_type = cs->Index();
576 if (te.all_capacities[cargo_type] == 0) continue;
577
578 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_CAPACITY, cargo_type, te.all_capacities[cargo_type], refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY));
579 y += GetCharacterHeight(FS_NORMAL);
580 }
581
582 return y;
583}
584
585/* Draw rail wagon specific details */
586static int DrawRailWagonPurchaseInfo(int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi, TestedEngineDetails &te)
587{
588 const Engine *e = Engine::Get(engine_number);
589
590 /* Purchase cost */
591 if (te.cost != 0) {
592 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_COST_REFIT, e->GetCost() + te.cost, te.cost));
593 } else {
594 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_COST, e->GetCost()));
595 }
596 y += GetCharacterHeight(FS_NORMAL);
597
598 /* Wagon weight - (including cargo) */
599 uint weight = e->GetDisplayWeight();
600 DrawString(left, right, y,
601 GetString(STR_PURCHASE_INFO_WEIGHT_CWEIGHT, weight, GetCargoWeight(te.all_capacities, VEH_TRAIN) + weight));
602 y += GetCharacterHeight(FS_NORMAL);
603
604 /* Wagon speed limit, displayed if above zero */
605 if (_settings_game.vehicle.wagon_speed_limits) {
606 uint max_speed = e->GetDisplayMaxSpeed();
607 if (max_speed > 0) {
608 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_SPEED, PackVelocity(max_speed, e->type)));
609 y += GetCharacterHeight(FS_NORMAL);
610 }
611 }
612
613 /* Running cost */
614 if (rvi->running_cost_class != INVALID_PRICE) {
615 DrawString(left, right, y, GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_PURCHASE_INFO_RUNNINGCOST_PERIOD : STR_PURCHASE_INFO_RUNNINGCOST_YEAR, e->GetRunningCost()));
616 y += GetCharacterHeight(FS_NORMAL);
617 }
618
619 return y;
620}
621
622/* Draw locomotive specific details */
623static int DrawRailEnginePurchaseInfo(int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi, TestedEngineDetails &te)
624{
625 const Engine *e = Engine::Get(engine_number);
626
627 /* Purchase Cost - Engine weight */
628 if (te.cost != 0) {
629 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_COST_REFIT_WEIGHT, e->GetCost() + te.cost, te.cost, e->GetDisplayWeight()));
630 } else {
631 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_COST_WEIGHT, e->GetCost(), e->GetDisplayWeight()));
632 }
633 y += GetCharacterHeight(FS_NORMAL);
634
635 /* Supported rail types */
636 std::string railtypes{};
637 std::string_view list_separator = GetListSeparator();
638
639 for (const auto &rt : _sorted_railtypes) {
640 if (!rvi->railtypes.Test(rt)) continue;
641
642 if (!railtypes.empty()) railtypes += list_separator;
643 AppendStringInPlace(railtypes, GetRailTypeInfo(rt)->strings.name);
644 }
645 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_RAILTYPES, railtypes));
646 y += GetCharacterHeight(FS_NORMAL);
647
648 /* Max speed - Engine power */
649 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_SPEED_POWER, PackVelocity(e->GetDisplayMaxSpeed(), e->type), e->GetPower()));
650 y += GetCharacterHeight(FS_NORMAL);
651
652 /* Max tractive effort - not applicable if old acceleration or maglev */
653 if (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL) {
654 bool is_maglev = true;
655 for (RailType rt : rvi->railtypes) {
656 is_maglev &= GetRailTypeInfo(rt)->acceleration_type == VehicleAccelerationModel::Maglev;
657 }
658 if (!is_maglev) {
659 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_MAX_TE, e->GetDisplayMaxTractiveEffort()));
660 y += GetCharacterHeight(FS_NORMAL);
661 }
662 }
663
664 /* Running cost */
665 if (rvi->running_cost_class != INVALID_PRICE) {
666 DrawString(left, right, y, GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_PURCHASE_INFO_RUNNINGCOST_PERIOD : STR_PURCHASE_INFO_RUNNINGCOST_YEAR, e->GetRunningCost()));
667 y += GetCharacterHeight(FS_NORMAL);
668 }
669
670 /* Powered wagons power - Powered wagons extra weight */
671 if (rvi->pow_wag_power != 0) {
672 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT, rvi->pow_wag_power, rvi->pow_wag_weight));
673 y += GetCharacterHeight(FS_NORMAL);
674 }
675
676 return y;
677}
678
679/* Draw road vehicle specific details */
680static int DrawRoadVehPurchaseInfo(int left, int right, int y, EngineID engine_number, TestedEngineDetails &te)
681{
682 const Engine *e = Engine::Get(engine_number);
683
684 if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) {
685 /* Purchase Cost */
686 if (te.cost != 0) {
687 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_COST_REFIT, e->GetCost() + te.cost, te.cost));
688 } else {
689 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_COST, e->GetCost()));
690 }
691 y += GetCharacterHeight(FS_NORMAL);
692
693 /* Road vehicle weight - (including cargo) */
694 int16_t weight = e->GetDisplayWeight();
695 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_WEIGHT_CWEIGHT, weight, GetCargoWeight(te.all_capacities, VEH_ROAD) + weight));
696 y += GetCharacterHeight(FS_NORMAL);
697
698 /* Max speed - Engine power */
699 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_SPEED_POWER, PackVelocity(e->GetDisplayMaxSpeed(), e->type), e->GetPower()));
700 y += GetCharacterHeight(FS_NORMAL);
701
702 /* Max tractive effort */
703 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_MAX_TE, e->GetDisplayMaxTractiveEffort()));
704 y += GetCharacterHeight(FS_NORMAL);
705 } else {
706 /* Purchase cost - Max speed */
707 if (te.cost != 0) {
708 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_COST_REFIT_SPEED, e->GetCost() + te.cost, te.cost, PackVelocity(e->GetDisplayMaxSpeed(), e->type)));
709 } else {
710 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_COST_SPEED, e->GetCost(), PackVelocity(e->GetDisplayMaxSpeed(), e->type)));
711 }
712 y += GetCharacterHeight(FS_NORMAL);
713 }
714
715 /* Running cost */
716 DrawString(left, right, y, GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_PURCHASE_INFO_RUNNINGCOST_PERIOD : STR_PURCHASE_INFO_RUNNINGCOST_YEAR, e->GetRunningCost()));
717 y += GetCharacterHeight(FS_NORMAL);
718
719 return y;
720}
721
722/* Draw ship specific details */
723static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable, TestedEngineDetails &te)
724{
725 const Engine *e = Engine::Get(engine_number);
726
727 /* Purchase cost - Max speed */
728 uint raw_speed = e->GetDisplayMaxSpeed();
729 uint ocean_speed = e->VehInfo<ShipVehicleInfo>().ApplyWaterClassSpeedFrac(raw_speed, true);
730 uint canal_speed = e->VehInfo<ShipVehicleInfo>().ApplyWaterClassSpeedFrac(raw_speed, false);
731
732 if (ocean_speed == canal_speed) {
733 if (te.cost != 0) {
734 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_COST_REFIT_SPEED, e->GetCost() + te.cost, te.cost, PackVelocity(ocean_speed, e->type)));
735 } else {
736 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_COST_SPEED, e->GetCost(), PackVelocity(ocean_speed, e->type)));
737 }
738 y += GetCharacterHeight(FS_NORMAL);
739 } else {
740 if (te.cost != 0) {
741 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_COST_REFIT, e->GetCost() + te.cost, te.cost));
742 } else {
743 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_COST, e->GetCost()));
744 }
745 y += GetCharacterHeight(FS_NORMAL);
746
747 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_SPEED_OCEAN, PackVelocity(ocean_speed, e->type)));
748 y += GetCharacterHeight(FS_NORMAL);
749
750 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_SPEED_CANAL, PackVelocity(canal_speed, e->type)));
751 y += GetCharacterHeight(FS_NORMAL);
752 }
753
754 /* Cargo type + capacity */
755 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_CAPACITY, te.cargo, te.capacity, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY));
756 y += GetCharacterHeight(FS_NORMAL);
757
758 /* Running cost */
759 DrawString(left, right, y, GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_PURCHASE_INFO_RUNNINGCOST_PERIOD : STR_PURCHASE_INFO_RUNNINGCOST_YEAR, e->GetRunningCost()));
760 y += GetCharacterHeight(FS_NORMAL);
761
762 return y;
763}
764
774 static int DrawAircraftPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable, TestedEngineDetails &te)
775{
776 const Engine *e = Engine::Get(engine_number);
777
778 /* Purchase cost - Max speed */
779 if (te.cost != 0) {
780 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_COST_REFIT_SPEED, e->GetCost() + te.cost, te.cost, PackVelocity(e->GetDisplayMaxSpeed(), e->type)));
781 } else {
782 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_COST_SPEED, e->GetCost(), PackVelocity(e->GetDisplayMaxSpeed(), e->type)));
783 }
784 y += GetCharacterHeight(FS_NORMAL);
785
786 /* Cargo capacity */
787 if (te.mail_capacity > 0) {
788 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_AIRCRAFT_CAPACITY, te.cargo, te.capacity, GetCargoTypeByLabel(CT_MAIL), te.mail_capacity));
789 } else {
790 /* Note, if the default capacity is selected by the refit capacity
791 * callback, then the capacity shown is likely to be incorrect. */
792 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_CAPACITY, te.cargo, te.capacity, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY));
793 }
794 y += GetCharacterHeight(FS_NORMAL);
795
796 /* Running cost */
797 DrawString(left, right, y, GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_PURCHASE_INFO_RUNNINGCOST_PERIOD : STR_PURCHASE_INFO_RUNNINGCOST_YEAR, e->GetRunningCost()));
798 y += GetCharacterHeight(FS_NORMAL);
799
800 /* Aircraft type */
801 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_AIRCRAFT_TYPE, e->GetAircraftTypeText()));
802 y += GetCharacterHeight(FS_NORMAL);
803
804 /* Aircraft range, if available. */
805 uint16_t range = e->GetRange();
806 if (range != 0) {
807 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_AIRCRAFT_RANGE, range));
808 y += GetCharacterHeight(FS_NORMAL);
809 }
810
811 return y;
812}
813
814
820 static std::optional<std::string> GetNewGRFAdditionalText(EngineID engine)
821{
822 std::array<int32_t, 16> regs100;
823 uint16_t callback = GetVehicleCallback(CBID_VEHICLE_ADDITIONAL_TEXT, 0, 0, engine, nullptr, regs100);
824 if (callback == CALLBACK_FAILED || callback == 0x400) return std::nullopt;
825 const GRFFile *grffile = Engine::Get(engine)->GetGRF();
826 assert(grffile != nullptr);
827 if (callback == 0x40F) {
828 return GetGRFStringWithTextStack(grffile, static_cast<GRFStringID>(regs100[0]), std::span{regs100}.subspan(1));
829 }
830 if (callback > 0x400) {
831 ErrorUnknownCallbackResult(grffile->grfid, CBID_VEHICLE_ADDITIONAL_TEXT, callback);
832 return std::nullopt;
833 }
834
835 return GetGRFStringWithTextStack(grffile, GRFSTR_MISC_GRF_TEXT + callback, regs100);
836}
837
846 static uint ShowAdditionalText(int left, int right, int y, EngineID engine)
847{
848 auto text = GetNewGRFAdditionalText(engine);
849 if (!text) return y;
850 return DrawStringMultiLine(left, right, y, INT32_MAX, *text, TC_BLACK);
851}
852
853void TestedEngineDetails::FillDefaultCapacities(const Engine *e)
854{
855 this->cargo = e->GetDefaultCargoType();
856 if (e->type == VEH_TRAIN || e->type == VEH_ROAD) {
857 this->all_capacities = GetCapacityOfArticulatedParts(e->index);
858 this->capacity = this->all_capacities[this->cargo];
859 this->mail_capacity = 0;
860 } else {
861 this->capacity = e->GetDisplayDefaultCapacity(&this->mail_capacity);
862 this->all_capacities[this->cargo] = this->capacity;
863 if (IsValidCargoType(GetCargoTypeByLabel(CT_MAIL))) {
864 this->all_capacities[GetCargoTypeByLabel(CT_MAIL)] = this->mail_capacity;
865 } else {
866 this->mail_capacity = 0;
867 }
868 }
869 if (this->all_capacities.GetCount() == 0) this->cargo = INVALID_CARGO;
870}
871
878 int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number, TestedEngineDetails &te)
879{
880 const Engine *e = Engine::Get(engine_number);
881 TimerGameCalendar::YearMonthDay ymd = TimerGameCalendar::ConvertDateToYMD(e->intro_date);
882 bool refittable = IsArticulatedVehicleRefittable(engine_number);
883 bool articulated_cargo = false;
884
885 switch (e->type) {
886 default: NOT_REACHED();
887 case VEH_TRAIN:
888 if (e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON) {
889 y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, &e->VehInfo<RailVehicleInfo>(), te);
890 } else {
891 y = DrawRailEnginePurchaseInfo(left, right, y, engine_number, &e->VehInfo<RailVehicleInfo>(), te);
892 }
893 articulated_cargo = true;
894 break;
895
896 case VEH_ROAD:
897 y = DrawRoadVehPurchaseInfo(left, right, y, engine_number, te);
898 articulated_cargo = true;
899 break;
900
901 case VEH_SHIP:
902 y = DrawShipPurchaseInfo(left, right, y, engine_number, refittable, te);
903 break;
904
905 case VEH_AIRCRAFT:
906 y = DrawAircraftPurchaseInfo(left, right, y, engine_number, refittable, te);
907 break;
908 }
909
910 if (articulated_cargo) {
911 /* Cargo type + capacity, or N/A */
912 int new_y = DrawCargoCapacityInfo(left, right, y, te, refittable);
913
914 if (new_y == y) {
915 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_CAPACITY, INVALID_CARGO, 0, STR_EMPTY));
916 y += GetCharacterHeight(FS_NORMAL);
917 } else {
918 y = new_y;
919 }
920 }
921
922 /* Draw details that apply to all types except rail wagons. */
923 if (e->type != VEH_TRAIN || e->VehInfo<RailVehicleInfo>().railveh_type != RAILVEH_WAGON) {
924 /* Design date - Life length */
925 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_DESIGNED_LIFE, ymd.year, TimerGameCalendar::DateToYear(e->GetLifeLengthInDays())));
926 y += GetCharacterHeight(FS_NORMAL);
927
928 /* Reliability */
929 DrawString(left, right, y, GetString(STR_PURCHASE_INFO_RELIABILITY, ToPercent16(e->reliability)));
930 y += GetCharacterHeight(FS_NORMAL);
931 }
932
933 if (refittable) y = ShowRefitOptionsList(left, right, y, engine_number);
934
935 y = DrawBadgeNameList({left, y, right, INT16_MAX}, e->badges, static_cast<GrfSpecFeature>(GSF_TRAINS + e->type));
936
937 /* Additional text from NewGRF */
938 y = ShowAdditionalText(left, right, y, engine_number);
939
940 /* The NewGRF's name which the vehicle comes from */
941 const GRFConfig *config = GetGRFConfig(e->GetGRFID());
942 if (_settings_client.gui.show_newgrf_name && config != nullptr)
943 {
944 DrawString(left, right, y, config->GetName(), TC_BLACK);
945 y += GetCharacterHeight(FS_NORMAL);
946 }
947
948 return y;
949}
950
951static void DrawEngineBadgeColumn(const Rect &r, int column_group, const GUIBadgeClasses &badge_classes, const Engine *e, PaletteID remap)
952{
953 DrawBadgeColumn(r, column_group, badge_classes, e->badges, static_cast<GrfSpecFeature>(GSF_TRAINS + e->type), e->info.base_intro, remap);
954}
955
966 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)
967{
968 static const std::array<int8_t, VehicleType::VEH_COMPANY_END> sprite_y_offsets = { 0, 0, -1, -1 };
969
970 auto [first, last] = sb.GetVisibleRangeIterators(eng_list);
971
972 bool rtl = _current_text_dir == TD_RTL;
973 int step_size = GetEngineListHeight(type);
974 int sprite_left = GetVehicleImageCellSize(type, EIT_PURCHASE).extend_left;
975 int sprite_right = GetVehicleImageCellSize(type, EIT_PURCHASE).extend_right;
976 int sprite_width = sprite_left + sprite_right;
977 int circle_width = std::max(GetScaledSpriteSize(SPR_CIRCLE_FOLDED).width, GetScaledSpriteSize(SPR_CIRCLE_UNFOLDED).width);
978 PixelColour linecolour = GetColourGradient(COLOUR_ORANGE, SHADE_NORMAL);
979
980 auto badge_column_widths = badge_classes.GetColumnWidths();
981
982 Rect ir = r.WithHeight(step_size).Shrink(WidgetDimensions::scaled.matrix, RectPadding::zero);
983 int sprite_y_offset = ScaleSpriteTrad(sprite_y_offsets[type]) + ir.Height() / 2;
984
985 Dimension replace_icon = {0, 0};
986 int count_width = 0;
987 if (show_count) {
988 replace_icon = GetSpriteSize(SPR_GROUP_REPLACE_ACTIVE);
989
990 uint biggest_num_engines = 0;
991 for (auto it = first; it != last; ++it) {
992 const uint num_engines = GetGroupNumEngines(_local_company, selected_group, it->engine_id);
993 biggest_num_engines = std::max(biggest_num_engines, num_engines);
994 }
995
996 count_width = GetStringBoundingBox(GetString(STR_JUST_COMMA, biggest_num_engines), FS_SMALL).width;
997 }
998
999 const int text_row_height = ir.Shrink(WidgetDimensions::scaled.matrix).Height();
1000 const int normal_text_y_offset = (text_row_height - GetCharacterHeight(FS_NORMAL)) / 2;
1001 const int small_text_y_offset = text_row_height - GetCharacterHeight(FS_SMALL);
1002
1003 const int offset = (rtl ? -circle_width : circle_width) / 2;
1004 const int level_width = rtl ? -WidgetDimensions::scaled.hsep_indent : WidgetDimensions::scaled.hsep_indent;
1005
1006 for (auto it = first; it != last; ++it) {
1007 const auto &item = *it;
1008 const Engine *e = Engine::Get(item.engine_id);
1009
1010 uint indent = item.indent * WidgetDimensions::scaled.hsep_indent;
1011 bool has_variants = item.flags.Test(EngineDisplayFlag::HasVariants);
1012 bool is_folded = item.flags.Test(EngineDisplayFlag::IsFolded);
1013 bool shaded = item.flags.Test(EngineDisplayFlag::Shaded);
1014
1015 Rect textr = ir.Shrink(WidgetDimensions::scaled.matrix);
1016 Rect tr = ir.Indent(indent, rtl);
1017
1018 if (item.indent > 0) {
1019 /* Draw tree continuation lines. */
1020 int tx = (rtl ? ir.right : ir.left) + offset;
1021 for (uint lvl = 1; lvl <= item.indent; ++lvl) {
1022 if (HasBit(item.level_mask, lvl)) GfxDrawLine(tx, ir.top, tx, ir.bottom, linecolour, WidgetDimensions::scaled.fullbevel.top);
1023 if (lvl < item.indent) tx += level_width;
1024 }
1025 /* Draw our node in the tree. */
1026 int ycentre = CentreBounds(textr.top, textr.bottom, WidgetDimensions::scaled.fullbevel.top);
1027 if (!HasBit(item.level_mask, item.indent)) GfxDrawLine(tx, ir.top, tx, ycentre, linecolour, WidgetDimensions::scaled.fullbevel.top);
1028 GfxDrawLine(tx, ycentre, tx + offset - (rtl ? -1 : 1), ycentre, linecolour, WidgetDimensions::scaled.fullbevel.top);
1029 }
1030
1031 if (has_variants) {
1032 Rect fr = tr.WithWidth(circle_width, rtl);
1033 DrawSpriteIgnorePadding(is_folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, fr.WithY(textr), SA_CENTER);
1034 }
1035
1036 tr = tr.Indent(circle_width + WidgetDimensions::scaled.hsep_normal, rtl);
1037
1038 /* Note: num_engines is only used in the autoreplace GUI, so it is correct to use _local_company here. */
1039 const uint num_engines = GetGroupNumEngines(_local_company, selected_group, item.engine_id);
1040 const PaletteID pal = (show_count && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(item.engine_id, _local_company);
1041
1042 if (badge_column_widths.size() >= 1 && badge_column_widths[0] > 0) {
1043 Rect br = tr.WithWidth(badge_column_widths[0], rtl);
1044 DrawEngineBadgeColumn(br, 0, badge_classes, e, pal);
1045 tr = tr.Indent(badge_column_widths[0], rtl);
1046 }
1047
1048 int sprite_x = tr.WithWidth(sprite_width, rtl).left + sprite_left;
1049 DrawVehicleEngine(r.left, r.right, sprite_x, tr.top + sprite_y_offset, item.engine_id, pal, EIT_PURCHASE);
1050
1051 tr = tr.Indent(sprite_width + WidgetDimensions::scaled.hsep_wide, rtl);
1052
1053 if (badge_column_widths.size() >= 2 && badge_column_widths[1] > 0) {
1054 Rect br = tr.WithWidth(badge_column_widths[1], rtl);
1055 DrawEngineBadgeColumn(br, 1, badge_classes, e, pal);
1056 tr = tr.Indent(badge_column_widths[1], rtl);
1057 }
1058
1059 if (show_count) {
1060 /* Rect for replace-protection icon. */
1061 Rect rr = tr.WithWidth(replace_icon.width, !rtl);
1062 tr = tr.Indent(replace_icon.width + WidgetDimensions::scaled.hsep_normal, !rtl);
1063 /* Rect for engine type count text. */
1064 Rect cr = tr.WithWidth(count_width, !rtl);
1065 tr = tr.Indent(count_width + WidgetDimensions::scaled.hsep_normal, !rtl);
1066
1067 DrawString(cr.left, cr.right, textr.top + small_text_y_offset, GetString(STR_JUST_COMMA, num_engines), TC_BLACK, SA_RIGHT | SA_FORCE, false, FS_SMALL);
1068
1069 if (EngineHasReplacementForCompany(Company::Get(_local_company), item.engine_id, selected_group)) {
1070 DrawSpriteIgnorePadding(SPR_GROUP_REPLACE_ACTIVE, num_engines == 0 ? PALETTE_CRASH : PAL_NONE, rr, SA_CENTER);
1071 }
1072 }
1073
1074 if (badge_column_widths.size() >= 3 && badge_column_widths[2] > 0) {
1075 Rect br = tr.WithWidth(badge_column_widths[2], !rtl).Indent(WidgetDimensions::scaled.hsep_wide, rtl);
1076 DrawEngineBadgeColumn(br, 2, badge_classes, e, pal);
1077 tr = tr.Indent(badge_column_widths[2], !rtl);
1078 }
1079
1080 bool hidden = e->company_hidden.Test(_local_company);
1081 StringID str = hidden ? STR_HIDDEN_ENGINE_NAME : STR_ENGINE_NAME;
1082 TextColour tc = (item.engine_id == selected_id) ? TC_WHITE : ((hidden | shaded) ? (TC_GREY | TC_FORCED | TC_NO_SHADE) : TC_BLACK);
1083
1084 /* If the count is visible then this is part of in-use autoreplace list. */
1085 auto engine_name = PackEngineNameDParam(item.engine_id, show_count ? EngineNameContext::AutoreplaceVehicleInUse : EngineNameContext::PurchaseList, item.indent);
1086 DrawString(tr.left, tr.right, textr.top + normal_text_y_offset,GetString(str, engine_name), tc);
1087
1088 ir = ir.Translate(0, step_size);
1089 }
1090}
1091
1099 void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selected, WidgetID button)
1100{
1101 uint32_t hidden_mask = 0;
1102 /* Disable sorting by power or tractive effort when the original acceleration model for road vehicles is being used. */
1103 if (vehicle_type == VEH_ROAD && _settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) {
1104 SetBit(hidden_mask, 3); // power
1105 SetBit(hidden_mask, 4); // tractive effort
1106 SetBit(hidden_mask, 8); // power by running costs
1107 }
1108 /* Disable sorting by tractive effort when the original acceleration model for trains is being used. */
1109 if (vehicle_type == VEH_TRAIN && _settings_game.vehicle.train_acceleration_model == AM_ORIGINAL) {
1110 SetBit(hidden_mask, 4); // tractive effort
1111 }
1112 ShowDropDownMenu(w, _engine_sort_listing[vehicle_type], selected, button, 0, hidden_mask);
1113}
1114
1122 void GUIEngineListAddChildren(GUIEngineList &dst, const GUIEngineList &src, EngineID parent, uint8_t indent)
1123{
1124 for (const auto &item : src) {
1125 if (item.variant_id != parent || item.engine_id == parent) continue;
1126
1127 const Engine *e = Engine::Get(item.engine_id);
1128 EngineDisplayFlags flags = item.flags;
1129 if (e->display_last_variant != EngineID::Invalid()) flags.Reset(EngineDisplayFlag::Shaded);
1130 dst.emplace_back(e->display_last_variant == EngineID::Invalid() ? item.engine_id : e->display_last_variant, item.engine_id, flags, indent);
1131
1132 /* Add variants if not folded */
1133 if (item.flags.Test(EngineDisplayFlag::HasVariants) && !item.flags.Test(EngineDisplayFlag::IsFolded)) {
1134 /* Add this engine again as a child */
1135 if (!item.flags.Test(EngineDisplayFlag::Shaded)) {
1136 dst.emplace_back(item.engine_id, item.engine_id, EngineDisplayFlags{}, indent + 1);
1137 }
1138 GUIEngineListAddChildren(dst, src, item.engine_id, indent + 1);
1139 }
1140 }
1141
1142 if (indent > 0 || dst.empty()) return;
1143
1144 /* Hierarchy is complete, traverse in reverse to find where indentation levels continue. */
1145 uint16_t level_mask = 0;
1146 for (auto it = std::rbegin(dst); std::next(it) != std::rend(dst); ++it) {
1147 auto next_it = std::next(it);
1148 SB(level_mask, it->indent, 1, it->indent <= next_it->indent);
1149 next_it->level_mask = level_mask;
1150 }
1151}
1152
1154 struct BuildVehicleWindow : Window {
1155 VehicleType vehicle_type = VEH_INVALID;
1156 union {
1157 RailType railtype;
1158 RoadType roadtype;
1159 } filter{};
1160 bool descending_sort_order = false;
1161 uint8_t sort_criteria = 0;
1162 bool show_hidden_engines = false;
1163 bool listview_mode = false;
1164 EngineID sel_engine = EngineID::Invalid();
1165 EngineID rename_engine = EngineID::Invalid();
1166 GUIEngineList eng_list{};
1167 CargoType cargo_filter_criteria{};
1168 int details_height = 0;
1169 Scrollbar *vscroll = nullptr;
1170 TestedEngineDetails te{};
1171 GUIBadgeClasses badge_classes{};
1172
1173 static constexpr int BADGE_COLUMNS = 3;
1174
1175 StringFilter string_filter{};
1176 QueryString vehicle_editbox;
1177
1178 std::pair<WidgetID, WidgetID> badge_filters{};
1179 BadgeFilterChoices badge_filter_choices{};
1180
1181 void SetBuyVehicleText()
1182 {
1183 NWidgetCore *widget = this->GetWidget<NWidgetCore>(WID_BV_BUILD);
1184
1185 bool refit = this->sel_engine != EngineID::Invalid() && this->cargo_filter_criteria != CargoFilterCriteria::CF_ANY && this->cargo_filter_criteria != CargoFilterCriteria::CF_NONE && this->cargo_filter_criteria != CargoFilterCriteria::CF_ENGINES;
1186 if (refit) refit = Engine::Get(this->sel_engine)->GetDefaultCargoType() != this->cargo_filter_criteria;
1187
1188 if (refit) {
1189 widget->SetStringTip(STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_BUTTON + this->vehicle_type, STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_TOOLTIP + this->vehicle_type);
1190 } else {
1191 widget->SetStringTip(STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + this->vehicle_type, STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_TOOLTIP + this->vehicle_type);
1192 }
1193 }
1194
1195 BuildVehicleWindow(WindowDesc &desc, TileIndex tile, VehicleType type) : Window(desc), vehicle_editbox(MAX_LENGTH_VEHICLE_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_VEHICLE_NAME_CHARS)
1196 {
1197 this->vehicle_type = type;
1198 this->listview_mode = tile == INVALID_TILE;
1199 this->window_number = this->listview_mode ? (int)type : tile.base();
1200
1201 this->sort_criteria = _engine_sort_last_criteria[type];
1202 this->descending_sort_order = _engine_sort_last_order[type];
1203 this->show_hidden_engines = _engine_sort_show_hidden_engines[type];
1204
1205 this->UpdateFilterByTile();
1206
1207 this->CreateNestedTree();
1208
1209 this->vscroll = this->GetScrollbar(WID_BV_SCROLLBAR);
1210
1211 /* If we are just viewing the list of vehicles, we do not need the Build button.
1212 * So we just hide it, and enlarge the Rename button by the now vacant place. */
1213 if (this->listview_mode) this->GetWidget<NWidgetStacked>(WID_BV_BUILD_SEL)->SetDisplayedPlane(SZSP_NONE);
1214
1215 NWidgetCore *widget = this->GetWidget<NWidgetCore>(WID_BV_LIST);
1216 widget->SetToolTip(STR_BUY_VEHICLE_TRAIN_LIST_TOOLTIP + type);
1217
1218 widget = this->GetWidget<NWidgetCore>(WID_BV_SHOW_HIDE);
1219 widget->SetToolTip(STR_BUY_VEHICLE_TRAIN_HIDE_SHOW_TOGGLE_TOOLTIP + type);
1220
1221 widget = this->GetWidget<NWidgetCore>(WID_BV_RENAME);
1222 widget->SetStringTip(STR_BUY_VEHICLE_TRAIN_RENAME_BUTTON + type, STR_BUY_VEHICLE_TRAIN_RENAME_TOOLTIP + type);
1223
1224 widget = this->GetWidget<NWidgetCore>(WID_BV_SHOW_HIDDEN_ENGINES);
1225 widget->SetStringTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + type, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + type);
1226 widget->SetLowered(this->show_hidden_engines);
1227
1228 this->details_height = ((this->vehicle_type == VEH_TRAIN) ? 10 : 9);
1229
1230 if (tile == INVALID_TILE) {
1231 this->FinishInitNested(type);
1232 } else {
1233 this->FinishInitNested(tile);
1234 }
1235
1236 this->querystrings[WID_BV_FILTER] = &this->vehicle_editbox;
1237 this->vehicle_editbox.cancel_button = QueryString::ACTION_CLEAR;
1238
1239 this->owner = (tile != INVALID_TILE) ? GetTileOwner(tile) : _local_company;
1240
1241 this->eng_list.ForceRebuild();
1242 this->GenerateBuildList(); // generate the list, since we need it in the next line
1243
1244 /* Select the first unshaded engine in the list as default when opening the window */
1245 EngineID engine = EngineID::Invalid();
1246 auto it = std::ranges::find_if(this->eng_list, [](const GUIEngineListItem &item) { return !item.flags.Test(EngineDisplayFlag::Shaded); });
1247 if (it != this->eng_list.end()) engine = it->engine_id;
1248 this->SelectEngine(engine);
1249 }
1250
1252 void UpdateFilterByTile()
1253 {
1254 switch (this->vehicle_type) {
1255 default: NOT_REACHED();
1256 case VEH_TRAIN:
1257 if (this->listview_mode) {
1258 this->filter.railtype = INVALID_RAILTYPE;
1259 } else {
1260 this->filter.railtype = GetRailType(this->window_number);
1261 }
1262 break;
1263
1264 case VEH_ROAD:
1265 if (this->listview_mode) {
1266 this->filter.roadtype = INVALID_ROADTYPE;
1267 } else {
1268 this->filter.roadtype = GetRoadTypeRoad(this->window_number);
1269 if (this->filter.roadtype == INVALID_ROADTYPE) {
1270 this->filter.roadtype = GetRoadTypeTram(this->window_number);
1271 }
1272 }
1273 break;
1274
1275 case VEH_SHIP:
1276 case VEH_AIRCRAFT:
1277 break;
1278 }
1279 }
1280
1281 StringID GetCargoFilterLabel(CargoType cargo_type) const
1282 {
1283 switch (cargo_type) {
1284 case CargoFilterCriteria::CF_ANY: return STR_PURCHASE_INFO_ALL_TYPES;
1285 case CargoFilterCriteria::CF_ENGINES: return STR_PURCHASE_INFO_ENGINES_ONLY;
1286 case CargoFilterCriteria::CF_NONE: return STR_PURCHASE_INFO_NONE;
1287 default: return CargoSpec::Get(cargo_type)->name;
1288 }
1289 }
1290
1292 void SetCargoFilterArray()
1293 {
1294 /* Set the last cargo filter criteria. */
1295 this->cargo_filter_criteria = _engine_sort_last_cargo_criteria[this->vehicle_type];
1296 if (this->cargo_filter_criteria < NUM_CARGO && !HasBit(_standard_cargo_mask, this->cargo_filter_criteria)) this->cargo_filter_criteria = CargoFilterCriteria::CF_ANY;
1297
1298 this->eng_list.SetFilterFuncs(_engine_filter_funcs);
1299 this->eng_list.SetFilterState(this->cargo_filter_criteria != CargoFilterCriteria::CF_ANY);
1300 }
1301
1302 void SelectEngine(EngineID engine)
1303 {
1304 CargoType cargo = this->cargo_filter_criteria;
1305 if (cargo == CargoFilterCriteria::CF_ANY || cargo == CargoFilterCriteria::CF_ENGINES || cargo == CargoFilterCriteria::CF_NONE) cargo = INVALID_CARGO;
1306
1307 this->sel_engine = engine;
1308 this->SetBuyVehicleText();
1309
1310 if (this->sel_engine == EngineID::Invalid()) return;
1311
1312 const Engine *e = Engine::Get(this->sel_engine);
1313
1314 if (!this->listview_mode) {
1315 /* Query for cost and refitted capacity */
1316 auto [ret, veh_id, refit_capacity, refit_mail, cargo_capacities] = Command<CMD_BUILD_VEHICLE>::Do(DoCommandFlag::QueryCost, TileIndex(this->window_number), this->sel_engine, true, cargo, INVALID_CLIENT_ID);
1317 if (ret.Succeeded()) {
1318 this->te.cost = ret.GetCost() - e->GetCost();
1319 this->te.capacity = refit_capacity;
1320 this->te.mail_capacity = refit_mail;
1321 this->te.cargo = !IsValidCargoType(cargo) ? e->GetDefaultCargoType() : cargo;
1322 this->te.all_capacities = cargo_capacities;
1323 return;
1324 }
1325 }
1326
1327 /* Purchase test was not possible or failed, fill in the defaults instead. */
1328 this->te.cost = 0;
1329 this->te.FillDefaultCapacities(e);
1330 }
1331
1332 void OnInit() override
1333 {
1334 this->badge_classes = GUIBadgeClasses(static_cast<GrfSpecFeature>(GSF_TRAINS + this->vehicle_type));
1335 this->SetCargoFilterArray();
1336
1337 this->badge_filters = AddBadgeDropdownFilters(this, WID_BV_BADGE_FILTER, WID_BV_BADGE_FILTER, COLOUR_GREY, static_cast<GrfSpecFeature>(GSF_TRAINS + this->vehicle_type));
1338
1339 this->widget_lookup.clear();
1340 this->nested_root->FillWidgetLookup(this->widget_lookup);
1341 }
1342
1344 void FilterEngineList()
1345 {
1346 this->eng_list.Filter(this->cargo_filter_criteria);
1347 if (0 == this->eng_list.size()) { // no engine passed through the filter, invalidate the previously selected engine
1348 this->SelectEngine(EngineID::Invalid());
1349 } else if (std::ranges::find(this->eng_list, this->sel_engine, &GUIEngineListItem::engine_id) == this->eng_list.end()) { // previously selected engine didn't pass the filter, select the first engine of the list
1350 this->SelectEngine(this->eng_list[0].engine_id);
1351 }
1352 }
1353
1355 bool FilterSingleEngine(EngineID eid)
1356 {
1357 GUIEngineListItem item = {eid, eid, EngineDisplayFlags{}, 0};
1358 return CargoAndEngineFilter(&item, this->cargo_filter_criteria);
1359 }
1360
1362 bool FilterByText(const Engine *e)
1363 {
1364 /* Do not filter if the filter text box is empty */
1365 if (this->string_filter.IsEmpty()) return true;
1366
1367 /* Filter engine name */
1368 this->string_filter.ResetState();
1369 this->string_filter.AddLine(GetString(STR_ENGINE_NAME, PackEngineNameDParam(e->index, EngineNameContext::PurchaseList)));
1370
1371 /* Filter NewGRF extra text */
1372 auto text = GetNewGRFAdditionalText(e->index);
1373 if (text) this->string_filter.AddLine(*text);
1374
1375 return this->string_filter.GetState();
1376 }
1377
1378 /* Figure out what train EngineIDs to put in the list */
1379 void GenerateBuildTrainList(GUIEngineList &list)
1380 {
1381 FlatSet<EngineID> variants;
1382 EngineID sel_id = EngineID::Invalid();
1383 size_t num_engines = 0;
1384
1385 list.clear();
1386
1387 BadgeTextFilter btf(this->string_filter, GSF_TRAINS);
1388 BadgeDropdownFilter bdf(this->badge_filter_choices);
1389
1390 /* Make list of all available train engines and wagons.
1391 * Also check to see if the previously selected engine is still available,
1392 * and if not, reset selection to EngineID::Invalid(). This could be the case
1393 * when engines become obsolete and are removed */
1394 for (const Engine *e : Engine::IterateType(VEH_TRAIN)) {
1395 if (!this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue;
1396 EngineID eid = e->index;
1397 const RailVehicleInfo *rvi = &e->VehInfo<RailVehicleInfo>();
1398
1399 if (this->filter.railtype != INVALID_RAILTYPE && !HasPowerOnRail(rvi->railtypes, this->filter.railtype)) continue;
1400 if (!IsEngineBuildable(eid, VEH_TRAIN, _local_company)) continue;
1401
1402 /* Filter now! So num_engines and num_wagons is valid */
1403 if (!FilterSingleEngine(eid)) continue;
1404
1405 if (!bdf.Filter(e->badges)) continue;
1406
1407 /* Filter by name or NewGRF extra text */
1408 if (!FilterByText(e) && !btf.Filter(e->badges)) continue;
1409
1410 list.emplace_back(eid, e->info.variant_id, e->display_flags, 0);
1411
1412 if (rvi->railveh_type != RAILVEH_WAGON) num_engines++;
1413
1414 /* Add all parent variants of this engine to the variant list */
1415 EngineID parent = e->info.variant_id;
1416 while (parent != EngineID::Invalid() && variants.insert(parent).second) {
1417 parent = Engine::Get(parent)->info.variant_id;
1418 }
1419
1420 if (eid == this->sel_engine) sel_id = eid;
1421 }
1422
1423 /* ensure primary engine of variant group is in list */
1424 for (const auto &variant : variants) {
1425 if (std::ranges::find(list, variant, &GUIEngineListItem::engine_id) == list.end()) {
1426 const Engine *e = Engine::Get(variant);
1427 list.emplace_back(variant, e->info.variant_id, e->display_flags | EngineDisplayFlag::Shaded, 0);
1428 if (e->VehInfo<RailVehicleInfo>().railveh_type != RAILVEH_WAGON) num_engines++;
1429 }
1430 }
1431
1432 this->SelectEngine(sel_id);
1433
1434 /* invalidate cached values for name sorter - engine names could change */
1435 _last_engine[0] = _last_engine[1] = EngineID::Invalid();
1436
1437 /* make engines first, and then wagons, sorted by selected sort_criteria */
1438 _engine_sort_direction = false;
1439 EngList_Sort(list, TrainEnginesThenWagonsSorter);
1440
1441 /* and then sort engines */
1442 _engine_sort_direction = this->descending_sort_order;
1443 EngList_SortPartial(list, _engine_sort_functions[0][this->sort_criteria], 0, num_engines);
1444
1445 /* and finally sort wagons */
1446 EngList_SortPartial(list, _engine_sort_functions[0][this->sort_criteria], num_engines, list.size() - num_engines);
1447 }
1448
1449 /* Figure out what road vehicle EngineIDs to put in the list */
1450 void GenerateBuildRoadVehList()
1451 {
1452 EngineID sel_id = EngineID::Invalid();
1453
1454 this->eng_list.clear();
1455
1456 BadgeTextFilter btf(this->string_filter, GSF_ROADVEHICLES);
1457 BadgeDropdownFilter bdf(this->badge_filter_choices);
1458
1459 for (const Engine *e : Engine::IterateType(VEH_ROAD)) {
1460 if (!this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue;
1461 EngineID eid = e->index;
1462 if (!IsEngineBuildable(eid, VEH_ROAD, _local_company)) continue;
1463 if (this->filter.roadtype != INVALID_ROADTYPE && !HasPowerOnRoad(e->VehInfo<RoadVehicleInfo>().roadtype, this->filter.roadtype)) continue;
1464 if (!bdf.Filter(e->badges)) continue;
1465
1466 /* Filter by name or NewGRF extra text */
1467 if (!FilterByText(e) && !btf.Filter(e->badges)) continue;
1468
1469 this->eng_list.emplace_back(eid, e->info.variant_id, e->display_flags, 0);
1470
1471 if (eid == this->sel_engine) sel_id = eid;
1472 }
1473 this->SelectEngine(sel_id);
1474 }
1475
1476 /* Figure out what ship EngineIDs to put in the list */
1477 void GenerateBuildShipList()
1478 {
1479 EngineID sel_id = EngineID::Invalid();
1480 this->eng_list.clear();
1481
1482 BadgeTextFilter btf(this->string_filter, GSF_SHIPS);
1483 BadgeDropdownFilter bdf(this->badge_filter_choices);
1484
1485 for (const Engine *e : Engine::IterateType(VEH_SHIP)) {
1486 if (!this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue;
1487 EngineID eid = e->index;
1488 if (!IsEngineBuildable(eid, VEH_SHIP, _local_company)) continue;
1489 if (!bdf.Filter(e->badges)) continue;
1490
1491 /* Filter by name or NewGRF extra text */
1492 if (!FilterByText(e) && !btf.Filter(e->badges)) continue;
1493
1494 this->eng_list.emplace_back(eid, e->info.variant_id, e->display_flags, 0);
1495
1496 if (eid == this->sel_engine) sel_id = eid;
1497 }
1498 this->SelectEngine(sel_id);
1499 }
1500
1501 /* Figure out what aircraft EngineIDs to put in the list */
1502 void GenerateBuildAircraftList()
1503 {
1504 EngineID sel_id = EngineID::Invalid();
1505
1506 this->eng_list.clear();
1507
1508 const Station *st = this->listview_mode ? nullptr : Station::GetByTile(TileIndex(this->window_number));
1509
1510 BadgeTextFilter btf(this->string_filter, GSF_AIRCRAFT);
1511 BadgeDropdownFilter bdf(this->badge_filter_choices);
1512
1513 /* Make list of all available planes.
1514 * Also check to see if the previously selected plane is still available,
1515 * and if not, reset selection to EngineID::Invalid(). This could be the case
1516 * when planes become obsolete and are removed */
1517 for (const Engine *e : Engine::IterateType(VEH_AIRCRAFT)) {
1518 if (!this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue;
1519 EngineID eid = e->index;
1520 if (!IsEngineBuildable(eid, VEH_AIRCRAFT, _local_company)) continue;
1521 /* First VEH_END window_numbers are fake to allow a window open for all different types at once */
1522 if (!this->listview_mode && !CanVehicleUseStation(eid, st)) continue;
1523 if (!bdf.Filter(e->badges)) continue;
1524
1525 /* Filter by name or NewGRF extra text */
1526 if (!FilterByText(e) && !btf.Filter(e->badges)) continue;
1527
1528 this->eng_list.emplace_back(eid, e->info.variant_id, e->display_flags, 0);
1529
1530 if (eid == this->sel_engine) sel_id = eid;
1531 }
1532
1533 this->SelectEngine(sel_id);
1534 }
1535
1536 /* Generate the list of vehicles */
1537 void GenerateBuildList()
1538 {
1539 if (!this->eng_list.NeedRebuild()) return;
1540
1541 /* Update filter type in case the road/railtype of the depot got converted */
1542 this->UpdateFilterByTile();
1543
1544 this->eng_list.clear();
1545
1546 GUIEngineList list;
1547
1548 switch (this->vehicle_type) {
1549 default: NOT_REACHED();
1550 case VEH_TRAIN:
1551 this->GenerateBuildTrainList(list);
1552 GUIEngineListAddChildren(this->eng_list, list);
1553 this->eng_list.RebuildDone();
1554 return;
1555 case VEH_ROAD:
1556 this->GenerateBuildRoadVehList();
1557 break;
1558 case VEH_SHIP:
1559 this->GenerateBuildShipList();
1560 break;
1561 case VEH_AIRCRAFT:
1562 this->GenerateBuildAircraftList();
1563 break;
1564 }
1565
1566 this->FilterEngineList();
1567
1568 /* ensure primary engine of variant group is in list after filtering */
1569 FlatSet<EngineID> variants;
1570 for (const auto &item : this->eng_list) {
1571 EngineID parent = item.variant_id;
1572 while (parent != EngineID::Invalid() && variants.insert(parent).second) {
1573 parent = Engine::Get(parent)->info.variant_id;
1574 }
1575 }
1576
1577 for (const auto &variant : variants) {
1578 if (std::ranges::find(this->eng_list, variant, &GUIEngineListItem::engine_id) == this->eng_list.end()) {
1579 const Engine *e = Engine::Get(variant);
1580 this->eng_list.emplace_back(variant, e->info.variant_id, e->display_flags | EngineDisplayFlag::Shaded, 0);
1581 }
1582 }
1583
1584 _engine_sort_direction = this->descending_sort_order;
1585 EngList_Sort(this->eng_list, _engine_sort_functions[this->vehicle_type][this->sort_criteria]);
1586
1587 this->eng_list.swap(list);
1588 GUIEngineListAddChildren(this->eng_list, list, EngineID::Invalid(), 0);
1589 this->eng_list.RebuildDone();
1590 }
1591
1592 DropDownList BuildCargoDropDownList() const
1593 {
1594 DropDownList list;
1595
1596 /* Add item for disabling filtering. */
1597 list.push_back(MakeDropDownListStringItem(this->GetCargoFilterLabel(CargoFilterCriteria::CF_ANY), CargoFilterCriteria::CF_ANY));
1598 /* Specific filters for trains. */
1599 if (this->vehicle_type == VEH_TRAIN) {
1600 /* Add item for locomotives only in case of trains. */
1601 list.push_back(MakeDropDownListStringItem(this->GetCargoFilterLabel(CargoFilterCriteria::CF_ENGINES), CargoFilterCriteria::CF_ENGINES));
1602 /* Add item for vehicles not carrying anything, e.g. train engines.
1603 * This could also be useful for eyecandy vehicles of other types, but is likely too confusing for joe, */
1604 list.push_back(MakeDropDownListStringItem(this->GetCargoFilterLabel(CargoFilterCriteria::CF_NONE), CargoFilterCriteria::CF_NONE));
1605 }
1606
1607 /* Add cargos */
1608 Dimension d = GetLargestCargoIconSize();
1609 for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
1610 list.push_back(MakeDropDownListIconItem(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index()));
1611 }
1612
1613 return list;
1614 }
1615
1616 DropDownList BuildBadgeConfigurationList() const
1617 {
1618 static const auto separators = {STR_BADGE_CONFIG_PREVIEW, STR_BADGE_CONFIG_NAME};
1619 return BuildBadgeClassConfigurationList(this->badge_classes, BADGE_COLUMNS, separators, COLOUR_GREY);
1620 }
1621
1622 void BuildVehicle()
1623 {
1624 EngineID sel_eng = this->sel_engine;
1625 if (sel_eng == EngineID::Invalid()) return;
1626
1627 CargoType cargo = this->cargo_filter_criteria;
1628 if (cargo == CargoFilterCriteria::CF_ANY || cargo == CargoFilterCriteria::CF_ENGINES || cargo == CargoFilterCriteria::CF_NONE) cargo = INVALID_CARGO;
1629 if (this->vehicle_type == VEH_TRAIN && RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) {
1630 Command<CMD_BUILD_VEHICLE>::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildWagon, TileIndex(this->window_number), sel_eng, true, cargo, INVALID_CLIENT_ID);
1631 } else {
1632 Command<CMD_BUILD_VEHICLE>::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildPrimaryVehicle, TileIndex(this->window_number), sel_eng, true, cargo, INVALID_CLIENT_ID);
1633 }
1634
1635 /* Update last used variant in hierarchy and refresh if necessary. */
1636 bool refresh = false;
1637 EngineID parent = sel_eng;
1638 while (parent != EngineID::Invalid()) {
1639 Engine *e = Engine::Get(parent);
1640 refresh |= (e->display_last_variant != sel_eng);
1641 e->display_last_variant = sel_eng;
1642 parent = e->info.variant_id;
1643 }
1644
1645 if (refresh) {
1646 InvalidateWindowData(WC_REPLACE_VEHICLE, this->vehicle_type, 0); // Update the autoreplace window
1647 InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well
1648 }
1649 }
1650
1651 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1652 {
1653 switch (widget) {
1654 case WID_BV_SORT_ASCENDING_DESCENDING:
1655 this->descending_sort_order ^= true;
1656 _engine_sort_last_order[this->vehicle_type] = this->descending_sort_order;
1657 this->eng_list.ForceRebuild();
1658 this->SetDirty();
1659 break;
1660
1661 case WID_BV_SHOW_HIDDEN_ENGINES:
1662 this->show_hidden_engines ^= true;
1663 _engine_sort_show_hidden_engines[this->vehicle_type] = this->show_hidden_engines;
1664 this->eng_list.ForceRebuild();
1665 this->SetWidgetLoweredState(widget, this->show_hidden_engines);
1666 this->SetDirty();
1667 break;
1668
1669 case WID_BV_LIST: {
1670 EngineID e = EngineID::Invalid();
1671 const auto it = this->vscroll->GetScrolledItemFromWidget(this->eng_list, pt.y, this, WID_BV_LIST);
1672 if (it != this->eng_list.end()) {
1673 const auto &item = *it;
1674 const Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.matrix).WithWidth(WidgetDimensions::scaled.hsep_indent * (item.indent + 1), _current_text_dir == TD_RTL);
1675 if (item.flags.Test(EngineDisplayFlag::HasVariants) && IsInsideMM(r.left, r.right, pt.x)) {
1676 /* toggle folded flag on engine */
1677 assert(item.variant_id != EngineID::Invalid());
1678 Engine *engine = Engine::Get(item.variant_id);
1679 engine->display_flags.Flip(EngineDisplayFlag::IsFolded);
1680
1681 InvalidateWindowData(WC_REPLACE_VEHICLE, this->vehicle_type, 0); // Update the autoreplace window
1682 InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well
1683 return;
1684 }
1685 if (!item.flags.Test(EngineDisplayFlag::Shaded)) e = item.engine_id;
1686 }
1687 this->SelectEngine(e);
1688 this->SetDirty();
1689 if (_ctrl_pressed) {
1690 this->OnClick(pt, WID_BV_SHOW_HIDE, 1);
1691 } else if (click_count > 1 && !this->listview_mode) {
1692 this->OnClick(pt, WID_BV_BUILD, 1);
1693 }
1694 break;
1695 }
1696
1697 case WID_BV_SORT_DROPDOWN: // Select sorting criteria dropdown menu
1698 DisplayVehicleSortDropDown(this, this->vehicle_type, this->sort_criteria, WID_BV_SORT_DROPDOWN);
1699 break;
1700
1701 case WID_BV_CARGO_FILTER_DROPDOWN: // Select cargo filtering criteria dropdown menu
1702 ShowDropDownList(this, this->BuildCargoDropDownList(), this->cargo_filter_criteria, widget);
1703 break;
1704
1705 case WID_BV_CONFIGURE_BADGES:
1706 if (this->badge_classes.GetClasses().empty()) break;
1707 ShowDropDownList(this, this->BuildBadgeConfigurationList(), -1, widget, 0, DropDownOption::Persist);
1708 break;
1709
1710 case WID_BV_SHOW_HIDE: {
1711 const Engine *e = (this->sel_engine == EngineID::Invalid()) ? nullptr : Engine::Get(this->sel_engine);
1712 if (e != nullptr) {
1713 Command<CMD_SET_VEHICLE_VISIBILITY>::Post(this->sel_engine, !e->IsHidden(_current_company));
1714 }
1715 break;
1716 }
1717
1718 case WID_BV_BUILD:
1719 this->BuildVehicle();
1720 break;
1721
1722 case WID_BV_RENAME: {
1723 EngineID sel_eng = this->sel_engine;
1724 if (sel_eng != EngineID::Invalid()) {
1725 this->rename_engine = sel_eng;
1726 ShowQueryString(GetString(STR_ENGINE_NAME, PackEngineNameDParam(sel_eng, EngineNameContext::Generic)), STR_QUERY_RENAME_TRAIN_TYPE_CAPTION + this->vehicle_type, MAX_LENGTH_ENGINE_NAME_CHARS, this, CS_ALPHANUMERAL, {QueryStringFlag::EnableDefault, QueryStringFlag::LengthIsInChars});
1727 }
1728 break;
1729 }
1730
1731 default:
1732 if (IsInsideMM(widget, this->badge_filters.first, this->badge_filters.second)) {
1733 PaletteID palette = SPR_2CCMAP_BASE + Company::Get(_local_company)->GetCompanyRecolourOffset(LS_DEFAULT);
1734 ShowDropDownList(this, this->GetWidget<NWidgetBadgeFilter>(widget)->GetDropDownList(palette), -1, widget, 0);
1735 }
1736 break;
1737 }
1738 }
1739
1745 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1746 {
1747 if (!gui_scope) return;
1748 /* When switching to original acceleration model for road vehicles, clear the selected sort criteria if it is not available now. */
1749 if (this->vehicle_type == VEH_ROAD &&
1750 _settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL &&
1751 this->sort_criteria > 7) {
1752 this->sort_criteria = 0;
1753 _engine_sort_last_criteria[VEH_ROAD] = 0;
1754 }
1755 this->eng_list.ForceRebuild();
1756 }
1757
1758 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
1759 {
1760 switch (widget) {
1761 case WID_BV_CAPTION:
1762 if (this->vehicle_type == VEH_TRAIN && !this->listview_mode) {
1763 const RailTypeInfo *rti = GetRailTypeInfo(this->filter.railtype);
1764 return GetString(rti->strings.build_caption);
1765 }
1766 if (this->vehicle_type == VEH_ROAD && !this->listview_mode) {
1767 const RoadTypeInfo *rti = GetRoadTypeInfo(this->filter.roadtype);
1768 return GetString(rti->strings.build_caption);
1769 }
1770 return GetString((this->listview_mode ? STR_VEHICLE_LIST_AVAILABLE_TRAINS : STR_BUY_VEHICLE_TRAIN_ALL_CAPTION) + this->vehicle_type);
1771
1772 case WID_BV_SORT_DROPDOWN:
1773 return GetString(std::data(_engine_sort_listing[this->vehicle_type])[this->sort_criteria]);
1774
1775 case WID_BV_CARGO_FILTER_DROPDOWN:
1776 return GetString(this->GetCargoFilterLabel(this->cargo_filter_criteria));
1777
1778 case WID_BV_SHOW_HIDE: {
1779 const Engine *e = (this->sel_engine == EngineID::Invalid()) ? nullptr : Engine::Get(this->sel_engine);
1780 if (e != nullptr && e->IsHidden(_local_company)) {
1781 return GetString(STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + this->vehicle_type);
1782 }
1783 return GetString(STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + this->vehicle_type);
1784 }
1785
1786 default:
1787 if (IsInsideMM(widget, this->badge_filters.first, this->badge_filters.second)) {
1788 return this->GetWidget<NWidgetBadgeFilter>(widget)->GetStringParameter(this->badge_filter_choices);
1789 }
1790
1791 return this->Window::GetWidgetString(widget, stringid);
1792 }
1793 }
1794
1795 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
1796 {
1797 switch (widget) {
1798 case WID_BV_LIST:
1799 fill.height = resize.height = GetEngineListHeight(this->vehicle_type);
1800 size.height = 3 * resize.height;
1801 size.width = std::max(size.width, this->badge_classes.GetTotalColumnsWidth() + GetVehicleImageCellSize(this->vehicle_type, EIT_PURCHASE).extend_left + GetVehicleImageCellSize(this->vehicle_type, EIT_PURCHASE).extend_right + 165) + padding.width;
1802 break;
1803
1804 case WID_BV_PANEL:
1805 size.height = GetCharacterHeight(FS_NORMAL) * this->details_height + padding.height;
1806 break;
1807
1808 case WID_BV_SORT_ASCENDING_DESCENDING: {
1809 Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->GetString());
1810 d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
1811 d.height += padding.height;
1812 size = maxdim(size, d);
1813 break;
1814 }
1815
1816 case WID_BV_CARGO_FILTER_DROPDOWN:
1817 size.width = std::max(size.width, GetDropDownListDimension(this->BuildCargoDropDownList()).width + padding.width);
1818 break;
1819
1820 case WID_BV_CONFIGURE_BADGES:
1821 /* Hide the configuration button if no configurable badges are present. */
1822 if (this->badge_classes.GetClasses().empty()) size = {0, 0};
1823 break;
1824
1825 case WID_BV_BUILD:
1826 size = GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + this->vehicle_type);
1827 size = maxdim(size, GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_BUTTON + this->vehicle_type));
1828 size.width += padding.width;
1829 size.height += padding.height;
1830 break;
1831
1832 case WID_BV_SHOW_HIDE:
1833 size = GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + this->vehicle_type);
1834 size = maxdim(size, GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + this->vehicle_type));
1835 size.width += padding.width;
1836 size.height += padding.height;
1837 break;
1838 }
1839 }
1840
1841 void DrawWidget(const Rect &r, WidgetID widget) const override
1842 {
1843 switch (widget) {
1844 case WID_BV_LIST:
1845 DrawEngineList(
1846 this->vehicle_type,
1847 r,
1848 this->eng_list,
1849 *this->vscroll,
1850 this->sel_engine,
1851 false,
1852 DEFAULT_GROUP,
1853 this->badge_classes
1854 );
1855 break;
1856
1857 case WID_BV_SORT_ASCENDING_DESCENDING:
1858 this->DrawSortButtonState(WID_BV_SORT_ASCENDING_DESCENDING, this->descending_sort_order ? SBS_DOWN : SBS_UP);
1859 break;
1860 }
1861 }
1862
1863 void OnPaint() override
1864 {
1865 this->GenerateBuildList();
1866 this->vscroll->SetCount(this->eng_list.size());
1867
1868 this->SetWidgetsDisabledState(this->sel_engine == EngineID::Invalid(), WID_BV_SHOW_HIDE, WID_BV_BUILD);
1869
1870 /* Disable renaming engines in network games if you are not the server. */
1871 this->SetWidgetDisabledState(WID_BV_RENAME, this->sel_engine == EngineID::Invalid() || (_networking && !_network_server));
1872
1873 this->DrawWidgets();
1874
1875 if (!this->IsShaded()) {
1876 int needed_height = this->details_height;
1877 /* Draw details panels. */
1878 if (this->sel_engine != EngineID::Invalid()) {
1879 const Rect r = this->GetWidget<NWidgetBase>(WID_BV_PANEL)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
1880 int text_end = DrawVehiclePurchaseInfo(r.left, r.right, r.top, this->sel_engine, this->te);
1881 needed_height = std::max(needed_height, (text_end - r.top) / GetCharacterHeight(FS_NORMAL));
1882 }
1883 if (needed_height != this->details_height) { // Details window are not high enough, enlarge them.
1884 int resize = needed_height - this->details_height;
1885 this->details_height = needed_height;
1886 this->ReInit(0, resize * GetCharacterHeight(FS_NORMAL));
1887 return;
1888 }
1889 }
1890 }
1891
1892 void OnQueryTextFinished(std::optional<std::string> str) override
1893 {
1894 if (!str.has_value()) return;
1895
1896 Command<CMD_RENAME_ENGINE>::Post(STR_ERROR_CAN_T_RENAME_TRAIN_TYPE + this->vehicle_type, this->rename_engine, *str);
1897 }
1898
1899 void OnDropdownSelect(WidgetID widget, int index, int click_result) override
1900 {
1901 switch (widget) {
1902 case WID_BV_SORT_DROPDOWN:
1903 if (this->sort_criteria != index) {
1904 this->sort_criteria = index;
1905 _engine_sort_last_criteria[this->vehicle_type] = this->sort_criteria;
1906 this->eng_list.ForceRebuild();
1907 }
1908 break;
1909
1910 case WID_BV_CARGO_FILTER_DROPDOWN: // Select a cargo filter criteria
1911 if (this->cargo_filter_criteria != index) {
1912 this->cargo_filter_criteria = index;
1913 _engine_sort_last_cargo_criteria[this->vehicle_type] = this->cargo_filter_criteria;
1914 /* deactivate filter if criteria is 'Show All', activate it otherwise */
1915 this->eng_list.SetFilterState(this->cargo_filter_criteria != CargoFilterCriteria::CF_ANY);
1916 this->eng_list.ForceRebuild();
1917 this->SelectEngine(this->sel_engine);
1918 }
1919 break;
1920
1921 case WID_BV_CONFIGURE_BADGES: {
1922 bool reopen = HandleBadgeConfigurationDropDownClick(static_cast<GrfSpecFeature>(GSF_TRAINS + this->vehicle_type), BADGE_COLUMNS, index, click_result, this->badge_filter_choices);
1923
1924 this->ReInit();
1925
1926 if (reopen) {
1927 ReplaceDropDownList(this, this->BuildBadgeConfigurationList(), -1);
1928 } else {
1929 this->CloseChildWindows(WC_DROPDOWN_MENU);
1930 }
1931
1932 /* We need to refresh if a filter is removed. */
1933 this->eng_list.ForceRebuild();
1934 break;
1935 }
1936
1937 default:
1938 if (IsInsideMM(widget, this->badge_filters.first, this->badge_filters.second)) {
1939 if (index < 0) {
1940 ResetBadgeFilter(this->badge_filter_choices, this->GetWidget<NWidgetBadgeFilter>(widget)->GetBadgeClassID());
1941 } else {
1942 SetBadgeFilter(this->badge_filter_choices, BadgeID(index));
1943 }
1944 this->eng_list.ForceRebuild();
1945 }
1946 break;
1947 }
1948 this->SetDirty();
1949 }
1950
1951 void OnResize() override
1952 {
1953 this->vscroll->SetCapacityFromWidget(this, WID_BV_LIST);
1954 }
1955
1956 void OnEditboxChanged(WidgetID wid) override
1957 {
1958 if (wid == WID_BV_FILTER) {
1959 this->string_filter.SetFilterTerm(this->vehicle_editbox.text.GetText());
1960 this->InvalidateData();
1961 }
1962 }
1963
1964 static inline HotkeyList hotkeys{"buildvehicle", {
1965 Hotkey('F', "focus_filter_box", WID_BV_FILTER),
1966 }};
1967};
1968
1969static WindowDesc _build_vehicle_desc(
1970 WDP_AUTO, "build_vehicle", 240, 268,
1971 WC_BUILD_VEHICLE, WC_NONE,
1972 WindowDefaultFlag::Construction,
1973 _nested_build_vehicle_widgets,
1974 &BuildVehicleWindow::hotkeys
1975);
1976
1977void ShowBuildVehicleWindow(TileIndex tile, VehicleType type)
1978{
1979 /* We want to be able to open both Available Train as Available Ships,
1980 * so if tile == INVALID_TILE (Available XXX Window), use 'type' as unique number.
1981 * As it always is a low value, it won't collide with any real tile
1982 * number. */
1983 uint num = (tile == INVALID_TILE) ? (int)type : tile.base();
1984
1985 assert(IsCompanyBuildableVehicleType(type));
1986
1987 CloseWindowById(WC_BUILD_VEHICLE, num);
1988
1989 new BuildVehicleWindow(_build_vehicle_desc, tile, type);
1990}
GetUnionOfArticulatedRefitMasks
CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ors the refit_masks of all articulated parts.
Definition articulated_vehicles.cpp:248
GetCapacityOfArticulatedParts
CargoArray GetCapacityOfArticulatedParts(EngineID engine)
Get the capacity of the parts of a given engine.
Definition articulated_vehicles.cpp:136
IsArticulatedVehicleRefittable
bool IsArticulatedVehicleRefittable(EngineID engine)
Checks whether any of the articulated parts is refittable.
Definition articulated_vehicles.cpp:196
articulated_vehicles.h
Functions related to articulated vehicles.
autoreplace_func.h
Functions related to autoreplacing.
EngineHasReplacementForCompany
bool EngineHasReplacementForCompany(const Company *c, EngineID engine, GroupID group)
Check if a company has a replacement set up for the given engine.
Definition autoreplace_func.h:51
SB
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.
Definition bitmath_func.hpp:58
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition bitmath_func.hpp:121
HasBit
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
EngineIntroDateSorter
static bool EngineIntroDateSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by introduction date.
Definition build_vehicle_gui.cpp:129
EngineCostSorter
static bool EngineCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by purchase cost.
Definition build_vehicle_gui.cpp:193
_engine_sort_last_cargo_criteria
static CargoType _engine_sort_last_cargo_criteria[]
Last set filter criteria, for each vehicle type.
Definition build_vehicle_gui.cpp:108
GUIEngineListAddChildren
void GUIEngineListAddChildren(GUIEngineList &dst, const GUIEngineList &src, EngineID parent, uint8_t indent)
Add children to GUI engine list to build a hierarchical tree.
Definition build_vehicle_gui.cpp:1122
TrainEnginesThenWagonsSorter
static bool TrainEnginesThenWagonsSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of train engines by engine / wagon.
Definition build_vehicle_gui.cpp:340
DrawEngineList
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.
Definition build_vehicle_gui.cpp:966
CargoAndEngineFilter
static bool CargoAndEngineFilter(const GUIEngineListItem *item, const CargoType cargo_type)
Filters vehicles by cargo and engine (in case of rail vehicle).
Definition build_vehicle_gui.cpp:541
GetNewGRFAdditionalText
static std::optional< std::string > GetNewGRFAdditionalText(EngineID engine)
Try to get the NewGRF engine additional text callback as an optional std::string.
Definition build_vehicle_gui.cpp:820
AircraftEngineCargoSorter
static bool AircraftEngineCargoSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of aircraft by cargo.
Definition build_vehicle_gui.cpp:400
_engine_sort_last_order
bool _engine_sort_last_order[]
Last set direction of the sort order, for each vehicle type.
Definition build_vehicle_gui.cpp:106
EngineNumberSorter
static bool EngineNumberSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by engineID.
Definition build_vehicle_gui.cpp:116
GetEngineListHeight
uint GetEngineListHeight(VehicleType type)
Get the height of a single 'entry' in the engine lists.
Definition build_vehicle_gui.cpp:56
TrainEngineCapacitySorter
static bool TrainEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of train engines by capacity.
Definition build_vehicle_gui.cpp:320
DrawAircraftPurchaseInfo
static int DrawAircraftPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable, TestedEngineDetails &te)
Draw aircraft specific details in the buy window.
Definition build_vehicle_gui.cpp:774
EnginePowerVsRunningCostSorter
static bool EnginePowerVsRunningCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by running costs.
Definition build_vehicle_gui.cpp:278
EngineReliabilitySorter
static bool EngineReliabilitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by reliability.
Definition build_vehicle_gui.cpp:176
_engine_sort_listing
const std::initializer_list< const StringID > _engine_sort_listing[]
Dropdown menu strings for the vehicle sort criteria.
Definition build_vehicle_gui.cpp:491
_engine_sort_last_criteria
uint8_t _engine_sort_last_criteria[]
Last set sort criteria, for each vehicle type.
Definition build_vehicle_gui.cpp:105
ShipEngineCapacitySorter
static bool ShipEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of ships by capacity.
Definition build_vehicle_gui.cpp:378
DrawVehiclePurchaseInfo
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.
Definition build_vehicle_gui.cpp:878
EngineTractiveEffortSorter
static bool EngineTractiveEffortSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by tractive effort.
Definition build_vehicle_gui.cpp:244
_engine_sort_functions
EngList_SortTypeFunction *const _engine_sort_functions[][11]
Sort functions for the vehicle sort criteria, for each vehicle type.
Definition build_vehicle_gui.cpp:441
DisplayVehicleSortDropDown
void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selected, WidgetID button)
Display the dropdown for the vehicle sort criteria.
Definition build_vehicle_gui.cpp:1099
ShowAdditionalText
static uint ShowAdditionalText(int left, int right, int y, EngineID engine)
Display additional text from NewGRF in the purchase information window.
Definition build_vehicle_gui.cpp:846
EngineSpeedSorter
static bool EngineSpeedSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by speed.
Definition build_vehicle_gui.cpp:210
_engine_sort_direction
bool _engine_sort_direction
false = descending, true = ascending.
Definition build_vehicle_gui.cpp:104
EngineNameSorter
static bool EngineNameSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by name.
Definition build_vehicle_gui.cpp:149
EnginePowerSorter
static bool EnginePowerSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by power.
Definition build_vehicle_gui.cpp:227
EngineRunningCostSorter
static bool EngineRunningCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by running costs.
Definition build_vehicle_gui.cpp:261
AircraftRangeSorter
static bool AircraftRangeSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of aircraft by range.
Definition build_vehicle_gui.cpp:428
RoadVehEngineCapacitySorter
static bool RoadVehEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of road vehicles by capacity.
Definition build_vehicle_gui.cpp:359
_engine_sort_show_hidden_engines
bool _engine_sort_show_hidden_engines[]
Last set 'show hidden engines' setting for each vehicle type.
Definition build_vehicle_gui.cpp:107
build_vehicle_widget.h
Types related to the build_vehicle widgets.
WID_BV_BUILD
@ WID_BV_BUILD
Build panel.
Definition build_vehicle_widget.h:24
WID_BV_SHOW_HIDE
@ WID_BV_SHOW_HIDE
Button to hide or show the selected engine.
Definition build_vehicle_widget.h:25
WID_BV_SORT_ASCENDING_DESCENDING
@ WID_BV_SORT_ASCENDING_DESCENDING
Sort direction.
Definition build_vehicle_widget.h:16
WID_BV_CAPTION
@ WID_BV_CAPTION
Caption of window.
Definition build_vehicle_widget.h:15
WID_BV_SHOW_HIDDEN_ENGINES
@ WID_BV_SHOW_HIDDEN_ENGINES
Toggle whether to display the hidden vehicles.
Definition build_vehicle_widget.h:20
WID_BV_CONFIGURE_BADGES
@ WID_BV_CONFIGURE_BADGES
Button to configure badges.
Definition build_vehicle_widget.h:28
WID_BV_BADGE_FILTER
@ WID_BV_BADGE_FILTER
Container for dropdown badge filters.
Definition build_vehicle_widget.h:29
WID_BV_LIST
@ WID_BV_LIST
List of vehicles.
Definition build_vehicle_widget.h:21
WID_BV_SORT_DROPDOWN
@ WID_BV_SORT_DROPDOWN
Criteria of sorting dropdown.
Definition build_vehicle_widget.h:17
WID_BV_RENAME
@ WID_BV_RENAME
Rename button.
Definition build_vehicle_widget.h:27
WID_BV_SCROLLBAR
@ WID_BV_SCROLLBAR
Scrollbar of list.
Definition build_vehicle_widget.h:22
WID_BV_BUILD_SEL
@ WID_BV_BUILD_SEL
Build button.
Definition build_vehicle_widget.h:26
WID_BV_PANEL
@ WID_BV_PANEL
Button panel.
Definition build_vehicle_widget.h:23
WID_BV_FILTER
@ WID_BV_FILTER
Filter by name.
Definition build_vehicle_widget.h:19
WID_BV_CARGO_FILTER_DROPDOWN
@ WID_BV_CARGO_FILTER_DROPDOWN
Cargo filter dropdown.
Definition build_vehicle_widget.h:18
CargoType
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
IsValidCargoType
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
Definition cargo_type.h:104
NUM_CARGO
static const CargoType NUM_CARGO
Maximum number of cargo types in a game.
Definition cargo_type.h:73
GetLargestCargoIconSize
Dimension GetLargestCargoIconSize()
Get dimensions of largest cargo icon.
Definition cargotype.cpp:163
_sorted_standard_cargo_specs
std::span< const CargoSpec * > _sorted_standard_cargo_specs
Standard cargo specifications sorted alphabetically by name.
Definition cargotype.cpp:191
_standard_cargo_mask
CargoTypes _standard_cargo_mask
Bitmask of real cargo types available.
Definition cargotype.cpp:36
_sorted_cargo_specs
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
Definition cargotype.cpp:190
cargotype.h
Types/functions related to cargoes.
BadgeDropdownFilter
Definition newgrf_badge.h:80
BadgeTextFilter
Definition newgrf_badge.h:71
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
BaseBitSet::Reset
constexpr Timpl & Reset()
Reset all bits.
Definition base_bitset_type.hpp:83
BaseBitSet::Flip
constexpr Timpl & Flip(Tvalue_type value)
Flip the value-th bit.
Definition base_bitset_type.hpp:116
Engine
Definition engine_base.h:38
Engine::GetAircraftTypeText
StringID GetAircraftTypeText() const
Get the name of the aircraft type for display purposes.
Definition engine.cpp:466
Engine::GetPower
uint GetPower() const
Returns the power of the engine for display and sorting purposes.
Definition engine.cpp:389
Engine::GetRange
uint16_t GetRange() const
Get the range of an aircraft type.
Definition engine.cpp:452
Engine::GetGRFID
uint32_t GetGRFID() const
Retrieve the GRF ID of the NewGRF the engine is tied to.
Definition engine.cpp:156
Engine::GetCost
Money GetCost() const
Return how much a new engine costs.
Definition engine.cpp:317
Engine::intro_date
TimerGameCalendar::Date intro_date
Date of introduction of the engine.
Definition engine_base.h:46
Engine::GetDisplayMaxSpeed
uint GetDisplayMaxSpeed() const
Returns max speed of the engine for display purposes.
Definition engine.cpp:357
Engine::display_flags
EngineDisplayFlags display_flags
NOSAVE client-side-only display flags for build engine list.
Definition engine_base.h:64
Engine::GetDisplayWeight
uint GetDisplayWeight() const
Returns the weight of the engine for display purposes.
Definition engine.cpp:407
Engine::type
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
Definition engine_base.h:62
Engine::IsVariantHidden
bool IsVariantHidden(CompanyID c) const
Check whether the engine variant chain is hidden in the GUI for the given company.
Definition engine.cpp:486
Engine::GetLifeLengthInDays
TimerGameCalendar::Date GetLifeLengthInDays() const
Returns the vehicle's (not model's!) life length in days.
Definition engine.cpp:442
Engine::GetDisplayDefaultCapacity
uint GetDisplayDefaultCapacity(uint16_t *mail_capacity=nullptr) const
Determines the default cargo capacity of an engine for display purposes.
Definition engine_base.h:115
Engine::GetDefaultCargoType
CargoType GetDefaultCargoType() const
Determines the default cargo type of an engine.
Definition engine_base.h:95
Engine::company_hidden
CompanyMask company_hidden
Bit for each company whether the engine is normally hidden in the build gui for that company.
Definition engine_base.h:41
Engine::GetRunningCost
Money GetRunningCost() const
Return how much the running costs of this engine are.
Definition engine.cpp:280
Engine::reliability
uint16_t reliability
Current reliability of the engine.
Definition engine_base.h:49
Engine::GetDisplayMaxTractiveEffort
uint GetDisplayMaxTractiveEffort() const
Returns the tractive effort of the engine for display purposes.
Definition engine.cpp:425
Engine::IsHidden
bool IsHidden(CompanyID c) const
Check whether the engine is hidden in the GUI for the given company.
Definition engine_base.h:135
Engine::display_last_variant
EngineID display_last_variant
NOSAVE client-side-only last variant selected.
Definition engine_base.h:65
EnumBitSet< EngineDisplayFlag, uint8_t >
FlatSet
Flat set implementation that uses a sorted vector for storage.
Definition flatset_type.hpp:20
FlatSet::insert
std::pair< const_iterator, bool > insert(const Tkey &key)
Insert a key into the set, if it does not already exist.
Definition flatset_type.hpp:31
GUIBadgeClasses
Definition newgrf_badge_gui.h:19
GUIList< GUIEngineListItem, std::nullptr_t, CargoType >
GUIList::Filter
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
Definition sortlist_type.h:342
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition sortlist_type.h:405
GUIList::SetFilterState
void SetFilterState(bool state)
Enable or disable the filter.
Definition sortlist_type.h:326
GUIList< GUIEngineListItem, std::nullptr_t, CargoType >::FilterFunction
bool(const GUIEngineListItem *, CargoType) FilterFunction
Signature of filter function.
Definition sortlist_type.h:46
GUIList::SetFilterFuncs
void SetFilterFuncs(std::span< FilterFunction *const > n_funcs)
Hand the filter function pointers to the GUIList.
Definition sortlist_type.h:365
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition sortlist_type.h:387
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition sortlist_type.h:395
NWidgetCore
Base class for a 'real' widget.
Definition widget_type.h:368
NWidgetCore::SetToolTip
void SetToolTip(StringID tool_tip)
Set the tool tip of the nested widget.
Definition widget.cpp:1224
NWidgetCore::SetLowered
void SetLowered(bool lowered)
Lower or raise the widget.
Definition widget_type.h:440
NWidgetCore::SetStringTip
void SetStringTip(StringID string, StringID tool_tip)
Set string and tool tip of the nested widget.
Definition widget.cpp:1164
OverflowSafeInt< int64_t >
RailTypeInfo
This struct contains all the info that is needed to draw and construct tracks.
Definition rail.h:115
RailTypeInfo::acceleration_type
VehicleAccelerationModel acceleration_type
Acceleration type of this rail type.
Definition rail.h:215
RailTypeInfo::name
StringID name
Name of this rail type.
Definition rail.h:165
RailTypeInfo::strings
struct RailTypeInfo::@22 strings
Strings associated with the rail type.
RailTypeInfo::build_caption
StringID build_caption
Caption of the build vehicle GUI for this rail type.
Definition rail.h:168
RoadTypeInfo
Definition road.h:52
RoadTypeInfo::strings
struct RoadTypeInfo::@25 strings
Strings associated with the rail type.
RoadTypeInfo::build_caption
StringID build_caption
Caption of the build vehicle GUI for this rail type.
Definition road.h:80
Scrollbar
Scrollbar data structure.
Definition widget_type.h:708
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition widget_type.h:792
Scrollbar::GetScrolledItemFromWidget
auto GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Return an iterator pointing to the element of a scrolled widget that a user clicked in.
Definition widget_type.h:891
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition widget.cpp:2499
Scrollbar::GetVisibleRangeIterators
auto GetVisibleRangeIterators(Tcontainer &container) const
Get a pair of iterators for the range of visible elements in a container.
Definition widget_type.h:872
TimerGameCalendar::ConvertDateToYMD
static YearMonthDay ConvertDateToYMD(Date date)
Converts a Date to a Year, Month & Day.
Definition timer_game_calendar.cpp:42
TimerGameEconomy::UsingWallclockUnits
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
Definition timer_game_economy.cpp:98
TimerGame< struct Calendar >::DateToYear
static constexpr Year DateToYear(Date date)
Calculate the year of a given date.
Definition timer_game_common.h:77
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
WidgetDimensions::fullbevel
RectPadding fullbevel
Always-scaled bevel thickness.
Definition window_gui.h:39
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition window_gui.h:61
WidgetDimensions::hsep_indent
int hsep_indent
Width of indentation for tree layouts.
Definition window_gui.h:63
command_func.h
Functions related to commands.
DoCommandFlag::QueryCost
@ QueryCost
query cost only, don't build.
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition company_cmd.cpp:55
_current_company
CompanyID _current_company
Company currently doing an action.
Definition company_cmd.cpp:56
company_func.h
Functions related to companies.
GetVehicleImageCellSize
VehicleCellSize GetVehicleImageCellSize(VehicleType type, EngineImageType image_type)
Get the GUI cell size for a vehicle image.
Definition depot_gui.cpp:162
ShowDropDownMenu
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.
Definition dropdown.cpp:458
GetDropDownListDimension
Dimension GetDropDownListDimension(const DropDownList &list)
Determine width and height required to fully display a DropDownList.
Definition dropdown.cpp:381
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, DropDownOptions options)
Show a drop down list.
Definition dropdown.cpp:418
dropdown_func.h
Functions related to the drop down widget.
dropdown_type.h
Types related to the drop down widget.
DropDownList
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Definition dropdown_type.h:56
DropDownOption::Persist
@ Persist
Set if this dropdown should stay open after an option is selected.
IsEngineBuildable
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
Check if an engine is buildable.
Definition engine.cpp:1246
engine_base.h
Base class for engines.
EngineDisplayFlag::HasVariants
@ HasVariants
Set if engine has variants.
EngineDisplayFlag::IsFolded
@ IsFolded
Set if display of variants should be folded (hidden).
EngineDisplayFlag::Shaded
@ Shaded
Set if engine should be masked.
engine_cmd.h
Command definitions related to engines.
engine_func.h
Functions related to engines.
GetTotalCapacityOfArticulatedParts
uint GetTotalCapacityOfArticulatedParts(EngineID engine)
Get the capacity of an engine with articulated parts.
Definition engine_gui.cpp:162
EngList_Sort
void EngList_Sort(GUIEngineList &el, EngList_SortTypeFunction compare)
Sort all items using quick sort and given 'CompareItems' function.
Definition engine_gui.cpp:356
EngList_SortPartial
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>)
Definition engine_gui.cpp:369
DrawVehicleEngine
void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
Draw an engine.
Definition engine_gui.cpp:326
engine_gui.h
Engine GUI functions, used by build_vehicle_gui and autoreplace_gui
EngList_SortTypeFunction
bool EngList_SortTypeFunction(const GUIEngineListItem &, const GUIEngineListItem &)
argument type for EngList_Sort.
Definition engine_gui.h:33
MAX_LENGTH_ENGINE_NAME_CHARS
static const uint MAX_LENGTH_ENGINE_NAME_CHARS
The maximum length of an engine name in characters including '\0'.
Definition engine_type.h:244
PackEngineNameDParam
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.
Definition engine_type.h:239
EngineNameContext::PurchaseList
@ PurchaseList
Name is shown in the purchase list (including autoreplace window 'Available vehicles' panel).
EngineNameContext::Generic
@ Generic
No specific context available.
EngineNameContext::AutoreplaceVehicleInUse
@ AutoreplaceVehicleInUse
Name is show in the autoreplace window 'Vehicles in use' panel.
VehicleAccelerationModel::Maglev
@ Maglev
Maglev acceleration model.
RAILVEH_WAGON
@ RAILVEH_WAGON
simple wagon, not motorized
Definition engine_type.h:34
RAILVEH_MULTIHEAD
@ RAILVEH_MULTIHEAD
indicates a combination of two locomotives
Definition engine_type.h:33
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:87
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition geometry_func.cpp:22
geometry_func.hpp
Geometry functions.
CentreBounds
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
Definition geometry_type.hpp:26
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:965
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:894
DrawString
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.
Definition gfx.cpp:665
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:38
DrawStringMultiLine
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.
Definition gfx.cpp:782
GetScaledSpriteSize
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
Definition widget.cpp:68
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition gfx_type.h:250
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:249
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition gfx_type.h:390
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition gfx_type.h:400
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition gfx_type.h:398
PaletteID
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:307
TC_FORCED
@ TC_FORCED
Ignore colour changes from strings.
Definition gfx_type.h:332
TC_NO_SHADE
@ TC_NO_SHADE
Do not add shading to this text colour.
Definition gfx_type.h:331
group.h
Base class for groups and group functions.
GetGroupNumEngines
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.
Definition group_cmd.cpp:809
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint32_t cols, uint32_t rows, StringID tip={})
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition widget_type.h:1308
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1219
SetSpriteTip
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
Definition widget_type.h:1251
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition widget_type.h:1399
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition widget_type.h:1332
SetStringTip
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
Definition widget_type.h:1240
SetAspect
constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags=AspectFlag::ResizeX)
Widget part function for setting the aspect ratio.
Definition widget_type.h:1410
SetTextStyle
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
Definition widget_type.h:1198
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition widget_type.h:1156
SetToolTip
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
Definition widget_type.h:1318
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1229
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1424
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1145
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:966
DEFAULT_GROUP
static constexpr GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
Definition group_type.h:18
hotkeys.h
Hotkey related functions.
IsInsideMM
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition math_func.hpp:267
ToPercent16
constexpr uint ToPercent16(uint i)
Converts a "fract" value 0..65535 to "percent" value 0..100.
Definition math_func.hpp:296
ShowQueryString
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.
Definition misc_gui.cpp:1062
CargoFilterCriteria::CF_NONE
static constexpr CargoType CF_NONE
Show only items which do not carry cargo (e.g. train engines)
Definition cargo_type.h:94
CargoFilterCriteria::CF_ENGINES
static constexpr CargoType CF_ENGINES
Show only engines (for rail vehicles only)
Definition cargo_type.h:95
CargoFilterCriteria::CF_ANY
static constexpr CargoType CF_ANY
Show all items independent of carried cargo (i.e. no filtering)
Definition cargo_type.h:93
_networking
bool _networking
are we in networking mode?
Definition network.cpp:66
_network_server
bool _network_server
network-server is active
Definition network.cpp:67
network.h
Basic functions/variables used all over the place.
INVALID_CLIENT_ID
@ INVALID_CLIENT_ID
Client is not part of anything.
Definition network_type.h:44
GrfSpecFeature
GrfSpecFeature
Definition newgrf.h:68
newgrf_badge.h
Functions related to NewGRF badges.
newgrf_badge_config.h
Functions related to NewGRF badge configuration.
newgrf_badge_gui.h
GUI functions related to NewGRF badges.
CBID_VEHICLE_ADDITIONAL_TEXT
@ CBID_VEHICLE_ADDITIONAL_TEXT
This callback is called from vehicle purchase lists.
Definition newgrf_callbacks.h:95
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition newgrf_callbacks.h:439
ErrorUnknownCallbackResult
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
Definition newgrf_commons.cpp:517
GetGRFConfig
GRFConfig * GetGRFConfig(uint32_t grfid, uint32_t mask)
Retrieve a NewGRF from the current config by its grfid.
Definition newgrf_config.cpp:622
GetVehicleCallback
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.
Definition newgrf_engine.cpp:1198
newgrf_engine.h
Functions for NewGRF engines.
GetGRFStringWithTextStack
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.
Definition newgrf_text.cpp:999
newgrf_text.h
Header of Action 04 "universal holder" structure and functions.
GRFSTR_MISC_GRF_TEXT
static constexpr GRFStringID GRFSTR_MISC_GRF_TEXT
Miscellaneous GRF text range.
Definition newgrf_text_type.h:18
GetColourGradient
PixelColour GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
Definition palette.cpp:388
querystring_gui.h
Base for the GUIs that have an edit box in them.
_sorted_railtypes
std::vector< RailType > _sorted_railtypes
Sorted list of rail types.
Definition rail_cmd.cpp:47
HasPowerOnRail
bool HasPowerOnRail(RailType enginetype, RailType tiletype)
Checks if an engine of the given RailType got power on a tile with a given RailType.
Definition rail.h:376
GetRailTypeInfo
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition rail.h:300
GetRailType
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
Definition rail_map.h:115
RailType
RailType
Enumeration for all possible railtypes.
Definition rail_type.h:25
INVALID_RAILTYPE
@ INVALID_RAILTYPE
Flag for invalid railtype.
Definition rail_type.h:32
HasPowerOnRoad
bool HasPowerOnRoad(RoadType enginetype, RoadType tiletype)
Checks if an engine of the given RoadType got power on a tile with a given RoadType.
Definition road.h:230
GetRoadTypeInfo
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition road.h:215
RoadType
RoadType
The different roadtypes we support.
Definition road_type.h:23
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition road_type.h:28
safeguards.h
A number of safeguards to prevent using unsafe methods.
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
PALETTE_CRASH
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition sprites.h:1619
station_base.h
Base classes/functions for stations.
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
StrNaturalCompare
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Definition string.cpp:427
string_func.h
Functions related to low-level strings.
CS_ALPHANUMERAL
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition string_type.h:25
stringfilter_type.h
Searching and filtering using a stringterm.
GetListSeparator
std::string_view GetListSeparator()
Get the list separator string for the current language.
Definition strings.cpp:299
AppendStringInPlace
void AppendStringInPlace(std::string &result, StringID string)
Resolve the given StringID and append in place into an existing std::string with formatting but no pa...
Definition strings.cpp:434
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
strings_func.h
Functions related to OTTD's strings.
PackVelocity
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
Definition strings_func.h:83
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition strings_type.h:27
MAX_CHAR_LENGTH
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
Definition strings_type.h:21
BaseStation::GetByTile
static BaseStation * GetByTile(TileIndex tile)
Get the base station belonging to a specific tile.
Definition base_station_base.h:160
BuildVehicleWindow
GUI for building vehicles.
Definition build_vehicle_gui.cpp:1154
BuildVehicleWindow::vehicle_type
VehicleType vehicle_type
Type of vehicles shown in the window.
Definition build_vehicle_gui.cpp:1155
BuildVehicleWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition build_vehicle_gui.cpp:1745
BuildVehicleWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition build_vehicle_gui.cpp:1841
BuildVehicleWindow::BADGE_COLUMNS
static constexpr int BADGE_COLUMNS
Number of columns available for badges (0 = left of image, 1 = between image and name,...
Definition build_vehicle_gui.cpp:1173
BuildVehicleWindow::FilterByText
bool FilterByText(const Engine *e)
Filter by name and NewGRF extra text.
Definition build_vehicle_gui.cpp:1362
BuildVehicleWindow::UpdateFilterByTile
void UpdateFilterByTile()
Set the filter type according to the depot type.
Definition build_vehicle_gui.cpp:1252
BuildVehicleWindow::descending_sort_order
bool descending_sort_order
Sort direction,.
Definition build_vehicle_gui.cpp:1160
BuildVehicleWindow::listview_mode
bool listview_mode
If set, only display the available vehicles and do not show a 'build' button.
Definition build_vehicle_gui.cpp:1163
BuildVehicleWindow::OnDropdownSelect
void OnDropdownSelect(WidgetID widget, int index, int click_result) override
A dropdown option associated to this window has been selected.
Definition build_vehicle_gui.cpp:1899
BuildVehicleWindow::cargo_filter_criteria
CargoType cargo_filter_criteria
Selected cargo filter.
Definition build_vehicle_gui.cpp:1167
BuildVehicleWindow::SetCargoFilterArray
void SetCargoFilterArray()
Populate the filter list and set the cargo filter criteria.
Definition build_vehicle_gui.cpp:1292
BuildVehicleWindow::railtype
RailType railtype
Rail type to show, or INVALID_RAILTYPE.
Definition build_vehicle_gui.cpp:1157
BuildVehicleWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition build_vehicle_gui.cpp:1863
BuildVehicleWindow::details_height
int details_height
Minimal needed height of the details panels, in text lines (found so far).
Definition build_vehicle_gui.cpp:1168
BuildVehicleWindow::vehicle_editbox
QueryString vehicle_editbox
Filter editbox.
Definition build_vehicle_gui.cpp:1176
BuildVehicleWindow::filter
union BuildVehicleWindow::@0 filter
Filter to apply.
BuildVehicleWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition build_vehicle_gui.cpp:1951
BuildVehicleWindow::show_hidden_engines
bool show_hidden_engines
State of the 'show hidden engines' button.
Definition build_vehicle_gui.cpp:1162
BuildVehicleWindow::FilterEngineList
void FilterEngineList()
Filter the engine list against the currently selected cargo filter.
Definition build_vehicle_gui.cpp:1344
BuildVehicleWindow::rename_engine
EngineID rename_engine
Engine being renamed.
Definition build_vehicle_gui.cpp:1165
BuildVehicleWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition build_vehicle_gui.cpp:1651
BuildVehicleWindow::te
TestedEngineDetails te
Tested cost and capacity after refit.
Definition build_vehicle_gui.cpp:1170
BuildVehicleWindow::badge_filters
std::pair< WidgetID, WidgetID > badge_filters
First and last widgets IDs of badge filters.
Definition build_vehicle_gui.cpp:1178
BuildVehicleWindow::GetWidgetString
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition build_vehicle_gui.cpp:1758
BuildVehicleWindow::OnEditboxChanged
void OnEditboxChanged(WidgetID wid) override
The text in an editbox has been edited.
Definition build_vehicle_gui.cpp:1956
BuildVehicleWindow::string_filter
StringFilter string_filter
Filter for vehicle name.
Definition build_vehicle_gui.cpp:1175
BuildVehicleWindow::sort_criteria
uint8_t sort_criteria
Current sort criterium.
Definition build_vehicle_gui.cpp:1161
BuildVehicleWindow::UpdateWidgetSize
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.
Definition build_vehicle_gui.cpp:1795
BuildVehicleWindow::FilterSingleEngine
bool FilterSingleEngine(EngineID eid)
Filter a single engine.
Definition build_vehicle_gui.cpp:1355
BuildVehicleWindow::sel_engine
EngineID sel_engine
Currently selected engine, or EngineID::Invalid()
Definition build_vehicle_gui.cpp:1164
BuildVehicleWindow::roadtype
RoadType roadtype
Road type to show, or INVALID_ROADTYPE.
Definition build_vehicle_gui.cpp:1158
BuildVehicleWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition build_vehicle_gui.cpp:1332
BuildVehicleWindow::OnQueryTextFinished
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
Definition build_vehicle_gui.cpp:1892
CargoArray
Class for storing amounts of cargo.
Definition cargo_type.h:111
CargoArray::GetCount
uint GetCount() const
Get the amount of cargos that have an amount.
Definition cargo_type.h:126
CargoSpec
Specification of a cargo type.
Definition cargotype.h:74
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo type.
Definition cargotype.h:137
CargoSpec::name
StringID name
Name of this type of cargo.
Definition cargotype.h:91
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition settings_type.h:650
CommandHelper
Definition command_func.h:83
Coord2D< int >
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:56
EngineInfo::variant_id
EngineID variant_id
Engine variant ID. If set, will be treated specially in purchase lists.
Definition engine_type.h:215
EngineInfo::base_intro
TimerGameCalendar::Date base_intro
Basic date of engine introduction (without random parts).
Definition engine_type.h:199
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition newgrf_config.h:158
GRFConfig::GetName
std::string GetName() const
Get the name of this grf.
Definition newgrf_config.cpp:85
GRFFile
Dynamic data of a loaded NewGRF.
Definition newgrf.h:114
GUIEngineListItem
Definition engine_gui.h:21
GUIEngineListItem::flags
EngineDisplayFlags flags
Flags for toggling/drawing (un)folded status and controlling indentation.
Definition engine_gui.h:24
GUIEngineListItem::variant_id
EngineID variant_id
Variant group of the engine.
Definition engine_gui.h:23
GUIEngineListItem::engine_id
EngineID engine_id
Engine to display in build purchase list.
Definition engine_gui.h:22
GUIEngineListItem::indent
uint8_t indent
Display indentation level.
Definition engine_gui.h:25
GUISettings::show_newgrf_name
bool show_newgrf_name
Show the name of the NewGRF in the build vehicle window.
Definition settings_type.h:233
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition settings_type.h:641
HotkeyList
List of hotkeys for a window.
Definition hotkeys.h:37
Hotkey
All data for a single hotkey.
Definition hotkeys.h:21
PixelColour
Colour for pixel/line drawing.
Definition gfx_type.h:405
PoolID< uint16_t, struct EngineIDTag, 64000, 0xFFFF >
Pool::PoolItem<&_engine_pool >::Get
static Titem * Get(auto index)
Returns Titem with given index.
Definition pool_type.hpp:387
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition pool_type.hpp:286
QueryString
Data stored about a string that can be modified in the GUI.
Definition querystring_gui.h:20
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition querystring_gui.h:28
QueryString::ACTION_CLEAR
static const int ACTION_CLEAR
Clear editbox.
Definition querystring_gui.h:24
RailVehicleInfo
Information about a rail vehicle.
Definition engine_type.h:74
RailVehicleInfo::railtypes
RailTypes railtypes
Railtypes, mangled if elrail is disabled.
Definition engine_type.h:78
RailVehicleInfo::pow_wag_power
uint16_t pow_wag_power
Extra power applied to consist if wagon should be powered.
Definition engine_type.h:88
RailVehicleInfo::pow_wag_weight
uint8_t pow_wag_weight
Extra weight applied to consist if wagon should be powered.
Definition engine_type.h:89
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:101
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition geometry_type.hpp:211
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition geometry_type.hpp:124
Rect::WithHeight
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Definition geometry_type.hpp:237
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition geometry_type.hpp:224
Rect::Height
int Height() const
Get height of Rect.
Definition geometry_type.hpp:117
Rect::WithY
Rect WithY(int new_top, int new_bottom) const
Create a new Rect, replacing the top and bottom coordiates.
Definition geometry_type.hpp:280
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition geometry_type.hpp:200
RoadVehicleInfo
Information about a road vehicle.
Definition engine_type.h:146
RoadVehicleInfo::roadtype
RoadType roadtype
Road type.
Definition engine_type.h:160
ShipVehicleInfo
Information about a ship vehicle.
Definition engine_type.h:99
Station
Station data structure.
Definition station_base.h:500
StringFilter
String filter and state.
Definition stringfilter_type.h:30
StringFilter::IsEmpty
bool IsEmpty() const
Check whether any filter words were entered.
Definition stringfilter_type.h:57
StringFilter::SetFilterTerm
void SetFilterTerm(std::string_view str)
Set the term to filter on.
Definition stringfilter.cpp:29
StringFilter::ResetState
void ResetState()
Reset the matching state to process a new item.
Definition stringfilter.cpp:80
StringFilter::GetState
bool GetState() const
Get the matching state of the current item.
Definition stringfilter_type.h:67
StrongType::Typedef< uint32_t, struct GRFStringIDTag, StrongType::Compare, StrongType::Integer >
TestedEngineDetails
Extra information about refitted cargo and capacity.
Definition vehicle_gui.h:42
TestedEngineDetails::cargo
CargoType cargo
Cargo type.
Definition vehicle_gui.h:44
TestedEngineDetails::cost
Money cost
Refit cost.
Definition vehicle_gui.h:43
TestedEngineDetails::all_capacities
CargoArray all_capacities
Capacities for all cargoes.
Definition vehicle_gui.h:47
TestedEngineDetails::mail_capacity
uint16_t mail_capacity
Mail capacity if available.
Definition vehicle_gui.h:46
TestedEngineDetails::capacity
uint capacity
Cargo capacity.
Definition vehicle_gui.h:45
Textbuf::GetText
std::string_view GetText() const
Get the current text.
Definition textbuf.cpp:284
VehicleCellSize::extend_left
uint extend_left
Extend of the cell to the left.
Definition vehicle_gui.h:85
VehicleCellSize::extend_right
uint extend_right
Extend of the cell to the right.
Definition vehicle_gui.h:86
VehicleSettings::roadveh_acceleration_model
uint8_t roadveh_acceleration_model
realistic acceleration for road vehicles
Definition settings_type.h:521
VehicleSettings::train_acceleration_model
uint8_t train_acceleration_model
realistic acceleration for trains
Definition settings_type.h:520
VehicleSettings::wagon_speed_limits
bool wagon_speed_limits
enable wagon speed limits
Definition settings_type.h:524
WindowDesc
High level window description.
Definition window_gui.h:168
Window
Data structure for an opened window.
Definition window_gui.h:274
Window::ReInit
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:978
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition widget.cpp:815
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1807
Window::querystrings
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition window_gui.h:321
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:766
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition window.cpp:3234
Window::parent
Window * parent
Parent window.
Definition window_gui.h:329
Window::GetWidgetString
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:504
Window::DrawSortButtonState
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition widget.cpp:798
Window::CloseChildWindows
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
Definition window.cpp:1075
Window::resize
ResizeInfo resize
Resize information.
Definition window_gui.h:315
Window::SetWidgetsDisabledState
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition window_gui.h:516
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1797
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition window_gui.h:317
Window::SetWidgetLoweredState
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:442
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition window_gui.h:560
Window::widget_lookup
WidgetLookup widget_lookup
Indexed access to the nested widget tree. Do not access directly, use Window::GetWidget() instead.
Definition window_gui.h:323
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:313
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:382
Window::nested_root
std::unique_ptr< NWidgetBase > nested_root
Root of the nested tree.
Definition window_gui.h:322
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:312
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:303
textbuf_gui.h
Stuff related to the text buffer GUI.
QueryStringFlag::EnableDefault
@ EnableDefault
enable the 'Default' button ("\0" is returned)
QueryStringFlag::LengthIsInChars
@ LengthIsInChars
the length of the string is counted in characters
GetTileOwner
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition tile_map.h:178
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
TileIndex
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 tile_type.h:87
timer_game_calendar.h
Definition of the game-calendar-timer.
train_cmd.h
Command definitions related to trains.
CcBuildWagon
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.
Definition train_gui.cpp:29
GetEnginePalette
PaletteID GetEnginePalette(EngineID engine_type, CompanyID company)
Get the colour map for an engine.
Definition vehicle.cpp:2123
CanVehicleUseStation
bool CanVehicleUseStation(EngineID engine_type, const Station *st)
Can this station be used by the given engine type?
Definition vehicle.cpp:3046
vehicle_cmd.h
Command definitions for vehicles.
CcBuildPrimaryVehicle
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.
Definition vehicle_gui.cpp:3495
vehicle_func.h
Functions related to vehicles.
IsCompanyBuildableVehicleType
bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
Definition vehicle_func.h:228
ShowRefitOptionsList
uint ShowRefitOptionsList(int left, int right, int y, EngineID engine)
Display list of cargo types of the engine, for the purchase information window.
Definition vehicle_gui.cpp:1358
vehicle_gui.h
Functions related to the vehicle's GUIs.
EIT_PURCHASE
@ EIT_PURCHASE
Vehicle drawn in purchase list, autoreplace gui, ...
Definition vehicle_type.h:79
VehicleType
VehicleType
Available vehicle types.
Definition vehicle_type.h:22
VEH_INVALID
@ VEH_INVALID
Non-existing type of vehicle.
Definition vehicle_type.h:36
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition vehicle_type.h:26
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition vehicle_type.h:28
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition vehicle_type.h:27
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition vehicle_type.h:25
MAX_LENGTH_VEHICLE_NAME_CHARS
static const uint MAX_LENGTH_VEHICLE_NAME_CHARS
The maximum length of a vehicle name in characters including '\0'.
Definition vehicle_type.h:62
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition widget_type.h:104
WWT_IMGBTN
@ WWT_IMGBTN
(Toggle) Button with image
Definition widget_type.h:41
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition widget_type.h:62
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:44
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:57
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition widget_type.h:50
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:55
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:52
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:60
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition widget_type.h:59
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition widget_type.h:56
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition widget_type.h:61
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:71
SZSP_NONE
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
Definition widget_type.h:506
NWidContainerFlag
NWidContainerFlag
Nested widget container flags,.
Definition widget_type.h:540
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition window.cpp:1193
InvalidateWindowData
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-...
Definition window.cpp:3294
InvalidateWindowClassesData
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...
Definition window.cpp:3311
window_func.h
Window functions not directly related to making/drawing windows.
WindowDefaultFlag::Construction
@ Construction
This window is used for construction; close it whenever changing company.
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition window_gui.h:219
SBS_UP
@ SBS_UP
Sort descending.
Definition window_gui.h:220
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:144
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:20
WC_REPLACE_VEHICLE
@ WC_REPLACE_VEHICLE
Replace vehicle window; Window numbers:
Definition window_type.h:223
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:50
WC_DROPDOWN_MENU
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
Definition window_type.h:161
WC_BUILD_VEHICLE
@ WC_BUILD_VEHICLE
Build vehicle; Window numbers:
Definition window_type.h:394
zoom_func.h
Functions related to zooming.
ScaleSpriteTrad
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition zoom_func.h:107