2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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 /** @file aircraft_gui.cpp The GUI of aircraft. */
12 #include "vehicle_gui.h"
13 #include "newgrf_engine.h"
14 #include "strings_func.h"
15 #include "vehicle_func.h"
16 #include "window_gui.h"
17 #include "spritecache.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 DrawAircraftDetails(const Aircraft
*v
, int left
, int right
, int y
)
34 int y_offset
= (v
->Next()->cargo_cap
!= 0) ? -(FONT_HEIGHT_NORMAL
+ 1): 0;
35 Money feeder_share
= 0;
37 for (const Aircraft
*u
= v
; u
!= nullptr; u
= u
->Next()) {
38 if (u
->IsNormalAircraft()) {
39 SetDParam(0, u
->engine_type
);
40 SetDParam(1, u
->build_year
);
41 SetDParam(2, u
->value
);
42 DrawString(left
, right
, y
, STR_VEHICLE_INFO_BUILT_VALUE
);
44 SetDParam(0, u
->cargo_type
);
45 SetDParam(1, u
->cargo_cap
);
46 SetDParam(2, u
->Next()->cargo_type
);
47 SetDParam(3, u
->Next()->cargo_cap
);
48 SetDParam(4, GetCargoSubtypeText(u
));
49 DrawString(left
, right
, y
+ FONT_HEIGHT_NORMAL
, (u
->Next()->cargo_cap
!= 0) ? STR_VEHICLE_INFO_CAPACITY_CAPACITY
: STR_VEHICLE_INFO_CAPACITY
);
52 if (u
->cargo_cap
!= 0) {
53 uint cargo_count
= u
->cargo
.StoredCount();
55 y_offset
+= FONT_HEIGHT_NORMAL
+ 1;
56 if (cargo_count
!= 0) {
57 /* Cargo names (fix pluralness) */
58 SetDParam(0, u
->cargo_type
);
59 SetDParam(1, cargo_count
);
60 SetDParam(2, u
->cargo
.Source());
61 DrawString(left
, right
, y
+ 2 * FONT_HEIGHT_NORMAL
+ 1 + y_offset
, STR_VEHICLE_DETAILS_CARGO_FROM
);
62 feeder_share
+= u
->cargo
.FeederShare();
67 SetDParam(0, feeder_share
);
68 DrawString(left
, right
, y
+ 3 * FONT_HEIGHT_NORMAL
+ 3 + y_offset
, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE
);
73 * Draws an image of an aircraft
74 * @param v Front vehicle
75 * @param left The minimum horizontal position
76 * @param right The maximum horizontal position
77 * @param y Vertical position to draw at
78 * @param selection Selected vehicle to draw a frame around
80 void DrawAircraftImage(const Vehicle
*v
, int left
, int right
, int y
, VehicleID selection
, EngineImageType image_type
)
82 bool rtl
= _current_text_dir
== TD_RTL
;
85 v
->GetImage(rtl
? DIR_E
: DIR_W
, image_type
, &seq
);
90 int width
= UnScaleGUI(rect
.right
- rect
.left
+ 1);
91 int x_offs
= UnScaleGUI(rect
.left
);
92 int x
= rtl
? right
- width
- x_offs
: left
- x_offs
;
93 bool helicopter
= v
->subtype
== AIR_HELICOPTER
;
95 int y_offs
= ScaleGUITrad(10);
98 PaletteID pal
= (v
->vehstatus
& VS_CRASHED
) ? PALETTE_CRASH
: GetVehiclePalette(v
);
99 seq
.Draw(x
, y
+ y_offs
, pal
, (v
->vehstatus
& VS_CRASHED
) != 0);
101 const Aircraft
*a
= Aircraft::From(v
);
102 VehicleSpriteSeq rotor_seq
;
103 GetCustomRotorSprite(a
, image_type
, &rotor_seq
);
104 if (!rotor_seq
.IsValid()) rotor_seq
.Set(SPR_ROTOR_STOPPED
);
105 heli_offs
= ScaleGUITrad(5);
106 rotor_seq
.Draw(x
, y
+ y_offs
- heli_offs
, PAL_NONE
, false);
108 if (v
->index
== selection
) {
110 y
+= UnScaleGUI(rect
.top
) + y_offs
- heli_offs
;
111 DrawFrameRect(x
- 1, y
- 1, x
+ width
+ 1, y
+ UnScaleGUI(rect
.bottom
- rect
.top
+ 1) + heli_offs
+ 1, COLOUR_WHITE
, FR_BORDERONLY
);