00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "stdafx.h"
00013 #include "roadveh.h"
00014 #include "window_gui.h"
00015 #include "gfx_func.h"
00016 #include "vehicle_gui.h"
00017 #include "strings_func.h"
00018 #include "vehicle_func.h"
00019 #include "string_func.h"
00020
00021 #include "table/sprites.h"
00022 #include "table/strings.h"
00023
00032 void DrawRoadVehDetails(const Vehicle *v, int left, int right, int y)
00033 {
00034 const RoadVehicle *rv = RoadVehicle::From(v);
00035
00036 uint y_offset = rv->HasArticulatedPart() ? 15 : 0;
00037 StringID str;
00038 Money feeder_share = 0;
00039
00040 SetDParam(0, v->engine_type);
00041 SetDParam(1, v->build_year);
00042 SetDParam(2, v->value);
00043 DrawString(left, right, y + y_offset, STR_VEHICLE_INFO_BUILT_VALUE, TC_FROMSTRING, SA_LEFT | SA_STRIP);
00044
00045 if (rv->HasArticulatedPart()) {
00046 CargoArray max_cargo;
00047 StringID subtype_text[NUM_CARGO];
00048 char capacity[512];
00049
00050 memset(subtype_text, 0, sizeof(subtype_text));
00051
00052 for (const Vehicle *u = v; u != NULL; u = u->Next()) {
00053 max_cargo[u->cargo_type] += u->cargo_cap;
00054 if (u->cargo_cap > 0) {
00055 StringID text = GetCargoSubtypeText(u);
00056 if (text != STR_EMPTY) subtype_text[u->cargo_type] = text;
00057 }
00058 }
00059
00060 GetString(capacity, STR_VEHICLE_DETAILS_TRAIN_ARTICULATED_RV_CAPACITY, lastof(capacity));
00061
00062 bool first = true;
00063 for (CargoID i = 0; i < NUM_CARGO; i++) {
00064 if (max_cargo[i] > 0) {
00065 char buffer[128];
00066
00067 SetDParam(0, i);
00068 SetDParam(1, max_cargo[i]);
00069 GetString(buffer, STR_JUST_CARGO, lastof(buffer));
00070
00071 if (!first) strecat(capacity, ", ", lastof(capacity));
00072 strecat(capacity, buffer, lastof(capacity));
00073
00074 if (subtype_text[i] != 0) {
00075 GetString(buffer, subtype_text[i], lastof(buffer));
00076 strecat(capacity, buffer, lastof(capacity));
00077 }
00078
00079 first = false;
00080 }
00081 }
00082
00083 DrawString(left, right, y + FONT_HEIGHT_NORMAL + y_offset, capacity, TC_BLUE);
00084
00085 for (const Vehicle *u = v; u != NULL; u = u->Next()) {
00086 if (u->cargo_cap == 0) continue;
00087
00088 str = STR_VEHICLE_DETAILS_CARGO_EMPTY;
00089 if (!u->cargo.Empty()) {
00090 SetDParam(0, u->cargo_type);
00091 SetDParam(1, u->cargo.Count());
00092 SetDParam(2, u->cargo.Source());
00093 str = STR_VEHICLE_DETAILS_CARGO_FROM;
00094 feeder_share += u->cargo.FeederShare();
00095 }
00096 DrawString(left, right, y + 2 * FONT_HEIGHT_NORMAL + 1 + y_offset, str);
00097
00098 y_offset += FONT_HEIGHT_NORMAL + 1;
00099 }
00100
00101 y_offset -= FONT_HEIGHT_NORMAL + 1;
00102 } else {
00103 SetDParam(0, v->cargo_type);
00104 SetDParam(1, v->cargo_cap);
00105 SetDParam(4, GetCargoSubtypeText(v));
00106 DrawString(left, right, y + FONT_HEIGHT_NORMAL + y_offset, STR_VEHICLE_INFO_CAPACITY);
00107
00108 str = STR_VEHICLE_DETAILS_CARGO_EMPTY;
00109 if (!v->cargo.Empty()) {
00110 SetDParam(0, v->cargo_type);
00111 SetDParam(1, v->cargo.Count());
00112 SetDParam(2, v->cargo.Source());
00113 str = STR_VEHICLE_DETAILS_CARGO_FROM;
00114 feeder_share += v->cargo.FeederShare();
00115 }
00116 DrawString(left, right, y + 2 * FONT_HEIGHT_NORMAL + 1 + y_offset, str);
00117 }
00118
00119
00120 SetDParam(0, feeder_share);
00121 DrawString(left, right, y + 3 * FONT_HEIGHT_NORMAL + 3 + y_offset, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);
00122 }
00123
00133 void DrawRoadVehImage(const Vehicle *v, int left, int right, int y, VehicleID selection, int skip)
00134 {
00135 bool rtl = _current_text_dir == TD_RTL;
00136 Direction dir = rtl ? DIR_E : DIR_W;
00137 const RoadVehicle *u = RoadVehicle::From(v);
00138
00139 DrawPixelInfo tmp_dpi, *old_dpi;
00140 int max_width = right - left + 1;
00141
00142 if (!FillDrawPixelInfo(&tmp_dpi, left, y, max_width, 14)) return;
00143
00144 old_dpi = _cur_dpi;
00145 _cur_dpi = &tmp_dpi;
00146
00147 int px = rtl ? max_width + skip : -skip;
00148 for (; u != NULL && (rtl ? px > 0 : px < max_width); u = u->Next()) {
00149 Point offset;
00150 int width = u->GetDisplayImageWidth(&offset);
00151
00152 if (rtl ? px + width > 0 : px - width < max_width) {
00153 PaletteID pal = (u->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(u);
00154 DrawSprite(u->GetImage(dir), pal, px + (rtl ? -offset.x : offset.x), 6 + offset.y);
00155 }
00156
00157 px += rtl ? -width : width;
00158 }
00159
00160 if (v->index == selection) {
00161 DrawFrameRect((rtl ? px : left) - 1, y - 1, (rtl ? px : right) - 1, y + 12, COLOUR_WHITE, FR_BORDERONLY);
00162 }
00163
00164 _cur_dpi = old_dpi;
00165 }