OpenTTD
aircraft_gui.cpp
Go to the documentation of this file.
1 /* $Id: aircraft_gui.cpp 27134 2015-02-01 20:54:24Z 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  SpriteID sprite = v->GetImage(rtl ? DIR_E : DIR_W, image_type);
87  const Sprite *real_sprite = GetSprite(sprite, ST_NORMAL);
88 
89  int width = UnScaleGUI(real_sprite->width);
90  int x_offs = UnScaleGUI(real_sprite->x_offs);
91  int x = rtl ? right - width - x_offs : left - x_offs;
92  bool helicopter = v->subtype == AIR_HELICOPTER;
93 
94  int y_offs = ScaleGUITrad(10);
95  int heli_offs = 0;
96 
98  DrawSprite(sprite, pal, x, y + y_offs);
99  if (helicopter) {
100  const Aircraft *a = Aircraft::From(v);
101  SpriteID rotor_sprite = GetCustomRotorSprite(a, true, image_type);
102  if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
103  heli_offs = ScaleGUITrad(5);
104  DrawSprite(rotor_sprite, PAL_NONE, x, y + y_offs - heli_offs);
105  }
106  if (v->index == selection) {
107  x += x_offs;
108  y += UnScaleGUI(real_sprite->y_offs) + y_offs - heli_offs;
109  DrawFrameRect(x - 1, y - 1, x + width + 1, y + UnScaleGUI(real_sprite->height) + heli_offs + 1, COLOUR_WHITE, FR_BORDERONLY);
110  }
111 }