OpenTTD

ship_gui.cpp
Go to the documentation of this file.
1 /* $Id: ship_gui.cpp 27667 2016-10-16 14:58:38Z 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 "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"
21
22 #include "table/strings.h"
23
24 #include "safeguards.h"
25
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;
37
38 VehicleSpriteSeq seq;
39 v->GetImage(rtl ? DIR_E : DIR_W, image_type, &seq);
40
41 Rect rect;
42 seq.GetBounds(&rect);
43
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;
47
48 y += ScaleGUITrad(10);
49 seq.Draw(x, y, GetVehiclePalette(v), false);
50
51 if (v->index == selection) {
52 x += x_offs;
53 y += UnScaleGUI(rect.top);
54 DrawFrameRect(x - 1, y - 1, x + width + 1, y + UnScaleGUI(rect.bottom - rect.top + 1) + 1, COLOUR_WHITE, FR_BORDERONLY);
55 }
56 }
57
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);
72
73 SetDParam(0, v->cargo_type);
74 SetDParam(1, v->cargo_cap);
75 SetDParam(4, GetCargoSubtypeText(v));
76 DrawString(left, right, y + FONT_HEIGHT_NORMAL, STR_VEHICLE_INFO_CAPACITY);
77
78 StringID str = STR_VEHICLE_DETAILS_CARGO_EMPTY;
79 if (v->cargo.StoredCount() > 0) {
80 SetDParam(0, v->cargo_type);
81 SetDParam(1, v->cargo.StoredCount());
82 SetDParam(2, v->cargo.Source());
83 str = STR_VEHICLE_DETAILS_CARGO_FROM;
84 }
85 DrawString(left, right, y + 2 * FONT_HEIGHT_NORMAL + 1, str);
86
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 }
VehicleCargoList::Source
StationID Source() const
Returns source of the first cargo packet in this list.
Definition: cargopacket.h:337
strings_func.h
Functions related to OTTD&#39;s strings.
Vehicle::cargo
VehicleCargoList cargo
The cargo this vehicle is carrying.
Definition: vehicle_base.h:309
Vehicle::value
Money value
Value of the vehicle.
Definition: vehicle_base.h:241
DrawShipDetails
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
UnScaleGUI
static int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
Definition: zoom_func.h:72
DrawShipImage
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
DIR_E
East.
Definition: direction_type.h:30
ScaleGUITrad
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:82
vehicle_func.h
Functions related to vehicles.
VehicleSpriteSeq::Draw
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
Definition: vehicle.cpp:127
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:212
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
VehicleCargoList::FeederShare
Money FeederShare() const
Returns total sum of the feeder share for all packets.
Definition: cargopacket.h:346
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:443
GetVehiclePalette
PaletteID GetVehiclePalette(const Vehicle *v)
Get the colour map for a vehicle.
Definition: vehicle.cpp:1954
EngineImageType
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:87
VehicleCargoList::StoredCount
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
Definition: cargopacket.h:366
vehicle_gui.h
Functions related to the vehicle&#39;s GUIs.
window_gui.h
Functions, definitions and such used only by the GUI.
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:177
Vehicle::cargo_cap
uint16 cargo_cap
total capacity
Definition: vehicle_base.h:307
DIR_W
West.
Definition: direction_type.h:34
VehicleID
uint32 VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:18
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:180
gfx_func.h
Functions related to the gfx engine.
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
safeguards.h
A number of safeguards to prevent using unsafe methods.
Vehicle::cargo_type
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:305
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:499
VehicleSpriteSeq
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:130
spritecache.h
Functions to cache sprites in memory.
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
FR_BORDERONLY
Draw border only, no background.
Definition: window_gui.h:30
Vehicle::build_year
Year build_year
Year the vehicle has been built.
Definition: vehicle_base.h:257
vehicle_base.h
Base class for all vehicles.
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:52
zoom_func.h
Functions related to zooming.
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:288
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:40
TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:26
GetCargoSubtypeText
StringID GetCargoSubtypeText(const Vehicle *v)
Get the cargo subtype text from NewGRF for the vehicle details window.
Definition: vehicle_gui.cpp:1072
VehicleSpriteSeq::GetBounds
void GetBounds(Rect *bounds) const
Determine shared bounds of all sprites.
Definition: vehicle.cpp:99
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:201