OpenTTD Source: src/aircraft_gui.cpp Source File

OpenTTD Source 1.11.0-RC1

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
32 void DrawAircraftDetails(const Aircraft *v, int left, int right, int y)
33 {
34 int y_offset = (v->Next()->cargo_cap != 0) ? -(FONT_HEIGHT_NORMAL + 1): 0;
35 Money feeder_share = 0;
36
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);
43
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);
50 }
51
52 if (u->cargo_cap != 0) {
53 uint cargo_count = u->cargo.StoredCount();
54
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();
63 }
64 }
65 }
66
67 SetDParam(0, feeder_share);
68 DrawString(left, right, y + 3 * FONT_HEIGHT_NORMAL + 3 + y_offset, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);
69 }
70
71
80 void DrawAircraftImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type)
81 {
82 bool rtl = _current_text_dir == TD_RTL;
83
84 VehicleSpriteSeq seq;
85 v->GetImage(rtl ? DIR_E : DIR_W, image_type, &seq);
86
87 Rect rect;
88 seq.GetBounds(&rect);
89
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;
94
95 int y_offs = ScaleGUITrad(10);
96 int heli_offs = 0;
97
98 PaletteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
99 seq.Draw(x, y + y_offs, pal, (v->vehstatus & VS_CRASHED) != 0);
100 if (helicopter) {
101 const Aircraft *a = Aircraft::From(v);
102 VehicleSpriteSeq rotor_seq;
103 GetCustomRotorSprite(a, true, 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);
107 }
108 if (v->index == selection) {
109 x += x_offs;
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);
112 }
113 }
vehicle_gui.h
SpecializedVehicle::Next
T * Next() const
Get next vehicle in the chain.
Definition: vehicle_base.h:1077
VehicleSpriteSeq::Set
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
Definition: vehicle_base.h:161
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:326
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:227
UnScaleGUI
static int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
Definition: zoom_func.h:66
zoom_func.h
aircraft.h
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:640
DIR_W
@ DIR_W
West.
Definition: direction_type.h:32
EngineImageType
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:85
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:222
VehicleSpriteSeq::Draw
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
Definition: vehicle.cpp:126
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:199
Aircraft
Aircraft, helicopters, rotors and their shadows belong to this class.
Definition: aircraft.h:74
window_gui.h
VehicleSpriteSeq::IsValid
bool IsValid() const
Check whether the sequence contains any sprites.
Definition: vehicle_base.h:145
newgrf_engine.h
DIR_E
@ DIR_E
East.
Definition: direction_type.h:28
VS_CRASHED
@ VS_CRASHED
Vehicle is crashed.
Definition: vehicle_base.h:37
VehicleSpriteSeq
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:128
DrawAircraftDetails
void DrawAircraftDetails(const Aircraft *v, int left, int right, int y)
Draw the details for the given vehicle at the given position.
Definition: aircraft_gui.cpp:32
safeguards.h
stdafx.h
GetCargoSubtypeText
StringID GetCargoSubtypeText(const Vehicle *v)
Get the cargo subtype text from NewGRF for the vehicle details window.
Definition: vehicle_gui.cpp:1152
spritecache.h
vehicle_func.h
PALETTE_CRASH
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition: sprites.h:1594
strings_func.h
Vehicle::cargo_cap
uint16 cargo_cap
total capacity
Definition: vehicle_base.h:316
SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From
static Aircraft * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1162
GetVehiclePalette
PaletteID GetVehiclePalette(const Vehicle *v)
Get the colour map for a vehicle.
Definition: vehicle.cpp:2041
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:179
ScaleGUITrad
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:76
PaletteID
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
AIR_HELICOPTER
@ AIR_HELICOPTER
an helicopter
Definition: aircraft.h:31
VehicleID
uint32 VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:175
Vehicle::subtype
byte subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
Definition: vehicle_base.h:336
OverflowSafeInt< int64, INT64_MAX, INT64_MIN >
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
DrawAircraftImage
void DrawAircraftImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type)
Draws an image of an aircraft.
Definition: aircraft_gui.cpp:80
VehicleSpriteSeq::GetBounds
void GetBounds(Rect *bounds) const
Determine shared bounds of all sprites.
Definition: vehicle.cpp:98
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:48
FR_BORDERONLY
@ FR_BORDERONLY
Draw border only, no background.
Definition: window_gui.h:28
Vehicle::GetImage
virtual void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
Gets the sprite to show for the given direction.
Definition: vehicle_base.h:453