OpenTTD Source  14.0-beta3
aircraft_gui.cpp
Go to the documentation of this file.
1 /*
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/>.
6  */
7 
10 #include "stdafx.h"
11 #include "aircraft.h"
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"
19 
20 #include "table/strings.h"
21 
22 #include "safeguards.h"
23 
30 void DrawAircraftDetails(const Aircraft *v, const Rect &r)
31 {
32  Money feeder_share = 0;
33 
34  int y = r.top;
35  for (const Aircraft *u = v; u != nullptr; u = u->Next()) {
36  if (u->IsNormalAircraft()) {
38  SetDParam(1, u->build_year);
39  SetDParam(2, u->value);
40  DrawString(r.left, r.right, y, STR_VEHICLE_INFO_BUILT_VALUE);
42 
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);
48  DrawString(r.left, r.right, y, (u->Next()->cargo_cap != 0) ? STR_VEHICLE_INFO_CAPACITY_CAPACITY : STR_VEHICLE_INFO_CAPACITY);
50  }
51 
52  if (u->cargo_cap != 0) {
53  uint cargo_count = u->cargo.StoredCount();
54 
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);
62  feeder_share += u->cargo.GetFeederShare();
63  }
64  }
65  }
66 
68  SetDParam(0, feeder_share);
69  DrawString(r.left, r.right, y, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);
70 }
71 
72 
79 void DrawAircraftImage(const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type)
80 {
81  bool rtl = _current_text_dir == TD_RTL;
82 
83  VehicleSpriteSeq seq;
84  v->GetImage(rtl ? DIR_E : DIR_W, image_type, &seq);
85 
86  Rect rect;
87  seq.GetBounds(&rect);
88 
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;
95 
96  int heli_offs = 0;
97 
99  seq.Draw(x, y, pal, (v->vehstatus & VS_CRASHED) != 0);
100  if (helicopter) {
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 = ScaleSpriteTrad(5);
106  rotor_seq.Draw(x, y - heli_offs, PAL_NONE, false);
107  }
108  if (v->index == selection) {
109  x += x_offs;
110  y += UnScaleGUI(rect.top) - heli_offs;
111  Rect hr = {x, y, x + width - 1, y + UnScaleGUI(rect.Height()) + heli_offs - 1};
113  }
114 }
Rect::Height
int Height() const
Get height of Rect.
Definition: geometry_type.hpp:91
vehicle_gui.h
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
SpecializedVehicle::Next
T * Next() const
Get next vehicle in the chain.
Definition: vehicle_base.h:1116
VehicleSpriteSeq::Set
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
Definition: vehicle_base.h:164
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:348
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:234
zoom_func.h
aircraft.h
DIR_W
@ DIR_W
West.
Definition: direction_type.h:32
Rect::Expand
Rect Expand(int s) const
Copy and expand Rect by s pixels.
Definition: geometry_type.hpp:153
EngineImageType
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:85
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:240
VehicleSpriteSeq::Draw
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
Definition: vehicle.cpp:131
PaletteID
uint32_t PaletteID
The number of the palette.
Definition: gfx_type.h:18
Aircraft
Aircraft, helicopters, rotors and their shadows belong to this class.
Definition: aircraft.h:74
Vehicle::GetImage
virtual void GetImage([[maybe_unused]] Direction direction, [[maybe_unused]] EngineImageType image_type, [[maybe_unused]] VehicleSpriteSeq *result) const
Gets the sprite to show for the given direction.
Definition: vehicle_base.h:481
window_gui.h
VehicleSpriteSeq::IsValid
bool IsValid() const
Check whether the sequence contains any sprites.
Definition: vehicle_base.h:148
newgrf_engine.h
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
DIR_E
@ DIR_E
East.
Definition: direction_type.h:28
PackEngineNameDParam
uint64_t PackEngineNameDParam(EngineID engine_id, EngineNameContext context, uint32_t extra_data=0)
Combine an engine ID and a name context to an engine name dparam.
Definition: engine_type.h:199
VS_CRASHED
@ VS_CRASHED
Vehicle is crashed.
Definition: vehicle_base.h:40
VehicleSpriteSeq
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:131
safeguards.h
VehicleID
uint32_t VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
CenterBounds
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition: gfx_func.h:166
stdafx.h
GetCargoSubtypeText
StringID GetCargoSubtypeText(const Vehicle *v)
Get the cargo subtype text from NewGRF for the vehicle details window.
Definition: vehicle_gui.cpp:1325
spritecache.h
vehicle_func.h
PALETTE_CRASH
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition: sprites.h:1602
strings_func.h
SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From
static Aircraft * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1201
GetVehiclePalette
PaletteID GetVehiclePalette(const Vehicle *v)
Get the colour map for a vehicle.
Definition: vehicle.cpp:2123
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
AIR_HELICOPTER
@ AIR_HELICOPTER
an helicopter
Definition: aircraft.h:31
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition: window_gui.h:60
DrawAircraftDetails
void DrawAircraftDetails(const Aircraft *v, const Rect &r)
Draw the details for the given vehicle at the given position.
Definition: aircraft_gui.cpp:30
ScaleSpriteTrad
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition: zoom_func.h:107
VehicleDetails
@ VehicleDetails
Name is shown in the vehicle details GUI.
Definition: engine_type.h:192
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:281
Vehicle::subtype
byte subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
Definition: vehicle_base.h:358
UnScaleGUI
int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
Definition: zoom_func.h:77
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
OverflowSafeInt< int64_t >
DrawString
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:658
WidgetDimensions::bevel
RectPadding bevel
Bevel thickness, affected by "scaled bevels" game option.
Definition: window_gui.h:40
DrawAircraftImage
void DrawAircraftImage(const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type)
Draws an image of an aircraft.
Definition: aircraft_gui.cpp:79
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:85
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
VehicleSpriteSeq::GetBounds
void GetBounds(Rect *bounds) const
Determine shared bounds of all sprites.
Definition: vehicle.cpp:103
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
FR_BORDERONLY
@ FR_BORDERONLY
Draw border only, no background.
Definition: window_gui.h:27