OpenTTD Source  14.0-beta1
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 <http://www.gnu.org/licenses/>.
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_engine.h"
21 #include "newgrf_text.h"
22 #include "group.h"
23 #include "string_func.h"
24 #include "strings_func.h"
25 #include "window_func.h"
27 #include "vehicle_func.h"
28 #include "widgets/dropdown_func.h"
29 #include "engine_gui.h"
30 #include "cargotype.h"
31 #include "core/geometry_func.hpp"
32 #include "autoreplace_func.h"
33 #include "engine_cmd.h"
34 #include "train_cmd.h"
35 #include "vehicle_cmd.h"
36 #include "zoom_func.h"
37 #include "querystring_gui.h"
38 #include "stringfilter_type.h"
39 #include "hotkeys.h"
40 
42 
43 #include "table/strings.h"
44 
45 #include "safeguards.h"
46 
53 {
54  return std::max<uint>(GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.matrix.Vertical(), GetVehicleImageCellSize(type, EIT_PURCHASE).height);
55 }
56 
57 static constexpr NWidgetPart _nested_build_vehicle_widgets[] = {
59  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
60  NWidget(WWT_CAPTION, COLOUR_GREY, WID_BV_CAPTION), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS), SetTextStyle(TC_WHITE),
61  NWidget(WWT_SHADEBOX, COLOUR_GREY),
62  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
63  NWidget(WWT_STICKYBOX, COLOUR_GREY),
64  EndContainer(),
67  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_SORT_ASCENDING_DESCENDING), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
68  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
69  EndContainer(),
72  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_CARGO_FILTER_DROPDOWN), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_FILTER_CRITERIA),
73  EndContainer(),
74  NWidget(WWT_PANEL, COLOUR_GREY),
75  NWidget(WWT_EDITBOX, COLOUR_GREY, WID_BV_FILTER), SetResize(1, 0), SetFill(1, 0), SetPadding(2), SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
76  EndContainer(),
77  EndContainer(),
78  /* Vehicle list. */
80  NWidget(WWT_MATRIX, COLOUR_GREY, WID_BV_LIST), SetResize(1, 1), SetFill(1, 0), SetMatrixDataTip(1, 0, STR_NULL), SetScrollbar(WID_BV_SCROLLBAR),
82  EndContainer(),
83  /* Panel with details. */
84  NWidget(WWT_PANEL, COLOUR_GREY, WID_BV_PANEL), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
85  /* Build/rename buttons, resize button. */
87  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_BV_BUILD_SEL),
88  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_BUILD), SetResize(1, 0), SetFill(1, 0),
89  EndContainer(),
90  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_SHOW_HIDE), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_NULL),
91  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_RENAME), SetResize(1, 0), SetFill(1, 0),
92  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
93  EndContainer(),
94 };
95 
96 
98 byte _engine_sort_last_criteria[] = {0, 0, 0, 0};
99 bool _engine_sort_last_order[] = {false, false, false, false};
100 bool _engine_sort_show_hidden_engines[] = {false, false, false, false};
102 
110 {
111  int r = Engine::Get(a.engine_id)->list_position - Engine::Get(b.engine_id)->list_position;
112 
113  return _engine_sort_direction ? r > 0 : r < 0;
114 }
115 
123 {
124  const auto va = Engine::Get(a.engine_id)->intro_date;
125  const auto vb = Engine::Get(b.engine_id)->intro_date;
126  const auto r = va - vb;
127 
128  /* Use EngineID to sort instead since we want consistent sorting */
129  if (r == 0) return EngineNumberSorter(a, b);
130  return _engine_sort_direction ? r > 0 : r < 0;
131 }
132 
133 /* cached values for EngineNameSorter to spare many GetString() calls */
134 static EngineID _last_engine[2] = { INVALID_ENGINE, INVALID_ENGINE };
135 
142 static bool EngineNameSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
143 {
144  static std::string last_name[2] = { {}, {} };
145 
146  if (a.engine_id != _last_engine[0]) {
147  _last_engine[0] = a.engine_id;
149  last_name[0] = GetString(STR_ENGINE_NAME);
150  }
151 
152  if (b.engine_id != _last_engine[1]) {
153  _last_engine[1] = b.engine_id;
155  last_name[1] = GetString(STR_ENGINE_NAME);
156  }
157 
158  int r = StrNaturalCompare(last_name[0], last_name[1]); // Sort by name (natural sorting).
159 
160  /* Use EngineID to sort instead since we want consistent sorting */
161  if (r == 0) return EngineNumberSorter(a, b);
162  return _engine_sort_direction ? r > 0 : r < 0;
163 }
164 
172 {
173  const int va = Engine::Get(a.engine_id)->reliability;
174  const int vb = Engine::Get(b.engine_id)->reliability;
175  const int r = va - vb;
176 
177  /* Use EngineID to sort instead since we want consistent sorting */
178  if (r == 0) return EngineNumberSorter(a, b);
179  return _engine_sort_direction ? r > 0 : r < 0;
180 }
181 
188 static bool EngineCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
189 {
190  Money va = Engine::Get(a.engine_id)->GetCost();
191  Money vb = Engine::Get(b.engine_id)->GetCost();
192  int r = ClampTo<int32_t>(va - vb);
193 
194  /* Use EngineID to sort instead since we want consistent sorting */
195  if (r == 0) return EngineNumberSorter(a, b);
196  return _engine_sort_direction ? r > 0 : r < 0;
197 }
198 
206 {
207  int va = Engine::Get(a.engine_id)->GetDisplayMaxSpeed();
208  int vb = Engine::Get(b.engine_id)->GetDisplayMaxSpeed();
209  int r = va - vb;
210 
211  /* Use EngineID to sort instead since we want consistent sorting */
212  if (r == 0) return EngineNumberSorter(a, b);
213  return _engine_sort_direction ? r > 0 : r < 0;
214 }
215 
223 {
224  int va = Engine::Get(a.engine_id)->GetPower();
225  int vb = Engine::Get(b.engine_id)->GetPower();
226  int r = va - vb;
227 
228  /* Use EngineID to sort instead since we want consistent sorting */
229  if (r == 0) return EngineNumberSorter(a, b);
230  return _engine_sort_direction ? r > 0 : r < 0;
231 }
232 
240 {
241  int va = Engine::Get(a.engine_id)->GetDisplayMaxTractiveEffort();
242  int vb = Engine::Get(b.engine_id)->GetDisplayMaxTractiveEffort();
243  int r = va - vb;
244 
245  /* Use EngineID to sort instead since we want consistent sorting */
246  if (r == 0) return EngineNumberSorter(a, b);
247  return _engine_sort_direction ? r > 0 : r < 0;
248 }
249 
257 {
258  Money va = Engine::Get(a.engine_id)->GetRunningCost();
259  Money vb = Engine::Get(b.engine_id)->GetRunningCost();
260  int r = ClampTo<int32_t>(va - vb);
261 
262  /* Use EngineID to sort instead since we want consistent sorting */
263  if (r == 0) return EngineNumberSorter(a, b);
264  return _engine_sort_direction ? r > 0 : r < 0;
265 }
266 
274 {
275  const Engine *e_a = Engine::Get(a.engine_id);
276  const Engine *e_b = Engine::Get(b.engine_id);
277  uint p_a = e_a->GetPower();
278  uint p_b = e_b->GetPower();
279  Money r_a = e_a->GetRunningCost();
280  Money r_b = e_b->GetRunningCost();
281  /* Check if running cost is zero in one or both engines.
282  * If only one of them is zero then that one has higher value,
283  * else if both have zero cost then compare powers. */
284  if (r_a == 0) {
285  if (r_b == 0) {
286  /* If it is ambiguous which to return go with their ID */
287  if (p_a == p_b) return EngineNumberSorter(a, b);
288  return _engine_sort_direction != (p_a < p_b);
289  }
290  return !_engine_sort_direction;
291  }
292  if (r_b == 0) return _engine_sort_direction;
293  /* Using double for more precision when comparing close values.
294  * This shouldn't have any major effects in performance nor in keeping
295  * the game in sync between players since it's used in GUI only in client side */
296  double v_a = (double)p_a / (double)r_a;
297  double v_b = (double)p_b / (double)r_b;
298  /* Use EngineID to sort if both have same power/running cost,
299  * since we want consistent sorting.
300  * Also if both have no power then sort with reverse of running cost to simulate
301  * previous sorting behaviour for wagons. */
302  if (v_a == 0 && v_b == 0) return EngineRunningCostSorter(b, a);
303  if (v_a == v_b) return EngineNumberSorter(a, b);
304  return _engine_sort_direction != (v_a < v_b);
305 }
306 
307 /* Train sorting functions */
308 
316 {
317  const RailVehicleInfo *rvi_a = RailVehInfo(a.engine_id);
318  const RailVehicleInfo *rvi_b = RailVehInfo(b.engine_id);
319 
320  int va = GetTotalCapacityOfArticulatedParts(a.engine_id) * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
321  int vb = GetTotalCapacityOfArticulatedParts(b.engine_id) * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
322  int r = va - vb;
323 
324  /* Use EngineID to sort instead since we want consistent sorting */
325  if (r == 0) return EngineNumberSorter(a, b);
326  return _engine_sort_direction ? r > 0 : r < 0;
327 }
328 
336 {
337  int val_a = (RailVehInfo(a.engine_id)->railveh_type == RAILVEH_WAGON ? 1 : 0);
338  int val_b = (RailVehInfo(b.engine_id)->railveh_type == RAILVEH_WAGON ? 1 : 0);
339  int r = val_a - val_b;
340 
341  /* Use EngineID to sort instead since we want consistent sorting */
342  if (r == 0) return EngineNumberSorter(a, b);
343  return _engine_sort_direction ? r > 0 : r < 0;
344 }
345 
346 /* Road vehicle sorting functions */
347 
355 {
358  int r = va - vb;
359 
360  /* Use EngineID to sort instead since we want consistent sorting */
361  if (r == 0) return EngineNumberSorter(a, b);
362  return _engine_sort_direction ? r > 0 : r < 0;
363 }
364 
365 /* Ship vehicle sorting functions */
366 
374 {
375  const Engine *e_a = Engine::Get(a.engine_id);
376  const Engine *e_b = Engine::Get(b.engine_id);
377 
378  int va = e_a->GetDisplayDefaultCapacity();
379  int vb = e_b->GetDisplayDefaultCapacity();
380  int r = va - vb;
381 
382  /* Use EngineID to sort instead since we want consistent sorting */
383  if (r == 0) return EngineNumberSorter(a, b);
384  return _engine_sort_direction ? r > 0 : r < 0;
385 }
386 
387 /* Aircraft sorting functions */
388 
396 {
397  const Engine *e_a = Engine::Get(a.engine_id);
398  const Engine *e_b = Engine::Get(b.engine_id);
399 
400  uint16_t mail_a, mail_b;
401  int va = e_a->GetDisplayDefaultCapacity(&mail_a);
402  int vb = e_b->GetDisplayDefaultCapacity(&mail_b);
403  int r = va - vb;
404 
405  if (r == 0) {
406  /* The planes have the same passenger capacity. Check mail capacity instead */
407  r = mail_a - mail_b;
408 
409  if (r == 0) {
410  /* Use EngineID to sort instead since we want consistent sorting */
411  return EngineNumberSorter(a, b);
412  }
413  }
414  return _engine_sort_direction ? r > 0 : r < 0;
415 }
416 
424 {
425  uint16_t r_a = Engine::Get(a.engine_id)->GetRange();
426  uint16_t r_b = Engine::Get(b.engine_id)->GetRange();
427 
428  int r = r_a - r_b;
429 
430  /* Use EngineID to sort instead since we want consistent sorting */
431  if (r == 0) return EngineNumberSorter(a, b);
432  return _engine_sort_direction ? r > 0 : r < 0;
433 }
434 
437  /* Trains */
449 }, {
450  /* Road vehicles */
462 }, {
463  /* Ships */
472 }, {
473  /* Aircraft */
483 }};
484 
487  /* Trains */
488  STR_SORT_BY_ENGINE_ID,
489  STR_SORT_BY_COST,
490  STR_SORT_BY_MAX_SPEED,
491  STR_SORT_BY_POWER,
492  STR_SORT_BY_TRACTIVE_EFFORT,
493  STR_SORT_BY_INTRO_DATE,
494  STR_SORT_BY_NAME,
495  STR_SORT_BY_RUNNING_COST,
496  STR_SORT_BY_POWER_VS_RUNNING_COST,
497  STR_SORT_BY_RELIABILITY,
498  STR_SORT_BY_CARGO_CAPACITY,
500 }, {
501  /* Road vehicles */
502  STR_SORT_BY_ENGINE_ID,
503  STR_SORT_BY_COST,
504  STR_SORT_BY_MAX_SPEED,
505  STR_SORT_BY_POWER,
506  STR_SORT_BY_TRACTIVE_EFFORT,
507  STR_SORT_BY_INTRO_DATE,
508  STR_SORT_BY_NAME,
509  STR_SORT_BY_RUNNING_COST,
510  STR_SORT_BY_POWER_VS_RUNNING_COST,
511  STR_SORT_BY_RELIABILITY,
512  STR_SORT_BY_CARGO_CAPACITY,
514 }, {
515  /* Ships */
516  STR_SORT_BY_ENGINE_ID,
517  STR_SORT_BY_COST,
518  STR_SORT_BY_MAX_SPEED,
519  STR_SORT_BY_INTRO_DATE,
520  STR_SORT_BY_NAME,
521  STR_SORT_BY_RUNNING_COST,
522  STR_SORT_BY_RELIABILITY,
523  STR_SORT_BY_CARGO_CAPACITY,
525 }, {
526  /* Aircraft */
527  STR_SORT_BY_ENGINE_ID,
528  STR_SORT_BY_COST,
529  STR_SORT_BY_MAX_SPEED,
530  STR_SORT_BY_INTRO_DATE,
531  STR_SORT_BY_NAME,
532  STR_SORT_BY_RUNNING_COST,
533  STR_SORT_BY_RELIABILITY,
534  STR_SORT_BY_CARGO_CAPACITY,
535  STR_SORT_BY_RANGE,
537 }};
538 
540 static bool CDECL CargoAndEngineFilter(const GUIEngineListItem *item, const CargoID cid)
541 {
542  if (cid == CargoFilterCriteria::CF_ANY) {
543  return true;
544  } else if (cid == CargoFilterCriteria::CF_ENGINES) {
545  return Engine::Get(item->engine_id)->GetPower() != 0;
546  } else {
547  CargoTypes refit_mask = GetUnionOfArticulatedRefitMasks(item->engine_id, true) & _standard_cargo_mask;
548  return (cid == CargoFilterCriteria::CF_NONE ? refit_mask == 0 : HasBit(refit_mask, cid));
549  }
550 }
551 
552 static GUIEngineList::FilterFunction * const _filter_funcs[] = {
554 };
555 
556 static uint GetCargoWeight(const CargoArray &cap, VehicleType vtype)
557 {
558  uint weight = 0;
559  for (CargoID c = 0; c < NUM_CARGO; c++) {
560  if (cap[c] != 0) {
561  if (vtype == VEH_TRAIN) {
562  weight += CargoSpec::Get(c)->WeightOfNUnitsInTrain(cap[c]);
563  } else {
564  weight += CargoSpec::Get(c)->WeightOfNUnits(cap[c]);
565  }
566  }
567  }
568  return weight;
569 }
570 
571 static int DrawCargoCapacityInfo(int left, int right, int y, TestedEngineDetails &te, bool refittable)
572 {
573  for (const CargoSpec *cs : _sorted_cargo_specs) {
574  CargoID cid = cs->Index();
575  if (te.all_capacities[cid] == 0) continue;
576 
577  SetDParam(0, cid);
578  SetDParam(1, te.all_capacities[cid]);
579  SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
580  DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
582  }
583 
584  return y;
585 }
586 
587 /* Draw rail wagon specific details */
588 static int DrawRailWagonPurchaseInfo(int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi, TestedEngineDetails &te)
589 {
590  const Engine *e = Engine::Get(engine_number);
591 
592  /* Purchase cost */
593  if (te.cost != 0) {
594  SetDParam(0, e->GetCost() + te.cost);
595  SetDParam(1, te.cost);
596  DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
597  } else {
598  SetDParam(0, e->GetCost());
599  DrawString(left, right, y, STR_PURCHASE_INFO_COST);
600  }
602 
603  /* Wagon weight - (including cargo) */
604  uint weight = e->GetDisplayWeight();
605  SetDParam(0, weight);
606  SetDParam(1, GetCargoWeight(te.all_capacities, VEH_TRAIN) + weight);
607  DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
609 
610  /* Wagon speed limit, displayed if above zero */
612  uint max_speed = e->GetDisplayMaxSpeed();
613  if (max_speed > 0) {
614  SetDParam(0, PackVelocity(max_speed, e->type));
615  DrawString(left, right, y, STR_PURCHASE_INFO_SPEED);
617  }
618  }
619 
620  /* Running cost */
621  if (rvi->running_cost_class != INVALID_PRICE) {
622  SetDParam(0, e->GetRunningCost());
623  DrawString(left, right, y, TimerGameEconomy::UsingWallclockUnits() ? STR_PURCHASE_INFO_RUNNINGCOST_PERIOD : STR_PURCHASE_INFO_RUNNINGCOST_YEAR);
625  }
626 
627  return y;
628 }
629 
630 /* Draw locomotive specific details */
631 static int DrawRailEnginePurchaseInfo(int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi, TestedEngineDetails &te)
632 {
633  const Engine *e = Engine::Get(engine_number);
634 
635  /* Purchase Cost - Engine weight */
636  if (te.cost != 0) {
637  SetDParam(0, e->GetCost() + te.cost);
638  SetDParam(1, te.cost);
639  SetDParam(2, e->GetDisplayWeight());
640  DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_WEIGHT);
641  } else {
642  SetDParam(0, e->GetCost());
643  SetDParam(1, e->GetDisplayWeight());
644  DrawString(left, right, y, STR_PURCHASE_INFO_COST_WEIGHT);
645  }
647 
648  /* Max speed - Engine power */
650  SetDParam(1, e->GetPower());
651  DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_POWER);
653 
654  /* Max tractive effort - not applicable if old acceleration or maglev */
657  DrawString(left, right, y, STR_PURCHASE_INFO_MAX_TE);
659  }
660 
661  /* Running cost */
662  if (rvi->running_cost_class != INVALID_PRICE) {
663  SetDParam(0, e->GetRunningCost());
664  DrawString(left, right, y, TimerGameEconomy::UsingWallclockUnits() ? STR_PURCHASE_INFO_RUNNINGCOST_PERIOD : STR_PURCHASE_INFO_RUNNINGCOST_YEAR);
666  }
667 
668  /* Powered wagons power - Powered wagons extra weight */
669  if (rvi->pow_wag_power != 0) {
670  SetDParam(0, rvi->pow_wag_power);
671  SetDParam(1, rvi->pow_wag_weight);
672  DrawString(left, right, y, STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT);
674  }
675 
676  return y;
677 }
678 
679 /* Draw road vehicle specific details */
680 static int DrawRoadVehPurchaseInfo(int left, int right, int y, EngineID engine_number, TestedEngineDetails &te)
681 {
682  const Engine *e = Engine::Get(engine_number);
683 
685  /* Purchase Cost */
686  if (te.cost != 0) {
687  SetDParam(0, e->GetCost() + te.cost);
688  SetDParam(1, te.cost);
689  DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
690  } else {
691  SetDParam(0, e->GetCost());
692  DrawString(left, right, y, STR_PURCHASE_INFO_COST);
693  }
695 
696  /* Road vehicle weight - (including cargo) */
697  int16_t weight = e->GetDisplayWeight();
698  SetDParam(0, weight);
699  SetDParam(1, GetCargoWeight(te.all_capacities, VEH_ROAD) + weight);
700  DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
702 
703  /* Max speed - Engine power */
705  SetDParam(1, e->GetPower());
706  DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_POWER);
708 
709  /* Max tractive effort */
711  DrawString(left, right, y, STR_PURCHASE_INFO_MAX_TE);
713  } else {
714  /* Purchase cost - Max speed */
715  if (te.cost != 0) {
716  SetDParam(0, e->GetCost() + te.cost);
717  SetDParam(1, te.cost);
719  DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
720  } else {
721  SetDParam(0, e->GetCost());
723  DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
724  }
726  }
727 
728  /* Running cost */
729  SetDParam(0, e->GetRunningCost());
730  DrawString(left, right, y, TimerGameEconomy::UsingWallclockUnits() ? STR_PURCHASE_INFO_RUNNINGCOST_PERIOD : STR_PURCHASE_INFO_RUNNINGCOST_YEAR);
732 
733  return y;
734 }
735 
736 /* Draw ship specific details */
737 static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable, TestedEngineDetails &te)
738 {
739  const Engine *e = Engine::Get(engine_number);
740 
741  /* Purchase cost - Max speed */
742  uint raw_speed = e->GetDisplayMaxSpeed();
743  uint ocean_speed = e->u.ship.ApplyWaterClassSpeedFrac(raw_speed, true);
744  uint canal_speed = e->u.ship.ApplyWaterClassSpeedFrac(raw_speed, false);
745 
746  if (ocean_speed == canal_speed) {
747  if (te.cost != 0) {
748  SetDParam(0, e->GetCost() + te.cost);
749  SetDParam(1, te.cost);
750  SetDParam(2, PackVelocity(ocean_speed, e->type));
751  DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
752  } else {
753  SetDParam(0, e->GetCost());
754  SetDParam(1, PackVelocity(ocean_speed, e->type));
755  DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
756  }
758  } else {
759  if (te.cost != 0) {
760  SetDParam(0, e->GetCost() + te.cost);
761  SetDParam(1, te.cost);
762  DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
763  } else {
764  SetDParam(0, e->GetCost());
765  DrawString(left, right, y, STR_PURCHASE_INFO_COST);
766  }
768 
769  SetDParam(0, PackVelocity(ocean_speed, e->type));
770  DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_OCEAN);
772 
773  SetDParam(0, PackVelocity(canal_speed, e->type));
774  DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_CANAL);
776  }
777 
778  /* Cargo type + capacity */
779  SetDParam(0, te.cargo);
780  SetDParam(1, te.capacity);
781  SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
782  DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
784 
785  /* Running cost */
786  SetDParam(0, e->GetRunningCost());
787  DrawString(left, right, y, TimerGameEconomy::UsingWallclockUnits() ? STR_PURCHASE_INFO_RUNNINGCOST_PERIOD : STR_PURCHASE_INFO_RUNNINGCOST_YEAR);
789 
790  return y;
791 }
792 
802 static int DrawAircraftPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable, TestedEngineDetails &te)
803 {
804  const Engine *e = Engine::Get(engine_number);
805 
806  /* Purchase cost - Max speed */
807  if (te.cost != 0) {
808  SetDParam(0, e->GetCost() + te.cost);
809  SetDParam(1, te.cost);
811  DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
812  } else {
813  SetDParam(0, e->GetCost());
815  DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
816  }
818 
819  /* Cargo capacity */
820  if (te.mail_capacity > 0) {
821  SetDParam(0, te.cargo);
822  SetDParam(1, te.capacity);
823  SetDParam(2, CT_MAIL);
824  SetDParam(3, te.mail_capacity);
825  DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_CAPACITY);
826  } else {
827  /* Note, if the default capacity is selected by the refit capacity
828  * callback, then the capacity shown is likely to be incorrect. */
829  SetDParam(0, te.cargo);
830  SetDParam(1, te.capacity);
831  SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
832  DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
833  }
835 
836  /* Running cost */
837  SetDParam(0, e->GetRunningCost());
838  DrawString(left, right, y, TimerGameEconomy::UsingWallclockUnits() ? STR_PURCHASE_INFO_RUNNINGCOST_PERIOD : STR_PURCHASE_INFO_RUNNINGCOST_YEAR);
840 
841  /* Aircraft type */
843  DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_TYPE);
845 
846  /* Aircraft range, if available. */
847  uint16_t range = e->GetRange();
848  if (range != 0) {
849  SetDParam(0, range);
850  DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_RANGE);
852  }
853 
854  return y;
855 }
856 
857 
863 static std::optional<std::string> GetNewGRFAdditionalText(EngineID engine)
864 {
865  uint16_t callback = GetVehicleCallback(CBID_VEHICLE_ADDITIONAL_TEXT, 0, 0, engine, nullptr);
866  if (callback == CALLBACK_FAILED || callback == 0x400) return std::nullopt;
867  const GRFFile *grffile = Engine::Get(engine)->GetGRF();
868  assert(grffile != nullptr);
869  if (callback > 0x400) {
870  ErrorUnknownCallbackResult(grffile->grfid, CBID_VEHICLE_ADDITIONAL_TEXT, callback);
871  return std::nullopt;
872  }
873 
874  StartTextRefStackUsage(grffile, 6);
875  std::string result = GetString(GetGRFStringID(grffile->grfid, 0xD000 + callback));
877  return result;
878 }
879 
888 static uint ShowAdditionalText(int left, int right, int y, EngineID engine)
889 {
890  auto text = GetNewGRFAdditionalText(engine);
891  if (!text) return y;
892  return DrawStringMultiLine(left, right, y, INT32_MAX, *text, TC_BLACK);
893 }
894 
895 void TestedEngineDetails::FillDefaultCapacities(const Engine *e)
896 {
897  this->cargo = e->GetDefaultCargoType();
898  if (e->type == VEH_TRAIN || e->type == VEH_ROAD) {
900  this->capacity = this->all_capacities[this->cargo];
901  this->mail_capacity = 0;
902  } else {
904  this->all_capacities[this->cargo] = this->capacity;
905  this->all_capacities[CT_MAIL] = this->mail_capacity;
906  }
907  if (this->all_capacities.GetCount() == 0) this->cargo = INVALID_CARGO;
908 }
909 
916 int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number, TestedEngineDetails &te)
917 {
918  const Engine *e = Engine::Get(engine_number);
919  TimerGameCalendar::YearMonthDay ymd = TimerGameCalendar::ConvertDateToYMD(e->intro_date);
920  bool refittable = IsArticulatedVehicleRefittable(engine_number);
921  bool articulated_cargo = false;
922 
923  switch (e->type) {
924  default: NOT_REACHED();
925  case VEH_TRAIN:
926  if (e->u.rail.railveh_type == RAILVEH_WAGON) {
927  y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, &e->u.rail, te);
928  } else {
929  y = DrawRailEnginePurchaseInfo(left, right, y, engine_number, &e->u.rail, te);
930  }
931  articulated_cargo = true;
932  break;
933 
934  case VEH_ROAD:
935  y = DrawRoadVehPurchaseInfo(left, right, y, engine_number, te);
936  articulated_cargo = true;
937  break;
938 
939  case VEH_SHIP:
940  y = DrawShipPurchaseInfo(left, right, y, engine_number, refittable, te);
941  break;
942 
943  case VEH_AIRCRAFT:
944  y = DrawAircraftPurchaseInfo(left, right, y, engine_number, refittable, te);
945  break;
946  }
947 
948  if (articulated_cargo) {
949  /* Cargo type + capacity, or N/A */
950  int new_y = DrawCargoCapacityInfo(left, right, y, te, refittable);
951 
952  if (new_y == y) {
953  SetDParam(0, INVALID_CARGO);
954  SetDParam(2, STR_EMPTY);
955  DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
957  } else {
958  y = new_y;
959  }
960  }
961 
962  /* Draw details that apply to all types except rail wagons. */
963  if (e->type != VEH_TRAIN || e->u.rail.railveh_type != RAILVEH_WAGON) {
964  /* Design date - Life length */
965  SetDParam(0, ymd.year);
967  DrawString(left, right, y, STR_PURCHASE_INFO_DESIGNED_LIFE);
969 
970  /* Reliability */
972  DrawString(left, right, y, STR_PURCHASE_INFO_RELIABILITY);
974  }
975 
976  if (refittable) y = ShowRefitOptionsList(left, right, y, engine_number);
977 
978  /* Additional text from NewGRF */
979  y = ShowAdditionalText(left, right, y, engine_number);
980 
981  /* The NewGRF's name which the vehicle comes from */
982  const GRFConfig *config = GetGRFConfig(e->GetGRFID());
983  if (_settings_client.gui.show_newgrf_name && config != nullptr)
984  {
985  DrawString(left, right, y, config->GetName(), TC_BLACK);
987  }
988 
989  return y;
990 }
991 
1003 void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, uint16_t min, uint16_t max, EngineID selected_id, bool show_count, GroupID selected_group)
1004 {
1005  static const int sprite_y_offsets[] = { -1, -1, -2, -2 };
1006 
1007  /* Obligatory sanity checks! */
1008  assert(max <= eng_list.size());
1009 
1010  bool rtl = _current_text_dir == TD_RTL;
1011  int step_size = GetEngineListHeight(type);
1012  int sprite_left = GetVehicleImageCellSize(type, EIT_PURCHASE).extend_left;
1013  int sprite_right = GetVehicleImageCellSize(type, EIT_PURCHASE).extend_right;
1014  int sprite_width = sprite_left + sprite_right;
1015  int circle_width = std::max(GetScaledSpriteSize(SPR_CIRCLE_FOLDED).width, GetScaledSpriteSize(SPR_CIRCLE_UNFOLDED).width);
1016  int linecolour = _colour_gradient[COLOUR_ORANGE][4];
1017 
1018  Rect ir = r.WithHeight(step_size).Shrink(WidgetDimensions::scaled.matrix);
1019  int sprite_y_offset = ScaleSpriteTrad(sprite_y_offsets[type]) + ir.Height() / 2;
1020 
1021  Dimension replace_icon = {0, 0};
1022  int count_width = 0;
1023  if (show_count) {
1024  replace_icon = GetSpriteSize(SPR_GROUP_REPLACE_ACTIVE);
1025 
1026  uint biggest_num_engines = 0;
1027  for (auto i = min; i < max; i++) {
1028  const auto &item = eng_list[i];
1029  const uint num_engines = GetGroupNumEngines(_local_company, selected_group, item.engine_id);
1030  biggest_num_engines = std::max(biggest_num_engines, num_engines);
1031  }
1032 
1033  SetDParam(0, biggest_num_engines);
1034  count_width = GetStringBoundingBox(STR_JUST_COMMA, FS_SMALL).width;
1035  }
1036 
1037  Rect tr = ir.Indent(circle_width + WidgetDimensions::scaled.hsep_normal + sprite_width + WidgetDimensions::scaled.hsep_wide, rtl); // Name position
1038  Rect cr = tr.Indent(replace_icon.width + WidgetDimensions::scaled.hsep_wide, !rtl).WithWidth(count_width, !rtl); // Count position
1039  Rect rr = tr.WithWidth(replace_icon.width, !rtl); // Replace icon position
1040  if (show_count) tr = tr.Indent(count_width + WidgetDimensions::scaled.hsep_normal + replace_icon.width + WidgetDimensions::scaled.hsep_wide, !rtl);
1041 
1042  int normal_text_y_offset = (ir.Height() - GetCharacterHeight(FS_NORMAL)) / 2;
1043  int small_text_y_offset = ir.Height() - GetCharacterHeight(FS_SMALL);
1044  int replace_icon_y_offset = (ir.Height() - replace_icon.height) / 2;
1045 
1046  int y = ir.top;
1047  for (; min < max; min++, y += step_size) {
1048  const auto &item = eng_list[min];
1049  uint indent = item.indent * WidgetDimensions::scaled.hsep_indent;
1050  bool has_variants = (item.flags & EngineDisplayFlags::HasVariants) != EngineDisplayFlags::None;
1051  bool is_folded = (item.flags & EngineDisplayFlags::IsFolded) != EngineDisplayFlags::None;
1052  bool shaded = (item.flags & EngineDisplayFlags::Shaded) != EngineDisplayFlags::None;
1053  /* Note: num_engines is only used in the autoreplace GUI, so it is correct to use _local_company here. */
1054  const uint num_engines = GetGroupNumEngines(_local_company, selected_group, item.engine_id);
1055 
1056  const Engine *e = Engine::Get(item.engine_id);
1057  bool hidden = HasBit(e->company_hidden, _local_company);
1058  StringID str = hidden ? STR_HIDDEN_ENGINE_NAME : STR_ENGINE_NAME;
1059  TextColour tc = (item.engine_id == selected_id) ? TC_WHITE : ((hidden | shaded) ? (TC_GREY | TC_FORCED | TC_NO_SHADE) : TC_BLACK);
1060 
1061  if (show_count) {
1062  /* relies on show_count to find 'Vehicle in use' panel of autoreplace window */
1064  } else {
1065  SetDParam(0, PackEngineNameDParam(item.engine_id, EngineNameContext::PurchaseList, item.indent));
1066  }
1067  Rect itr = tr.Indent(indent, rtl);
1068  DrawString(itr.left, itr.right, y + normal_text_y_offset, str, tc);
1069  int sprite_x = ir.Indent(indent + circle_width + WidgetDimensions::scaled.hsep_normal, rtl).WithWidth(sprite_width, rtl).left + sprite_left;
1070  DrawVehicleEngine(r.left, r.right, sprite_x, y + sprite_y_offset, item.engine_id, (show_count && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(item.engine_id, _local_company), EIT_PURCHASE);
1071  if (show_count) {
1072  SetDParam(0, num_engines);
1073  DrawString(cr.left, cr.right, y + small_text_y_offset, STR_JUST_COMMA, TC_BLACK, SA_RIGHT | SA_FORCE, false, FS_SMALL);
1074  if (EngineHasReplacementForCompany(Company::Get(_local_company), item.engine_id, selected_group)) DrawSprite(SPR_GROUP_REPLACE_ACTIVE, num_engines == 0 ? PALETTE_CRASH : PAL_NONE, rr.left, y + replace_icon_y_offset);
1075  }
1076  if (has_variants) {
1077  Rect fr = ir.Indent(indent, rtl).WithWidth(circle_width, rtl);
1078  DrawSpriteIgnorePadding(is_folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, {fr.left, y, fr.right, y + ir.Height() - 1}, SA_CENTER);
1079  }
1080  if (indent > 0) {
1081  /* Draw tree lines */
1082  Rect fr = ir.Indent(indent - WidgetDimensions::scaled.hsep_indent, rtl).WithWidth(circle_width, rtl);
1083  int ycenter = y + normal_text_y_offset + GetCharacterHeight(FS_NORMAL) / 2;
1084  bool continues = (min + 1U) < eng_list.size() && eng_list[min + 1].indent == item.indent;
1085  GfxDrawLine(fr.left + circle_width / 2, y - WidgetDimensions::scaled.matrix.top, fr.left + circle_width / 2, continues ? y - WidgetDimensions::scaled.matrix.top + step_size - 1 : ycenter, linecolour, WidgetDimensions::scaled.fullbevel.top);
1086  GfxDrawLine(fr.left + circle_width / 2, ycenter, fr.right, ycenter, linecolour, WidgetDimensions::scaled.fullbevel.top);
1087  }
1088  }
1089 }
1090 
1098 void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selected, WidgetID button)
1099 {
1100  uint32_t hidden_mask = 0;
1101  /* Disable sorting by power or tractive effort when the original acceleration model for road vehicles is being used. */
1102  if (vehicle_type == VEH_ROAD && _settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) {
1103  SetBit(hidden_mask, 3); // power
1104  SetBit(hidden_mask, 4); // tractive effort
1105  SetBit(hidden_mask, 8); // power by running costs
1106  }
1107  /* Disable sorting by tractive effort when the original acceleration model for trains is being used. */
1108  if (vehicle_type == VEH_TRAIN && _settings_game.vehicle.train_acceleration_model == AM_ORIGINAL) {
1109  SetBit(hidden_mask, 4); // tractive effort
1110  }
1111  ShowDropDownMenu(w, _engine_sort_listing[vehicle_type], selected, button, 0, hidden_mask);
1112 }
1113 
1117 };
1118 
1122  union {
1125  } filter;
1132  GUIEngineList eng_list;
1135  Scrollbar *vscroll;
1137 
1140 
1141  void SetBuyVehicleText()
1142  {
1143  NWidgetCore *widget = this->GetWidget<NWidgetCore>(WID_BV_BUILD);
1144 
1145  bool refit = this->sel_engine != INVALID_ENGINE && this->cargo_filter_criteria != CargoFilterCriteria::CF_ANY && this->cargo_filter_criteria != CargoFilterCriteria::CF_NONE && this->cargo_filter_criteria != CargoFilterCriteria::CF_ENGINES;
1146  if (refit) refit = Engine::Get(this->sel_engine)->GetDefaultCargoType() != this->cargo_filter_criteria;
1147 
1148  if (refit) {
1149  widget->widget_data = STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_BUTTON + this->vehicle_type;
1150  widget->tool_tip = STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_TOOLTIP + this->vehicle_type;
1151  } else {
1152  widget->widget_data = STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + this->vehicle_type;
1153  widget->tool_tip = STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_TOOLTIP + this->vehicle_type;
1154  }
1155  }
1156 
1157  void AddChildren(const GUIEngineList &source, EngineID parent, int indent)
1158  {
1159  for (const auto &item : source) {
1160  if (item.variant_id != parent || item.engine_id == parent) continue;
1161 
1162  const Engine *e = Engine::Get(item.engine_id);
1163  EngineDisplayFlags flags = item.flags;
1165  this->eng_list.emplace_back(e->display_last_variant == INVALID_ENGINE ? item.engine_id : e->display_last_variant, item.engine_id, flags, indent);
1166 
1167  /* Add variants if not folded */
1169  /* Add this engine again as a child */
1170  if ((item.flags & EngineDisplayFlags::Shaded) == EngineDisplayFlags::None) {
1171  this->eng_list.emplace_back(item.engine_id, item.engine_id, EngineDisplayFlags::None, indent + 1);
1172  }
1173  AddChildren(source, item.engine_id, indent + 1);
1174  }
1175  }
1176  }
1177 
1179  {
1180  this->vehicle_type = type;
1181  this->listview_mode = tile == INVALID_TILE;
1182  this->window_number = this->listview_mode ? (int)type : tile.base();
1183 
1184  this->sel_engine = INVALID_ENGINE;
1185 
1186  this->sort_criteria = _engine_sort_last_criteria[type];
1187  this->descending_sort_order = _engine_sort_last_order[type];
1188  this->show_hidden_engines = _engine_sort_show_hidden_engines[type];
1189 
1190  this->UpdateFilterByTile();
1191 
1192  this->CreateNestedTree();
1193 
1194  this->vscroll = this->GetScrollbar(WID_BV_SCROLLBAR);
1195 
1196  /* If we are just viewing the list of vehicles, we do not need the Build button.
1197  * So we just hide it, and enlarge the Rename button by the now vacant place. */
1198  if (this->listview_mode) this->GetWidget<NWidgetStacked>(WID_BV_BUILD_SEL)->SetDisplayedPlane(SZSP_NONE);
1199 
1200  NWidgetCore *widget = this->GetWidget<NWidgetCore>(WID_BV_LIST);
1201  widget->tool_tip = STR_BUY_VEHICLE_TRAIN_LIST_TOOLTIP + type;
1202 
1203  widget = this->GetWidget<NWidgetCore>(WID_BV_SHOW_HIDE);
1204  widget->tool_tip = STR_BUY_VEHICLE_TRAIN_HIDE_SHOW_TOGGLE_TOOLTIP + type;
1205 
1206  widget = this->GetWidget<NWidgetCore>(WID_BV_RENAME);
1207  widget->widget_data = STR_BUY_VEHICLE_TRAIN_RENAME_BUTTON + type;
1208  widget->tool_tip = STR_BUY_VEHICLE_TRAIN_RENAME_TOOLTIP + type;
1209 
1210  widget = this->GetWidget<NWidgetCore>(WID_BV_SHOW_HIDDEN_ENGINES);
1211  widget->widget_data = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + type;
1212  widget->tool_tip = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + type;
1213  widget->SetLowered(this->show_hidden_engines);
1214 
1215  this->details_height = ((this->vehicle_type == VEH_TRAIN) ? 10 : 9);
1216 
1217  if (tile == INVALID_TILE) {
1218  this->FinishInitNested(type);
1219  } else {
1220  this->FinishInitNested(tile);
1221  }
1222 
1223  this->querystrings[WID_BV_FILTER] = &this->vehicle_editbox;
1224  this->vehicle_editbox.cancel_button = QueryString::ACTION_CLEAR;
1225 
1226  this->owner = (tile != INVALID_TILE) ? GetTileOwner(tile) : _local_company;
1227 
1228  this->eng_list.ForceRebuild();
1229  this->GenerateBuildList(); // generate the list, since we need it in the next line
1230 
1231  /* Select the first unshaded engine in the list as default when opening the window */
1232  EngineID engine = INVALID_ENGINE;
1233  auto it = std::find_if(this->eng_list.begin(), this->eng_list.end(), [&](GUIEngineListItem &item){ return (item.flags & EngineDisplayFlags::Shaded) == EngineDisplayFlags::None; });
1234  if (it != this->eng_list.end()) engine = it->engine_id;
1235  this->SelectEngine(engine);
1236  }
1237 
1240  {
1241  switch (this->vehicle_type) {
1242  default: NOT_REACHED();
1243  case VEH_TRAIN:
1244  if (this->listview_mode) {
1245  this->filter.railtype = INVALID_RAILTYPE;
1246  } else {
1247  this->filter.railtype = GetRailType(this->window_number);
1248  }
1249  break;
1250 
1251  case VEH_ROAD:
1252  if (this->listview_mode) {
1253  this->filter.roadtype = INVALID_ROADTYPE;
1254  } else {
1255  this->filter.roadtype = GetRoadTypeRoad(this->window_number);
1256  if (this->filter.roadtype == INVALID_ROADTYPE) {
1257  this->filter.roadtype = GetRoadTypeTram(this->window_number);
1258  }
1259  }
1260  break;
1261 
1262  case VEH_SHIP:
1263  case VEH_AIRCRAFT:
1264  break;
1265  }
1266  }
1267 
1268  StringID GetCargoFilterLabel(CargoID cid) const
1269  {
1270  switch (cid) {
1271  case CargoFilterCriteria::CF_ANY: return STR_PURCHASE_INFO_ALL_TYPES;
1272  case CargoFilterCriteria::CF_ENGINES: return STR_PURCHASE_INFO_ENGINES_ONLY;
1273  case CargoFilterCriteria::CF_NONE: return STR_PURCHASE_INFO_NONE;
1274  default: return CargoSpec::Get(cid)->name;
1275  }
1276  }
1277 
1280  {
1281  /* Set the last cargo filter criteria. */
1282  this->cargo_filter_criteria = _engine_sort_last_cargo_criteria[this->vehicle_type];
1283  if (this->cargo_filter_criteria < NUM_CARGO && !HasBit(_standard_cargo_mask, this->cargo_filter_criteria)) this->cargo_filter_criteria = CargoFilterCriteria::CF_ANY;
1284 
1285  this->eng_list.SetFilterFuncs(_filter_funcs);
1286  this->eng_list.SetFilterState(this->cargo_filter_criteria != CargoFilterCriteria::CF_ANY);
1287  }
1288 
1289  void SelectEngine(EngineID engine)
1290  {
1291  CargoID cargo = this->cargo_filter_criteria;
1292  if (cargo == CargoFilterCriteria::CF_ANY || cargo == CargoFilterCriteria::CF_ENGINES || cargo == CargoFilterCriteria::CF_NONE) cargo = INVALID_CARGO;
1293 
1294  this->sel_engine = engine;
1295  this->SetBuyVehicleText();
1296 
1297  if (this->sel_engine == INVALID_ENGINE) return;
1298 
1299  const Engine *e = Engine::Get(this->sel_engine);
1300 
1301  if (!this->listview_mode) {
1302  /* Query for cost and refitted capacity */
1303  auto [ret, veh_id, refit_capacity, refit_mail, cargo_capacities] = Command<CMD_BUILD_VEHICLE>::Do(DC_QUERY_COST, this->window_number, this->sel_engine, true, cargo, INVALID_CLIENT_ID);
1304  if (ret.Succeeded()) {
1305  this->te.cost = ret.GetCost() - e->GetCost();
1306  this->te.capacity = refit_capacity;
1307  this->te.mail_capacity = refit_mail;
1308  this->te.cargo = !IsValidCargoID(cargo) ? e->GetDefaultCargoType() : cargo;
1309  this->te.all_capacities = cargo_capacities;
1310  return;
1311  }
1312  }
1313 
1314  /* Purchase test was not possible or failed, fill in the defaults instead. */
1315  this->te.cost = 0;
1316  this->te.FillDefaultCapacities(e);
1317  }
1318 
1319  void OnInit() override
1320  {
1321  this->SetCargoFilterArray();
1322  }
1323 
1326  {
1327  this->eng_list.Filter(this->cargo_filter_criteria);
1328  if (0 == this->eng_list.size()) { // no engine passed through the filter, invalidate the previously selected engine
1329  this->SelectEngine(INVALID_ENGINE);
1330  } else if (std::find(this->eng_list.begin(), this->eng_list.end(), this->sel_engine) == this->eng_list.end()) { // previously selected engine didn't pass the filter, select the first engine of the list
1331  this->SelectEngine(this->eng_list[0].engine_id);
1332  }
1333  }
1334 
1337  {
1338  GUIEngineListItem item = {eid, eid, EngineDisplayFlags::None, 0};
1339  return CargoAndEngineFilter(&item, this->cargo_filter_criteria);
1340  }
1341 
1343  bool FilterByText(const Engine *e)
1344  {
1345  /* Do not filter if the filter text box is empty */
1346  if (this->string_filter.IsEmpty()) return true;
1347 
1348  /* Filter engine name */
1349  this->string_filter.ResetState();
1351  this->string_filter.AddLine(GetString(STR_ENGINE_NAME));
1352 
1353  /* Filter NewGRF extra text */
1354  auto text = GetNewGRFAdditionalText(e->index);
1355  if (text) this->string_filter.AddLine(*text);
1356 
1357  return this->string_filter.GetState();
1358  }
1359 
1360  /* Figure out what train EngineIDs to put in the list */
1361  void GenerateBuildTrainList(GUIEngineList &list)
1362  {
1363  std::vector<EngineID> variants;
1364  EngineID sel_id = INVALID_ENGINE;
1365  size_t num_engines = 0;
1366 
1367  list.clear();
1368 
1369  /* Make list of all available train engines and wagons.
1370  * Also check to see if the previously selected engine is still available,
1371  * and if not, reset selection to INVALID_ENGINE. This could be the case
1372  * when engines become obsolete and are removed */
1373  for (const Engine *e : Engine::IterateType(VEH_TRAIN)) {
1374  if (!this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue;
1375  EngineID eid = e->index;
1376  const RailVehicleInfo *rvi = &e->u.rail;
1377 
1378  if (this->filter.railtype != INVALID_RAILTYPE && !HasPowerOnRail(rvi->railtype, this->filter.railtype)) continue;
1379  if (!IsEngineBuildable(eid, VEH_TRAIN, _local_company)) continue;
1380 
1381  /* Filter now! So num_engines and num_wagons is valid */
1382  if (!FilterSingleEngine(eid)) continue;
1383 
1384  /* Filter by name or NewGRF extra text */
1385  if (!FilterByText(e)) continue;
1386 
1387  list.emplace_back(eid, e->info.variant_id, e->display_flags, 0);
1388 
1389  if (rvi->railveh_type != RAILVEH_WAGON) num_engines++;
1390 
1391  /* Add all parent variants of this engine to the variant list */
1392  EngineID parent = e->info.variant_id;
1393  while (parent != INVALID_ENGINE) {
1394  variants.push_back(parent);
1395  parent = Engine::Get(parent)->info.variant_id;
1396  }
1397 
1398  if (eid == this->sel_engine) sel_id = eid;
1399  }
1400 
1401  /* ensure primary engine of variant group is in list */
1402  for (const auto &variant : variants) {
1403  if (std::find(list.begin(), list.end(), variant) == list.end()) {
1404  const Engine *e = Engine::Get(variant);
1405  list.emplace_back(variant, e->info.variant_id, e->display_flags | EngineDisplayFlags::Shaded, 0);
1406  if (e->u.rail.railveh_type != RAILVEH_WAGON) num_engines++;
1407  }
1408  }
1409 
1410  this->SelectEngine(sel_id);
1411 
1412  /* invalidate cached values for name sorter - engine names could change */
1413  _last_engine[0] = _last_engine[1] = INVALID_ENGINE;
1414 
1415  /* make engines first, and then wagons, sorted by selected sort_criteria */
1416  _engine_sort_direction = false;
1418 
1419  /* and then sort engines */
1421  EngList_SortPartial(list, _engine_sort_functions[0][this->sort_criteria], 0, num_engines);
1422 
1423  /* and finally sort wagons */
1424  EngList_SortPartial(list, _engine_sort_functions[0][this->sort_criteria], num_engines, list.size() - num_engines);
1425  }
1426 
1427  /* Figure out what road vehicle EngineIDs to put in the list */
1428  void GenerateBuildRoadVehList()
1429  {
1430  EngineID sel_id = INVALID_ENGINE;
1431 
1432  this->eng_list.clear();
1433 
1434  for (const Engine *e : Engine::IterateType(VEH_ROAD)) {
1435  if (!this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue;
1436  EngineID eid = e->index;
1437  if (!IsEngineBuildable(eid, VEH_ROAD, _local_company)) continue;
1438  if (this->filter.roadtype != INVALID_ROADTYPE && !HasPowerOnRoad(e->u.road.roadtype, this->filter.roadtype)) continue;
1439 
1440  /* Filter by name or NewGRF extra text */
1441  if (!FilterByText(e)) continue;
1442 
1443  this->eng_list.emplace_back(eid, e->info.variant_id, e->display_flags, 0);
1444 
1445  if (eid == this->sel_engine) sel_id = eid;
1446  }
1447  this->SelectEngine(sel_id);
1448  }
1449 
1450  /* Figure out what ship EngineIDs to put in the list */
1451  void GenerateBuildShipList()
1452  {
1453  EngineID sel_id = INVALID_ENGINE;
1454  this->eng_list.clear();
1455 
1456  for (const Engine *e : Engine::IterateType(VEH_SHIP)) {
1457  if (!this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue;
1458  EngineID eid = e->index;
1459  if (!IsEngineBuildable(eid, VEH_SHIP, _local_company)) continue;
1460 
1461  /* Filter by name or NewGRF extra text */
1462  if (!FilterByText(e)) continue;
1463 
1464  this->eng_list.emplace_back(eid, e->info.variant_id, e->display_flags, 0);
1465 
1466  if (eid == this->sel_engine) sel_id = eid;
1467  }
1468  this->SelectEngine(sel_id);
1469  }
1470 
1471  /* Figure out what aircraft EngineIDs to put in the list */
1472  void GenerateBuildAircraftList()
1473  {
1474  EngineID sel_id = INVALID_ENGINE;
1475 
1476  this->eng_list.clear();
1477 
1478  const Station *st = this->listview_mode ? nullptr : Station::GetByTile(this->window_number);
1479 
1480  /* Make list of all available planes.
1481  * Also check to see if the previously selected plane is still available,
1482  * and if not, reset selection to INVALID_ENGINE. This could be the case
1483  * when planes become obsolete and are removed */
1484  for (const Engine *e : Engine::IterateType(VEH_AIRCRAFT)) {
1485  if (!this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue;
1486  EngineID eid = e->index;
1487  if (!IsEngineBuildable(eid, VEH_AIRCRAFT, _local_company)) continue;
1488  /* First VEH_END window_numbers are fake to allow a window open for all different types at once */
1489  if (!this->listview_mode && !CanVehicleUseStation(eid, st)) continue;
1490 
1491  /* Filter by name or NewGRF extra text */
1492  if (!FilterByText(e)) 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 
1499  this->SelectEngine(sel_id);
1500  }
1501 
1502  /* Generate the list of vehicles */
1503  void GenerateBuildList()
1504  {
1505  if (!this->eng_list.NeedRebuild()) return;
1506 
1507  /* Update filter type in case the road/railtype of the depot got converted */
1508  this->UpdateFilterByTile();
1509 
1510  this->eng_list.clear();
1511 
1512  GUIEngineList list;
1513 
1514  switch (this->vehicle_type) {
1515  default: NOT_REACHED();
1516  case VEH_TRAIN:
1517  this->GenerateBuildTrainList(list);
1518  AddChildren(list, INVALID_ENGINE, 0);
1519  this->eng_list.shrink_to_fit();
1520  this->eng_list.RebuildDone();
1521  return;
1522  case VEH_ROAD:
1523  this->GenerateBuildRoadVehList();
1524  break;
1525  case VEH_SHIP:
1526  this->GenerateBuildShipList();
1527  break;
1528  case VEH_AIRCRAFT:
1529  this->GenerateBuildAircraftList();
1530  break;
1531  }
1532 
1533  this->FilterEngineList();
1534 
1535  /* ensure primary engine of variant group is in list after filtering */
1536  std::vector<EngineID> variants;
1537  for (const auto &item : this->eng_list) {
1538  EngineID parent = item.variant_id;
1539  while (parent != INVALID_ENGINE) {
1540  variants.push_back(parent);
1541  parent = Engine::Get(parent)->info.variant_id;
1542  }
1543  }
1544 
1545  for (const auto &variant : variants) {
1546  if (std::find(this->eng_list.begin(), this->eng_list.end(), variant) == this->eng_list.end()) {
1547  const Engine *e = Engine::Get(variant);
1548  this->eng_list.emplace_back(variant, e->info.variant_id, e->display_flags | EngineDisplayFlags::Shaded, 0);
1549  }
1550  }
1551 
1553  EngList_Sort(this->eng_list, _engine_sort_functions[this->vehicle_type][this->sort_criteria]);
1554 
1555  this->eng_list.swap(list);
1556  AddChildren(list, INVALID_ENGINE, 0);
1557  this->eng_list.shrink_to_fit();
1558  this->eng_list.RebuildDone();
1559  }
1560 
1561  DropDownList BuildCargoDropDownList() const
1562  {
1563  DropDownList list;
1564 
1565  /* Add item for disabling filtering. */
1566  list.push_back(std::make_unique<DropDownListStringItem>(this->GetCargoFilterLabel(CargoFilterCriteria::CF_ANY), CargoFilterCriteria::CF_ANY, false));
1567  /* Specific filters for trains. */
1568  if (this->vehicle_type == VEH_TRAIN) {
1569  /* Add item for locomotives only in case of trains. */
1570  list.push_back(std::make_unique<DropDownListStringItem>(this->GetCargoFilterLabel(CargoFilterCriteria::CF_ENGINES), CargoFilterCriteria::CF_ENGINES, false));
1571  /* Add item for vehicles not carrying anything, e.g. train engines.
1572  * This could also be useful for eyecandy vehicles of other types, but is likely too confusing for joe, */
1573  list.push_back(std::make_unique<DropDownListStringItem>(this->GetCargoFilterLabel(CargoFilterCriteria::CF_NONE), CargoFilterCriteria::CF_NONE, false));
1574  }
1575 
1576  /* Add cargos */
1578  for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
1579  list.push_back(std::make_unique<DropDownListIconItem>(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index(), false));
1580  }
1581 
1582  return list;
1583  }
1584 
1585  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1586  {
1587  switch (widget) {
1589  this->descending_sort_order ^= true;
1591  this->eng_list.ForceRebuild();
1592  this->SetDirty();
1593  break;
1594 
1596  this->show_hidden_engines ^= true;
1598  this->eng_list.ForceRebuild();
1599  this->SetWidgetLoweredState(widget, this->show_hidden_engines);
1600  this->SetDirty();
1601  break;
1602 
1603  case WID_BV_LIST: {
1605  const auto it = this->vscroll->GetScrolledItemFromWidget(this->eng_list, pt.y, this, WID_BV_LIST);
1606  if (it != this->eng_list.end()) {
1607  const auto &item = *it;
1608  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);
1609  if ((item.flags & EngineDisplayFlags::HasVariants) != EngineDisplayFlags::None && IsInsideMM(r.left, r.right, pt.x)) {
1610  /* toggle folded flag on engine */
1611  assert(item.variant_id != INVALID_ENGINE);
1612  Engine *engine = Engine::Get(item.variant_id);
1614 
1615  InvalidateWindowData(WC_REPLACE_VEHICLE, this->vehicle_type, 0); // Update the autoreplace window
1616  InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well
1617  return;
1618  }
1619  if ((item.flags & EngineDisplayFlags::Shaded) == EngineDisplayFlags::None) e = item.engine_id;
1620  }
1621  this->SelectEngine(e);
1622  this->SetDirty();
1623  if (_ctrl_pressed) {
1624  this->OnClick(pt, WID_BV_SHOW_HIDE, 1);
1625  } else if (click_count > 1 && !this->listview_mode) {
1626  this->OnClick(pt, WID_BV_BUILD, 1);
1627  }
1628  break;
1629  }
1630 
1631  case WID_BV_SORT_DROPDOWN: // Select sorting criteria dropdown menu
1632  DisplayVehicleSortDropDown(this, this->vehicle_type, this->sort_criteria, WID_BV_SORT_DROPDOWN);
1633  break;
1634 
1635  case WID_BV_CARGO_FILTER_DROPDOWN: // Select cargo filtering criteria dropdown menu
1636  ShowDropDownList(this, this->BuildCargoDropDownList(), this->cargo_filter_criteria, widget);
1637  break;
1638 
1639  case WID_BV_SHOW_HIDE: {
1640  const Engine *e = (this->sel_engine == INVALID_ENGINE) ? nullptr : Engine::Get(this->sel_engine);
1641  if (e != nullptr) {
1643  }
1644  break;
1645  }
1646 
1647  case WID_BV_BUILD: {
1648  EngineID sel_eng = this->sel_engine;
1649  if (sel_eng != INVALID_ENGINE) {
1650  CargoID cargo = this->cargo_filter_criteria;
1651  if (cargo == CargoFilterCriteria::CF_ANY || cargo == CargoFilterCriteria::CF_ENGINES || cargo == CargoFilterCriteria::CF_NONE) cargo = INVALID_CARGO;
1652  if (this->vehicle_type == VEH_TRAIN && RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) {
1653  Command<CMD_BUILD_VEHICLE>::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildWagon, this->window_number, sel_eng, true, cargo, INVALID_CLIENT_ID);
1654  } else {
1655  Command<CMD_BUILD_VEHICLE>::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildPrimaryVehicle, this->window_number, sel_eng, true, cargo, INVALID_CLIENT_ID);
1656  }
1657 
1658  /* Update last used variant in hierarchy and refresh if necessary. */
1659  bool refresh = false;
1660  EngineID parent = sel_eng;
1661  while (parent != INVALID_ENGINE) {
1662  Engine *e = Engine::Get(parent);
1663  refresh |= (e->display_last_variant != sel_eng);
1664  e->display_last_variant = sel_eng;
1665  parent = e->info.variant_id;
1666  }
1667  if (refresh) {
1668  InvalidateWindowData(WC_REPLACE_VEHICLE, this->vehicle_type, 0); // Update the autoreplace window
1669  InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well
1670  return;
1671  }
1672  }
1673  break;
1674  }
1675 
1676  case WID_BV_RENAME: {
1677  EngineID sel_eng = this->sel_engine;
1678  if (sel_eng != INVALID_ENGINE) {
1679  this->rename_engine = sel_eng;
1681  ShowQueryString(STR_ENGINE_NAME, STR_QUERY_RENAME_TRAIN_TYPE_CAPTION + this->vehicle_type, MAX_LENGTH_ENGINE_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS);
1682  }
1683  break;
1684  }
1685  }
1686  }
1687 
1693  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1694  {
1695  if (!gui_scope) return;
1696  /* When switching to original acceleration model for road vehicles, clear the selected sort criteria if it is not available now. */
1697  if (this->vehicle_type == VEH_ROAD &&
1699  this->sort_criteria > 7) {
1700  this->sort_criteria = 0;
1702  }
1703  this->eng_list.ForceRebuild();
1704  }
1705 
1706  void SetStringParameters(WidgetID widget) const override
1707  {
1708  switch (widget) {
1709  case WID_BV_CAPTION:
1710  if (this->vehicle_type == VEH_TRAIN && !this->listview_mode) {
1711  const RailTypeInfo *rti = GetRailTypeInfo(this->filter.railtype);
1712  SetDParam(0, rti->strings.build_caption);
1713  } else if (this->vehicle_type == VEH_ROAD && !this->listview_mode) {
1714  const RoadTypeInfo *rti = GetRoadTypeInfo(this->filter.roadtype);
1715  SetDParam(0, rti->strings.build_caption);
1716  } else {
1717  SetDParam(0, (this->listview_mode ? STR_VEHICLE_LIST_AVAILABLE_TRAINS : STR_BUY_VEHICLE_TRAIN_ALL_CAPTION) + this->vehicle_type);
1718  }
1719  break;
1720 
1721  case WID_BV_SORT_DROPDOWN:
1722  SetDParam(0, _engine_sort_listing[this->vehicle_type][this->sort_criteria]);
1723  break;
1724 
1726  SetDParam(0, this->GetCargoFilterLabel(this->cargo_filter_criteria));
1727  break;
1728 
1729  case WID_BV_SHOW_HIDE: {
1730  const Engine *e = (this->sel_engine == INVALID_ENGINE) ? nullptr : Engine::Get(this->sel_engine);
1731  if (e != nullptr && e->IsHidden(_local_company)) {
1732  SetDParam(0, STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + this->vehicle_type);
1733  } else {
1734  SetDParam(0, STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + this->vehicle_type);
1735  }
1736  break;
1737  }
1738  }
1739  }
1740 
1741  void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
1742  {
1743  switch (widget) {
1744  case WID_BV_LIST:
1745  resize->height = GetEngineListHeight(this->vehicle_type);
1746  size->height = 3 * resize->height;
1747  size->width = std::max(size->width, GetVehicleImageCellSize(this->vehicle_type, EIT_PURCHASE).extend_left + GetVehicleImageCellSize(this->vehicle_type, EIT_PURCHASE).extend_right + 165) + padding.width;
1748  break;
1749 
1750  case WID_BV_PANEL:
1751  size->height = GetCharacterHeight(FS_NORMAL) * this->details_height + padding.height;
1752  break;
1753 
1755  Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
1756  d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
1757  d.height += padding.height;
1758  *size = maxdim(*size, d);
1759  break;
1760  }
1761 
1763  size->width = std::max(size->width, GetDropDownListDimension(this->BuildCargoDropDownList()).width + padding.width);
1764  break;
1765 
1766  case WID_BV_BUILD:
1767  *size = GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + this->vehicle_type);
1768  *size = maxdim(*size, GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_BUTTON + this->vehicle_type));
1769  size->width += padding.width;
1770  size->height += padding.height;
1771  break;
1772 
1773  case WID_BV_SHOW_HIDE:
1774  *size = GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + this->vehicle_type);
1775  *size = maxdim(*size, GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + this->vehicle_type));
1776  size->width += padding.width;
1777  size->height += padding.height;
1778  break;
1779  }
1780  }
1781 
1782  void DrawWidget(const Rect &r, WidgetID widget) const override
1783  {
1784  switch (widget) {
1785  case WID_BV_LIST:
1787  this->vehicle_type,
1788  r,
1789  this->eng_list,
1790  this->vscroll->GetPosition(),
1791  static_cast<uint16_t>(std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->eng_list.size())),
1792  this->sel_engine,
1793  false,
1795  );
1796  break;
1797 
1799  this->DrawSortButtonState(WID_BV_SORT_ASCENDING_DESCENDING, this->descending_sort_order ? SBS_DOWN : SBS_UP);
1800  break;
1801  }
1802  }
1803 
1804  void OnPaint() override
1805  {
1806  this->GenerateBuildList();
1807  this->vscroll->SetCount(this->eng_list.size());
1808 
1810 
1811  /* Disable renaming engines in network games if you are not the server. */
1812  this->SetWidgetDisabledState(WID_BV_RENAME, this->sel_engine == INVALID_ENGINE || (_networking && !_network_server));
1813 
1814  this->DrawWidgets();
1815 
1816  if (!this->IsShaded()) {
1817  int needed_height = this->details_height;
1818  /* Draw details panels. */
1819  if (this->sel_engine != INVALID_ENGINE) {
1820  const Rect r = this->GetWidget<NWidgetBase>(WID_BV_PANEL)->GetCurrentRect().Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect);
1821  int text_end = DrawVehiclePurchaseInfo(r.left, r.right, r.top, this->sel_engine, this->te);
1822  needed_height = std::max(needed_height, (text_end - r.top) / GetCharacterHeight(FS_NORMAL));
1823  }
1824  if (needed_height != this->details_height) { // Details window are not high enough, enlarge them.
1825  int resize = needed_height - this->details_height;
1826  this->details_height = needed_height;
1827  this->ReInit(0, resize * GetCharacterHeight(FS_NORMAL));
1828  return;
1829  }
1830  }
1831  }
1832 
1833  void OnQueryTextFinished(char *str) override
1834  {
1835  if (str == nullptr) return;
1836 
1837  Command<CMD_RENAME_ENGINE>::Post(STR_ERROR_CAN_T_RENAME_TRAIN_TYPE + this->vehicle_type, this->rename_engine, str);
1838  }
1839 
1840  void OnDropdownSelect(WidgetID widget, int index) override
1841  {
1842  switch (widget) {
1843  case WID_BV_SORT_DROPDOWN:
1844  if (this->sort_criteria != index) {
1845  this->sort_criteria = index;
1847  this->eng_list.ForceRebuild();
1848  }
1849  break;
1850 
1851  case WID_BV_CARGO_FILTER_DROPDOWN: // Select a cargo filter criteria
1852  if (this->cargo_filter_criteria != index) {
1853  this->cargo_filter_criteria = index;
1855  /* deactivate filter if criteria is 'Show All', activate it otherwise */
1856  this->eng_list.SetFilterState(this->cargo_filter_criteria != CargoFilterCriteria::CF_ANY);
1857  this->eng_list.ForceRebuild();
1858  this->SelectEngine(this->sel_engine);
1859  }
1860  break;
1861  }
1862  this->SetDirty();
1863  }
1864 
1865  void OnResize() override
1866  {
1867  this->vscroll->SetCapacityFromWidget(this, WID_BV_LIST);
1868  }
1869 
1870  void OnEditboxChanged(WidgetID wid) override
1871  {
1872  if (wid == WID_BV_FILTER) {
1873  this->string_filter.SetFilterTerm(this->vehicle_editbox.text.buf);
1874  this->InvalidateData();
1875  }
1876  }
1877 
1878  EventState OnHotkey(int hotkey) override
1879  {
1880  switch (hotkey) {
1881  case BVHK_FOCUS_FILTER_BOX:
1883  SetFocusedWindow(this); // The user has asked to give focus to the text box, so make sure this window is focused.
1884  return ES_HANDLED;
1885 
1886  default:
1887  return ES_NOT_HANDLED;
1888  }
1889 
1890  return ES_HANDLED;
1891  }
1892 
1893  static inline HotkeyList hotkeys{"buildvehicle", {
1894  Hotkey('F', "focus_filter_box", BVHK_FOCUS_FILTER_BOX),
1895  }};
1896 };
1897 
1898 static WindowDesc _build_vehicle_desc(__FILE__, __LINE__,
1899  WDP_AUTO, "build_vehicle", 240, 268,
1902  std::begin(_nested_build_vehicle_widgets), std::end(_nested_build_vehicle_widgets),
1903  &BuildVehicleWindow::hotkeys
1904 );
1905 
1906 void ShowBuildVehicleWindow(TileIndex tile, VehicleType type)
1907 {
1908  /* We want to be able to open both Available Train as Available Ships,
1909  * so if tile == INVALID_TILE (Available XXX Window), use 'type' as unique number.
1910  * As it always is a low value, it won't collide with any real tile
1911  * number. */
1912  uint num = (tile == INVALID_TILE) ? (int)type : tile.base();
1913 
1914  assert(IsCompanyBuildableVehicleType(type));
1915 
1917 
1918  new BuildVehicleWindow(&_build_vehicle_desc, tile, type);
1919 }
SZSP_NONE
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
Definition: widget_type.h:469
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
_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:436
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:739
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:1098
TC_FORCED
@ TC_FORCED
Ignore colour changes from strings.
Definition: gfx_type.h:278
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1141
_standard_cargo_mask
CargoTypes _standard_cargo_mask
Bitmask of real cargo types available.
Definition: cargotype.cpp:36
RailVehicleInfo::pow_wag_power
uint16_t pow_wag_power
Extra power applied to consist if wagon should be powered.
Definition: engine_type.h:56
INVALID_ENGINE
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
Definition: engine_type.h:205
BuildVehicleWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: build_vehicle_gui.cpp:1804
RoadTypeInfo
Definition: road.h:78
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:485
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:3200
EngineNumberSorter
static bool EngineNumberSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by engineID.
Definition: build_vehicle_gui.cpp:109
RailVehicleInfo::pow_wag_weight
byte pow_wag_weight
Extra weight applied to consist if wagon should be powered.
Definition: engine_type.h:57
Engine::IterateType
static Pool::IterateWrapperFiltered< Engine, EngineTypeFilter > IterateType(VehicleType vt, size_t from=0)
Returns an iterable ensemble of all valid engines of the given type.
Definition: engine_base.h:186
EngineDisplayFlags::HasVariants
@ HasVariants
Set if engine has variants.
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
TestedEngineDetails::mail_capacity
uint16_t mail_capacity
Mail capacity if available.
Definition: vehicle_gui.h:46
Rect::Height
int Height() const
Get height of Rect.
Definition: geometry_type.hpp:91
Pool::PoolItem<&_engine_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:335
vehicle_gui.h
BuildVehicleWindow::te
TestedEngineDetails te
Tested cost and capacity after refit.
Definition: build_vehicle_gui.cpp:1136
querystring_gui.h
HotkeyList
List of hotkeys for a window.
Definition: hotkeys.h:37
SetFocusedWindow
void SetFocusedWindow(Window *w)
Set the window that has the focus.
Definition: window.cpp:423
GUISettings::show_newgrf_name
bool show_newgrf_name
Show the name of the NewGRF in the build vehicle window.
Definition: settings_type.h:198
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
command_func.h
WID_BV_SORT_ASCENDING_DESCENDING
@ WID_BV_SORT_ASCENDING_DESCENDING
Sort direction.
Definition: build_vehicle_widget.h:16
IsInsideMM
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition: math_func.hpp:268
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
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:863
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:68
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:197
TestedEngineDetails::all_capacities
CargoArray all_capacities
Capacities for all cargoes.
Definition: vehicle_gui.h:47
dropdown_func.h
GetRailTypeInfo
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:307
GUIList::SetFilterState
void SetFilterState(bool state)
Enable or disable the filter.
Definition: sortlist_type.h:327
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
BuildVehicleWindow::vehicle_type
VehicleType vehicle_type
Type of vehicles shown in the window.
Definition: build_vehicle_gui.cpp:1121
StringFilter::IsEmpty
bool IsEmpty() const
Check whether any filter words were entered.
Definition: stringfilter_type.h:60
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:116
BuildVehicleWindow::cargo_filter_criteria
CargoID cargo_filter_criteria
Selected cargo filter.
Definition: build_vehicle_gui.cpp:1133
_sorted_cargo_specs
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
Definition: cargotype.cpp:161
StringFilter::SetFilterTerm
void SetFilterTerm(const char *str)
Set the term to filter on.
Definition: stringfilter.cpp:28
EngList_SortTypeFunction
bool EngList_SortTypeFunction(const GUIEngineListItem &, const GUIEngineListItem &)
argument type for EngList_Sort.
Definition: engine_gui.h:33
_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:99
timer_game_calendar.h
CargoArray::GetCount
uint GetCount() const
Get the amount of cargos that have an amount.
Definition: cargo_type.h:112
EngineDisplayFlags::IsFolded
@ IsFolded
Set if display of variants should be folded (hidden).
GetTotalCapacityOfArticulatedParts
uint GetTotalCapacityOfArticulatedParts(EngineID engine)
Get the capacity of an engine with articulated parts.
Definition: engine_gui.cpp:165
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
Station
Station data structure.
Definition: station_base.h:442
_engine_sort_direction
bool _engine_sort_direction
false = descending, true = ascending.
Definition: build_vehicle_gui.cpp:97
WID_BV_SCROLLBAR
@ WID_BV_SCROLLBAR
Scrollbar of list.
Definition: build_vehicle_widget.h:22
Engine::GetLifeLengthInDays
TimerGameCalendar::Date GetLifeLengthInDays() const
Returns the vehicle's (not model's!) life length in days.
Definition: engine.cpp:441
CargoFilterCriteria::CF_ENGINES
static constexpr CargoID CF_ENGINES
Show only engines (for rail vehicles only)
Definition: cargo_type.h:83
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
GUIList< GUIEngineListItem, std::nullptr_t, CargoID >
_network_server
bool _network_server
network-server is active
Definition: network.cpp:60
GetCapacityOfArticulatedParts
CargoArray GetCapacityOfArticulatedParts(EngineID engine)
Get the capacity of the parts of a given engine.
Definition: articulated_vehicles.cpp:141
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:1141
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:210
Engine::GetDisplayMaxTractiveEffort
uint GetDisplayMaxTractiveEffort() const
Returns the tractive effort of the engine for display purposes.
Definition: engine.cpp:424
NWidgetCore::widget_data
uint32_t widget_data
Data of the widget.
Definition: widget_type.h:379
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:67
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:234
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:134
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
EIT_PURCHASE
@ EIT_PURCHASE
Vehicle drawn in purchase list, autoreplace gui, ...
Definition: vehicle_type.h:90
StartTextRefStackUsage
void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32_t *values)
Start using the TTDP compatible string code parsing.
Definition: newgrf_text.cpp:798
CargoArray
Class for storing amounts of cargo.
Definition: cargo_type.h:97
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:61
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
Engine::GetRunningCost
Money GetRunningCost() const
Return how much the running costs of this engine are.
Definition: engine.cpp:279
AircraftRangeSorter
static bool AircraftRangeSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of aircraft by range.
Definition: build_vehicle_gui.cpp:423
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1151
group.h
RailTypeInfo
This struct contains all the info that is needed to draw and construct tracks.
Definition: rail.h:127
VehicleSettings::wagon_speed_limits
bool wagon_speed_limits
enable wagon speed limits
Definition: settings_type.h:522
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1174
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:37
EngineTractiveEffortSorter
static bool EngineTractiveEffortSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by tractive effort.
Definition: build_vehicle_gui.cpp:239
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
zoom_func.h
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:2334
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:585
TestedEngineDetails::cargo
CargoID cargo
Cargo type.
Definition: vehicle_gui.h:44
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
BuildVehicleWindow::FilterByText
bool FilterByText(const Engine *e)
Filter by name and NewGRF extra text.
Definition: build_vehicle_gui.cpp:1343
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:71
VehicleCellSize::extend_right
uint extend_right
Extend of the cell to the right.
Definition: vehicle_gui.h:86
WidgetDimensions::hsep_wide
int hsep_wide
Wide horizontal spacing.
Definition: window_gui.h:64
TimerGameEconomy::UsingWallclockUnits
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
Definition: timer_game_economy.cpp:97
GetGRFConfig
GRFConfig * GetGRFConfig(uint32_t grfid, uint32_t mask)
Retrieve a NewGRF from the current config by its grfid.
Definition: newgrf_config.cpp:716
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition: window_gui.h:310
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
StringFilter::AddLine
void AddLine(const char *str)
Pass another text line from the current item to the filter.
Definition: stringfilter.cpp:114
NWidgetCore::tool_tip
StringID tool_tip
Tooltip of the widget.
Definition: widget_type.h:380
StopTextRefStackUsage
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
Definition: newgrf_text.cpp:815
BuildVehicleWindow::descending_sort_order
bool descending_sort_order
Sort direction,.
Definition: build_vehicle_gui.cpp:1126
RoadVehEngineCapacitySorter
static bool RoadVehEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of road vehicles by capacity.
Definition: build_vehicle_gui.cpp:354
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:340
Engine
Definition: engine_base.h:37
BuildVehicleWindow::FilterEngineList
void FilterEngineList()
Filter the engine list against the currently selected cargo filter.
Definition: build_vehicle_gui.cpp:1325
NWidgetCore::SetLowered
void SetLowered(bool lowered)
Lower or raise the widget.
Definition: widget_type.h:414
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Generic
@ Generic
No specific context available.
Definition: engine_type.h:190
RailTypeInfo::strings
struct RailTypeInfo::@26 strings
Strings associated with the rail type.
GetRailType
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
Definition: rail_map.h:115
Engine::GetDefaultCargoType
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
Definition: engine_base.h:96
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:54
RoadVehicleInfo::roadtype
RoadType roadtype
Road type.
Definition: engine_type.h:128
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:678
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:315
Engine::GetGRFID
uint32_t GetGRFID() const
Retrieve the GRF ID of the NewGRF the engine is tied to.
Definition: engine.cpp:157
GetEnginePalette
PaletteID GetEnginePalette(EngineID engine_type, CompanyID company)
Get the colour map for an engine.
Definition: vehicle.cpp:2110
WID_BV_CAPTION
@ WID_BV_CAPTION
Caption of window.
Definition: build_vehicle_widget.h:15
WID_BV_FILTER
@ WID_BV_FILTER
Filter by name.
Definition: build_vehicle_widget.h:19
Rect::WithHeight
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Definition: geometry_type.hpp:211
GetVehicleImageCellSize
VehicleCellSize GetVehicleImageCellSize(VehicleType type, EngineImageType image_type)
Get the GUI cell size for a vehicle image.
Definition: depot_gui.cpp:161
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1038
_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:100
EngineIntroDateSorter
static bool EngineIntroDateSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by introduction date.
Definition: build_vehicle_gui.cpp:122
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition: road_type.h:30
BVHK_FOCUS_FILTER_BOX
@ BVHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
Definition: build_vehicle_gui.cpp:1116
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:387
Scrollbar::GetPosition
uint16_t GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:720
engine_cmd.h
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:20
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: palette.cpp:26
textbuf_gui.h
TestedEngineDetails::capacity
uint capacity
Cargo capacity.
Definition: vehicle_gui.h:45
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
train_cmd.h
QSF_LEN_IN_CHARS
@ QSF_LEN_IN_CHARS
the length of the string is counted in characters
Definition: textbuf_gui.h:22
CBID_VEHICLE_ADDITIONAL_TEXT
@ CBID_VEHICLE_ADDITIONAL_TEXT
This callback is called from vehicle purchase lists.
Definition: newgrf_callbacks.h:93
MAX_CHAR_LENGTH
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
Definition: strings_type.h:18
CcBuildWagon
void CcBuildWagon(Commands cmd, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray, TileIndex tile, EngineID, bool, CargoID, ClientID)
Callback for building wagons.
Definition: train_gui.cpp:29
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:242
BuildVehicleWindow::show_hidden_engines
bool show_hidden_engines
State of the 'show hidden engines' button.
Definition: build_vehicle_gui.cpp:1128
WindowDesc
High level window description.
Definition: window_gui.h:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
EnginePowerVsRunningCostSorter
static bool EnginePowerVsRunningCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by running costs.
Definition: build_vehicle_gui.cpp:273
VehicleSettings::train_acceleration_model
uint8_t train_acceleration_model
realistic acceleration for trains
Definition: settings_type.h:518
Engine::display_last_variant
EngineID display_last_variant
NOSAVE client-side-only last variant selected.
Definition: engine_base.h:59
Engine::GetDisplayMaxSpeed
uint GetDisplayMaxSpeed() const
Returns max speed of the engine for display purposes.
Definition: engine.cpp:356
WID_BV_SORT_DROPDOWN
@ WID_BV_SORT_DROPDOWN
Criteria of sorting dropdown.
Definition: build_vehicle_widget.h:17
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:1188
_sorted_standard_cargo_specs
std::span< const CargoSpec * > _sorted_standard_cargo_specs
Standard cargo specifications sorted alphabetically by name.
Definition: cargotype.cpp:162
RailVehicleInfo
Information about a rail vehicle.
Definition: engine_type.h:42
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1086
_engine_sort_listing
const StringID _engine_sort_listing[][12]
Dropdown menu strings for the vehicle sort criteria.
Definition: build_vehicle_gui.cpp:486
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
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:141
RailType
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
WID_BV_LIST
@ WID_BV_LIST
List of vehicles.
Definition: build_vehicle_widget.h:21
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:308
WidgetDimensions::matrix
RectPadding matrix
Padding of WWT_MATRIX items.
Definition: window_gui.h:44
GetUnionOfArticulatedRefitMasks
CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ors the refit_masks of all articulated parts.
Definition: articulated_vehicles.cpp:251
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:147
newgrf_engine.h
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
EngineCostSorter
static bool EngineCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by purchase cost.
Definition: build_vehicle_gui.cpp:188
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1244
GUIList::Filter
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
Definition: sortlist_type.h:343
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:73
WID_BV_PANEL
@ WID_BV_PANEL
Button panel.
Definition: build_vehicle_widget.h:23
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:1129
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:198
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:941
Engine::intro_date
TimerGameCalendar::Date intro_date
Date of introduction of the engine.
Definition: engine_base.h:39
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition: gfx_type.h:204
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:740
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:110
CargoFilterCriteria::CF_NONE
static constexpr CargoID CF_NONE
Show only items which do not carry cargo (e.g. train engines)
Definition: cargo_type.h:82
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:203
CcBuildPrimaryVehicle
void CcBuildPrimaryVehicle(Commands, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray)
This is the Callback method after the construction attempt of a primary vehicle.
Definition: vehicle_gui.cpp:3461
Engine::display_flags
EngineDisplayFlags display_flags
NOSAVE client-side-only display flags for build engine list.
Definition: engine_base.h:58
WC_REPLACE_VEHICLE
@ WC_REPLACE_VEHICLE
Replace vehicle window; Window numbers:
Definition: window_type.h:218
TimerGame< struct Calendar >::DateToYear
static constexpr Year DateToYear(Date date)
Calculate the year of a given date.
Definition: timer_game_common.h:77
EngineDisplayFlags::Shaded
@ Shaded
Set if engine should be masked.
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
IsCompanyBuildableVehicleType
bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
Definition: vehicle_func.h:89
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:953
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_type.h:350
Engine::GetDisplayWeight
uint GetDisplayWeight() const
Returns the weight of the engine for display purposes.
Definition: engine.cpp:406
EngineDisplayFlags::None
@ None
No flag set.
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:322
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1258
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:49
ShipEngineCapacitySorter
static bool ShipEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of ships by capacity.
Definition: build_vehicle_gui.cpp:373
TimerGameCalendar::ConvertDateToYMD
static YearMonthDay ConvertDateToYMD(Date date)
Converts a Date to a Year, Month & Day.
Definition: timer_game_calendar.cpp:42
safeguards.h
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:802
ShowQueryString
void ShowQueryString(StringID 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:1083
BuildVehicleWindow::rename_engine
EngineID rename_engine
Engine being renamed.
Definition: build_vehicle_gui.cpp:1131
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:294
vehicle_cmd.h
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:198
AutoreplaceVehicleInUse
@ AutoreplaceVehicleInUse
Name is show in the autoreplace window 'Vehicles in use' panel.
Definition: engine_type.h:194
DEFAULT_GROUP
static const GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
Definition: group_type.h:17
TestedEngineDetails
Extra information about refitted cargo and capacity.
Definition: vehicle_gui.h:42
TC_NO_SHADE
@ TC_NO_SHADE
Do not add shading to this text colour.
Definition: gfx_type.h:277
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:185
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:59
GetTileOwner
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition: tile_map.h:178
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:1007
newgrf_text.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
BuildVehicleWindow::details_height
int details_height
Minimal needed height of the details panels, in text lines (found so far).
Definition: build_vehicle_gui.cpp:1134
build_vehicle_widget.h
WID_BV_SHOW_HIDDEN_ENGINES
@ WID_BV_SHOW_HIDDEN_ENGINES
Toggle whether to display the hidden vehicles.
Definition: build_vehicle_widget.h:20
Scrollbar::GetScrolledItemFromWidget
Tcontainer::iterator 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:845
ShowDropDownMenu
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
Definition: dropdown.cpp:386
GetGRFStringID
StringID GetGRFStringID(uint32_t grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
Definition: newgrf_text.cpp:587
Engine::GetCost
Money GetCost() const
Return how much a new engine costs.
Definition: engine.cpp:316
BuildVehicleWindow::sort_criteria
byte sort_criteria
Current sort criterium.
Definition: build_vehicle_gui.cpp:1127
stdafx.h
_engine_sort_last_criteria
byte _engine_sort_last_criteria[]
Last set sort criteria, for each vehicle type.
Definition: build_vehicle_gui.cpp:98
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:296
Window::SetFocusedWidget
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
Definition: window.cpp:487
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
WID_BV_BUILD
@ WID_BV_BUILD
Build panel.
Definition: build_vehicle_widget.h:24
BuildVehicleWindow::FilterSingleEngine
bool FilterSingleEngine(EngineID eid)
Filter a single engine.
Definition: build_vehicle_gui.cpp:1336
Engine::reliability
uint16_t reliability
Current reliability of the engine.
Definition: engine_base.h:41
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:3140
IsArticulatedVehicleRefittable
bool IsArticulatedVehicleRefittable(EngineID engine)
Checks whether any of the articulated parts is refittable.
Definition: articulated_vehicles.cpp:199
CS_ALPHANUMERAL
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition: string_type.h:25
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
BuildVehicleWindow::string_filter
StringFilter string_filter
Filter for vehicle name.
Definition: build_vehicle_gui.cpp:1138
Window::SetWidgetLoweredState
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:441
RAILVEH_WAGON
@ RAILVEH_WAGON
simple wagon, not motorized
Definition: engine_type.h:29
BuildVehicleWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: build_vehicle_gui.cpp:1693
GUIEngineListItem::engine_id
EngineID engine_id
Engine to display in build purchase list.
Definition: engine_gui.h:20
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
EngList_Sort
void EngList_Sort(GUIEngineList &el, EngList_SortTypeFunction compare)
Sort all items using quick sort and given 'CompareItems' function.
Definition: engine_gui.cpp:333
GetRoadTypeInfo
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:227
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:381
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:941
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:70
VehicleSettings::roadveh_acceleration_model
uint8_t roadveh_acceleration_model
realistic acceleration for road vehicles
Definition: settings_type.h:519
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:395
string_func.h
EngineReliabilitySorter
static bool EngineReliabilitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by reliability.
Definition: build_vehicle_gui.cpp:171
ToPercent16
constexpr uint ToPercent16(uint i)
Converts a "fract" value 0..65535 to "percent" value 0..100.
Definition: math_func.hpp:306
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition: newgrf_callbacks.h:420
_engine_sort_last_cargo_criteria
static CargoID _engine_sort_last_cargo_criteria[]
Last set filter criteria, for each vehicle type.
Definition: build_vehicle_gui.cpp:101
Window::querystrings
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:314
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:214
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition: querystring_gui.h:28
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:775
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:50
Window::DrawSortButtonState
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition: widget.cpp:763
vehicle_func.h
TrainEnginesThenWagonsSorter
static bool TrainEnginesThenWagonsSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of train engines by engine / wagon.
Definition: build_vehicle_gui.cpp:335
EnginePowerSorter
static bool EnginePowerSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by power.
Definition: build_vehicle_gui.cpp:222
station_base.h
PALETTE_CRASH
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition: sprites.h:1602
engine_gui.h
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1724
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:349
TrainEngineCapacitySorter
static bool TrainEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of train engines by capacity.
Definition: build_vehicle_gui.cpp:315
EngineRunningCostSorter
static bool EngineRunningCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by running costs.
Definition: build_vehicle_gui.cpp:256
Engine::IsHidden
bool IsHidden(CompanyID c) const
Check whether the engine is hidden in the GUI for the given company.
Definition: engine_base.h:136
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:556
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:73
EngineDisplayFlags
EngineDisplayFlags
Flags used client-side in the purchase/autorenew engine list.
Definition: engine_base.h:26
CargoAndEngineFilter
static bool CDECL CargoAndEngineFilter(const GUIEngineListItem *item, const CargoID cid)
Filters vehicles by cargo and engine (in case of rail vehicle).
Definition: build_vehicle_gui.cpp:540
WC_BUILD_VEHICLE
@ WC_BUILD_VEHICLE
Build vehicle; Window numbers:
Definition: window_type.h:383
WidgetDimensions::hsep_indent
int hsep_indent
Width of identation for tree layouts.
Definition: window_gui.h:65
Engine::GetPower
uint GetPower() const
Returns the power of the engine for display and sorting purposes.
Definition: engine.cpp:388
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
geometry_func.hpp
BuildVehicleWindow::roadtype
RoadType roadtype
Road type to show, or INVALID_ROADTYPE.
Definition: build_vehicle_gui.cpp:1124
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:3217
BuildVehicleWindow
GUI for building vehicles.
Definition: build_vehicle_gui.cpp:1120
RAILVEH_MULTIHEAD
@ RAILVEH_MULTIHEAD
indicates a combination of two locomotives
Definition: engine_type.h:28
StringFilter::ResetState
void ResetState()
Reset the matching state to process a new item.
Definition: stringfilter.cpp:98
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
EngineInfo::variant_id
EngineID variant_id
Engine variant ID. If set, will be treated specially in purchase lists.
Definition: engine_type.h:159
ScaleSpriteTrad
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition: zoom_func.h:107
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:760
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
Definition: strings.cpp:327
SpecializedStation< Station, false >::GetByTile
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
Definition: base_station_base.h:278
EventState
EventState
State of handling an event.
Definition: window_type.h:738
cargotype.h
StringFilter::GetState
bool GetState() const
Get the matching state of the current item.
Definition: stringfilter_type.h:71
WID_BV_BUILD_SEL
@ WID_BV_BUILD_SEL
Build button.
Definition: build_vehicle_widget.h:26
TestedEngineDetails::cost
Money cost
Refit cost.
Definition: vehicle_gui.h:43
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:346
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:25
CargoSpec::name
StringID name
Name of this type of cargo.
Definition: cargotype.h:88
RailVehicleInfo::railtype
RailType railtype
Railtype, mangled if elrail is disabled.
Definition: engine_type.h:46
PackVelocity
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
Definition: strings_func.h:74
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1734
BuildVehicleHotkeys
BuildVehicleHotkeys
Enum referring to the Hotkeys in the build vehicle window.
Definition: build_vehicle_gui.cpp:1115
GroupID
uint16_t GroupID
Type for all group identifiers.
Definition: group_type.h:13
INVALID_CLIENT_ID
@ INVALID_CLIENT_ID
Client is not part of anything.
Definition: network_type.h:50
BuildVehicleWindow::railtype
RailType railtype
Rail type to show, or INVALID_RAILTYPE.
Definition: build_vehicle_gui.cpp:1123
RoadTypeInfo::strings
struct RoadTypeInfo::@29 strings
Strings associated with the rail type.
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:797
company_func.h
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:1296
BuildVehicleWindow::sel_engine
EngineID sel_engine
Currently selected engine, or INVALID_ENGINE.
Definition: build_vehicle_gui.cpp:1130
WidgetDimensions::fullbevel
RectPadding fullbevel
Always-scaled bevel thickness.
Definition: window_gui.h:41
QueryString::ACTION_CLEAR
static const int ACTION_CLEAR
Clear editbox.
Definition: querystring_gui.h:24
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:499
BuildVehicleWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: build_vehicle_gui.cpp:1319
network.h
CommandHelper
Definition: command_func.h:93
GUIList::SetFilterFuncs
void SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
Definition: sortlist_type.h:366
window_func.h
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition: gfx_type.h:348
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:305
stringfilter_type.h
BuildVehicleWindow::OnHotkey
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition: build_vehicle_gui.cpp:1878
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1097
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:780
BuildVehicleWindow::vehicle_editbox
QueryString vehicle_editbox
Filter editbox.
Definition: build_vehicle_gui.cpp:1139
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:405
GUIList< GUIEngineListItem, std::nullptr_t, CargoID >::FilterFunction
bool CDECL FilterFunction(const GUIEngineListItem *, CargoID)
Signature of filter function.
Definition: sortlist_type.h:50
AircraftEngineCargoSorter
static bool AircraftEngineCargoSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of aircraft by cargo.
Definition: build_vehicle_gui.cpp:395
OverflowSafeInt< int64_t >
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
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:658
engine_base.h
BuildVehicleWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: build_vehicle_gui.cpp:1865
IsValidCargoID
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
Definition: cargo_type.h:90
EngineNameSorter
static bool EngineNameSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by name.
Definition: build_vehicle_gui.cpp:142
BuildVehicleWindow::UpdateFilterByTile
void UpdateFilterByTile()
Set the filter type according to the depot type.
Definition: build_vehicle_gui.cpp:1239
articulated_vehicles.h
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition: settings_type.h:627
EngineID
uint16_t EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
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:888
WID_BV_CARGO_FILTER_DROPDOWN
@ WID_BV_CARGO_FILTER_DROPDOWN
Cargo filter dropdown.
Definition: build_vehicle_widget.h:18
Window
Data structure for an opened window.
Definition: window_gui.h:267
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:731
EngineSpeedSorter
static bool EngineSpeedSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by speed.
Definition: build_vehicle_gui.cpp:205
DC_QUERY_COST
@ DC_QUERY_COST
query cost only, don't build.
Definition: command_type.h:373
GetDropDownListDimension
Dimension GetDropDownListDimension(const DropDownList &list)
Determine width and height required to fully display a DropDownList.
Definition: dropdown.cpp:310
NUM_CARGO
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
Definition: cargo_type.h:68
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:335
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1162
autoreplace_func.h
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:215
CanVehicleUseStation
bool CanVehicleUseStation(EngineID engine_type, const Station *st)
Can this station be used by the given engine type?
Definition: vehicle.cpp:2980
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:82
GetVehicleCallback
uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Definition: newgrf_engine.cpp:1149
GetScaledSpriteSize
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
Definition: widget.cpp:54
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:356
WID_BV_RENAME
@ WID_BV_RENAME
Rename button.
Definition: build_vehicle_widget.h:27
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
RailTypeInfo::build_caption
StringID build_caption
Caption of the build vehicle GUI for this rail type.
Definition: rail.h:179
RailTypeInfo::acceleration_type
uint8_t acceleration_type
Acceleration type of this rail type.
Definition: rail.h:226
Window::SetWidgetsDisabledState
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition: window_gui.h:515
RoadTypeInfo::build_caption
StringID build_caption
Caption of the build vehicle GUI for this rail type.
Definition: road.h:106
QSF_ENABLE_DEFAULT
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
Definition: textbuf_gui.h:21
ShipVehicleInfo::ApplyWaterClassSpeedFrac
uint ApplyWaterClassSpeedFrac(uint raw_speed, bool is_ocean) const
Apply ocean/canal speed fraction to a velocity.
Definition: engine_type.h:81
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:916
IsEngineBuildable
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
Check if an engine is buildable.
Definition: engine.cpp:1216
GetEngineListHeight
uint GetEngineListHeight(VehicleType type)
Get the height of a single 'entry' in the engine lists.
Definition: build_vehicle_gui.cpp:52
Engine::GetAircraftTypeText
StringID GetAircraftTypeText() const
Get the name of the aircraft type for display purposes.
Definition: engine.cpp:465
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
SetTextStyle
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
Definition: widget_type.h:1120
DrawEngineList
void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, uint16_t min, uint16_t max, EngineID selected_id, bool show_count, GroupID selected_group)
Engine drawing loop.
Definition: build_vehicle_gui.cpp:1003
GetLargestCargoIconSize
Dimension GetLargestCargoIconSize()
Get dimensions of largest cargo icon.
Definition: cargotype.cpp:79
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:852
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:303
StringFilter
String filter and state.
Definition: stringfilter_type.h:30
VehicleCellSize::extend_left
uint extend_left
Extend of the cell to the left.
Definition: vehicle_gui.h:85
CargoFilterCriteria::CF_ANY
static constexpr CargoID CF_ANY
Show all items independent of carried cargo (i.e. no filtering)
Definition: cargo_type.h:81
BuildVehicleWindow::filter
union BuildVehicleWindow::@0 filter
Filter to apply.
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:57
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
GRFFile
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:107
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:636
Engine::type
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
Definition: engine_base.h:56
Engine::GetRange
uint16_t GetRange() const
Get the range of an aircraft type.
Definition: engine.cpp:451
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:72
BuildVehicleWindow::SetCargoFilterArray
void SetCargoFilterArray()
Populate the filter list and set the cargo filter criteria.
Definition: build_vehicle_gui.cpp:1279
GRFConfig::GetName
const char * GetName() const
Get the name of this grf.
Definition: newgrf_config.cpp:98
PurchaseList
@ PurchaseList
Name is shown in the purchase list (including autoreplace window 'Available vehicles' panel).
Definition: engine_type.h:192
GUIEngineListItem
Definition: engine_gui.h:19
engine_func.h
Hotkey
All data for a single hotkey.
Definition: hotkeys.h:21
hotkeys.h
INVALID_RAILTYPE
@ INVALID_RAILTYPE
Flag for invalid railtype.
Definition: rail_type.h:34
WID_BV_SHOW_HIDE
@ WID_BV_SHOW_HIDE
Button to hide or show the selected engine.
Definition: build_vehicle_widget.h:25
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:66
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103