depot_gui.cpp

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