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"
18 #include "zoom_func.h"
20 #include "table/strings.h"
23 * Draw the details for the given vehicle at the given position
25 * @param v current vehicle
26 * @param left The left most coordinate to draw
27 * @param right The right most coordinate to draw
28 * @param y The y coordinate
30 void DrawRoadVehDetails(const Vehicle
*v
, int left
, int right
, int y
)
32 uint y_offset
= v
->HasArticulatedPart() ? ScaleGUITrad(15) : 0; // Draw the first line below the sprite of an articulated RV instead of after it.
34 Money feeder_share
= 0;
36 SetDParam(0, v
->engine_type
);
37 SetDParam(1, v
->build_year
);
38 SetDParam(2, v
->value
);
39 DrawString(left
, right
, y
+ y_offset
, STR_VEHICLE_INFO_BUILT_VALUE
);
41 if (v
->HasArticulatedPart()) {
43 StringID subtype_text
[NUM_CARGO
];
44 sstring
<512> capacity
;
46 memset(subtype_text
, 0, sizeof(subtype_text
));
48 for (const Vehicle
*u
= v
; u
!= NULL
; u
= u
->Next()) {
49 max_cargo
[u
->cargo_type
] += u
->cargo_cap
;
50 if (u
->cargo_cap
> 0) {
51 StringID text
= GetCargoSubtypeText(u
);
52 if (text
!= STR_EMPTY
) subtype_text
[u
->cargo_type
] = text
;
56 GetString (&capacity
, STR_VEHICLE_DETAILS_TRAIN_ARTICULATED_RV_CAPACITY
);
59 for (CargoID i
= 0; i
< NUM_CARGO
; i
++) {
60 if (max_cargo
[i
] > 0) {
64 SetDParam(1, max_cargo
[i
]);
65 GetString (buffer
, STR_JUST_CARGO
);
67 if (!first
) capacity
.append (", ");
68 capacity
.append (buffer
);
70 if (subtype_text
[i
] != 0) {
71 GetString (buffer
, subtype_text
[i
]);
72 capacity
.append (buffer
);
79 DrawString(left
, right
, y
+ FONT_HEIGHT_NORMAL
+ y_offset
, capacity
.c_str(), TC_BLUE
);
81 for (const Vehicle
*u
= v
; u
!= NULL
; u
= u
->Next()) {
82 if (u
->cargo_cap
== 0) continue;
84 str
= STR_VEHICLE_DETAILS_CARGO_EMPTY
;
85 if (u
->cargo
.StoredCount() > 0) {
86 SetDParam(0, u
->cargo_type
);
87 SetDParam(1, u
->cargo
.StoredCount());
88 SetDParam(2, u
->cargo
.Source());
89 str
= STR_VEHICLE_DETAILS_CARGO_FROM
;
90 feeder_share
+= u
->cargo
.FeederShare();
92 DrawString(left
, right
, y
+ 2 * FONT_HEIGHT_NORMAL
+ 1 + y_offset
, str
);
94 y_offset
+= FONT_HEIGHT_NORMAL
+ 1;
97 y_offset
-= FONT_HEIGHT_NORMAL
+ 1;
99 SetDParam(0, v
->cargo_type
);
100 SetDParam(1, v
->cargo_cap
);
101 SetDParam(4, GetCargoSubtypeText(v
));
102 DrawString(left
, right
, y
+ FONT_HEIGHT_NORMAL
+ y_offset
, STR_VEHICLE_INFO_CAPACITY
);
104 str
= STR_VEHICLE_DETAILS_CARGO_EMPTY
;
105 if (v
->cargo
.StoredCount() > 0) {
106 SetDParam(0, v
->cargo_type
);
107 SetDParam(1, v
->cargo
.StoredCount());
108 SetDParam(2, v
->cargo
.Source());
109 str
= STR_VEHICLE_DETAILS_CARGO_FROM
;
110 feeder_share
+= v
->cargo
.FeederShare();
112 DrawString(left
, right
, y
+ 2 * FONT_HEIGHT_NORMAL
+ 1 + y_offset
, str
);
115 /* Draw Transfer credits text */
116 SetDParam(0, feeder_share
);
117 DrawString(left
, right
, y
+ 3 * FONT_HEIGHT_NORMAL
+ 3 + y_offset
, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE
);
121 * Draws an image of a road vehicle chain
122 * @param v Front vehicle
123 * @param left The minimum horizontal position
124 * @param right The maximum horizontal position
125 * @param y Vertical position to draw at
126 * @param selection Selected vehicle to draw a frame around
127 * @param skip Number of pixels to skip at the front (for scrolling)
129 void DrawRoadVehImage(const Vehicle
*v
, int left
, int right
, int y
, VehicleID selection
, EngineImageType image_type
, int skip
)
131 bool rtl
= _current_text_dir
== TD_RTL
;
132 Direction dir
= rtl
? DIR_E
: DIR_W
;
133 const RoadVehicle
*u
= RoadVehicle::From(v
);
135 DrawPixelInfo tmp_dpi
, *old_dpi
;
136 int max_width
= right
- left
+ 1;
138 if (!FillDrawPixelInfo(&tmp_dpi
, left
, y
, max_width
, ScaleGUITrad(14))) return;
143 int px
= rtl
? max_width
+ skip
: -skip
;
144 for (; u
!= NULL
&& (rtl
? px
> 0 : px
< max_width
); u
= u
->Next()) {
146 int width
= u
->GetDisplayImageWidth(&offset
);
148 if (rtl
? px
+ width
> 0 : px
- width
< max_width
) {
149 PaletteID pal
= (u
->vehstatus
& VS_CRASHED
) ? PALETTE_CRASH
: GetVehiclePalette(u
);
150 DrawSprite(u
->GetImage(dir
, image_type
), pal
, px
+ (rtl
? -offset
.x
: offset
.x
), ScaleGUITrad(6) + offset
.y
);
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
);