# roadveh_gui.cpp

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    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   uint y_offset = v->HasArticulatedPart() ? 15 : 0; // Draw the first line below the sprite of an articulated RV instead of after it.
    00035   StringID str;
    00036   Money feeder_share = 0;
    00037
    00038   SetDParam(0, v->engine_type);
    00039   SetDParam(1, v->build_year);
    00040   SetDParam(2, v->value);
    00041   DrawString(left, right, y + y_offset, STR_VEHICLE_INFO_BUILT_VALUE, TC_FROMSTRING, SA_LEFT | SA_STRIP);
    00042
    00043   if (v->HasArticulatedPart()) {
    00044     CargoArray max_cargo;
    00045     StringID subtype_text[NUM_CARGO];
    00046     char capacity[512];
    00047
    00048     memset(subtype_text, 0, sizeof(subtype_text));
    00049
    00050     for (const Vehicle *u = v; u != NULL; u = u->Next()) {
    00051       max_cargo[u->cargo_type] += u->cargo_cap;
    00052       if (u->cargo_cap > 0) {
    00053         StringID text = GetCargoSubtypeText(u);
    00054         if (text != STR_EMPTY) subtype_text[u->cargo_type] = text;
    00055       }
    00056     }
    00057
    00058     GetString(capacity, STR_VEHICLE_DETAILS_TRAIN_ARTICULATED_RV_CAPACITY, lastof(capacity));
    00059
    00060     bool first = true;
    00061     for (CargoID i = 0; i < NUM_CARGO; i++) {
    00062       if (max_cargo[i] > 0) {
    00063         char buffer[128];
    00064
    00065         SetDParam(0, i);
    00066         SetDParam(1, max_cargo[i]);
    00067         GetString(buffer, STR_JUST_CARGO, lastof(buffer));
    00068
    00069         if (!first) strecat(capacity, ", ", lastof(capacity));
    00070         strecat(capacity, buffer, lastof(capacity));
    00071
    00072         if (subtype_text[i] != 0) {
    00073           GetString(buffer, subtype_text[i], lastof(buffer));
    00074           strecat(capacity, buffer, lastof(capacity));
    00075         }
    00076
    00077         first = false;
    00078       }
    00079     }
    00080
    00081     DrawString(left, right, y + FONT_HEIGHT_NORMAL + y_offset, capacity, TC_BLUE);
    00082
    00083     for (const Vehicle *u = v; u != NULL; u = u->Next()) {
    00084       if (u->cargo_cap == 0) continue;
    00085
    00086       str = STR_VEHICLE_DETAILS_CARGO_EMPTY;
    00087       if (!u->cargo.Empty()) {
    00088         SetDParam(0, u->cargo_type);
    00089         SetDParam(1, u->cargo.Count());
    00090         SetDParam(2, u->cargo.Source());
    00091         str = STR_VEHICLE_DETAILS_CARGO_FROM;
    00092         feeder_share += u->cargo.FeederShare();
    00093       }
    00094       DrawString(left, right, y + 2 * FONT_HEIGHT_NORMAL + 1 + y_offset, str);
    00095
    00096       y_offset += FONT_HEIGHT_NORMAL + 1;
    00097     }
    00098
    00099     y_offset -= FONT_HEIGHT_NORMAL + 1;
    00100   } else {
    00101     SetDParam(0, v->cargo_type);
    00102     SetDParam(1, v->cargo_cap);
    00103     SetDParam(4, GetCargoSubtypeText(v));
    00104     DrawString(left, right, y + FONT_HEIGHT_NORMAL + y_offset, STR_VEHICLE_INFO_CAPACITY);
    00105
    00106     str = STR_VEHICLE_DETAILS_CARGO_EMPTY;
    00107     if (!v->cargo.Empty()) {
    00108       SetDParam(0, v->cargo_type);
    00109       SetDParam(1, v->cargo.Count());
    00110       SetDParam(2, v->cargo.Source());
    00111       str = STR_VEHICLE_DETAILS_CARGO_FROM;
    00112       feeder_share += v->cargo.FeederShare();
    00113     }
    00114     DrawString(left, right, y + 2 * FONT_HEIGHT_NORMAL + 1 + y_offset, str);
    00115   }
    00116
    00117   /* Draw Transfer credits text */
    00118   SetDParam(0, feeder_share);
    00119   DrawString(left, right, y + 3 * FONT_HEIGHT_NORMAL + 3 + y_offset, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);
    00120 }
    00121
    00131 void DrawRoadVehImage(const Vehicle *v, int left, int right, int y, VehicleID selection, int skip)
    00132 {
    00133   bool rtl = _current_text_dir == TD_RTL;
    00134   Direction dir = rtl ? DIR_E : DIR_W;
    00135   const RoadVehicle *u = RoadVehicle::From(v);
    00136
    00137   DrawPixelInfo tmp_dpi, *old_dpi;
    00138   int max_width = right - left + 1;
    00139
    00140   if (!FillDrawPixelInfo(&tmp_dpi, left, y, max_width, 14)) return;
    00141
    00142   old_dpi = _cur_dpi;
    00143   _cur_dpi = &tmp_dpi;
    00144
    00145   int px = rtl ? max_width + skip : -skip;
    00146   for (; u != NULL && (rtl ? px > 0 : px < max_width); u = u->Next()) {
    00147     Point offset;
    00148     int width = u->GetDisplayImageWidth(&offset);
    00149
    00150     if (rtl ? px + width > 0 : px - width < max_width) {
    00151       PaletteID pal = (u->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(u);
    00152       DrawSprite(u->GetImage(dir), pal, px + (rtl ? -offset.x : offset.x), 6 + offset.y);
    00153     }
    00154
    00155     px += rtl ? -width : width;
    00156   }
    00157
    00158   if (v->index == selection) {
    00159     DrawFrameRect((rtl ? px : left) - 1, y - 1, (rtl ? px : right) - 1, y + 12, COLOUR_WHITE, FR_BORDERONLY);
    00160   }
    00161
    00162   _cur_dpi = old_dpi;
    00163 }