# autoreplace_gui.cpp

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #include "stdafx.h"
    00013 #include "command_func.h"
    00014 #include "vehicle_gui.h"
    00015 #include "newgrf_engine.h"
    00016 #include "rail.h"
    00017 #include "strings_func.h"
    00018 #include "window_func.h"
    00019 #include "autoreplace_func.h"
    00020 #include "company_func.h"
    00021 #include "engine_base.h"
    00022 #include "window_gui.h"
    00023 #include "engine_gui.h"
    00024 #include "settings_func.h"
    00025 #include "core/geometry_func.hpp"
    00026 #include "rail_gui.h"
    00027
    00028 #include "widgets/autoreplace_widget.h"
    00029
    00030
    00031 uint GetEngineListHeight(VehicleType type);
    00032 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);
    00033
    00034 static int CDECL EngineNumberSorter(const EngineID *a, const EngineID *b)
    00035 {
    00036   int r = ListPositionOfEngine(*a) - ListPositionOfEngine(*b);
    00037
    00038   return r;
    00039 }
    00040
    00050 void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g)
    00051 {
    00052   if (GetGroupNumEngines(_local_company, id_g, e) == 0 || GetGroupNumEngines(_local_company, ALL_GROUP, e) == 0) {
    00053     /* We don't have any of this engine type.
    00054      * Either we just sold the last one, we build a new one or we stopped replacing it.
    00055      * In all cases, we need to update the left list */
    00056     InvalidateWindowData(WC_REPLACE_VEHICLE, Engine::Get(e)->type, 1);
    00057   }
    00058 }
    00059
    00064 void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type)
    00065 {
    00066   InvalidateWindowData(WC_REPLACE_VEHICLE, type, 0); // Update the autoreplace window
    00067   InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well
    00068 }
    00069
    00073 class ReplaceVehicleWindow : public Window {
    00074   EngineID sel_engine[2];
    00075   GUIEngineList engines[2];
    00076   bool replace_engines;
    00077   bool reset_sel_engine;
    00078   GroupID sel_group;
    00079   int details_height;
    00080   RailType sel_railtype;
    00081   Scrollbar *vscroll[2];
    00082
    00090   bool GenerateReplaceRailList(EngineID e, bool draw_left, bool show_engines)
    00091   {
    00092     const RailVehicleInfo *rvi = RailVehInfo(e);
    00093
    00094     /* Ensure that the wagon/engine selection fits the engine. */
    00095     if ((rvi->railveh_type == RAILVEH_WAGON) == show_engines) return false;
    00096
    00097     if (draw_left && show_engines) {
    00098       /* Ensure that the railtype is specific to the selected one */
    00099       if (rvi->railtype != this->sel_railtype) return false;
    00100     }
    00101     return true;
    00102   }
    00103
    00104
    00109   void GenerateReplaceVehList(bool draw_left)
    00110   {
    00111     EngineID selected_engine = INVALID_ENGINE;
    00112     VehicleType type = (VehicleType)this->window_number;
    00113     byte side = draw_left ? 0 : 1;
    00114
    00115     GUIEngineList *list = &this->engines[side];
    00116     list->Clear();
    00117
    00118     const Engine *e;
    00119     FOR_ALL_ENGINES_OF_TYPE(e, type) {
    00120       EngineID eid = e->index;
    00121       if (type == VEH_TRAIN && !this->GenerateReplaceRailList(eid, draw_left, this->replace_engines)) continue; // special rules for trains
    00122
    00123       if (draw_left) {
    00124         const uint num_engines = GetGroupNumEngines(_local_company, this->sel_group, eid);
    00125
    00126         /* Skip drawing the engines we don't have any of and haven't set for replacement */
    00127         if (num_engines == 0 && EngineReplacementForCompany(Company::Get(_local_company), eid, this->sel_group) == INVALID_ENGINE) continue;
    00128       } else {
    00129         if (!CheckAutoreplaceValidity(this->sel_engine[0], eid, _local_company)) continue;
    00130       }
    00131
    00132       *list->Append() = eid;
    00133       if (eid == this->sel_engine[side]) selected_engine = eid; // The selected engine is still in the list
    00134     }
    00135     this->sel_engine[side] = selected_engine; // update which engine we selected (the same or none, if it's not in the list anymore)
    00136     EngList_Sort(list, &EngineNumberSorter);
    00137   }
    00138
    00140   void GenerateLists()
    00141   {
    00142     EngineID e = this->sel_engine[0];
    00143
    00144     if (this->engines[0].NeedRebuild()) {
    00145       /* We need to rebuild the left engines list */
    00146       this->GenerateReplaceVehList(true);
    00147       this->vscroll[0]->SetCount(this->engines[0].Length());
    00148       if (this->reset_sel_engine && this->sel_engine[0] == INVALID_ENGINE && this->engines[0].Length() != 0) {
    00149         this->sel_engine[0] = this->engines[0][0];
    00150       }
    00151     }
    00152
    00153     if (this->engines[1].NeedRebuild() || e != this->sel_engine[0]) {
    00154       /* Either we got a request to rebuild the right engines list, or the left engines list selected a different engine */
    00155       if (this->sel_engine[0] == INVALID_ENGINE) {
    00156         /* Always empty the right engines list when nothing is selected in the left engines list */
    00157         this->engines[1].Clear();
    00158         this->sel_engine[1] = INVALID_ENGINE;
    00159       } else {
    00160         this->GenerateReplaceVehList(false);
    00161         this->vscroll[1]->SetCount(this->engines[1].Length());
    00162         if (this->reset_sel_engine && this->sel_engine[1] == INVALID_ENGINE && this->engines[1].Length() != 0) {
    00163           this->sel_engine[1] = this->engines[1][0];
    00164         }
    00165       }
    00166     }
    00167     /* Reset the flags about needed updates */
    00168     this->engines[0].RebuildDone();
    00169     this->engines[1].RebuildDone();
    00170     this->reset_sel_engine = false;
    00171   }
    00172
    00173 public:
    00174   ReplaceVehicleWindow(const WindowDesc *desc, VehicleType vehicletype, GroupID id_g) : Window()
    00175   {
    00176     if (vehicletype == VEH_TRAIN) {
    00177       /* For rail vehicles find the most used vehicle type, which is usually
    00178        * better than 'just' the first/previous vehicle type. */
    00179       uint type_count[RAILTYPE_END];
    00180       memset(type_count, 0, sizeof(type_count));
    00181
    00182       const Engine *e;
    00183       FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
    00184         if (e->u.rail.railveh_type == RAILVEH_WAGON) continue;
    00185         type_count[e->u.rail.railtype] += GetGroupNumEngines(_local_company, id_g, e->index);
    00186       }
    00187
    00188       this->sel_railtype = RAILTYPE_BEGIN;
    00189       for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) {
    00190         if (type_count[this->sel_railtype] < type_count[rt]) this->sel_railtype = rt;
    00191       }
    00192     }
    00193
    00194     this->replace_engines  = true; // start with locomotives (all other vehicles will not read this bool)
    00195     this->engines[0].ForceRebuild();
    00196     this->engines[1].ForceRebuild();
    00197     this->reset_sel_engine = true;
    00198     this->details_height   = ((vehicletype == VEH_TRAIN) ? 10 : 9) * FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
    00199     this->sel_engine[0] = INVALID_ENGINE;
    00200     this->sel_engine[1] = INVALID_ENGINE;
    00201
    00202     this->CreateNestedTree(desc);
    00203     this->vscroll[0] = this->GetScrollbar(WID_RV_LEFT_SCROLLBAR);
    00204     this->vscroll[1] = this->GetScrollbar(WID_RV_RIGHT_SCROLLBAR);
    00205     this->FinishInitNested(desc, vehicletype);
    00206
    00207     this->owner = _local_company;
    00208     this->sel_group = id_g;
    00209   }
    00210
    00211   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
    00212   {
    00213     switch (widget) {
    00214       case WID_RV_LEFT_MATRIX:
    00215       case WID_RV_RIGHT_MATRIX:
    00216         resize->height = GetEngineListHeight((VehicleType)this->window_number);
    00217         size->height = (this->window_number <= VEH_ROAD ? 8 : 4) * resize->height;
    00218         break;
    00219
    00220       case WID_RV_LEFT_DETAILS:
    00221       case WID_RV_RIGHT_DETAILS:
    00222         size->height = this->details_height;
    00223         break;
    00224
    00225       case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
    00226         StringID str = this->GetWidget<NWidgetCore>(widget)->widget_data;
    00227         SetDParam(0, STR_CONFIG_SETTING_ON);
    00228         Dimension d = GetStringBoundingBox(str);
    00229         SetDParam(0, STR_CONFIG_SETTING_OFF);
    00230         d = maxdim(d, GetStringBoundingBox(str));
    00231         d.width += padding.width;
    00232         d.height += padding.height;
    00233         *size = maxdim(*size, d);
    00234         break;
    00235       }
    00236
    00237       case WID_RV_TRAIN_ENGINEWAGON_TOGGLE: {
    00238         StringID str = this->GetWidget<NWidgetCore>(widget)->widget_data;
    00239         SetDParam(0, STR_REPLACE_ENGINES);
    00240         Dimension d = GetStringBoundingBox(str);
    00241         SetDParam(0, STR_REPLACE_WAGONS);
    00242         d = maxdim(d, GetStringBoundingBox(str));
    00243         d.width += padding.width;
    00244         d.height += padding.height;
    00245         *size = maxdim(*size, d);
    00246         break;
    00247       }
    00248
    00249       case WID_RV_INFO_TAB: {
    00250         SetDParam(0, STR_REPLACE_NOT_REPLACING);
    00251         Dimension d = GetStringBoundingBox(STR_BLACK_STRING);
    00252         SetDParam(0, STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED);
    00253         d = maxdim(d, GetStringBoundingBox(STR_BLACK_STRING));
    00254         d.width += WD_FRAMETEXT_LEFT +  WD_FRAMETEXT_RIGHT;
    00255         d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
    00256         *size = maxdim(*size, d);
    00257         break;
    00258       }
    00259
    00260       case WID_RV_TRAIN_RAILTYPE_DROPDOWN: {
    00261         Dimension d = {0, 0};
    00262         for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
    00263           const RailtypeInfo *rti = GetRailTypeInfo(rt);
    00264           /* Skip rail type if it has no label */
    00265           if (rti->label == 0) continue;
    00266           d = maxdim(d, GetStringBoundingBox(rti->strings.replace_text));
    00267         }
    00268         d.width += padding.width;
    00269         d.height += padding.height;
    00270         *size = maxdim(*size, d);
    00271         break;
    00272       }
    00273     }
    00274   }
    00275
    00276   virtual void SetStringParameters(int widget) const
    00277   {
    00278     switch (widget) {
    00279       case WID_RV_CAPTION:
    00280         SetDParam(0, STR_REPLACE_VEHICLE_TRAIN + this->window_number);
    00281         break;
    00282
    00283       case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
    00284         const Company *c = Company::Get(_local_company);
    00285         SetDParam(0, c->settings.renew_keep_length ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
    00286         break;
    00287       }
    00288
    00289       case WID_RV_TRAIN_ENGINEWAGON_TOGGLE:
    00290         SetDParam(0, this->replace_engines ? STR_REPLACE_ENGINES : STR_REPLACE_WAGONS);
    00291         break;
    00292     }
    00293   }
    00294
    00295   virtual void DrawWidget(const Rect &r, int widget) const
    00296   {
    00297     switch (widget) {
    00298       case WID_RV_INFO_TAB: {
    00299         const Company *c = Company::Get(_local_company);
    00300         if (this->sel_engine[0] != INVALID_ENGINE) {
    00301           if (!EngineHasReplacementForCompany(c, this->sel_engine[0], this->sel_group)) {
    00302             SetDParam(0, STR_REPLACE_NOT_REPLACING);
    00303           } else {
    00304             SetDParam(0, STR_ENGINE_NAME);
    00305             SetDParam(1, EngineReplacementForCompany(c, this->sel_engine[0], this->sel_group));
    00306           }
    00307         } else {
    00308           SetDParam(0, STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED);
    00309         }
    00310
    00311         DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top + WD_FRAMERECT_TOP, STR_BLACK_STRING, TC_FROMSTRING, SA_HOR_CENTER);
    00312         break;
    00313       }
    00314
    00315       case WID_RV_LEFT_MATRIX:
    00316       case WID_RV_RIGHT_MATRIX: {
    00317         int side = (widget == WID_RV_LEFT_MATRIX) ? 0 : 1;
    00318         EngineID start  = this->vscroll[side]->GetPosition(); // what is the offset for the start (scrolling)
    00319         EngineID end    = min(this->vscroll[side]->GetCapacity() + start, this->engines[side].Length());
    00320
    00321         /* Do the actual drawing */
    00322         DrawEngineList((VehicleType)this->window_number, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP,
    00323             &this->engines[side], start, end, this->sel_engine[side], side == 0, this->sel_group);
    00324         break;
    00325       }
    00326     }
    00327   }
    00328
    00329   virtual void OnPaint()
    00330   {
    00331     if (this->engines[0].NeedRebuild() || this->engines[1].NeedRebuild()) this->GenerateLists();
    00332
    00333     Company *c = Company::Get(_local_company);
    00334
    00335     /* Disable the "Start Replacing" button if:
    00336      *    Either engines list is empty
    00337      * or The selected replacement engine has a replacement (to prevent loops)
    00338      * or The right engines list (new replacement) has the existing replacement vehicle selected */
    00339     this->SetWidgetDisabledState(WID_RV_START_REPLACE,
    00340                     this->sel_engine[0] == INVALID_ENGINE ||
    00341                     this->sel_engine[1] == INVALID_ENGINE ||
    00342                     EngineReplacementForCompany(c, this->sel_engine[1], this->sel_group) != INVALID_ENGINE ||
    00343                     EngineReplacementForCompany(c, this->sel_engine[0], this->sel_group) == this->sel_engine[1]);
    00344
    00345     /* Disable the "Stop Replacing" button if:
    00346      *   The left engines list (existing vehicle) is empty
    00347      *   or The selected vehicle has no replacement set up */
    00348     this->SetWidgetDisabledState(WID_RV_STOP_REPLACE,
    00349                     this->sel_engine[0] == INVALID_ENGINE ||
    00350                     !EngineHasReplacementForCompany(c, this->sel_engine[0], this->sel_group));
    00351
    00352     /* now the actual drawing of the window itself takes place */
    00353     SetDParam(0, STR_REPLACE_VEHICLE_TRAIN + this->window_number);
    00354
    00355     if (this->window_number == VEH_TRAIN) {
    00356       /* sets the colour of that art thing */
    00357       this->GetWidget<NWidgetCore>(WID_RV_TRAIN_FLUFF_LEFT)->colour  = _company_colours[_local_company];
    00358       this->GetWidget<NWidgetCore>(WID_RV_TRAIN_FLUFF_RIGHT)->colour = _company_colours[_local_company];
    00359
    00360       /* Show the selected railtype in the pulldown menu */
    00361       this->GetWidget<NWidgetCore>(WID_RV_TRAIN_RAILTYPE_DROPDOWN)->widget_data = GetRailTypeInfo(sel_railtype)->strings.replace_text;
    00362     }
    00363
    00364     this->DrawWidgets();
    00365
    00366     if (!this->IsShaded()) {
    00367       int needed_height = this->details_height;
    00368       /* Draw details panels. */
    00369       for (int side = 0; side < 2; side++) {
    00370         if (this->sel_engine[side] != INVALID_ENGINE) {
    00371           NWidgetBase *nwi = this->GetWidget<NWidgetBase>(side == 0 ? WID_RV_LEFT_DETAILS : WID_RV_RIGHT_DETAILS);
    00372           int text_end = DrawVehiclePurchaseInfo(nwi->pos_x + WD_FRAMETEXT_LEFT, nwi->pos_x + nwi->current_x - WD_FRAMETEXT_RIGHT,
    00373               nwi->pos_y + WD_FRAMERECT_TOP, this->sel_engine[side]);
    00374           needed_height = max(needed_height, text_end - (int)nwi->pos_y + WD_FRAMERECT_BOTTOM);
    00375         }
    00376       }
    00377       if (needed_height != this->details_height) { // Details window are not high enough, enlarge them.
    00378         this->details_height = needed_height;
    00379         this->ReInit();
    00380         return;
    00381       }
    00382     }
    00383   }
    00384
    00385   virtual void OnClick(Point pt, int widget, int click_count)
    00386   {
    00387     switch (widget) {
    00388       case WID_RV_TRAIN_ENGINEWAGON_TOGGLE:
    00389         this->replace_engines  = !(this->replace_engines);
    00390         this->engines[0].ForceRebuild();
    00391         this->reset_sel_engine = true;
    00392         this->SetDirty();
    00393         break;
    00394
    00395       case WID_RV_TRAIN_RAILTYPE_DROPDOWN: // Railtype selection dropdown menu
    00396         ShowDropDownList(this, GetRailTypeDropDownList(true), sel_railtype, WID_RV_TRAIN_RAILTYPE_DROPDOWN);
    00397         break;
    00398
    00399       case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: // toggle renew_keep_length
    00400         DoCommandP(0, GetCompanySettingIndex("company.renew_keep_length"), Company::Get(_local_company)->settings.renew_keep_length ? 0 : 1, CMD_CHANGE_COMPANY_SETTING);
    00401         break;
    00402
    00403       case WID_RV_START_REPLACE: { // Start replacing
    00404         EngineID veh_from = this->sel_engine[0];
    00405         EngineID veh_to = this->sel_engine[1];
    00406         DoCommandP(0, this->sel_group << 16, veh_from + (veh_to << 16), CMD_SET_AUTOREPLACE);
    00407         this->SetDirty();
    00408         break;
    00409       }
    00410
    00411       case WID_RV_STOP_REPLACE: { // Stop replacing
    00412         EngineID veh_from = this->sel_engine[0];
    00413         DoCommandP(0, this->sel_group << 16, veh_from + (INVALID_ENGINE << 16), CMD_SET_AUTOREPLACE);
    00414         this->SetDirty();
    00415         break;
    00416       }
    00417
    00418       case WID_RV_LEFT_MATRIX:
    00419       case WID_RV_RIGHT_MATRIX: {
    00420         byte click_side;
    00421         if (widget == WID_RV_LEFT_MATRIX) {
    00422           click_side = 0;
    00423         } else {
    00424           click_side = 1;
    00425         }
    00426         uint i = this->vscroll[click_side]->GetScrolledRowFromWidget(pt.y, this, widget);
    00427         size_t engine_count = this->engines[click_side].Length();
    00428
    00429         EngineID e = engine_count > i ? this->engines[click_side][i] : INVALID_ENGINE;
    00430         if (e == this->sel_engine[click_side]) break; // we clicked the one we already selected
    00431         this->sel_engine[click_side] = e;
    00432         if (click_side == 0) {
    00433           this->engines[1].ForceRebuild();
    00434           this->reset_sel_engine = true;
    00435         }
    00436         this->SetDirty();
    00437         break;
    00438       }
    00439     }
    00440   }
    00441
    00442   virtual void OnDropdownSelect(int widget, int index)
    00443   {
    00444     RailType temp = (RailType)index;
    00445     if (temp == sel_railtype) return; // we didn't select a new one. No need to change anything
    00446     sel_railtype = temp;
    00447     /* Reset scrollbar positions */
    00448     this->vscroll[0]->SetPosition(0);
    00449     this->vscroll[1]->SetPosition(0);
    00450     /* Rebuild the lists */
    00451     this->engines[0].ForceRebuild();
    00452     this->engines[1].ForceRebuild();
    00453     this->reset_sel_engine = true;
    00454     this->SetDirty();
    00455   }
    00456
    00457   virtual void OnResize()
    00458   {
    00459     this->vscroll[0]->SetCapacityFromWidget(this, WID_RV_LEFT_MATRIX);
    00460     this->vscroll[1]->SetCapacityFromWidget(this, WID_RV_RIGHT_MATRIX);
    00461
    00462     this->GetWidget<NWidgetCore>(WID_RV_LEFT_MATRIX)->widget_data =
    00463         this->GetWidget<NWidgetCore>(WID_RV_RIGHT_MATRIX)->widget_data = (this->vscroll[0]->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
    00464   }
    00465
    00471   virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
    00472   {
    00473     if (data != 0) {
    00474       /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
    00475       this->engines[0].ForceRebuild();
    00476     } else {
    00477       this->engines[1].ForceRebuild();
    00478     }
    00479   }
    00480 };
    00481
    00482 static const NWidgetPart _nested_replace_rail_vehicle_widgets[] = {
    00483   NWidget(NWID_HORIZONTAL),
    00484     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
    00485     NWidget(WWT_CAPTION, COLOUR_GREY, WID_RV_CAPTION), SetDataTip(STR_REPLACE_VEHICLES_WHITE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    00486     NWidget(WWT_SHADEBOX, COLOUR_GREY),
    00487     NWidget(WWT_STICKYBOX, COLOUR_GREY),
    00488   EndContainer(),
    00489   NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    00490     NWidget(WWT_MATRIX, COLOUR_GREY, WID_RV_LEFT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetDataTip(0x1, STR_REPLACE_HELP_LEFT_ARRAY), SetResize(1, 1), SetScrollbar(WID_RV_LEFT_SCROLLBAR),
    00491     NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_LEFT_SCROLLBAR),
    00492     NWidget(WWT_MATRIX, COLOUR_GREY, WID_RV_RIGHT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetDataTip(0x1, STR_REPLACE_HELP_RIGHT_ARRAY), SetResize(1, 1), SetScrollbar(WID_RV_RIGHT_SCROLLBAR),
    00493     NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_RIGHT_SCROLLBAR),
    00494   EndContainer(),
    00495   NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    00496     NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_LEFT_DETAILS), SetMinimalSize(228, 102), SetResize(1, 0), EndContainer(),
    00497     NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_RIGHT_DETAILS), SetMinimalSize(228, 102), SetResize(1, 0), EndContainer(),
    00498   EndContainer(),
    00499   NWidget(NWID_HORIZONTAL),
    00500     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON),
    00501     NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB), SetResize(1, 0),
    00502     EndContainer(),
    00503     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_STOP_REPLACE), SetMinimalSize(150, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON),
    00504   EndContainer(),
    00505   NWidget(NWID_HORIZONTAL),
    00506     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_TRAIN_ENGINEWAGON_TOGGLE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_ENGINE_WAGON_SELECT, STR_REPLACE_ENGINE_WAGON_SELECT_HELP),
    00507     NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_TRAIN_FLUFF_LEFT), SetMinimalSize(15, 12), EndContainer(),
    00508     NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_TRAIN_RAILTYPE_DROPDOWN), SetMinimalSize(136, 12), SetDataTip(0x0, STR_REPLACE_HELP_RAILTYPE), SetResize(1, 0),
    00509     NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_TRAIN_FLUFF_RIGHT), SetMinimalSize(16, 12), EndContainer(),
    00510     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_TRAIN_WAGONREMOVE_TOGGLE), SetMinimalSize(138, 12), SetDataTip(STR_REPLACE_REMOVE_WAGON, STR_REPLACE_REMOVE_WAGON_HELP),
    00511     NWidget(WWT_RESIZEBOX, COLOUR_GREY),
    00512   EndContainer(),
    00513 };
    00514
    00515 static const WindowDesc _replace_rail_vehicle_desc(
    00516   WDP_AUTO, 456, 140,
    00517   WC_REPLACE_VEHICLE, WC_NONE,
    00518   WDF_UNCLICK_BUTTONS | WDF_CONSTRUCTION,
    00519   _nested_replace_rail_vehicle_widgets, lengthof(_nested_replace_rail_vehicle_widgets)
    00520 );
    00521
    00522 static const NWidgetPart _nested_replace_vehicle_widgets[] = {
    00523   NWidget(NWID_HORIZONTAL),
    00524     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
    00525     NWidget(WWT_CAPTION, COLOUR_GREY, WID_RV_CAPTION), SetMinimalSize(433, 14), SetDataTip(STR_REPLACE_VEHICLES_WHITE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    00526     NWidget(WWT_SHADEBOX, COLOUR_GREY),
    00527     NWidget(WWT_STICKYBOX, COLOUR_GREY),
    00528   EndContainer(),
    00529   NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    00530     NWidget(WWT_MATRIX, COLOUR_GREY, WID_RV_LEFT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetDataTip(0x1, STR_REPLACE_HELP_LEFT_ARRAY), SetResize(1, 1), SetScrollbar(WID_RV_LEFT_SCROLLBAR),
    00531     NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_LEFT_SCROLLBAR),
    00532     NWidget(WWT_MATRIX, COLOUR_GREY, WID_RV_RIGHT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetDataTip(0x1, STR_REPLACE_HELP_RIGHT_ARRAY), SetResize(1, 1), SetScrollbar(WID_RV_RIGHT_SCROLLBAR),
    00533     NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_RIGHT_SCROLLBAR),
    00534   EndContainer(),
    00535   NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    00536     NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_LEFT_DETAILS), SetMinimalSize(228, 92), SetResize(1, 0), EndContainer(),
    00537     NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_RIGHT_DETAILS), SetMinimalSize(228, 92), SetResize(1, 0), EndContainer(),
    00538   EndContainer(),
    00539   NWidget(NWID_HORIZONTAL),
    00540     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON),
    00541     NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB), SetResize(1, 0), EndContainer(),
    00542     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_STOP_REPLACE), SetMinimalSize(138, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON),
    00543     NWidget(WWT_RESIZEBOX, COLOUR_GREY),
    00544   EndContainer(),
    00545 };
    00546
    00547 static const WindowDesc _replace_vehicle_desc(
    00548   WDP_AUTO, 456, 118,
    00549   WC_REPLACE_VEHICLE, WC_NONE,
    00550   WDF_UNCLICK_BUTTONS | WDF_CONSTRUCTION,
    00551   _nested_replace_vehicle_widgets, lengthof(_nested_replace_vehicle_widgets)
    00552 );
    00553
    00559 void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
    00560 {
    00561   DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype);
    00562   new ReplaceVehicleWindow(vehicletype == VEH_TRAIN ? &_replace_rail_vehicle_desc : &_replace_vehicle_desc, vehicletype, id_g);
    00563 }