Update: Translations from eints
[openttd-github.git] / src / ship_gui.cpp
blob2ea017e7bc9658685f981e2d5d84effc278894cf
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 */
8 /** @file ship_gui.cpp GUI for ships. */
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"
20 #include "table/strings.h"
22 #include "safeguards.h"
24 /**
25 * Draws an image of a ship
26 * @param v Front vehicle
27 * @param r Rect to draw at
28 * @param selection Selected vehicle to draw a frame around
30 void DrawShipImage(const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type)
32 bool rtl = _current_text_dir == TD_RTL;
34 VehicleSpriteSeq seq;
35 v->GetImage(rtl ? DIR_E : DIR_W, image_type, &seq);
37 Rect rect;
38 seq.GetBounds(&rect);
40 int width = UnScaleGUI(rect.Width());
41 int x_offs = UnScaleGUI(rect.left);
42 int x = rtl ? r.right - width - x_offs : r.left - x_offs;
43 /* This magic -1 offset is related to the sprite_y_offsets in build_vehicle_gui.cpp */
44 int y = ScaleSpriteTrad(-1) + CenterBounds(r.top, r.bottom, 0);
46 seq.Draw(x, y, GetVehiclePalette(v), false);
47 if (v->cargo_cap > 0) DrawCargoIconOverlay(x, y, v->cargo_type);
49 if (v->index == selection) {
50 x += x_offs;
51 y += UnScaleGUI(rect.top);
52 Rect hr = {x, y, x + width - 1, y + UnScaleGUI(rect.Height()) - 1};
53 DrawFrameRect(hr.Expand(WidgetDimensions::scaled.bevel), COLOUR_WHITE, FR_BORDERONLY);
57 /**
58 * Draw the details for the given vehicle at the given position
60 * @param v current vehicle
61 * @param r the Rect to draw within
63 void DrawShipDetails(const Vehicle *v, const Rect &r)
65 int y = r.top;
67 SetDParam(0, PackEngineNameDParam(v->engine_type, EngineNameContext::VehicleDetails));
68 SetDParam(1, v->build_year);
69 SetDParam(2, v->value);
70 DrawString(r.left, r.right, y, STR_VEHICLE_INFO_BUILT_VALUE);
71 y += GetCharacterHeight(FS_NORMAL);
73 SetDParam(0, v->cargo_type);
74 SetDParam(1, v->cargo_cap);
75 SetDParam(4, GetCargoSubtypeText(v));
76 DrawString(r.left, r.right, y, STR_VEHICLE_INFO_CAPACITY);
77 y += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
79 StringID str = STR_VEHICLE_DETAILS_CARGO_EMPTY;
80 if (v->cargo.StoredCount() > 0) {
81 SetDParam(0, v->cargo_type);
82 SetDParam(1, v->cargo.StoredCount());
83 SetDParam(2, v->cargo.GetFirstStation());
84 str = STR_VEHICLE_DETAILS_CARGO_FROM;
86 DrawString(r.left, r.right, y, str);
87 y += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
89 /* Draw Transfer credits text */
90 SetDParam(0, v->cargo.GetFeederShare());
91 DrawString(r.left, r.right, y, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);