Go to the documentation of this file.
1 /* $Id: ship_gui.cpp 27667 2016-10-16 14:58:38Z frosch $ */
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 <>.
8  */
12 #include "stdafx.h"
13 #include "vehicle_base.h"
14 #include "window_gui.h"
15 #include "gfx_func.h"
16 #include "vehicle_gui.h"
17 #include "strings_func.h"
18 #include "vehicle_func.h"
19 #include "spritecache.h"
20 #include "zoom_func.h"
22 #include "table/strings.h"
24 #include "safeguards.h"
34 void DrawShipImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type)
35 {
36  bool rtl = _current_text_dir == TD_RTL;
38  VehicleSpriteSeq seq;
39  v->GetImage(rtl ? DIR_E : DIR_W, image_type, &seq);
41  Rect rect;
42  seq.GetBounds(&rect);
44  int width = UnScaleGUI(rect.right - rect.left + 1);
45  int x_offs = UnScaleGUI(rect.left);
46  int x = rtl ? right - width - x_offs : left - x_offs;
48  y += ScaleGUITrad(10);
49  seq.Draw(x, y, GetVehiclePalette(v), false);
51  if (v->index == selection) {
52  x += x_offs;
53  y += UnScaleGUI(;
54  DrawFrameRect(x - 1, y - 1, x + width + 1, y + UnScaleGUI(rect.bottom - + 1) + 1, COLOUR_WHITE, FR_BORDERONLY);
55  }
56 }
66 void DrawShipDetails(const Vehicle *v, int left, int right, int y)
67 {
68  SetDParam(0, v->engine_type);
69  SetDParam(1, v->build_year);
70  SetDParam(2, v->value);
71  DrawString(left, right, y, STR_VEHICLE_INFO_BUILT_VALUE);
73  SetDParam(0, v->cargo_type);
74  SetDParam(1, v->cargo_cap);
79  if (v->cargo.StoredCount() > 0) {
80  SetDParam(0, v->cargo_type);
81  SetDParam(1, v->cargo.StoredCount());
82  SetDParam(2, v->cargo.Source());
84  }
85  DrawString(left, right, y + 2 * FONT_HEIGHT_NORMAL + 1, str);
87  /* Draw Transfer credits text */
88  SetDParam(0, v->cargo.FeederShare());
89  DrawString(left, right, y + 3 * FONT_HEIGHT_NORMAL + 3, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);
90 }
StationID Source() const
Returns source of the first cargo packet in this list.
Definition: cargopacket.h:337
Functions related to OTTD&#39;s strings.
VehicleCargoList cargo
The cargo this vehicle is carrying.
Definition: vehicle_base.h:309
Money value
Value of the vehicle.
Definition: vehicle_base.h:241
void DrawShipDetails(const Vehicle *v, int left, int right, int y)
Draw the details for the given vehicle at the given position.
Definition: ship_gui.cpp:66
static int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
Definition: zoom_func.h:72
void DrawShipImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type)
Draws an image of a ship.
Definition: ship_gui.cpp:34
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:82
Functions related to vehicles.
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
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
Money FeederShare() const
Returns total sum of the feeder share for all packets.
Definition: cargopacket.h:346
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
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:87
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
Definition: cargopacket.h:366
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
uint16 cargo_cap
total capacity
Definition: vehicle_base.h:307
uint32 VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:18
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:180
Functions related to the gfx engine.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:305
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.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
Draw border only, no background.
Definition: window_gui.h:30
Year build_year
Year the vehicle has been built.
Definition: vehicle_base.h:257
Base class for all vehicles.
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:52
Functions related to zooming.
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:288
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