autoreplace_gui.cpp

Go to the documentation of this file.
00001 /* $Id: autoreplace_gui.cpp 24939 2013-01-23 20:00:00Z peter1138 $ */
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         this->GenerateReplaceVehList(false);
00168         this->vscroll[1]->SetCount(this->engines[1].Length());
00169         if (this->reset_sel_engine && this->sel_engine[1] == INVALID_ENGINE && this->engines[1].Length() != 0) {
00170           this->sel_engine[1] = this->engines[1][0];
00171         }
00172       }
00173     }
00174     /* Reset the flags about needed updates */
00175     this->engines[0].RebuildDone();
00176     this->engines[1].RebuildDone();
00177     this->reset_sel_engine = false;
00178   }
00179 
00184   void ReplaceClick_StartReplace(bool replace_when_old)
00185   {
00186     EngineID veh_from = this->sel_engine[0];
00187     EngineID veh_to = this->sel_engine[1];
00188     DoCommandP(0, (replace_when_old ? 1 : 0) | (this->sel_group << 16), veh_from + (veh_to << 16), CMD_SET_AUTOREPLACE);
00189   }
00190 
00191 public:
00192   ReplaceVehicleWindow(const WindowDesc *desc, VehicleType vehicletype, GroupID id_g) : Window()
00193   {
00194     if (vehicletype == VEH_TRAIN) {
00195       /* For rail vehicles find the most used vehicle type, which is usually
00196        * better than 'just' the first/previous vehicle type. */
00197       uint type_count[RAILTYPE_END];
00198       memset(type_count, 0, sizeof(type_count));
00199 
00200       const Engine *e;
00201       FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
00202         if (e->u.rail.railveh_type == RAILVEH_WAGON) continue;
00203         type_count[e->u.rail.railtype] += GetGroupNumEngines(_local_company, id_g, e->index);
00204       }
00205 
00206       this->sel_railtype = RAILTYPE_BEGIN;
00207       for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) {
00208         if (type_count[this->sel_railtype] < type_count[rt]) this->sel_railtype = rt;
00209       }
00210     }
00211 
00212     this->replace_engines  = true; // start with locomotives (all other vehicles will not read this bool)
00213     this->engines[0].ForceRebuild();
00214     this->engines[1].ForceRebuild();
00215     this->reset_sel_engine = true;
00216     this->details_height   = ((vehicletype == VEH_TRAIN) ? 10 : 9) * FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
00217     this->sel_engine[0] = INVALID_ENGINE;
00218     this->sel_engine[1] = INVALID_ENGINE;
00219 
00220     this->CreateNestedTree(desc);
00221     this->vscroll[0] = this->GetScrollbar(WID_RV_LEFT_SCROLLBAR);
00222     this->vscroll[1] = this->GetScrollbar(WID_RV_RIGHT_SCROLLBAR);
00223     this->FinishInitNested(desc, vehicletype);
00224 
00225     this->owner = _local_company;
00226     this->sel_group = id_g;
00227   }
00228 
00229   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
00230   {
00231     switch (widget) {
00232       case WID_RV_LEFT_MATRIX:
00233       case WID_RV_RIGHT_MATRIX:
00234         resize->height = GetEngineListHeight((VehicleType)this->window_number);
00235         size->height = (this->window_number <= VEH_ROAD ? 8 : 4) * resize->height;
00236         break;
00237 
00238       case WID_RV_LEFT_DETAILS:
00239       case WID_RV_RIGHT_DETAILS:
00240         size->height = this->details_height;
00241         break;
00242 
00243       case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
00244         StringID str = this->GetWidget<NWidgetCore>(widget)->widget_data;
00245         SetDParam(0, STR_CONFIG_SETTING_ON);
00246         Dimension d = GetStringBoundingBox(str);
00247         SetDParam(0, STR_CONFIG_SETTING_OFF);
00248         d = maxdim(d, GetStringBoundingBox(str));
00249         d.width += padding.width;
00250         d.height += padding.height;
00251         *size = maxdim(*size, d);
00252         break;
00253       }
00254 
00255       case WID_RV_TRAIN_ENGINEWAGON_TOGGLE: {
00256         StringID str = this->GetWidget<NWidgetCore>(widget)->widget_data;
00257         SetDParam(0, STR_REPLACE_ENGINES);
00258         Dimension d = GetStringBoundingBox(str);
00259         SetDParam(0, STR_REPLACE_WAGONS);
00260         d = maxdim(d, GetStringBoundingBox(str));
00261         d.width += padding.width;
00262         d.height += padding.height;
00263         *size = maxdim(*size, d);
00264         break;
00265       }
00266 
00267       case WID_RV_INFO_TAB: {
00268         SetDParam(0, STR_REPLACE_NOT_REPLACING);
00269         Dimension d = GetStringBoundingBox(STR_BLACK_STRING);
00270         SetDParam(0, STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED);
00271         d = maxdim(d, GetStringBoundingBox(STR_BLACK_STRING));
00272         d.width += WD_FRAMETEXT_LEFT +  WD_FRAMETEXT_RIGHT;
00273         d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
00274         *size = maxdim(*size, d);
00275         break;
00276       }
00277 
00278       case WID_RV_TRAIN_RAILTYPE_DROPDOWN: {
00279         Dimension d = {0, 0};
00280         for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
00281           const RailtypeInfo *rti = GetRailTypeInfo(rt);
00282           /* Skip rail type if it has no label */
00283           if (rti->label == 0) continue;
00284           d = maxdim(d, GetStringBoundingBox(rti->strings.replace_text));
00285         }
00286         d.width += padding.width;
00287         d.height += padding.height;
00288         *size = maxdim(*size, d);
00289         break;
00290       }
00291 
00292       case WID_RV_START_REPLACE: {
00293         Dimension d = GetStringBoundingBox(STR_REPLACE_VEHICLES_START);
00294         for (int i = 0; _start_replace_dropdown[i] != INVALID_STRING_ID; i++) {
00295           d = maxdim(d, GetStringBoundingBox(_start_replace_dropdown[i]));
00296         }
00297         d.width += padding.width;
00298         d.height += padding.height;
00299         *size = maxdim(*size, d);
00300         break;
00301       }
00302     }
00303   }
00304 
00305   virtual void SetStringParameters(int widget) const
00306   {
00307     switch (widget) {
00308       case WID_RV_CAPTION:
00309         SetDParam(0, STR_REPLACE_VEHICLE_TRAIN + this->window_number);
00310         switch (this->sel_group) {
00311           case ALL_GROUP:
00312             SetDParam(1, STR_GROUP_ALL_TRAINS + this->window_number);
00313             break;
00314 
00315           case DEFAULT_GROUP:
00316             SetDParam(1, STR_GROUP_DEFAULT_TRAINS + this->window_number);
00317             break;
00318 
00319           default:
00320             SetDParam(1, STR_GROUP_NAME);
00321             SetDParam(2, sel_group);
00322             break;
00323         }
00324         break;
00325 
00326       case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
00327         const Company *c = Company::Get(_local_company);
00328         SetDParam(0, c->settings.renew_keep_length ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
00329         break;
00330       }
00331 
00332       case WID_RV_TRAIN_ENGINEWAGON_TOGGLE:
00333         SetDParam(0, this->replace_engines ? STR_REPLACE_ENGINES : STR_REPLACE_WAGONS);
00334         break;
00335     }
00336   }
00337 
00338   virtual void DrawWidget(const Rect &r, int widget) const
00339   {
00340     switch (widget) {
00341       case WID_RV_INFO_TAB: {
00342         const Company *c = Company::Get(_local_company);
00343         if (this->sel_engine[0] != INVALID_ENGINE) {
00344           if (!EngineHasReplacementForCompany(c, this->sel_engine[0], this->sel_group)) {
00345             SetDParam(0, STR_REPLACE_NOT_REPLACING);
00346           } else {
00347             bool when_old = false;
00348             EngineID e = EngineReplacementForCompany(c, this->sel_engine[0], this->sel_group, &when_old);
00349             SetDParam(0, when_old ? STR_REPLACE_REPLACING_WHEN_OLD : STR_ENGINE_NAME);
00350             SetDParam(1, e);
00351           }
00352         } else {
00353           SetDParam(0, STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED);
00354         }
00355 
00356         DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top + WD_FRAMERECT_TOP, STR_BLACK_STRING, TC_FROMSTRING, SA_HOR_CENTER);
00357         break;
00358       }
00359 
00360       case WID_RV_LEFT_MATRIX:
00361       case WID_RV_RIGHT_MATRIX: {
00362         int side = (widget == WID_RV_LEFT_MATRIX) ? 0 : 1;
00363         EngineID start  = this->vscroll[side]->GetPosition(); // what is the offset for the start (scrolling)
00364         EngineID end    = min(this->vscroll[side]->GetCapacity() + start, this->engines[side].Length());
00365 
00366         /* Do the actual drawing */
00367         DrawEngineList((VehicleType)this->window_number, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP,
00368             &this->engines[side], start, end, this->sel_engine[side], side == 0, this->sel_group);
00369         break;
00370       }
00371     }
00372   }
00373 
00374   virtual void OnPaint()
00375   {
00376     if (this->engines[0].NeedRebuild() || this->engines[1].NeedRebuild()) this->GenerateLists();
00377 
00378     Company *c = Company::Get(_local_company);
00379 
00380     /* Disable the "Start Replacing" button if:
00381      *    Either engines list is empty
00382      * or The selected replacement engine has a replacement (to prevent loops). */
00383     this->SetWidgetDisabledState(WID_RV_START_REPLACE,
00384                     this->sel_engine[0] == INVALID_ENGINE ||
00385                     this->sel_engine[1] == INVALID_ENGINE ||
00386                     EngineReplacementForCompany(c, this->sel_engine[1], this->sel_group) != INVALID_ENGINE);
00387 
00388     /* Disable the "Stop Replacing" button if:
00389      *   The left engines list (existing vehicle) is empty
00390      *   or The selected vehicle has no replacement set up */
00391     this->SetWidgetDisabledState(WID_RV_STOP_REPLACE,
00392                     this->sel_engine[0] == INVALID_ENGINE ||
00393                     !EngineHasReplacementForCompany(c, this->sel_engine[0], this->sel_group));
00394 
00395     if (this->window_number == VEH_TRAIN) {
00396       /* sets the colour of that art thing */
00397       this->GetWidget<NWidgetCore>(WID_RV_TRAIN_FLUFF_LEFT)->colour  = _company_colours[_local_company];
00398       this->GetWidget<NWidgetCore>(WID_RV_TRAIN_FLUFF_RIGHT)->colour = _company_colours[_local_company];
00399 
00400       /* Show the selected railtype in the pulldown menu */
00401       this->GetWidget<NWidgetCore>(WID_RV_TRAIN_RAILTYPE_DROPDOWN)->widget_data = GetRailTypeInfo(sel_railtype)->strings.replace_text;
00402     }
00403 
00404     this->DrawWidgets();
00405 
00406     if (!this->IsShaded()) {
00407       int needed_height = this->details_height;
00408       /* Draw details panels. */
00409       for (int side = 0; side < 2; side++) {
00410         if (this->sel_engine[side] != INVALID_ENGINE) {
00411           NWidgetBase *nwi = this->GetWidget<NWidgetBase>(side == 0 ? WID_RV_LEFT_DETAILS : WID_RV_RIGHT_DETAILS);
00412           int text_end = DrawVehiclePurchaseInfo(nwi->pos_x + WD_FRAMETEXT_LEFT, nwi->pos_x + nwi->current_x - WD_FRAMETEXT_RIGHT,
00413               nwi->pos_y + WD_FRAMERECT_TOP, this->sel_engine[side]);
00414           needed_height = max(needed_height, text_end - (int)nwi->pos_y + WD_FRAMERECT_BOTTOM);
00415         }
00416       }
00417       if (needed_height != this->details_height) { // Details window are not high enough, enlarge them.
00418         this->details_height = needed_height;
00419         this->ReInit();
00420         return;
00421       }
00422     }
00423   }
00424 
00425   virtual void OnClick(Point pt, int widget, int click_count)
00426   {
00427     switch (widget) {
00428       case WID_RV_TRAIN_ENGINEWAGON_TOGGLE:
00429         this->replace_engines  = !(this->replace_engines);
00430         this->engines[0].ForceRebuild();
00431         this->reset_sel_engine = true;
00432         this->SetDirty();
00433         break;
00434 
00435       case WID_RV_TRAIN_RAILTYPE_DROPDOWN: // Railtype selection dropdown menu
00436         ShowDropDownList(this, GetRailTypeDropDownList(true), sel_railtype, WID_RV_TRAIN_RAILTYPE_DROPDOWN);
00437         break;
00438 
00439       case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: // toggle renew_keep_length
00440         DoCommandP(0, GetCompanySettingIndex("company.renew_keep_length"), Company::Get(_local_company)->settings.renew_keep_length ? 0 : 1, CMD_CHANGE_COMPANY_SETTING);
00441         break;
00442 
00443       case WID_RV_START_REPLACE: { // Start replacing
00444         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
00445           this->HandleButtonClick(WID_RV_START_REPLACE);
00446           ReplaceClick_StartReplace(false);
00447         } else {
00448           bool replacment_when_old = EngineHasReplacementWhenOldForCompany(Company::Get(_local_company), this->sel_engine[0], this->sel_group);
00449           ShowDropDownMenu(this, _start_replace_dropdown, replacment_when_old ? 1 : 0, WID_RV_START_REPLACE, !this->replace_engines ? 1 << 1 : 0, 0);
00450         }
00451         break;
00452       }
00453 
00454       case WID_RV_STOP_REPLACE: { // Stop replacing
00455         EngineID veh_from = this->sel_engine[0];
00456         DoCommandP(0, this->sel_group << 16, veh_from + (INVALID_ENGINE << 16), CMD_SET_AUTOREPLACE);
00457         break;
00458       }
00459 
00460       case WID_RV_LEFT_MATRIX:
00461       case WID_RV_RIGHT_MATRIX: {
00462         byte click_side;
00463         if (widget == WID_RV_LEFT_MATRIX) {
00464           click_side = 0;
00465         } else {
00466           click_side = 1;
00467         }
00468         uint i = this->vscroll[click_side]->GetScrolledRowFromWidget(pt.y, this, widget);
00469         size_t engine_count = this->engines[click_side].Length();
00470 
00471         EngineID e = engine_count > i ? this->engines[click_side][i] : INVALID_ENGINE;
00472         if (e == this->sel_engine[click_side]) break; // we clicked the one we already selected
00473         this->sel_engine[click_side] = e;
00474         if (click_side == 0) {
00475           this->engines[1].ForceRebuild();
00476           this->reset_sel_engine = true;
00477         }
00478         this->SetDirty();
00479         break;
00480       }
00481     }
00482   }
00483 
00484   virtual void OnDropdownSelect(int widget, int index)
00485   {
00486     switch (widget) {
00487       case WID_RV_TRAIN_RAILTYPE_DROPDOWN: {
00488         RailType temp = (RailType)index;
00489         if (temp == sel_railtype) return; // we didn't select a new one. No need to change anything
00490         sel_railtype = temp;
00491         /* Reset scrollbar positions */
00492         this->vscroll[0]->SetPosition(0);
00493         this->vscroll[1]->SetPosition(0);
00494         /* Rebuild the lists */
00495         this->engines[0].ForceRebuild();
00496         this->engines[1].ForceRebuild();
00497         this->reset_sel_engine = true;
00498         this->SetDirty();
00499         break;
00500       }
00501 
00502       case WID_RV_START_REPLACE:
00503         this->ReplaceClick_StartReplace(index != 0);
00504         break;
00505     }
00506   }
00507 
00508   virtual void OnResize()
00509   {
00510     this->vscroll[0]->SetCapacityFromWidget(this, WID_RV_LEFT_MATRIX);
00511     this->vscroll[1]->SetCapacityFromWidget(this, WID_RV_RIGHT_MATRIX);
00512 
00513     this->GetWidget<NWidgetCore>(WID_RV_LEFT_MATRIX)->widget_data =
00514         this->GetWidget<NWidgetCore>(WID_RV_RIGHT_MATRIX)->widget_data = (this->vscroll[0]->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
00515   }
00516 
00522   virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
00523   {
00524     if (data != 0) {
00525       /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
00526       this->engines[0].ForceRebuild();
00527     } else {
00528       this->engines[1].ForceRebuild();
00529     }
00530   }
00531 };
00532 
00533 static const NWidgetPart _nested_replace_rail_vehicle_widgets[] = {
00534   NWidget(NWID_HORIZONTAL),
00535     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
00536     NWidget(WWT_CAPTION, COLOUR_GREY, WID_RV_CAPTION), SetDataTip(STR_REPLACE_VEHICLES_WHITE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00537     NWidget(WWT_SHADEBOX, COLOUR_GREY),
00538     NWidget(WWT_STICKYBOX, COLOUR_GREY),
00539   EndContainer(),
00540   NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
00541     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),
00542     NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_LEFT_SCROLLBAR),
00543     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),
00544     NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_RIGHT_SCROLLBAR),
00545   EndContainer(),
00546   NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
00547     NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_LEFT_DETAILS), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
00548     NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_RIGHT_DETAILS), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
00549   EndContainer(),
00550   NWidget(NWID_HORIZONTAL),
00551     NWidget(NWID_PUSHBUTTON_DROPDOWN, COLOUR_GREY, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON),
00552     NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB), SetResize(1, 0),
00553     EndContainer(),
00554     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_STOP_REPLACE), SetMinimalSize(150, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON),
00555   EndContainer(),
00556   NWidget(NWID_HORIZONTAL),
00557     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),
00558     NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_TRAIN_FLUFF_LEFT), SetMinimalSize(15, 12), EndContainer(),
00559     NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_TRAIN_RAILTYPE_DROPDOWN), SetMinimalSize(136, 12), SetDataTip(0x0, STR_REPLACE_HELP_RAILTYPE), SetResize(1, 0),
00560     NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_TRAIN_FLUFF_RIGHT), SetMinimalSize(16, 12), EndContainer(),
00561     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_TRAIN_WAGONREMOVE_TOGGLE), SetMinimalSize(138, 12), SetDataTip(STR_REPLACE_REMOVE_WAGON, STR_REPLACE_REMOVE_WAGON_HELP),
00562     NWidget(WWT_RESIZEBOX, COLOUR_GREY),
00563   EndContainer(),
00564 };
00565 
00566 static const WindowDesc _replace_rail_vehicle_desc(
00567   WDP_AUTO, 500, 140,
00568   WC_REPLACE_VEHICLE, WC_NONE,
00569   WDF_CONSTRUCTION,
00570   _nested_replace_rail_vehicle_widgets, lengthof(_nested_replace_rail_vehicle_widgets)
00571 );
00572 
00573 static const NWidgetPart _nested_replace_vehicle_widgets[] = {
00574   NWidget(NWID_HORIZONTAL),
00575     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
00576     NWidget(WWT_CAPTION, COLOUR_GREY, WID_RV_CAPTION), SetMinimalSize(433, 14), SetDataTip(STR_REPLACE_VEHICLES_WHITE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00577     NWidget(WWT_SHADEBOX, COLOUR_GREY),
00578     NWidget(WWT_STICKYBOX, COLOUR_GREY),
00579   EndContainer(),
00580   NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
00581     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),
00582     NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_LEFT_SCROLLBAR),
00583     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),
00584     NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_RIGHT_SCROLLBAR),
00585   EndContainer(),
00586   NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
00587     NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_LEFT_DETAILS), SetMinimalSize(228, 92), SetResize(1, 0), EndContainer(),
00588     NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_RIGHT_DETAILS), SetMinimalSize(228, 92), SetResize(1, 0), EndContainer(),
00589   EndContainer(),
00590   NWidget(NWID_HORIZONTAL),
00591     NWidget(NWID_PUSHBUTTON_DROPDOWN, COLOUR_GREY, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON),
00592     NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB), SetResize(1, 0), EndContainer(),
00593     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_STOP_REPLACE), SetMinimalSize(138, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON),
00594     NWidget(WWT_RESIZEBOX, COLOUR_GREY),
00595   EndContainer(),
00596 };
00597 
00598 static const WindowDesc _replace_vehicle_desc(
00599   WDP_AUTO, 456, 118,
00600   WC_REPLACE_VEHICLE, WC_NONE,
00601   WDF_CONSTRUCTION,
00602   _nested_replace_vehicle_widgets, lengthof(_nested_replace_vehicle_widgets)
00603 );
00604 
00610 void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
00611 {
00612   DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype);
00613   new ReplaceVehicleWindow(vehicletype == VEH_TRAIN ? &_replace_rail_vehicle_desc : &_replace_vehicle_desc, vehicletype, id_g);
00614 }