train_gui.c
changeset 3919 b64f70fcca85
parent 3887 ece644bbf459
child 3948 a09379beffd5
equal deleted inserted replaced
3918:2432e667e8a7 3919:b64f70fcca85
   360 	return (len * _traininfo_vehicle_width) / 8;
   360 	return (len * _traininfo_vehicle_width) / 8;
   361 }
   361 }
   362 
   362 
   363 static void DrawTrainImage(const Vehicle *v, int x, int y, int count, int skip, VehicleID selection)
   363 static void DrawTrainImage(const Vehicle *v, int x, int y, int count, int skip, VehicleID selection)
   364 {
   364 {
   365 	int dx = 0;
   365 	DrawPixelInfo tmp_dpi, *old_dpi;
   366 	count *= 29;
   366 	int dx = -(skip * 8) / _traininfo_vehicle_width;
       
   367 
       
   368 	if (!FillDrawPixelInfo(&tmp_dpi, NULL, x - 1, y - 1, count, 14)) return;
       
   369 
       
   370 	count = (count * 8) / _traininfo_vehicle_width;
       
   371 
       
   372 	old_dpi = _cur_dpi;
       
   373 	_cur_dpi = &tmp_dpi;
   367 
   374 
   368 	do {
   375 	do {
   369 		if (--skip < 0) {
   376 		int width = v->u.rail.cached_veh_length;
   370 			int width = v->u.rail.cached_veh_length;
   377 
   371 
   378 		if (dx + width > 0) {
   372 			if (WagonLengthToPixels(dx + width) <= count) {
   379 			if (dx <= count) {
   373 				PalSpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
   380 				PalSpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
   374 				DrawSprite(GetTrainImage(v, DIR_W) | pal, x + 14 + WagonLengthToPixels(dx), y + 6 + (is_custom_sprite(RailVehInfo(v->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0));
   381 				DrawSprite(GetTrainImage(v, DIR_W) | pal, 15 + WagonLengthToPixels(dx), 7 + (is_custom_sprite(RailVehInfo(v->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0));
   375 				if (v->index == selection)
   382 				if (v->index == selection)
   376 					DrawFrameRect(x - 1 + WagonLengthToPixels(dx), y - 1, x + WagonLengthToPixels(dx + width) - 1, y + 12, 15, FR_BORDERONLY);
   383 					DrawFrameRect(WagonLengthToPixels(dx), 0, WagonLengthToPixels(dx + width), 13, 15, FR_BORDERONLY);
   377 			}
   384 			}
   378 			dx += width;
   385 		}
   379 		}
   386 		dx += width;
   380 
   387 
   381 		v = v->next;
   388 		v = v->next;
   382 	} while (WagonLengthToPixels(dx) < count && v != NULL);
   389 	} while (dx < count && v != NULL);
       
   390 
       
   391 	_cur_dpi = old_dpi;
   383 }
   392 }
   384 
   393 
   385 static void DrawTrainDepotWindow(Window *w)
   394 static void DrawTrainDepotWindow(Window *w)
   386 {
   395 {
   387 	TileIndex tile;
   396 	TileIndex tile;
   413 
   422 
   414 	/* Always have 1 empty row, so people can change the setting of the train */
   423 	/* Always have 1 empty row, so people can change the setting of the train */
   415 	num++;
   424 	num++;
   416 
   425 
   417 	SetVScrollCount(w, num);
   426 	SetVScrollCount(w, num);
   418 	SetHScrollCount(w, (hnum + 7) / 8);
   427 	SetHScrollCount(w, WagonLengthToPixels(hnum));
   419 
   428 
   420 	/* locate the depot struct */
   429 	/* locate the depot struct */
   421 	depot = GetDepotByTile(tile);
   430 	depot = GetDepotByTile(tile);
   422 	assert(depot != NULL);
   431 	assert(depot != NULL);
   423 
   432 
   431 	// draw all trains
   440 	// draw all trains
   432 	FOR_ALL_VEHICLES(v) {
   441 	FOR_ALL_VEHICLES(v) {
   433 		if (v->type == VEH_Train && IsFrontEngine(v) &&
   442 		if (v->type == VEH_Train && IsFrontEngine(v) &&
   434 				v->tile == tile && v->u.rail.track == 0x80 &&
   443 				v->tile == tile && v->u.rail.track == 0x80 &&
   435 				--num < 0 && num >= -w->vscroll.cap) {
   444 				--num < 0 && num >= -w->vscroll.cap) {
   436 			DrawTrainImage(v, x+21, y, w->hscroll.cap, w->hscroll.pos, WP(w,traindepot_d).sel);
   445 			DrawTrainImage(v, x+21, y, w->hscroll.cap + 4, w->hscroll.pos, WP(w,traindepot_d).sel);
   437 			/* Draw the train number */
   446 			/* Draw the train number */
   438 			SetDParam(0, v->unitnumber);
   447 			SetDParam(0, v->unitnumber);
   439 			DrawString(x, y, (v->max_age - 366 < v->age) ? STR_00E3 : STR_00E2, 0);
   448 			DrawString(x, y, (v->max_age - 366 < v->age) ? STR_00E3 : STR_00E2, 0);
   440 
   449 
   441 			// Number of wagons relative to a standard length wagon (rounded up)
   450 			// Number of wagons relative to a standard length wagon (rounded up)
   452 	// draw all remaining vehicles
   461 	// draw all remaining vehicles
   453 	FOR_ALL_VEHICLES(v) {
   462 	FOR_ALL_VEHICLES(v) {
   454 		if (v->type == VEH_Train && IsFreeWagon(v) &&
   463 		if (v->type == VEH_Train && IsFreeWagon(v) &&
   455 				v->tile == tile && v->u.rail.track == 0x80 &&
   464 				v->tile == tile && v->u.rail.track == 0x80 &&
   456 				--num < 0 && num >= -w->vscroll.cap) {
   465 				--num < 0 && num >= -w->vscroll.cap) {
   457 			DrawTrainImage(v, x+50, y, w->hscroll.cap - 1, 0, WP(w,traindepot_d).sel);
   466 			DrawTrainImage(v, x+50, y, w->hscroll.cap - 29, 0, WP(w,traindepot_d).sel);
   458 			DrawString(x, y+2, STR_8816, 0);
   467 			DrawString(x, y+2, STR_8816, 0);
   459 
   468 
   460 			/*Draw the train counter */
   469 			/*Draw the train counter */
   461 			i = 0;
   470 			i = 0;
   462 			u = v;
   471 			u = v;
   521 	d->head = d->wagon = v;
   530 	d->head = d->wagon = v;
   522 
   531 
   523 	/* either pressed the flag or the number, but only when it's a loco */
   532 	/* either pressed the flag or the number, but only when it's a loco */
   524 	if (x < 0 && IsFrontEngine(v)) return (x >= -10) ? -2 : -1;
   533 	if (x < 0 && IsFrontEngine(v)) return (x >= -10) ? -2 : -1;
   525 
   534 
   526 	// skip vehicles that are scrolled off the left side
   535 	skip = (skip * 8) / _traininfo_vehicle_width;
   527 	while (v != NULL && skip--) v = v->next;
   536 	x = (x * 8) / _traininfo_vehicle_width;
       
   537 
       
   538 	/* Skip vehicles that are scrolled off the list */
       
   539 	x += skip;
   528 
   540 
   529 	/* find the vehicle in this row that was clicked */
   541 	/* find the vehicle in this row that was clicked */
   530 	while (v != NULL && (x -= WagonLengthToPixels(v->u.rail.cached_veh_length)) >= 0) v = v->next;
   542 	while (v != NULL && (x -= v->u.rail.cached_veh_length) >= 0) v = v->next;
   531 
   543 
   532 	// if an articulated part was selected, find its parent
   544 	// if an articulated part was selected, find its parent
   533 	while (v != NULL && IsArticulatedPart(v)) v = GetPrevVehicleInChain(v);
   545 	while (v != NULL && IsArticulatedPart(v)) v = GetPrevVehicleInChain(v);
   534 
   546 
   535 	d->wagon = v;
   547 	d->wagon = v;
   747 		}
   759 		}
   748 		} break;
   760 		} break;
   749 	case WE_RESIZE: {
   761 	case WE_RESIZE: {
   750 		/* Update the scroll + matrix */
   762 		/* Update the scroll + matrix */
   751 		w->vscroll.cap += e->sizing.diff.y / 14;
   763 		w->vscroll.cap += e->sizing.diff.y / 14;
   752 		w->hscroll.cap += e->sizing.diff.x / 29;
   764 		w->hscroll.cap += e->sizing.diff.x;
   753 		w->widget[6].unkA = (w->vscroll.cap << 8) + 1;
   765 		w->widget[6].unkA = (w->vscroll.cap << 8) + 1;
   754 	} break;
   766 	} break;
   755 	}
   767 	}
   756 }
   768 }
   757 
   769 
   793 
   805 
   794 	w = AllocateWindowDescFront(&_train_depot_desc, tile);
   806 	w = AllocateWindowDescFront(&_train_depot_desc, tile);
   795 	if (w) {
   807 	if (w) {
   796 		w->caption_color = GetTileOwner(w->window_number);
   808 		w->caption_color = GetTileOwner(w->window_number);
   797 		w->vscroll.cap = 6;
   809 		w->vscroll.cap = 6;
   798 		w->hscroll.cap = 10;
   810 		w->hscroll.cap = 10 * 29;
   799 		w->resize.step_width = 29;
   811 		w->resize.step_width = 1;
   800 		w->resize.step_height = 14;
   812 		w->resize.step_height = 14;
   801 		WP(w,traindepot_d).sel = INVALID_VEHICLE;
   813 		WP(w,traindepot_d).sel = INVALID_VEHICLE;
   802 		_backup_orders_tile = 0;
   814 		_backup_orders_tile = 0;
   803 	}
   815 	}
   804 }
   816 }
  1545 		}
  1557 		}
  1546 		break;
  1558 		break;
  1547 
  1559 
  1548 	case WE_RESIZE:
  1560 	case WE_RESIZE:
  1549 		/* Update the scroll + matrix */
  1561 		/* Update the scroll + matrix */
  1550 		w->hscroll.cap += e->sizing.diff.x / 29;
  1562 		w->hscroll.cap += e->sizing.diff.x;
  1551 		w->vscroll.cap += e->sizing.diff.y / PLY_WND_PRC__SIZE_OF_ROW_SMALL;
  1563 		w->vscroll.cap += e->sizing.diff.y / PLY_WND_PRC__SIZE_OF_ROW_SMALL;
  1552 		w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
  1564 		w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
  1553 		break;
  1565 		break;
  1554 	}
  1566 	}
  1555 }
  1567 }
  1579 	} else {
  1591 	} else {
  1580 		w = AllocateWindowDescFront(&_other_player_trains_desc, (station << 16) | player);
  1592 		w = AllocateWindowDescFront(&_other_player_trains_desc, (station << 16) | player);
  1581 	}
  1593 	}
  1582 	if (w) {
  1594 	if (w) {
  1583 		w->caption_color = player;
  1595 		w->caption_color = player;
  1584 		w->hscroll.cap = 10;
  1596 		w->hscroll.cap = 10 * 29;
  1585 		w->vscroll.cap = 7; // maximum number of vehicles shown
  1597 		w->vscroll.cap = 7; // maximum number of vehicles shown
  1586 		w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
  1598 		w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
  1587 		w->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_SMALL;
  1599 		w->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_SMALL;
  1588 		w->resize.step_width = 29;
  1600 		w->resize.step_width = 1;
  1589 		w->resize.height = 220 - (PLY_WND_PRC__SIZE_OF_ROW_SMALL * 3); /* Minimum of 4 vehicles */
  1601 		w->resize.height = 220 - (PLY_WND_PRC__SIZE_OF_ROW_SMALL * 3); /* Minimum of 4 vehicles */
  1590 	}
  1602 	}
  1591 }
  1603 }