roadveh_gui.cpp

Go to the documentation of this file.
00001 /* $Id: roadveh_gui.cpp 18872 2010-01-21 01:38:13Z rubidium $ */
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   const RoadVehicle *rv = RoadVehicle::From(v);
00035 
00036   uint y_offset = rv->HasArticulatedPart() ? 15 : 0; // Draw the first line below the sprite of an articulated RV instead of after it.
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   /* Draw Transfer credits text */
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 
00132 void DrawRoadVehImage(const Vehicle *v, int left, int right, int y, VehicleID selection)
00133 {
00134   bool rtl = _dynlang.text_dir == TD_RTL;
00135   Direction dir = rtl ? DIR_E : DIR_W;
00136   const RoadVehicle *u = RoadVehicle::From(v);
00137 
00138   int max_width = right - left + 1;
00139   int spent_width = 0;
00140   int pos = rtl ? right : left;
00141 
00142   for (; u != NULL && spent_width < max_width; u = u->Next()) {
00143     Point offset;
00144     int width = u->GetDisplayImageWidth(&offset);
00145 
00146     PaletteID pal = (u->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(u);
00147     DrawSprite(u->GetImage(dir), pal, pos + (rtl ? -offset.x : offset.x), y + 6 + offset.y);
00148 
00149     pos += rtl ? -width : width;
00150     spent_width += width;
00151   }
00152 
00153   if (v->index == selection) {
00154     DrawFrameRect((rtl ? pos : left) - 1, y - 1, (rtl ? pos : right) - 1, y + 12, COLOUR_WHITE, FR_BORDERONLY);
00155   }
00156 }

Generated on Wed Feb 17 23:06:51 2010 for OpenTTD by  doxygen 1.6.1