src/depot_gui.cpp
branchNewGRF_ports
changeset 10731 67db0d431d5e
parent 10724 68a692eacf22
child 10991 d8811e327d12
equal deleted inserted replaced
10724:68a692eacf22 10731:67db0d431d5e
   105 static const WindowDesc _train_depot_desc = {
   105 static const WindowDesc _train_depot_desc = {
   106 	WDP_AUTO, WDP_AUTO, 36, 27, 36, 27,
   106 	WDP_AUTO, WDP_AUTO, 36, 27, 36, 27,
   107 	WC_VEHICLE_DEPOT, WC_NONE,
   107 	WC_VEHICLE_DEPOT, WC_NONE,
   108 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
   108 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
   109 	_depot_widgets,
   109 	_depot_widgets,
   110 	NULL
       
   111 };
   110 };
   112 
   111 
   113 static const WindowDesc _road_depot_desc = {
   112 static const WindowDesc _road_depot_desc = {
   114 	WDP_AUTO, WDP_AUTO, 36, 27, 36, 27,
   113 	WDP_AUTO, WDP_AUTO, 36, 27, 36, 27,
   115 	WC_VEHICLE_DEPOT, WC_NONE,
   114 	WC_VEHICLE_DEPOT, WC_NONE,
   116 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
   115 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
   117 	_depot_widgets,
   116 	_depot_widgets,
   118 	NULL
       
   119 };
   117 };
   120 
   118 
   121 static const WindowDesc _ship_depot_desc = {
   119 static const WindowDesc _ship_depot_desc = {
   122 	WDP_AUTO, WDP_AUTO, 36, 27, 36, 27,
   120 	WDP_AUTO, WDP_AUTO, 36, 27, 36, 27,
   123 	WC_VEHICLE_DEPOT, WC_NONE,
   121 	WC_VEHICLE_DEPOT, WC_NONE,
   124 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
   122 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
   125 	_depot_widgets,
   123 	_depot_widgets,
   126 	NULL
       
   127 };
   124 };
   128 
   125 
   129 static const WindowDesc _aircraft_depot_desc = {
   126 static const WindowDesc _aircraft_depot_desc = {
   130 	WDP_AUTO, WDP_AUTO, 36, 27, 36, 27,
   127 	WDP_AUTO, WDP_AUTO, 36, 27, 36, 27,
   131 	WC_VEHICLE_DEPOT, WC_NONE,
   128 	WC_VEHICLE_DEPOT, WC_NONE,
   132 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
   129 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
   133 	_depot_widgets,
   130 	_depot_widgets,
   134 	NULL
       
   135 };
   131 };
   136 
   132 
   137 extern int WagonLengthToPixels(int len);
   133 extern int WagonLengthToPixels(int len);
   138 extern void DepotSortList(Vehicle **v, uint16 length);
   134 extern void DepotSortList(VehicleList *list);
   139 
   135 
   140 /**
   136 /**
   141  * This is the Callback method after the cloning attempt of a vehicle
   137  * This is the Callback method after the cloning attempt of a vehicle
   142  * @param success indicates completion (or not) of the operation
   138  * @param success indicates completion (or not) of the operation
   143  * @param tile unused
   139  * @param tile unused
   146  */
   142  */
   147 void CcCloneVehicle(bool success, TileIndex tile, uint32 p1, uint32 p2)
   143 void CcCloneVehicle(bool success, TileIndex tile, uint32 p1, uint32 p2)
   148 {
   144 {
   149 	if (!success) return;
   145 	if (!success) return;
   150 
   146 
   151 	Vehicle *v = GetVehicle(_new_vehicle_id);
   147 	const Vehicle *v = GetVehicle(_new_vehicle_id);
   152 
   148 
   153 	ShowVehicleViewWindow(v);
   149 	ShowVehicleViewWindow(v);
   154 }
   150 }
   155 
   151 
   156 static void TrainDepotMoveVehicle(Vehicle *wagon, VehicleID sel, Vehicle *head)
   152 static void TrainDepotMoveVehicle(const Vehicle *wagon, VehicleID sel, const Vehicle *head)
   157 {
   153 {
   158 	Vehicle *v;
   154 	const Vehicle *v = GetVehicle(sel);
   159 
       
   160 	v = GetVehicle(sel);
       
   161 
   155 
   162 	if (v == wagon) return;
   156 	if (v == wagon) return;
   163 
   157 
   164 	if (wagon == NULL) {
   158 	if (wagon == NULL) {
   165 		if (head != NULL) wagon = GetLastVehicleInChain(head);
   159 		if (head != NULL) wagon = GetLastVehicleInChain(head);
   244 
   238 
   245 struct DepotWindow : Window {
   239 struct DepotWindow : Window {
   246 	VehicleID sel;
   240 	VehicleID sel;
   247 	VehicleType type;
   241 	VehicleType type;
   248 	bool generate_list;
   242 	bool generate_list;
   249 	uint16 engine_list_length;
   243 	VehicleList vehicle_list;
   250 	uint16 wagon_list_length;
   244 	VehicleList wagon_list;
   251 	uint16 engine_count;
       
   252 	uint16 wagon_count;
       
   253 	Vehicle **vehicle_list;
       
   254 	Vehicle **wagon_list;
       
   255 
   245 
   256 	DepotWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
   246 	DepotWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
   257 	{
   247 	{
   258 		this->sel = INVALID_VEHICLE;
   248 		this->sel = INVALID_VEHICLE;
   259 		this->vehicle_list  = NULL;
       
   260 		this->wagon_list    = NULL;
       
   261 		this->engine_count  = 0;
       
   262 		this->wagon_count   = 0;
       
   263 		this->generate_list = true;
   249 		this->generate_list = true;
   264 
   250 
   265 		this->FindWindowPlacementAndResize(desc);
   251 		this->FindWindowPlacementAndResize(desc);
   266 	}
   252 	}
   267 
   253 
   268 	~DepotWindow()
   254 	~DepotWindow()
   269 	{
   255 	{
   270 		DeleteWindowById(WC_BUILD_VEHICLE, this->window_number);
   256 		DeleteWindowById(WC_BUILD_VEHICLE, this->window_number);
   271 		free((void*)this->vehicle_list);
       
   272 		free((void*)this->wagon_list);
       
   273 	}
   257 	}
   274 
   258 
   275 	/** Draw a vehicle in the depot window in the box with the top left corner at x,y
   259 	/** Draw a vehicle in the depot window in the box with the top left corner at x,y
   276 	* @param *w Window to draw in
   260 	* @param *w Window to draw in
   277 	* @param *v Vehicle to draw
   261 	* @param *v Vehicle to draw
   318 		DrawString(x, y + 2, (uint16)(v->max_age - 366) >= v->age ? STR_00E2 : STR_00E3, TC_FROMSTRING);
   302 		DrawString(x, y + 2, (uint16)(v->max_age - 366) >= v->age ? STR_00E2 : STR_00E3, TC_FROMSTRING);
   319 	}
   303 	}
   320 
   304 
   321 	void DrawDepotWindow(Window *w)
   305 	void DrawDepotWindow(Window *w)
   322 	{
   306 	{
   323 		Vehicle **vl = this->vehicle_list;
       
   324 		TileIndex tile = this->window_number;
   307 		TileIndex tile = this->window_number;
   325 		int x, y, i, maxval;
   308 		int x, y, i, maxval;
   326 		uint16 hnum;
   309 		uint16 hnum;
   327 		uint16 num = this->engine_count;
       
   328 
   310 
   329 		/* Set the row and number of boxes in each row based on the number of boxes drawn in the matrix */
   311 		/* Set the row and number of boxes in each row based on the number of boxes drawn in the matrix */
   330 		uint16 rows_in_display   = this->widget[DEPOT_WIDGET_MATRIX].data >> 8;
   312 		uint16 rows_in_display   = this->widget[DEPOT_WIDGET_MATRIX].data >> 8;
   331 		uint16 boxes_in_each_row = this->widget[DEPOT_WIDGET_MATRIX].data & 0xFF;
   313 		uint16 boxes_in_each_row = this->widget[DEPOT_WIDGET_MATRIX].data & 0xFF;
   332 
   314 
   343 			WIDGET_LIST_END);
   325 			WIDGET_LIST_END);
   344 
   326 
   345 		/* determine amount of items for scroller */
   327 		/* determine amount of items for scroller */
   346 		if (this->type == VEH_TRAIN) {
   328 		if (this->type == VEH_TRAIN) {
   347 			hnum = 8;
   329 			hnum = 8;
   348 			for (num = 0; num < this->engine_count; num++) {
   330 			for (uint num = 0; num < this->vehicle_list.Length(); num++) {
   349 				const Vehicle *v = vl[num];
   331 				const Vehicle *v = this->vehicle_list[num];
   350 				hnum = max(hnum, v->u.rail.cached_total_length);
   332 				hnum = max(hnum, v->u.rail.cached_total_length);
   351 			}
   333 			}
   352 			/* Always have 1 empty row, so people can change the setting of the train */
   334 			/* Always have 1 empty row, so people can change the setting of the train */
   353 			SetVScrollCount(w, this->engine_count + this->wagon_count + 1);
   335 			SetVScrollCount(w, this->vehicle_list.Length() + this->wagon_list.Length() + 1);
   354 			SetHScrollCount(w, WagonLengthToPixels(hnum));
   336 			SetHScrollCount(w, WagonLengthToPixels(hnum));
   355 		} else {
   337 		} else {
   356 			SetVScrollCount(w, (num + this->hscroll.cap - 1) / this->hscroll.cap);
   338 			SetVScrollCount(w, (this->vehicle_list.Length() + this->hscroll.cap - 1) / this->hscroll.cap);
   357 		}
   339 		}
   358 
   340 
   359 		/* locate the depot struct */
   341 		/* locate the depot struct */
   360 		if (this->type == VEH_AIRCRAFT) {
   342 		if (this->type == VEH_AIRCRAFT) {
   361 			SetDParam(0, GetStationIndex(tile)); // Airport name
   343 			SetDParam(0, GetStationIndex(tile)); // Airport name
   366 			SetDParam(0, depot->town_index);
   348 			SetDParam(0, depot->town_index);
   367 		}
   349 		}
   368 
   350 
   369 		w->DrawWidgets();
   351 		w->DrawWidgets();
   370 
   352 
   371 		num = this->vscroll.pos * boxes_in_each_row;
   353 		uint16 num = this->vscroll.pos * boxes_in_each_row;
   372 		maxval = min(this->engine_count, num + (rows_in_display * boxes_in_each_row));
   354 		maxval = min(this->vehicle_list.Length(), num + (rows_in_display * boxes_in_each_row));
   373 
   355 
   374 		for (x = 2, y = 15; num < maxval; y += this->resize.step_height, x = 2) { // Draw the rows
   356 		for (x = 2, y = 15; num < maxval; y += this->resize.step_height, x = 2) { // Draw the rows
   375 			byte i;
   357 			byte i;
   376 
   358 
   377 			for (i = 0; i < boxes_in_each_row && num < maxval; i++, num++, x += this->resize.step_width) {
   359 			for (i = 0; i < boxes_in_each_row && num < maxval; i++, num++, x += this->resize.step_width) {
   378 				/* Draw all vehicles in the current row */
   360 				/* Draw all vehicles in the current row */
   379 				const Vehicle *v = vl[num];
   361 				const Vehicle *v = this->vehicle_list[num];
   380 				DrawVehicleInDepot(w, v, x, y);
   362 				DrawVehicleInDepot(w, v, x, y);
   381 			}
   363 			}
   382 		}
   364 		}
   383 
   365 
   384 		maxval = min(this->engine_count + this->wagon_count, (this->vscroll.pos * boxes_in_each_row) + (rows_in_display * boxes_in_each_row));
   366 		maxval = min(this->vehicle_list.Length() + this->wagon_list.Length(), (this->vscroll.pos * boxes_in_each_row) + (rows_in_display * boxes_in_each_row));
   385 
   367 
   386 		/* draw the train wagons, that do not have an engine in front */
   368 		/* draw the train wagons, that do not have an engine in front */
   387 		for (; num < maxval; num++, y += 14) {
   369 		for (; num < maxval; num++, y += 14) {
   388 			const Vehicle *v = this->wagon_list[num - this->engine_count];
   370 			const Vehicle *v = this->wagon_list[num - this->vehicle_list.Length()];
   389 			const Vehicle *u;
   371 			const Vehicle *u;
   390 
   372 
   391 			DrawTrainImage(v, x + 50, y, this->sel, this->hscroll.cap - 29, 0);
   373 			DrawTrainImage(v, x + 50, y, this->sel, this->hscroll.cap - 29, 0);
   392 			DrawString(x, y + 2, STR_8816, TC_FROMSTRING);
   374 			DrawString(x, y + 2, STR_8816, TC_FROMSTRING);
   393 
   375 
   399 			DrawStringRightAligned(this->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, TC_FROMSTRING); // Draw the counter
   381 			DrawStringRightAligned(this->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, TC_FROMSTRING); // Draw the counter
   400 		}
   382 		}
   401 	}
   383 	}
   402 
   384 
   403 	struct GetDepotVehiclePtData {
   385 	struct GetDepotVehiclePtData {
   404 		Vehicle *head;
   386 		const Vehicle *head;
   405 		Vehicle *wagon;
   387 		const Vehicle *wagon;
   406 	};
   388 	};
   407 
   389 
   408 	enum DepotGUIAction {
   390 	enum DepotGUIAction {
   409 		MODE_ERROR,
   391 		MODE_ERROR,
   410 		MODE_DRAG_VEHICLE,
   392 		MODE_DRAG_VEHICLE,
   411 		MODE_SHOW_VEHICLE,
   393 		MODE_SHOW_VEHICLE,
   412 		MODE_START_STOP,
   394 		MODE_START_STOP,
   413 	};
   395 	};
   414 
   396 
   415 	DepotGUIAction GetVehicleFromDepotWndPt(int x, int y, Vehicle **veh, GetDepotVehiclePtData *d) const
   397 	DepotGUIAction GetVehicleFromDepotWndPt(int x, int y, const Vehicle **veh, GetDepotVehiclePtData *d) const
   416 	{
   398 	{
   417 		Vehicle **vl = this->vehicle_list;
       
   418 		uint xt, row, xm = 0, ym = 0;
   399 		uint xt, row, xm = 0, ym = 0;
   419 		int pos, skip = 0;
   400 		int pos, skip = 0;
   420 		uint16 boxes_in_each_row = this->widget[DEPOT_WIDGET_MATRIX].data & 0xFF;
   401 		uint16 boxes_in_each_row = this->widget[DEPOT_WIDGET_MATRIX].data & 0xFF;
   421 
   402 
   422 		if (this->type == VEH_TRAIN) {
   403 		if (this->type == VEH_TRAIN) {
   433 		row = (y - 14) / this->resize.step_height;
   414 		row = (y - 14) / this->resize.step_height;
   434 		if (row >= this->vscroll.cap) return MODE_ERROR;
   415 		if (row >= this->vscroll.cap) return MODE_ERROR;
   435 
   416 
   436 		pos = ((row + this->vscroll.pos) * boxes_in_each_row) + xt;
   417 		pos = ((row + this->vscroll.pos) * boxes_in_each_row) + xt;
   437 
   418 
   438 		if (this->engine_count + this->wagon_count <= pos) {
   419 		if ((int)(this->vehicle_list.Length() + this->wagon_list.Length()) <= pos) {
   439 			if (this->type == VEH_TRAIN) {
   420 			if (this->type == VEH_TRAIN) {
   440 				d->head  = NULL;
   421 				d->head  = NULL;
   441 				d->wagon = NULL;
   422 				d->wagon = NULL;
   442 				return MODE_DRAG_VEHICLE;
   423 				return MODE_DRAG_VEHICLE;
   443 			} else {
   424 			} else {
   444 				return MODE_ERROR; // empty block, so no vehicle is selected
   425 				return MODE_ERROR; // empty block, so no vehicle is selected
   445 			}
   426 			}
   446 		}
   427 		}
   447 
   428 
   448 		if (this->engine_count > pos) {
   429 		if ((int)this->vehicle_list.Length() > pos) {
   449 			*veh = vl[pos];
   430 			*veh = this->vehicle_list[pos];
   450 			skip = this->hscroll.pos;
   431 			skip = this->hscroll.pos;
   451 		} else {
   432 		} else {
   452 			vl = this->wagon_list;
   433 			pos -= this->vehicle_list.Length();
   453 			pos -= this->engine_count;
   434 			*veh = this->wagon_list[pos];
   454 			*veh = vl[pos];
       
   455 			/* free wagons don't have an initial loco. */
   435 			/* free wagons don't have an initial loco. */
   456 			x -= _traininfo_vehicle_width;
   436 			x -= _traininfo_vehicle_width;
   457 		}
   437 		}
   458 
   438 
   459 		switch (this->type) {
   439 		switch (this->type) {
   460 			case VEH_TRAIN: {
   440 			case VEH_TRAIN: {
   461 				Vehicle *v = *veh;
   441 				const Vehicle *v = *veh;
   462 				d->head = d->wagon = v;
   442 				d->head = d->wagon = v;
   463 
   443 
   464 				/* either pressed the flag or the number, but only when it's a loco */
   444 				/* either pressed the flag or the number, but only when it's a loco */
   465 				if (x < 0 && IsFrontEngine(v)) return (x >= -10) ? MODE_START_STOP : MODE_SHOW_VEHICLE;
   445 				if (x < 0 && IsFrontEngine(v)) return (x >= -10) ? MODE_START_STOP : MODE_SHOW_VEHICLE;
   466 
   446 
   503 	}
   483 	}
   504 
   484 
   505 	void DepotClick(int x, int y)
   485 	void DepotClick(int x, int y)
   506 	{
   486 	{
   507 		GetDepotVehiclePtData gdvp = { NULL, NULL };
   487 		GetDepotVehiclePtData gdvp = { NULL, NULL };
   508 		Vehicle *v = NULL;
   488 		const Vehicle *v = NULL;
   509 		DepotGUIAction mode = this->GetVehicleFromDepotWndPt(x, y, &v, &gdvp);
   489 		DepotGUIAction mode = this->GetVehicleFromDepotWndPt(x, y, &v, &gdvp);
   510 
   490 
   511 		/* share / copy orders */
   491 		/* share / copy orders */
   512 		if (_thd.place_mode != VHM_NONE && mode != MODE_ERROR) {
   492 		if (_thd.place_mode != VHM_NONE && mode != MODE_ERROR) {
   513 			_place_clicked_vehicle = (this->type == VEH_TRAIN ? gdvp.head : v);
   493 			_place_clicked_vehicle = (this->type == VEH_TRAIN ? gdvp.head : v);
   763 	virtual void OnPaint()
   743 	virtual void OnPaint()
   764 	{
   744 	{
   765 		if (this->generate_list) {
   745 		if (this->generate_list) {
   766 			/* Generate the vehicle list
   746 			/* Generate the vehicle list
   767 			 * It's ok to use the wagon pointers for non-trains as they will be ignored */
   747 			 * It's ok to use the wagon pointers for non-trains as they will be ignored */
   768 			BuildDepotVehicleList(this->type, this->window_number,
   748 			BuildDepotVehicleList(this->type, this->window_number, &this->vehicle_list, &this->wagon_list);
   769 				&this->vehicle_list, &this->engine_list_length, &this->engine_count,
       
   770 				&this->wagon_list,   &this->wagon_list_length,  &this->wagon_count);
       
   771 			this->generate_list = false;
   749 			this->generate_list = false;
   772 			DepotSortList(this->vehicle_list, this->engine_count);
   750 			DepotSortList(&this->vehicle_list);
   773 		}
   751 		}
   774 		DrawDepotWindow(this);
   752 		DrawDepotWindow(this);
   775 	}
   753 	}
   776 
   754 
   777 	virtual void OnClick(Point pt, int widget)
   755 	virtual void OnClick(Point pt, int widget)
   816 				DoCommandP(this->window_number, 0, this->type | (widget == DEPOT_WIDGET_START_ALL ? (1 << 5) : 0), NULL, CMD_MASS_START_STOP);
   794 				DoCommandP(this->window_number, 0, this->type | (widget == DEPOT_WIDGET_START_ALL ? (1 << 5) : 0), NULL, CMD_MASS_START_STOP);
   817 				break;
   795 				break;
   818 
   796 
   819 			case DEPOT_WIDGET_SELL_ALL:
   797 			case DEPOT_WIDGET_SELL_ALL:
   820 				/* Only open the confimation window if there are anything to sell */
   798 				/* Only open the confimation window if there are anything to sell */
   821 				if (this->engine_count != 0 || this->wagon_count != 0) {
   799 				if (this->vehicle_list.Length() != 0 || this->wagon_list.Length() != 0) {
   822 					static const StringID confirm_captions[] = {
   800 					static const StringID confirm_captions[] = {
   823 						STR_8800_TRAIN_DEPOT,
   801 						STR_8800_TRAIN_DEPOT,
   824 						STR_9003_ROAD_VEHICLE_DEPOT,
   802 						STR_9003_ROAD_VEHICLE_DEPOT,
   825 						STR_9803_SHIP_DEPOT,
   803 						STR_9803_SHIP_DEPOT,
   826 						STR_A002_AIRCRAFT_HANGAR
   804 						STR_A002_AIRCRAFT_HANGAR
   881 
   859 
   882 	virtual void OnDragDrop(Point pt, int widget)
   860 	virtual void OnDragDrop(Point pt, int widget)
   883 	{
   861 	{
   884 		switch (widget) {
   862 		switch (widget) {
   885 			case DEPOT_WIDGET_MATRIX: {
   863 			case DEPOT_WIDGET_MATRIX: {
   886 				Vehicle *v;
   864 				const Vehicle *v = NULL;
   887 				VehicleID sel = this->sel;
   865 				VehicleID sel = this->sel;
   888 
   866 
   889 				this->sel = INVALID_VEHICLE;
   867 				this->sel = INVALID_VEHICLE;
   890 				this->SetDirty();
   868 				this->SetDirty();
   891 
   869 
   910 			} break;
   888 			} break;
   911 
   889 
   912 			case DEPOT_WIDGET_SELL: case DEPOT_WIDGET_SELL_CHAIN:
   890 			case DEPOT_WIDGET_SELL: case DEPOT_WIDGET_SELL_CHAIN:
   913 				if (!this->IsWidgetDisabled(DEPOT_WIDGET_SELL) &&
   891 				if (!this->IsWidgetDisabled(DEPOT_WIDGET_SELL) &&
   914 					this->sel != INVALID_VEHICLE) {
   892 					this->sel != INVALID_VEHICLE) {
   915 					Vehicle *v;
       
   916 					uint command;
   893 					uint command;
   917 					int sell_cmd;
       
   918 					bool is_engine;
       
   919 
   894 
   920 					if (this->IsWidgetDisabled(widget)) return;
   895 					if (this->IsWidgetDisabled(widget)) return;
   921 					if (this->sel == INVALID_VEHICLE) return;
   896 					if (this->sel == INVALID_VEHICLE) return;
   922 
   897 
   923 					this->HandleButtonClick(widget);
   898 					this->HandleButtonClick(widget);
   924 
   899 
   925 					v = GetVehicle(this->sel);
   900 					const Vehicle *v = GetVehicle(this->sel);
   926 					this->sel = INVALID_VEHICLE;
   901 					this->sel = INVALID_VEHICLE;
   927 					this->SetDirty();
   902 					this->SetDirty();
   928 
   903 
   929 					sell_cmd = (v->type == VEH_TRAIN && (widget == DEPOT_WIDGET_SELL_CHAIN || _ctrl_pressed)) ? 1 : 0;
   904 					int sell_cmd = (v->type == VEH_TRAIN && (widget == DEPOT_WIDGET_SELL_CHAIN || _ctrl_pressed)) ? 1 : 0;
   930 
   905 
   931 					is_engine = (!(v->type == VEH_TRAIN && !IsFrontEngine(v)));
   906 					bool is_engine = (!(v->type == VEH_TRAIN && !IsFrontEngine(v)));
   932 
   907 
   933 					if (is_engine) {
   908 					if (is_engine) {
   934 						_backup_orders_tile = v->tile;
   909 						_backup_orders_tile = v->tile;
   935 						BackupVehicleOrders(v);
   910 						BackupVehicleOrders(v);
   936 					}
   911 					}
   959 		this->hscroll.cap += delta.x / (int)this->resize.step_width;
   934 		this->hscroll.cap += delta.x / (int)this->resize.step_width;
   960 		this->widget[DEPOT_WIDGET_MATRIX].data = (this->vscroll.cap << 8) + (this->type == VEH_TRAIN ? 1 : this->hscroll.cap);
   935 		this->widget[DEPOT_WIDGET_MATRIX].data = (this->vscroll.cap << 8) + (this->type == VEH_TRAIN ? 1 : this->hscroll.cap);
   961 		ResizeDepotButtons(this);
   936 		ResizeDepotButtons(this);
   962 	}
   937 	}
   963 
   938 
   964 	virtual bool OnCTRLStateChange()
   939 	virtual EventState OnCTRLStateChange()
   965 	{
   940 	{
   966 		if (this->sel != INVALID_VEHICLE) {
   941 		if (this->sel != INVALID_VEHICLE) {
   967 			_cursor.vehchain = _ctrl_pressed;
   942 			_cursor.vehchain = _ctrl_pressed;
   968 			this->InvalidateWidget(DEPOT_WIDGET_MATRIX);
   943 			this->InvalidateWidget(DEPOT_WIDGET_MATRIX);
   969 		}
   944 		}
   970 
   945 
   971 		return true;
   946 		return ES_HANDLED;
   972 	}
   947 	}
   973 };
   948 };
   974 
   949 
   975 static void DepotSellAllConfirmationCallback(Window *win, bool confirmed)
   950 static void DepotSellAllConfirmationCallback(Window *win, bool confirmed)
   976 {
   951 {