OpenTTD
aircraft_gui.cpp
Go to the documentation of this file.
1 /* $Id: aircraft_gui.cpp 27689 2016-12-10 14:33:58Z frosch $ */
2 
3 /*
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/>.
8  */
9 
12 #include "stdafx.h"
13 #include "aircraft.h"
14 #include "vehicle_gui.h"
15 #include "newgrf_engine.h"
16 #include "strings_func.h"
17 #include "vehicle_func.h"
18 #include "window_gui.h"
19 #include "spritecache.h"
20 #include "zoom_func.h"
21 
22 #include "table/strings.h"
23 
24 #include "safeguards.h"
25 
34 void DrawAircraftDetails(const Aircraft *v, int left, int right, int y)
35 {
36  int y_offset = (v->Next()->cargo_cap != 0) ? -(FONT_HEIGHT_NORMAL + 1): 0;
37  Money feeder_share = 0;
38 
39  for (const Aircraft *u = v; u != NULL; u = u->Next()) {
40  if (u->IsNormalAircraft()) {
41  SetDParam(0, u->engine_type);
42  SetDParam(1, u->build_year);
43  SetDParam(2, u->value);
44  DrawString(left, right, y, STR_VEHICLE_INFO_BUILT_VALUE);
45 
46  SetDParam(0, u->cargo_type);
47  SetDParam(1, u->cargo_cap);
48  SetDParam(2, u->Next()->cargo_type);
49  SetDParam(3, u->Next()->cargo_cap);
51  DrawString(left, right, y + FONT_HEIGHT_NORMAL, (u->Next()->cargo_cap != 0) ? STR_VEHICLE_INFO_CAPACITY_CAPACITY : STR_VEHICLE_INFO_CAPACITY);
52  }
53 
54  if (u->cargo_cap != 0) {
55  uint cargo_count = u->cargo.StoredCount();
56 
57  y_offset += FONT_HEIGHT_NORMAL + 1;
58  if (cargo_count != 0) {
59  /* Cargo names (fix pluralness) */
60  SetDParam(0, u->cargo_type);
61  SetDParam(1, cargo_count);
62  SetDParam(2, u->cargo.Source());
63  DrawString(left, right, y + 2 * FONT_HEIGHT_NORMAL + 1 + y_offset, STR_VEHICLE_DETAILS_CARGO_FROM);
64  feeder_share += u->cargo.FeederShare();
65  }
66  }
67  }
68 
69  SetDParam(0, feeder_share);
70  DrawString(left, right, y + 3 * FONT_HEIGHT_NORMAL + 3 + y_offset, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);
71 }
72 
73 
82 void DrawAircraftImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type)
83 {
84  bool rtl = _current_text_dir == TD_RTL;
85 
86  VehicleSpriteSeq seq;
87  v->GetImage(rtl ? DIR_E : DIR_W, image_type, &seq);
88 
89  Rect rect;
90  seq.GetBounds(&rect);
91 
92  int width = UnScaleGUI(rect.right - rect.left + 1);
93  int x_offs = UnScaleGUI(rect.left);
94  int x = rtl ? right - width - x_offs : left - x_offs;
95  bool helicopter = v->subtype == AIR_HELICOPTER;
96 
97  int y_offs = ScaleGUITrad(10);
98  int heli_offs = 0;
99 
101  seq.Draw(x, y + y_offs, pal, (v->vehstatus & VS_CRASHED) != 0);
102  if (helicopter) {
103  const Aircraft *a = Aircraft::From(v);
104  VehicleSpriteSeq rotor_seq;
105  GetCustomRotorSprite(a, true, image_type, &rotor_seq);
106  if (!rotor_seq.IsValid()) rotor_seq.Set(SPR_ROTOR_STOPPED);
107  heli_offs = ScaleGUITrad(5);
108  rotor_seq.Draw(x, y + y_offs - heli_offs, PAL_NONE, false);
109  }
110  if (v->index == selection) {
111  x += x_offs;
112  y += UnScaleGUI(rect.top) + y_offs - heli_offs;
113  DrawFrameRect(x - 1, y - 1, x + width + 1, y + UnScaleGUI(rect.bottom - rect.top + 1) + heli_offs + 1, COLOUR_WHITE, FR_BORDERONLY);
114  }
115 }
Functions related to OTTD&#39;s strings.
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:20
Functions for NewGRF engines.
static int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
Definition: zoom_func.h:72
East.
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:82
Functions related to vehicles.
Aircraft, helicopters, rotors and their shadows belong to this class.
Definition: aircraft.h:74
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
Definition: vehicle.cpp:127
Vehicle data structure.
Definition: vehicle_base.h:212
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
Definition: vehicle_base.h:163
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
virtual void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
Gets the sprite to show for the given direction.
Definition: vehicle_base.h:443
PaletteID GetVehiclePalette(const Vehicle *v)
Get the colour map for a vehicle.
Definition: vehicle.cpp:1954
Base for aircraft.
byte vehstatus
Status.
Definition: vehicle_base.h:317
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:87
static Aircraft * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Functions related to the vehicle&#39;s GUIs.
Functions, definitions and such used only by the GUI.
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:177
void DrawAircraftImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type)
Draws an image of an aircraft.
byte subtype
subtype (Filled with values from #EffectVehicles/#TrainSubTypes/#AircraftSubTypes) ...
Definition: vehicle_base.h:327
uint16 cargo_cap
total capacity
Definition: vehicle_base.h:307
Vehicle is crashed.
Definition: vehicle_base.h:39
bool IsValid() const
Check whether the sequence contains any sprites.
Definition: vehicle_base.h:147
West.
uint32 VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:18
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:180
T * Next() const
Get next vehicle in the chain.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
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:499
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:130
Functions to cache sprites in memory.
Draw border only, no background.
Definition: window_gui.h:30
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition: sprites.h:1569
void DrawAircraftDetails(const Aircraft *v, int left, int right, int y)
Draw the details for the given vehicle at the given position.
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:52
Functions related to zooming.
an helicopter
Definition: aircraft.h:33
Specification of a rectangle with absolute coordinates of all edges.
Text is written right-to-left by default.
Definition: strings_type.h:26
StringID GetCargoSubtypeText(const Vehicle *v)
Get the cargo subtype text from NewGRF for the vehicle details window.
void GetBounds(Rect *bounds) const
Determine shared bounds of all sprites.
Definition: vehicle.cpp:99
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:201