OpenTTD Source 20261112-master-gbcbec5e63f
autoreplace_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 "command_func.h"
12#include "vehicle_gui.h"
13#include "rail.h"
14#include "road.h"
15#include "strings_func.h"
16#include "window_func.h"
17#include "autoreplace_func.h"
18#include "company_func.h"
19#include "engine_base.h"
20#include "window_gui.h"
21#include "engine_gui.h"
22#include "settings_func.h"
24#include "rail_gui.h"
25#include "road_gui.h"
26#include "dropdown_type.h"
27#include "dropdown_func.h"
28#include "autoreplace_cmd.h"
29#include "group_cmd.h"
30#include "settings_cmd.h"
31
33
34#include "table/strings.h"
35
36#include "safeguards.h"
37
40{
41 return Engine::Get(a.engine_id)->list_position < Engine::Get(b.engine_id)->list_position;
42}
43
54{
56 /* We don't have any of this engine type.
57 * Either we just sold the last one, we build a new one or we stopped replacing it.
58 * In all cases, we need to update the left list */
59 InvalidateWindowData(WindowClass::ReplaceVehicle, Engine::Get(e)->type, 1);
60 }
61}
62
68{
69 InvalidateWindowData(WindowClass::ReplaceVehicle, type, 0); // Update the autoreplace window
70 InvalidateWindowClassesData(WindowClass::BuildVehicle); // The build windows needs updating as well
71}
72
73static const StringID _start_replace_dropdown[] = {
74 STR_REPLACE_VEHICLES_NOW,
75 STR_REPLACE_VEHICLES_WHEN_OLD,
76};
77
81class ReplaceVehicleWindow : public Window {
82 std::array<EngineID, 2> sel_engine{};
83 std::array<GUIEngineList, 2> engines{};
84 bool replace_engines = true;
85 bool reset_sel_engine = true;
86 GroupID sel_group = GroupID::Invalid();
89 uint8_t sort_criteria = 0;
90 bool descending_sort_order = false;
91 bool show_hidden_engines = false;
94 std::array<Scrollbar *, 2> vscroll{};
95 GUIBadgeClasses badge_classes{};
96
104 bool GenerateReplaceRailList(EngineID e, bool draw_left, bool show_engines)
105 {
106 const RailVehicleInfo *rvi = RailVehInfo(e);
107
108 /* Ensure that the wagon/engine selection fits the engine. */
109 if ((rvi->railveh_type == RailVehicleType::Wagon) == show_engines) return false;
110
111 if (draw_left && this->sel_railtype != INVALID_RAILTYPE) {
112 /* Ensure that the railtype is specific to the selected one */
113 if (!rvi->railtypes.Test(this->sel_railtype)) return false;
114 }
115 return true;
116 }
117
122 void GenerateReplaceVehList(bool draw_left)
123 {
124 FlatSet<EngineID> variants;
125 EngineID selected_engine = EngineID::Invalid();
126 VehicleType type = this->window_number;
127 uint8_t side = draw_left ? 0 : 1;
128
129 GUIEngineList list;
130
131 for (const Engine *e : Engine::IterateType(type)) {
132 if (!draw_left && !this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue;
133 EngineID eid = e->index;
134 switch (type) {
136 if (!this->GenerateReplaceRailList(eid, draw_left, this->replace_engines)) continue; // special rules for trains
137 break;
138
140 if (draw_left && this->sel_roadtype != INVALID_ROADTYPE) {
141 /* Ensure that the roadtype is specific to the selected one */
142 if (e->VehInfo<RoadVehicleInfo>().roadtype != this->sel_roadtype) continue;
143 }
144 break;
145
146 default:
147 break;
148 }
149
150 if (draw_left) {
151 const uint num_engines = GetGroupNumEngines(_local_company, this->sel_group, eid);
152
153 /* Skip drawing the engines we don't have any of and haven't set for replacement */
154 if (num_engines == 0 && EngineReplacementForCompany(Company::Get(_local_company), eid, this->sel_group) == EngineID::Invalid()) continue;
155 } else {
156 if (!CheckAutoreplaceValidity(this->sel_engine[0], eid, _local_company)) continue;
157 }
158
159 list.emplace_back(eid, e->info.variant_id, (side == 0) ? EngineDisplayFlags{} : e->display_flags, 0);
160
161 if (side == 1) {
162 EngineID parent = e->info.variant_id;
163 while (parent != EngineID::Invalid() && variants.insert(parent).second) {
164 parent = Engine::Get(parent)->info.variant_id;
165 }
166 }
167 if (eid == this->sel_engine[side]) selected_engine = eid; // The selected engine is still in the list
168 }
169
170 if (side == 1) {
171 /* ensure primary engine of variant group is in list */
172 for (const auto &variant : variants) {
173 if (std::ranges::find(list, variant, &GUIEngineListItem::engine_id) == list.end()) {
174 const Engine *e = Engine::Get(variant);
175 list.emplace_back(variant, e->info.variant_id, e->display_flags | EngineDisplayFlag::Shaded, 0);
176 }
177 }
178 }
179
180 this->sel_engine[side] = selected_engine; // update which engine we selected (the same or none, if it's not in the list anymore)
181 if (draw_left) {
183 } else {
184 _engine_sort_direction = this->descending_sort_order;
185 EngList_Sort(list, GetEngineSortFunctions(this->vehicle_type)[this->sort_criteria]);
186 }
187
188 this->engines[side].clear();
189 if (side == 1) {
190 GUIEngineListAddChildren(this->engines[side], list);
191 } else {
192 this->engines[side].swap(list);
193 }
194 }
195
198 {
199 EngineID e = this->sel_engine[0];
200
201 if (this->engines[0].NeedRebuild()) {
202 /* We need to rebuild the left engines list */
203 this->GenerateReplaceVehList(true);
204 this->vscroll[0]->SetCount(this->engines[0].size());
205 if (this->reset_sel_engine && this->sel_engine[0] == EngineID::Invalid() && !this->engines[0].empty()) {
206 this->sel_engine[0] = this->engines[0][0].engine_id;
207 }
208 }
209
210 if (this->engines[1].NeedRebuild() || e != this->sel_engine[0]) {
211 /* Either we got a request to rebuild the right engines list, or the left engines list selected a different engine */
212 if (this->sel_engine[0] == EngineID::Invalid()) {
213 /* Always empty the right engines list when nothing is selected in the left engines list */
214 this->engines[1].clear();
215 this->sel_engine[1] = EngineID::Invalid();
216 this->vscroll[1]->SetCount(this->engines[1].size());
217 } else {
218 if (this->reset_sel_engine && this->sel_engine[0] != EngineID::Invalid()) {
219 /* Select the current replacement for sel_engine[0]. */
221 this->sel_engine[1] = EngineReplacementForCompany(c, this->sel_engine[0], this->sel_group);
222 }
223 /* Regenerate the list on the right. Note: This resets sel_engine[1] to EngineID::Invalid(), if it is no longer available. */
224 this->GenerateReplaceVehList(false);
225 this->vscroll[1]->SetCount(this->engines[1].size());
226 if (this->reset_sel_engine && this->sel_engine[1] != EngineID::Invalid()) {
227 int position = 0;
228 for (const auto &item : this->engines[1]) {
229 if (item.engine_id == this->sel_engine[1]) break;
230 ++position;
231 }
232 this->vscroll[1]->ScrollTowards(position);
233 }
234 }
235 }
236 /* Reset the flags about needed updates */
237 this->engines[0].RebuildDone();
238 this->engines[1].RebuildDone();
239 this->reset_sel_engine = false;
240 }
241
246 void ReplaceClick_StartReplace(bool replace_when_old)
247 {
248 EngineID veh_from = this->sel_engine[0];
249 EngineID veh_to = this->sel_engine[1];
250 Command<Commands::SetAutoreplace>::Post(this->sel_group, veh_from, veh_to, replace_when_old);
251 }
252
257 {
258 /* Reset scrollbar positions */
259 this->vscroll[0]->SetPosition(0);
260 this->vscroll[1]->SetPosition(0);
261 /* Rebuild the lists */
262 this->engines[0].ForceRebuild();
263 this->engines[1].ForceRebuild();
264 this->reset_sel_engine = true;
265 this->SetDirty();
266 }
267
268public:
269 ReplaceVehicleWindow(WindowDesc &desc, VehicleType vehicletype, GroupID id_g) : Window(desc)
270 {
271 this->vehicle_type = vehicletype;
272 this->engines[0].ForceRebuild();
273 this->engines[1].ForceRebuild();
274 this->details_height = ((vehicletype == VehicleType::Train) ? 10 : 9);
275 this->sel_engine[0] = EngineID::Invalid();
276 this->sel_engine[1] = EngineID::Invalid();
277 this->show_hidden_engines = _engine_sort_show_hidden_engines[vehicletype];
278
279 this->CreateNestedTree();
280 this->vscroll[0] = this->GetScrollbar(WID_RV_LEFT_SCROLLBAR);
281 this->vscroll[1] = this->GetScrollbar(WID_RV_RIGHT_SCROLLBAR);
282
284 widget->SetStringTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + to_underlying(vehicletype), STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + to_underlying(vehicletype));
285 widget->SetLowered(this->show_hidden_engines);
286 this->FinishInitNested(vehicletype);
287
288 this->sort_criteria = _engine_sort_last_criteria[vehicletype];
289 this->descending_sort_order = _engine_sort_last_order[vehicletype];
290 this->owner = _local_company;
291 this->sel_group = id_g;
292 }
293
294 void OnInit() override
295 {
296 this->badge_classes = GUIBadgeClasses(GetGrfSpecFeature(this->vehicle_type));
297 }
298
299 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
300 {
301 switch (widget) {
304 d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
305 d.height += padding.height;
306 size = maxdim(size, d);
307 break;
308 }
309
312 fill.height = resize.height = GetEngineListHeight(this->window_number);
313 size.height = (this->vehicle_type <= VehicleType::Road ? 8 : 4) * resize.height;
314 break;
315
318 size.height = GetCharacterHeight(FontSize::Normal) * this->details_height + padding.height;
319 break;
320
322 StringID str = this->GetWidget<NWidgetCore>(widget)->GetString();
323 StringID group_str = Group::IsValidID(this->sel_group) ? STR_GROUP_NAME : STR_GROUP_DEFAULT_TRAINS + this->window_number;
324 Dimension d = GetStringBoundingBox(GetString(str, group_str, this->sel_group, STR_CONFIG_SETTING_ON));
325 d = maxdim(d, GetStringBoundingBox(GetString(str, group_str, this->sel_group, STR_CONFIG_SETTING_OFF)));
326 d.width += padding.width;
327 d.height += padding.height;
328 size = maxdim(size, d);
329 break;
330 }
331
333 Dimension d = GetStringBoundingBox(STR_REPLACE_ENGINES);
334 d = maxdim(d, GetStringBoundingBox(STR_REPLACE_WAGONS));
335 d.width += padding.width;
336 d.height += padding.height;
337 size = maxdim(size, d);
338 break;
339 }
340
341 case WID_RV_INFO_TAB: {
342 Dimension d = GetStringBoundingBox(STR_REPLACE_NOT_REPLACING);
343 d = maxdim(d, GetStringBoundingBox(STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED));
344 d.width += padding.width;
345 d.height += padding.height;
346 size = maxdim(size, d);
347 break;
348 }
349
351 Dimension d = {0, 0};
352 for (const RailType &rt : _sorted_railtypes) {
354 }
355 d.width += padding.width;
356 d.height += padding.height;
357 size = maxdim(size, d);
358 break;
359 }
360
362 Dimension d = {0, 0};
363 for (const RoadType &rt : _sorted_roadtypes) {
365 }
366 d.width += padding.width;
367 d.height += padding.height;
368 size = maxdim(size, d);
369 break;
370 }
371
373 Dimension d = GetStringBoundingBox(STR_REPLACE_VEHICLES_START);
374 d = maxdim(d, GetStringListBoundingBox(_start_replace_dropdown));
375 d.width += padding.width;
376 d.height += padding.height;
377 size = maxdim(size, d);
378 break;
379 }
380 }
381 }
382
383 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
384 {
385 switch (widget) {
386 case WID_RV_CAPTION:
387 switch (this->sel_group.base()) {
388 case ALL_GROUP.base():
389 return GetString(STR_REPLACE_VEHICLES_WHITE, STR_REPLACE_VEHICLE_TRAIN + this->window_number, STR_GROUP_ALL_TRAINS + this->window_number, std::monostate{});
390 break;
391
392 case DEFAULT_GROUP.base():
393 return GetString(STR_REPLACE_VEHICLES_WHITE, STR_REPLACE_VEHICLE_TRAIN + this->window_number, STR_GROUP_DEFAULT_TRAINS + this->window_number, std::monostate{});
394 break;
395
396 default:
397 return GetString(STR_REPLACE_VEHICLES_WHITE, STR_REPLACE_VEHICLE_TRAIN + this->window_number, STR_GROUP_NAME, sel_group);
398 }
399 break;
400
402 return GetString(GetEngineSortNames(this->window_number)[this->sort_criteria]);
403
405 if (const Group *g = Group::GetIfValid(this->sel_group); g != nullptr) {
406 bool remove_wagon = g->flags.Test(GroupFlag::ReplaceWagonRemoval);
407 return GetString(STR_REPLACE_REMOVE_WAGON, STR_GROUP_NAME, sel_group, remove_wagon ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
408 } else {
410 bool remove_wagon = c->settings.renew_keep_length;
411 return GetString(STR_REPLACE_REMOVE_WAGON, STR_GROUP_DEFAULT_TRAINS + this->window_number, std::monostate{}, remove_wagon ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
412 }
413 break;
414
416 return GetString(this->replace_engines ? STR_REPLACE_ENGINES : STR_REPLACE_WAGONS);
417
419 return GetString(this->sel_railtype == INVALID_RAILTYPE ? STR_REPLACE_ALL_RAILTYPE : GetRailTypeInfo(this->sel_railtype)->strings.replace_text);
420
422 return GetString(this->sel_roadtype == INVALID_ROADTYPE ? STR_REPLACE_ALL_ROADTYPE : GetRoadTypeInfo(this->sel_roadtype)->strings.replace_text);
423
424 default:
425 return this->Window::GetWidgetString(widget, stringid);
426 }
427 }
428
429 void DrawWidget(const Rect &r, WidgetID widget) const override
430 {
431 switch (widget) {
433 this->DrawSortButton(WID_RV_SORT_ASCENDING_DESCENDING, this->descending_sort_order);
434 break;
435
436 case WID_RV_INFO_TAB: {
438 std::string str;
439 if (this->sel_engine[0] != EngineID::Invalid()) {
440 if (!EngineHasReplacementForCompany(c, this->sel_engine[0], this->sel_group)) {
441 str = GetString(STR_REPLACE_NOT_REPLACING);
442 } else {
443 bool when_old = false;
444 EngineID e = EngineReplacementForCompany(c, this->sel_engine[0], this->sel_group, &when_old);
445 str = GetString(when_old ? STR_REPLACE_REPLACING_WHEN_OLD : STR_ENGINE_NAME, PackEngineNameDParam(e, EngineNameContext::PurchaseList));
446 }
447 } else {
448 str = GetString(STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED);
449 }
450
452 break;
453 }
454
456 case WID_RV_RIGHT_MATRIX: {
457 int side = (widget == WID_RV_LEFT_MATRIX) ? 0 : 1;
458
459 /* Do the actual drawing */
460 DrawEngineList(this->window_number, r, this->engines[side], *this->vscroll[side], this->sel_engine[side], side == 0, this->sel_group, this->badge_classes, this->sort_criteria);
461 break;
462 }
463 }
464 }
465
466 void OnPaint() override
467 {
468 if (this->engines[0].NeedRebuild() || this->engines[1].NeedRebuild()) this->GenerateLists();
469
471
472 /* Disable the "Start Replacing" button if:
473 * Either engines list is empty
474 * or The selected replacement engine has a replacement (to prevent loops). */
476 this->sel_engine[0] == EngineID::Invalid() || this->sel_engine[1] == EngineID::Invalid() || EngineReplacementForCompany(c, this->sel_engine[1], this->sel_group) != EngineID::Invalid());
477
478 /* Disable the "Stop Replacing" button if:
479 * The left engines list (existing vehicle) is empty
480 * or The selected vehicle has no replacement set up */
481 this->SetWidgetDisabledState(WID_RV_STOP_REPLACE, this->sel_engine[0] == EngineID::Invalid() || !EngineHasReplacementForCompany(c, this->sel_engine[0], this->sel_group));
482
483 this->DrawWidgets();
484
485 if (!this->IsShaded()) {
486 int needed_height = this->details_height;
487 /* Draw details panels. */
488 for (int side = 0; side < 2; side++) {
489 if (this->sel_engine[side] != EngineID::Invalid()) {
490 /* Use default engine details without refitting */
491 const Engine *e = Engine::Get(this->sel_engine[side]);
493 ted.cost = 0;
494 ted.FillDefaultCapacities(e);
495
496 const Rect r = this->GetWidget<NWidgetBase>(side == 0 ? WID_RV_LEFT_DETAILS : WID_RV_RIGHT_DETAILS)->GetCurrentRect()
498 int text_end = DrawVehiclePurchaseInfo(r.left, r.right, r.top, this->sel_engine[side], ted);
499 needed_height = std::max(needed_height, (text_end - r.top) / GetCharacterHeight(FontSize::Normal));
500 }
501 }
502 if (needed_height != this->details_height) { // Details window are not high enough, enlarge them.
503 this->details_height = needed_height;
504 this->ReInit();
505 return;
506 }
507 }
508 }
509
510 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
511 {
512 switch (widget) {
514 this->descending_sort_order ^= true;
515 _engine_sort_last_order[this->vehicle_type] = this->descending_sort_order;
516 this->engines[1].ForceRebuild();
517 this->SetDirty();
518 break;
519
521 this->show_hidden_engines ^= true;
522 _engine_sort_show_hidden_engines[this->vehicle_type] = this->show_hidden_engines;
523 this->engines[1].ForceRebuild();
524 this->SetWidgetLoweredState(widget, this->show_hidden_engines);
525 this->SetDirty();
526 break;
527
529 DisplayVehicleSortDropDown(this, this->window_number, this->sort_criteria, WID_RV_SORT_DROPDOWN);
530 break;
531
533 DropDownList list;
534 list.push_back(MakeDropDownListStringItem(STR_REPLACE_ENGINES, 1));
535 list.push_back(MakeDropDownListStringItem(STR_REPLACE_WAGONS, 0));
536 ShowDropDownList(this, std::move(list), this->replace_engines ? 1 : 0, WID_RV_TRAIN_ENGINEWAGON_DROPDOWN);
537 break;
538 }
539
540 case WID_RV_RAIL_TYPE_DROPDOWN: { // Railtype selection dropdown menu
541 static std::string railtype_filter;
542 ShowDropDownList(this, GetRailTypeDropDownList(true, true), this->sel_railtype, widget, 0, DropDownOption::Filterable, &railtype_filter);
543 break;
544 }
545
546 case WID_RV_ROAD_TYPE_DROPDOWN: { // Roadtype selection dropdown menu
547 static std::string roadtype_filter;
548 ShowDropDownList(this, GetRoadTypeDropDownList(ROADTRAMTYPES_ALL, true, true), this->sel_roadtype, widget, 0, DropDownOption::Filterable, &roadtype_filter);
549 break;
550 }
551
553 const Group *g = Group::GetIfValid(this->sel_group);
554 if (g != nullptr) {
555 Command<Commands::SetGroupFlag>::Post(this->sel_group, GroupFlag::ReplaceWagonRemoval, !g->flags.Test(GroupFlag::ReplaceWagonRemoval), IsCtrlPressed());
556 } else {
557 /* toggle renew_keep_length */
558 Command<Commands::ChangeCompanySetting>::Post("company.renew_keep_length", Company::Get(_local_company)->settings.renew_keep_length ? 0 : 1);
559 }
560 break;
561 }
562
563 case WID_RV_START_REPLACE: { // Start replacing
564 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
567 } else {
568 bool replacement_when_old = EngineHasReplacementWhenOldForCompany(Company::Get(_local_company), this->sel_engine[0], this->sel_group);
569 ShowDropDownMenu(this, _start_replace_dropdown, replacement_when_old ? 1 : 0, WID_RV_START_REPLACE, !this->replace_engines ? 1 << 1 : 0, 0);
570 }
571 break;
572 }
573
574 case WID_RV_STOP_REPLACE: { // Stop replacing
575 EngineID veh_from = this->sel_engine[0];
576 Command<Commands::SetAutoreplace>::Post(this->sel_group, veh_from, EngineID::Invalid(), false);
577 break;
578 }
579
581 case WID_RV_RIGHT_MATRIX: {
582 uint8_t click_side;
583 if (widget == WID_RV_LEFT_MATRIX) {
584 click_side = 0;
585 } else {
586 click_side = 1;
587 }
588
589 EngineID e = EngineID::Invalid();
590 const auto it = this->vscroll[click_side]->GetScrolledItemFromWidget(this->engines[click_side], pt.y, this, widget);
591 if (it != this->engines[click_side].end()) {
592 const auto &item = *it;
593 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);
594 if (item.flags.Test(EngineDisplayFlag::HasVariants) && IsInsideMM(r.left, r.right, pt.x)) {
595 /* toggle folded flag on engine */
596 assert(item.variant_id != EngineID::Invalid());
597 Engine *engine = Engine::Get(item.variant_id);
599
600 InvalidateWindowData(WindowClass::ReplaceVehicle, this->window_number, 0); // Update the autoreplace window
601 InvalidateWindowClassesData(WindowClass::BuildVehicle); // The build windows needs updating as well
602 return;
603 }
604 if (!item.flags.Test(EngineDisplayFlag::Shaded)) e = item.engine_id;
605 }
606
607 /* If Ctrl is pressed on the left side and we don't have any engines of the selected type, stop autoreplacing.
608 * This is most common when we have finished autoreplacing the engine and want to remove it from the list. */
609 if (click_side == 0 && IsCtrlPressed() && e != EngineID::Invalid() &&
611 EngineID veh_from = e;
612 Command<Commands::SetAutoreplace>::Post(this->sel_group, veh_from, EngineID::Invalid(), false);
613 break;
614 }
615
616 if (e == this->sel_engine[click_side]) break; // we clicked the one we already selected
617 this->sel_engine[click_side] = e;
618 if (click_side == 0) {
619 this->engines[1].ForceRebuild();
620 this->reset_sel_engine = true;
621 }
622 this->SetDirty();
623 break;
624 }
625 }
626 }
627
628 void OnDropdownSelect(WidgetID widget, int index, int) override
629 {
630 switch (widget) {
632 if (this->sort_criteria != index) {
633 this->sort_criteria = index;
634 _engine_sort_last_criteria[this->vehicle_type] = this->sort_criteria;
635 this->engines[1].ForceRebuild();
636 this->SetDirty();
637 }
638 break;
639
641 RailType temp = (RailType)index;
642 if (temp == this->sel_railtype) return; // we didn't select a new one. No need to change anything
643 this->sel_railtype = temp;
644 this->OnRailRoadTypeChange();
645 break;
646 }
647
649 RoadType temp = (RoadType)index;
650 if (temp == this->sel_roadtype) return; // we didn't select a new one. No need to change anything
651 this->sel_roadtype = temp;
652 this->OnRailRoadTypeChange();
653 break;
654 }
655
657 this->replace_engines = index != 0;
658 this->engines[0].ForceRebuild();
659 this->reset_sel_engine = true;
660 this->SetDirty();
661 break;
662 }
663
665 this->ReplaceClick_StartReplace(index != 0);
666 break;
667 }
668 }
669
670 bool OnTooltip([[maybe_unused]] Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
671 {
672 if (widget != WID_RV_TRAIN_WAGONREMOVE_TOGGLE) return false;
673
674 if (Group::IsValidID(this->sel_group)) {
675 GuiShowTooltips(this, GetEncodedString(STR_REPLACE_REMOVE_WAGON_GROUP_HELP, STR_REPLACE_REMOVE_WAGON_TOOLTIP), close_cond);
676 } else {
677 GuiShowTooltips(this, GetEncodedString(STR_REPLACE_REMOVE_WAGON_TOOLTIP), close_cond);
678 }
679 return true;
680 }
681
682 void OnResize() override
683 {
684 this->vscroll[0]->SetCapacityFromWidget(this, WID_RV_LEFT_MATRIX);
685 this->vscroll[1]->SetCapacityFromWidget(this, WID_RV_RIGHT_MATRIX);
686 }
687
693 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
694 {
695 if (data != 0) {
696 /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
697 this->engines[0].ForceRebuild();
698 } else {
699 this->engines[1].ForceRebuild();
700 }
701 }
702};
703
704static constexpr std::initializer_list<NWidgetPart> _nested_replace_rail_vehicle_widgets = {
711 EndContainer(),
714 NWidget(WWT_LABEL, Colours::Invalid), SetStringTip(STR_REPLACE_VEHICLE_VEHICLES_IN_USE, STR_REPLACE_VEHICLE_VEHICLES_IN_USE_TOOLTIP), SetFill(1, 1), SetMinimalTextLines(1, WidgetDimensions::unscaled.framerect.Vertical()), SetResize(1, 0),
715 EndContainer(),
717 NWidget(WWT_LABEL, Colours::Invalid), SetStringTip(STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES, STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES_TOOLTIP), SetFill(1, 1), SetMinimalTextLines(1, WidgetDimensions::unscaled.framerect.Vertical()), SetResize(1, 0),
718 EndContainer(),
719 EndContainer(),
723 NWidget(WWT_DROPDOWN, Colours::Grey, WID_RV_RAIL_TYPE_DROPDOWN), SetMinimalSize(136, 12), SetToolTip(STR_REPLACE_RAILTYPE_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
724 NWidget(WWT_DROPDOWN, Colours::Grey, WID_RV_TRAIN_ENGINEWAGON_DROPDOWN), SetToolTip(STR_REPLACE_ENGINE_WAGON_SELECT_TOOLTIP),
725 EndContainer(),
727 EndContainer(),
730 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_RV_SORT_ASCENDING_DESCENDING), SetStringTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), SetFill(1, 1),
731 NWidget(WWT_DROPDOWN, Colours::Grey, WID_RV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 1), SetToolTip(STR_TOOLTIP_SORT_CRITERIA),
732 EndContainer(),
734 NWidget(WWT_TEXTBTN, Colours::Grey, WID_RV_SHOW_HIDDEN_ENGINES), SetStringTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP),
736 EndContainer(),
737 EndContainer(),
738 EndContainer(),
744 EndContainer(),
749 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_RV_TRAIN_WAGONREMOVE_TOGGLE), SetMinimalSize(138, 12), SetToolTip(STR_REPLACE_REMOVE_WAGON_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
750 EndContainer(),
751 EndContainer(),
753 NWidget(NWID_PUSHBUTTON_DROPDOWN, Colours::Grey, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetStringTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_START_BUTTON_TOOLTIP),
754 NWidget(WWT_PANEL, Colours::Grey, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetToolTip(STR_REPLACE_REPLACE_INFO_TAB_TOOLTIP), SetResize(1, 0),
755 EndContainer(),
756 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_RV_STOP_REPLACE), SetMinimalSize(150, 12), SetStringTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_STOP_BUTTON_TOOLTIP),
758 EndContainer(),
759};
760
763 WindowPosition::Automatic, "replace_vehicle_train", 500, 140,
764 WindowClass::ReplaceVehicle, WindowClass::None,
766 _nested_replace_rail_vehicle_widgets
767);
768
769static constexpr std::initializer_list<NWidgetPart> _nested_replace_road_vehicle_widgets = {
776 EndContainer(),
779 NWidget(WWT_LABEL, Colours::Invalid), SetStringTip(STR_REPLACE_VEHICLE_VEHICLES_IN_USE, STR_REPLACE_VEHICLE_VEHICLES_IN_USE_TOOLTIP), SetFill(1, 1), SetMinimalTextLines(1, WidgetDimensions::unscaled.framerect.Vertical()), SetResize(1, 0),
780 EndContainer(),
782 NWidget(WWT_LABEL, Colours::Invalid), SetStringTip(STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES, STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES_TOOLTIP), SetFill(1, 1), SetMinimalTextLines(1, WidgetDimensions::unscaled.framerect.Vertical()), SetResize(1, 0),
783 EndContainer(),
784 EndContainer(),
787 NWidget(WWT_DROPDOWN, Colours::Grey, WID_RV_ROAD_TYPE_DROPDOWN), SetMinimalSize(136, 12), SetToolTip(STR_REPLACE_ROADTYPE_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
789 EndContainer(),
792 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_RV_SORT_ASCENDING_DESCENDING), SetStringTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), SetFill(1, 1),
793 NWidget(WWT_DROPDOWN, Colours::Grey, WID_RV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 1), SetToolTip(STR_TOOLTIP_SORT_CRITERIA),
794 EndContainer(),
796 NWidget(WWT_TEXTBTN, Colours::Grey, WID_RV_SHOW_HIDDEN_ENGINES), SetStringTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP),
798 EndContainer(),
799 EndContainer(),
800 EndContainer(),
806 EndContainer(),
810 EndContainer(),
812 NWidget(NWID_PUSHBUTTON_DROPDOWN, Colours::Grey, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetStringTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_START_BUTTON_TOOLTIP),
813 NWidget(WWT_PANEL, Colours::Grey, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetToolTip(STR_REPLACE_REPLACE_INFO_TAB_TOOLTIP), SetResize(1, 0),
814 EndContainer(),
815 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_RV_STOP_REPLACE), SetMinimalSize(150, 12), SetStringTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_STOP_BUTTON_TOOLTIP),
817 EndContainer(),
818};
819
822 WindowPosition::Automatic, "replace_vehicle_road", 500, 140,
823 WindowClass::ReplaceVehicle, WindowClass::None,
825 _nested_replace_road_vehicle_widgets
826);
827
828static constexpr std::initializer_list<NWidgetPart> _nested_replace_vehicle_widgets = {
835 EndContainer(),
838 NWidget(WWT_LABEL, Colours::Invalid), SetStringTip(STR_REPLACE_VEHICLE_VEHICLES_IN_USE, STR_REPLACE_VEHICLE_VEHICLES_IN_USE_TOOLTIP), SetFill(1, 1), SetMinimalTextLines(1, WidgetDimensions::unscaled.framerect.Vertical()), SetResize(1, 0),
839 EndContainer(),
841 NWidget(WWT_LABEL, Colours::Invalid), SetStringTip(STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES, STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES_TOOLTIP), SetFill(1, 1), SetMinimalTextLines(1, WidgetDimensions::unscaled.framerect.Vertical()), SetResize(1, 0),
842 EndContainer(),
843 EndContainer(),
848 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_RV_SORT_ASCENDING_DESCENDING), SetStringTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
849 NWidget(WWT_DROPDOWN, Colours::Grey, WID_RV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 1), SetToolTip(STR_TOOLTIP_SORT_CRITERIA),
850 EndContainer(),
852 NWidget(WWT_TEXTBTN, Colours::Grey, WID_RV_SHOW_HIDDEN_ENGINES), SetStringTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP),
854 EndContainer(),
855 EndContainer(),
856 EndContainer(),
862 EndContainer(),
866 EndContainer(),
868 NWidget(NWID_PUSHBUTTON_DROPDOWN, Colours::Grey, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetStringTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_START_BUTTON_TOOLTIP),
869 NWidget(WWT_PANEL, Colours::Grey, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetToolTip(STR_REPLACE_REPLACE_INFO_TAB_TOOLTIP), SetResize(1, 0), EndContainer(),
870 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_RV_STOP_REPLACE), SetMinimalSize(138, 12), SetStringTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_STOP_BUTTON_TOOLTIP),
872 EndContainer(),
873};
874
877 WindowPosition::Automatic, "replace_vehicle", 456, 118,
878 WindowClass::ReplaceVehicle, WindowClass::None,
880 _nested_replace_vehicle_widgets
881);
882
888void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
889{
890 CloseWindowById(WindowClass::ReplaceVehicle, vehicletype);
891 switch (vehicletype) {
892 case VehicleType::Train: new ReplaceVehicleWindow(_replace_rail_vehicle_desc, vehicletype, id_g); break;
893 case VehicleType::Road: new ReplaceVehicleWindow(_replace_road_vehicle_desc, vehicletype, id_g); break;
894 default: new ReplaceVehicleWindow(_replace_vehicle_desc, vehicletype, id_g); break;
895 }
896}
bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company)
Checks some basic properties whether autoreplace is allowed.
Command definitions related to autoreplace.
Functions related to autoreplacing.
bool EngineHasReplacementWhenOldForCompany(const Company *c, EngineID engine, GroupID group)
Check if a company has a replacement set up for the given engine when it gets old.
EngineID EngineReplacementForCompany(const Company *c, EngineID engine, GroupID group, bool *replace_when_old=nullptr)
Retrieve the engine replacement for the given company and original engine type.
bool EngineHasReplacementForCompany(const Company *c, EngineID engine, GroupID group)
Check if a company has a replacement set up for the given engine.
void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
Show the autoreplace configuration window for a particular group.
static WindowDesc _replace_road_vehicle_desc(WindowPosition::Automatic, "replace_vehicle_road", 500, 140, WindowClass::ReplaceVehicle, WindowClass::None, WindowDefaultFlag::Construction, _nested_replace_road_vehicle_widgets)
Window definition for the replace road vehicle window.
static bool EngineNumberSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Compare the (NewGRF) list position.
void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g)
Rebuild the left autoreplace list if an engine is removed or added.
void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type)
When an engine is made buildable or is removed from being buildable, add/remove it from the build/aut...
static WindowDesc _replace_vehicle_desc(WindowPosition::Automatic, "replace_vehicle", 456, 118, WindowClass::ReplaceVehicle, WindowClass::None, WindowDefaultFlag::Construction, _nested_replace_vehicle_widgets)
Window definition for the replace ship/aircraft window.
static WindowDesc _replace_rail_vehicle_desc(WindowPosition::Automatic, "replace_vehicle_train", 500, 140, WindowClass::ReplaceVehicle, WindowClass::None, WindowDefaultFlag::Construction, _nested_replace_rail_vehicle_widgets)
Window definition for the replace rail vehicle window.
Types related to the autoreplace widgets.
@ WID_RV_SHOW_HIDDEN_ENGINES
Toggle whether to display the hidden vehicles.
@ WID_RV_TRAIN_ENGINEWAGON_DROPDOWN
Dropdown to select engines and/or wagons.
@ WID_RV_LEFT_SCROLLBAR
The scrollbar for the matrix on the left.
@ WID_RV_CAPTION
Caption of the window.
@ WID_RV_RIGHT_DETAILS
Details of the entry on the right.
@ WID_RV_TRAIN_WAGONREMOVE_TOGGLE
Button to toggle removing wagons.
@ WID_RV_STOP_REPLACE
Stop Replacing button.
@ WID_RV_ROAD_TYPE_DROPDOWN
Dropdown to select roadtype.
@ WID_RV_RIGHT_MATRIX
The matrix on the right.
@ WID_RV_INFO_TAB
Info tab.
@ WID_RV_RAIL_TYPE_DROPDOWN
Dropdown to select railtype.
@ WID_RV_LEFT_MATRIX
The matrix on the left.
@ WID_RV_SORT_ASCENDING_DESCENDING
Ascending/descending sort order button.
@ WID_RV_RIGHT_SCROLLBAR
The scrollbar for the matrix on the right.
@ WID_RV_START_REPLACE
Start Replacing button.
@ WID_RV_SORT_DROPDOWN
Dropdown for the sort criteria.
@ WID_RV_LEFT_DETAILS
Details of the entry on the left.
void GUIEngineListAddChildren(GUIEngineList &dst, const GUIEngineList &src, EngineID parent, uint8_t indent)
Add children to GUI engine list to build a hierarchical tree.
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.
uint GetEngineListHeight(VehicleType type)
Get the height of a single 'entry' in the engine lists.
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.
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.
bool _engine_sort_direction
false = descending, true = ascending.
std::span< EngList_SortTypeFunction *const > GetEngineSortFunctions(VehicleType vehicle_type)
Get the engine sorter functions for a VehicleType.
VehicleTypeIndexArray< bool > _engine_sort_last_order
Last set direction of the sort order, for each vehicle type.
VehicleTypeIndexArray< bool > _engine_sort_show_hidden_engines
Last set 'show hidden engines' setting for each vehicle type.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Flip()
Flip all bits.
static Pool::IterateWrapperFiltered< Engine, EngineTypeFilter > IterateType(VehicleType vt, size_t from=0)
Returns an iterable ensemble of all valid engines of the given type.
EngineDisplayFlags display_flags
NOSAVE client-side-only display flags for build engine list.
Definition engine_base.h:66
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.
Base class for a 'real' widget.
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
StringID replace_text
Text used in the autoreplace GUI.
Definition rail.h:188
Window for the autoreplacing of vehicles.
void OnInit() override
Notification that the nested widget tree gets initialized.
void OnResize() override
Called after the window got resized.
bool GenerateReplaceRailList(EngineID e, bool draw_left, bool show_engines)
Figure out if an engine should be added to a list.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void ReplaceClick_StartReplace(bool replace_when_old)
Handle click on the start replace button.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
bool OnTooltip(Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
Event to display a custom tooltip.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
uint8_t sort_criteria
Criteria of sorting vehicles.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
RailType sel_railtype
Type of rail tracks selected. INVALID_RAILTYPE to show all.
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.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
bool replace_engines
If true, engines are replaced, if false, wagons are replaced (only for trains).
bool reset_sel_engine
Also reset sel_engine while updating left and/or right and no valid engine selected.
void OnPaint() override
The window must be repainted.
bool show_hidden_engines
Whether to show the hidden engines.
void GenerateLists()
Generate the lists.
RoadType sel_roadtype
Type of road selected. INVALID_ROADTYPE to show all.
std::array< GUIEngineList, 2 > engines
Left and right list of engines.
VehicleType vehicle_type
Type of vehicle in this window.
int details_height
Minimal needed height of the details panels, in text lines (found so far).
void GenerateReplaceVehList(bool draw_left)
Generate an engines list.
GroupID sel_group
Group selected to replace.
std::array< EngineID, 2 > sel_engine
Selected engine left and right.
bool descending_sort_order
Order of sorting vehicles.
void OnRailRoadTypeChange()
Perform tasks after rail or road type is changed.
StringID replace_text
Text used in the autoreplace GUI.
Definition road.h:83
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:94
Functions related to commands.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
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 > MakeDropDownListStringItem(StringID str, int value, bool masked, bool shaded)
Creates new DropDownListStringItem.
Definition dropdown.cpp:49
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.
@ Filterable
Set if the dropdown is filterable.
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
void EngList_Sort(GUIEngineList &el, EngList_SortTypeFunction compare)
Sort all items using quick sort and given 'CompareItems' function.
Engine GUI functions, used by build_vehicle_gui and autoreplace_gui.
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).
@ 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
fluid_settings_t * settings
FluidSynth settings handle.
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.
@ Centre
Align to the centre.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:894
Dimension GetStringListBoundingBox(std::span< const StringID > list, FontSize fontsize)
Get maximum dimension of a list of strings.
Definition gfx.cpp:933
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 IsCtrlPressed()
Test if the ctrl key is pressed.
Definition gfx_func.h:82
@ Normal
Index of the normal font in the font tables.
Definition gfx_type.h:249
@ Invalid
Invalid marker.
Definition gfx_type.h:302
@ Grey
Grey.
Definition gfx_type.h:299
@ Black
Black colour.
Definition gfx_type.h:334
@ ReplaceWagonRemoval
If set, autoreplace will perform wagon removal on vehicles in this group.
Definition group.h:69
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 SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FontSize::Normal)
Widget part function for setting the minimal text lines.
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 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.
Command definitions related to engine groups.
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
static constexpr GroupID ALL_GROUP
All vehicles are in this group.
Definition group_type.h:17
#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.
void GuiShowTooltips(Window *parent, EncodedString &&text, TooltipCloseCondition close_tooltip)
Shows a tooltip.
Definition misc_gui.cpp:690
GrfSpecFeature GetGrfSpecFeature(VehicleType type)
Get the GrfSpecFeature associated with a VehicleType.
Definition newgrf.cpp:1889
Rail specific functions.
std::vector< RailType > _sorted_railtypes
Sorted list of rail types.
Definition rail_cmd.cpp:46
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition rail.h:320
DropDownList GetRailTypeDropDownList(bool for_replacement, bool all_option)
Create a drop down list for all the rail types of the local company.
Functions/types etc.
RailType
Enumeration for all possible railtypes.
Definition rail_type.h:26
@ INVALID_RAILTYPE
Flag for invalid railtype.
Definition rail_type.h:33
Road specific functions.
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition road.h:217
std::vector< RoadType > _sorted_roadtypes
Sorted list of road types.
Definition road_cmd.cpp:56
Functions/types related to the road GUIs.
static constexpr RoadTramTypes ROADTRAMTYPES_ALL
All possible RoadTramTypes.
Definition road_type.h:49
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.
Command definitions related to settings.
Functions related to setting/changing the settings.
Definition of base types and functions in a cross-platform compatible way.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:89
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.
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.
CompanySettings settings
settings specific for each company
bool renew_keep_length
sell some wagons if after autoreplace the train is longer than before
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.
EngineID variant_id
Engine variant ID. If set, will be treated specially in purchase lists.
EngineID engine_id
Engine to display in build purchase list.
Definition engine_gui.h:22
Group data.
Definition group.h:76
GroupFlags flags
Group flags.
Definition group.h:81
static Engine * Get(auto index)
static bool IsValidID(auto index)
static Group * GetIfValid(auto index)
Information about a rail vehicle.
Definition engine_type.h:73
RailTypes railtypes
Railtypes, mangled if elrail is disabled.
Definition engine_type.h:77
RailVehicleType railveh_type
Type of rail vehicle.
Definition engine_type.h:75
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.
Information about a road vehicle.
RoadType roadtype
Road type.
Extra information about refitted cargo and capacity.
Definition vehicle_gui.h:41
Money cost
Refit cost.
Definition vehicle_gui.h:42
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
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
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:792
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 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
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.
void HandleButtonClick(WidgetID widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
Definition window.cpp:604
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
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:301
Functions related to the vehicle's GUIs.
VehicleType
Available vehicle types.
@ Invalid
Non-existing type of vehicle.
@ Road
Road vehicle type.
@ Train
Train vehicle type.
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
@ WWT_LABEL
Centered label.
Definition widget_type.h:48
@ 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
@ EqualSize
Containers should keep all their (resizing) children equally large.
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.
Functions, definitions and such used only by the GUI.
@ Construction
This window is used for construction; close it whenever changing company.
Definition window_gui.h:154
TooltipCloseCondition
Definition window_gui.h:262
@ Automatic
Find a place automatically.
Definition window_gui.h:145
int WidgetID
Widget ID.
Definition window_type.h:21