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