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