OpenTTD Source: src/ship_gui.cpp Source File

OpenTTD Source 12.0-beta1

ship_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 "vehicle_base.h"
12 #include "window_gui.h"
13 #include "gfx_func.h"
14 #include "vehicle_gui.h"
15 #include "strings_func.h"
16 #include "vehicle_func.h"
17 #include "spritecache.h"
18 #include "zoom_func.h"
19
20 #include "table/strings.h"
21
22 #include "safeguards.h"
23
32 void DrawShipImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type)
33 {
34 bool rtl = _current_text_dir == TD_RTL;
35
36 VehicleSpriteSeq seq;
37 v->GetImage(rtl ? DIR_E : DIR_W, image_type, &seq);
38
39 Rect rect;
40 seq.GetBounds(&rect);
41
42 int width = UnScaleGUI(rect.right - rect.left + 1);
43 int x_offs = UnScaleGUI(rect.left);
44 int x = rtl ? right - width - x_offs : left - x_offs;
45
46 y += ScaleGUITrad(10);
47 seq.Draw(x, y, GetVehiclePalette(v), false);
48
49 if (v->index == selection) {
50 x += x_offs;
51 y += UnScaleGUI(rect.top);
52 DrawFrameRect(x - 1, y - 1, x + width + 1, y + UnScaleGUI(rect.bottom - rect.top + 1) + 1, COLOUR_WHITE, FR_BORDERONLY);
53 }
54 }
55
64 void DrawShipDetails(const Vehicle *v, int left, int right, int y)
65 {
66 SetDParam(0, v->engine_type);
67 SetDParam(1, v->build_year);
68 SetDParam(2, v->value);
69 DrawString(left, right, y, STR_VEHICLE_INFO_BUILT_VALUE);
70
71 SetDParam(0, v->cargo_type);
72 SetDParam(1, v->cargo_cap);
73 SetDParam(4, GetCargoSubtypeText(v));
74 DrawString(left, right, y + FONT_HEIGHT_NORMAL, STR_VEHICLE_INFO_CAPACITY);
75
76 StringID str = STR_VEHICLE_DETAILS_CARGO_EMPTY;
77 if (v->cargo.StoredCount() > 0) {
78 SetDParam(0, v->cargo_type);
79 SetDParam(1, v->cargo.StoredCount());
80 SetDParam(2, v->cargo.Source());
81 str = STR_VEHICLE_DETAILS_CARGO_FROM;
82 }
83 DrawString(left, right, y + 2 * FONT_HEIGHT_NORMAL + 1, str);
84
85 /* Draw Transfer credits text */
86 SetDParam(0, v->cargo.FeederShare());
87 DrawString(left, right, y + 3 * FONT_HEIGHT_NORMAL + 3, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);
88 }
VehicleCargoList::StoredCount
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
Definition: cargopacket.h:352
vehicle_gui.h
Vehicle::value
Money value
Value of the vehicle.
Definition: vehicle_base.h:253
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
UnScaleGUI
static int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
Definition: zoom_func.h:66
vehicle_base.h
zoom_func.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:642
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:221
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:196
gfx_func.h
window_gui.h
DIR_E
@ DIR_E
East.
Definition: direction_type.h:28
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:299
VehicleSpriteSeq
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:129
Vehicle::cargo
VehicleCargoList cargo
The cargo this vehicle is carrying.
Definition: vehicle_base.h:320
safeguards.h
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:32
stdafx.h
GetCargoSubtypeText
StringID GetCargoSubtypeText(const Vehicle *v)
Get the cargo subtype text from NewGRF for the vehicle details window.
Definition: vehicle_gui.cpp:1156
spritecache.h
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:64
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
vehicle_func.h
strings_func.h
Vehicle::cargo_cap
uint16 cargo_cap
total capacity
Definition: vehicle_base.h:318
GetVehiclePalette
PaletteID GetVehiclePalette(const Vehicle *v)
Get the colour map for a vehicle.
Definition: vehicle.cpp:2048
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:165
ScaleGUITrad
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:76
Vehicle::build_year
Year build_year
Year the vehicle has been built.
Definition: vehicle_base.h:269
VehicleCargoList::Source
StationID Source() const
Returns source of the first cargo packet in this list.
Definition: cargopacket.h:323
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:209
Vehicle::cargo_type
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:316
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
VehicleCargoList::FeederShare
Money FeederShare() const
Returns total sum of the feeder share for all packets.
Definition: cargopacket.h:332
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:30
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:455