# autoreplace_gui.cpp

Go to the documentation of this file.

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