Fix #10490: Allow ships to exit depots if another is not moving at the exit point...
[openttd-github.git] / src / autoreplace_gui.cpp
blob64707259d3a2e51605f9412572e4ffc46472fa14
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 */
8 /** @file autoreplace_gui.cpp GUI for autoreplace handling. */
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 "widgets/dropdown_func.h"
28 #include "autoreplace_cmd.h"
29 #include "group_cmd.h"
30 #include "settings_cmd.h"
32 #include "widgets/autoreplace_widget.h"
34 #include "safeguards.h"
36 void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, uint16_t min, uint16_t max, EngineID selected_id, bool show_count, GroupID selected_group);
38 static bool EngineNumberSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
40 return Engine::Get(a.engine_id)->list_position < Engine::Get(b.engine_id)->list_position;
43 /**
44 * Rebuild the left autoreplace list if an engine is removed or added
45 * @param e Engine to check if it is removed or added
46 * @param id_g The group the engine belongs to
47 * Note: this function only works if it is called either
48 * - when a new vehicle is build, but before it's counted in num_engines
49 * - when a vehicle is deleted and after it's subtracted from num_engines
50 * - when not changing the count (used when changing replace orders)
52 void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g)
54 if (GetGroupNumEngines(_local_company, id_g, e) == 0 || GetGroupNumEngines(_local_company, ALL_GROUP, e) == 0) {
55 /* We don't have any of this engine type.
56 * Either we just sold the last one, we build a new one or we stopped replacing it.
57 * In all cases, we need to update the left list */
58 InvalidateWindowData(WC_REPLACE_VEHICLE, Engine::Get(e)->type, 1);
62 /**
63 * When an engine is made buildable or is removed from being buildable, add/remove it from the build/autoreplace lists
64 * @param type The type of engine
66 void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type)
68 InvalidateWindowData(WC_REPLACE_VEHICLE, type, 0); // Update the autoreplace window
69 InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well
72 static const StringID _start_replace_dropdown[] = {
73 STR_REPLACE_VEHICLES_NOW,
74 STR_REPLACE_VEHICLES_WHEN_OLD,
75 INVALID_STRING_ID
78 /**
79 * Window for the autoreplacing of vehicles.
81 class ReplaceVehicleWindow : public Window {
82 EngineID sel_engine[2]; ///< Selected engine left and right.
83 GUIEngineList engines[2]; ///< Left and right list of engines.
84 bool replace_engines; ///< If \c true, engines are replaced, if \c false, wagons are replaced (only for trains).
85 bool reset_sel_engine; ///< Also reset #sel_engine while updating left and/or right and no valid engine selected.
86 GroupID sel_group; ///< Group selected to replace.
87 int details_height; ///< Minimal needed height of the details panels, in text lines (found so far).
88 byte sort_criteria; ///< Criteria of sorting vehicles.
89 bool descending_sort_order; ///< Order of sorting vehicles.
90 bool show_hidden_engines; ///< Whether to show the hidden engines.
91 RailType sel_railtype; ///< Type of rail tracks selected. #INVALID_RAILTYPE to show all.
92 RoadType sel_roadtype; ///< Type of road selected. #INVALID_ROADTYPE to show all.
93 Scrollbar *vscroll[2];
95 /**
96 * Figure out if an engine should be added to a list.
97 * @param e The EngineID.
98 * @param draw_left If \c true, the left list is drawn (the engines specific to the railtype you selected).
99 * @param show_engines If \c true, the locomotives are drawn, else the wagons are drawn (never both).
100 * @return \c true if the engine should be in the list (based on this check), else \c false.
102 bool GenerateReplaceRailList(EngineID e, bool draw_left, bool show_engines)
104 const RailVehicleInfo *rvi = RailVehInfo(e);
106 /* Ensure that the wagon/engine selection fits the engine. */
107 if ((rvi->railveh_type == RAILVEH_WAGON) == show_engines) return false;
109 if (draw_left && this->sel_railtype != INVALID_RAILTYPE) {
110 /* Ensure that the railtype is specific to the selected one */
111 if (rvi->railtype != this->sel_railtype) return false;
113 return true;
116 void AddChildren(const GUIEngineList &source, GUIEngineList &target, EngineID parent, int indent, int side)
118 for (const auto &item : source) {
119 if (item.variant_id != parent || item.engine_id == parent) continue;
121 const Engine *e = Engine::Get(item.engine_id);
122 EngineDisplayFlags flags = item.flags;
123 if (e->display_last_variant != INVALID_ENGINE) flags &= ~EngineDisplayFlags::Shaded;
124 target.emplace_back(e->display_last_variant == INVALID_ENGINE ? item.engine_id : e->display_last_variant, item.engine_id, flags, indent);
126 /* Add variants if not folded */
127 if ((item.flags & (EngineDisplayFlags::HasVariants | EngineDisplayFlags::IsFolded)) == EngineDisplayFlags::HasVariants) {
128 /* Add this engine again as a child */
129 if ((item.flags & EngineDisplayFlags::Shaded) == EngineDisplayFlags::None) {
130 target.emplace_back(item.engine_id, item.engine_id, EngineDisplayFlags::None, indent + 1);
132 AddChildren(source, target, item.engine_id, indent + 1, side);
138 * Generate an engines list
139 * @param draw_left true if generating the left list, otherwise false
141 void GenerateReplaceVehList(bool draw_left)
143 std::vector<EngineID> variants;
144 EngineID selected_engine = INVALID_ENGINE;
145 VehicleType type = (VehicleType)this->window_number;
146 byte side = draw_left ? 0 : 1;
148 GUIEngineList list;
150 for (const Engine *e : Engine::IterateType(type)) {
151 if (!draw_left && !this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue;
152 EngineID eid = e->index;
153 switch (type) {
154 case VEH_TRAIN:
155 if (!this->GenerateReplaceRailList(eid, draw_left, this->replace_engines)) continue; // special rules for trains
156 break;
158 case VEH_ROAD:
159 if (draw_left && this->sel_roadtype != INVALID_ROADTYPE) {
160 /* Ensure that the roadtype is specific to the selected one */
161 if (e->u.road.roadtype != this->sel_roadtype) continue;
163 break;
165 default:
166 break;
169 if (draw_left) {
170 const uint num_engines = GetGroupNumEngines(_local_company, this->sel_group, eid);
172 /* Skip drawing the engines we don't have any of and haven't set for replacement */
173 if (num_engines == 0 && EngineReplacementForCompany(Company::Get(_local_company), eid, this->sel_group) == INVALID_ENGINE) continue;
174 } else {
175 if (!CheckAutoreplaceValidity(this->sel_engine[0], eid, _local_company)) continue;
178 list.emplace_back(eid, e->info.variant_id, (side == 0) ? EngineDisplayFlags::None : e->display_flags, 0);
180 if (side == 1) {
181 EngineID parent = e->info.variant_id;
182 while (parent != INVALID_ENGINE) {
183 variants.push_back(parent);
184 parent = Engine::Get(parent)->info.variant_id;
187 if (eid == this->sel_engine[side]) selected_engine = eid; // The selected engine is still in the list
190 if (side == 1) {
191 /* ensure primary engine of variant group is in list */
192 for (const auto &variant : variants) {
193 if (std::find(list.begin(), list.end(), variant) == list.end()) {
194 const Engine *e = Engine::Get(variant);
195 list.emplace_back(variant, e->info.variant_id, e->display_flags | EngineDisplayFlags::Shaded, 0);
200 this->sel_engine[side] = selected_engine; // update which engine we selected (the same or none, if it's not in the list anymore)
201 if (draw_left) {
202 EngList_Sort(list, &EngineNumberSorter);
203 } else {
204 _engine_sort_direction = this->descending_sort_order;
205 EngList_Sort(list, _engine_sort_functions[this->window_number][this->sort_criteria]);
208 this->engines[side].clear();
209 if (side == 1) {
210 AddChildren(list, this->engines[side], INVALID_ENGINE, 0, side);
211 } else {
212 this->engines[side].swap(list);
216 /** Generate the lists */
217 void GenerateLists()
219 EngineID e = this->sel_engine[0];
221 if (this->engines[0].NeedRebuild()) {
222 /* We need to rebuild the left engines list */
223 this->GenerateReplaceVehList(true);
224 this->vscroll[0]->SetCount(this->engines[0].size());
225 if (this->reset_sel_engine && this->sel_engine[0] == INVALID_ENGINE && !this->engines[0].empty()) {
226 this->sel_engine[0] = this->engines[0][0].engine_id;
230 if (this->engines[1].NeedRebuild() || e != this->sel_engine[0]) {
231 /* Either we got a request to rebuild the right engines list, or the left engines list selected a different engine */
232 if (this->sel_engine[0] == INVALID_ENGINE) {
233 /* Always empty the right engines list when nothing is selected in the left engines list */
234 this->engines[1].clear();
235 this->sel_engine[1] = INVALID_ENGINE;
236 this->vscroll[1]->SetCount(this->engines[1].size());
237 } else {
238 if (this->reset_sel_engine && this->sel_engine[0] != INVALID_ENGINE) {
239 /* Select the current replacement for sel_engine[0]. */
240 const Company *c = Company::Get(_local_company);
241 this->sel_engine[1] = EngineReplacementForCompany(c, this->sel_engine[0], this->sel_group);
243 /* Regenerate the list on the right. Note: This resets sel_engine[1] to INVALID_ENGINE, if it is no longer available. */
244 this->GenerateReplaceVehList(false);
245 this->vscroll[1]->SetCount(this->engines[1].size());
246 if (this->reset_sel_engine && this->sel_engine[1] != INVALID_ENGINE) {
247 int position = 0;
248 for (const auto &item : this->engines[1]) {
249 if (item.engine_id == this->sel_engine[1]) break;
250 ++position;
252 this->vscroll[1]->ScrollTowards(position);
256 /* Reset the flags about needed updates */
257 this->engines[0].RebuildDone();
258 this->engines[1].RebuildDone();
259 this->reset_sel_engine = false;
263 * Handle click on the start replace button.
264 * @param replace_when_old Replace now or only when old?
266 void ReplaceClick_StartReplace(bool replace_when_old)
268 EngineID veh_from = this->sel_engine[0];
269 EngineID veh_to = this->sel_engine[1];
270 Command<CMD_SET_AUTOREPLACE>::Post(this->sel_group, veh_from, veh_to, replace_when_old);
274 * Perform tasks after rail or road type is changed.
276 void OnRailRoadTypeChange()
278 /* Reset scrollbar positions */
279 this->vscroll[0]->SetPosition(0);
280 this->vscroll[1]->SetPosition(0);
281 /* Rebuild the lists */
282 this->engines[0].ForceRebuild();
283 this->engines[1].ForceRebuild();
284 this->reset_sel_engine = true;
285 this->SetDirty();
288 public:
289 ReplaceVehicleWindow(WindowDesc *desc, VehicleType vehicletype, GroupID id_g) : Window(desc)
291 this->sel_railtype = INVALID_RAILTYPE;
292 this->sel_roadtype = INVALID_ROADTYPE;
293 this->replace_engines = true; // start with locomotives (all other vehicles will not read this bool)
294 this->engines[0].ForceRebuild();
295 this->engines[1].ForceRebuild();
296 this->reset_sel_engine = true;
297 this->details_height = ((vehicletype == VEH_TRAIN) ? 10 : 9);
298 this->sel_engine[0] = INVALID_ENGINE;
299 this->sel_engine[1] = INVALID_ENGINE;
300 this->show_hidden_engines = _engine_sort_show_hidden_engines[vehicletype];
302 this->CreateNestedTree();
303 this->vscroll[0] = this->GetScrollbar(WID_RV_LEFT_SCROLLBAR);
304 this->vscroll[1] = this->GetScrollbar(WID_RV_RIGHT_SCROLLBAR);
306 NWidgetCore *widget = this->GetWidget<NWidgetCore>(WID_RV_SHOW_HIDDEN_ENGINES);
307 widget->widget_data = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + vehicletype;
308 widget->tool_tip = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + vehicletype;
309 widget->SetLowered(this->show_hidden_engines);
310 this->FinishInitNested(vehicletype);
312 this->sort_criteria = _engine_sort_last_criteria[vehicletype];
313 this->descending_sort_order = _engine_sort_last_order[vehicletype];
314 this->owner = _local_company;
315 this->sel_group = id_g;
318 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
320 switch (widget) {
321 case WID_RV_SORT_ASCENDING_DESCENDING: {
322 Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
323 d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
324 d.height += padding.height;
325 *size = maxdim(*size, d);
326 break;
329 case WID_RV_LEFT_MATRIX:
330 case WID_RV_RIGHT_MATRIX:
331 resize->height = GetEngineListHeight((VehicleType)this->window_number);
332 size->height = (this->window_number <= VEH_ROAD ? 8 : 4) * resize->height;
333 break;
335 case WID_RV_LEFT_DETAILS:
336 case WID_RV_RIGHT_DETAILS:
337 size->height = GetCharacterHeight(FS_NORMAL) * this->details_height + padding.height;
338 break;
340 case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
341 StringID str = this->GetWidget<NWidgetCore>(widget)->widget_data;
342 SetDParam(0, STR_CONFIG_SETTING_ON);
343 Dimension d = GetStringBoundingBox(str);
344 SetDParam(0, STR_CONFIG_SETTING_OFF);
345 d = maxdim(d, GetStringBoundingBox(str));
346 d.width += padding.width;
347 d.height += padding.height;
348 *size = maxdim(*size, d);
349 break;
352 case WID_RV_TRAIN_ENGINEWAGON_DROPDOWN: {
353 Dimension d = GetStringBoundingBox(STR_REPLACE_ENGINES);
354 d = maxdim(d, GetStringBoundingBox(STR_REPLACE_WAGONS));
355 d.width += padding.width;
356 d.height += padding.height;
357 *size = maxdim(*size, d);
358 break;
361 case WID_RV_INFO_TAB: {
362 Dimension d = GetStringBoundingBox(STR_REPLACE_NOT_REPLACING);
363 d = maxdim(d, GetStringBoundingBox(STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED));
364 d.width += padding.width;
365 d.height += padding.height;
366 *size = maxdim(*size, d);
367 break;
370 case WID_RV_RAIL_TYPE_DROPDOWN: {
371 Dimension d = {0, 0};
372 for (const RailType &rt : _sorted_railtypes) {
373 d = maxdim(d, GetStringBoundingBox(GetRailTypeInfo(rt)->strings.replace_text));
375 d.width += padding.width;
376 d.height += padding.height;
377 *size = maxdim(*size, d);
378 break;
381 case WID_RV_ROAD_TYPE_DROPDOWN: {
382 Dimension d = {0, 0};
383 for (const RoadType &rt : _sorted_roadtypes) {
384 d = maxdim(d, GetStringBoundingBox(GetRoadTypeInfo(rt)->strings.replace_text));
386 d.width += padding.width;
387 d.height += padding.height;
388 *size = maxdim(*size, d);
389 break;
392 case WID_RV_START_REPLACE: {
393 Dimension d = GetStringBoundingBox(STR_REPLACE_VEHICLES_START);
394 for (int i = 0; _start_replace_dropdown[i] != INVALID_STRING_ID; i++) {
395 d = maxdim(d, GetStringBoundingBox(_start_replace_dropdown[i]));
397 d.width += padding.width;
398 d.height += padding.height;
399 *size = maxdim(*size, d);
400 break;
405 void SetStringParameters(WidgetID widget) const override
407 switch (widget) {
408 case WID_RV_CAPTION:
409 SetDParam(0, STR_REPLACE_VEHICLE_TRAIN + this->window_number);
410 switch (this->sel_group) {
411 case ALL_GROUP:
412 SetDParam(1, STR_GROUP_ALL_TRAINS + this->window_number);
413 break;
415 case DEFAULT_GROUP:
416 SetDParam(1, STR_GROUP_DEFAULT_TRAINS + this->window_number);
417 break;
419 default:
420 SetDParam(1, STR_GROUP_NAME);
421 SetDParam(2, sel_group);
422 break;
424 break;
426 case WID_RV_SORT_DROPDOWN:
427 SetDParam(0, _engine_sort_listing[this->window_number][this->sort_criteria]);
428 break;
430 case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
431 bool remove_wagon;
432 const Group *g = Group::GetIfValid(this->sel_group);
433 if (g != nullptr) {
434 remove_wagon = HasBit(g->flags, GroupFlags::GF_REPLACE_WAGON_REMOVAL);
435 SetDParam(0, STR_GROUP_NAME);
436 SetDParam(1, sel_group);
437 } else {
438 const Company *c = Company::Get(_local_company);
439 remove_wagon = c->settings.renew_keep_length;
440 SetDParam(0, STR_GROUP_DEFAULT_TRAINS + this->window_number);
442 SetDParam(2, remove_wagon ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
443 break;
446 case WID_RV_TRAIN_ENGINEWAGON_DROPDOWN:
447 SetDParam(0, this->replace_engines ? STR_REPLACE_ENGINES : STR_REPLACE_WAGONS);
448 break;
450 case WID_RV_RAIL_TYPE_DROPDOWN:
451 SetDParam(0, this->sel_railtype == INVALID_RAILTYPE ? STR_REPLACE_ALL_RAILTYPE : GetRailTypeInfo(this->sel_railtype)->strings.replace_text);
452 break;
454 case WID_RV_ROAD_TYPE_DROPDOWN:
455 SetDParam(0, this->sel_roadtype == INVALID_ROADTYPE ? STR_REPLACE_ALL_ROADTYPE : GetRoadTypeInfo(this->sel_roadtype)->strings.replace_text);
456 break;
460 void DrawWidget(const Rect &r, WidgetID widget) const override
462 switch (widget) {
463 case WID_RV_SORT_ASCENDING_DESCENDING:
464 this->DrawSortButtonState(WID_RV_SORT_ASCENDING_DESCENDING, this->descending_sort_order ? SBS_DOWN : SBS_UP);
465 break;
467 case WID_RV_INFO_TAB: {
468 const Company *c = Company::Get(_local_company);
469 StringID str;
470 if (this->sel_engine[0] != INVALID_ENGINE) {
471 if (!EngineHasReplacementForCompany(c, this->sel_engine[0], this->sel_group)) {
472 str = STR_REPLACE_NOT_REPLACING;
473 } else {
474 bool when_old = false;
475 EngineID e = EngineReplacementForCompany(c, this->sel_engine[0], this->sel_group, &when_old);
476 str = when_old ? STR_REPLACE_REPLACING_WHEN_OLD : STR_ENGINE_NAME;
477 SetDParam(0, PackEngineNameDParam(e, EngineNameContext::PurchaseList));
479 } else {
480 str = STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED;
483 DrawString(r.Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect), str, TC_BLACK, SA_HOR_CENTER);
484 break;
487 case WID_RV_LEFT_MATRIX:
488 case WID_RV_RIGHT_MATRIX: {
489 int side = (widget == WID_RV_LEFT_MATRIX) ? 0 : 1;
490 EngineID start = static_cast<EngineID>(this->vscroll[side]->GetPosition()); // what is the offset for the start (scrolling)
491 EngineID end = static_cast<EngineID>(std::min<size_t>(this->vscroll[side]->GetCapacity() + start, this->engines[side].size()));
493 /* Do the actual drawing */
494 DrawEngineList((VehicleType)this->window_number, r, this->engines[side], start, end, this->sel_engine[side], side == 0, this->sel_group);
495 break;
500 void OnPaint() override
502 if (this->engines[0].NeedRebuild() || this->engines[1].NeedRebuild()) this->GenerateLists();
504 Company *c = Company::Get(_local_company);
506 /* Disable the "Start Replacing" button if:
507 * Either engines list is empty
508 * or The selected replacement engine has a replacement (to prevent loops). */
509 this->SetWidgetDisabledState(WID_RV_START_REPLACE,
510 this->sel_engine[0] == INVALID_ENGINE || this->sel_engine[1] == INVALID_ENGINE || EngineReplacementForCompany(c, this->sel_engine[1], this->sel_group) != INVALID_ENGINE);
512 /* Disable the "Stop Replacing" button if:
513 * The left engines list (existing vehicle) is empty
514 * or The selected vehicle has no replacement set up */
515 this->SetWidgetDisabledState(WID_RV_STOP_REPLACE, this->sel_engine[0] == INVALID_ENGINE || !EngineHasReplacementForCompany(c, this->sel_engine[0], this->sel_group));
517 this->DrawWidgets();
519 if (!this->IsShaded()) {
520 int needed_height = this->details_height;
521 /* Draw details panels. */
522 for (int side = 0; side < 2; side++) {
523 if (this->sel_engine[side] != INVALID_ENGINE) {
524 /* Use default engine details without refitting */
525 const Engine *e = Engine::Get(this->sel_engine[side]);
526 TestedEngineDetails ted;
527 ted.cost = 0;
528 ted.FillDefaultCapacities(e);
530 const Rect r = this->GetWidget<NWidgetBase>(side == 0 ? WID_RV_LEFT_DETAILS : WID_RV_RIGHT_DETAILS)->GetCurrentRect()
531 .Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect);
532 int text_end = DrawVehiclePurchaseInfo(r.left, r.right, r.top, this->sel_engine[side], ted);
533 needed_height = std::max(needed_height, (text_end - r.top) / GetCharacterHeight(FS_NORMAL));
536 if (needed_height != this->details_height) { // Details window are not high enough, enlarge them.
537 this->details_height = needed_height;
538 this->ReInit();
539 return;
544 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
546 switch (widget) {
547 case WID_RV_SORT_ASCENDING_DESCENDING:
548 this->descending_sort_order ^= true;
549 _engine_sort_last_order[this->window_number] = this->descending_sort_order;
550 this->engines[1].ForceRebuild();
551 this->SetDirty();
552 break;
554 case WID_RV_SHOW_HIDDEN_ENGINES:
555 this->show_hidden_engines ^= true;
556 _engine_sort_show_hidden_engines[this->window_number] = this->show_hidden_engines;
557 this->engines[1].ForceRebuild();
558 this->SetWidgetLoweredState(widget, this->show_hidden_engines);
559 this->SetDirty();
560 break;
562 case WID_RV_SORT_DROPDOWN:
563 DisplayVehicleSortDropDown(this, static_cast<VehicleType>(this->window_number), this->sort_criteria, WID_RV_SORT_DROPDOWN);
564 break;
566 case WID_RV_TRAIN_ENGINEWAGON_DROPDOWN: {
567 DropDownList list;
568 list.push_back(std::make_unique<DropDownListStringItem>(STR_REPLACE_ENGINES, 1, false));
569 list.push_back(std::make_unique<DropDownListStringItem>(STR_REPLACE_WAGONS, 0, false));
570 ShowDropDownList(this, std::move(list), this->replace_engines ? 1 : 0, WID_RV_TRAIN_ENGINEWAGON_DROPDOWN);
571 break;
574 case WID_RV_RAIL_TYPE_DROPDOWN: // Railtype selection dropdown menu
575 ShowDropDownList(this, GetRailTypeDropDownList(true, true), this->sel_railtype, widget);
576 break;
578 case WID_RV_ROAD_TYPE_DROPDOWN: // Roadtype selection dropdown menu
579 ShowDropDownList(this, GetRoadTypeDropDownList(RTTB_ROAD | RTTB_TRAM, true, true), this->sel_roadtype, widget);
580 break;
582 case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
583 const Group *g = Group::GetIfValid(this->sel_group);
584 if (g != nullptr) {
585 Command<CMD_SET_GROUP_FLAG>::Post(this->sel_group, GroupFlags::GF_REPLACE_WAGON_REMOVAL, !HasBit(g->flags, GroupFlags::GF_REPLACE_WAGON_REMOVAL), _ctrl_pressed);
586 } else {
587 // toggle renew_keep_length
588 Command<CMD_CHANGE_COMPANY_SETTING>::Post("company.renew_keep_length", Company::Get(_local_company)->settings.renew_keep_length ? 0 : 1);
590 break;
593 case WID_RV_START_REPLACE: { // Start replacing
594 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
595 this->HandleButtonClick(WID_RV_START_REPLACE);
596 ReplaceClick_StartReplace(false);
597 } else {
598 bool replacment_when_old = EngineHasReplacementWhenOldForCompany(Company::Get(_local_company), this->sel_engine[0], this->sel_group);
599 ShowDropDownMenu(this, _start_replace_dropdown, replacment_when_old ? 1 : 0, WID_RV_START_REPLACE, !this->replace_engines ? 1 << 1 : 0, 0);
601 break;
604 case WID_RV_STOP_REPLACE: { // Stop replacing
605 EngineID veh_from = this->sel_engine[0];
606 Command<CMD_SET_AUTOREPLACE>::Post(this->sel_group, veh_from, INVALID_ENGINE, false);
607 break;
610 case WID_RV_LEFT_MATRIX:
611 case WID_RV_RIGHT_MATRIX: {
612 byte click_side;
613 if (widget == WID_RV_LEFT_MATRIX) {
614 click_side = 0;
615 } else {
616 click_side = 1;
619 EngineID e = INVALID_ENGINE;
620 const auto it = this->vscroll[click_side]->GetScrolledItemFromWidget(this->engines[click_side], pt.y, this, widget);
621 if (it != this->engines[click_side].end()) {
622 const auto &item = *it;
623 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);
624 if ((item.flags & EngineDisplayFlags::HasVariants) != EngineDisplayFlags::None && IsInsideMM(r.left, r.right, pt.x)) {
625 /* toggle folded flag on engine */
626 assert(item.variant_id != INVALID_ENGINE);
627 Engine *engine = Engine::Get(item.variant_id);
628 engine->display_flags ^= EngineDisplayFlags::IsFolded;
630 InvalidateWindowData(WC_REPLACE_VEHICLE, (VehicleType)this->window_number, 0); // Update the autoreplace window
631 InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well
632 return;
634 if ((item.flags & EngineDisplayFlags::Shaded) == EngineDisplayFlags::None) e = item.engine_id;
637 /* If Ctrl is pressed on the left side and we don't have any engines of the selected type, stop autoreplacing.
638 * This is most common when we have finished autoreplacing the engine and want to remove it from the list. */
639 if (click_side == 0 && _ctrl_pressed && e != INVALID_ENGINE &&
640 (GetGroupNumEngines(_local_company, sel_group, e) == 0 || GetGroupNumEngines(_local_company, ALL_GROUP, e) == 0)) {
641 EngineID veh_from = e;
642 Command<CMD_SET_AUTOREPLACE>::Post(this->sel_group, veh_from, INVALID_ENGINE, false);
643 break;
646 if (e == this->sel_engine[click_side]) break; // we clicked the one we already selected
647 this->sel_engine[click_side] = e;
648 if (click_side == 0) {
649 this->engines[1].ForceRebuild();
650 this->reset_sel_engine = true;
652 this->SetDirty();
653 break;
658 void OnDropdownSelect(WidgetID widget, int index) override
660 switch (widget) {
661 case WID_RV_SORT_DROPDOWN:
662 if (this->sort_criteria != index) {
663 this->sort_criteria = index;
664 _engine_sort_last_criteria[this->window_number] = this->sort_criteria;
665 this->engines[1].ForceRebuild();
666 this->SetDirty();
668 break;
670 case WID_RV_RAIL_TYPE_DROPDOWN: {
671 RailType temp = (RailType)index;
672 if (temp == this->sel_railtype) return; // we didn't select a new one. No need to change anything
673 this->sel_railtype = temp;
674 this->OnRailRoadTypeChange();
675 break;
678 case WID_RV_ROAD_TYPE_DROPDOWN: {
679 RoadType temp = (RoadType)index;
680 if (temp == this->sel_roadtype) return; // we didn't select a new one. No need to change anything
681 this->sel_roadtype = temp;
682 this->OnRailRoadTypeChange();
683 break;
686 case WID_RV_TRAIN_ENGINEWAGON_DROPDOWN: {
687 this->replace_engines = index != 0;
688 this->engines[0].ForceRebuild();
689 this->reset_sel_engine = true;
690 this->SetDirty();
691 break;
694 case WID_RV_START_REPLACE:
695 this->ReplaceClick_StartReplace(index != 0);
696 break;
700 bool OnTooltip([[maybe_unused]] Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
702 if (widget != WID_RV_TRAIN_WAGONREMOVE_TOGGLE) return false;
704 if (Group::IsValidID(this->sel_group)) {
705 SetDParam(0, STR_REPLACE_REMOVE_WAGON_HELP);
706 GuiShowTooltips(this, STR_REPLACE_REMOVE_WAGON_GROUP_HELP, close_cond, 1);
707 } else {
708 GuiShowTooltips(this, STR_REPLACE_REMOVE_WAGON_HELP, close_cond);
710 return true;
713 void OnResize() override
715 this->vscroll[0]->SetCapacityFromWidget(this, WID_RV_LEFT_MATRIX);
716 this->vscroll[1]->SetCapacityFromWidget(this, WID_RV_RIGHT_MATRIX);
720 * Some data on this window has become invalid.
721 * @param data Information about the changed data.
722 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
724 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
726 if (data != 0) {
727 /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
728 this->engines[0].ForceRebuild();
729 } else {
730 this->engines[1].ForceRebuild();
735 static constexpr NWidgetPart _nested_replace_rail_vehicle_widgets[] = {
736 NWidget(NWID_HORIZONTAL),
737 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
738 NWidget(WWT_CAPTION, COLOUR_GREY, WID_RV_CAPTION), SetDataTip(STR_REPLACE_VEHICLES_WHITE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
739 NWidget(WWT_SHADEBOX, COLOUR_GREY),
740 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
741 NWidget(WWT_STICKYBOX, COLOUR_GREY),
742 EndContainer(),
743 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
744 NWidget(WWT_PANEL, COLOUR_GREY),
745 NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_VEHICLES_IN_USE, STR_REPLACE_VEHICLE_VEHICLES_IN_USE_TOOLTIP), SetFill(1, 1), SetMinimalSize(0, 12), SetResize(1, 0),
746 EndContainer(),
747 NWidget(WWT_PANEL, COLOUR_GREY),
748 NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES, STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES_TOOLTIP), SetFill(1, 1), SetMinimalSize(0, 12), SetResize(1, 0),
749 EndContainer(),
750 EndContainer(),
751 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
752 NWidget(NWID_VERTICAL),
753 NWidget(NWID_HORIZONTAL),
754 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),
755 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_TRAIN_ENGINEWAGON_DROPDOWN), SetDataTip(STR_JUST_STRING, STR_REPLACE_ENGINE_WAGON_SELECT_HELP),
756 EndContainer(),
757 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), EndContainer(),
758 EndContainer(),
759 NWidget(NWID_VERTICAL),
760 NWidget(NWID_HORIZONTAL),
761 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_SORT_ASCENDING_DESCENDING), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), SetFill(1, 1),
762 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
763 EndContainer(),
764 NWidget(NWID_HORIZONTAL),
765 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_RV_SHOW_HIDDEN_ENGINES), SetDataTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP),
766 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(),
767 EndContainer(),
768 EndContainer(),
769 EndContainer(),
770 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
771 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),
772 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_LEFT_SCROLLBAR),
773 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),
774 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_RIGHT_SCROLLBAR),
775 EndContainer(),
776 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
777 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_LEFT_DETAILS), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
778 NWidget(NWID_VERTICAL),
779 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_RIGHT_DETAILS), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
780 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),
781 EndContainer(),
782 EndContainer(),
783 NWidget(NWID_HORIZONTAL),
784 NWidget(NWID_PUSHBUTTON_DROPDOWN, COLOUR_GREY, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON),
785 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB), SetResize(1, 0),
786 EndContainer(),
787 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_STOP_REPLACE), SetMinimalSize(150, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON),
788 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
789 EndContainer(),
792 static WindowDesc _replace_rail_vehicle_desc(__FILE__, __LINE__,
793 WDP_AUTO, "replace_vehicle_train", 500, 140,
794 WC_REPLACE_VEHICLE, WC_NONE,
795 WDF_CONSTRUCTION,
796 std::begin(_nested_replace_rail_vehicle_widgets), std::end(_nested_replace_rail_vehicle_widgets)
799 static constexpr NWidgetPart _nested_replace_road_vehicle_widgets[] = {
800 NWidget(NWID_HORIZONTAL),
801 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
802 NWidget(WWT_CAPTION, COLOUR_GREY, WID_RV_CAPTION), SetDataTip(STR_REPLACE_VEHICLES_WHITE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
803 NWidget(WWT_SHADEBOX, COLOUR_GREY),
804 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
805 NWidget(WWT_STICKYBOX, COLOUR_GREY),
806 EndContainer(),
807 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
808 NWidget(WWT_PANEL, COLOUR_GREY),
809 NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_VEHICLES_IN_USE, STR_REPLACE_VEHICLE_VEHICLES_IN_USE_TOOLTIP), SetFill(1, 1), SetMinimalSize(0, 12), SetResize(1, 0),
810 EndContainer(),
811 NWidget(WWT_PANEL, COLOUR_GREY),
812 NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES, STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES_TOOLTIP), SetFill(1, 1), SetMinimalSize(0, 12), SetResize(1, 0),
813 EndContainer(),
814 EndContainer(),
815 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
816 NWidget(NWID_VERTICAL),
817 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),
818 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), EndContainer(),
819 EndContainer(),
820 NWidget(NWID_VERTICAL),
821 NWidget(NWID_HORIZONTAL),
822 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_SORT_ASCENDING_DESCENDING), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), SetFill(1, 1),
823 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
824 EndContainer(),
825 NWidget(NWID_HORIZONTAL),
826 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_RV_SHOW_HIDDEN_ENGINES), SetDataTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP),
827 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(),
828 EndContainer(),
829 EndContainer(),
830 EndContainer(),
831 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
832 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),
833 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_LEFT_SCROLLBAR),
834 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),
835 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_RIGHT_SCROLLBAR),
836 EndContainer(),
837 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
838 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_LEFT_DETAILS), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
839 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_RIGHT_DETAILS), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
840 EndContainer(),
841 NWidget(NWID_HORIZONTAL),
842 NWidget(NWID_PUSHBUTTON_DROPDOWN, COLOUR_GREY, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON),
843 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB), SetResize(1, 0),
844 EndContainer(),
845 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_STOP_REPLACE), SetMinimalSize(150, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON),
846 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
847 EndContainer(),
850 static WindowDesc _replace_road_vehicle_desc(__FILE__, __LINE__,
851 WDP_AUTO, "replace_vehicle_road", 500, 140,
852 WC_REPLACE_VEHICLE, WC_NONE,
853 WDF_CONSTRUCTION,
854 std::begin(_nested_replace_road_vehicle_widgets), std::end(_nested_replace_road_vehicle_widgets)
857 static constexpr NWidgetPart _nested_replace_vehicle_widgets[] = {
858 NWidget(NWID_HORIZONTAL),
859 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
860 NWidget(WWT_CAPTION, COLOUR_GREY, WID_RV_CAPTION), SetMinimalSize(433, 14), SetDataTip(STR_REPLACE_VEHICLES_WHITE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
861 NWidget(WWT_SHADEBOX, COLOUR_GREY),
862 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
863 NWidget(WWT_STICKYBOX, COLOUR_GREY),
864 EndContainer(),
865 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
866 NWidget(WWT_PANEL, COLOUR_GREY),
867 NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_VEHICLES_IN_USE, STR_REPLACE_VEHICLE_VEHICLES_IN_USE_TOOLTIP), SetFill(1, 1), SetMinimalSize(0, 12), SetResize(1, 0),
868 EndContainer(),
869 NWidget(WWT_PANEL, COLOUR_GREY),
870 NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES, STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES_TOOLTIP), SetFill(1, 1), SetMinimalSize(0, 12), SetResize(1, 0),
871 EndContainer(),
872 EndContainer(),
873 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
874 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), EndContainer(),
875 NWidget(NWID_VERTICAL),
876 NWidget(NWID_HORIZONTAL),
877 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_SORT_ASCENDING_DESCENDING), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
878 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
879 EndContainer(),
880 NWidget(NWID_HORIZONTAL),
881 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_RV_SHOW_HIDDEN_ENGINES), SetDataTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP),
882 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(),
883 EndContainer(),
884 EndContainer(),
885 EndContainer(),
886 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
887 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),
888 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_LEFT_SCROLLBAR),
889 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),
890 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_RIGHT_SCROLLBAR),
891 EndContainer(),
892 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
893 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_LEFT_DETAILS), SetMinimalSize(228, 92), SetResize(1, 0), EndContainer(),
894 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_RIGHT_DETAILS), SetMinimalSize(228, 92), SetResize(1, 0), EndContainer(),
895 EndContainer(),
896 NWidget(NWID_HORIZONTAL),
897 NWidget(NWID_PUSHBUTTON_DROPDOWN, COLOUR_GREY, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON),
898 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB), SetResize(1, 0), EndContainer(),
899 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_STOP_REPLACE), SetMinimalSize(138, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON),
900 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
901 EndContainer(),
904 static WindowDesc _replace_vehicle_desc(__FILE__, __LINE__,
905 WDP_AUTO, "replace_vehicle", 456, 118,
906 WC_REPLACE_VEHICLE, WC_NONE,
907 WDF_CONSTRUCTION,
908 std::begin(_nested_replace_vehicle_widgets), std::end(_nested_replace_vehicle_widgets)
912 * Show the autoreplace configuration window for a particular group.
913 * @param id_g The group to replace the vehicles for.
914 * @param vehicletype The type of vehicles in the group.
916 void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
918 CloseWindowById(WC_REPLACE_VEHICLE, vehicletype);
919 WindowDesc *desc;
920 switch (vehicletype) {
921 case VEH_TRAIN: desc = &_replace_rail_vehicle_desc; break;
922 case VEH_ROAD: desc = &_replace_road_vehicle_desc; break;
923 default: desc = &_replace_vehicle_desc; break;
925 new ReplaceVehicleWindow(desc, vehicletype, id_g);