OpenTTD Source: src/build_vehicle_gui.cpp Source File

OpenTTD Source 13.2.1

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"
26 #include "date_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
38 #include "widgets/build_vehicle_widget.h"
39
40 #include "table/strings.h"
41
42 #include "safeguards.h"
43
49 uint GetEngineListHeight(VehicleType type)
50 {
51 return std::max<uint>(FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.matrix.Vertical(), GetVehicleImageCellSize(type, EIT_PURCHASE).height);
52 }
53
54 static const NWidgetPart _nested_build_vehicle_widgets[] = {
55 NWidget(NWID_HORIZONTAL),
56 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
57 NWidget(WWT_CAPTION, COLOUR_GREY, WID_BV_CAPTION), SetDataTip(STR_WHITE_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
58 NWidget(WWT_SHADEBOX, COLOUR_GREY),
59 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
60 NWidget(WWT_STICKYBOX, COLOUR_GREY),
61 EndContainer(),
62 NWidget(WWT_PANEL, COLOUR_GREY),
63 NWidget(NWID_VERTICAL),
64 NWidget(NWID_HORIZONTAL),
65 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_SORT_ASCENDING_DESCENDING), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
66 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
67 EndContainer(),
68 NWidget(NWID_HORIZONTAL),
69 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BV_SHOW_HIDDEN_ENGINES),
70 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_CARGO_FILTER_DROPDOWN), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_FILTER_CRITERIA),
71 EndContainer(),
72 EndContainer(),
73 EndContainer(),
74 /* Vehicle list. */
75 NWidget(NWID_HORIZONTAL),
76 NWidget(WWT_MATRIX, COLOUR_GREY, WID_BV_LIST), SetResize(1, 1), SetFill(1, 0), SetMatrixDataTip(1, 0, STR_NULL), SetScrollbar(WID_BV_SCROLLBAR),
77 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_BV_SCROLLBAR),
78 EndContainer(),
79 /* Panel with details. */
80 NWidget(WWT_PANEL, COLOUR_GREY, WID_BV_PANEL), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
81 /* Build/rename buttons, resize button. */
82 NWidget(NWID_HORIZONTAL),
83 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_BV_BUILD_SEL),
84 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_BUILD), SetResize(1, 0), SetFill(1, 0),
85 EndContainer(),
86 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_SHOW_HIDE), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_NULL),
87 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_RENAME), SetResize(1, 0), SetFill(1, 0),
88 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
89 EndContainer(),
90 };
91
93 static const CargoID CF_ANY = CT_NO_REFIT;
94 static const CargoID CF_NONE = CT_INVALID;
95 static const CargoID CF_ENGINES = CT_AUTO_REFIT;
96
97 bool _engine_sort_direction;
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};
101 static CargoID _engine_sort_last_cargo_criteria[] = {CF_ANY, CF_ANY, CF_ANY, CF_ANY};
102
109 static bool EngineNumberSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
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
122 static bool EngineIntroDateSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
123 {
124 const int va = Engine::Get(a.engine_id)->intro_date;
125 const int vb = Engine::Get(b.engine_id)->intro_date;
126 const int 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 char last_name[2][64] = { "", "" };
145
146 if (a.engine_id != _last_engine[0]) {
147 _last_engine[0] = a.engine_id;
148 SetDParam(0, PackEngineNameDParam(a.engine_id, EngineNameContext::PurchaseList));
149
150 GetString(last_name[0], STR_ENGINE_NAME, lastof(last_name[0]));
151 }
152
153 if (b.engine_id != _last_engine[1]) {
154 _last_engine[1] = b.engine_id;
155 SetDParam(0, PackEngineNameDParam(b.engine_id, EngineNameContext::PurchaseList));
156 GetString(last_name[1], STR_ENGINE_NAME, lastof(last_name[1]));
157 }
158
159 int r = strnatcmp(last_name[0], last_name[1]); // Sort by name (natural sorting).
160
161 /* Use EngineID to sort instead since we want consistent sorting */
162 if (r == 0) return EngineNumberSorter(a, b);
163 return _engine_sort_direction ? r > 0 : r < 0;
164 }
165
172 static bool EngineReliabilitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
173 {
174 const int va = Engine::Get(a.engine_id)->reliability;
175 const int vb = Engine::Get(b.engine_id)->reliability;
176 const int r = va - vb;
177
178 /* Use EngineID to sort instead since we want consistent sorting */
179 if (r == 0) return EngineNumberSorter(a, b);
180 return _engine_sort_direction ? r > 0 : r < 0;
181 }
182
189 static bool EngineCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
190 {
191 Money va = Engine::Get(a.engine_id)->GetCost();
192 Money vb = Engine::Get(b.engine_id)->GetCost();
193 int r = ClampToI32(va - vb);
194
195 /* Use EngineID to sort instead since we want consistent sorting */
196 if (r == 0) return EngineNumberSorter(a, b);
197 return _engine_sort_direction ? r > 0 : r < 0;
198 }
199
206 static bool EngineSpeedSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
207 {
208 int va = Engine::Get(a.engine_id)->GetDisplayMaxSpeed();
209 int vb = Engine::Get(b.engine_id)->GetDisplayMaxSpeed();
210 int r = va - vb;
211
212 /* Use EngineID to sort instead since we want consistent sorting */
213 if (r == 0) return EngineNumberSorter(a, b);
214 return _engine_sort_direction ? r > 0 : r < 0;
215 }
216
223 static bool EnginePowerSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
224 {
225 int va = Engine::Get(a.engine_id)->GetPower();
226 int vb = Engine::Get(b.engine_id)->GetPower();
227 int r = va - vb;
228
229 /* Use EngineID to sort instead since we want consistent sorting */
230 if (r == 0) return EngineNumberSorter(a, b);
231 return _engine_sort_direction ? r > 0 : r < 0;
232 }
233
240 static bool EngineTractiveEffortSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
241 {
242 int va = Engine::Get(a.engine_id)->GetDisplayMaxTractiveEffort();
243 int vb = Engine::Get(b.engine_id)->GetDisplayMaxTractiveEffort();
244 int r = va - vb;
245
246 /* Use EngineID to sort instead since we want consistent sorting */
247 if (r == 0) return EngineNumberSorter(a, b);
248 return _engine_sort_direction ? r > 0 : r < 0;
249 }
250
257 static bool EngineRunningCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
258 {
259 Money va = Engine::Get(a.engine_id)->GetRunningCost();
260 Money vb = Engine::Get(b.engine_id)->GetRunningCost();
261 int r = ClampToI32(va - vb);
262
263 /* Use EngineID to sort instead since we want consistent sorting */
264 if (r == 0) return EngineNumberSorter(a, b);
265 return _engine_sort_direction ? r > 0 : r < 0;
266 }
267
274 static bool EnginePowerVsRunningCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
275 {
276 const Engine *e_a = Engine::Get(a.engine_id);
277 const Engine *e_b = Engine::Get(b.engine_id);
278 uint p_a = e_a->GetPower();
279 uint p_b = e_b->GetPower();
280 Money r_a = e_a->GetRunningCost();
281 Money r_b = e_b->GetRunningCost();
282 /* Check if running cost is zero in one or both engines.
283 * If only one of them is zero then that one has higher value,
284 * else if both have zero cost then compare powers. */
285 if (r_a == 0) {
286 if (r_b == 0) {
287 /* If it is ambiguous which to return go with their ID */
288 if (p_a == p_b) return EngineNumberSorter(a, b);
289 return _engine_sort_direction != (p_a < p_b);
290 }
291 return !_engine_sort_direction;
292 }
293 if (r_b == 0) return _engine_sort_direction;
294 /* Using double for more precision when comparing close values.
295 * This shouldn't have any major effects in performance nor in keeping
296 * the game in sync between players since it's used in GUI only in client side */
297 double v_a = (double)p_a / (double)r_a;
298 double v_b = (double)p_b / (double)r_b;
299 /* Use EngineID to sort if both have same power/running cost,
300 * since we want consistent sorting.
301 * Also if both have no power then sort with reverse of running cost to simulate
302 * previous sorting behaviour for wagons. */
303 if (v_a == 0 && v_b == 0) return !EngineRunningCostSorter(a, b);
304 if (v_a == v_b) return EngineNumberSorter(a, b);
305 return _engine_sort_direction != (v_a < v_b);
306 }
307
308 /* Train sorting functions */
309
316 static bool TrainEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
317 {
318 const RailVehicleInfo *rvi_a = RailVehInfo(a.engine_id);
319 const RailVehicleInfo *rvi_b = RailVehInfo(b.engine_id);
320
321 int va = GetTotalCapacityOfArticulatedParts(a.engine_id) * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
322 int vb = GetTotalCapacityOfArticulatedParts(b.engine_id) * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
323 int r = va - vb;
324
325 /* Use EngineID to sort instead since we want consistent sorting */
326 if (r == 0) return EngineNumberSorter(a, b);
327 return _engine_sort_direction ? r > 0 : r < 0;
328 }
329
336 static bool TrainEnginesThenWagonsSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
337 {
338 int val_a = (RailVehInfo(a.engine_id)->railveh_type == RAILVEH_WAGON ? 1 : 0);
339 int val_b = (RailVehInfo(b.engine_id)->railveh_type == RAILVEH_WAGON ? 1 : 0);
340 int r = val_a - val_b;
341
342 /* Use EngineID to sort instead since we want consistent sorting */
343 if (r == 0) return EngineNumberSorter(a, b);
344 return _engine_sort_direction ? r > 0 : r < 0;
345 }
346
347 /* Road vehicle sorting functions */
348
355 static bool RoadVehEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
356 {
357 int va = GetTotalCapacityOfArticulatedParts(a.engine_id);
358 int vb = GetTotalCapacityOfArticulatedParts(b.engine_id);
359 int r = va - vb;
360
361 /* Use EngineID to sort instead since we want consistent sorting */
362 if (r == 0) return EngineNumberSorter(a, b);
363 return _engine_sort_direction ? r > 0 : r < 0;
364 }
365
366 /* Ship vehicle sorting functions */
367
374 static bool ShipEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
375 {
376 const Engine *e_a = Engine::Get(a.engine_id);
377 const Engine *e_b = Engine::Get(b.engine_id);
378
379 int va = e_a->GetDisplayDefaultCapacity();
380 int vb = e_b->GetDisplayDefaultCapacity();
381 int r = va - vb;
382
383 /* Use EngineID to sort instead since we want consistent sorting */
384 if (r == 0) return EngineNumberSorter(a, b);
385 return _engine_sort_direction ? r > 0 : r < 0;
386 }
387
388 /* Aircraft sorting functions */
389
396 static bool AircraftEngineCargoSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
397 {
398 const Engine *e_a = Engine::Get(a.engine_id);
399 const Engine *e_b = Engine::Get(b.engine_id);
400
401 uint16 mail_a, mail_b;
402 int va = e_a->GetDisplayDefaultCapacity(&mail_a);
403 int vb = e_b->GetDisplayDefaultCapacity(&mail_b);
404 int r = va - vb;
405
406 if (r == 0) {
407 /* The planes have the same passenger capacity. Check mail capacity instead */
408 r = mail_a - mail_b;
409
410 if (r == 0) {
411 /* Use EngineID to sort instead since we want consistent sorting */
412 return EngineNumberSorter(a, b);
413 }
414 }
415 return _engine_sort_direction ? r > 0 : r < 0;
416 }
417
424 static bool AircraftRangeSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
425 {
426 uint16 r_a = Engine::Get(a.engine_id)->GetRange();
427 uint16 r_b = Engine::Get(b.engine_id)->GetRange();
428
429 int r = r_a - r_b;
430
431 /* Use EngineID to sort instead since we want consistent sorting */
432 if (r == 0) return EngineNumberSorter(a, b);
433 return _engine_sort_direction ? r > 0 : r < 0;
434 }
435
437 EngList_SortTypeFunction * const _engine_sort_functions[][11] = {{
438 /* Trains */
439 &EngineNumberSorter,
440 &EngineCostSorter,
441 &EngineSpeedSorter,
442 &EnginePowerSorter,
443 &EngineTractiveEffortSorter,
444 &EngineIntroDateSorter,
445 &EngineNameSorter,
446 &EngineRunningCostSorter,
447 &EnginePowerVsRunningCostSorter,
448 &EngineReliabilitySorter,
449 &TrainEngineCapacitySorter,
450 }, {
451 /* Road vehicles */
452 &EngineNumberSorter,
453 &EngineCostSorter,
454 &EngineSpeedSorter,
455 &EnginePowerSorter,
456 &EngineTractiveEffortSorter,
457 &EngineIntroDateSorter,
458 &EngineNameSorter,
459 &EngineRunningCostSorter,
460 &EnginePowerVsRunningCostSorter,
461 &EngineReliabilitySorter,
462 &RoadVehEngineCapacitySorter,
463 }, {
464 /* Ships */
465 &EngineNumberSorter,
466 &EngineCostSorter,
467 &EngineSpeedSorter,
468 &EngineIntroDateSorter,
469 &EngineNameSorter,
470 &EngineRunningCostSorter,
471 &EngineReliabilitySorter,
472 &ShipEngineCapacitySorter,
473 }, {
474 /* Aircraft */
475 &EngineNumberSorter,
476 &EngineCostSorter,
477 &EngineSpeedSorter,
478 &EngineIntroDateSorter,
479 &EngineNameSorter,
480 &EngineRunningCostSorter,
481 &EngineReliabilitySorter,
482 &AircraftEngineCargoSorter,
483 &AircraftRangeSorter,
484 }};
485
487 const StringID _engine_sort_listing[][12] = {{
488 /* Trains */
489 STR_SORT_BY_ENGINE_ID,
490 STR_SORT_BY_COST,
491 STR_SORT_BY_MAX_SPEED,
492 STR_SORT_BY_POWER,
493 STR_SORT_BY_TRACTIVE_EFFORT,
494 STR_SORT_BY_INTRO_DATE,
495 STR_SORT_BY_NAME,
496 STR_SORT_BY_RUNNING_COST,
497 STR_SORT_BY_POWER_VS_RUNNING_COST,
498 STR_SORT_BY_RELIABILITY,
499 STR_SORT_BY_CARGO_CAPACITY,
500 INVALID_STRING_ID
501 }, {
502 /* Road vehicles */
503 STR_SORT_BY_ENGINE_ID,
504 STR_SORT_BY_COST,
505 STR_SORT_BY_MAX_SPEED,
506 STR_SORT_BY_POWER,
507 STR_SORT_BY_TRACTIVE_EFFORT,
508 STR_SORT_BY_INTRO_DATE,
509 STR_SORT_BY_NAME,
510 STR_SORT_BY_RUNNING_COST,
511 STR_SORT_BY_POWER_VS_RUNNING_COST,
512 STR_SORT_BY_RELIABILITY,
513 STR_SORT_BY_CARGO_CAPACITY,
514 INVALID_STRING_ID
515 }, {
516 /* Ships */
517 STR_SORT_BY_ENGINE_ID,
518 STR_SORT_BY_COST,
519 STR_SORT_BY_MAX_SPEED,
520 STR_SORT_BY_INTRO_DATE,
521 STR_SORT_BY_NAME,
522 STR_SORT_BY_RUNNING_COST,
523 STR_SORT_BY_RELIABILITY,
524 STR_SORT_BY_CARGO_CAPACITY,
525 INVALID_STRING_ID
526 }, {
527 /* Aircraft */
528 STR_SORT_BY_ENGINE_ID,
529 STR_SORT_BY_COST,
530 STR_SORT_BY_MAX_SPEED,
531 STR_SORT_BY_INTRO_DATE,
532 STR_SORT_BY_NAME,
533 STR_SORT_BY_RUNNING_COST,
534 STR_SORT_BY_RELIABILITY,
535 STR_SORT_BY_CARGO_CAPACITY,
536 STR_SORT_BY_RANGE,
537 INVALID_STRING_ID
538 }};
539
541 static bool CDECL CargoAndEngineFilter(const GUIEngineListItem *item, const CargoID cid)
542 {
543 if (cid == CF_ANY) {
544 return true;
545 } else if (cid == CF_ENGINES) {
546 return Engine::Get(item->engine_id)->GetPower() != 0;
547 } else {
548 CargoTypes refit_mask = GetUnionOfArticulatedRefitMasks(item->engine_id, true) & _standard_cargo_mask;
549 return (cid == CF_NONE ? refit_mask == 0 : HasBit(refit_mask, cid));
550 }
551 }
552
553 static GUIEngineList::FilterFunction * const _filter_funcs[] = {
554 &CargoAndEngineFilter,
555 };
556
557 static uint GetCargoWeight(const CargoArray &cap, VehicleType vtype)
558 {
559 uint weight = 0;
560 for (CargoID c = 0; c < NUM_CARGO; c++) {
561 if (cap[c] != 0) {
562 if (vtype == VEH_TRAIN) {
563 weight += CargoSpec::Get(c)->WeightOfNUnitsInTrain(cap[c]);
564 } else {
565 weight += CargoSpec::Get(c)->WeightOfNUnits(cap[c]);
566 }
567 }
568 }
569 return weight;
570 }
571
572 static int DrawCargoCapacityInfo(int left, int right, int y, TestedEngineDetails &te, bool refittable)
573 {
574 for (CargoID c = 0; c < NUM_CARGO; c++) {
575 if (te.all_capacities[c] == 0) continue;
576
577 SetDParam(0, c);
578 SetDParam(1, te.all_capacities[c]);
579 SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
580 DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
581 y += FONT_HEIGHT_NORMAL;
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 }
601 y += FONT_HEIGHT_NORMAL;
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);
608 y += FONT_HEIGHT_NORMAL;
609
610 /* Wagon speed limit, displayed if above zero */
611 if (_settings_game.vehicle.wagon_speed_limits) {
612 uint max_speed = e->GetDisplayMaxSpeed();
613 if (max_speed > 0) {
614 SetDParam(0, max_speed);
615 DrawString(left, right, y, STR_PURCHASE_INFO_SPEED);
616 y += FONT_HEIGHT_NORMAL;
617 }
618 }
619
620 /* Running cost */
621 if (rvi->running_cost_class != INVALID_PRICE) {
622 SetDParam(0, e->GetRunningCost());
623 DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
624 y += FONT_HEIGHT_NORMAL;
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 }
646 y += FONT_HEIGHT_NORMAL;
647
648 /* Max speed - Engine power */
649 SetDParam(0, e->GetDisplayMaxSpeed());
650 SetDParam(1, e->GetPower());
651 DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_POWER);
652 y += FONT_HEIGHT_NORMAL;
653
654 /* Max tractive effort - not applicable if old acceleration or maglev */
655 if (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && GetRailTypeInfo(rvi->railtype)->acceleration_type != 2) {
656 SetDParam(0, e->GetDisplayMaxTractiveEffort());
657 DrawString(left, right, y, STR_PURCHASE_INFO_MAX_TE);
658 y += FONT_HEIGHT_NORMAL;
659 }
660
661 /* Running cost */
662 if (rvi->running_cost_class != INVALID_PRICE) {
663 SetDParam(0, e->GetRunningCost());
664 DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
665 y += FONT_HEIGHT_NORMAL;
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);
673 y += FONT_HEIGHT_NORMAL;
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
684 if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) {
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 }
694 y += FONT_HEIGHT_NORMAL;
695
696 /* Road vehicle weight - (including cargo) */
697 int16 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);
701 y += FONT_HEIGHT_NORMAL;
702
703 /* Max speed - Engine power */
704 SetDParam(0, e->GetDisplayMaxSpeed());
705 SetDParam(1, e->GetPower());
706 DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_POWER);
707 y += FONT_HEIGHT_NORMAL;
708
709 /* Max tractive effort */
710 SetDParam(0, e->GetDisplayMaxTractiveEffort());
711 DrawString(left, right, y, STR_PURCHASE_INFO_MAX_TE);
712 y += FONT_HEIGHT_NORMAL;
713 } else {
714 /* Purchase cost - Max speed */
715 if (te.cost != 0) {
716 SetDParam(0, e->GetCost() + te.cost);
717 SetDParam(1, te.cost);
718 SetDParam(2, e->GetDisplayMaxSpeed());
719 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
720 } else {
721 SetDParam(0, e->GetCost());
722 SetDParam(1, e->GetDisplayMaxSpeed());
723 DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
724 }
725 y += FONT_HEIGHT_NORMAL;
726 }
727
728 /* Running cost */
729 SetDParam(0, e->GetRunningCost());
730 DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
731 y += FONT_HEIGHT_NORMAL;
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, ocean_speed);
751 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
752 } else {
753 SetDParam(0, e->GetCost());
754 SetDParam(1, ocean_speed);
755 DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
756 }
757 y += FONT_HEIGHT_NORMAL;
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 }
767 y += FONT_HEIGHT_NORMAL;
768
769 SetDParam(0, ocean_speed);
770 DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_OCEAN);
771 y += FONT_HEIGHT_NORMAL;
772
773 SetDParam(0, canal_speed);
774 DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_CANAL);
775 y += FONT_HEIGHT_NORMAL;
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);
783 y += FONT_HEIGHT_NORMAL;
784
785 /* Running cost */
786 SetDParam(0, e->GetRunningCost());
787 DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
788 y += FONT_HEIGHT_NORMAL;
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);
810 SetDParam(2, e->GetDisplayMaxSpeed());
811 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
812 } else {
813 SetDParam(0, e->GetCost());
814 SetDParam(1, e->GetDisplayMaxSpeed());
815 DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
816 }
817 y += FONT_HEIGHT_NORMAL;
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 }
834 y += FONT_HEIGHT_NORMAL;
835
836 /* Running cost */
837 SetDParam(0, e->GetRunningCost());
838 DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
839 y += FONT_HEIGHT_NORMAL;
840
841 /* Aircraft type */
842 SetDParam(0, e->GetAircraftTypeText());
843 DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_TYPE);
844 y += FONT_HEIGHT_NORMAL;
845
846 /* Aircraft range, if available. */
847 uint16 range = e->GetRange();
848 if (range != 0) {
849 SetDParam(0, range);
850 DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_RANGE);
851 y += FONT_HEIGHT_NORMAL;
852 }
853
854 return y;
855 }
856
865 static uint ShowAdditionalText(int left, int right, int y, EngineID engine)
866 {
867 uint16 callback = GetVehicleCallback(CBID_VEHICLE_ADDITIONAL_TEXT, 0, 0, engine, nullptr);
868 if (callback == CALLBACK_FAILED || callback == 0x400) return y;
869 const GRFFile *grffile = Engine::Get(engine)->GetGRF();
870 if (callback > 0x400) {
871 ErrorUnknownCallbackResult(grffile->grfid, CBID_VEHICLE_ADDITIONAL_TEXT, callback);
872 return y;
873 }
874
875 StartTextRefStackUsage(grffile, 6);
876 uint result = DrawStringMultiLine(left, right, y, INT32_MAX, GetGRFStringID(grffile->grfid, 0xD000 + callback), TC_BLACK);
877 StopTextRefStackUsage();
878 return result;
879 }
880
881 void TestedEngineDetails::FillDefaultCapacities(const Engine *e)
882 {
883 this->cargo = e->GetDefaultCargoType();
884 if (e->type == VEH_TRAIN || e->type == VEH_ROAD) {
885 this->all_capacities = GetCapacityOfArticulatedParts(e->index);
886 this->capacity = this->all_capacities[this->cargo];
887 this->mail_capacity = 0;
888 } else {
889 this->capacity = e->GetDisplayDefaultCapacity(&this->mail_capacity);
890 this->all_capacities[this->cargo] = this->capacity;
891 this->all_capacities[CT_MAIL] = this->mail_capacity;
892 }
893 if (this->all_capacities.GetCount() == 0) this->cargo = CT_INVALID;
894 }
895
902 int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number, TestedEngineDetails &te)
903 {
904 const Engine *e = Engine::Get(engine_number);
905 YearMonthDay ymd;
906 ConvertDateToYMD(e->intro_date, &ymd);
907 bool refittable = IsArticulatedVehicleRefittable(engine_number);
908 bool articulated_cargo = false;
909
910 switch (e->type) {
911 default: NOT_REACHED();
912 case VEH_TRAIN:
913 if (e->u.rail.railveh_type == RAILVEH_WAGON) {
914 y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, &e->u.rail, te);
915 } else {
916 y = DrawRailEnginePurchaseInfo(left, right, y, engine_number, &e->u.rail, te);
917 }
918 articulated_cargo = true;
919 break;
920
921 case VEH_ROAD:
922 y = DrawRoadVehPurchaseInfo(left, right, y, engine_number, te);
923 articulated_cargo = true;
924 break;
925
926 case VEH_SHIP:
927 y = DrawShipPurchaseInfo(left, right, y, engine_number, refittable, te);
928 break;
929
930 case VEH_AIRCRAFT:
931 y = DrawAircraftPurchaseInfo(left, right, y, engine_number, refittable, te);
932 break;
933 }
934
935 if (articulated_cargo) {
936 /* Cargo type + capacity, or N/A */
937 int new_y = DrawCargoCapacityInfo(left, right, y, te, refittable);
938
939 if (new_y == y) {
940 SetDParam(0, CT_INVALID);
941 SetDParam(2, STR_EMPTY);
942 DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
943 y += FONT_HEIGHT_NORMAL;
944 } else {
945 y = new_y;
946 }
947 }
948
949 /* Draw details that apply to all types except rail wagons. */
950 if (e->type != VEH_TRAIN || e->u.rail.railveh_type != RAILVEH_WAGON) {
951 /* Design date - Life length */
952 SetDParam(0, ymd.year);
953 SetDParam(1, e->GetLifeLengthInDays() / DAYS_IN_LEAP_YEAR);
954 DrawString(left, right, y, STR_PURCHASE_INFO_DESIGNED_LIFE);
955 y += FONT_HEIGHT_NORMAL;
956
957 /* Reliability */
958 SetDParam(0, ToPercent16(e->reliability));
959 DrawString(left, right, y, STR_PURCHASE_INFO_RELIABILITY);
960 y += FONT_HEIGHT_NORMAL;
961 }
962
963 if (refittable) y = ShowRefitOptionsList(left, right, y, engine_number);
964
965 /* Additional text from NewGRF */
966 y = ShowAdditionalText(left, right, y, engine_number);
967
968 /* The NewGRF's name which the vehicle comes from */
969 const GRFConfig *config = GetGRFConfig(e->GetGRFID());
970 if (_settings_client.gui.show_newgrf_name && config != nullptr)
971 {
972 DrawString(left, right, y, config->GetName(), TC_BLACK);
973 y += FONT_HEIGHT_NORMAL;
974 }
975
976 return y;
977 }
978
990 void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group)
991 {
992 static const int sprite_y_offsets[] = { -1, -1, -2, -2 };
993
994 /* Obligatory sanity checks! */
995 assert(max <= eng_list.size());
996
997 bool rtl = _current_text_dir == TD_RTL;
998 int step_size = GetEngineListHeight(type);
999 int sprite_left = GetVehicleImageCellSize(type, EIT_PURCHASE).extend_left;
1000 int sprite_right = GetVehicleImageCellSize(type, EIT_PURCHASE).extend_right;
1001 int sprite_width = sprite_left + sprite_right;
1002 int circle_width = std::max(GetScaledSpriteSize(SPR_CIRCLE_FOLDED).width, GetScaledSpriteSize(SPR_CIRCLE_UNFOLDED).width);
1003 int linecolour = _colour_gradient[COLOUR_ORANGE][4];
1004
1005 Rect ir = r.WithHeight(step_size).Shrink(WidgetDimensions::scaled.matrix);
1006 int sprite_y_offset = ScaleSpriteTrad(sprite_y_offsets[type]) + ir.Height() / 2;
1007
1008 Dimension replace_icon = {0, 0};
1009 int count_width = 0;
1010 if (show_count) {
1011 replace_icon = GetSpriteSize(SPR_GROUP_REPLACE_ACTIVE);
1012 SetDParamMaxDigits(0, 3, FS_SMALL);
1013 count_width = GetStringBoundingBox(STR_TINY_BLACK_COMA).width;
1014 }
1015
1016 Rect tr = ir.Indent(circle_width + WidgetDimensions::scaled.hsep_normal + sprite_width + WidgetDimensions::scaled.hsep_wide, rtl); // Name position
1017 Rect cr = tr.Indent(replace_icon.width + WidgetDimensions::scaled.hsep_wide, !rtl).WithWidth(count_width, !rtl); // Count position
1018 Rect rr = tr.WithWidth(replace_icon.width, !rtl); // Replace icon position
1019 if (show_count) tr = tr.Indent(count_width + WidgetDimensions::scaled.hsep_normal + replace_icon.width + WidgetDimensions::scaled.hsep_wide, !rtl);
1020
1021 int normal_text_y_offset = (ir.Height() - FONT_HEIGHT_NORMAL) / 2;
1022 int small_text_y_offset = ir.Height() - FONT_HEIGHT_SMALL;
1023 int replace_icon_y_offset = (ir.Height() - replace_icon.height) / 2;
1024
1025 int y = ir.top;
1026 for (; min < max; min++, y += step_size) {
1027 const auto &item = eng_list[min];
1028 uint indent = item.indent * WidgetDimensions::scaled.hsep_indent;
1029 bool has_variants = (item.flags & EngineDisplayFlags::HasVariants) != EngineDisplayFlags::None;
1030 bool is_folded = (item.flags & EngineDisplayFlags::IsFolded) != EngineDisplayFlags::None;
1031 bool shaded = (item.flags & EngineDisplayFlags::Shaded) != EngineDisplayFlags::None;
1032 /* Note: num_engines is only used in the autoreplace GUI, so it is correct to use _local_company here. */
1033 const uint num_engines = GetGroupNumEngines(_local_company, selected_group, item.engine_id);
1034
1035 const Engine *e = Engine::Get(item.engine_id);
1036 bool hidden = HasBit(e->company_hidden, _local_company);
1037 StringID str = hidden ? STR_HIDDEN_ENGINE_NAME : STR_ENGINE_NAME;
1038 TextColour tc = (item.engine_id == selected_id) ? TC_WHITE : ((hidden | shaded) ? (TC_GREY | TC_FORCED | TC_NO_SHADE) : TC_BLACK);
1039
1040 SetDParam(0, PackEngineNameDParam(item.engine_id, EngineNameContext::PurchaseList, item.indent));
1041 Rect itr = tr.Indent(indent, rtl);
1042 DrawString(itr.left, itr.right, y + normal_text_y_offset, str, tc);
1043 int sprite_x = ir.Indent(indent + circle_width + WidgetDimensions::scaled.hsep_normal, rtl).WithWidth(sprite_width, rtl).left + sprite_left;
1044 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);
1045 if (show_count) {
1046 SetDParam(0, num_engines);
1047 DrawString(cr.left, cr.right, y + small_text_y_offset, STR_TINY_BLACK_COMA, TC_FROMSTRING, SA_RIGHT | SA_FORCE);
1048 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);
1049 }
1050 if (has_variants) {
1051 Rect fr = ir.Indent(indent, rtl).WithWidth(circle_width, rtl);
1052 DrawSpriteIgnorePadding(is_folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, {fr.left, y, fr.right, y + ir.Height() - 1}, false, SA_CENTER);
1053 }
1054 if (indent > 0) {
1055 /* Draw tree lines */
1056 Rect fr = ir.Indent(indent - WidgetDimensions::scaled.hsep_indent, rtl).WithWidth(circle_width, rtl);
1057 int ycenter = y + normal_text_y_offset + FONT_HEIGHT_NORMAL / 2;
1058 bool continues = (min + 1U) < eng_list.size() && eng_list[min + 1].indent == item.indent;
1059 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);
1060 GfxDrawLine(fr.left + circle_width / 2, ycenter, fr.right, ycenter, linecolour, WidgetDimensions::scaled.fullbevel.top);
1061 }
1062 }
1063 }
1064
1072 void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selected, int button)
1073 {
1074 uint32 hidden_mask = 0;
1075 /* Disable sorting by power or tractive effort when the original acceleration model for road vehicles is being used. */
1076 if (vehicle_type == VEH_ROAD && _settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) {
1077 SetBit(hidden_mask, 3); // power
1078 SetBit(hidden_mask, 4); // tractive effort
1079 SetBit(hidden_mask, 8); // power by running costs
1080 }
1081 /* Disable sorting by tractive effort when the original acceleration model for trains is being used. */
1082 if (vehicle_type == VEH_TRAIN && _settings_game.vehicle.train_acceleration_model == AM_ORIGINAL) {
1083 SetBit(hidden_mask, 4); // tractive effort
1084 }
1085 ShowDropDownMenu(w, _engine_sort_listing[vehicle_type], selected, button, 0, hidden_mask);
1086 }
1087
1089 struct BuildVehicleWindow : Window {
1090 VehicleType vehicle_type;
1091 union {
1092 RailType railtype;
1093 RoadType roadtype;
1094 } filter;
1095 bool descending_sort_order;
1096 byte sort_criteria;
1097 bool show_hidden_engines;
1098 bool listview_mode;
1099 EngineID sel_engine;
1100 EngineID rename_engine;
1101 GUIEngineList eng_list;
1102 CargoID cargo_filter[NUM_CARGO + 3];
1103 StringID cargo_filter_texts[NUM_CARGO + 4];
1104 byte cargo_filter_criteria;
1105 int details_height;
1106 Scrollbar *vscroll;
1107 TestedEngineDetails te;
1108
1109 void SetBuyVehicleText()
1110 {
1111 NWidgetCore *widget = this->GetWidget<NWidgetCore>(WID_BV_BUILD);
1112
1113 bool refit = this->sel_engine != INVALID_ENGINE && this->cargo_filter[this->cargo_filter_criteria] != CF_ANY && this->cargo_filter[this->cargo_filter_criteria] != CF_NONE;
1114 if (refit) refit = Engine::Get(this->sel_engine)->GetDefaultCargoType() != this->cargo_filter[this->cargo_filter_criteria];
1115
1116 if (refit) {
1117 widget->widget_data = STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_BUTTON + this->vehicle_type;
1118 widget->tool_tip = STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_TOOLTIP + this->vehicle_type;
1119 } else {
1120 widget->widget_data = STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + this->vehicle_type;
1121 widget->tool_tip = STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_TOOLTIP + this->vehicle_type;
1122 }
1123 }
1124
1125 void AddChildren(const GUIEngineList &source, EngineID parent, int indent)
1126 {
1127 for (const auto &item : source) {
1128 if (item.variant_id != parent || item.engine_id == parent) continue;
1129
1130 const Engine *e = Engine::Get(item.engine_id);
1131 EngineDisplayFlags flags = item.flags;
1132 if (e->display_last_variant != INVALID_ENGINE) flags &= ~EngineDisplayFlags::Shaded;
1133 this->eng_list.emplace_back(e->display_last_variant == INVALID_ENGINE ? item.engine_id : e->display_last_variant, item.engine_id, flags, indent);
1134
1135 /* Add variants if not folded */
1136 if ((item.flags & (EngineDisplayFlags::HasVariants | EngineDisplayFlags::IsFolded)) == EngineDisplayFlags::HasVariants) {
1137 /* Add this engine again as a child */
1138 if ((item.flags & EngineDisplayFlags::Shaded) == EngineDisplayFlags::None) {
1139 this->eng_list.emplace_back(item.engine_id, item.engine_id, EngineDisplayFlags::None, indent + 1);
1140 }
1141 AddChildren(source, item.engine_id, indent + 1);
1142 }
1143 }
1144 }
1145
1146 BuildVehicleWindow(WindowDesc *desc, TileIndex tile, VehicleType type) : Window(desc)
1147 {
1148 this->vehicle_type = type;
1149 this->listview_mode = tile == INVALID_TILE;
1150 this->window_number = this->listview_mode ? (int)type : (int)tile;
1151
1152 this->sel_engine = INVALID_ENGINE;
1153
1154 this->sort_criteria = _engine_sort_last_criteria[type];
1155 this->descending_sort_order = _engine_sort_last_order[type];
1156 this->show_hidden_engines = _engine_sort_show_hidden_engines[type];
1157
1158 this->UpdateFilterByTile();
1159
1160 this->CreateNestedTree();
1161
1162 this->vscroll = this->GetScrollbar(WID_BV_SCROLLBAR);
1163
1164 /* If we are just viewing the list of vehicles, we do not need the Build button.
1165 * So we just hide it, and enlarge the Rename button by the now vacant place. */
1166 if (this->listview_mode) this->GetWidget<NWidgetStacked>(WID_BV_BUILD_SEL)->SetDisplayedPlane(SZSP_NONE);
1167
1168 NWidgetCore *widget = this->GetWidget<NWidgetCore>(WID_BV_LIST);
1169 widget->tool_tip = STR_BUY_VEHICLE_TRAIN_LIST_TOOLTIP + type;
1170
1171 widget = this->GetWidget<NWidgetCore>(WID_BV_SHOW_HIDE);
1172 widget->tool_tip = STR_BUY_VEHICLE_TRAIN_HIDE_SHOW_TOGGLE_TOOLTIP + type;
1173
1174 widget = this->GetWidget<NWidgetCore>(WID_BV_RENAME);
1175 widget->widget_data = STR_BUY_VEHICLE_TRAIN_RENAME_BUTTON + type;
1176 widget->tool_tip = STR_BUY_VEHICLE_TRAIN_RENAME_TOOLTIP + type;
1177
1178 widget = this->GetWidget<NWidgetCore>(WID_BV_SHOW_HIDDEN_ENGINES);
1179 widget->widget_data = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + type;
1180 widget->tool_tip = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + type;
1181 widget->SetLowered(this->show_hidden_engines);
1182
1183 this->details_height = ((this->vehicle_type == VEH_TRAIN) ? 10 : 9);
1184
1185 this->FinishInitNested(tile == INVALID_TILE ? (int)type : (int)tile);
1186
1187 this->owner = (tile != INVALID_TILE) ? GetTileOwner(tile) : _local_company;
1188
1189 this->eng_list.ForceRebuild();
1190 this->GenerateBuildList(); // generate the list, since we need it in the next line
1191
1192 /* Select the first unshaded engine in the list as default when opening the window */
1193 EngineID engine = INVALID_ENGINE;
1194 auto it = std::find_if(this->eng_list.begin(), this->eng_list.end(), [&](GUIEngineListItem &item){ return (item.flags & EngineDisplayFlags::Shaded) == EngineDisplayFlags::None; });
1195 if (it != this->eng_list.end()) engine = it->engine_id;
1196 this->SelectEngine(engine);
1197 }
1198
1200 void UpdateFilterByTile()
1201 {
1202 switch (this->vehicle_type) {
1203 default: NOT_REACHED();
1204 case VEH_TRAIN:
1205 if (this->listview_mode) {
1206 this->filter.railtype = INVALID_RAILTYPE;
1207 } else {
1208 this->filter.railtype = GetRailType(this->window_number);
1209 }
1210 break;
1211
1212 case VEH_ROAD:
1213 if (this->listview_mode) {
1214 this->filter.roadtype = INVALID_ROADTYPE;
1215 } else {
1216 this->filter.roadtype = GetRoadTypeRoad(this->window_number);
1217 if (this->filter.roadtype == INVALID_ROADTYPE) {
1218 this->filter.roadtype = GetRoadTypeTram(this->window_number);
1219 }
1220 }
1221 break;
1222
1223 case VEH_SHIP:
1224 case VEH_AIRCRAFT:
1225 break;
1226 }
1227 }
1228
1230 void SetCargoFilterArray()
1231 {
1232 uint filter_items = 0;
1233
1234 /* Add item for disabling filtering. */
1235 this->cargo_filter[filter_items] = CF_ANY;
1236 this->cargo_filter_texts[filter_items] = STR_PURCHASE_INFO_ALL_TYPES;
1237 filter_items++;
1238
1239 /* Specific filters for trains. */
1240 if (this->vehicle_type == VEH_TRAIN) {
1241 /* Add item for locomotives only in case of trains. */
1242 this->cargo_filter[filter_items] = CF_ENGINES;
1243 this->cargo_filter_texts[filter_items] = STR_PURCHASE_INFO_ENGINES_ONLY;
1244 filter_items++;
1245
1246 /* Add item for vehicles not carrying anything, e.g. train engines.
1247 * This could also be useful for eyecandy vehicles of other types, but is likely too confusing for joe, */
1248 this->cargo_filter[filter_items] = CF_NONE;
1249 this->cargo_filter_texts[filter_items] = STR_PURCHASE_INFO_NONE;
1250 filter_items++;
1251 }
1252
1253 /* Collect available cargo types for filtering. */
1254 for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
1255 this->cargo_filter[filter_items] = cs->Index();
1256 this->cargo_filter_texts[filter_items] = cs->name;
1257 filter_items++;
1258 }
1259
1260 /* Terminate the filter list. */
1261 this->cargo_filter_texts[filter_items] = INVALID_STRING_ID;
1262
1263 /* If not found, the cargo criteria will be set to all cargoes. */
1264 this->cargo_filter_criteria = 0;
1265
1266 /* Find the last cargo filter criteria. */
1267 for (uint i = 0; i < filter_items; i++) {
1268 if (this->cargo_filter[i] == _engine_sort_last_cargo_criteria[this->vehicle_type]) {
1269 this->cargo_filter_criteria = i;
1270 break;
1271 }
1272 }
1273
1274 this->eng_list.SetFilterFuncs(_filter_funcs);
1275 this->eng_list.SetFilterState(this->cargo_filter[this->cargo_filter_criteria] != CF_ANY);
1276 }
1277
1278 void SelectEngine(EngineID engine)
1279 {
1280 CargoID cargo = this->cargo_filter[this->cargo_filter_criteria];
1281 if (cargo == CF_ANY) cargo = CF_NONE;
1282
1283 this->sel_engine = engine;
1284 this->SetBuyVehicleText();
1285
1286 if (this->sel_engine == INVALID_ENGINE) return;
1287
1288 const Engine *e = Engine::Get(this->sel_engine);
1289
1290 if (!this->listview_mode) {
1291 /* Query for cost and refitted capacity */
1292 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);
1293 if (ret.Succeeded()) {
1294 this->te.cost = ret.GetCost() - e->GetCost();
1295 this->te.capacity = refit_capacity;
1296 this->te.mail_capacity = refit_mail;
1297 this->te.cargo = (cargo == CT_INVALID) ? e->GetDefaultCargoType() : cargo;
1298 this->te.all_capacities = cargo_capacities;
1299 return;
1300 }
1301 }
1302
1303 /* Purchase test was not possible or failed, fill in the defaults instead. */
1304 this->te.cost = 0;
1305 this->te.FillDefaultCapacities(e);
1306 }
1307
1308 void OnInit() override
1309 {
1310 this->SetCargoFilterArray();
1311 }
1312
1314 void FilterEngineList()
1315 {
1316 this->eng_list.Filter(this->cargo_filter[this->cargo_filter_criteria]);
1317 if (0 == this->eng_list.size()) { // no engine passed through the filter, invalidate the previously selected engine
1318 this->SelectEngine(INVALID_ENGINE);
1319 } 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
1320 this->SelectEngine(this->eng_list[0].engine_id);
1321 }
1322 }
1323
1325 bool FilterSingleEngine(EngineID eid)
1326 {
1327 CargoID filter_type = this->cargo_filter[this->cargo_filter_criteria];
1328 GUIEngineListItem item = {eid, eid, EngineDisplayFlags::None, 0};
1329 return CargoAndEngineFilter(&item, filter_type);
1330 }
1331
1332 /* Figure out what train EngineIDs to put in the list */
1333 void GenerateBuildTrainList(GUIEngineList &list)
1334 {
1335 std::vector<EngineID> variants;
1336 EngineID sel_id = INVALID_ENGINE;
1337 size_t num_engines = 0;
1338
1339 list.clear();
1340
1341 /* Make list of all available train engines and wagons.
1342 * Also check to see if the previously selected engine is still available,
1343 * and if not, reset selection to INVALID_ENGINE. This could be the case
1344 * when engines become obsolete and are removed */
1345 for (const Engine *e : Engine::IterateType(VEH_TRAIN)) {
1346 if (!this->show_hidden_engines && e->IsHidden(_local_company)) continue;
1347 EngineID eid = e->index;
1348 const RailVehicleInfo *rvi = &e->u.rail;
1349
1350 if (this->filter.railtype != INVALID_RAILTYPE && !HasPowerOnRail(rvi->railtype, this->filter.railtype)) continue;
1351 if (!IsEngineBuildable(eid, VEH_TRAIN, _local_company)) continue;
1352
1353 /* Filter now! So num_engines and num_wagons is valid */
1354 if (!FilterSingleEngine(eid)) continue;
1355
1356 list.emplace_back(eid, e->info.variant_id, e->display_flags, 0);
1357
1358 if (rvi->railveh_type != RAILVEH_WAGON) num_engines++;
1359 if (e->info.variant_id != eid && e->info.variant_id != INVALID_ENGINE) variants.push_back(e->info.variant_id);
1360 if (eid == this->sel_engine) sel_id = eid;
1361 }
1362
1363 /* ensure primary engine of variant group is in list */
1364 for (const auto &variant : variants) {
1365 if (std::find(list.begin(), list.end(), variant) == list.end()) {
1366 const Engine *e = Engine::Get(variant);
1367 list.emplace_back(variant, e->info.variant_id, e->display_flags | EngineDisplayFlags::Shaded, 0);
1368 if (e->u.rail.railveh_type != RAILVEH_WAGON) num_engines++;
1369 }
1370 }
1371
1372 this->SelectEngine(sel_id);
1373
1374 /* invalidate cached values for name sorter - engine names could change */
1375 _last_engine[0] = _last_engine[1] = INVALID_ENGINE;
1376
1377 /* make engines first, and then wagons, sorted by selected sort_criteria */
1378 _engine_sort_direction = false;
1379 EngList_Sort(&list, TrainEnginesThenWagonsSorter);
1380
1381 /* and then sort engines */
1382 _engine_sort_direction = this->descending_sort_order;
1383 EngList_SortPartial(&list, _engine_sort_functions[0][this->sort_criteria], 0, num_engines);
1384
1385 /* and finally sort wagons */
1386 EngList_SortPartial(&list, _engine_sort_functions[0][this->sort_criteria], num_engines, list.size() - num_engines);
1387 }
1388
1389 /* Figure out what road vehicle EngineIDs to put in the list */
1390 void GenerateBuildRoadVehList()
1391 {
1392 EngineID sel_id = INVALID_ENGINE;
1393
1394 this->eng_list.clear();
1395
1396 for (const Engine *e : Engine::IterateType(VEH_ROAD)) {
1397 if (!this->show_hidden_engines && e->IsHidden(_local_company)) continue;
1398 EngineID eid = e->index;
1399 if (!IsEngineBuildable(eid, VEH_ROAD, _local_company)) continue;
1400 if (this->filter.roadtype != INVALID_ROADTYPE && !HasPowerOnRoad(e->u.road.roadtype, this->filter.roadtype)) continue;
1401
1402 this->eng_list.emplace_back(eid, e->info.variant_id, e->display_flags, 0);
1403
1404 if (eid == this->sel_engine) sel_id = eid;
1405 }
1406 this->SelectEngine(sel_id);
1407 }
1408
1409 /* Figure out what ship EngineIDs to put in the list */
1410 void GenerateBuildShipList()
1411 {
1412 EngineID sel_id = INVALID_ENGINE;
1413 this->eng_list.clear();
1414
1415 for (const Engine *e : Engine::IterateType(VEH_SHIP)) {
1416 if (!this->show_hidden_engines && e->IsHidden(_local_company)) continue;
1417 EngineID eid = e->index;
1418 if (!IsEngineBuildable(eid, VEH_SHIP, _local_company)) continue;
1419 this->eng_list.emplace_back(eid, e->info.variant_id, e->display_flags, 0);
1420
1421 if (eid == this->sel_engine) sel_id = eid;
1422 }
1423 this->SelectEngine(sel_id);
1424 }
1425
1426 /* Figure out what aircraft EngineIDs to put in the list */
1427 void GenerateBuildAircraftList()
1428 {
1429 EngineID sel_id = INVALID_ENGINE;
1430
1431 this->eng_list.clear();
1432
1433 const Station *st = this->listview_mode ? nullptr : Station::GetByTile(this->window_number);
1434
1435 /* Make list of all available planes.
1436 * Also check to see if the previously selected plane is still available,
1437 * and if not, reset selection to INVALID_ENGINE. This could be the case
1438 * when planes become obsolete and are removed */
1439 for (const Engine *e : Engine::IterateType(VEH_AIRCRAFT)) {
1440 if (!this->show_hidden_engines && e->IsHidden(_local_company)) continue;
1441 EngineID eid = e->index;
1442 if (!IsEngineBuildable(eid, VEH_AIRCRAFT, _local_company)) continue;
1443 /* First VEH_END window_numbers are fake to allow a window open for all different types at once */
1444 if (!this->listview_mode && !CanVehicleUseStation(eid, st)) continue;
1445
1446 this->eng_list.emplace_back(eid, e->info.variant_id, e->display_flags, 0);
1447 if (eid == this->sel_engine) sel_id = eid;
1448 }
1449
1450 this->SelectEngine(sel_id);
1451 }
1452
1453 /* Generate the list of vehicles */
1454 void GenerateBuildList()
1455 {
1456 if (!this->eng_list.NeedRebuild()) return;
1457
1458 /* Update filter type in case the road/railtype of the depot got converted */
1459 this->UpdateFilterByTile();
1460
1461 this->eng_list.clear();
1462
1463 GUIEngineList list;
1464
1465 switch (this->vehicle_type) {
1466 default: NOT_REACHED();
1467 case VEH_TRAIN:
1468 this->GenerateBuildTrainList(list);
1469 AddChildren(list, INVALID_ENGINE, 0);
1470 this->eng_list.shrink_to_fit();
1471 this->eng_list.RebuildDone();
1472 return;
1473 case VEH_ROAD:
1474 this->GenerateBuildRoadVehList();
1475 break;
1476 case VEH_SHIP:
1477 this->GenerateBuildShipList();
1478 break;
1479 case VEH_AIRCRAFT:
1480 this->GenerateBuildAircraftList();
1481 break;
1482 }
1483
1484 this->FilterEngineList();
1485
1486 /* ensure primary engine of variant group is in list after filtering */
1487 std::vector<EngineID> variants;
1488 for (const auto &item : this->eng_list) {
1489 if (item.engine_id != item.variant_id && item.variant_id != INVALID_ENGINE) variants.push_back(item.variant_id);
1490 }
1491 for (const auto &variant : variants) {
1492 if (std::find(this->eng_list.begin(), this->eng_list.end(), variant) == this->eng_list.end()) {
1493 const Engine *e = Engine::Get(variant);
1494 this->eng_list.emplace_back(variant, e->info.variant_id, e->display_flags | EngineDisplayFlags::Shaded, 0);
1495 }
1496 }
1497
1498 _engine_sort_direction = this->descending_sort_order;
1499 EngList_Sort(&this->eng_list, _engine_sort_functions[this->vehicle_type][this->sort_criteria]);
1500
1501 this->eng_list.swap(list);
1502 AddChildren(list, INVALID_ENGINE, 0);
1503 this->eng_list.shrink_to_fit();
1504 this->eng_list.RebuildDone();
1505 }
1506
1507 void OnClick(Point pt, int widget, int click_count) override
1508 {
1509 switch (widget) {
1510 case WID_BV_SORT_ASCENDING_DESCENDING:
1511 this->descending_sort_order ^= true;
1512 _engine_sort_last_order[this->vehicle_type] = this->descending_sort_order;
1513 this->eng_list.ForceRebuild();
1514 this->SetDirty();
1515 break;
1516
1517 case WID_BV_SHOW_HIDDEN_ENGINES:
1518 this->show_hidden_engines ^= true;
1519 _engine_sort_show_hidden_engines[this->vehicle_type] = this->show_hidden_engines;
1520 this->eng_list.ForceRebuild();
1521 this->SetWidgetLoweredState(widget, this->show_hidden_engines);
1522 this->SetDirty();
1523 break;
1524
1525 case WID_BV_LIST: {
1526 uint i = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_BV_LIST);
1527 size_t num_items = this->eng_list.size();
1528 EngineID e = INVALID_ENGINE;
1529 if (i < num_items) {
1530 const auto &item = this->eng_list[i];
1531 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);
1532 if ((item.flags & EngineDisplayFlags::HasVariants) != EngineDisplayFlags::None && IsInsideMM(r.left, r.right, pt.x)) {
1533 /* toggle folded flag on engine */
1534 assert(item.variant_id != INVALID_ENGINE);
1535 Engine *engine = Engine::Get(item.variant_id);
1536 engine->display_flags ^= EngineDisplayFlags::IsFolded;
1537
1538 InvalidateWindowData(WC_REPLACE_VEHICLE, this->vehicle_type, 0); // Update the autoreplace window
1539 InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well
1540 return;
1541 }
1542 if ((item.flags & EngineDisplayFlags::Shaded) == EngineDisplayFlags::None) e = item.engine_id;
1543 }
1544 this->SelectEngine(e);
1545 this->SetDirty();
1546 if (_ctrl_pressed) {
1547 this->OnClick(pt, WID_BV_SHOW_HIDE, 1);
1548 } else if (click_count > 1 && !this->listview_mode) {
1549 this->OnClick(pt, WID_BV_BUILD, 1);
1550 }
1551 break;
1552 }
1553
1554 case WID_BV_SORT_DROPDOWN: // Select sorting criteria dropdown menu
1555 DisplayVehicleSortDropDown(this, this->vehicle_type, this->sort_criteria, WID_BV_SORT_DROPDOWN);
1556 break;
1557
1558 case WID_BV_CARGO_FILTER_DROPDOWN: // Select cargo filtering criteria dropdown menu
1559 ShowDropDownMenu(this, this->cargo_filter_texts, this->cargo_filter_criteria, WID_BV_CARGO_FILTER_DROPDOWN, 0, 0);
1560 break;
1561
1562 case WID_BV_SHOW_HIDE: {
1563 const Engine *e = (this->sel_engine == INVALID_ENGINE) ? nullptr : Engine::Get(this->sel_engine);
1564 if (e != nullptr) {
1565 Command<CMD_SET_VEHICLE_VISIBILITY>::Post(this->sel_engine, !e->IsHidden(_current_company));
1566 }
1567 break;
1568 }
1569
1570 case WID_BV_BUILD: {
1571 EngineID sel_eng = this->sel_engine;
1572 if (sel_eng != INVALID_ENGINE) {
1573 CargoID cargo = this->cargo_filter[this->cargo_filter_criteria];
1574 if (cargo == CF_ANY || cargo == CF_ENGINES) cargo = CF_NONE;
1575 if (this->vehicle_type == VEH_TRAIN && RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) {
1576 Command<CMD_BUILD_VEHICLE>::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildWagon, this->window_number, sel_eng, true, cargo, INVALID_CLIENT_ID);
1577 } else {
1578 Command<CMD_BUILD_VEHICLE>::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildPrimaryVehicle, this->window_number, sel_eng, true, cargo, INVALID_CLIENT_ID);
1579 }
1580
1581 /* Update last used variant and refresh if necessary. */
1582 bool refresh = false;
1583 int recursion = 10; /* In case of infinite loop */
1584 for (Engine *e = Engine::Get(sel_eng); recursion > 0; e = Engine::Get(e->info.variant_id), --recursion) {
1585 refresh |= (e->display_last_variant != sel_eng);
1586 e->display_last_variant = sel_eng;
1587 if (e->info.variant_id == INVALID_ENGINE) break;
1588 }
1589 if (refresh) {
1590 InvalidateWindowData(WC_REPLACE_VEHICLE, this->vehicle_type, 0); // Update the autoreplace window
1591 InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well
1592 return;
1593 }
1594 }
1595 break;
1596 }
1597
1598 case WID_BV_RENAME: {
1599 EngineID sel_eng = this->sel_engine;
1600 if (sel_eng != INVALID_ENGINE) {
1601 this->rename_engine = sel_eng;
1602 SetDParam(0, PackEngineNameDParam(sel_eng, EngineNameContext::Generic));
1603 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);
1604 }
1605 break;
1606 }
1607 }
1608 }
1609
1615 void OnInvalidateData(int data = 0, bool gui_scope = true) override
1616 {
1617 if (!gui_scope) return;
1618 /* When switching to original acceleration model for road vehicles, clear the selected sort criteria if it is not available now. */
1619 if (this->vehicle_type == VEH_ROAD &&
1620 _settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL &&
1621 this->sort_criteria > 7) {
1622 this->sort_criteria = 0;
1623 _engine_sort_last_criteria[VEH_ROAD] = 0;
1624 }
1625 this->eng_list.ForceRebuild();
1626 }
1627
1628 void SetStringParameters(int widget) const override
1629 {
1630 switch (widget) {
1631 case WID_BV_CAPTION:
1632 if (this->vehicle_type == VEH_TRAIN && !this->listview_mode) {
1633 const RailtypeInfo *rti = GetRailTypeInfo(this->filter.railtype);
1634 SetDParam(0, rti->strings.build_caption);
1635 } else if (this->vehicle_type == VEH_ROAD && !this->listview_mode) {
1636 const RoadTypeInfo *rti = GetRoadTypeInfo(this->filter.roadtype);
1637 SetDParam(0, rti->strings.build_caption);
1638 } else {
1639 SetDParam(0, (this->listview_mode ? STR_VEHICLE_LIST_AVAILABLE_TRAINS : STR_BUY_VEHICLE_TRAIN_ALL_CAPTION) + this->vehicle_type);
1640 }
1641 break;
1642
1643 case WID_BV_SORT_DROPDOWN:
1644 SetDParam(0, _engine_sort_listing[this->vehicle_type][this->sort_criteria]);
1645 break;
1646
1647 case WID_BV_CARGO_FILTER_DROPDOWN:
1648 SetDParam(0, this->cargo_filter_texts[this->cargo_filter_criteria]);
1649 break;
1650
1651 case WID_BV_SHOW_HIDE: {
1652 const Engine *e = (this->sel_engine == INVALID_ENGINE) ? nullptr : Engine::Get(this->sel_engine);
1653 if (e != nullptr && e->IsHidden(_local_company)) {
1654 SetDParam(0, STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + this->vehicle_type);
1655 } else {
1656 SetDParam(0, STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + this->vehicle_type);
1657 }
1658 break;
1659 }
1660 }
1661 }
1662
1663 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1664 {
1665 switch (widget) {
1666 case WID_BV_LIST:
1667 resize->height = GetEngineListHeight(this->vehicle_type);
1668 size->height = 3 * resize->height;
1669 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;
1670 break;
1671
1672 case WID_BV_PANEL:
1673 size->height = FONT_HEIGHT_NORMAL * this->details_height + padding.height;
1674 break;
1675
1676 case WID_BV_SORT_ASCENDING_DESCENDING: {
1677 Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
1678 d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
1679 d.height += padding.height;
1680 *size = maxdim(*size, d);
1681 break;
1682 }
1683
1684 case WID_BV_BUILD:
1685 *size = GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + this->vehicle_type);
1686 *size = maxdim(*size, GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_BUTTON + this->vehicle_type));
1687 size->width += padding.width;
1688 size->height += padding.height;
1689 break;
1690
1691 case WID_BV_SHOW_HIDE:
1692 *size = GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + this->vehicle_type);
1693 *size = maxdim(*size, GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + this->vehicle_type));
1694 size->width += padding.width;
1695 size->height += padding.height;
1696 break;
1697 }
1698 }
1699
1700 void DrawWidget(const Rect &r, int widget) const override
1701 {
1702 switch (widget) {
1703 case WID_BV_LIST:
1704 DrawEngineList(
1705 this->vehicle_type,
1706 r,
1707 this->eng_list,
1708 this->vscroll->GetPosition(),
1709 static_cast<uint16>(std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->eng_list.size())),
1710 this->sel_engine,
1711 false,
1712 DEFAULT_GROUP
1713 );
1714 break;
1715
1716 case WID_BV_SORT_ASCENDING_DESCENDING:
1717 this->DrawSortButtonState(WID_BV_SORT_ASCENDING_DESCENDING, this->descending_sort_order ? SBS_DOWN : SBS_UP);
1718 break;
1719 }
1720 }
1721
1722 void OnPaint() override
1723 {
1724 this->GenerateBuildList();
1725 this->vscroll->SetCount((uint)this->eng_list.size());
1726
1727 this->SetWidgetsDisabledState(this->sel_engine == INVALID_ENGINE, WID_BV_SHOW_HIDE, WID_BV_BUILD, WIDGET_LIST_END);
1728
1729 /* Disable renaming engines in network games if you are not the server. */
1730 this->SetWidgetDisabledState(WID_BV_RENAME, this->sel_engine == INVALID_ENGINE || (_networking && !_network_server));
1731
1732 this->DrawWidgets();
1733
1734 if (!this->IsShaded()) {
1735 int needed_height = this->details_height;
1736 /* Draw details panels. */
1737 if (this->sel_engine != INVALID_ENGINE) {
1738 const Rect r = this->GetWidget<NWidgetBase>(WID_BV_PANEL)->GetCurrentRect().Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect);
1739 int text_end = DrawVehiclePurchaseInfo(r.left, r.right, r.top, this->sel_engine, this->te);
1740 needed_height = std::max(needed_height, (text_end - r.top) / FONT_HEIGHT_NORMAL);
1741 }
1742 if (needed_height != this->details_height) { // Details window are not high enough, enlarge them.
1743 int resize = needed_height - this->details_height;
1744 this->details_height = needed_height;
1745 this->ReInit(0, resize * FONT_HEIGHT_NORMAL);
1746 return;
1747 }
1748 }
1749 }
1750
1751 void OnQueryTextFinished(char *str) override
1752 {
1753 if (str == nullptr) return;
1754
1755 Command<CMD_RENAME_ENGINE>::Post(STR_ERROR_CAN_T_RENAME_TRAIN_TYPE + this->vehicle_type, this->rename_engine, str);
1756 }
1757
1758 void OnDropdownSelect(int widget, int index) override
1759 {
1760 switch (widget) {
1761 case WID_BV_SORT_DROPDOWN:
1762 if (this->sort_criteria != index) {
1763 this->sort_criteria = index;
1764 _engine_sort_last_criteria[this->vehicle_type] = this->sort_criteria;
1765 this->eng_list.ForceRebuild();
1766 }
1767 break;
1768
1769 case WID_BV_CARGO_FILTER_DROPDOWN: // Select a cargo filter criteria
1770 if (this->cargo_filter_criteria != index) {
1771 this->cargo_filter_criteria = index;
1772 _engine_sort_last_cargo_criteria[this->vehicle_type] = this->cargo_filter[this->cargo_filter_criteria];
1773 /* deactivate filter if criteria is 'Show All', activate it otherwise */
1774 this->eng_list.SetFilterState(this->cargo_filter[this->cargo_filter_criteria] != CF_ANY);
1775 this->eng_list.ForceRebuild();
1776 this->SelectEngine(this->sel_engine);
1777 }
1778 break;
1779 }
1780 this->SetDirty();
1781 }
1782
1783 void OnResize() override
1784 {
1785 this->vscroll->SetCapacityFromWidget(this, WID_BV_LIST);
1786 }
1787 };
1788
1789 static WindowDesc _build_vehicle_desc(
1790 WDP_AUTO, "build_vehicle", 240, 268,
1791 WC_BUILD_VEHICLE, WC_NONE,
1792 WDF_CONSTRUCTION,
1793 _nested_build_vehicle_widgets, lengthof(_nested_build_vehicle_widgets)
1794 );
1795
1796 void ShowBuildVehicleWindow(TileIndex tile, VehicleType type)
1797 {
1798 /* We want to be able to open both Available Train as Available Ships,
1799 * so if tile == INVALID_TILE (Available XXX Window), use 'type' as unique number.
1800 * As it always is a low value, it won't collide with any real tile
1801 * number. */
1802 uint num = (tile == INVALID_TILE) ? (int)type : (int)tile;
1803
1804 assert(IsCompanyBuildableVehicleType(type));
1805
1806 CloseWindowById(WC_BUILD_VEHICLE, num);
1807
1808 new BuildVehicleWindow(&_build_vehicle_desc, tile, type);
1809 }
SZSP_NONE
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
Definition: widget_type.h:428
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:437
TC_FORCED
@ TC_FORCED
Ignore colour changes from strings.
Definition: gfx_type.h:278
BuildVehicleWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: build_vehicle_gui.cpp:1615
Engine::GetDisplayDefaultCapacity
uint GetDisplayDefaultCapacity(uint16 *mail_capacity=nullptr) const
Determines the default cargo capacity of an engine for display purposes.
Definition: engine_base.h:115
_standard_cargo_mask
CargoTypes _standard_cargo_mask
Bitmask of real cargo types available.
Definition: cargotype.cpp:34
INVALID_ENGINE
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
Definition: engine_type.h:203
IsCompanyBuildableVehicleType
static bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
Definition: vehicle_func.h:89
BuildVehicleWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: build_vehicle_gui.cpp:1722
WID_BV_SORT_DROPDOWN
@ WID_BV_SORT_DROPDOWN
Criteria of sorting dropdown.
Definition: build_vehicle_widget.h:17
Engine::GetGRFID
uint32 GetGRFID() const
Retrieve the GRF ID of the NewGRF the engine is tied to.
Definition: engine.cpp:153
RoadTypeInfo
Definition: road.h:76
WID_BV_SHOW_HIDE
@ WID_BV_SHOW_HIDE
Button to hide or show the selected engine.
Definition: build_vehicle_widget.h:24
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:3254
IsInsideMM
static 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:230
EngineNumberSorter
static bool EngineNumberSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by engineID.
Definition: build_vehicle_gui.cpp:109
ClampToI32
static int32 ClampToI32(const int64 a)
Reduce a signed 64-bit int to a signed 32-bit one.
Definition: math_func.hpp:167
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:173
EngineDisplayFlags::HasVariants
@ HasVariants
Set if engine has variants.
Rect::Height
int Height() const
Get height of Rect.
Definition: geometry_type.hpp:85
Pool::PoolItem<&_engine_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
vehicle_gui.h
BuildVehicleWindow::te
TestedEngineDetails te
Tested cost and capacity after refit.
Definition: build_vehicle_gui.cpp:1107
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1210
INVALID_CLIENT_ID
@ INVALID_CLIENT_ID
Client is not part of anything.
Definition: network_type.h:48
VehicleSettings::train_acceleration_model
uint8 train_acceleration_model
realistic acceleration for trains
Definition: settings_type.h:489
GUISettings::show_newgrf_name
bool show_newgrf_name
Show the name of the NewGRF in the build vehicle window.
Definition: settings_type.h:174
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
command_func.h
PackEngineNameDParam
uint64 PackEngineNameDParam(EngineID engine_id, EngineNameContext context, uint32 extra_data=0)
Combine an engine ID and a name context to an engine name dparam.
Definition: engine_type.h:196
Window::DrawSortButtonState
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition: widget.cpp:890
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:319
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:144
TestedEngineDetails::all_capacities
CargoArray all_capacities
Capacities for all cargoes.
Definition: vehicle_gui.h:46
dropdown_func.h
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:92
BuildVehicleWindow::vehicle_type
VehicleType vehicle_type
Type of vehicles shown in the window.
Definition: build_vehicle_gui.cpp:1090
WID_BV_SHOW_HIDDEN_ENGINES
@ WID_BV_SHOW_HIDDEN_ENGINES
Toggle whether to display the hidden vehicles.
Definition: build_vehicle_widget.h:19
Window::ReInit
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:1019
TestedEngineDetails::mail_capacity
uint16 mail_capacity
Mail capacity if available.
Definition: vehicle_gui.h:45
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
EngineDisplayFlags::IsFolded
@ IsFolded
Set if display of variants should be folded (hidden).
BuildVehicleWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: build_vehicle_gui.cpp:1751
GetTotalCapacityOfArticulatedParts
uint GetTotalCapacityOfArticulatedParts(EngineID engine)
Get the capacity of an engine with articulated parts.
Definition: engine_gui.cpp:164
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
Station
Station data structure.
Definition: station_base.h:454
_engine_sort_direction
bool _engine_sort_direction
false = descending, true = ascending.
Definition: build_vehicle_gui.cpp:97
GUIList< GUIEngineListItem, CargoID >
_network_server
bool _network_server
network-server is active
Definition: network.cpp:59
GetCapacityOfArticulatedParts
CargoArray GetCapacityOfArticulatedParts(EngineID engine)
Get the capacity of the parts of a given engine.
Definition: articulated_vehicles.cpp:139
Engine::GetDisplayMaxTractiveEffort
uint GetDisplayMaxTractiveEffort() const
Returns the tractive effort of the engine for display purposes.
Definition: engine.cpp:420
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1775
CF_ENGINES
static const CargoID CF_ENGINES
Show only engines (for rail vehicles only)
Definition: build_vehicle_gui.cpp:95
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:118
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
EIT_PURCHASE
@ EIT_PURCHASE
Vehicle drawn in purchase list, autoreplace gui, ...
Definition: vehicle_type.h:91
HasPowerOnRail
static 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:332
CargoArray
Class for storing amounts of cargo.
Definition: cargo_type.h:82
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:57
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
INVALID_TILE
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:108
Engine::GetRunningCost
Money GetRunningCost() const
Return how much the running costs of this engine are.
Definition: engine.cpp:275
RailtypeInfo
This struct contains all the info that is needed to draw and construct tracks.
Definition: rail.h:124
AircraftRangeSorter
static bool AircraftRangeSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of aircraft by range.
Definition: build_vehicle_gui.cpp:424
group.h
VehicleSettings::wagon_speed_limits
bool wagon_speed_limits
enable wagon speed limits
Definition: settings_type.h:493
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:717
WID_BV_CAPTION
@ WID_BV_CAPTION
Caption of window.
Definition: build_vehicle_widget.h:15
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:38
EngineTractiveEffortSorter
static bool EngineTractiveEffortSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by tractive effort.
Definition: build_vehicle_gui.cpp:240
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:997
zoom_func.h
StartTextRefStackUsage
void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32 *values)
Start using the TTDP compatible string code parsing.
Definition: newgrf_text.cpp:821
TestedEngineDetails::cargo
CargoID cargo
Cargo type.
Definition: vehicle_gui.h:43
WID_BV_BUILD_SEL
@ WID_BV_BUILD_SEL
Build button.
Definition: build_vehicle_widget.h:25
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:644
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:57
VehicleCellSize::extend_right
uint extend_right
Extend of the cell to the right.
Definition: vehicle_gui.h:85
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition: window_gui.h:253
Engine::GetLifeLengthInDays
Date GetLifeLengthInDays() const
Returns the vehicle's (not model's!) life length in days.
Definition: engine.cpp:437
NWidgetCore::tool_tip
StringID tool_tip
Tooltip of the widget.
Definition: widget_type.h:341
StopTextRefStackUsage
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
Definition: newgrf_text.cpp:838
BuildVehicleWindow::descending_sort_order
bool descending_sort_order
Sort direction,.
Definition: build_vehicle_gui.cpp:1095
RoadVehEngineCapacitySorter
static bool RoadVehEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of road vehicles by capacity.
Definition: build_vehicle_gui.cpp:355
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:336
Engine
Definition: engine_base.h:36
BuildVehicleWindow::FilterEngineList
void FilterEngineList()
Filter the engine list against the currently selected cargo filter.
Definition: build_vehicle_gui.cpp:1314
NWidgetCore::SetLowered
void SetLowered(bool lowered)
Lower or raise the widget.
Definition: widget_type.h:374
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
CargoArray::GetCount
byte GetCount() const
Get the amount of cargos that have an amount.
Definition: cargo_type.h:135
Engine::GetDefaultCargoType
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
Definition: engine_base.h:95
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:2353
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:53
RoadVehicleInfo::roadtype
RoadType roadtype
Road type.
Definition: engine_type.h:127
BuildVehicleWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: build_vehicle_gui.cpp:1700
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:636
GetVehicleCallback
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Definition: newgrf_engine.cpp:1162
GetEnginePalette
PaletteID GetEnginePalette(EngineID engine_type, CompanyID company)
Get the colour map for an engine.
Definition: vehicle.cpp:2052
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:55
Rect::WithHeight
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Definition: geometry_type.hpp:205
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
GetVehicleImageCellSize
VehicleCellSize GetVehicleImageCellSize(VehicleType type, EngineImageType image_type)
Get the GUI cell size for a vehicle image.
Definition: depot_gui.cpp:162
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:975
_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:27
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1111
WID_BV_BUILD
@ WID_BV_BUILD
Build panel.
Definition: build_vehicle_widget.h:23
engine_cmd.h
NWidgetCore::widget_data
uint32 widget_data
Data of the widget.
Definition: widget_type.h:340
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:890
GUIList::SetFilterFuncs
void SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
Definition: sortlist_type.h:341
textbuf_gui.h
TestedEngineDetails::capacity
uint capacity
Cargo capacity.
Definition: vehicle_gui.h:44
train_cmd.h
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:789
DisplayVehicleSortDropDown
void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selected, int button)
Display the dropdown for the vehicle sort criteria.
Definition: build_vehicle_gui.cpp:1072
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
WID_BV_SORT_ASCENDING_DESCENDING
@ WID_BV_SORT_ASCENDING_DESCENDING
Sort direction.
Definition: build_vehicle_widget.h:16
WID_BV_PANEL
@ WID_BV_PANEL
Button panel.
Definition: build_vehicle_widget.h:22
BuildVehicleWindow::show_hidden_engines
bool show_hidden_engines
State of the 'show hidden engines' button.
Definition: build_vehicle_gui.cpp:1097
WindowDesc
High level window description.
Definition: window_gui.h:102
EnginePowerVsRunningCostSorter
static bool EnginePowerVsRunningCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by running costs.
Definition: build_vehicle_gui.cpp:274
GetRailTypeInfo
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:304
Engine::display_last_variant
EngineID display_last_variant
NOSAVE client-side-only last variant selected.
Definition: engine_base.h:58
Engine::GetDisplayMaxSpeed
uint GetDisplayMaxSpeed() const
Returns max speed of the engine for display purposes.
Definition: engine.cpp:352
EngineID
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
BuildVehicleWindow::cargo_filter_criteria
byte cargo_filter_criteria
Selected cargo filter.
Definition: build_vehicle_gui.cpp:1104
RailVehicleInfo
Information about a rail vehicle.
Definition: engine_type.h:42
_engine_sort_listing
const StringID _engine_sort_listing[][12]
Dropdown menu strings for the vehicle sort criteria.
Definition: build_vehicle_gui.cpp:487
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:90
GUIList::SetFilterState
void SetFilterState(bool state)
Enable or disable the filter.
Definition: sortlist_type.h:302
RailType
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:251
GetUnionOfArticulatedRefitMasks
CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ors the refit_masks of all articulated parts.
Definition: articulated_vehicles.cpp:220
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:155
newgrf_engine.h
EngineCostSorter
static bool EngineCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by purchase cost.
Definition: build_vehicle_gui.cpp:189
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:1098
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:1008
WidgetDimensions::matrix
RectPadding matrix
Offsets within a matrix cell.
Definition: window_gui.h:49
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition: gfx_type.h:204
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
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:201
WidgetDimensions::hsep_wide
int hsep_wide
Wide horizontal spacing.
Definition: window_gui.h:64
Engine::display_flags
EngineDisplayFlags display_flags
NOSAVE client-side-only display flags for build engine list.
Definition: engine_base.h:57
WC_REPLACE_VEHICLE
@ WC_REPLACE_VEHICLE
Replace vehicle window; Window numbers:
Definition: window_type.h:211
ScaleSpriteTrad
static int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition: zoom_func.h:107
SetMatrixDataTip
static NWidgetPart SetMatrixDataTip(uint8 cols, uint8 rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1129
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:54
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_type.h:346
Engine::GetDisplayWeight
uint GetDisplayWeight() const
Returns the weight of the engine for display purposes.
Definition: engine.cpp:402
ConvertDateToYMD
void ConvertDateToYMD(Date date, YearMonthDay *ymd)
Converts a Date to a Year, Month & Day.
Definition: date.cpp:94
EngineDisplayFlags::None
@ None
No flag set.
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:321
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:266
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
CF_NONE
static const CargoID CF_NONE
Show only vehicles which do not carry cargo (e.g. train engines)
Definition: build_vehicle_gui.cpp:94
CcBuildPrimaryVehicle
void CcBuildPrimaryVehicle(Commands cmd, const CommandCost &result, VehicleID new_veh_id, uint, uint16, CargoArray)
This is the Callback method after the construction attempt of a primary vehicle.
Definition: vehicle_gui.cpp:3359
ShipEngineCapacitySorter
static bool ShipEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of ships by capacity.
Definition: build_vehicle_gui.cpp:374
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:1115
BuildVehicleWindow::rename_engine
EngineID rename_engine
Engine being renamed.
Definition: build_vehicle_gui.cpp:1100
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:239
vehicle_cmd.h
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:192
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:41
GetGRFStringID
StringID GetGRFStringID(uint32 grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
Definition: newgrf_text.cpp:601
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:179
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:58
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:1058
newgrf_text.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
BuildVehicleWindow::cargo_filter
CargoID cargo_filter[NUM_CARGO+3]
Available cargo filters; CargoID or CF_ANY or CF_NONE or CF_ENGINES.
Definition: build_vehicle_gui.cpp:1102
BuildVehicleWindow::details_height
int details_height
Minimal needed height of the details panels, in text lines (found so far).
Definition: build_vehicle_gui.cpp:1105
build_vehicle_widget.h
ShowDropDownMenu
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
Definition: dropdown.cpp:481
WID_BV_CARGO_FILTER_DROPDOWN
@ WID_BV_CARGO_FILTER_DROPDOWN
Cargo filter dropdown.
Definition: build_vehicle_widget.h:18
DAYS_IN_LEAP_YEAR
static const int DAYS_IN_LEAP_YEAR
sometimes, you need one day more...
Definition: date_type.h:30
Engine::GetCost
Money GetCost() const
Return how much a new engine costs.
Definition: engine.cpp:312
BuildVehicleWindow::sort_criteria
byte sort_criteria
Current sort criterium.
Definition: build_vehicle_gui.cpp:1096
date_func.h
WID_BV_RENAME
@ WID_BV_RENAME
Rename button.
Definition: build_vehicle_widget.h:26
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:241
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
BuildVehicleWindow::FilterSingleEngine
bool FilterSingleEngine(EngineID eid)
Filter a single engine.
Definition: build_vehicle_gui.cpp:1325
RailVehicleInfo::pow_wag_power
uint16 pow_wag_power
Extra power applied to consist if wagon should be powered.
Definition: engine_type.h:56
IsArticulatedVehicleRefittable
bool IsArticulatedVehicleRefittable(EngineID engine)
Checks whether any of the articulated parts is refittable.
Definition: articulated_vehicles.cpp:168
CS_ALPHANUMERAL
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition: string_type.h:27
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
RAILVEH_WAGON
@ RAILVEH_WAGON
simple wagon, not motorized
Definition: engine_type.h:29
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:75
GetTileOwner
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:178
FONT_HEIGHT_SMALL
#define FONT_HEIGHT_SMALL
Height of characters in the small (FS_SMALL) font.
Definition: gfx_func.h:203
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:993
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:362
Generic
@ Generic
No specific context available.
Definition: engine_type.h:189
YearMonthDay::year
Year year
Year (0...)
Definition: date_type.h:105
string_func.h
EngineReliabilitySorter
static bool EngineReliabilitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by reliability.
Definition: build_vehicle_gui.cpp:172
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition: newgrf_callbacks.h:408
RailtypeInfo::acceleration_type
uint8 acceleration_type
Acceleration type of this rail type.
Definition: rail.h:223
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
_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
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:160
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
vehicle_func.h
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1096
TrainEnginesThenWagonsSorter
static bool TrainEnginesThenWagonsSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of train engines by engine / wagon.
Definition: build_vehicle_gui.cpp:336
EnginePowerSorter
static bool EnginePowerSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by power.
Definition: build_vehicle_gui.cpp:223
station_base.h
WID_BV_SCROLLBAR
@ WID_BV_SCROLLBAR
Scrollbar of list.
Definition: build_vehicle_widget.h:21
PALETTE_CRASH
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition: sprites.h:1598
engine_gui.h
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
_sorted_standard_cargo_specs
span< const CargoSpec * > _sorted_standard_cargo_specs
Standard cargo specifications sorted alphabetically by name.
Definition: cargotype.cpp:154
TrainEngineCapacitySorter
static bool TrainEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of train engines by capacity.
Definition: build_vehicle_gui.cpp:316
EngineRunningCostSorter
static bool EngineRunningCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by running costs.
Definition: build_vehicle_gui.cpp:257
Engine::IsHidden
bool IsHidden(CompanyID c) const
Check whether the engine is hidden in the GUI for the given company.
Definition: engine_base.h:135
GroupID
uint16 GroupID
Type for all group identifiers.
Definition: group_type.h:13
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:455
EngineDisplayFlags
EngineDisplayFlags
Flags used client-side in the purchase/autorenew engine list.
Definition: engine_base.h:25
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:541
WC_BUILD_VEHICLE
@ WC_BUILD_VEHICLE
Build vehicle; Window numbers:
Definition: window_type.h:376
WIDGET_LIST_END
static const int WIDGET_LIST_END
indicate the end of widgets' list for vararg functions
Definition: widget_type.h:20
VehicleSettings::roadveh_acceleration_model
uint8 roadveh_acceleration_model
realistic acceleration for road vehicles
Definition: settings_type.h:490
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:384
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:206
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1229
BuildVehicleWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: build_vehicle_gui.cpp:1663
WidgetDimensions::fullbevel
RectPadding fullbevel
Always-scaled bevel border.
Definition: window_gui.h:46
geometry_func.hpp
GUIList< GUIEngineListItem, CargoID >::FilterFunction
bool CDECL FilterFunction(const GUIEngineListItem *, CargoID)
Signature of filter function.
Definition: sortlist_type.h:49
BuildVehicleWindow::roadtype
RoadType roadtype
Road type to show, or INVALID_ROADTYPE.
Definition: build_vehicle_gui.cpp:1093
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:3271
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1014
BuildVehicleWindow
GUI for building vehicles.
Definition: build_vehicle_gui.cpp:1089
RAILVEH_MULTIHEAD
@ RAILVEH_MULTIHEAD
indicates a combination of two locomotives
Definition: engine_type.h:28
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
EngineInfo::variant_id
EngineID variant_id
Engine variant ID. If set, will be treated specially in purchase lists.
Definition: engine_type.h:158
Window::SetWidgetsDisabledState
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets,...)
Sets the enabled/disabled status of a list of widgets.
Definition: window.cpp:560
GetRailType
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
Definition: rail_map.h:115
BuildVehicleWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: build_vehicle_gui.cpp:1507
CT_AUTO_REFIT
@ CT_AUTO_REFIT
Automatically choose cargo type when doing auto refitting.
Definition: cargo_type.h:67
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:65
SpecializedStation< Station, false >::GetByTile
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
Definition: base_station_base.h:237
CF_ANY
static const CargoID CF_ANY
Special cargo filter criteria.
Definition: build_vehicle_gui.cpp:93
BuildVehicleWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: build_vehicle_gui.cpp:1758
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:678
cargotype.h
RailtypeInfo::build_caption
StringID build_caption
Caption of the build vehicle GUI for this rail type.
Definition: rail.h:176
EngList_Sort
void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare)
Sort all items using quick sort and given 'CompareItems' function.
Definition: engine_gui.cpp:327
TestedEngineDetails::cost
Money cost
Refit cost.
Definition: vehicle_gui.h:42
GetRoadTypeInfo
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:225
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:22
RailVehicleInfo::railtype
RailType railtype
Railtype, mangled if elrail is disabled.
Definition: engine_type.h:46
GUIList::Filter
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
Definition: sortlist_type.h:318
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1791
BuildVehicleWindow::railtype
RailType railtype
Rail type to show, or INVALID_RAILTYPE.
Definition: build_vehicle_gui.cpp:1092
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:775
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:1251
BuildVehicleWindow::sel_engine
EngineID sel_engine
Currently selected engine, or INVALID_ENGINE.
Definition: build_vehicle_gui.cpp:1099
BuildVehicleWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: build_vehicle_gui.cpp:1308
network.h
CommandHelper
Definition: command_func.h:94
WID_BV_LIST
@ WID_BV_LIST
List of vehicles.
Definition: build_vehicle_widget.h:20
window_func.h
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:370
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition: gfx_type.h:344
BuildVehicleWindow::cargo_filter_texts
StringID cargo_filter_texts[NUM_CARGO+4]
Texts for filter_cargo, terminated by INVALID_STRING_ID.
Definition: build_vehicle_gui.cpp:1103
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
PurchaseList
@ PurchaseList
Name is shown in the purchase list (including autoreplace window).
Definition: engine_type.h:191
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
YearMonthDay
Data structure to convert between Date and triplet (year, month, and day).
Definition: date_type.h:104
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:2427
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:907
AircraftEngineCargoSorter
static bool AircraftEngineCargoSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of aircraft by cargo.
Definition: build_vehicle_gui.cpp:396
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:340
OverflowSafeInt< int64 >
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1191
ToPercent16
static uint ToPercent16(uint i)
Converts a "fract" value 0..65535 to "percent" value 0..100.
Definition: math_func.hpp:264
HasPowerOnRoad
static 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:240
engine_base.h
BuildVehicleWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: build_vehicle_gui.cpp:1628
BuildVehicleWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: build_vehicle_gui.cpp:1783
strnatcmp
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Definition: string.cpp:737
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1080
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:1200
articulated_vehicles.h
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition: settings_type.h:595
ErrorUnknownCallbackResult
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
Definition: newgrf_commons.cpp:516
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:865
Window
Data structure for an opened window.
Definition: window_gui.h:213
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:380
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
RailtypeInfo::strings
struct RailtypeInfo::@39 strings
Strings associated with the rail type.
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:858
EngineSpeedSorter
static bool EngineSpeedSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by speed.
Definition: build_vehicle_gui.cpp:206
DC_QUERY_COST
@ DC_QUERY_COST
query cost only, don't build.
Definition: command_type.h:359
Engine::GetRange
uint16 GetRange() const
Get the range of an aircraft type.
Definition: engine.cpp:447
autoreplace_func.h
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:161
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
CanVehicleUseStation
bool CanVehicleUseStation(EngineID engine_type, const Station *st)
Can this station be used by the given engine type?
Definition: vehicle.cpp:2861
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:78
GetScaledSpriteSize
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
Definition: widget.cpp:187
CT_INVALID
@ CT_INVALID
Invalid cargo type.
Definition: cargo_type.h:69
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:316
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:69
CT_NO_REFIT
@ CT_NO_REFIT
Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-new).
Definition: cargo_type.h:68
RoadTypeInfo::build_caption
StringID build_caption
Caption of the build vehicle GUI for this rail type.
Definition: road.h:104
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:80
EngineHasReplacementForCompany
static 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
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:402
SetDParamMaxDigits
void SetDParamMaxDigits(uint n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:111
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:902
IsEngineBuildable
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
Check if an engine is buildable.
Definition: engine.cpp:1168
GetEngineListHeight
uint GetEngineListHeight(VehicleType type)
Get the height of a single 'entry' in the engine lists.
Definition: build_vehicle_gui.cpp:49
DrawEngineList
void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group)
Engine drawing loop.
Definition: build_vehicle_gui.cpp:990
Window::SetWidgetLoweredState
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:382
Engine::intro_date
Date intro_date
Date of introduction of the engine.
Definition: engine_base.h:38
Engine::GetAircraftTypeText
StringID GetAircraftTypeText() const
Get the name of the aircraft type for display purposes.
Definition: engine.cpp:461
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:49
GetGRFConfig
GRFConfig * GetGRFConfig(uint32 grfid, uint32 mask)
Retrieve a NewGRF from the current config by its grfid.
Definition: newgrf_config.cpp:771
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:297
VehicleCellSize::extend_left
uint extend_left
Extend of the cell to the left.
Definition: vehicle_gui.h:84
BuildVehicleWindow::filter
union BuildVehicleWindow::@0 filter
Filter to apply.
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:53
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:106
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:604
Engine::reliability
uint16 reliability
Current reliability of the engine.
Definition: engine_base.h:40
Engine::type
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
Definition: engine_base.h:55
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:68
BuildVehicleWindow::SetCargoFilterArray
void SetCargoFilterArray()
Populate the filter list and set the cargo filter criteria.
Definition: build_vehicle_gui.cpp:1230
GRFConfig::GetName
const char * GetName() const
Get the name of this grf.
Definition: newgrf_config.cpp:105
GUIEngineListItem
Definition: engine_gui.h:19
engine_func.h
RoadTypeInfo::strings
struct RoadTypeInfo::@42 strings
Strings associated with the rail type.
INVALID_RAILTYPE
@ INVALID_RAILTYPE
Flag for invalid railtype.
Definition: rail_type.h:34
CcBuildWagon
void CcBuildWagon(Commands cmd, const CommandCost &result, VehicleID new_veh_id, uint, uint16, CargoArray, TileIndex tile, EngineID, bool, CargoID, ClientID)
Callback for building wagons.
Definition: train_gui.cpp:30
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62