src/depot_gui.cpp
branchNewGRF_ports
changeset 6872 1c4a4a609f85
parent 6871 5a9dc001e1ad
child 6878 7d1ff2f621c7
equal deleted inserted replaced
6871:5a9dc001e1ad 6872:1c4a4a609f85
     2 
     2 
     3 /** @file depot_gui.cpp */
     3 /** @file depot_gui.cpp */
     4 
     4 
     5 #include "stdafx.h"
     5 #include "stdafx.h"
     6 #include "openttd.h"
     6 #include "openttd.h"
     7 #include "functions.h"
       
     8 #include "train.h"
     7 #include "train.h"
     9 #include "roadveh.h"
     8 #include "roadveh.h"
    10 #include "ship.h"
     9 #include "ship.h"
    11 #include "aircraft.h"
    10 #include "aircraft.h"
    12 #include "table/strings.h"
       
    13 #include "strings.h"
       
    14 #include "table/sprites.h"
       
    15 #include "gui.h"
    11 #include "gui.h"
    16 #include "gfx.h"
    12 #include "textbuf_gui.h"
    17 #include "vehicle.h"
    13 #include "viewport_func.h"
    18 #include "viewport.h"
    14 #include "gfx_func.h"
    19 #include "command.h"
    15 #include "command_func.h"
    20 #include "depot.h"
    16 #include "depot.h"
    21 #include "vehicle_gui.h"
    17 #include "vehicle_gui.h"
    22 #include "station_map.h"
    18 #include "station_map.h"
    23 #include "newgrf_engine.h"
    19 #include "newgrf_engine.h"
    24 #include "spritecache.h"
    20 #include "spritecache.h"
       
    21 #include "strings_func.h"
       
    22 #include "window_func.h"
       
    23 #include "vehicle_func.h"
       
    24 #include "player_func.h"
       
    25 
       
    26 #include "table/strings.h"
       
    27 #include "table/sprites.h"
    25 
    28 
    26 /*
    29 /*
    27  * Since all depot window sizes aren't the same, we need to modify sizes a little.
    30  * Since all depot window sizes aren't the same, we need to modify sizes a little.
    28  * 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.
    31  * 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.
    29  * How long they should be moved and for what window types are controlled in ShowDepotWindow()
    32  * How long they should be moved and for what window types are controlled in ShowDepotWindow()
   169 
   172 
   170 	int sprite_y = y + w->resize.step_height - GetVehicleListHeight(v->type);
   173 	int sprite_y = y + w->resize.step_height - GetVehicleListHeight(v->type);
   171 
   174 
   172 	switch (v->type) {
   175 	switch (v->type) {
   173 		case VEH_TRAIN:
   176 		case VEH_TRAIN:
   174 			DrawTrainImage(v, x + 21, sprite_y, w->hscroll.cap + 4, w->hscroll.pos, WP(w,depot_d).sel);
   177 			DrawTrainImage(v, x + 21, sprite_y, WP(w, depot_d).sel, w->hscroll.cap + 4, w->hscroll.pos);
   175 
   178 
   176 			/* Number of wagons relative to a standard length wagon (rounded up) */
   179 			/* Number of wagons relative to a standard length wagon (rounded up) */
   177 			SetDParam(0, (v->u.rail.cached_total_length + 7) / 8);
   180 			SetDParam(0, (v->u.rail.cached_total_length + 7) / 8);
   178 			DrawStringRightAligned(w->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, TC_FROMSTRING); // Draw the counter
   181 			DrawStringRightAligned(w->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, TC_FROMSTRING); // Draw the counter
   179 			break;
   182 			break;
   180 
   183 
   181 		case VEH_ROAD:     DrawRoadVehImage( v, x + 24, sprite_y, 1, WP(w, depot_d).sel); break;
   184 		case VEH_ROAD:     DrawRoadVehImage( v, x + 24, sprite_y, WP(w, depot_d).sel, 1); break;
   182 		case VEH_SHIP:     DrawShipImage(    v, x + 19, sprite_y - 1, WP(w, depot_d).sel); break;
   185 		case VEH_SHIP:     DrawShipImage(    v, x + 19, sprite_y - 1, WP(w, depot_d).sel); break;
   183 		case VEH_AIRCRAFT: {
   186 		case VEH_AIRCRAFT: {
   184 			const Sprite *spr = GetSprite(v->GetImage(DIR_W));
   187 			const Sprite *spr = GetSprite(v->GetImage(DIR_W));
   185 			DrawAircraftImage(v, x + 12,
   188 			DrawAircraftImage(v, x + 12,
   186 							  y + max(spr->height + spr->y_offs - 14, 0), // tall sprites needs an y offset
   189 							  y + max(spr->height + spr->y_offs - 14, 0), // tall sprites needs an y offset
   271 	/* draw the train wagons, that do not have an engine in front */
   274 	/* draw the train wagons, that do not have an engine in front */
   272 	for (; num < maxval; num++, y += 14) {
   275 	for (; num < maxval; num++, y += 14) {
   273 		const Vehicle *v = WP(w, depot_d).wagon_list[num - WP(w, depot_d).engine_count];
   276 		const Vehicle *v = WP(w, depot_d).wagon_list[num - WP(w, depot_d).engine_count];
   274 		const Vehicle *u;
   277 		const Vehicle *u;
   275 
   278 
   276 		DrawTrainImage(v, x + 50, y, w->hscroll.cap - 29, 0, WP(w,depot_d).sel);
   279 		DrawTrainImage(v, x + 50, y, WP(w, depot_d).sel, w->hscroll.cap - 29, 0);
   277 		DrawString(x, y + 2, STR_8816, TC_FROMSTRING);
   280 		DrawString(x, y + 2, STR_8816, TC_FROMSTRING);
   278 
   281 
   279 		/*Draw the train counter */
   282 		/*Draw the train counter */
   280 		i = 0;
   283 		i = 0;
   281 		u = v;
   284 		u = v;
   427 
   430 
   428 		case MODE_DRAG_VEHICLE: { // start dragging of vehicle
   431 		case MODE_DRAG_VEHICLE: { // start dragging of vehicle
   429 			VehicleID sel = WP(w, depot_d).sel;
   432 			VehicleID sel = WP(w, depot_d).sel;
   430 
   433 
   431 			if (WP(w, depot_d).type == VEH_TRAIN && sel != INVALID_VEHICLE) {
   434 			if (WP(w, depot_d).type == VEH_TRAIN && sel != INVALID_VEHICLE) {
   432 				WP(w,depot_d).sel = INVALID_VEHICLE;
   435 				WP(w, depot_d).sel = INVALID_VEHICLE;
   433 				TrainDepotMoveVehicle(v, sel, gdvp.head);
   436 				TrainDepotMoveVehicle(v, sel, gdvp.head);
   434 			} else if (v != NULL) {
   437 			} else if (v != NULL) {
   435 				int image = v->GetImage(DIR_W);
   438 				int image = v->GetImage(DIR_W);
   436 
   439 
   437 				WP(w, depot_d).sel = v->index;
   440 				WP(w, depot_d).sel = v->index;
   792 					ResetObjectToPlace();
   795 					ResetObjectToPlace();
   793 					ShowBuildVehicleWindow(w->window_number, WP(w, depot_d).type);
   796 					ShowBuildVehicleWindow(w->window_number, WP(w, depot_d).type);
   794 					break;
   797 					break;
   795 
   798 
   796 				case DEPOT_WIDGET_CLONE: // Clone button
   799 				case DEPOT_WIDGET_CLONE: // Clone button
   797 					InvalidateWidget(w, DEPOT_WIDGET_CLONE);
   800 					w->InvalidateWidget(DEPOT_WIDGET_CLONE);
   798 					w->ToggleWidgetLoweredState(DEPOT_WIDGET_CLONE);
   801 					w->ToggleWidgetLoweredState(DEPOT_WIDGET_CLONE);
   799 
   802 
   800 					if (w->IsWidgetLowered(DEPOT_WIDGET_CLONE)) {
   803 					if (w->IsWidgetLowered(DEPOT_WIDGET_CLONE)) {
   801 						static const CursorID clone_icons[] = {
   804 						static const CursorID clone_icons[] = {
   802 							SPR_CURSOR_CLONE_TRAIN, SPR_CURSOR_CLONE_ROADVEH,
   805 							SPR_CURSOR_CLONE_TRAIN, SPR_CURSOR_CLONE_ROADVEH,
   854 			ClonePlaceObj(w);
   857 			ClonePlaceObj(w);
   855 		} break;
   858 		} break;
   856 
   859 
   857 		case WE_ABORT_PLACE_OBJ: {
   860 		case WE_ABORT_PLACE_OBJ: {
   858 			w->RaiseWidget(DEPOT_WIDGET_CLONE);
   861 			w->RaiseWidget(DEPOT_WIDGET_CLONE);
   859 			InvalidateWidget(w, DEPOT_WIDGET_CLONE);
   862 			w->InvalidateWidget(DEPOT_WIDGET_CLONE);
   860 		} break;
   863 		} break;
   861 
   864 
   862 			/* check if a vehicle in a depot was clicked.. */
   865 			/* check if a vehicle in a depot was clicked.. */
   863 		case WE_MOUSELOOP: {
   866 		case WE_MOUSELOOP: {
   864 			const Vehicle *v = _place_clicked_vehicle;
   867 			const Vehicle *v = _place_clicked_vehicle;
   914 						bool is_engine;
   917 						bool is_engine;
   915 
   918 
   916 						if (w->IsWidgetDisabled(e->we.click.widget)) return;
   919 						if (w->IsWidgetDisabled(e->we.click.widget)) return;
   917 						if (WP(w, depot_d).sel == INVALID_VEHICLE) return;
   920 						if (WP(w, depot_d).sel == INVALID_VEHICLE) return;
   918 
   921 
   919 						HandleButtonClick(w, e->we.click.widget);
   922 						w->HandleButtonClick(e->we.click.widget);
   920 
   923 
   921 						v = GetVehicle(WP(w, depot_d).sel);
   924 						v = GetVehicle(WP(w, depot_d).sel);
   922 						WP(w, depot_d).sel = INVALID_VEHICLE;
   925 						WP(w, depot_d).sel = INVALID_VEHICLE;
   923 						SetWindowDirty(w);
   926 						SetWindowDirty(w);
   924 
   927