OpenTTD Source: src/autoreplace_gui.cpp Source File

OpenTTD Source 15.0-beta1

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 <http://www.gnu.org/licenses/>.
6 */
7
10#include "stdafx.h"
11#include "command_func.h"
12#include "vehicle_gui.h"
13#include "newgrf_engine.h"
14#include "rail.h"
15#include "road.h"
16#include "strings_func.h"
17#include "window_func.h"
18#include "autoreplace_func.h"
19#include "company_func.h"
20#include "engine_base.h"
21#include "window_gui.h"
22#include "engine_gui.h"
23#include "settings_func.h"
24#include "core/geometry_func.hpp"
25#include "rail_gui.h"
26#include "road_gui.h"
27#include "dropdown_type.h"
28#include "dropdown_func.h"
29#include "autoreplace_cmd.h"
30#include "group_cmd.h"
31#include "settings_cmd.h"
32
33#include "widgets/autoreplace_widget.h"
34
35#include "safeguards.h"
36
37static bool EngineNumberSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
38{
39 return Engine::Get(a.engine_id)->list_position < Engine::Get(b.engine_id)->list_position;
40}
41
51 void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g)
52{
53 if (GetGroupNumEngines(_local_company, id_g, e) == 0 || GetGroupNumEngines(_local_company, ALL_GROUP, e) == 0) {
54 /* We don't have any of this engine type.
55 * Either we just sold the last one, we build a new one or we stopped replacing it.
56 * In all cases, we need to update the left list */
57 InvalidateWindowData(WC_REPLACE_VEHICLE, Engine::Get(e)->type, 1);
58 }
59}
60
65 void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type)
66{
67 InvalidateWindowData(WC_REPLACE_VEHICLE, type, 0); // Update the autoreplace window
68 InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well
69}
70
71static const StringID _start_replace_dropdown[] = {
72 STR_REPLACE_VEHICLES_NOW,
73 STR_REPLACE_VEHICLES_WHEN_OLD,
74};
75
79 class ReplaceVehicleWindow : public Window {
80 EngineID sel_engine[2];
81 GUIEngineList engines[2];
82 bool replace_engines;
83 bool reset_sel_engine;
84 GroupID sel_group;
85 int details_height;
86 uint8_t sort_criteria;
87 bool descending_sort_order;
88 bool show_hidden_engines;
89 RailType sel_railtype;
90 RoadType sel_roadtype;
91 Scrollbar *vscroll[2];
92
100 bool GenerateReplaceRailList(EngineID e, bool draw_left, bool show_engines)
101 {
102 const RailVehicleInfo *rvi = RailVehInfo(e);
103
104 /* Ensure that the wagon/engine selection fits the engine. */
105 if ((rvi->railveh_type == RAILVEH_WAGON) == show_engines) return false;
106
107 if (draw_left && this->sel_railtype != INVALID_RAILTYPE) {
108 /* Ensure that the railtype is specific to the selected one */
109 if (rvi->railtype != this->sel_railtype) return false;
110 }
111 return true;
112 }
113
118 void GenerateReplaceVehList(bool draw_left)
119 {
120 std::vector<EngineID> variants;
121 EngineID selected_engine = INVALID_ENGINE;
122 VehicleType type = (VehicleType)this->window_number;
123 uint8_t side = draw_left ? 0 : 1;
124
125 GUIEngineList list;
126
127 for (const Engine *e : Engine::IterateType(type)) {
128 if (!draw_left && !this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue;
129 EngineID eid = e->index;
130 switch (type) {
131 case VEH_TRAIN:
132 if (!this->GenerateReplaceRailList(eid, draw_left, this->replace_engines)) continue; // special rules for trains
133 break;
134
135 case VEH_ROAD:
136 if (draw_left && this->sel_roadtype != INVALID_ROADTYPE) {
137 /* Ensure that the roadtype is specific to the selected one */
138 if (e->u.road.roadtype != this->sel_roadtype) continue;
139 }
140 break;
141
142 default:
143 break;
144 }
145
146 if (draw_left) {
147 const uint num_engines = GetGroupNumEngines(_local_company, this->sel_group, eid);
148
149 /* Skip drawing the engines we don't have any of and haven't set for replacement */
150 if (num_engines == 0 && EngineReplacementForCompany(Company::Get(_local_company), eid, this->sel_group) == INVALID_ENGINE) continue;
151 } else {
152 if (!CheckAutoreplaceValidity(this->sel_engine[0], eid, _local_company)) continue;
153 }
154
155 list.emplace_back(eid, e->info.variant_id, (side == 0) ? EngineDisplayFlags::None : e->display_flags, 0);
156
157 if (side == 1) {
158 EngineID parent = e->info.variant_id;
159 while (parent != INVALID_ENGINE) {
160 variants.push_back(parent);
161 parent = Engine::Get(parent)->info.variant_id;
162 }
163 }
164 if (eid == this->sel_engine[side]) selected_engine = eid; // The selected engine is still in the list
165 }
166
167 if (side == 1) {
168 /* ensure primary engine of variant group is in list */
169 for (const auto &variant : variants) {
170 if (std::ranges::find(list, variant, &GUIEngineListItem::engine_id) == list.end()) {
171 const Engine *e = Engine::Get(variant);
172 list.emplace_back(variant, e->info.variant_id, e->display_flags | EngineDisplayFlags::Shaded, 0);
173 }
174 }
175 }
176
177 this->sel_engine[side] = selected_engine; // update which engine we selected (the same or none, if it's not in the list anymore)
178 if (draw_left) {
179 EngList_Sort(list, &EngineNumberSorter);
180 } else {
181 _engine_sort_direction = this->descending_sort_order;
182 EngList_Sort(list, _engine_sort_functions[this->window_number][this->sort_criteria]);
183 }
184
185 this->engines[side].clear();
186 if (side == 1) {
187 GUIEngineListAddChildren(this->engines[side], list);
188 } else {
189 this->engines[side].swap(list);
190 }
191 }
192
194 void GenerateLists()
195 {
196 EngineID e = this->sel_engine[0];
197
198 if (this->engines[0].NeedRebuild()) {
199 /* We need to rebuild the left engines list */
200 this->GenerateReplaceVehList(true);
201 this->vscroll[0]->SetCount(this->engines[0].size());
202 if (this->reset_sel_engine && this->sel_engine[0] == INVALID_ENGINE && !this->engines[0].empty()) {
203 this->sel_engine[0] = this->engines[0][0].engine_id;
204 }
205 }
206
207 if (this->engines[1].NeedRebuild() || e != this->sel_engine[0]) {
208 /* Either we got a request to rebuild the right engines list, or the left engines list selected a different engine */
209 if (this->sel_engine[0] == INVALID_ENGINE) {
210 /* Always empty the right engines list when nothing is selected in the left engines list */
211 this->engines[1].clear();
212 this->sel_engine[1] = INVALID_ENGINE;
213 this->vscroll[1]->SetCount(this->engines[1].size());
214 } else {
215 if (this->reset_sel_engine && this->sel_engine[0] != INVALID_ENGINE) {
216 /* Select the current replacement for sel_engine[0]. */
217 const Company *c = Company::Get(_local_company);
218 this->sel_engine[1] = EngineReplacementForCompany(c, this->sel_engine[0], this->sel_group);
219 }
220 /* Regenerate the list on the right. Note: This resets sel_engine[1] to INVALID_ENGINE, if it is no longer available. */
221 this->GenerateReplaceVehList(false);
222 this->vscroll[1]->SetCount(this->engines[1].size());
223 if (this->reset_sel_engine && this->sel_engine[1] != INVALID_ENGINE) {
224 int position = 0;
225 for (const auto &item : this->engines[1]) {
226 if (item.engine_id == this->sel_engine[1]) break;
227 ++position;
228 }
229 this->vscroll[1]->ScrollTowards(position);
230 }
231 }
232 }
233 /* Reset the flags about needed updates */
234 this->engines[0].RebuildDone();
235 this->engines[1].RebuildDone();
236 this->reset_sel_engine = false;
237 }
238
243 void ReplaceClick_StartReplace(bool replace_when_old)
244 {
245 EngineID veh_from = this->sel_engine[0];
246 EngineID veh_to = this->sel_engine[1];
247 Command<CMD_SET_AUTOREPLACE>::Post(this->sel_group, veh_from, veh_to, replace_when_old);
248 }
249
253 void OnRailRoadTypeChange()
254 {
255 /* Reset scrollbar positions */
256 this->vscroll[0]->SetPosition(0);
257 this->vscroll[1]->SetPosition(0);
258 /* Rebuild the lists */
259 this->engines[0].ForceRebuild();
260 this->engines[1].ForceRebuild();
261 this->reset_sel_engine = true;
262 this->SetDirty();
263 }
264
265public:
266 ReplaceVehicleWindow(WindowDesc &desc, VehicleType vehicletype, GroupID id_g) : Window(desc)
267 {
268 this->sel_railtype = INVALID_RAILTYPE;
269 this->sel_roadtype = INVALID_ROADTYPE;
270 this->replace_engines = true; // start with locomotives (all other vehicles will not read this bool)
271 this->engines[0].ForceRebuild();
272 this->engines[1].ForceRebuild();
273 this->reset_sel_engine = true;
274 this->details_height = ((vehicletype == VEH_TRAIN) ? 10 : 9);
275 this->sel_engine[0] = INVALID_ENGINE;
276 this->sel_engine[1] = INVALID_ENGINE;
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
283 NWidgetCore *widget = this->GetWidget<NWidgetCore>(WID_RV_SHOW_HIDDEN_ENGINES);
284 widget->widget_data = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + vehicletype;
285 widget->tool_tip = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + vehicletype;
286 widget->SetLowered(this->show_hidden_engines);
287 this->FinishInitNested(vehicletype);
288
289 this->sort_criteria = _engine_sort_last_criteria[vehicletype];
290 this->descending_sort_order = _engine_sort_last_order[vehicletype];
291 this->owner = _local_company;
292 this->sel_group = id_g;
293 }
294
295 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
296 {
297 switch (widget) {
298 case WID_RV_SORT_ASCENDING_DESCENDING: {
299 Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
300 d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
301 d.height += padding.height;
302 size = maxdim(size, d);
303 break;
304 }
305
306 case WID_RV_LEFT_MATRIX:
307 case WID_RV_RIGHT_MATRIX:
308 resize.height = GetEngineListHeight((VehicleType)this->window_number);
309 size.height = (this->window_number <= VEH_ROAD ? 8 : 4) * resize.height;
310 break;
311
312 case WID_RV_LEFT_DETAILS:
313 case WID_RV_RIGHT_DETAILS:
314 size.height = GetCharacterHeight(FS_NORMAL) * this->details_height + padding.height;
315 break;
316
317 case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
318 StringID str = this->GetWidget<NWidgetCore>(widget)->widget_data;
319 SetDParam(0, STR_CONFIG_SETTING_ON);
320 Dimension d = GetStringBoundingBox(str);
321 SetDParam(0, STR_CONFIG_SETTING_OFF);
322 d = maxdim(d, GetStringBoundingBox(str));
323 d.width += padding.width;
324 d.height += padding.height;
325 size = maxdim(size, d);
326 break;
327 }
328
329 case WID_RV_TRAIN_ENGINEWAGON_DROPDOWN: {
330 Dimension d = GetStringBoundingBox(STR_REPLACE_ENGINES);
331 d = maxdim(d, GetStringBoundingBox(STR_REPLACE_WAGONS));
332 d.width += padding.width;
333 d.height += padding.height;
334 size = maxdim(size, d);
335 break;
336 }
337
338 case WID_RV_INFO_TAB: {
339 Dimension d = GetStringBoundingBox(STR_REPLACE_NOT_REPLACING);
340 d = maxdim(d, GetStringBoundingBox(STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED));
341 d.width += padding.width;
342 d.height += padding.height;
343 size = maxdim(size, d);
344 break;
345 }
346
347 case WID_RV_RAIL_TYPE_DROPDOWN: {
348 Dimension d = {0, 0};
349 for (const RailType &rt : _sorted_railtypes) {
350 d = maxdim(d, GetStringBoundingBox(GetRailTypeInfo(rt)->strings.replace_text));
351 }
352 d.width += padding.width;
353 d.height += padding.height;
354 size = maxdim(size, d);
355 break;
356 }
357
358 case WID_RV_ROAD_TYPE_DROPDOWN: {
359 Dimension d = {0, 0};
360 for (const RoadType &rt : _sorted_roadtypes) {
361 d = maxdim(d, GetStringBoundingBox(GetRoadTypeInfo(rt)->strings.replace_text));
362 }
363 d.width += padding.width;
364 d.height += padding.height;
365 size = maxdim(size, d);
366 break;
367 }
368
369 case WID_RV_START_REPLACE: {
370 Dimension d = GetStringBoundingBox(STR_REPLACE_VEHICLES_START);
371 d = maxdim(d, GetStringListBoundingBox(_start_replace_dropdown));
372 d.width += padding.width;
373 d.height += padding.height;
374 size = maxdim(size, d);
375 break;
376 }
377 }
378 }
379
380 void SetStringParameters(WidgetID widget) const override
381 {
382 switch (widget) {
383 case WID_RV_CAPTION:
384 SetDParam(0, STR_REPLACE_VEHICLE_TRAIN + this->window_number);
385 switch (this->sel_group) {
386 case ALL_GROUP:
387 SetDParam(1, STR_GROUP_ALL_TRAINS + this->window_number);
388 break;
389
390 case DEFAULT_GROUP:
391 SetDParam(1, STR_GROUP_DEFAULT_TRAINS + this->window_number);
392 break;
393
394 default:
395 SetDParam(1, STR_GROUP_NAME);
396 SetDParam(2, sel_group);
397 break;
398 }
399 break;
400
401 case WID_RV_SORT_DROPDOWN:
402 SetDParam(0, std::data(_engine_sort_listing[this->window_number])[this->sort_criteria]);
403 break;
404
405 case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
406 bool remove_wagon;
407 const Group *g = Group::GetIfValid(this->sel_group);
408 if (g != nullptr) {
409 remove_wagon = HasBit(g->flags, GroupFlags::GF_REPLACE_WAGON_REMOVAL);
410 SetDParam(0, STR_GROUP_NAME);
411 SetDParam(1, sel_group);
412 } else {
413 const Company *c = Company::Get(_local_company);
414 remove_wagon = c->settings.renew_keep_length;
415 SetDParam(0, STR_GROUP_DEFAULT_TRAINS + this->window_number);
416 }
417 SetDParam(2, remove_wagon ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
418 break;
419 }
420
421 case WID_RV_TRAIN_ENGINEWAGON_DROPDOWN:
422 SetDParam(0, this->replace_engines ? STR_REPLACE_ENGINES : STR_REPLACE_WAGONS);
423 break;
424
425 case WID_RV_RAIL_TYPE_DROPDOWN:
426 SetDParam(0, this->sel_railtype == INVALID_RAILTYPE ? STR_REPLACE_ALL_RAILTYPE : GetRailTypeInfo(this->sel_railtype)->strings.replace_text);
427 break;
428
429 case WID_RV_ROAD_TYPE_DROPDOWN:
430 SetDParam(0, this->sel_roadtype == INVALID_ROADTYPE ? STR_REPLACE_ALL_ROADTYPE : GetRoadTypeInfo(this->sel_roadtype)->strings.replace_text);
431 break;
432 }
433 }
434
435 void DrawWidget(const Rect &r, WidgetID widget) const override
436 {
437 switch (widget) {
438 case WID_RV_SORT_ASCENDING_DESCENDING:
439 this->DrawSortButtonState(WID_RV_SORT_ASCENDING_DESCENDING, this->descending_sort_order ? SBS_DOWN : SBS_UP);
440 break;
441
442 case WID_RV_INFO_TAB: {
443 const Company *c = Company::Get(_local_company);
444 StringID str;
445 if (this->sel_engine[0] != INVALID_ENGINE) {
446 if (!EngineHasReplacementForCompany(c, this->sel_engine[0], this->sel_group)) {
447 str = STR_REPLACE_NOT_REPLACING;
448 } else {
449 bool when_old = false;
450 EngineID e = EngineReplacementForCompany(c, this->sel_engine[0], this->sel_group, &when_old);
451 str = when_old ? STR_REPLACE_REPLACING_WHEN_OLD : STR_ENGINE_NAME;
452 SetDParam(0, PackEngineNameDParam(e, EngineNameContext::PurchaseList));
453 }
454 } else {
455 str = STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED;
456 }
457
458 DrawString(r.Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect), str, TC_BLACK, SA_HOR_CENTER);
459 break;
460 }
461
462 case WID_RV_LEFT_MATRIX:
463 case WID_RV_RIGHT_MATRIX: {
464 int side = (widget == WID_RV_LEFT_MATRIX) ? 0 : 1;
465
466 /* Do the actual drawing */
467 DrawEngineList((VehicleType)this->window_number, r, this->engines[side], *this->vscroll[side], this->sel_engine[side], side == 0, this->sel_group);
468 break;
469 }
470 }
471 }
472
473 void OnPaint() override
474 {
475 if (this->engines[0].NeedRebuild() || this->engines[1].NeedRebuild()) this->GenerateLists();
476
477 Company *c = Company::Get(_local_company);
478
479 /* Disable the "Start Replacing" button if:
480 * Either engines list is empty
481 * or The selected replacement engine has a replacement (to prevent loops). */
482 this->SetWidgetDisabledState(WID_RV_START_REPLACE,
483 this->sel_engine[0] == INVALID_ENGINE || this->sel_engine[1] == INVALID_ENGINE || EngineReplacementForCompany(c, this->sel_engine[1], this->sel_group) != INVALID_ENGINE);
484
485 /* Disable the "Stop Replacing" button if:
486 * The left engines list (existing vehicle) is empty
487 * or The selected vehicle has no replacement set up */
488 this->SetWidgetDisabledState(WID_RV_STOP_REPLACE, this->sel_engine[0] == INVALID_ENGINE || !EngineHasReplacementForCompany(c, this->sel_engine[0], this->sel_group));
489
490 this->DrawWidgets();
491
492 if (!this->IsShaded()) {
493 int needed_height = this->details_height;
494 /* Draw details panels. */
495 for (int side = 0; side < 2; side++) {
496 if (this->sel_engine[side] != INVALID_ENGINE) {
497 /* Use default engine details without refitting */
498 const Engine *e = Engine::Get(this->sel_engine[side]);
499 TestedEngineDetails ted;
500 ted.cost = 0;
501 ted.FillDefaultCapacities(e);
502
503 const Rect r = this->GetWidget<NWidgetBase>(side == 0 ? WID_RV_LEFT_DETAILS : WID_RV_RIGHT_DETAILS)->GetCurrentRect()
504 .Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect);
505 int text_end = DrawVehiclePurchaseInfo(r.left, r.right, r.top, this->sel_engine[side], ted);
506 needed_height = std::max(needed_height, (text_end - r.top) / GetCharacterHeight(FS_NORMAL));
507 }
508 }
509 if (needed_height != this->details_height) { // Details window are not high enough, enlarge them.
510 this->details_height = needed_height;
511 this->ReInit();
512 return;
513 }
514 }
515 }
516
517 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
518 {
519 switch (widget) {
520 case WID_RV_SORT_ASCENDING_DESCENDING:
521 this->descending_sort_order ^= true;
522 _engine_sort_last_order[this->window_number] = this->descending_sort_order;
523 this->engines[1].ForceRebuild();
524 this->SetDirty();
525 break;
526
527 case WID_RV_SHOW_HIDDEN_ENGINES:
528 this->show_hidden_engines ^= true;
529 _engine_sort_show_hidden_engines[this->window_number] = this->show_hidden_engines;
530 this->engines[1].ForceRebuild();
531 this->SetWidgetLoweredState(widget, this->show_hidden_engines);
532 this->SetDirty();
533 break;
534
535 case WID_RV_SORT_DROPDOWN:
536 DisplayVehicleSortDropDown(this, static_cast<VehicleType>(this->window_number), this->sort_criteria, WID_RV_SORT_DROPDOWN);
537 break;
538
539 case WID_RV_TRAIN_ENGINEWAGON_DROPDOWN: {
540 DropDownList list;
541 list.push_back(MakeDropDownListStringItem(STR_REPLACE_ENGINES, 1));
542 list.push_back(MakeDropDownListStringItem(STR_REPLACE_WAGONS, 0));
543 ShowDropDownList(this, std::move(list), this->replace_engines ? 1 : 0, WID_RV_TRAIN_ENGINEWAGON_DROPDOWN);
544 break;
545 }
546
547 case WID_RV_RAIL_TYPE_DROPDOWN: // Railtype selection dropdown menu
548 ShowDropDownList(this, GetRailTypeDropDownList(true, true), this->sel_railtype, widget);
549 break;
550
551 case WID_RV_ROAD_TYPE_DROPDOWN: // Roadtype selection dropdown menu
552 ShowDropDownList(this, GetRoadTypeDropDownList(RTTB_ROAD | RTTB_TRAM, true, true), this->sel_roadtype, widget);
553 break;
554
555 case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
556 const Group *g = Group::GetIfValid(this->sel_group);
557 if (g != nullptr) {
558 Command<CMD_SET_GROUP_FLAG>::Post(this->sel_group, GroupFlags::GF_REPLACE_WAGON_REMOVAL, !HasBit(g->flags, GroupFlags::GF_REPLACE_WAGON_REMOVAL), _ctrl_pressed);
559 } else {
560 // toggle renew_keep_length
561 Command<CMD_CHANGE_COMPANY_SETTING>::Post("company.renew_keep_length", Company::Get(_local_company)->settings.renew_keep_length ? 0 : 1);
562 }
563 break;
564 }
565
566 case WID_RV_START_REPLACE: { // Start replacing
567 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
568 this->HandleButtonClick(WID_RV_START_REPLACE);
569 ReplaceClick_StartReplace(false);
570 } else {
571 bool replacment_when_old = EngineHasReplacementWhenOldForCompany(Company::Get(_local_company), this->sel_engine[0], this->sel_group);
572 ShowDropDownMenu(this, _start_replace_dropdown, replacment_when_old ? 1 : 0, WID_RV_START_REPLACE, !this->replace_engines ? 1 << 1 : 0, 0);
573 }
574 break;
575 }
576
577 case WID_RV_STOP_REPLACE: { // Stop replacing
578 EngineID veh_from = this->sel_engine[0];
579 Command<CMD_SET_AUTOREPLACE>::Post(this->sel_group, veh_from, INVALID_ENGINE, false);
580 break;
581 }
582
583 case WID_RV_LEFT_MATRIX:
584 case WID_RV_RIGHT_MATRIX: {
585 uint8_t click_side;
586 if (widget == WID_RV_LEFT_MATRIX) {
587 click_side = 0;
588 } else {
589 click_side = 1;
590 }
591
592 EngineID e = INVALID_ENGINE;
593 const auto it = this->vscroll[click_side]->GetScrolledItemFromWidget(this->engines[click_side], pt.y, this, widget);
594 if (it != this->engines[click_side].end()) {
595 const auto &item = *it;
596 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);
597 if (HasFlag(item.flags, EngineDisplayFlags::HasVariants) && IsInsideMM(r.left, r.right, pt.x)) {
598 /* toggle folded flag on engine */
599 assert(item.variant_id != INVALID_ENGINE);
600 Engine *engine = Engine::Get(item.variant_id);
601 engine->display_flags ^= EngineDisplayFlags::IsFolded;
602
603 InvalidateWindowData(WC_REPLACE_VEHICLE, (VehicleType)this->window_number, 0); // Update the autoreplace window
604 InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well
605 return;
606 }
607 if (!HasFlag(item.flags, EngineDisplayFlags::Shaded)) e = item.engine_id;
608 }
609
610 /* If Ctrl is pressed on the left side and we don't have any engines of the selected type, stop autoreplacing.
611 * This is most common when we have finished autoreplacing the engine and want to remove it from the list. */
612 if (click_side == 0 && _ctrl_pressed && e != INVALID_ENGINE &&
613 (GetGroupNumEngines(_local_company, sel_group, e) == 0 || GetGroupNumEngines(_local_company, ALL_GROUP, e) == 0)) {
614 EngineID veh_from = e;
615 Command<CMD_SET_AUTOREPLACE>::Post(this->sel_group, veh_from, INVALID_ENGINE, false);
616 break;
617 }
618
619 if (e == this->sel_engine[click_side]) break; // we clicked the one we already selected
620 this->sel_engine[click_side] = e;
621 if (click_side == 0) {
622 this->engines[1].ForceRebuild();
623 this->reset_sel_engine = true;
624 }
625 this->SetDirty();
626 break;
627 }
628 }
629 }
630
631 void OnDropdownSelect(WidgetID widget, int index) override
632 {
633 switch (widget) {
634 case WID_RV_SORT_DROPDOWN:
635 if (this->sort_criteria != index) {
636 this->sort_criteria = index;
637 _engine_sort_last_criteria[this->window_number] = this->sort_criteria;
638 this->engines[1].ForceRebuild();
639 this->SetDirty();
640 }
641 break;
642
643 case WID_RV_RAIL_TYPE_DROPDOWN: {
644 RailType temp = (RailType)index;
645 if (temp == this->sel_railtype) return; // we didn't select a new one. No need to change anything
646 this->sel_railtype = temp;
647 this->OnRailRoadTypeChange();
648 break;
649 }
650
651 case WID_RV_ROAD_TYPE_DROPDOWN: {
652 RoadType temp = (RoadType)index;
653 if (temp == this->sel_roadtype) return; // we didn't select a new one. No need to change anything
654 this->sel_roadtype = temp;
655 this->OnRailRoadTypeChange();
656 break;
657 }
658
659 case WID_RV_TRAIN_ENGINEWAGON_DROPDOWN: {
660 this->replace_engines = index != 0;
661 this->engines[0].ForceRebuild();
662 this->reset_sel_engine = true;
663 this->SetDirty();
664 break;
665 }
666
667 case WID_RV_START_REPLACE:
668 this->ReplaceClick_StartReplace(index != 0);
669 break;
670 }
671 }
672
673 bool OnTooltip([[maybe_unused]] Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
674 {
675 if (widget != WID_RV_TRAIN_WAGONREMOVE_TOGGLE) return false;
676
677 if (Group::IsValidID(this->sel_group)) {
678 SetDParam(0, STR_REPLACE_REMOVE_WAGON_HELP);
679 GuiShowTooltips(this, STR_REPLACE_REMOVE_WAGON_GROUP_HELP, close_cond, 1);
680 } else {
681 GuiShowTooltips(this, STR_REPLACE_REMOVE_WAGON_HELP, close_cond);
682 }
683 return true;
684 }
685
686 void OnResize() override
687 {
688 this->vscroll[0]->SetCapacityFromWidget(this, WID_RV_LEFT_MATRIX);
689 this->vscroll[1]->SetCapacityFromWidget(this, WID_RV_RIGHT_MATRIX);
690 }
691
697 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
698 {
699 if (data != 0) {
700 /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
701 this->engines[0].ForceRebuild();
702 } else {
703 this->engines[1].ForceRebuild();
704 }
705 }
706};
707
708static constexpr NWidgetPart _nested_replace_rail_vehicle_widgets[] = {
709 NWidget(NWID_HORIZONTAL),
710 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
711 NWidget(WWT_CAPTION, COLOUR_GREY, WID_RV_CAPTION), SetDataTip(STR_REPLACE_VEHICLES_WHITE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
712 NWidget(WWT_SHADEBOX, COLOUR_GREY),
713 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
714 NWidget(WWT_STICKYBOX, COLOUR_GREY),
715 EndContainer(),
716 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
717 NWidget(WWT_PANEL, COLOUR_GREY),
718 NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(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),
719 EndContainer(),
720 NWidget(WWT_PANEL, COLOUR_GREY),
721 NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES, STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES_TOOLTIP), SetFill(1, 1), SetMinimalTextLines(1, WidgetDimensions::unscaled.framerect.Vertical()), SetResize(1, 0),
722 EndContainer(),
723 EndContainer(),
724 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
725 NWidget(NWID_VERTICAL),
726 NWidget(NWID_HORIZONTAL),
727 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_RAIL_TYPE_DROPDOWN), SetMinimalSize(136, 12), SetDataTip(STR_JUST_STRING, STR_REPLACE_HELP_RAILTYPE), SetFill(1, 0), SetResize(1, 0),
728 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_TRAIN_ENGINEWAGON_DROPDOWN), SetDataTip(STR_JUST_STRING, STR_REPLACE_ENGINE_WAGON_SELECT_HELP),
729 EndContainer(),
730 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), EndContainer(),
731 EndContainer(),
732 NWidget(NWID_VERTICAL),
733 NWidget(NWID_HORIZONTAL),
734 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_SORT_ASCENDING_DESCENDING), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), SetFill(1, 1),
735 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
736 EndContainer(),
737 NWidget(NWID_HORIZONTAL),
738 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_RV_SHOW_HIDDEN_ENGINES), SetDataTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP),
739 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(),
740 EndContainer(),
741 EndContainer(),
742 EndContainer(),
743 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
744 NWidget(WWT_MATRIX, COLOUR_GREY, WID_RV_LEFT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_REPLACE_HELP_LEFT_ARRAY), SetResize(1, 1), SetScrollbar(WID_RV_LEFT_SCROLLBAR),
745 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_LEFT_SCROLLBAR),
746 NWidget(WWT_MATRIX, COLOUR_GREY, WID_RV_RIGHT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_REPLACE_HELP_RIGHT_ARRAY), SetResize(1, 1), SetScrollbar(WID_RV_RIGHT_SCROLLBAR),
747 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_RIGHT_SCROLLBAR),
748 EndContainer(),
749 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
750 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_LEFT_DETAILS), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
751 NWidget(NWID_VERTICAL),
752 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_RIGHT_DETAILS), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
753 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_TRAIN_WAGONREMOVE_TOGGLE), SetMinimalSize(138, 12), SetDataTip(STR_REPLACE_REMOVE_WAGON, STR_REPLACE_REMOVE_WAGON_HELP), SetFill(1, 0), SetResize(1, 0),
754 EndContainer(),
755 EndContainer(),
756 NWidget(NWID_HORIZONTAL),
757 NWidget(NWID_PUSHBUTTON_DROPDOWN, COLOUR_GREY, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON),
758 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB), SetResize(1, 0),
759 EndContainer(),
760 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_STOP_REPLACE), SetMinimalSize(150, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON),
761 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
762 EndContainer(),
763};
764
765static WindowDesc _replace_rail_vehicle_desc(
766 WDP_AUTO, "replace_vehicle_train", 500, 140,
767 WC_REPLACE_VEHICLE, WC_NONE,
768 WDF_CONSTRUCTION,
769 _nested_replace_rail_vehicle_widgets
770);
771
772static constexpr NWidgetPart _nested_replace_road_vehicle_widgets[] = {
773 NWidget(NWID_HORIZONTAL),
774 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
775 NWidget(WWT_CAPTION, COLOUR_GREY, WID_RV_CAPTION), SetDataTip(STR_REPLACE_VEHICLES_WHITE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
776 NWidget(WWT_SHADEBOX, COLOUR_GREY),
777 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
778 NWidget(WWT_STICKYBOX, COLOUR_GREY),
779 EndContainer(),
780 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
781 NWidget(WWT_PANEL, COLOUR_GREY),
782 NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(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),
783 EndContainer(),
784 NWidget(WWT_PANEL, COLOUR_GREY),
785 NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES, STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES_TOOLTIP), SetFill(1, 1), SetMinimalTextLines(1, WidgetDimensions::unscaled.framerect.Vertical()), SetResize(1, 0),
786 EndContainer(),
787 EndContainer(),
788 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
789 NWidget(NWID_VERTICAL),
790 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_ROAD_TYPE_DROPDOWN), SetMinimalSize(136, 12), SetDataTip(STR_JUST_STRING, STR_REPLACE_HELP_ROADTYPE), SetFill(1, 0), SetResize(1, 0),
791 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), EndContainer(),
792 EndContainer(),
793 NWidget(NWID_VERTICAL),
794 NWidget(NWID_HORIZONTAL),
795 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_SORT_ASCENDING_DESCENDING), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), SetFill(1, 1),
796 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
797 EndContainer(),
798 NWidget(NWID_HORIZONTAL),
799 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_RV_SHOW_HIDDEN_ENGINES), SetDataTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP),
800 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(),
801 EndContainer(),
802 EndContainer(),
803 EndContainer(),
804 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
805 NWidget(WWT_MATRIX, COLOUR_GREY, WID_RV_LEFT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_REPLACE_HELP_LEFT_ARRAY), SetResize(1, 1), SetScrollbar(WID_RV_LEFT_SCROLLBAR),
806 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_LEFT_SCROLLBAR),
807 NWidget(WWT_MATRIX, COLOUR_GREY, WID_RV_RIGHT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_REPLACE_HELP_RIGHT_ARRAY), SetResize(1, 1), SetScrollbar(WID_RV_RIGHT_SCROLLBAR),
808 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_RIGHT_SCROLLBAR),
809 EndContainer(),
810 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
811 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_LEFT_DETAILS), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
812 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_RIGHT_DETAILS), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
813 EndContainer(),
814 NWidget(NWID_HORIZONTAL),
815 NWidget(NWID_PUSHBUTTON_DROPDOWN, COLOUR_GREY, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON),
816 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB), SetResize(1, 0),
817 EndContainer(),
818 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_STOP_REPLACE), SetMinimalSize(150, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON),
819 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
820 EndContainer(),
821};
822
823static WindowDesc _replace_road_vehicle_desc(
824 WDP_AUTO, "replace_vehicle_road", 500, 140,
825 WC_REPLACE_VEHICLE, WC_NONE,
826 WDF_CONSTRUCTION,
827 _nested_replace_road_vehicle_widgets
828);
829
830static constexpr NWidgetPart _nested_replace_vehicle_widgets[] = {
831 NWidget(NWID_HORIZONTAL),
832 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
833 NWidget(WWT_CAPTION, COLOUR_GREY, WID_RV_CAPTION), SetMinimalSize(433, 14), SetDataTip(STR_REPLACE_VEHICLES_WHITE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
834 NWidget(WWT_SHADEBOX, COLOUR_GREY),
835 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
836 NWidget(WWT_STICKYBOX, COLOUR_GREY),
837 EndContainer(),
838 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
839 NWidget(WWT_PANEL, COLOUR_GREY),
840 NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(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),
841 EndContainer(),
842 NWidget(WWT_PANEL, COLOUR_GREY),
843 NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES, STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES_TOOLTIP), SetFill(1, 1), SetMinimalTextLines(1, WidgetDimensions::unscaled.framerect.Vertical()), SetResize(1, 0),
844 EndContainer(),
845 EndContainer(),
846 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
847 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), EndContainer(),
848 NWidget(NWID_VERTICAL),
849 NWidget(NWID_HORIZONTAL),
850 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_SORT_ASCENDING_DESCENDING), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
851 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
852 EndContainer(),
853 NWidget(NWID_HORIZONTAL),
854 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_RV_SHOW_HIDDEN_ENGINES), SetDataTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP),
855 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(),
856 EndContainer(),
857 EndContainer(),
858 EndContainer(),
859 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
860 NWidget(WWT_MATRIX, COLOUR_GREY, WID_RV_LEFT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_REPLACE_HELP_LEFT_ARRAY), SetResize(1, 1), SetScrollbar(WID_RV_LEFT_SCROLLBAR),
861 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_LEFT_SCROLLBAR),
862 NWidget(WWT_MATRIX, COLOUR_GREY, WID_RV_RIGHT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_REPLACE_HELP_RIGHT_ARRAY), SetResize(1, 1), SetScrollbar(WID_RV_RIGHT_SCROLLBAR),
863 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_RIGHT_SCROLLBAR),
864 EndContainer(),
865 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
866 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_LEFT_DETAILS), SetMinimalSize(228, 92), SetResize(1, 0), EndContainer(),
867 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_RIGHT_DETAILS), SetMinimalSize(228, 92), SetResize(1, 0), EndContainer(),
868 EndContainer(),
869 NWidget(NWID_HORIZONTAL),
870 NWidget(NWID_PUSHBUTTON_DROPDOWN, COLOUR_GREY, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON),
871 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB), SetResize(1, 0), EndContainer(),
872 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_STOP_REPLACE), SetMinimalSize(138, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON),
873 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
874 EndContainer(),
875};
876
877static WindowDesc _replace_vehicle_desc(
878 WDP_AUTO, "replace_vehicle", 456, 118,
879 WC_REPLACE_VEHICLE, WC_NONE,
880 WDF_CONSTRUCTION,
881 _nested_replace_vehicle_widgets
882);
883
889 void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
890{
891 CloseWindowById(WC_REPLACE_VEHICLE, vehicletype);
892 switch (vehicletype) {
893 case VEH_TRAIN: new ReplaceVehicleWindow(_replace_rail_vehicle_desc, vehicletype, id_g); break;
894 case VEH_ROAD: new ReplaceVehicleWindow(_replace_road_vehicle_desc, vehicletype, id_g); break;
895 default: new ReplaceVehicleWindow(_replace_vehicle_desc, vehicletype, id_g); break;
896 }
897}
CheckAutoreplaceValidity
bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company)
Checks some basic properties whether autoreplace is allowed.
Definition autoreplace_cmd.cpp:60
autoreplace_cmd.h
Command definitions related to autoreplace.
autoreplace_func.h
Functions related to autoreplacing.
EngineHasReplacementWhenOldForCompany
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.
Definition autoreplace_func.h:63
EngineReplacementForCompany
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.
Definition autoreplace_func.h:39
EngineHasReplacementForCompany
bool EngineHasReplacementForCompany(const Company *c, EngineID engine, GroupID group)
Check if a company has a replacement set up for the given engine.
Definition autoreplace_func.h:51
ShowReplaceGroupVehicleWindow
void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
Show the autoreplace configuration window for a particular group.
Definition autoreplace_gui.cpp:889
InvalidateAutoreplaceWindow
void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g)
Rebuild the left autoreplace list if an engine is removed or added.
Definition autoreplace_gui.cpp:51
AddRemoveEngineFromAutoreplaceAndBuildWindows
void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type)
When an engine is made buildable or is removed from being buildable, add/remove it from the build/aut...
Definition autoreplace_gui.cpp:65
autoreplace_widget.h
Types related to the autoreplace widgets.
WID_RV_SHOW_HIDDEN_ENGINES
@ WID_RV_SHOW_HIDDEN_ENGINES
Toggle whether to display the hidden vehicles.
Definition autoreplace_widget.h:19
WID_RV_TRAIN_ENGINEWAGON_DROPDOWN
@ WID_RV_TRAIN_ENGINEWAGON_DROPDOWN
Dropdown to select engines and/or wagons.
Definition autoreplace_widget.h:37
WID_RV_LEFT_SCROLLBAR
@ WID_RV_LEFT_SCROLLBAR
The scrollbar for the matrix on the left.
Definition autoreplace_widget.h:24
WID_RV_CAPTION
@ WID_RV_CAPTION
Caption of the window.
Definition autoreplace_widget.h:15
WID_RV_RIGHT_DETAILS
@ WID_RV_RIGHT_DETAILS
Details of the entry on the right.
Definition autoreplace_widget.h:28
WID_RV_TRAIN_WAGONREMOVE_TOGGLE
@ WID_RV_TRAIN_WAGONREMOVE_TOGGLE
Button to toggle removing wagons.
Definition autoreplace_widget.h:38
WID_RV_STOP_REPLACE
@ WID_RV_STOP_REPLACE
Stop Replacing button.
Definition autoreplace_widget.h:33
WID_RV_ROAD_TYPE_DROPDOWN
@ WID_RV_ROAD_TYPE_DROPDOWN
Dropdown to select roadtype.
Definition autoreplace_widget.h:41
WID_RV_RIGHT_MATRIX
@ WID_RV_RIGHT_MATRIX
The matrix on the right.
Definition autoreplace_widget.h:25
WID_RV_INFO_TAB
@ WID_RV_INFO_TAB
Info tab.
Definition autoreplace_widget.h:32
WID_RV_RAIL_TYPE_DROPDOWN
@ WID_RV_RAIL_TYPE_DROPDOWN
Dropdown to select railtype.
Definition autoreplace_widget.h:36
WID_RV_LEFT_MATRIX
@ WID_RV_LEFT_MATRIX
The matrix on the left.
Definition autoreplace_widget.h:23
WID_RV_SORT_ASCENDING_DESCENDING
@ WID_RV_SORT_ASCENDING_DESCENDING
Ascending/descending sort order button.
Definition autoreplace_widget.h:18
WID_RV_RIGHT_SCROLLBAR
@ WID_RV_RIGHT_SCROLLBAR
The scrollbar for the matrix on the right.
Definition autoreplace_widget.h:26
WID_RV_START_REPLACE
@ WID_RV_START_REPLACE
Start Replacing button.
Definition autoreplace_widget.h:31
WID_RV_SORT_DROPDOWN
@ WID_RV_SORT_DROPDOWN
Dropdown for the sort criteria.
Definition autoreplace_widget.h:20
WID_RV_LEFT_DETAILS
@ WID_RV_LEFT_DETAILS
Details of the entry on the left.
Definition autoreplace_widget.h:27
HasBit
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
GUIEngineListAddChildren
void GUIEngineListAddChildren(GUIEngineList &dst, const GUIEngineList &src, EngineID parent, uint8_t indent)
Add children to GUI engine list to build a hierarchical tree.
Definition build_vehicle_gui.cpp:1130
_engine_sort_last_order
bool _engine_sort_last_order[]
Last set direction of the sort order, for each vehicle type.
Definition build_vehicle_gui.cpp:100
GetEngineListHeight
uint GetEngineListHeight(VehicleType type)
Get the height of a single 'entry' in the engine lists.
Definition build_vehicle_gui.cpp:53
_engine_sort_listing
const std::initializer_list< const StringID > _engine_sort_listing[]
Dropdown menu strings for the vehicle sort criteria.
Definition build_vehicle_gui.cpp:487
_engine_sort_last_criteria
uint8_t _engine_sort_last_criteria[]
Last set sort criteria, for each vehicle type.
Definition build_vehicle_gui.cpp:99
DrawVehiclePurchaseInfo
int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number, TestedEngineDetails &te)
Draw the purchase info details of a vehicle at a given location.
Definition build_vehicle_gui.cpp:917
_engine_sort_functions
EngList_SortTypeFunction *const _engine_sort_functions[][11]
Sort functions for the vehicle sort criteria, for each vehicle type.
Definition build_vehicle_gui.cpp:437
DisplayVehicleSortDropDown
void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selected, WidgetID button)
Display the dropdown for the vehicle sort criteria.
Definition build_vehicle_gui.cpp:1107
_engine_sort_direction
bool _engine_sort_direction
false = descending, true = ascending.
Definition build_vehicle_gui.cpp:98
_engine_sort_show_hidden_engines
bool _engine_sort_show_hidden_engines[]
Last set 'show hidden engines' setting for each vehicle type.
Definition build_vehicle_gui.cpp:101
DrawEngineList
void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, const Scrollbar &sb, EngineID selected_id, bool show_count, GroupID selected_group)
Engine drawing loop.
Definition build_vehicle_gui.cpp:1003
GUIList< GUIEngineListItem, std::nullptr_t, CargoID >
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition sortlist_type.h:409
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition sortlist_type.h:399
NWidgetCore
Base class for a 'real' widget.
Definition widget_type.h:371
NWidgetCore::widget_data
uint32_t widget_data
Data of the widget.
Definition widget_type.h:394
NWidgetCore::SetLowered
void SetLowered(bool lowered)
Lower or raise the widget.
Definition widget_type.h:429
NWidgetCore::tool_tip
StringID tool_tip
Tooltip of the widget.
Definition widget_type.h:395
RailTypeInfo::strings
struct RailTypeInfo::@26 strings
Strings associated with the rail type.
RailTypeInfo::replace_text
StringID replace_text
Text used in the autoreplace GUI.
Definition rail.h:180
ReplaceVehicleWindow
Window for the autoreplacing of vehicles.
Definition autoreplace_gui.cpp:79
ReplaceVehicleWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition autoreplace_gui.cpp:686
ReplaceVehicleWindow::GenerateReplaceRailList
bool GenerateReplaceRailList(EngineID e, bool draw_left, bool show_engines)
Figure out if an engine should be added to a list.
Definition autoreplace_gui.cpp:100
ReplaceVehicleWindow::OnDropdownSelect
void OnDropdownSelect(WidgetID widget, int index) override
A dropdown option associated to this window has been selected.
Definition autoreplace_gui.cpp:631
ReplaceVehicleWindow::engines
GUIEngineList engines[2]
Left and right list of engines.
Definition autoreplace_gui.cpp:81
ReplaceVehicleWindow::sel_engine
EngineID sel_engine[2]
Selected engine left and right.
Definition autoreplace_gui.cpp:80
ReplaceVehicleWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition autoreplace_gui.cpp:435
ReplaceVehicleWindow::ReplaceClick_StartReplace
void ReplaceClick_StartReplace(bool replace_when_old)
Handle click on the start replace button.
Definition autoreplace_gui.cpp:243
ReplaceVehicleWindow::OnTooltip
bool OnTooltip(Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
Event to display a custom tooltip.
Definition autoreplace_gui.cpp:673
ReplaceVehicleWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition autoreplace_gui.cpp:517
ReplaceVehicleWindow::sort_criteria
uint8_t sort_criteria
Criteria of sorting vehicles.
Definition autoreplace_gui.cpp:86
ReplaceVehicleWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition autoreplace_gui.cpp:697
ReplaceVehicleWindow::sel_railtype
RailType sel_railtype
Type of rail tracks selected. INVALID_RAILTYPE to show all.
Definition autoreplace_gui.cpp:89
ReplaceVehicleWindow::UpdateWidgetSize
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Definition autoreplace_gui.cpp:295
ReplaceVehicleWindow::SetStringParameters
void SetStringParameters(WidgetID widget) const override
Initialize string parameters for a widget.
Definition autoreplace_gui.cpp:380
ReplaceVehicleWindow::replace_engines
bool replace_engines
If true, engines are replaced, if false, wagons are replaced (only for trains).
Definition autoreplace_gui.cpp:82
ReplaceVehicleWindow::reset_sel_engine
bool reset_sel_engine
Also reset sel_engine while updating left and/or right and no valid engine selected.
Definition autoreplace_gui.cpp:83
ReplaceVehicleWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition autoreplace_gui.cpp:473
ReplaceVehicleWindow::show_hidden_engines
bool show_hidden_engines
Whether to show the hidden engines.
Definition autoreplace_gui.cpp:88
ReplaceVehicleWindow::GenerateLists
void GenerateLists()
Generate the lists.
Definition autoreplace_gui.cpp:194
ReplaceVehicleWindow::sel_roadtype
RoadType sel_roadtype
Type of road selected. INVALID_ROADTYPE to show all.
Definition autoreplace_gui.cpp:90
ReplaceVehicleWindow::details_height
int details_height
Minimal needed height of the details panels, in text lines (found so far).
Definition autoreplace_gui.cpp:85
ReplaceVehicleWindow::GenerateReplaceVehList
void GenerateReplaceVehList(bool draw_left)
Generate an engines list.
Definition autoreplace_gui.cpp:118
ReplaceVehicleWindow::sel_group
GroupID sel_group
Group selected to replace.
Definition autoreplace_gui.cpp:84
ReplaceVehicleWindow::descending_sort_order
bool descending_sort_order
Order of sorting vehicles.
Definition autoreplace_gui.cpp:87
ReplaceVehicleWindow::OnRailRoadTypeChange
void OnRailRoadTypeChange()
Perform tasks after rail or road type is changed.
Definition autoreplace_gui.cpp:253
RoadTypeInfo::replace_text
StringID replace_text
Text used in the autoreplace GUI.
Definition road.h:107
RoadTypeInfo::strings
struct RoadTypeInfo::@29 strings
Strings associated with the rail type.
Scrollbar
Scrollbar data structure.
Definition widget_type.h:694
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition widget_type.h:780
Scrollbar::GetScrolledItemFromWidget
auto GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Return an iterator pointing to the element of a scrolled widget that a user clicked in.
Definition widget_type.h:879
Scrollbar::SetPosition
bool SetPosition(size_type position)
Sets the position of the first visible element.
Definition widget_type.h:810
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition widget.cpp:2451
Scrollbar::ScrollTowards
void ScrollTowards(size_type position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
Definition widget_type.h:841
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition window_gui.h:42
WidgetDimensions::frametext
RectPadding frametext
Padding inside frame with text.
Definition window_gui.h:43
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:28
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:96
command_func.h
Functions related to commands.
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition company_cmd.cpp:52
company_func.h
Functions related to companies.
ShowDropDownMenu
void ShowDropDownMenu(Window *w, std::span< const StringID > strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
Definition dropdown.cpp:441
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
Show a drop down list.
Definition dropdown.cpp:404
dropdown_func.h
Functions related to the drop down widget.
dropdown_type.h
Types related to the drop down widget.
DropDownList
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Definition dropdown_type.h:50
engine_base.h
Base class for engines.
EngineDisplayFlags::HasVariants
@ HasVariants
Set if engine has variants.
EngineDisplayFlags::IsFolded
@ IsFolded
Set if display of variants should be folded (hidden).
EngineDisplayFlags::None
@ None
No flag set.
EngineDisplayFlags::Shaded
@ Shaded
Set if engine should be masked.
EngList_Sort
void EngList_Sort(GUIEngineList &el, EngList_SortTypeFunction compare)
Sort all items using quick sort and given 'CompareItems' function.
Definition engine_gui.cpp:333
engine_gui.h
Engine GUI functions, used by build_vehicle_gui and autoreplace_gui
INVALID_ENGINE
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
Definition engine_type.h:210
EngineID
uint16_t EngineID
Unique identification number of an engine.
Definition engine_type.h:21
PackEngineNameDParam
uint64_t PackEngineNameDParam(EngineID engine_id, EngineNameContext context, uint32_t extra_data=0)
Combine an engine ID and a name context to an engine name dparam.
Definition engine_type.h:203
PurchaseList
@ PurchaseList
Name is shown in the purchase list (including autoreplace window 'Available vehicles' panel).
Definition engine_type.h:197
RAILVEH_WAGON
@ RAILVEH_WAGON
simple wagon, not motorized
Definition engine_type.h:29
HasFlag
debug_inline constexpr bool HasFlag(const T x, const T y)
Checks if a value in a bitset enum is set.
Definition enum_type.hpp:58
settings
fluid_settings_t * settings
FluidSynth settings handle.
Definition fluidsynth.cpp:21
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:77
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition geometry_func.cpp:22
geometry_func.hpp
Geometry functions.
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:851
GetStringListBoundingBox
Dimension GetStringListBoundingBox(std::span< const StringID > list, FontSize fontsize)
Get maximum dimension of a list of strings.
Definition gfx.cpp:889
DrawString
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:657
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:38
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition gfx_type.h:344
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:209
GF_REPLACE_WAGON_REMOVAL
@ GF_REPLACE_WAGON_REMOVAL
If set, autoreplace will perform wagon removal on vehicles in this group.
Definition group.h:67
GetGroupNumEngines
uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e)
Get the number of engines with EngineID id_e in the group with GroupID id_g and its sub-groups.
Definition group_cmd.cpp:799
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1181
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition widget_type.h:1295
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition widget_type.h:1202
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition widget_type.h:1137
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1320
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition widget_type.h:1214
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1191
SetMinimalTextLines
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition widget_type.h:1149
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1126
group_cmd.h
Command definitions related to engine groups.
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:940
GroupID
uint16_t GroupID
Type for all group identifiers.
Definition group_type.h:13
DEFAULT_GROUP
static const GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
Definition group_type.h:17
ALL_GROUP
static const GroupID ALL_GROUP
All vehicles are in this group.
Definition group_type.h:16
IsInsideMM
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition math_func.hpp:268
GuiShowTooltips
void GuiShowTooltips(Window *parent, StringID str, TooltipCloseCondition close_tooltip, uint paramcount)
Shows a tooltip.
Definition misc_gui.cpp:740
newgrf_engine.h
Functions for NewGRF engines.
rail.h
Rail specific functions.
GetRailTypeInfo
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition rail.h:307
GetRailTypeDropDownList
DropDownList GetRailTypeDropDownList(bool for_replacement, bool all_option)
Create a drop down list for all the rail types of the local company.
Definition rail_gui.cpp:2011
rail_gui.h
Functions/types etc.
RailType
RailType
Enumeration for all possible railtypes.
Definition rail_type.h:27
INVALID_RAILTYPE
@ INVALID_RAILTYPE
Flag for invalid railtype.
Definition rail_type.h:34
road.h
Road specific functions.
GetRoadTypeInfo
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition road.h:227
road_gui.h
Functions/types related to the road GUIs.
RoadType
RoadType
The different roadtypes we support.
Definition road_type.h:25
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition road_type.h:30
safeguards.h
A number of safeguards to prevent using unsafe methods.
settings_cmd.h
Command definitions related to settings.
settings_func.h
Functions related to setting/changing the settings.
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition strings.cpp:104
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
strings_func.h
Functions related to OTTD's strings.
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition strings_type.h:24
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:16
CommandHelper
Definition command_func.h:83
CompanyProperties::settings
CompanySettings settings
settings specific for each company
Definition company_base.h:122
CompanySettings::renew_keep_length
bool renew_keep_length
sell some wagons if after autoreplace the train is longer than before
Definition settings_type.h:586
Company
Definition company_base.h:133
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:30
Engine
Definition engine_base.h:37
Engine::IterateType
static Pool::IterateWrapperFiltered< Engine, EngineTypeFilter > IterateType(VehicleType vt, size_t from=0)
Returns an iterable ensemble of all valid engines of the given type.
Definition engine_base.h:190
Engine::display_flags
EngineDisplayFlags display_flags
NOSAVE client-side-only display flags for build engine list.
Definition engine_base.h:62
GUIEngineListItem
Definition engine_gui.h:20
GUIEngineListItem::engine_id
EngineID engine_id
Engine to display in build purchase list.
Definition engine_gui.h:21
Group
Group data.
Definition group.h:72
Group::flags
uint8_t flags
Group flags.
Definition group.h:77
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition widget_type.h:1075
Point
Coordinates of a point in 2D.
Definition geometry_type.hpp:21
Pool::PoolItem<&_group_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition pool_type.hpp:328
Pool::PoolItem<&_group_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition pool_type.hpp:350
Pool::PoolItem<&_engine_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition pool_type.hpp:339
RailVehicleInfo
Information about a rail vehicle.
Definition engine_type.h:42
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:75
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition geometry_type.hpp:185
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition geometry_type.hpp:98
TestedEngineDetails
Extra information about refitted cargo and capacity.
Definition vehicle_gui.h:42
TestedEngineDetails::cost
Money cost
Refit cost.
Definition vehicle_gui.h:43
WindowDesc
High level window description.
Definition window_gui.h:159
Window
Data structure for an opened window.
Definition window_gui.h:273
Window::ReInit
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:952
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition widget.cpp:781
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1733
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:732
Window::parent
Window * parent
Parent window.
Definition window_gui.h:328
Window::DrawSortButtonState
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition widget.cpp:764
Window::resize
ResizeInfo resize
Resize information.
Definition window_gui.h:314
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1723
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition window_gui.h:316
Window::SetWidgetLoweredState
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:447
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition window_gui.h:563
Window::GetWidget
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:977
Window::HandleButtonClick
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:590
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:314
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:387
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:302
vehicle_gui.h
Functions related to the vehicle's GUIs.
VehicleType
VehicleType
Available vehicle types.
Definition vehicle_type.h:21
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition vehicle_type.h:25
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition vehicle_type.h:24
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition widget_type.h:524
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition widget_type.h:113
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition widget_type.h:57
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:75
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:55
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:50
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:66
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition widget_type.h:59
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:64
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:61
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:85
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:77
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:69
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition widget_type.h:68
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition widget_type.h:65
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition widget_type.h:70
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition window.cpp:1140
InvalidateWindowData
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition window.cpp:3219
InvalidateWindowClassesData
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition window.cpp:3236
window_func.h
Window functions not directly related to making/drawing windows.
window_gui.h
Functions, definitions and such used only by the GUI.
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition window_gui.h:220
SBS_UP
@ SBS_UP
Sort descending.
Definition window_gui.h:221
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition window_gui.h:203
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:147
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:18
WC_REPLACE_VEHICLE
@ WC_REPLACE_VEHICLE
Replace vehicle window; Window numbers:
Definition window_type.h:218
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:45
WC_BUILD_VEHICLE
@ WC_BUILD_VEHICLE
Build vehicle; Window numbers:
Definition window_type.h:389