# autoreplace_gui.cpp

Go to the documentation of this file.

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