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 r the Rect to draw within
30 void DrawAircraftDetails(const Aircraft
*v
, const Rect
&r
)
32 Money feeder_share
= 0;
35 for (const Aircraft
*u
= v
; u
!= nullptr; u
= u
->Next()) {
36 if (u
->IsNormalAircraft()) {
37 SetDParam(0, PackEngineNameDParam(u
->engine_type
, EngineNameContext::VehicleDetails
));
38 SetDParam(1, u
->build_year
);
39 SetDParam(2, u
->value
);
40 DrawString(r
.left
, r
.right
, y
, STR_VEHICLE_INFO_BUILT_VALUE
);
41 y
+= GetCharacterHeight(FS_NORMAL
);
43 SetDParam(0, u
->cargo_type
);
44 SetDParam(1, u
->cargo_cap
);
45 SetDParam(2, u
->Next()->cargo_type
);
46 SetDParam(3, u
->Next()->cargo_cap
);
47 SetDParam(4, GetCargoSubtypeText(u
));
48 DrawString(r
.left
, r
.right
, y
, (u
->Next()->cargo_cap
!= 0) ? STR_VEHICLE_INFO_CAPACITY_CAPACITY
: STR_VEHICLE_INFO_CAPACITY
);
49 y
+= GetCharacterHeight(FS_NORMAL
) + WidgetDimensions::scaled
.vsep_normal
;
52 if (u
->cargo_cap
!= 0) {
53 uint cargo_count
= u
->cargo
.StoredCount();
55 if (cargo_count
!= 0) {
56 /* Cargo names (fix pluralness) */
57 SetDParam(0, u
->cargo_type
);
58 SetDParam(1, cargo_count
);
59 SetDParam(2, u
->cargo
.GetFirstStation());
60 DrawString(r
.left
, r
.right
, y
, STR_VEHICLE_DETAILS_CARGO_FROM
);
61 y
+= GetCharacterHeight(FS_NORMAL
);
62 feeder_share
+= u
->cargo
.GetFeederShare();
67 y
+= WidgetDimensions::scaled
.vsep_normal
;
68 SetDParam(0, feeder_share
);
69 DrawString(r
.left
, r
.right
, y
, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE
);
74 * Draws an image of an aircraft
75 * @param v Front vehicle
76 * @param r Rect to draw at
77 * @param selection Selected vehicle to draw a frame around
79 void DrawAircraftImage(const Vehicle
*v
, const Rect
&r
, VehicleID selection
, EngineImageType image_type
)
81 bool rtl
= _current_text_dir
== TD_RTL
;
84 v
->GetImage(rtl
? DIR_E
: DIR_W
, image_type
, &seq
);
89 int width
= UnScaleGUI(rect
.Width());
90 int x_offs
= UnScaleGUI(rect
.left
);
91 int x
= rtl
? r
.right
- width
- x_offs
: r
.left
- x_offs
;
92 /* This magic -1 offset is related to the sprite_y_offsets in build_vehicle_gui.cpp */
93 int y
= ScaleSpriteTrad(-1) + CenterBounds(r
.top
, r
.bottom
, 0);
94 bool helicopter
= v
->subtype
== AIR_HELICOPTER
;
98 PaletteID pal
= (v
->vehstatus
& VS_CRASHED
) ? PALETTE_CRASH
: GetVehiclePalette(v
);
99 seq
.Draw(x
, y
, pal
, (v
->vehstatus
& VS_CRASHED
) != 0);
101 /* Aircraft can store cargo in their shadow, show this if present. */
102 const Vehicle
*u
= v
->Next();
103 assert(u
!= nullptr);
105 if (u
->cargo_cap
> 0 && u
->cargo_type
!= v
->cargo_type
) {
106 dx
= GetLargestCargoIconSize().width
/ 2;
107 DrawCargoIconOverlay(x
+ dx
, y
, u
->cargo_type
);
109 if (v
->cargo_cap
> 0) DrawCargoIconOverlay(x
- dx
, y
, v
->cargo_type
);
112 const Aircraft
*a
= Aircraft::From(v
);
113 VehicleSpriteSeq rotor_seq
;
114 GetCustomRotorSprite(a
, image_type
, &rotor_seq
);
115 if (!rotor_seq
.IsValid()) rotor_seq
.Set(SPR_ROTOR_STOPPED
);
116 heli_offs
= ScaleSpriteTrad(5);
117 rotor_seq
.Draw(x
, y
- heli_offs
, PAL_NONE
, false);
119 if (v
->index
== selection
) {
121 y
+= UnScaleGUI(rect
.top
) - heli_offs
;
122 Rect hr
= {x
, y
, x
+ width
- 1, y
+ UnScaleGUI(rect
.Height()) + heli_offs
- 1};
123 DrawFrameRect(hr
.Expand(WidgetDimensions::scaled
.bevel
), COLOUR_WHITE
, FR_BORDERONLY
);