depot_gui.c
changeset 4754 26ddeca70f94
parent 4745 008f7cbbb5bc
child 4758 090cf0f1b35e
equal deleted inserted replaced
4753:58daf74cb14f 4754:26ddeca70f94
   254 				break;
   254 				break;
   255 		}
   255 		}
   256 	}
   256 	}
   257 }
   257 }
   258 
   258 
       
   259 /** Draw a vehicle in the depot window in the box with the top left corner at x,y
       
   260  * @param *w Window to draw in
       
   261  * @param *v Vehicle to draw
       
   262  * @param x Left side of the box to draw in
       
   263  * @param y Top of the box to draw in
       
   264  */
       
   265 static void DrawVehicleInDepot(Window *w, const Vehicle *v, int x, int y)
       
   266 {
       
   267 	byte diff_x = 0, diff_y = 0;
       
   268 
       
   269 	switch (v->type) {
       
   270 		case VEH_Train:
       
   271 			DrawTrainImage(v, x + 21, y, w->hscroll.cap + 4, w->hscroll.pos, WP(w,depot_d).sel);
       
   272 
       
   273 			/* Number of wagons relative to a standard length wagon (rounded up) */
       
   274 			SetDParam(0, (v->u.rail.cached_total_length + 7) / 8);
       
   275 			DrawStringRightAligned(w->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, 0); // Draw the counter
       
   276 			break;
       
   277 
       
   278 		case VEH_Road:     DrawRoadVehImage( v, x + 24, y, WP(w, depot_d).sel); break;
       
   279 		case VEH_Ship:     DrawShipImage(    v, x + 19, y, WP(w, depot_d).sel); break;
       
   280 		case VEH_Aircraft: DrawAircraftImage(v, x + 12, y, WP(w, depot_d).sel); break;
       
   281 		default: NOT_REACHED();
       
   282 	}
       
   283 
       
   284 	if (w->resize.step_height == 14) {
       
   285 		/* VEH_Train and VEH_Road, which are low */
       
   286 		diff_x = 15;
       
   287 	} else {
       
   288 		/* VEH_Ship and VEH_Aircraft, which are tall */
       
   289 		diff_y = 12;
       
   290 	}
       
   291 
       
   292 	DrawSprite((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, x + diff_x, y + diff_y);
       
   293 
       
   294 	SetDParam(0, v->unitnumber);
       
   295 	DrawString(x, y + 2, (uint16)(v->max_age-366) >= v->age ? STR_00E2 : STR_00E3, 0);
       
   296 }
       
   297 
   259 static void DrawDepotWindow(Window *w)
   298 static void DrawDepotWindow(Window *w)
   260 {
   299 {
   261 	Vehicle **vl = WP(w, depot_d).vehicle_list;
   300 	Vehicle **vl = WP(w, depot_d).vehicle_list;
   262 	TileIndex tile = w->window_number;
   301 	TileIndex tile = w->window_number;
   263 	int x, y, i, hnum, max;
   302 	int x, y, i, hnum, max;
   264 	uint16 num = WP(w, depot_d).engine_count;
   303 	uint16 num = WP(w, depot_d).engine_count;
   265 	bool is_localplayer = IsTileOwner(tile, _local_player);
   304 	bool is_localplayer      = IsTileOwner(tile, _local_player);
       
   305 
       
   306 	/* Set the row and number of boxes in each row based on the number of boxes drawn in the matrix */
       
   307 	uint16 rows_in_display   = w->widget[DEPOT_WIDGET_MATRIX].data >> 8;
       
   308 	uint16 boxes_in_each_row = w->widget[DEPOT_WIDGET_MATRIX].data & 0xFF;
   266 
   309 
   267 	/* setup disabled buttons */
   310 	/* setup disabled buttons */
   268 	SetWindowWidgetDisabledState(w, DEPOT_WIDGET_STOP_ALL,    !is_localplayer);
   311 	SetWindowWidgetDisabledState(w, DEPOT_WIDGET_STOP_ALL,    !is_localplayer);
   269 	SetWindowWidgetDisabledState(w, DEPOT_WIDGET_START_ALL,   !is_localplayer);
   312 	SetWindowWidgetDisabledState(w, DEPOT_WIDGET_START_ALL,   !is_localplayer);
   270 	SetWindowWidgetDisabledState(w, DEPOT_WIDGET_SELL,        !is_localplayer);
   313 	SetWindowWidgetDisabledState(w, DEPOT_WIDGET_SELL,        !is_localplayer);
   298 		SetDParam(0, depot->town_index);
   341 		SetDParam(0, depot->town_index);
   299 	}
   342 	}
   300 
   343 
   301 	DrawWindowWidgets(w);
   344 	DrawWindowWidgets(w);
   302 
   345 
   303 	x = 2;
   346 	num = w->vscroll.pos * boxes_in_each_row;
   304 	y = 15;
   347 	max = min(WP(w, depot_d).engine_count, num + (rows_in_display * boxes_in_each_row));
   305 	num = w->vscroll.pos * w->hscroll.cap;
   348 
   306 	if (WP(w, depot_d).type == VEH_Train) {
   349 	for (x = 2, y = 15; num < max; y += w->resize.step_height, x = 2) { // Draw the rows
   307 		max = min(WP(w, depot_d).engine_count, w->vscroll.pos + w->vscroll.cap);
   350 		byte i;
   308 		num = w->vscroll.pos;
   351 
   309 	} else {
   352 		for (i = 0; i < boxes_in_each_row && num < max; i++, num++, x += w->resize.step_width) {
   310 		max = min(WP(w, depot_d).engine_count, num + (w->vscroll.cap * w->hscroll.cap));
   353 			/* Draw all vehicles in the current row */
   311 		num = w->vscroll.pos * w->hscroll.cap;
   354 			const Vehicle *v = vl[num];
   312 	}
   355 			DrawVehicleInDepot(w, v, x, y);
   313 
       
   314 	for (; num < max; num++) {
       
   315 		const Vehicle *v = vl[num];
       
   316 		byte diff_x = 0, diff_y = 0;
       
   317 
       
   318 		switch (WP(w, depot_d).type) {
       
   319 			case VEH_Train:
       
   320 				DrawTrainImage(v, x + 21, y, w->hscroll.cap + 4, w->hscroll.pos, WP(w,depot_d).sel);
       
   321 
       
   322 				/* Number of wagons relative to a standard length wagon (rounded up) */
       
   323 				SetDParam(0, (v->u.rail.cached_total_length + 7) / 8);
       
   324 				DrawStringRightAligned(w->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, 0); // Draw the counter
       
   325 				break;
       
   326 
       
   327 			case VEH_Road:     DrawRoadVehImage( v, x + 24, y, WP(w, depot_d).sel); break;
       
   328 			case VEH_Ship:     DrawShipImage(    v, x + 19, y, WP(w, depot_d).sel); break;
       
   329 			case VEH_Aircraft: DrawAircraftImage(v, x + 12, y, WP(w, depot_d).sel); break;
       
   330 			default: NOT_REACHED();
       
   331 		}
   356 		}
   332 
   357 	}
   333 		if (w->resize.step_height == 14) {
   358 
   334 			/* VEH_Train and VEH_Road, which are low */
   359 	max = min(WP(w, depot_d).engine_count + WP(w, depot_d).wagon_count, (w->vscroll.pos * boxes_in_each_row) + (rows_in_display * boxes_in_each_row));
   335 			diff_x = 15;
       
   336 		} else {
       
   337 			/* VEH_Ship and VEH_Aircraft, which are tall */
       
   338 			diff_y = 12;
       
   339 		}
       
   340 
       
   341 		DrawSprite((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, x + diff_x, y + diff_y);
       
   342 
       
   343 		SetDParam(0, v->unitnumber);
       
   344 		DrawString(x, y + 2, (uint16)(v->max_age-366) >= v->age ? STR_00E2 : STR_00E3, 0);
       
   345 
       
   346 		if (WP(w, depot_d).type == VEH_Train) {
       
   347 			y += w->resize.step_height;
       
   348 		} else {
       
   349 			if ((x += w->resize.step_width) == 2 + (int)w->resize.step_width * w->hscroll.cap) {
       
   350 				x = 2;
       
   351 				y += w->resize.step_height;
       
   352 			}
       
   353 		}
       
   354 	}
       
   355 
       
   356 	max = min(WP(w, depot_d).engine_count + WP(w, depot_d).wagon_count, w->vscroll.pos + w->vscroll.cap);
       
   357 
   360 
   358 	/* draw the train wagons, that do not have an engine in front */
   361 	/* draw the train wagons, that do not have an engine in front */
   359 	for (; num < max; num++) {
   362 	for (; num < max; num++, y += 14) {
   360 		const Vehicle *v = WP(w, depot_d).wagon_list[num - WP(w, depot_d).engine_count];
   363 		const Vehicle *v = WP(w, depot_d).wagon_list[num - WP(w, depot_d).engine_count];
   361 		const Vehicle *u;
   364 		const Vehicle *u;
   362 
   365 
   363 		DrawTrainImage(v, x + 50, y, w->hscroll.cap - 29, 0, WP(w,depot_d).sel);
   366 		DrawTrainImage(v, x + 50, y, w->hscroll.cap - 29, 0, WP(w,depot_d).sel);
   364 		DrawString(x, y + 2, STR_8816, 0);
   367 		DrawString(x, y + 2, STR_8816, 0);
   367 		i = 0;
   370 		i = 0;
   368 		u = v;
   371 		u = v;
   369 		do i++; while ( (u=u->next) != NULL); // Determine length of train
   372 		do i++; while ( (u=u->next) != NULL); // Determine length of train
   370 		SetDParam(0, i);                      // Set the counter
   373 		SetDParam(0, i);                      // Set the counter
   371 		DrawStringRightAligned(w->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, 0); // Draw the counter
   374 		DrawStringRightAligned(w->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, 0); // Draw the counter
   372 		y += 14;
       
   373 	}
   375 	}
   374 }
   376 }
   375 
   377 
   376 typedef struct GetDepotVehiclePtData {
   378 typedef struct GetDepotVehiclePtData {
   377 	Vehicle *head;
   379 	Vehicle *head;