Feature: Purchase land multiple tiles at a time
[openttd-github.git] / src / autoreplace_gui.cpp
blob4dae0eedc70e95b2c95fcc498cf5e496c034da49
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, int x, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group);
38 static bool EngineNumberSorter(const EngineID &a, const EngineID &b)
40 return Engine::Get(a)->list_position < Engine::Get(b)->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;
118 * Generate an engines list
119 * @param draw_left true if generating the left list, otherwise false
121 void GenerateReplaceVehList(bool draw_left)
123 EngineID selected_engine = INVALID_ENGINE;
124 VehicleType type = (VehicleType)this->window_number;
125 byte side = draw_left ? 0 : 1;
127 GUIEngineList *list = &this->engines[side];
128 list->clear();
130 for (const Engine *e : Engine::IterateType(type)) {
131 if (!draw_left && !this->show_hidden_engines && e->IsHidden(_local_company)) continue;
132 EngineID eid = e->index;
133 switch (type) {
134 case VEH_TRAIN:
135 if (!this->GenerateReplaceRailList(eid, draw_left, this->replace_engines)) continue; // special rules for trains
136 break;
138 case VEH_ROAD:
139 if (draw_left && this->sel_roadtype != INVALID_ROADTYPE) {
140 /* Ensure that the roadtype is specific to the selected one */
141 if (e->u.road.roadtype != this->sel_roadtype) continue;
143 break;
145 default:
146 break;
149 if (draw_left) {
150 const uint num_engines = GetGroupNumEngines(_local_company, this->sel_group, eid);
152 /* Skip drawing the engines we don't have any of and haven't set for replacement */
153 if (num_engines == 0 && EngineReplacementForCompany(Company::Get(_local_company), eid, this->sel_group) == INVALID_ENGINE) continue;
154 } else {
155 if (!CheckAutoreplaceValidity(this->sel_engine[0], eid, _local_company)) continue;
158 list->push_back(eid);
159 if (eid == this->sel_engine[side]) selected_engine = eid; // The selected engine is still in the list
161 this->sel_engine[side] = selected_engine; // update which engine we selected (the same or none, if it's not in the list anymore)
162 if (draw_left) {
163 EngList_Sort(list, &EngineNumberSorter);
164 } else {
165 _engine_sort_direction = this->descending_sort_order;
166 EngList_Sort(list, _engine_sort_functions[this->window_number][this->sort_criteria]);
170 /** Generate the lists */
171 void GenerateLists()
173 EngineID e = this->sel_engine[0];
175 if (this->engines[0].NeedRebuild()) {
176 /* We need to rebuild the left engines list */
177 this->GenerateReplaceVehList(true);
178 this->vscroll[0]->SetCount((uint)this->engines[0].size());
179 if (this->reset_sel_engine && this->sel_engine[0] == INVALID_ENGINE && this->engines[0].size() != 0) {
180 this->sel_engine[0] = this->engines[0][0];
184 if (this->engines[1].NeedRebuild() || e != this->sel_engine[0]) {
185 /* Either we got a request to rebuild the right engines list, or the left engines list selected a different engine */
186 if (this->sel_engine[0] == INVALID_ENGINE) {
187 /* Always empty the right engines list when nothing is selected in the left engines list */
188 this->engines[1].clear();
189 this->sel_engine[1] = INVALID_ENGINE;
190 } else {
191 if (this->reset_sel_engine && this->sel_engine[0] != INVALID_ENGINE) {
192 /* Select the current replacement for sel_engine[0]. */
193 const Company *c = Company::Get(_local_company);
194 this->sel_engine[1] = EngineReplacementForCompany(c, this->sel_engine[0], this->sel_group);
196 /* Regenerate the list on the right. Note: This resets sel_engine[1] to INVALID_ENGINE, if it is no longer available. */
197 this->GenerateReplaceVehList(false);
198 this->vscroll[1]->SetCount((uint)this->engines[1].size());
199 if (this->reset_sel_engine && this->sel_engine[1] != INVALID_ENGINE) {
200 int position = 0;
201 for (EngineID &eid : this->engines[1]) {
202 if (eid == this->sel_engine[1]) break;
203 ++position;
205 this->vscroll[1]->ScrollTowards(position);
209 /* Reset the flags about needed updates */
210 this->engines[0].RebuildDone();
211 this->engines[1].RebuildDone();
212 this->reset_sel_engine = false;
216 * Handle click on the start replace button.
217 * @param replace_when_old Replace now or only when old?
219 void ReplaceClick_StartReplace(bool replace_when_old)
221 EngineID veh_from = this->sel_engine[0];
222 EngineID veh_to = this->sel_engine[1];
223 Command<CMD_SET_AUTOREPLACE>::Post(this->sel_group, veh_from, veh_to, replace_when_old);
226 public:
227 ReplaceVehicleWindow(WindowDesc *desc, VehicleType vehicletype, GroupID id_g) : Window(desc)
229 this->sel_railtype = INVALID_RAILTYPE;
230 this->sel_roadtype = INVALID_ROADTYPE;
231 this->replace_engines = true; // start with locomotives (all other vehicles will not read this bool)
232 this->engines[0].ForceRebuild();
233 this->engines[1].ForceRebuild();
234 this->reset_sel_engine = true;
235 this->details_height = ((vehicletype == VEH_TRAIN) ? 10 : 9);
236 this->sel_engine[0] = INVALID_ENGINE;
237 this->sel_engine[1] = INVALID_ENGINE;
238 this->show_hidden_engines = _engine_sort_show_hidden_engines[vehicletype];
240 this->CreateNestedTree();
241 this->vscroll[0] = this->GetScrollbar(WID_RV_LEFT_SCROLLBAR);
242 this->vscroll[1] = this->GetScrollbar(WID_RV_RIGHT_SCROLLBAR);
244 NWidgetCore *widget = this->GetWidget<NWidgetCore>(WID_RV_SHOW_HIDDEN_ENGINES);
245 widget->widget_data = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + vehicletype;
246 widget->tool_tip = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + vehicletype;
247 widget->SetLowered(this->show_hidden_engines);
248 this->FinishInitNested(vehicletype);
250 if (vehicletype == VEH_TRAIN || vehicletype == VEH_ROAD) {
251 widget = this->GetWidget<NWidgetCore>(WID_RV_RAIL_ROAD_TYPE_DROPDOWN);
252 widget->tool_tip = STR_REPLACE_HELP_RAILTYPE + vehicletype;
255 this->sort_criteria = _engine_sort_last_criteria[vehicletype];
256 this->descending_sort_order = _engine_sort_last_order[vehicletype];
257 this->owner = _local_company;
258 this->sel_group = id_g;
261 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
263 switch (widget) {
264 case WID_RV_SORT_ASCENDING_DESCENDING: {
265 Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
266 d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
267 d.height += padding.height;
268 *size = maxdim(*size, d);
269 break;
272 case WID_RV_LEFT_MATRIX:
273 case WID_RV_RIGHT_MATRIX:
274 resize->height = GetEngineListHeight((VehicleType)this->window_number);
275 size->height = (this->window_number <= VEH_ROAD ? 8 : 4) * resize->height;
276 break;
278 case WID_RV_LEFT_DETAILS:
279 case WID_RV_RIGHT_DETAILS:
280 size->height = FONT_HEIGHT_NORMAL * this->details_height + padding.height;
281 break;
283 case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
284 StringID str = this->GetWidget<NWidgetCore>(widget)->widget_data;
285 SetDParam(0, STR_CONFIG_SETTING_ON);
286 Dimension d = GetStringBoundingBox(str);
287 SetDParam(0, STR_CONFIG_SETTING_OFF);
288 d = maxdim(d, GetStringBoundingBox(str));
289 d.width += padding.width;
290 d.height += padding.height;
291 *size = maxdim(*size, d);
292 break;
295 case WID_RV_TRAIN_ENGINEWAGON_DROPDOWN: {
296 Dimension d = GetStringBoundingBox(STR_REPLACE_ENGINES);
297 d = maxdim(d, GetStringBoundingBox(STR_REPLACE_WAGONS));
298 d.width += padding.width;
299 d.height += padding.height;
300 *size = maxdim(*size, d);
301 break;
304 case WID_RV_INFO_TAB: {
305 Dimension d = GetStringBoundingBox(STR_REPLACE_NOT_REPLACING);
306 d = maxdim(d, GetStringBoundingBox(STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED));
307 d.width += WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT;
308 d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
309 *size = maxdim(*size, d);
310 break;
313 case WID_RV_RAIL_ROAD_TYPE_DROPDOWN: {
314 Dimension d = {0, 0};
315 switch (this->window_number) {
316 case VEH_TRAIN:
317 for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
318 const RailtypeInfo *rti = GetRailTypeInfo(rt);
319 /* Skip rail type if it has no label */
320 if (rti->label == 0) continue;
321 d = maxdim(d, GetStringBoundingBox(rti->strings.replace_text));
323 break;
325 case VEH_ROAD:
326 for (RoadType rt = ROADTYPE_BEGIN; rt < ROADTYPE_END; rt++) {
327 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
328 /* Skip road type if it has no label */
329 if (rti->label == 0) continue;
330 d = maxdim(d, GetStringBoundingBox(rti->strings.replace_text));
332 break;
334 default: NOT_REACHED();
336 d.width += padding.width;
337 d.height += padding.height;
338 *size = maxdim(*size, d);
339 break;
342 case WID_RV_START_REPLACE: {
343 Dimension d = GetStringBoundingBox(STR_REPLACE_VEHICLES_START);
344 for (int i = 0; _start_replace_dropdown[i] != INVALID_STRING_ID; i++) {
345 d = maxdim(d, GetStringBoundingBox(_start_replace_dropdown[i]));
347 d.width += padding.width;
348 d.height += padding.height;
349 *size = maxdim(*size, d);
350 break;
355 void SetStringParameters(int widget) const override
357 switch (widget) {
358 case WID_RV_CAPTION:
359 SetDParam(0, STR_REPLACE_VEHICLE_TRAIN + this->window_number);
360 switch (this->sel_group) {
361 case ALL_GROUP:
362 SetDParam(1, STR_GROUP_ALL_TRAINS + this->window_number);
363 break;
365 case DEFAULT_GROUP:
366 SetDParam(1, STR_GROUP_DEFAULT_TRAINS + this->window_number);
367 break;
369 default:
370 SetDParam(1, STR_GROUP_NAME);
371 SetDParam(2, sel_group);
372 break;
374 break;
376 case WID_RV_SORT_DROPDOWN:
377 SetDParam(0, _engine_sort_listing[this->window_number][this->sort_criteria]);
378 break;
380 case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
381 bool remove_wagon;
382 const Group *g = Group::GetIfValid(this->sel_group);
383 if (g != nullptr) {
384 remove_wagon = HasBit(g->flags, GroupFlags::GF_REPLACE_WAGON_REMOVAL);
385 SetDParam(0, STR_GROUP_NAME);
386 SetDParam(1, sel_group);
387 } else {
388 const Company *c = Company::Get(_local_company);
389 remove_wagon = c->settings.renew_keep_length;
390 SetDParam(0, STR_GROUP_DEFAULT_TRAINS + this->window_number);
392 SetDParam(2, remove_wagon ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
393 break;
396 case WID_RV_TRAIN_ENGINEWAGON_DROPDOWN:
397 SetDParam(0, this->replace_engines ? STR_REPLACE_ENGINES : STR_REPLACE_WAGONS);
398 break;
402 void DrawWidget(const Rect &r, int widget) const override
404 switch (widget) {
405 case WID_RV_SORT_ASCENDING_DESCENDING:
406 this->DrawSortButtonState(WID_RV_SORT_ASCENDING_DESCENDING, this->descending_sort_order ? SBS_DOWN : SBS_UP);
407 break;
409 case WID_RV_INFO_TAB: {
410 const Company *c = Company::Get(_local_company);
411 StringID str;
412 if (this->sel_engine[0] != INVALID_ENGINE) {
413 if (!EngineHasReplacementForCompany(c, this->sel_engine[0], this->sel_group)) {
414 str = STR_REPLACE_NOT_REPLACING;
415 } else {
416 bool when_old = false;
417 EngineID e = EngineReplacementForCompany(c, this->sel_engine[0], this->sel_group, &when_old);
418 str = when_old ? STR_REPLACE_REPLACING_WHEN_OLD : STR_ENGINE_NAME;
419 SetDParam(0, e);
421 } else {
422 str = STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED;
425 DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top + WD_FRAMERECT_TOP, str, TC_BLACK, SA_HOR_CENTER);
426 break;
429 case WID_RV_LEFT_MATRIX:
430 case WID_RV_RIGHT_MATRIX: {
431 int side = (widget == WID_RV_LEFT_MATRIX) ? 0 : 1;
432 EngineID start = static_cast<EngineID>(this->vscroll[side]->GetPosition()); // what is the offset for the start (scrolling)
433 EngineID end = static_cast<EngineID>(std::min<size_t>(this->vscroll[side]->GetCapacity() + start, this->engines[side].size()));
435 /* Do the actual drawing */
436 DrawEngineList((VehicleType)this->window_number, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP,
437 &this->engines[side], start, end, this->sel_engine[side], side == 0, this->sel_group);
438 break;
443 void OnPaint() override
445 if (this->engines[0].NeedRebuild() || this->engines[1].NeedRebuild()) this->GenerateLists();
447 Company *c = Company::Get(_local_company);
449 /* Disable the "Start Replacing" button if:
450 * Either engines list is empty
451 * or The selected replacement engine has a replacement (to prevent loops). */
452 this->SetWidgetDisabledState(WID_RV_START_REPLACE,
453 this->sel_engine[0] == INVALID_ENGINE || this->sel_engine[1] == INVALID_ENGINE || EngineReplacementForCompany(c, this->sel_engine[1], this->sel_group) != INVALID_ENGINE);
455 /* Disable the "Stop Replacing" button if:
456 * The left engines list (existing vehicle) is empty
457 * or The selected vehicle has no replacement set up */
458 this->SetWidgetDisabledState(WID_RV_STOP_REPLACE, this->sel_engine[0] == INVALID_ENGINE || !EngineHasReplacementForCompany(c, this->sel_engine[0], this->sel_group));
460 switch (this->window_number) {
461 case VEH_TRAIN:
462 /* Show the selected railtype in the pulldown menu */
463 this->GetWidget<NWidgetCore>(WID_RV_RAIL_ROAD_TYPE_DROPDOWN)->widget_data = sel_railtype == INVALID_RAILTYPE ? STR_REPLACE_ALL_RAILTYPE : GetRailTypeInfo(sel_railtype)->strings.replace_text;
464 break;
466 case VEH_ROAD:
467 /* Show the selected roadtype in the pulldown menu */
468 this->GetWidget<NWidgetCore>(WID_RV_RAIL_ROAD_TYPE_DROPDOWN)->widget_data = sel_roadtype == INVALID_ROADTYPE ? STR_REPLACE_ALL_ROADTYPE : GetRoadTypeInfo(sel_roadtype)->strings.replace_text;
469 break;
471 default: break;
474 this->DrawWidgets();
476 if (!this->IsShaded()) {
477 int needed_height = this->details_height;
478 /* Draw details panels. */
479 for (int side = 0; side < 2; side++) {
480 if (this->sel_engine[side] != INVALID_ENGINE) {
481 /* Use default engine details without refitting */
482 const Engine *e = Engine::Get(this->sel_engine[side]);
483 TestedEngineDetails ted;
484 ted.cost = 0;
485 ted.cargo = e->GetDefaultCargoType();
486 ted.capacity = e->GetDisplayDefaultCapacity(&ted.mail_capacity);
488 NWidgetBase *nwi = this->GetWidget<NWidgetBase>(side == 0 ? WID_RV_LEFT_DETAILS : WID_RV_RIGHT_DETAILS);
489 int text_end = DrawVehiclePurchaseInfo(nwi->pos_x + WD_FRAMETEXT_LEFT, nwi->pos_x + nwi->current_x - WD_FRAMETEXT_RIGHT,
490 nwi->pos_y + WD_FRAMERECT_TOP, this->sel_engine[side], ted);
491 needed_height = std::max(needed_height, (text_end - (int)nwi->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_NORMAL);
494 if (needed_height != this->details_height) { // Details window are not high enough, enlarge them.
495 this->details_height = needed_height;
496 this->ReInit();
497 return;
502 void OnClick(Point pt, int widget, int click_count) override
504 switch (widget) {
505 case WID_RV_SORT_ASCENDING_DESCENDING:
506 this->descending_sort_order ^= true;
507 _engine_sort_last_order[this->window_number] = this->descending_sort_order;
508 this->engines[1].ForceRebuild();
509 this->SetDirty();
510 break;
512 case WID_RV_SHOW_HIDDEN_ENGINES:
513 this->show_hidden_engines ^= true;
514 _engine_sort_show_hidden_engines[this->window_number] = this->show_hidden_engines;
515 this->engines[1].ForceRebuild();
516 this->SetWidgetLoweredState(widget, this->show_hidden_engines);
517 this->SetDirty();
518 break;
520 case WID_RV_SORT_DROPDOWN:
521 DisplayVehicleSortDropDown(this, static_cast<VehicleType>(this->window_number), this->sort_criteria, WID_RV_SORT_DROPDOWN);
522 break;
524 case WID_RV_TRAIN_ENGINEWAGON_DROPDOWN: {
525 DropDownList list;
526 list.emplace_back(new DropDownListStringItem(STR_REPLACE_ENGINES, 1, false));
527 list.emplace_back(new DropDownListStringItem(STR_REPLACE_WAGONS, 0, false));
528 ShowDropDownList(this, std::move(list), this->replace_engines ? 1 : 0, WID_RV_TRAIN_ENGINEWAGON_DROPDOWN);
529 break;
532 case WID_RV_RAIL_ROAD_TYPE_DROPDOWN: // Rail/roadtype selection dropdown menu
533 switch (this->window_number) {
534 case VEH_TRAIN:
535 ShowDropDownList(this, GetRailTypeDropDownList(true, true), sel_railtype, WID_RV_RAIL_ROAD_TYPE_DROPDOWN);
536 break;
538 case VEH_ROAD:
539 ShowDropDownList(this, GetRoadTypeDropDownList(RTTB_ROAD | RTTB_TRAM, true, true), sel_roadtype, WID_RV_RAIL_ROAD_TYPE_DROPDOWN);
540 break;
542 break;
544 case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
545 const Group *g = Group::GetIfValid(this->sel_group);
546 if (g != nullptr) {
547 Command<CMD_SET_GROUP_FLAG>::Post(this->sel_group, GroupFlags::GF_REPLACE_WAGON_REMOVAL, !HasBit(g->flags, GroupFlags::GF_REPLACE_WAGON_REMOVAL), _ctrl_pressed);
548 } else {
549 // toggle renew_keep_length
550 Command<CMD_CHANGE_COMPANY_SETTING>::Post("company.renew_keep_length", Company::Get(_local_company)->settings.renew_keep_length ? 0 : 1);
552 break;
555 case WID_RV_START_REPLACE: { // Start replacing
556 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
557 this->HandleButtonClick(WID_RV_START_REPLACE);
558 ReplaceClick_StartReplace(false);
559 } else {
560 bool replacment_when_old = EngineHasReplacementWhenOldForCompany(Company::Get(_local_company), this->sel_engine[0], this->sel_group);
561 ShowDropDownMenu(this, _start_replace_dropdown, replacment_when_old ? 1 : 0, WID_RV_START_REPLACE, !this->replace_engines ? 1 << 1 : 0, 0);
563 break;
566 case WID_RV_STOP_REPLACE: { // Stop replacing
567 EngineID veh_from = this->sel_engine[0];
568 Command<CMD_SET_AUTOREPLACE>::Post(this->sel_group, veh_from, INVALID_ENGINE, false);
569 break;
572 case WID_RV_LEFT_MATRIX:
573 case WID_RV_RIGHT_MATRIX: {
574 byte click_side;
575 if (widget == WID_RV_LEFT_MATRIX) {
576 click_side = 0;
577 } else {
578 click_side = 1;
580 uint i = this->vscroll[click_side]->GetScrolledRowFromWidget(pt.y, this, widget);
581 size_t engine_count = this->engines[click_side].size();
583 EngineID e = engine_count > i ? this->engines[click_side][i] : INVALID_ENGINE;
585 /* If Ctrl is pressed on the left side and we don't have any engines of the selected type, stop autoreplacing.
586 * This is most common when we have finished autoreplacing the engine and want to remove it from the list. */
587 if (click_side == 0 && _ctrl_pressed && e != INVALID_ENGINE &&
588 (GetGroupNumEngines(_local_company, sel_group, e) == 0 || GetGroupNumEngines(_local_company, ALL_GROUP, e) == 0)) {
589 EngineID veh_from = e;
590 Command<CMD_SET_AUTOREPLACE>::Post(this->sel_group, veh_from, INVALID_ENGINE, false);
591 break;
594 if (e == this->sel_engine[click_side]) break; // we clicked the one we already selected
595 this->sel_engine[click_side] = e;
596 if (click_side == 0) {
597 this->engines[1].ForceRebuild();
598 this->reset_sel_engine = true;
600 this->SetDirty();
601 break;
606 void OnDropdownSelect(int widget, int index) override
608 switch (widget) {
609 case WID_RV_SORT_DROPDOWN:
610 if (this->sort_criteria != index) {
611 this->sort_criteria = index;
612 _engine_sort_last_criteria[this->window_number] = this->sort_criteria;
613 this->engines[1].ForceRebuild();
614 this->SetDirty();
616 break;
618 case WID_RV_RAIL_ROAD_TYPE_DROPDOWN:
619 switch (this->window_number) {
620 case VEH_TRAIN: {
621 RailType temp = (RailType)index;
622 if (temp == sel_railtype) return; // we didn't select a new one. No need to change anything
623 sel_railtype = temp;
624 break;
627 case VEH_ROAD: {
628 RoadType temp = (RoadType)index;
629 if (temp == sel_roadtype) return; // we didn't select a new one. No need to change anything
630 sel_roadtype = temp;
631 break;
634 default: NOT_REACHED();
637 /* Reset scrollbar positions */
638 this->vscroll[0]->SetPosition(0);
639 this->vscroll[1]->SetPosition(0);
640 /* Rebuild the lists */
641 this->engines[0].ForceRebuild();
642 this->engines[1].ForceRebuild();
643 this->reset_sel_engine = true;
644 this->SetDirty();
645 break;
647 case WID_RV_TRAIN_ENGINEWAGON_DROPDOWN: {
648 this->replace_engines = index != 0;
649 this->engines[0].ForceRebuild();
650 this->reset_sel_engine = true;
651 this->SetDirty();
652 break;
655 case WID_RV_START_REPLACE:
656 this->ReplaceClick_StartReplace(index != 0);
657 break;
661 bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) override
663 if (widget != WID_RV_TRAIN_WAGONREMOVE_TOGGLE) return false;
665 if (Group::IsValidID(this->sel_group)) {
666 uint64 params[1];
667 params[0] = STR_REPLACE_REMOVE_WAGON_HELP;
668 GuiShowTooltips(this, STR_REPLACE_REMOVE_WAGON_GROUP_HELP, 1, params, close_cond);
669 } else {
670 GuiShowTooltips(this, STR_REPLACE_REMOVE_WAGON_HELP, 0, nullptr, close_cond);
672 return true;
675 void OnResize() override
677 this->vscroll[0]->SetCapacityFromWidget(this, WID_RV_LEFT_MATRIX);
678 this->vscroll[1]->SetCapacityFromWidget(this, WID_RV_RIGHT_MATRIX);
682 * Some data on this window has become invalid.
683 * @param data Information about the changed data.
684 * @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.
686 void OnInvalidateData(int data = 0, bool gui_scope = true) override
688 if (data != 0) {
689 /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
690 this->engines[0].ForceRebuild();
691 } else {
692 this->engines[1].ForceRebuild();
697 static const NWidgetPart _nested_replace_rail_vehicle_widgets[] = {
698 NWidget(NWID_HORIZONTAL),
699 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
700 NWidget(WWT_CAPTION, COLOUR_GREY, WID_RV_CAPTION), SetDataTip(STR_REPLACE_VEHICLES_WHITE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
701 NWidget(WWT_SHADEBOX, COLOUR_GREY),
702 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
703 NWidget(WWT_STICKYBOX, COLOUR_GREY),
704 EndContainer(),
705 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
706 NWidget(WWT_PANEL, COLOUR_GREY),
707 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),
708 EndContainer(),
709 NWidget(WWT_PANEL, COLOUR_GREY),
710 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),
711 EndContainer(),
712 EndContainer(),
713 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
714 NWidget(NWID_VERTICAL),
715 NWidget(NWID_HORIZONTAL),
716 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_RAIL_ROAD_TYPE_DROPDOWN), SetMinimalSize(136, 12), SetDataTip(0x0, STR_REPLACE_HELP_RAILTYPE), SetFill(1, 0), SetResize(1, 0),
717 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_TRAIN_ENGINEWAGON_DROPDOWN), SetDataTip(STR_BLACK_STRING, STR_REPLACE_ENGINE_WAGON_SELECT_HELP),
718 EndContainer(),
719 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), EndContainer(),
720 EndContainer(),
721 NWidget(NWID_VERTICAL),
722 NWidget(NWID_HORIZONTAL),
723 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_SORT_ASCENDING_DESCENDING), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), SetFill(1, 1),
724 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
725 EndContainer(),
726 NWidget(NWID_HORIZONTAL),
727 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_RV_SHOW_HIDDEN_ENGINES), SetDataTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP),
728 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(),
729 EndContainer(),
730 EndContainer(),
731 EndContainer(),
732 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
733 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),
734 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_LEFT_SCROLLBAR),
735 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),
736 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_RIGHT_SCROLLBAR),
737 EndContainer(),
738 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
739 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_LEFT_DETAILS), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
740 NWidget(NWID_VERTICAL),
741 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_RIGHT_DETAILS), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
742 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),
743 EndContainer(),
744 EndContainer(),
745 NWidget(NWID_HORIZONTAL),
746 NWidget(NWID_PUSHBUTTON_DROPDOWN, COLOUR_GREY, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON),
747 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB), SetResize(1, 0),
748 EndContainer(),
749 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_STOP_REPLACE), SetMinimalSize(150, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON),
750 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
751 EndContainer(),
754 static WindowDesc _replace_rail_vehicle_desc(
755 WDP_AUTO, "replace_vehicle_train", 500, 140,
756 WC_REPLACE_VEHICLE, WC_NONE,
757 WDF_CONSTRUCTION,
758 _nested_replace_rail_vehicle_widgets, lengthof(_nested_replace_rail_vehicle_widgets)
761 static const NWidgetPart _nested_replace_road_vehicle_widgets[] = {
762 NWidget(NWID_HORIZONTAL),
763 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
764 NWidget(WWT_CAPTION, COLOUR_GREY, WID_RV_CAPTION), SetDataTip(STR_REPLACE_VEHICLES_WHITE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
765 NWidget(WWT_SHADEBOX, COLOUR_GREY),
766 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
767 NWidget(WWT_STICKYBOX, COLOUR_GREY),
768 EndContainer(),
769 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
770 NWidget(WWT_PANEL, COLOUR_GREY),
771 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),
772 EndContainer(),
773 NWidget(WWT_PANEL, COLOUR_GREY),
774 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),
775 EndContainer(),
776 EndContainer(),
777 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
778 NWidget(NWID_VERTICAL),
779 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_RAIL_ROAD_TYPE_DROPDOWN), SetMinimalSize(136, 12), SetDataTip(0x0, STR_REPLACE_HELP_RAILTYPE), SetFill(1, 0), SetResize(1, 0),
780 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), EndContainer(),
781 EndContainer(),
782 NWidget(NWID_VERTICAL),
783 NWidget(NWID_HORIZONTAL),
784 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_SORT_ASCENDING_DESCENDING), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), SetFill(1, 1),
785 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
786 EndContainer(),
787 NWidget(NWID_HORIZONTAL),
788 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_RV_SHOW_HIDDEN_ENGINES), SetDataTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP),
789 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(),
790 EndContainer(),
791 EndContainer(),
792 EndContainer(),
793 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
794 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),
795 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_LEFT_SCROLLBAR),
796 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),
797 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_RIGHT_SCROLLBAR),
798 EndContainer(),
799 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
800 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_LEFT_DETAILS), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
801 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_RIGHT_DETAILS), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
802 EndContainer(),
803 NWidget(NWID_HORIZONTAL),
804 NWidget(NWID_PUSHBUTTON_DROPDOWN, COLOUR_GREY, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON),
805 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB), SetResize(1, 0),
806 EndContainer(),
807 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_STOP_REPLACE), SetMinimalSize(150, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON),
808 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
809 EndContainer(),
812 static WindowDesc _replace_road_vehicle_desc(
813 WDP_AUTO, "replace_vehicle_road", 500, 140,
814 WC_REPLACE_VEHICLE, WC_NONE,
815 WDF_CONSTRUCTION,
816 _nested_replace_road_vehicle_widgets, lengthof(_nested_replace_road_vehicle_widgets)
819 static const NWidgetPart _nested_replace_vehicle_widgets[] = {
820 NWidget(NWID_HORIZONTAL),
821 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
822 NWidget(WWT_CAPTION, COLOUR_GREY, WID_RV_CAPTION), SetMinimalSize(433, 14), SetDataTip(STR_REPLACE_VEHICLES_WHITE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
823 NWidget(WWT_SHADEBOX, COLOUR_GREY),
824 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
825 NWidget(WWT_STICKYBOX, COLOUR_GREY),
826 EndContainer(),
827 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
828 NWidget(WWT_PANEL, COLOUR_GREY),
829 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),
830 EndContainer(),
831 NWidget(WWT_PANEL, COLOUR_GREY),
832 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),
833 EndContainer(),
834 EndContainer(),
835 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
836 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), EndContainer(),
837 NWidget(NWID_VERTICAL),
838 NWidget(NWID_HORIZONTAL),
839 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_SORT_ASCENDING_DESCENDING), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
840 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
841 EndContainer(),
842 NWidget(NWID_HORIZONTAL),
843 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_RV_SHOW_HIDDEN_ENGINES), SetDataTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP),
844 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(),
845 EndContainer(),
846 EndContainer(),
847 EndContainer(),
848 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
849 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),
850 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_LEFT_SCROLLBAR),
851 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),
852 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_RIGHT_SCROLLBAR),
853 EndContainer(),
854 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
855 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_LEFT_DETAILS), SetMinimalSize(228, 92), SetResize(1, 0), EndContainer(),
856 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_RIGHT_DETAILS), SetMinimalSize(228, 92), SetResize(1, 0), EndContainer(),
857 EndContainer(),
858 NWidget(NWID_HORIZONTAL),
859 NWidget(NWID_PUSHBUTTON_DROPDOWN, COLOUR_GREY, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON),
860 NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB), SetResize(1, 0), EndContainer(),
861 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_STOP_REPLACE), SetMinimalSize(138, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON),
862 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
863 EndContainer(),
866 static WindowDesc _replace_vehicle_desc(
867 WDP_AUTO, "replace_vehicle", 456, 118,
868 WC_REPLACE_VEHICLE, WC_NONE,
869 WDF_CONSTRUCTION,
870 _nested_replace_vehicle_widgets, lengthof(_nested_replace_vehicle_widgets)
874 * Show the autoreplace configuration window for a particular group.
875 * @param id_g The group to replace the vehicles for.
876 * @param vehicletype The type of vehicles in the group.
878 void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
880 CloseWindowById(WC_REPLACE_VEHICLE, vehicletype);
881 WindowDesc *desc;
882 switch (vehicletype) {
883 case VEH_TRAIN: desc = &_replace_rail_vehicle_desc; break;
884 case VEH_ROAD: desc = &_replace_road_vehicle_desc; break;
885 default: desc = &_replace_vehicle_desc; break;
887 new ReplaceVehicleWindow(desc, vehicletype, id_g);