# depot_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 "train.h"
    00014 #include "ship.h"
    00015 #include "aircraft.h"
    00016 #include "gui.h"
    00017 #include "textbuf_gui.h"
    00018 #include "viewport_func.h"
    00019 #include "command_func.h"
    00020 #include "depot_base.h"
    00021 #include "spritecache.h"
    00022 #include "strings_func.h"
    00023 #include "vehicle_func.h"
    00024 #include "company_func.h"
    00025 #include "tilehighlight_func.h"
    00026 #include "window_gui.h"
    00027 #include "vehiclelist.h"
    00028 #include "order_backup.h"
    00029 #include "zoom_func.h"
    00030
    00031 #include "widgets/depot_widget.h"
    00032
    00033 #include "table/strings.h"
    00034
    00035 /*
    00036  * Since all depot window sizes aren't the same, we need to modify sizes a little.
    00037  * It's done with the following arrays of widget indexes. Each of them tells if a widget side should be moved and in what direction.
    00038  * How long they should be moved and for what window types are controlled in ShowDepotWindow()
    00039  */
    00040
    00042 static const NWidgetPart _nested_train_depot_widgets[] = {
    00043   NWidget(NWID_HORIZONTAL),
    00044     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
    00045     NWidget(WWT_CAPTION, COLOUR_GREY, WID_D_CAPTION), SetDataTip(STR_DEPOT_CAPTION, STR_NULL),
    00046     NWidget(WWT_SHADEBOX, COLOUR_GREY),
    00047     NWidget(WWT_STICKYBOX, COLOUR_GREY),
    00048   EndContainer(),
    00049   NWidget(NWID_HORIZONTAL),
    00050     NWidget(NWID_VERTICAL),
    00051       NWidget(WWT_MATRIX, COLOUR_GREY, WID_D_MATRIX), SetDataTip(0x0, STR_NULL), SetResize(1, 1), SetScrollbar(WID_D_V_SCROLL),
    00052       NWidget(NWID_SELECTION, INVALID_COLOUR, WID_D_SHOW_H_SCROLL),
    00053         NWidget(NWID_HSCROLLBAR, COLOUR_GREY, WID_D_H_SCROLL),
    00054       EndContainer(),
    00055     EndContainer(),
    00056     NWidget(NWID_VERTICAL),
    00057       NWidget(WWT_IMGBTN, COLOUR_GREY, WID_D_SELL), SetDataTip(0x0, STR_NULL), SetResize(0, 1), SetFill(0, 1),
    00058       NWidget(NWID_SELECTION, INVALID_COLOUR, WID_D_SHOW_SELL_CHAIN),
    00059         NWidget(WWT_IMGBTN, COLOUR_GREY, WID_D_SELL_CHAIN), SetDataTip(SPR_SELL_CHAIN_TRAIN, STR_DEPOT_DRAG_WHOLE_TRAIN_TO_SELL_TOOLTIP), SetResize(0, 1), SetFill(0, 1),
    00060       EndContainer(),
    00061       NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_D_SELL_ALL), SetDataTip(0x0, STR_NULL),
    00062       NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_D_AUTOREPLACE), SetDataTip(0x0, STR_NULL),
    00063     EndContainer(),
    00064     NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_D_V_SCROLL),
    00065   EndContainer(),
    00066   NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    00067     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_D_BUILD), SetDataTip(0x0, STR_NULL), SetFill(1, 1), SetResize(1, 0),
    00068     NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_D_CLONE), SetDataTip(0x0, STR_NULL), SetFill(1, 1), SetResize(1, 0),
    00069     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_D_LOCATION), SetDataTip(STR_BUTTON_LOCATION, STR_NULL), SetFill(1, 1), SetResize(1, 0),
    00070     NWidget(NWID_SELECTION, INVALID_COLOUR, WID_D_SHOW_RENAME), // rename button
    00071       NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_D_RENAME), SetDataTip(STR_BUTTON_RENAME, STR_DEPOT_RENAME_TOOLTIP), SetFill(1, 1), SetResize(1, 0),
    00072     EndContainer(),
    00073     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_D_VEHICLE_LIST), SetDataTip(0x0, STR_NULL), SetFill(0, 1),
    00074     NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_D_STOP_ALL), SetDataTip(SPR_FLAG_VEH_STOPPED, STR_NULL), SetFill(0, 1),
    00075     NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_D_START_ALL), SetDataTip(SPR_FLAG_VEH_RUNNING, STR_NULL), SetFill(0, 1),
    00076     NWidget(WWT_RESIZEBOX, COLOUR_GREY),
    00077   EndContainer(),
    00078 };
    00079
    00080 static const WindowDesc _train_depot_desc(
    00081   WDP_AUTO, 362, 123,
    00082   WC_VEHICLE_DEPOT, WC_NONE,
    00083   0,
    00084   _nested_train_depot_widgets, lengthof(_nested_train_depot_widgets)
    00085 );
    00086
    00087 static const WindowDesc _road_depot_desc(
    00088   WDP_AUTO, 316, 97,
    00089   WC_VEHICLE_DEPOT, WC_NONE,
    00090   0,
    00091   _nested_train_depot_widgets, lengthof(_nested_train_depot_widgets)
    00092 );
    00093
    00094 static const WindowDesc _ship_depot_desc(
    00095   WDP_AUTO, 306, 99,
    00096   WC_VEHICLE_DEPOT, WC_NONE,
    00097   0,
    00098   _nested_train_depot_widgets, lengthof(_nested_train_depot_widgets)
    00099 );
    00100
    00101 static const WindowDesc _aircraft_depot_desc(
    00102   WDP_AUTO, 332, 99,
    00103   WC_VEHICLE_DEPOT, WC_NONE,
    00104   0,
    00105   _nested_train_depot_widgets, lengthof(_nested_train_depot_widgets)
    00106 );
    00107
    00108 extern void DepotSortList(VehicleList *list);
    00109
    00117 void CcCloneVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
    00118 {
    00119   if (result.Failed()) return;
    00120
    00121   const Vehicle *v = Vehicle::Get(_new_vehicle_id);
    00122
    00123   ShowVehicleViewWindow(v);
    00124 }
    00125
    00126 static void TrainDepotMoveVehicle(const Vehicle *wagon, VehicleID sel, const Vehicle *head)
    00127 {
    00128   const Vehicle *v = Vehicle::Get(sel);
    00129
    00130   if (v == wagon) return;
    00131
    00132   if (wagon == NULL) {
    00133     if (head != NULL) wagon = head->Last();
    00134   } else {
    00135     wagon = wagon->Previous();
    00136     if (wagon == NULL) return;
    00137   }
    00138
    00139   if (wagon == v) return;
    00140
    00141   DoCommandP(v->tile, v->index | (_ctrl_pressed ? 1 : 0) << 20, wagon == NULL ? INVALID_VEHICLE : wagon->index, CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_MOVE_VEHICLE));
    00142 }
    00143
    00148 static Dimension _base_block_sizes[4];
    00149
    00150 static void InitBlocksizeForShipAircraft(VehicleType type)
    00151 {
    00152   uint max_width  = 0;
    00153   uint max_height = 0;
    00154
    00155   const Engine *e;
    00156   FOR_ALL_ENGINES_OF_TYPE(e, type) {
    00157     EngineID eid = e->index;
    00158     uint x, y;
    00159
    00160     switch (type) {
    00161       default: NOT_REACHED();
    00162       case VEH_SHIP:     GetShipSpriteSize(    eid, x, y, EIT_IN_DEPOT); break;
    00163       case VEH_AIRCRAFT: GetAircraftSpriteSize(eid, x, y, EIT_IN_DEPOT); break;
    00164     }
    00165     if (x > max_width)  max_width  = x;
    00166     if (y > max_height) max_height = y;
    00167   }
    00168
    00169   switch (type) {
    00170     default: NOT_REACHED();
    00171     case VEH_SHIP:
    00172       _base_block_sizes[VEH_SHIP].width = max(76U, max_width);
    00173       break;
    00174     case VEH_AIRCRAFT:
    00175       _base_block_sizes[VEH_AIRCRAFT].width = max(67U, max_width);
    00176       break;
    00177   }
    00178   _base_block_sizes[type].height = max(GetVehicleHeight(type), max_height);
    00179 }
    00180
    00185 void InitDepotWindowBlockSizes()
    00186 {
    00187   _base_block_sizes[VEH_TRAIN].width = 0;
    00188   _base_block_sizes[VEH_TRAIN].height = GetVehicleHeight(VEH_TRAIN);
    00189
    00190   _base_block_sizes[VEH_ROAD].width = 32;
    00191   _base_block_sizes[VEH_ROAD].height = GetVehicleHeight(VEH_ROAD);
    00192
    00193   InitBlocksizeForShipAircraft(VEH_SHIP);
    00194   InitBlocksizeForShipAircraft(VEH_AIRCRAFT);
    00195 }
    00196
    00197 static void DepotSellAllConfirmationCallback(Window *w, bool confirmed);
    00198 const Sprite *GetAircraftSprite(EngineID engine);
    00199
    00200 struct DepotWindow : Window {
    00201   VehicleID sel;
    00202   VehicleID vehicle_over;
    00203   VehicleType type;
    00204   bool generate_list;
    00205   VehicleList vehicle_list;
    00206   VehicleList wagon_list;
    00207   uint num_columns;
    00208   Scrollbar *hscroll;
    00209   Scrollbar *vscroll;
    00210
    00211   DepotWindow(const WindowDesc *desc, TileIndex tile, VehicleType type) : Window()
    00212   {
    00213     assert(IsCompanyBuildableVehicleType(type)); // ensure that we make the call with a valid type
    00214
    00215     this->sel = INVALID_VEHICLE;
    00216     this->vehicle_over = INVALID_VEHICLE;
    00217     this->generate_list = true;
    00218     this->type = type;
    00219     this->num_columns = 1; // for non-trains this gets set in FinishInitNested()
    00220
    00221     this->CreateNestedTree(desc);
    00222     this->hscroll = (this->type == VEH_TRAIN ? this->GetScrollbar(WID_D_H_SCROLL) : NULL);
    00223     this->vscroll = this->GetScrollbar(WID_D_V_SCROLL);
    00224     /* Don't show 'rename button' of aircraft hangar */
    00225     this->GetWidget<NWidgetStacked>(WID_D_SHOW_RENAME)->SetDisplayedPlane(type == VEH_AIRCRAFT ? SZSP_NONE : 0);
    00226     /* Only train depots have a horizontal scrollbar and a 'sell chain' button */
    00227     this->GetWidget<NWidgetStacked>(WID_D_SHOW_H_SCROLL)->SetDisplayedPlane(type == VEH_TRAIN ? 0 : SZSP_HORIZONTAL);
    00228     this->GetWidget<NWidgetStacked>(WID_D_SHOW_SELL_CHAIN)->SetDisplayedPlane(type == VEH_TRAIN ? 0 : SZSP_NONE);
    00229     this->SetupWidgetData(type);
    00230     this->FinishInitNested(desc, tile);
    00231
    00232     this->owner = GetTileOwner(tile);
    00233     OrderBackup::Reset();
    00234   }
    00235
    00236   ~DepotWindow()
    00237   {
    00238     DeleteWindowById(WC_BUILD_VEHICLE, this->window_number);
    00239     OrderBackup::Reset(this->window_number);
    00240   }
    00241
    00249   void DrawVehicleInDepot(const Vehicle *v, int left, int right, int y) const
    00250   {
    00251     bool free_wagon = false;
    00252     int sprite_y = y + (this->resize.step_height - GetVehicleHeight(v->type)) / 2;
    00253
    00254     bool rtl = _current_text_dir == TD_RTL;
    00255     int image_left  = rtl ? left  + this->count_width  : left  + this->header_width;
    00256     int image_right = rtl ? right - this->header_width : right - this->count_width;
    00257
    00258     switch (v->type) {
    00259       case VEH_TRAIN: {
    00260         const Train *u = Train::From(v);
    00261         free_wagon = u->IsFreeWagon();
    00262
    00263         uint x_space = free_wagon ? TRAININFO_DEFAULT_VEHICLE_WIDTH : 0;
    00264         DrawTrainImage(u, image_left + (rtl ? 0 : x_space), image_right - (rtl ? x_space : 0), sprite_y - 1,
    00265             this->sel, EIT_IN_DEPOT, free_wagon ? 0 : this->hscroll->GetPosition(), this->vehicle_over);
    00266
    00267         /* Length of consist in tiles with 1 fractional digit (rounded up) */
    00268         SetDParam(0, CeilDiv(u->gcache.cached_total_length * 10, TILE_SIZE));
    00269         SetDParam(1, 1);
    00270         DrawString(rtl ? left + WD_FRAMERECT_LEFT : right - this->count_width, rtl ? left + this->count_width : right - WD_FRAMERECT_RIGHT, y + (this->resize.step_height - FONT_HEIGHT_SMALL) / 2, STR_TINY_BLACK_DECIMAL, TC_FROMSTRING, SA_RIGHT); // Draw the counter
    00271         break;
    00272       }
    00273
    00274       case VEH_ROAD:     DrawRoadVehImage( v, image_left, image_right, sprite_y, this->sel, EIT_IN_DEPOT); break;
    00275       case VEH_SHIP:     DrawShipImage(    v, image_left, image_right, sprite_y, this->sel, EIT_IN_DEPOT); break;
    00276       case VEH_AIRCRAFT: {
    00277         const Sprite *spr = GetSprite(v->GetImage(DIR_W, EIT_IN_DEPOT), ST_NORMAL);
    00278         DrawAircraftImage(v, image_left, image_right,
    00279                   y + max(UnScaleByZoom(spr->height, ZOOM_LVL_GUI) + UnScaleByZoom(spr->y_offs, ZOOM_LVL_GUI) - 14, 0), // tall sprites needs an y offset
    00280                   this->sel, EIT_IN_DEPOT);
    00281         break;
    00282       }
    00283       default: NOT_REACHED();
    00284     }
    00285
    00286     uint diff_x, diff_y;
    00287     if (v->IsGroundVehicle()) {
    00288       /* Arrange unitnumber and flag horizontally */
    00289       diff_x = this->flag_width + WD_FRAMERECT_LEFT;
    00290       diff_y = (this->resize.step_height - this->flag_height) / 2 - 2;
    00291     } else {
    00292       /* Arrange unitnumber and flag vertically */
    00293       diff_x = WD_FRAMERECT_LEFT;
    00294       diff_y = FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
    00295     }
    00296     int text_left  = rtl ? right - this->header_width - 1 : left + diff_x;
    00297     int text_right = rtl ? right - diff_x : left + this->header_width - 1;
    00298
    00299     if (free_wagon) {
    00300       DrawString(text_left, text_right, y + 2, STR_DEPOT_NO_ENGINE);
    00301     } else {
    00302       DrawSprite((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, rtl ? right - this->flag_width : left + WD_FRAMERECT_LEFT, y + diff_y);
    00303
    00304       SetDParam(0, v->unitnumber);
    00305       DrawString(text_left, text_right, y + 2, (uint16)(v->max_age - DAYS_IN_LEAP_YEAR) >= v->age ? STR_BLACK_COMMA : STR_RED_COMMA);
    00306     }
    00307   }
    00308
    00309   void DrawWidget(const Rect &r, int widget) const
    00310   {
    00311     if (widget != WID_D_MATRIX) return;
    00312
    00313     bool rtl = _current_text_dir == TD_RTL;
    00314
    00315     /* Set the row and number of boxes in each row based on the number of boxes drawn in the matrix */
    00316     uint16 mat_data = this->GetWidget<NWidgetCore>(WID_D_MATRIX)->widget_data;
    00317     uint16 rows_in_display   = GB(mat_data, MAT_ROW_START, MAT_ROW_BITS);
    00318     uint16 boxes_in_each_row = GB(mat_data, MAT_COL_START, MAT_COL_BITS);
    00319
    00320     uint16 num = this->vscroll->GetPosition() * boxes_in_each_row;
    00321     int maxval = min(this->vehicle_list.Length(), num + (rows_in_display * boxes_in_each_row));
    00322     int y;
    00323     for (y = r.top + 1; num < maxval; y += this->resize.step_height) { // Draw the rows
    00324       for (byte i = 0; i < boxes_in_each_row && num < maxval; i++, num++) {
    00325         /* Draw all vehicles in the current row */
    00326         const Vehicle *v = this->vehicle_list[num];
    00327         if (boxes_in_each_row == 1) {
    00328           this->DrawVehicleInDepot(v, r.left, r.right, y);
    00329         } else {
    00330           int x = r.left + (rtl ? (boxes_in_each_row - i - 1) : i) * this->resize.step_width;
    00331           this->DrawVehicleInDepot(v, x, x + this->resize.step_width - 1, y);
    00332         }
    00333       }
    00334     }
    00335
    00336     maxval = min(this->vehicle_list.Length() + this->wagon_list.Length(), (this->vscroll->GetPosition() * boxes_in_each_row) + (rows_in_display * boxes_in_each_row));
    00337
    00338     /* Draw the train wagons without an engine in front. */
    00339     for (; num < maxval; num++, y += this->resize.step_height) {
    00340       const Vehicle *v = this->wagon_list[num - this->vehicle_list.Length()];
    00341       this->DrawVehicleInDepot(v, r.left, r.right, y);
    00342     }
    00343   }
    00344
    00345   void SetStringParameters(int widget) const
    00346   {
    00347     if (widget != WID_D_CAPTION) return;
    00348
    00349     /* locate the depot struct */
    00350     TileIndex tile = this->window_number;
    00351     SetDParam(0, this->type);
    00352     SetDParam(1, (this->type == VEH_AIRCRAFT) ? GetStationIndex(tile) : GetDepotIndex(tile));
    00353   }
    00354
    00355   struct GetDepotVehiclePtData {
    00356     const Vehicle *head;
    00357     const Vehicle *wagon;
    00358   };
    00359
    00360   enum DepotGUIAction {
    00361     MODE_ERROR,
    00362     MODE_DRAG_VEHICLE,
    00363     MODE_SHOW_VEHICLE,
    00364     MODE_START_STOP,
    00365   };
    00366
    00367   DepotGUIAction GetVehicleFromDepotWndPt(int x, int y, const Vehicle **veh, GetDepotVehiclePtData *d) const
    00368   {
    00369     const NWidgetCore *matrix_widget = this->GetWidget<NWidgetCore>(WID_D_MATRIX);
    00370     /* In case of RTL the widgets are swapped as a whole */
    00371     if (_current_text_dir == TD_RTL) x = matrix_widget->current_x - x;
    00372
    00373     uint xt = 0, xm = 0, ym = 0;
    00374     if (this->type == VEH_TRAIN) {
    00375       xm = x;
    00376     } else {
    00377       xt = x / this->resize.step_width;
    00378       xm = x % this->resize.step_width;
    00379       if (xt >= this->num_columns) return MODE_ERROR;
    00380     }
    00381     ym = y % this->resize.step_height;
    00382
    00383     uint row = y / this->resize.step_height;
    00384     if (row >= this->vscroll->GetCapacity()) return MODE_ERROR;
    00385
    00386     uint boxes_in_each_row = GB(matrix_widget->widget_data, MAT_COL_START, MAT_COL_BITS);
    00387     uint pos = ((row + this->vscroll->GetPosition()) * boxes_in_each_row) + xt;
    00388
    00389     if (this->vehicle_list.Length() + this->wagon_list.Length() <= pos) {
    00390       /* Clicking on 'line' / 'block' without a vehicle */
    00391       if (this->type == VEH_TRAIN) {
    00392         /* End the dragging */
    00393         d->head  = NULL;
    00394         d->wagon = NULL;
    00395         return MODE_DRAG_VEHICLE;
    00396       } else {
    00397         return MODE_ERROR; // empty block, so no vehicle is selected
    00398       }
    00399     }
    00400
    00401     bool wagon = false;
    00402     if (this->vehicle_list.Length() > pos) {
    00403       *veh = this->vehicle_list[pos];
    00404       /* Skip vehicles that are scrolled off the list */
    00405       if (this->type == VEH_TRAIN) x += this->hscroll->GetPosition();
    00406     } else {
    00407       pos -= this->vehicle_list.Length();
    00408       *veh = this->wagon_list[pos];
    00409       /* free wagons don't have an initial loco. */
    00410       x -= VEHICLEINFO_FULL_VEHICLE_WIDTH;
    00411       wagon = true;
    00412     }
    00413
    00414     const Train *v = NULL;
    00415     if (this->type == VEH_TRAIN) {
    00416       v = Train::From(*veh);
    00417       d->head = d->wagon = v;
    00418     }
    00419
    00420     if (xm <= this->header_width) {
    00421       switch (this->type) {
    00422         case VEH_TRAIN:
    00423           if (wagon) return MODE_ERROR;
    00424         case VEH_ROAD:
    00425           if (xm <= this->flag_width) return MODE_START_STOP;
    00426           break;
    00427
    00428         case VEH_SHIP:
    00429         case VEH_AIRCRAFT:
    00430           if (xm <= this->flag_width && ym >= (uint)(FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL)) return MODE_START_STOP;
    00431           break;
    00432
    00433         default: NOT_REACHED();
    00434       }
    00435       return MODE_SHOW_VEHICLE;
    00436     }
    00437
    00438     if (this->type != VEH_TRAIN) return MODE_DRAG_VEHICLE;
    00439
    00440     /* Clicking on the counter */
    00441     if (xm >= matrix_widget->current_x - this->count_width) return wagon ? MODE_ERROR : MODE_SHOW_VEHICLE;
    00442
    00443     /* Account for the header */
    00444     x -= this->header_width;
    00445
    00446     /* find the vehicle in this row that was clicked */
    00447     for (; v != NULL; v = v->Next()) {
    00448       x -= v->GetDisplayImageWidth();
    00449       if (x < 0) break;
    00450     }
    00451
    00452     d->wagon = (v != NULL ? v->GetFirstEnginePart() : NULL);
    00453
    00454     return MODE_DRAG_VEHICLE;
    00455   }
    00456
    00462   void DepotClick(int x, int y)
    00463   {
    00464     GetDepotVehiclePtData gdvp = { NULL, NULL };
    00465     const Vehicle *v = NULL;
    00466     DepotGUIAction mode = this->GetVehicleFromDepotWndPt(x, y, &v, &gdvp);
    00467
    00468     if (this->type == VEH_TRAIN) v = gdvp.wagon;
    00469
    00470     switch (mode) {
    00471       case MODE_ERROR: // invalid
    00472         return;
    00473
    00474       case MODE_DRAG_VEHICLE: { // start dragging of vehicle
    00475         if (v != NULL && VehicleClicked(v)) return;
    00476
    00477         VehicleID sel = this->sel;
    00478
    00479         if (this->type == VEH_TRAIN && sel != INVALID_VEHICLE) {
    00480           this->sel = INVALID_VEHICLE;
    00481           TrainDepotMoveVehicle(v, sel, gdvp.head);
    00482         } else if (v != NULL) {
    00483           bool rtl = _current_text_dir == TD_RTL;
    00484           int image = v->GetImage(rtl ? DIR_E : DIR_W, EIT_IN_DEPOT);
    00485           SetObjectToPlaceWnd(image, GetVehiclePalette(v), HT_DRAG, this);
    00486
    00487           this->sel = v->index;
    00488           this->SetDirty();
    00489
    00490           _cursor.short_vehicle_offset = v->IsGroundVehicle() ? (16 - v->GetGroundVehicleCache()->cached_veh_length * 2) * (rtl ? -1 : 1) : 0;
    00491           _cursor.vehchain = _ctrl_pressed;
    00492         }
    00493         break;
    00494       }
    00495
    00496       case MODE_SHOW_VEHICLE: // show info window
    00497         ShowVehicleViewWindow(v);
    00498         break;
    00499
    00500       case MODE_START_STOP: // click start/stop flag
    00501         StartStopVehicle(v, false);
    00502         break;
    00503
    00504       default: NOT_REACHED();
    00505     }
    00506   }
    00507
    00514   void SetupWidgetData(VehicleType type)
    00515   {
    00516     this->GetWidget<NWidgetCore>(WID_D_STOP_ALL)->tool_tip     = STR_DEPOT_MASS_STOP_DEPOT_TRAIN_TOOLTIP + type;
    00517     this->GetWidget<NWidgetCore>(WID_D_START_ALL)->tool_tip    = STR_DEPOT_MASS_START_DEPOT_TRAIN_TOOLTIP + type;
    00518     this->GetWidget<NWidgetCore>(WID_D_SELL)->tool_tip         = STR_DEPOT_TRAIN_SELL_TOOLTIP + type;
    00519     this->GetWidget<NWidgetCore>(WID_D_SELL_ALL)->tool_tip     = STR_DEPOT_SELL_ALL_BUTTON_TRAIN_TOOLTIP + type;
    00520
    00521     this->GetWidget<NWidgetCore>(WID_D_BUILD)->SetDataTip(STR_DEPOT_TRAIN_NEW_VEHICLES_BUTTON + type, STR_DEPOT_TRAIN_NEW_VEHICLES_TOOLTIP + type);
    00522     this->GetWidget<NWidgetCore>(WID_D_CLONE)->SetDataTip(STR_DEPOT_CLONE_TRAIN + type, STR_DEPOT_CLONE_TRAIN_DEPOT_INFO + type);
    00523
    00524     this->GetWidget<NWidgetCore>(WID_D_LOCATION)->tool_tip     = STR_DEPOT_TRAIN_LOCATION_TOOLTIP + type;
    00525     this->GetWidget<NWidgetCore>(WID_D_VEHICLE_LIST)->tool_tip = STR_DEPOT_VEHICLE_ORDER_LIST_TRAIN_TOOLTIP + type;
    00526     this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->tool_tip  = STR_DEPOT_AUTOREPLACE_TRAIN_TOOLTIP + type;
    00527     this->GetWidget<NWidgetCore>(WID_D_MATRIX)->tool_tip       = STR_DEPOT_TRAIN_LIST_TOOLTIP + this->type;
    00528
    00529     switch (type) {
    00530       default: NOT_REACHED();
    00531
    00532       case VEH_TRAIN:
    00533         this->GetWidget<NWidgetCore>(WID_D_VEHICLE_LIST)->widget_data = STR_TRAIN;
    00534
    00535         /* Sprites */
    00536         this->GetWidget<NWidgetCore>(WID_D_SELL)->widget_data        = SPR_SELL_TRAIN;
    00537         this->GetWidget<NWidgetCore>(WID_D_SELL_ALL)->widget_data    = SPR_SELL_ALL_TRAIN;
    00538         this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->widget_data = SPR_REPLACE_TRAIN;
    00539         break;
    00540
    00541       case VEH_ROAD:
    00542         this->GetWidget<NWidgetCore>(WID_D_VEHICLE_LIST)->widget_data = STR_LORRY;
    00543
    00544         /* Sprites */
    00545         this->GetWidget<NWidgetCore>(WID_D_SELL)->widget_data        = SPR_SELL_ROADVEH;
    00546         this->GetWidget<NWidgetCore>(WID_D_SELL_ALL)->widget_data    = SPR_SELL_ALL_ROADVEH;
    00547         this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->widget_data = SPR_REPLACE_ROADVEH;
    00548         break;
    00549
    00550       case VEH_SHIP:
    00551         this->GetWidget<NWidgetCore>(WID_D_VEHICLE_LIST)->widget_data = STR_SHIP;
    00552
    00553         /* Sprites */
    00554         this->GetWidget<NWidgetCore>(WID_D_SELL)->widget_data        = SPR_SELL_SHIP;
    00555         this->GetWidget<NWidgetCore>(WID_D_SELL_ALL)->widget_data    = SPR_SELL_ALL_SHIP;
    00556         this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->widget_data = SPR_REPLACE_SHIP;
    00557         break;
    00558
    00559       case VEH_AIRCRAFT:
    00560         this->GetWidget<NWidgetCore>(WID_D_VEHICLE_LIST)->widget_data = STR_PLANE;
    00561
    00562         /* Sprites */
    00563         this->GetWidget<NWidgetCore>(WID_D_SELL)->widget_data        = SPR_SELL_AIRCRAFT;
    00564         this->GetWidget<NWidgetCore>(WID_D_SELL_ALL)->widget_data    = SPR_SELL_ALL_AIRCRAFT;
    00565         this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->widget_data = SPR_REPLACE_AIRCRAFT;
    00566         break;
    00567     }
    00568   }
    00569
    00570   uint count_width;
    00571   uint header_width;
    00572   uint flag_width;
    00573   uint flag_height;
    00574
    00575   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
    00576   {
    00577     switch (widget) {
    00578       case WID_D_MATRIX: {
    00579         uint min_height = 0;
    00580
    00581         if (this->type == VEH_TRAIN) {
    00582           SetDParam(0, 1000);
    00583           SetDParam(1, 1);
    00584           this->count_width = GetStringBoundingBox(STR_TINY_BLACK_DECIMAL).width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
    00585         } else {
    00586           this->count_width = 0;
    00587         }
    00588
    00589         Dimension unumber = { GetDigitWidth() * 4, FONT_HEIGHT_NORMAL };
    00590         const Sprite *spr = GetSprite(SPR_FLAG_VEH_STOPPED, ST_NORMAL);
    00591         this->flag_width  = UnScaleByZoom(spr->width, ZOOM_LVL_GUI) + WD_FRAMERECT_RIGHT;
    00592         this->flag_height = UnScaleByZoom(spr->height, ZOOM_LVL_GUI);
    00593
    00594         if (this->type == VEH_TRAIN || this->type == VEH_ROAD) {
    00595           min_height = max<uint>(unumber.height + WD_MATRIX_TOP, UnScaleByZoom(spr->height, ZOOM_LVL_GUI));
    00596           this->header_width = unumber.width + this->flag_width + WD_FRAMERECT_LEFT;
    00597         } else {
    00598           min_height = unumber.height + UnScaleByZoom(spr->height, ZOOM_LVL_GUI) + WD_MATRIX_TOP + WD_PAR_VSEP_NORMAL + WD_MATRIX_BOTTOM;
    00599           this->header_width = max<uint>(unumber.width, this->flag_width) + WD_FRAMERECT_RIGHT;
    00600         }
    00601         int base_width = this->count_width + this->header_width;
    00602
    00603         resize->height = max(_base_block_sizes[this->type].height, min_height);
    00604         if (this->type == VEH_TRAIN) {
    00605           resize->width = 1;
    00606           size->width = base_width + 2 * 29; // about 2 parts
    00607           size->height = resize->height * 6;
    00608         } else {
    00609           resize->width = base_width + _base_block_sizes[this->type].width;
    00610           size->width = resize->width * (this->type == VEH_ROAD ? 5 : 3);
    00611           size->height = resize->height * (this->type == VEH_ROAD ? 5 : 3);
    00612         }
    00613         fill->width = resize->width;
    00614         fill->height = resize->height;
    00615         break;
    00616       }
    00617     }
    00618   }
    00619
    00625   virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
    00626   {
    00627     this->generate_list = true;
    00628   }
    00629
    00630   virtual void OnPaint()
    00631   {
    00632     if (this->generate_list) {
    00633       /* Generate the vehicle list
    00634        * It's ok to use the wagon pointers for non-trains as they will be ignored */
    00635       BuildDepotVehicleList(this->type, this->window_number, &this->vehicle_list, &this->wagon_list);
    00636       this->generate_list = false;
    00637       DepotSortList(&this->vehicle_list);
    00638     }
    00639
    00640     /* determine amount of items for scroller */
    00641     if (this->type == VEH_TRAIN) {
    00642       uint max_width = VEHICLEINFO_FULL_VEHICLE_WIDTH;
    00643       for (uint num = 0; num < this->vehicle_list.Length(); num++) {
    00644         uint width = 0;
    00645         for (const Train *v = Train::From(this->vehicle_list[num]); v != NULL; v = v->Next()) {
    00646           width += v->GetDisplayImageWidth();
    00647         }
    00648         max_width = max(max_width, width);
    00649       }
    00650       /* Always have 1 empty row, so people can change the setting of the train */
    00651       this->vscroll->SetCount(this->vehicle_list.Length() + this->wagon_list.Length() + 1);
    00652       this->hscroll->SetCount(max_width);
    00653     } else {
    00654       this->vscroll->SetCount(CeilDiv(this->vehicle_list.Length(), this->num_columns));
    00655     }
    00656
    00657     /* Setup disabled buttons. */
    00658     TileIndex tile = this->window_number;
    00659     this->SetWidgetsDisabledState(!IsTileOwner(tile, _local_company),
    00660       WID_D_STOP_ALL,
    00661       WID_D_START_ALL,
    00662       WID_D_SELL,
    00663       WID_D_SELL_CHAIN,
    00664       WID_D_SELL_ALL,
    00665       WID_D_BUILD,
    00666       WID_D_CLONE,
    00667       WID_D_RENAME,
    00668       WID_D_AUTOREPLACE,
    00669       WIDGET_LIST_END);
    00670
    00671     this->DrawWidgets();
    00672   }
    00673
    00674   virtual void OnClick(Point pt, int widget, int click_count)
    00675   {
    00676     switch (widget) {
    00677       case WID_D_MATRIX: { // List
    00678         NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_D_MATRIX);
    00679         this->DepotClick(pt.x - nwi->pos_x, pt.y - nwi->pos_y);
    00680         break;
    00681       }
    00682
    00683       case WID_D_BUILD: // Build vehicle
    00684         ResetObjectToPlace();
    00685         ShowBuildVehicleWindow(this->window_number, this->type);
    00686         break;
    00687
    00688       case WID_D_CLONE: // Clone button
    00689         this->SetWidgetDirty(WID_D_CLONE);
    00690         this->ToggleWidgetLoweredState(WID_D_CLONE);
    00691
    00692         if (this->IsWidgetLowered(WID_D_CLONE)) {
    00693           static const CursorID clone_icons[] = {
    00694             SPR_CURSOR_CLONE_TRAIN, SPR_CURSOR_CLONE_ROADVEH,
    00695             SPR_CURSOR_CLONE_SHIP, SPR_CURSOR_CLONE_AIRPLANE
    00696           };
    00697
    00698           SetObjectToPlaceWnd(clone_icons[this->type], PAL_NONE, HT_VEHICLE, this);
    00699         } else {
    00700           ResetObjectToPlace();
    00701         }
    00702         break;
    00703
    00704       case WID_D_LOCATION:
    00705         if (_ctrl_pressed) {
    00706           ShowExtraViewPortWindow(this->window_number);
    00707         } else {
    00708           ScrollMainWindowToTile(this->window_number);
    00709         }
    00710         break;
    00711
    00712       case WID_D_RENAME: // Rename button
    00713         SetDParam(0, this->type);
    00714         SetDParam(1, Depot::GetByTile((TileIndex)this->window_number)->index);
    00715         ShowQueryString(STR_DEPOT_NAME, STR_DEPOT_RENAME_DEPOT_CAPTION, MAX_LENGTH_DEPOT_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS);
    00716         break;
    00717
    00718       case WID_D_STOP_ALL:
    00719       case WID_D_START_ALL: {
    00720         VehicleListIdentifier vli(VL_DEPOT_LIST, this->type, this->owner);
    00721         DoCommandP(this->window_number, (widget == WID_D_START_ALL ? (1 << 0) : 0), vli.Pack(), CMD_MASS_START_STOP);
    00722         break;
    00723       }
    00724
    00725       case WID_D_SELL_ALL:
    00726         /* Only open the confimation window if there are anything to sell */
    00727         if (this->vehicle_list.Length() != 0 || this->wagon_list.Length() != 0) {
    00728           TileIndex tile = this->window_number;
    00729           byte vehtype = this->type;
    00730
    00731           SetDParam(0, vehtype);
    00732           SetDParam(1, (vehtype == VEH_AIRCRAFT) ? GetStationIndex(tile) : GetDepotIndex(tile));
    00733           ShowQuery(
    00734             STR_DEPOT_CAPTION,
    00735             STR_DEPOT_SELL_CONFIRMATION_TEXT,
    00736             this,
    00737             DepotSellAllConfirmationCallback
    00738           );
    00739         }
    00740         break;
    00741
    00742       case WID_D_VEHICLE_LIST:
    00743         ShowVehicleListWindow(GetTileOwner(this->window_number), this->type, (TileIndex)this->window_number);
    00744         break;
    00745
    00746       case WID_D_AUTOREPLACE:
    00747         DoCommandP(this->window_number, this->type, 0, CMD_DEPOT_MASS_AUTOREPLACE);
    00748         break;
    00749
    00750     }
    00751   }
    00752
    00753   virtual void OnQueryTextFinished(char *str)
    00754   {
    00755     if (str == NULL) return;
    00756
    00757     /* Do depot renaming */
    00758     DoCommandP(0, GetDepotIndex(this->window_number), 0, CMD_RENAME_DEPOT | CMD_MSG(STR_ERROR_CAN_T_RENAME_DEPOT), NULL, str);
    00759   }
    00760
    00761   virtual bool OnRightClick(Point pt, int widget)
    00762   {
    00763     if (widget != WID_D_MATRIX) return false;
    00764
    00765     GetDepotVehiclePtData gdvp = { NULL, NULL };
    00766     const Vehicle *v = NULL;
    00767     NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_D_MATRIX);
    00768     DepotGUIAction mode = this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, &gdvp);
    00769
    00770     if (this->type == VEH_TRAIN) v = gdvp.wagon;
    00771
    00772     if (v == NULL || mode != MODE_DRAG_VEHICLE) return false;
    00773
    00774     CargoArray capacity, loaded;
    00775
    00776     /* Display info for single (articulated) vehicle, or for whole chain starting with selected vehicle */
    00777     bool whole_chain = (this->type == VEH_TRAIN && _ctrl_pressed);
    00778
    00779     /* loop through vehicle chain and collect cargoes */
    00780     uint num = 0;
    00781     for (const Vehicle *w = v; w != NULL; w = w->Next()) {
    00782       if (w->cargo_cap > 0 && w->cargo_type < NUM_CARGO) {
    00783         capacity[w->cargo_type] += w->cargo_cap;
    00784         loaded  [w->cargo_type] += w->cargo.Count();
    00785       }
    00786
    00787       if (w->type == VEH_TRAIN && !w->HasArticulatedPart()) {
    00788         num++;
    00789         if (!whole_chain) break;
    00790       }
    00791     }
    00792
    00793     /* Build tooltipstring */
    00794     static char details[1024];
    00795     details[0] = '\0';
    00796     char *pos = details;
    00797
    00798     for (CargoID cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) {
    00799       if (capacity[cargo_type] == 0) continue;
    00800
    00801       SetDParam(0, cargo_type);           // {CARGO} #1
    00802       SetDParam(1, loaded[cargo_type]);   // {CARGO} #2
    00803       SetDParam(2, cargo_type);           // {SHORTCARGO} #1
    00804       SetDParam(3, capacity[cargo_type]); // {SHORTCARGO} #2
    00805       pos = GetString(pos, STR_DEPOT_VEHICLE_TOOLTIP_CARGO, lastof(details));
    00806     }
    00807
    00808     /* Show tooltip window */
    00809     uint64 args[2];
    00810     args[0] = (whole_chain ? num : v->engine_type);
    00811     args[1] = (uint64)(size_t)details;
    00812     GuiShowTooltips(this, whole_chain ? STR_DEPOT_VEHICLE_TOOLTIP_CHAIN : STR_DEPOT_VEHICLE_TOOLTIP, 2, args, TCC_RIGHT_CLICK);
    00813
    00814     return true;
    00815   }
    00816
    00822   virtual bool OnVehicleSelect(const Vehicle *v)
    00823   {
    00824     if (DoCommandP(this->window_number, v->index, _ctrl_pressed ? 1 : 0, CMD_CLONE_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_TRAIN + v->type), CcCloneVehicle)) {
    00825       ResetObjectToPlace();
    00826     }
    00827     return true;
    00828   }
    00829
    00830   virtual void OnPlaceObjectAbort()
    00831   {
    00832     /* abort clone */
    00833     this->RaiseWidget(WID_D_CLONE);
    00834     this->SetWidgetDirty(WID_D_CLONE);
    00835
    00836     /* abort drag & drop */
    00837     this->sel = INVALID_VEHICLE;
    00838     this->vehicle_over = INVALID_VEHICLE;
    00839     this->SetWidgetDirty(WID_D_MATRIX);
    00840   }
    00841
    00842   virtual void OnMouseDrag(Point pt, int widget)
    00843   {
    00844     if (this->type != VEH_TRAIN || this->sel == INVALID_VEHICLE) return;
    00845
    00846     /* A rail vehicle is dragged.. */
    00847     if (widget != WID_D_MATRIX) { // ..outside of the depot matrix.
    00848       if (this->vehicle_over != INVALID_VEHICLE) {
    00849         this->vehicle_over = INVALID_VEHICLE;
    00850         this->SetWidgetDirty(WID_D_MATRIX);
    00851       }
    00852       return;
    00853     }
    00854
    00855     NWidgetBase *matrix = this->GetWidget<NWidgetBase>(widget);
    00856     const Vehicle *v = NULL;
    00857     GetDepotVehiclePtData gdvp = {NULL, NULL};
    00858
    00859     if (this->GetVehicleFromDepotWndPt(pt.x - matrix->pos_x, pt.y - matrix->pos_y, &v, &gdvp) != MODE_DRAG_VEHICLE) return;
    00860
    00861     VehicleID new_vehicle_over = INVALID_VEHICLE;
    00862     if (gdvp.head != NULL) {
    00863       if (gdvp.wagon == NULL && gdvp.head->Last()->index != this->sel) { // ..at the end of the train.
    00864         /* NOTE: As a wagon can't be moved at the begin of a train, head index isn't used to mark a drag-and-drop
    00865          * destination inside a train. This head index is then used to indicate that a wagon is inserted at
    00866          * the end of the train.
    00867          */
    00868         new_vehicle_over = gdvp.head->index;
    00869       } else if (gdvp.wagon != NULL && gdvp.head != gdvp.wagon &&
    00870           gdvp.wagon->index != this->sel &&
    00871           gdvp.wagon->Previous()->index != this->sel) { // ..over an existing wagon.
    00872         new_vehicle_over = gdvp.wagon->index;
    00873       }
    00874     }
    00875
    00876     if (this->vehicle_over == new_vehicle_over) return;
    00877
    00878     this->vehicle_over = new_vehicle_over;
    00879     this->SetWidgetDirty(widget);
    00880   }
    00881
    00882   virtual void OnDragDrop(Point pt, int widget)
    00883   {
    00884     switch (widget) {
    00885       case WID_D_MATRIX: {
    00886         const Vehicle *v = NULL;
    00887         VehicleID sel = this->sel;
    00888
    00889         this->sel = INVALID_VEHICLE;
    00890         this->SetDirty();
    00891
    00892         NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_D_MATRIX);
    00893         if (this->type == VEH_TRAIN) {
    00894           GetDepotVehiclePtData gdvp = { NULL, NULL };
    00895
    00896           if (this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, &gdvp) == MODE_DRAG_VEHICLE && sel != INVALID_VEHICLE) {
    00897             if (gdvp.wagon != NULL && gdvp.wagon->index == sel && _ctrl_pressed) {
    00898               DoCommandP(Vehicle::Get(sel)->tile, Vehicle::Get(sel)->index, true,
    00899                   CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE));
    00900             } else if (gdvp.wagon == NULL || gdvp.wagon->index != sel) {
    00901               this->vehicle_over = INVALID_VEHICLE;
    00902               TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head);
    00903             } else if (gdvp.head != NULL && gdvp.head->IsFrontEngine()) {
    00904               ShowVehicleViewWindow(gdvp.head);
    00905             }
    00906           }
    00907         } else if (this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, NULL) == MODE_DRAG_VEHICLE && v != NULL && sel == v->index) {
    00908           ShowVehicleViewWindow(v);
    00909         }
    00910         break;
    00911       }
    00912
    00913       case WID_D_SELL: case WID_D_SELL_CHAIN: {
    00914         if (this->IsWidgetDisabled(widget)) return;
    00915         if (this->sel == INVALID_VEHICLE) return;
    00916
    00917         this->HandleButtonClick(widget);
    00918
    00919         const Vehicle *v = Vehicle::Get(this->sel);
    00920         this->sel = INVALID_VEHICLE;
    00921         this->SetDirty();
    00922
    00923         int sell_cmd = (v->type == VEH_TRAIN && (widget == WID_D_SELL_CHAIN || _ctrl_pressed)) ? 1 : 0;
    00924         DoCommandP(v->tile, v->index | sell_cmd << 20 | MAKE_ORDER_BACKUP_FLAG, 0, GetCmdSellVeh(v->type));
    00925         break;
    00926       }
    00927
    00928       default:
    00929         this->sel = INVALID_VEHICLE;
    00930         this->SetDirty();
    00931     }
    00932     _cursor.vehchain = false;
    00933   }
    00934
    00935   virtual void OnTimeout()
    00936   {
    00937     if (!this->IsWidgetDisabled(WID_D_SELL)) {
    00938       this->RaiseWidget(WID_D_SELL);
    00939       this->SetWidgetDirty(WID_D_SELL);
    00940     }
    00941     if (this->nested_array[WID_D_SELL] != NULL && !this->IsWidgetDisabled(WID_D_SELL_CHAIN)) {
    00942       this->RaiseWidget(WID_D_SELL_CHAIN);
    00943       this->SetWidgetDirty(WID_D_SELL_CHAIN);
    00944     }
    00945   }
    00946
    00947   virtual void OnResize()
    00948   {
    00949     NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_D_MATRIX);
    00950     this->vscroll->SetCapacityFromWidget(this, WID_D_MATRIX);
    00951     if (this->type == VEH_TRAIN) {
    00952       this->hscroll->SetCapacity(nwi->current_x - this->header_width - this->count_width);
    00953       nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
    00954     } else {
    00955       this->num_columns = nwi->current_x / nwi->resize_x;
    00956       nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (this->num_columns << MAT_COL_START);
    00957     }
    00958   }
    00959
    00960   virtual EventState OnCTRLStateChange()
    00961   {
    00962     if (this->sel != INVALID_VEHICLE) {
    00963       _cursor.vehchain = _ctrl_pressed;
    00964       this->SetWidgetDirty(WID_D_MATRIX);
    00965       return ES_HANDLED;
    00966     }
    00967
    00968     return ES_NOT_HANDLED;
    00969   }
    00970 };
    00971
    00972 static void DepotSellAllConfirmationCallback(Window *win, bool confirmed)
    00973 {
    00974   if (confirmed) {
    00975     DepotWindow *w = (DepotWindow*)win;
    00976     TileIndex tile = w->window_number;
    00977     byte vehtype = w->type;
    00978     DoCommandP(tile, vehtype, 0, CMD_DEPOT_SELL_ALL_VEHICLES);
    00979   }
    00980 }
    00981
    00987 void ShowDepotWindow(TileIndex tile, VehicleType type)
    00988 {
    00989   if (BringWindowToFrontById(WC_VEHICLE_DEPOT, tile) != NULL) return;
    00990
    00991   const WindowDesc *desc;
    00992   switch (type) {
    00993     default: NOT_REACHED();
    00994     case VEH_TRAIN:    desc = &_train_depot_desc;    break;
    00995     case VEH_ROAD:     desc = &_road_depot_desc;     break;
    00996     case VEH_SHIP:     desc = &_ship_depot_desc;     break;
    00997     case VEH_AIRCRAFT: desc = &_aircraft_depot_desc; break;
    00998   }
    00999
    01000   new DepotWindow(desc, tile, type);
    01001 }
    01002
    01007 void DeleteDepotHighlightOfVehicle(const Vehicle *v)
    01008 {
    01009   DepotWindow *w;
    01010
    01011   /* If we haven't got any vehicles on the mouse pointer, we haven't got any highlighted in any depots either
    01012    * If that is the case, we can skip looping though the windows and save time
    01013    */
    01014   if (_special_mouse_mode != WSM_DRAGDROP) return;
    01015
    01016   w = dynamic_cast<DepotWindow*>(FindWindowById(WC_VEHICLE_DEPOT, v->tile));
    01017   if (w != NULL) {
    01018     if (w->sel == v->index) ResetObjectToPlace();
    01019   }
    01020 }