/** * Draw the details capacity tab for the given vehicle at the given position * * @param item Data to draw * @param left The left most coordinate to draw * @param right The right most coordinate to draw * @param y The y coordinate */ static void TrainDetailsCapacityTab(const CargoSummaryItem *item, int left, int right, int y) { SetDParam(0, item->cargo); SetDParam(1, item->capacity); SetDParam(4, item->subtype); SetDParam(5, _settings_game.vehicle.freight_trains); DrawString(left, right, y, FreightWagonMult(item->cargo) > 1 ? STR_VEHICLE_INFO_CAPACITY_MULT : STR_VEHICLE_INFO_CAPACITY); }
/** * Draw the details cargo tab for the given vehicle at the given position * * @param item Data to draw * @param left The left most coordinate to draw * @param right The right most coordinate to draw * @param y The y coordinate */ static void TrainDetailsCargoTab(const CargoSummaryItem *item, int left, int right, int y) { StringID str = STR_VEHICLE_DETAILS_CARGO_EMPTY; if (item->amount > 0) { SetDParam(0, item->cargo); SetDParam(1, item->amount); SetDParam(2, item->source); SetDParam(3, _settings_game.vehicle.freight_trains); str = FreightWagonMult(item->cargo) > 1 ? STR_VEHICLE_DETAILS_CARGO_FROM_MULT : STR_VEHICLE_DETAILS_CARGO_FROM; } DrawString(left, right, y, str); }
/** * Draw the details capacity tab for the given vehicle at the given position * * @param item Data to draw * @param left The left most coordinate to draw * @param right The right most coordinate to draw * @param y The y coordinate */ static void TrainDetailsCapacityTab(const CargoSummaryItem *item, int left, int right, int y) { StringID str; if (item->cargo != INVALID_CARGO) { SetDParam(0, item->cargo); SetDParam(1, item->capacity); SetDParam(4, item->subtype); SetDParam(5, _settings_game.vehicle.freight_trains); str = FreightWagonMult(item->cargo) > 1 ? STR_VEHICLE_INFO_CAPACITY_MULT : STR_VEHICLE_INFO_CAPACITY; } else { /* Draw subtype only */ SetDParam(0, item->subtype); str = STR_VEHICLE_INFO_NO_CAPACITY; } DrawString(left, right, y, str); }
/** * Draw the details for the given vehicle at the given position * * @param v current vehicle * @param left The left most coordinate to draw * @param right The right most coordinate to draw * @param y The y coordinate * @param vscroll_pos Position of scrollbar * @param vscroll_cap Number of lines currently displayed * @param det_tab Selected details tab */ void DrawTrainDetails(const Train *v, int left, int right, int y, int vscroll_pos, uint16 vscroll_cap, TrainDetailsWindowTabs det_tab) { /* get rid of awkward offset */ y -= WD_MATRIX_TOP; int sprite_height = ScaleGUITrad(GetVehicleHeight(VEH_TRAIN)); int line_height = max(sprite_height, WD_MATRIX_TOP + FONT_HEIGHT_NORMAL + WD_MATRIX_BOTTOM); int sprite_y_offset = line_height / 2; int text_y_offset = (line_height - FONT_HEIGHT_NORMAL) / 2; /* draw the first 3 details tabs */ if (det_tab != TDW_TAB_TOTALS) { bool rtl = _current_text_dir == TD_RTL; Direction dir = rtl ? DIR_E : DIR_W; int x = rtl ? right : left; for (; v != NULL && vscroll_pos > -vscroll_cap; v = v->GetNextVehicle()) { GetCargoSummaryOfArticulatedVehicle(v, &_cargo_summary); /* Draw sprites */ uint dx = 0; int px = x; const Train *u = v; do { Point offset; int width = u->GetDisplayImageWidth(&offset); if (vscroll_pos <= 0 && vscroll_pos > -vscroll_cap) { int pitch = 0; const Engine *e = Engine::Get(v->engine_type); if (e->GetGRF() != NULL) { pitch = ScaleGUITrad(e->GetGRF()->traininfo_vehicle_pitch); } PaletteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); VehicleSpriteSeq seq; u->GetImage(dir, EIT_IN_DETAILS, &seq); seq.Draw(px + (rtl ? -offset.x : offset.x), y - line_height * vscroll_pos + sprite_y_offset + pitch, pal, v->vehstatus & VS_CRASHED); } px += rtl ? -width : width; dx += width; u = u->Next(); } while (u != NULL && u->IsArticulatedPart()); bool separate_sprite_row = (dx > (uint)ScaleGUITrad(TRAIN_DETAILS_MAX_INDENT)); if (separate_sprite_row) { vscroll_pos--; dx = 0; } uint num_lines = max(1u, _cargo_summary.Length()); for (uint i = 0; i < num_lines; i++) { int sprite_width = max<int>(dx, ScaleGUITrad(TRAIN_DETAILS_MIN_INDENT)) + 3; int data_left = left + (rtl ? 0 : sprite_width); int data_right = right - (rtl ? sprite_width : 0); if (vscroll_pos <= 0 && vscroll_pos > -vscroll_cap) { int py = y - line_height * vscroll_pos + text_y_offset; if (i > 0 || separate_sprite_row) { if (vscroll_pos != 0) GfxFillRect(left, py - WD_MATRIX_TOP - 1, right, py - WD_MATRIX_TOP, _colour_gradient[COLOUR_GREY][5]); } switch (det_tab) { case TDW_TAB_CARGO: if (i < _cargo_summary.Length()) { TrainDetailsCargoTab(&_cargo_summary[i], data_left, data_right, py); } else { DrawString(data_left, data_right, py, STR_QUANTITY_N_A, TC_LIGHT_BLUE); } break; case TDW_TAB_INFO: if (i == 0) TrainDetailsInfoTab(v, data_left, data_right, py); break; case TDW_TAB_CAPACITY: if (i < _cargo_summary.Length()) { TrainDetailsCapacityTab(&_cargo_summary[i], data_left, data_right, py); } else { SetDParam(0, STR_EMPTY); DrawString(data_left, data_right, py, STR_VEHICLE_INFO_NO_CAPACITY); } break; default: NOT_REACHED(); } } vscroll_pos--; } } } else { CargoArray act_cargo; CargoArray max_cargo; Money feeder_share = 0; for (const Vehicle *u = v; u != NULL; u = u->Next()) { act_cargo[u->cargo_type] += u->cargo.StoredCount(); max_cargo[u->cargo_type] += u->cargo_cap; feeder_share += u->cargo.FeederShare(); } /* draw total cargo tab */ DrawString(left, right, y + text_y_offset, STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_TEXT); y += line_height; for (CargoID i = 0; i < NUM_CARGO; i++) { if (max_cargo[i] > 0 && --vscroll_pos < 0 && vscroll_pos > -vscroll_cap) { SetDParam(0, i); // {CARGO} #1 SetDParam(1, act_cargo[i]); // {CARGO} #2 SetDParam(2, i); // {SHORTCARGO} #1 SetDParam(3, max_cargo[i]); // {SHORTCARGO} #2 SetDParam(4, _settings_game.vehicle.freight_trains); DrawString(left, right, y + text_y_offset, FreightWagonMult(i) > 1 ? STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_MULT : STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY); y += line_height; } } SetDParam(0, feeder_share); DrawString(left, right, y + text_y_offset, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE); } }