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