src/depot_gui.cpp
branchNewGRF_ports
changeset 6871 5a9dc001e1ad
parent 6870 ca3fd1fbe311
child 6872 1c4a4a609f85
equal deleted inserted replaced
6870:ca3fd1fbe311 6871:5a9dc001e1ad
   173 		case VEH_TRAIN:
   173 		case VEH_TRAIN:
   174 			DrawTrainImage(v, x + 21, sprite_y, w->hscroll.cap + 4, w->hscroll.pos, WP(w,depot_d).sel);
   174 			DrawTrainImage(v, x + 21, sprite_y, w->hscroll.cap + 4, w->hscroll.pos, WP(w,depot_d).sel);
   175 
   175 
   176 			/* Number of wagons relative to a standard length wagon (rounded up) */
   176 			/* Number of wagons relative to a standard length wagon (rounded up) */
   177 			SetDParam(0, (v->u.rail.cached_total_length + 7) / 8);
   177 			SetDParam(0, (v->u.rail.cached_total_length + 7) / 8);
   178 			DrawStringRightAligned(w->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, 0); // Draw the counter
   178 			DrawStringRightAligned(w->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, TC_FROMSTRING); // Draw the counter
   179 			break;
   179 			break;
   180 
   180 
   181 		case VEH_ROAD:     DrawRoadVehImage( v, x + 24, sprite_y, 1, WP(w, depot_d).sel); break;
   181 		case VEH_ROAD:     DrawRoadVehImage( v, x + 24, sprite_y, 1, WP(w, depot_d).sel); break;
   182 		case VEH_SHIP:     DrawShipImage(    v, x + 19, sprite_y - 1, WP(w, depot_d).sel); break;
   182 		case VEH_SHIP:     DrawShipImage(    v, x + 19, sprite_y - 1, WP(w, depot_d).sel); break;
   183 		case VEH_AIRCRAFT: {
   183 		case VEH_AIRCRAFT: {
   198 	}
   198 	}
   199 
   199 
   200 	DrawSprite((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, x + diff_x, y + diff_y);
   200 	DrawSprite((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, x + diff_x, y + diff_y);
   201 
   201 
   202 	SetDParam(0, v->unitnumber);
   202 	SetDParam(0, v->unitnumber);
   203 	DrawString(x, y + 2, (uint16)(v->max_age-366) >= v->age ? STR_00E2 : STR_00E3, 0);
   203 	DrawString(x, y + 2, (uint16)(v->max_age-366) >= v->age ? STR_00E2 : STR_00E3, TC_FROMSTRING);
   204 }
   204 }
   205 
   205 
   206 static void DrawDepotWindow(Window *w)
   206 static void DrawDepotWindow(Window *w)
   207 {
   207 {
   208 	Vehicle **vl = WP(w, depot_d).vehicle_list;
   208 	Vehicle **vl = WP(w, depot_d).vehicle_list;
   214 	/* Set the row and number of boxes in each row based on the number of boxes drawn in the matrix */
   214 	/* Set the row and number of boxes in each row based on the number of boxes drawn in the matrix */
   215 	uint16 rows_in_display   = w->widget[DEPOT_WIDGET_MATRIX].data >> 8;
   215 	uint16 rows_in_display   = w->widget[DEPOT_WIDGET_MATRIX].data >> 8;
   216 	uint16 boxes_in_each_row = w->widget[DEPOT_WIDGET_MATRIX].data & 0xFF;
   216 	uint16 boxes_in_each_row = w->widget[DEPOT_WIDGET_MATRIX].data & 0xFF;
   217 
   217 
   218 	/* setup disabled buttons */
   218 	/* setup disabled buttons */
   219 	SetWindowWidgetsDisabledState(w, !IsTileOwner(tile, _local_player),
   219 	w->SetWidgetsDisabledState(!IsTileOwner(tile, _local_player),
   220 		DEPOT_WIDGET_STOP_ALL,
   220 		DEPOT_WIDGET_STOP_ALL,
   221 		DEPOT_WIDGET_START_ALL,
   221 		DEPOT_WIDGET_START_ALL,
   222 		DEPOT_WIDGET_SELL,
   222 		DEPOT_WIDGET_SELL,
   223 		DEPOT_WIDGET_SELL_CHAIN,
   223 		DEPOT_WIDGET_SELL_CHAIN,
   224 		DEPOT_WIDGET_SELL_ALL,
   224 		DEPOT_WIDGET_SELL_ALL,
   272 	for (; num < maxval; num++, y += 14) {
   272 	for (; num < maxval; num++, y += 14) {
   273 		const Vehicle *v = WP(w, depot_d).wagon_list[num - WP(w, depot_d).engine_count];
   273 		const Vehicle *v = WP(w, depot_d).wagon_list[num - WP(w, depot_d).engine_count];
   274 		const Vehicle *u;
   274 		const Vehicle *u;
   275 
   275 
   276 		DrawTrainImage(v, x + 50, y, w->hscroll.cap - 29, 0, WP(w,depot_d).sel);
   276 		DrawTrainImage(v, x + 50, y, w->hscroll.cap - 29, 0, WP(w,depot_d).sel);
   277 		DrawString(x, y + 2, STR_8816, 0);
   277 		DrawString(x, y + 2, STR_8816, TC_FROMSTRING);
   278 
   278 
   279 		/*Draw the train counter */
   279 		/*Draw the train counter */
   280 		i = 0;
   280 		i = 0;
   281 		u = v;
   281 		u = v;
   282 		do i++; while ((u = u->Next()) != NULL); // Determine length of train
   282 		do i++; while ((u = u->Next()) != NULL); // Determine length of train
   283 		SetDParam(0, i);                      // Set the counter
   283 		SetDParam(0, i);                      // Set the counter
   284 		DrawStringRightAligned(w->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, 0); // Draw the counter
   284 		DrawStringRightAligned(w->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, TC_FROMSTRING); // Draw the counter
   285 	}
   285 	}
   286 }
   286 }
   287 
   287 
   288 struct GetDepotVehiclePtData {
   288 struct GetDepotVehiclePtData {
   289 	Vehicle *head;
   289 	Vehicle *head;
   290 	Vehicle *wagon;
   290 	Vehicle *wagon;
   291 };
   291 };
   292 
   292 
   293 enum {
   293 enum DepotGUIAction {
   294 	MODE_ERROR        =  1,
   294 	MODE_ERROR,
   295 	MODE_DRAG_VEHICLE =  0,
   295 	MODE_DRAG_VEHICLE,
   296 	MODE_SHOW_VEHICLE = -1,
   296 	MODE_SHOW_VEHICLE,
   297 	MODE_START_STOP   = -2,
   297 	MODE_START_STOP,
   298 };
   298 };
   299 
   299 
   300 static int GetVehicleFromDepotWndPt(const Window *w, int x, int y, Vehicle **veh, GetDepotVehiclePtData *d)
   300 static DepotGUIAction GetVehicleFromDepotWndPt(const Window *w, int x, int y, Vehicle **veh, GetDepotVehiclePtData *d)
   301 {
   301 {
   302 	Vehicle **vl = WP(w, depot_d).vehicle_list;
   302 	Vehicle **vl = WP(w, depot_d).vehicle_list;
   303 	uint xt, row, xm = 0, ym = 0;
   303 	uint xt, row, xm = 0, ym = 0;
   304 	int pos, skip = 0;
   304 	int pos, skip = 0;
   305 	uint16 boxes_in_each_row = w->widget[DEPOT_WIDGET_MATRIX].data & 0xFF;
   305 	uint16 boxes_in_each_row = w->widget[DEPOT_WIDGET_MATRIX].data & 0xFF;
   409 
   409 
   410 static void DepotClick(Window *w, int x, int y)
   410 static void DepotClick(Window *w, int x, int y)
   411 {
   411 {
   412 	GetDepotVehiclePtData gdvp;
   412 	GetDepotVehiclePtData gdvp;
   413 	Vehicle *v = NULL;
   413 	Vehicle *v = NULL;
   414 	int mode = GetVehicleFromDepotWndPt(w, x, y, &v, &gdvp);
   414 	DepotGUIAction mode = GetVehicleFromDepotWndPt(w, x, y, &v, &gdvp);
   415 
   415 
   416 	/* share / copy orders */
   416 	/* share / copy orders */
   417 	if (_thd.place_mode && mode <= 0) {
   417 	if (_thd.place_mode != VHM_NONE && mode != MODE_ERROR) {
   418 		_place_clicked_vehicle = (WP(w, depot_d).type == VEH_TRAIN ? gdvp.head : v);
   418 		_place_clicked_vehicle = (WP(w, depot_d).type == VEH_TRAIN ? gdvp.head : v);
   419 		return;
   419 		return;
   420 	}
   420 	}
   421 
   421 
   422 	if (WP(w, depot_d).type == VEH_TRAIN) v = gdvp.wagon;
   422 	if (WP(w, depot_d).type == VEH_TRAIN) v = gdvp.wagon;
   434 			} else if (v != NULL) {
   434 			} else if (v != NULL) {
   435 				int image = v->GetImage(DIR_W);
   435 				int image = v->GetImage(DIR_W);
   436 
   436 
   437 				WP(w, depot_d).sel = v->index;
   437 				WP(w, depot_d).sel = v->index;
   438 				SetWindowDirty(w);
   438 				SetWindowDirty(w);
   439 				SetObjectToPlaceWnd(image, GetVehiclePalette(v), 4, w);
   439 				SetObjectToPlaceWnd(image, GetVehiclePalette(v), VHM_DRAG, w);
   440 			}
   440 			}
   441 			}
   441 			}
   442 			break;
   442 			break;
   443 
   443 
   444 		case MODE_SHOW_VEHICLE: // show info window
   444 		case MODE_SHOW_VEHICLE: // show info window
   722 	w->widget[DEPOT_WIDGET_MATRIX].data =
   722 	w->widget[DEPOT_WIDGET_MATRIX].data =
   723 		(w->vscroll.cap * 0x100) // number of rows to draw on the background
   723 		(w->vscroll.cap * 0x100) // number of rows to draw on the background
   724 		+ (type == VEH_TRAIN ? 1 : w->hscroll.cap); // number of boxes in each row. Trains always have just one
   724 		+ (type == VEH_TRAIN ? 1 : w->hscroll.cap); // number of boxes in each row. Trains always have just one
   725 
   725 
   726 
   726 
   727 	SetWindowWidgetsHiddenState(w, type != VEH_TRAIN,
   727 	w->SetWidgetsHiddenState(type != VEH_TRAIN,
   728 		DEPOT_WIDGET_H_SCROLL,
   728 		DEPOT_WIDGET_H_SCROLL,
   729 		DEPOT_WIDGET_SELL_CHAIN,
   729 		DEPOT_WIDGET_SELL_CHAIN,
   730 		WIDGET_LIST_END);
   730 		WIDGET_LIST_END);
   731 
   731 
   732 	ResizeDepotButtons(w);
   732 	ResizeDepotButtons(w);
   793 					ShowBuildVehicleWindow(w->window_number, WP(w, depot_d).type);
   793 					ShowBuildVehicleWindow(w->window_number, WP(w, depot_d).type);
   794 					break;
   794 					break;
   795 
   795 
   796 				case DEPOT_WIDGET_CLONE: // Clone button
   796 				case DEPOT_WIDGET_CLONE: // Clone button
   797 					InvalidateWidget(w, DEPOT_WIDGET_CLONE);
   797 					InvalidateWidget(w, DEPOT_WIDGET_CLONE);
   798 					ToggleWidgetLoweredState(w, DEPOT_WIDGET_CLONE);
   798 					w->ToggleWidgetLoweredState(DEPOT_WIDGET_CLONE);
   799 
   799 
   800 					if (IsWindowWidgetLowered(w, DEPOT_WIDGET_CLONE)) {
   800 					if (w->IsWidgetLowered(DEPOT_WIDGET_CLONE)) {
   801 						static const CursorID clone_icons[] = {
   801 						static const CursorID clone_icons[] = {
   802 							SPR_CURSOR_CLONE_TRAIN, SPR_CURSOR_CLONE_ROADVEH,
   802 							SPR_CURSOR_CLONE_TRAIN, SPR_CURSOR_CLONE_ROADVEH,
   803 							SPR_CURSOR_CLONE_SHIP, SPR_CURSOR_CLONE_AIRPLANE
   803 							SPR_CURSOR_CLONE_SHIP, SPR_CURSOR_CLONE_AIRPLANE
   804 						};
   804 						};
   805 
   805 
   853 		case WE_PLACE_OBJ: {
   853 		case WE_PLACE_OBJ: {
   854 			ClonePlaceObj(w);
   854 			ClonePlaceObj(w);
   855 		} break;
   855 		} break;
   856 
   856 
   857 		case WE_ABORT_PLACE_OBJ: {
   857 		case WE_ABORT_PLACE_OBJ: {
   858 			RaiseWindowWidget(w, DEPOT_WIDGET_CLONE);
   858 			w->RaiseWidget(DEPOT_WIDGET_CLONE);
   859 			InvalidateWidget(w, DEPOT_WIDGET_CLONE);
   859 			InvalidateWidget(w, DEPOT_WIDGET_CLONE);
   860 		} break;
   860 		} break;
   861 
   861 
   862 			/* check if a vehicle in a depot was clicked.. */
   862 			/* check if a vehicle in a depot was clicked.. */
   863 		case WE_MOUSELOOP: {
   863 		case WE_MOUSELOOP: {
   864 			const Vehicle *v = _place_clicked_vehicle;
   864 			const Vehicle *v = _place_clicked_vehicle;
   865 
   865 
   866 			/* since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button */
   866 			/* since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button */
   867 			if (v != NULL && IsWindowWidgetLowered(w, DEPOT_WIDGET_CLONE)) {
   867 			if (v != NULL && w->IsWidgetLowered(DEPOT_WIDGET_CLONE)) {
   868 				_place_clicked_vehicle = NULL;
   868 				_place_clicked_vehicle = NULL;
   869 				HandleCloneVehClick(v, w);
   869 				HandleCloneVehClick(v, w);
   870 			}
   870 			}
   871 		} break;
   871 		} break;
   872 
   872 
   904 						ShowVehicleViewWindow(v);
   904 						ShowVehicleViewWindow(v);
   905 					}
   905 					}
   906 				} break;
   906 				} break;
   907 
   907 
   908 				case DEPOT_WIDGET_SELL: case DEPOT_WIDGET_SELL_CHAIN:
   908 				case DEPOT_WIDGET_SELL: case DEPOT_WIDGET_SELL_CHAIN:
   909 					if (!IsWindowWidgetDisabled(w, DEPOT_WIDGET_SELL) &&
   909 					if (!w->IsWidgetDisabled(DEPOT_WIDGET_SELL) &&
   910 						WP(w, depot_d).sel != INVALID_VEHICLE) {
   910 						WP(w, depot_d).sel != INVALID_VEHICLE) {
   911 						Vehicle *v;
   911 						Vehicle *v;
   912 						uint command;
   912 						uint command;
   913 						int sell_cmd;
   913 						int sell_cmd;
   914 						bool is_engine;
   914 						bool is_engine;
   915 
   915 
   916 						if (IsWindowWidgetDisabled(w, e->we.click.widget)) return;
   916 						if (w->IsWidgetDisabled(e->we.click.widget)) return;
   917 						if (WP(w, depot_d).sel == INVALID_VEHICLE) return;
   917 						if (WP(w, depot_d).sel == INVALID_VEHICLE) return;
   918 
   918 
   919 						HandleButtonClick(w, e->we.click.widget);
   919 						HandleButtonClick(w, e->we.click.widget);
   920 
   920 
   921 						v = GetVehicle(WP(w, depot_d).sel);
   921 						v = GetVehicle(WP(w, depot_d).sel);