Merge branch 'development' into feature/no_multiplayer_grf_limit
[openttd-joker.git] / src / roadveh_gui.cpp
blob52613a5efcc0569484fcd0e22e1a4b19691ca0b4
1 /* $Id: roadveh_gui.cpp 25454 2013-06-24 18:39:19Z rubidium $ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
10 /** @file roadveh_gui.cpp GUI for road vehicles. */
12 #include "stdafx.h"
13 #include "roadveh.h"
14 #include "window_gui.h"
15 #include "strings_func.h"
16 #include "vehicle_func.h"
17 #include "string_func.h"
18 #include "zoom_func.h"
20 #include "table/strings.h"
22 #include "safeguards.h"
24 /**
25 * Draw the details for the given vehicle at the given position
27 * @param v current vehicle
28 * @param left The left most coordinate to draw
29 * @param right The right most coordinate to draw
30 * @param y The y coordinate
32 void DrawRoadVehDetails(const Vehicle *v, int left, int right, int y)
34 uint y_offset = v->HasArticulatedPart() ? ScaleGUITrad(15) : 0; // Draw the first line below the sprite of an articulated RV instead of after it.
35 StringID str;
36 Money feeder_share = 0;
38 SetDParam(0, v->engine_type);
39 SetDParam(1, v->build_year);
40 SetDParam(2, v->value);
41 DrawString(left, right, y + y_offset, STR_VEHICLE_INFO_BUILT_VALUE);
43 if (v->HasArticulatedPart()) {
44 CargoArray max_cargo;
45 StringID subtype_text[NUM_CARGO];
46 char capacity[512];
48 memset(subtype_text, 0, sizeof(subtype_text));
50 for (const Vehicle *u = v; u != NULL; u = u->Next()) {
51 max_cargo[u->cargo_type] += u->cargo_cap;
52 if (u->cargo_cap > 0) {
53 StringID text = GetCargoSubtypeText(u);
54 if (text != STR_EMPTY) subtype_text[u->cargo_type] = text;
58 GetString(capacity, STR_VEHICLE_DETAILS_TRAIN_ARTICULATED_RV_CAPACITY, lastof(capacity));
60 bool first = true;
61 for (CargoID i = 0; i < NUM_CARGO; i++) {
62 if (max_cargo[i] > 0) {
63 char buffer[128];
65 SetDParam(0, i);
66 SetDParam(1, max_cargo[i]);
67 GetString(buffer, STR_JUST_CARGO, lastof(buffer));
69 if (!first) strecat(capacity, ", ", lastof(capacity));
70 strecat(capacity, buffer, lastof(capacity));
72 if (subtype_text[i] != 0) {
73 GetString(buffer, subtype_text[i], lastof(buffer));
74 strecat(capacity, buffer, lastof(capacity));
77 first = false;
81 DrawString(left, right, y + FONT_HEIGHT_NORMAL + y_offset, capacity, TC_BLUE);
83 for (const Vehicle *u = v; u != NULL; u = u->Next()) {
84 if (u->cargo_cap == 0) continue;
86 str = STR_VEHICLE_DETAILS_CARGO_EMPTY;
87 if (u->cargo.StoredCount() > 0) {
88 SetDParam(0, u->cargo_type);
89 SetDParam(1, u->cargo.StoredCount());
90 SetDParam(2, u->cargo.Source());
91 str = STR_VEHICLE_DETAILS_CARGO_FROM;
92 feeder_share += u->cargo.FeederShare();
94 DrawString(left, right, y + 2 * FONT_HEIGHT_NORMAL + 1 + y_offset, str);
96 y_offset += FONT_HEIGHT_NORMAL + 1;
99 y_offset -= FONT_HEIGHT_NORMAL + 1;
100 } else {
101 SetDParam(0, v->cargo_type);
102 SetDParam(1, v->cargo_cap);
103 SetDParam(4, GetCargoSubtypeText(v));
104 DrawString(left, right, y + FONT_HEIGHT_NORMAL + y_offset, STR_VEHICLE_INFO_CAPACITY);
106 str = STR_VEHICLE_DETAILS_CARGO_EMPTY;
107 if (v->cargo.StoredCount() > 0) {
108 SetDParam(0, v->cargo_type);
109 SetDParam(1, v->cargo.StoredCount());
110 SetDParam(2, v->cargo.Source());
111 str = STR_VEHICLE_DETAILS_CARGO_FROM;
112 feeder_share += v->cargo.FeederShare();
114 DrawString(left, right, y + 2 * FONT_HEIGHT_NORMAL + 1 + y_offset, str);
119 * Draws an image of a road vehicle chain
120 * @param v Front vehicle
121 * @param left The minimum horizontal position
122 * @param right The maximum horizontal position
123 * @param y Vertical position to draw at
124 * @param selection Selected vehicle to draw a frame around
125 * @param skip Number of pixels to skip at the front (for scrolling)
127 void DrawRoadVehImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip)
129 bool rtl = _current_text_dir == TD_RTL;
130 Direction dir = rtl ? DIR_E : DIR_W;
131 const RoadVehicle *u = RoadVehicle::From(v);
133 DrawPixelInfo tmp_dpi, *old_dpi;
134 int max_width = right - left + 1;
136 if (!FillDrawPixelInfo(&tmp_dpi, left, y, max_width, ScaleGUITrad(14))) return;
138 old_dpi = _cur_dpi;
139 _cur_dpi = &tmp_dpi;
141 int px = rtl ? max_width + skip : -skip;
142 for (; u != NULL && (rtl ? px > 0 : px < max_width); u = u->Next()) {
143 Point offset;
144 int width = u->GetDisplayImageWidth(&offset);
146 if (rtl ? px + width > 0 : px - width < max_width) {
147 PaletteID pal = (u->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(u);
148 VehicleSpriteSeq seq;
149 u->GetImage(dir, image_type, &seq);
150 seq.Draw(px + (rtl ? -offset.x : offset.x), ScaleGUITrad(6) + offset.y, pal, (u->vehstatus & VS_CRASHED) != 0);
153 px += rtl ? -width : width;
156 if (v->index == selection) {
157 DrawFrameRect((rtl ? px : 0), 0, (rtl ? max_width : px) - 1, ScaleGUITrad(13) - 1, COLOUR_WHITE, FR_BORDERONLY);
160 _cur_dpi = old_dpi;