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/>.
10 /** @file roadveh_gui.cpp GUI for road vehicles. */
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"
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.
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()) {
45 StringID subtype_text
[NUM_CARGO
];
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
));
61 for (CargoID i
= 0; i
< NUM_CARGO
; i
++) {
62 if (max_cargo
[i
] > 0) {
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
));
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;
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
);
117 /* Draw Transfer credits text */
118 SetDParam(0, feeder_share
);
119 DrawString(left
, right
, y
+ 3 * FONT_HEIGHT_NORMAL
+ 3 + y_offset
, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE
);
123 * Draws an image of a road vehicle chain
124 * @param v Front vehicle
125 * @param left The minimum horizontal position
126 * @param right The maximum horizontal position
127 * @param y Vertical position to draw at
128 * @param selection Selected vehicle to draw a frame around
129 * @param skip Number of pixels to skip at the front (for scrolling)
131 void DrawRoadVehImage(const Vehicle
*v
, int left
, int right
, int y
, VehicleID selection
, EngineImageType image_type
, int skip
)
133 bool rtl
= _current_text_dir
== TD_RTL
;
134 Direction dir
= rtl
? DIR_E
: DIR_W
;
135 const RoadVehicle
*u
= RoadVehicle::From(v
);
137 DrawPixelInfo tmp_dpi
, *old_dpi
;
138 int max_width
= right
- left
+ 1;
140 if (!FillDrawPixelInfo(&tmp_dpi
, left
, y
, max_width
, ScaleGUITrad(14))) return;
145 int px
= rtl
? max_width
+ skip
: -skip
;
146 for (; u
!= NULL
&& (rtl
? px
> 0 : px
< max_width
); u
= u
->Next()) {
148 int width
= u
->GetDisplayImageWidth(&offset
);
150 if (rtl
? px
+ width
> 0 : px
- width
< max_width
) {
151 PaletteID pal
= (u
->vehstatus
& VS_CRASHED
) ? PALETTE_CRASH
: GetVehiclePalette(u
);
152 VehicleSpriteSeq seq
;
153 u
->GetImage(dir
, image_type
, &seq
);
154 seq
.Draw(px
+ (rtl
? -offset
.x
: offset
.x
), ScaleGUITrad(6) + offset
.y
, pal
, (u
->vehstatus
& VS_CRASHED
) != 0);
157 px
+= rtl
? -width
: width
;
160 if (v
->index
== selection
) {
161 DrawFrameRect((rtl
? px
: 0), 0, (rtl
? max_width
: px
) - 1, ScaleGUITrad(13) - 1, COLOUR_WHITE
, FR_BORDERONLY
);