Add ScriptStoryPageElementList to get the contents of a page
[openttd/fttd.git] / src / roadveh_gui.cpp
blobbf837bbad3be9dbdf5e492a87cc67fa60b2d7ef2
1 /* $Id$ */
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"
19 #include "table/strings.h"
21 /**
22 * Draw the details for the given vehicle at the given position
24 * @param v current vehicle
25 * @param left The left most coordinate to draw
26 * @param right The right most coordinate to draw
27 * @param y The y coordinate
29 void DrawRoadVehDetails(const Vehicle *v, int left, int right, int y)
31 uint y_offset = v->HasArticulatedPart() ? 15 : 0; // Draw the first line below the sprite of an articulated RV instead of after it.
32 StringID str;
33 Money feeder_share = 0;
35 SetDParam(0, v->engine_type);
36 SetDParam(1, v->build_year);
37 SetDParam(2, v->value);
38 DrawString(left, right, y + y_offset, STR_VEHICLE_INFO_BUILT_VALUE);
40 if (v->HasArticulatedPart()) {
41 CargoArray max_cargo;
42 StringID subtype_text[NUM_CARGO];
43 char capacity[512];
45 memset(subtype_text, 0, sizeof(subtype_text));
47 for (const Vehicle *u = v; u != NULL; u = u->Next()) {
48 max_cargo[u->cargo_type] += u->cargo_cap;
49 if (u->cargo_cap > 0) {
50 StringID text = GetCargoSubtypeText(u);
51 if (text != STR_EMPTY) subtype_text[u->cargo_type] = text;
55 GetString(capacity, STR_VEHICLE_DETAILS_TRAIN_ARTICULATED_RV_CAPACITY, lastof(capacity));
57 bool first = true;
58 for (CargoID i = 0; i < NUM_CARGO; i++) {
59 if (max_cargo[i] > 0) {
60 char buffer[128];
62 SetDParam(0, i);
63 SetDParam(1, max_cargo[i]);
64 GetString(buffer, STR_JUST_CARGO, lastof(buffer));
66 if (!first) strecat(capacity, ", ", lastof(capacity));
67 strecat(capacity, buffer, lastof(capacity));
69 if (subtype_text[i] != 0) {
70 GetString(buffer, subtype_text[i], lastof(buffer));
71 strecat(capacity, buffer, lastof(capacity));
74 first = false;
78 DrawString(left, right, y + FONT_HEIGHT_NORMAL + y_offset, capacity, TC_BLUE);
80 for (const Vehicle *u = v; u != NULL; u = u->Next()) {
81 if (u->cargo_cap == 0) continue;
83 str = STR_VEHICLE_DETAILS_CARGO_EMPTY;
84 if (u->cargo.StoredCount() > 0) {
85 SetDParam(0, u->cargo_type);
86 SetDParam(1, u->cargo.StoredCount());
87 SetDParam(2, u->cargo.Source());
88 str = STR_VEHICLE_DETAILS_CARGO_FROM;
89 feeder_share += u->cargo.FeederShare();
91 DrawString(left, right, y + 2 * FONT_HEIGHT_NORMAL + 1 + y_offset, str);
93 y_offset += FONT_HEIGHT_NORMAL + 1;
96 y_offset -= FONT_HEIGHT_NORMAL + 1;
97 } else {
98 SetDParam(0, v->cargo_type);
99 SetDParam(1, v->cargo_cap);
100 SetDParam(4, GetCargoSubtypeText(v));
101 DrawString(left, right, y + FONT_HEIGHT_NORMAL + y_offset, STR_VEHICLE_INFO_CAPACITY);
103 str = STR_VEHICLE_DETAILS_CARGO_EMPTY;
104 if (v->cargo.StoredCount() > 0) {
105 SetDParam(0, v->cargo_type);
106 SetDParam(1, v->cargo.StoredCount());
107 SetDParam(2, v->cargo.Source());
108 str = STR_VEHICLE_DETAILS_CARGO_FROM;
109 feeder_share += v->cargo.FeederShare();
111 DrawString(left, right, y + 2 * FONT_HEIGHT_NORMAL + 1 + y_offset, str);
114 /* Draw Transfer credits text */
115 SetDParam(0, feeder_share);
116 DrawString(left, right, y + 3 * FONT_HEIGHT_NORMAL + 3 + y_offset, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);
120 * Draws an image of a road vehicle chain
121 * @param v Front vehicle
122 * @param left The minimum horizontal position
123 * @param right The maximum horizontal position
124 * @param y Vertical position to draw at
125 * @param selection Selected vehicle to draw a frame around
126 * @param skip Number of pixels to skip at the front (for scrolling)
128 void DrawRoadVehImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip)
130 bool rtl = _current_text_dir == TD_RTL;
131 Direction dir = rtl ? DIR_E : DIR_W;
132 const RoadVehicle *u = RoadVehicle::From(v);
134 DrawPixelInfo tmp_dpi, *old_dpi;
135 int max_width = right - left + 1;
137 if (!FillDrawPixelInfo(&tmp_dpi, left, y, max_width, 14)) return;
139 old_dpi = _cur_dpi;
140 _cur_dpi = &tmp_dpi;
142 int px = rtl ? max_width + skip : -skip;
143 for (; u != NULL && (rtl ? px > 0 : px < max_width); u = u->Next()) {
144 Point offset;
145 int width = u->GetDisplayImageWidth(&offset);
147 if (rtl ? px + width > 0 : px - width < max_width) {
148 PaletteID pal = (u->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(u);
149 DrawSprite(u->GetImage(dir, image_type), pal, px + (rtl ? -offset.x : offset.x), 6 + offset.y);
152 px += rtl ? -width : width;
155 if (v->index == selection) {
156 DrawFrameRect((rtl ? px : 0), 0, (rtl ? max_width : px) - 1, 12, COLOUR_WHITE, FR_BORDERONLY);
159 _cur_dpi = old_dpi;