OpenTTD Source 20250312-master-gcdcc6b491d
train_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 "window_gui.h"
12#include "command_func.h"
13#include "train.h"
14#include "strings_func.h"
15#include "vehicle_func.h"
16#include "zoom_func.h"
17#include "train_cmd.h"
18
19#include "table/strings.h"
20
21#include "safeguards.h"
22
29void CcBuildWagon(Commands, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray, TileIndex tile, EngineID, bool, CargoType, ClientID)
30{
31 if (result.Failed()) return;
32
33 /* find a locomotive in the depot. */
34 const Vehicle *found = nullptr;
35 for (const Train *t : Train::Iterate()) {
36 if (t->IsFrontEngine() && t->tile == tile && t->IsStoppedInDepot()) {
37 if (found != nullptr) return; // must be exactly one.
38 found = t;
39 }
40 }
41
42 /* if we found a loco, */
43 if (found != nullptr) {
44 found = found->Last();
45 /* put the new wagon at the end of the loco. */
46 Command<CMD_MOVE_RAIL_VEHICLE>::Post(found->tile, new_veh_id, found->index, false);
48 }
49}
50
60static int HighlightDragPosition(int px, int max_width, int y, VehicleID selection, bool chain)
61{
62 bool rtl = _current_text_dir == TD_RTL;
63
64 assert(selection != VehicleID::Invalid());
65 int dragged_width = 0;
66 for (Train *t = Train::Get(selection); t != nullptr; t = chain ? t->Next() : (t->HasArticulatedPart() ? t->GetNextArticulatedPart() : nullptr)) {
67 dragged_width += t->GetDisplayImageWidth(nullptr);
68 }
69
70 int drag_hlight_left = rtl ? std::max(px - dragged_width + 1, 0) : px;
71 int drag_hlight_right = rtl ? px : std::min(px + dragged_width, max_width) - 1;
72 int drag_hlight_width = std::max(drag_hlight_right - drag_hlight_left + 1, 0);
73
74 if (drag_hlight_width > 0) {
75 int height = ScaleSpriteTrad(12);
76 int top = y - height / 2;
77 Rect r = {drag_hlight_left, top, drag_hlight_right, top + height - 1};
78 /* Sprite-scaling is used here as the area is from sprite size */
79 GfxFillRect(r.Shrink(ScaleSpriteTrad(1)), GetColourGradient(COLOUR_GREY, SHADE_LIGHTEST));
80 }
81
82 return drag_hlight_width;
83}
84
93void DrawTrainImage(const Train *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest)
94{
95 bool rtl = _current_text_dir == TD_RTL;
96 Direction dir = rtl ? DIR_E : DIR_W;
97
98 DrawPixelInfo tmp_dpi;
99 /* Position of highlight box */
100 int highlight_l = 0;
101 int highlight_r = 0;
102 int max_width = r.Width();
103
104 if (!FillDrawPixelInfo(&tmp_dpi, r)) return;
105
106 {
107 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
108
109 bool do_overlays = ShowCargoIconOverlay();
110 /* List of overlays, only used if cargo icon overlays are enabled. */
111 static std::vector<CargoIconOverlay> overlays;
112
113 int px = rtl ? max_width + skip : -skip;
114 int y = r.Height() / 2;
115 bool sel_articulated = false;
116 bool dragging = (drag_dest != VehicleID::Invalid());
117 bool drag_at_end_of_train = (drag_dest == v->index); // Head index is used to mark dragging at end of train.
118 for (; v != nullptr && (rtl ? px > 0 : px < max_width); v = v->Next()) {
119 if (dragging && !drag_at_end_of_train && drag_dest == v->index) {
120 /* Highlight the drag-and-drop destination inside the train. */
121 int drag_hlight_width = HighlightDragPosition(px, max_width, y, selection, _cursor.vehchain);
122 px += rtl ? -drag_hlight_width : drag_hlight_width;
123 }
124
125 Point offset;
126 int width = Train::From(v)->GetDisplayImageWidth(&offset);
127
128 if (rtl ? px + width > 0 : px - width < max_width) {
131 v->GetImage(dir, image_type, &seq);
132 seq.Draw(px + (rtl ? -offset.x : offset.x), y + offset.y, pal, v->vehstatus.Test(VehState::Crashed));
133 }
134
135 if (!v->IsArticulatedPart()) sel_articulated = false;
136
137 if (v->index == selection) {
138 /* Set the highlight position */
139 highlight_l = rtl ? px - width : px;
140 highlight_r = rtl ? px - 1 : px + width - 1;
141 sel_articulated = true;
142 } else if ((_cursor.vehchain && highlight_r != 0) || sel_articulated) {
143 if (rtl) {
144 highlight_l -= width;
145 } else {
146 highlight_r += width;
147 }
148 }
149
150 if (do_overlays) AddCargoIconOverlay(overlays, px, width, v);
151 px += rtl ? -width : width;
152 }
153
154 if (do_overlays) {
155 DrawCargoIconOverlays(overlays, y);
156 overlays.clear();
157 }
158
159 if (dragging && drag_at_end_of_train) {
160 /* Highlight the drag-and-drop destination at the end of the train. */
161 HighlightDragPosition(px, max_width, y, selection, _cursor.vehchain);
162 }
163 }
164
165 if (highlight_l != highlight_r) {
166 /* Draw the highlight. Now done after drawing all the engines, as
167 * the next engine after the highlight could overlap it. */
168 int height = ScaleSpriteTrad(12);
169 Rect hr = {highlight_l, 0, highlight_r, height - 1};
170 DrawFrameRect(hr.Translate(r.left, CenterBounds(r.top, r.bottom, height)).Expand(WidgetDimensions::scaled.bevel), COLOUR_WHITE, FrameFlag::BorderOnly);
171 }
172}
173
178 uint capacity;
179 uint amount;
181
183 inline bool operator == (const CargoSummaryItem &other) const
184 {
185 return !(this->cargo != other.cargo);
186 }
187};
188
189static const uint TRAIN_DETAILS_MIN_INDENT = 32;
190static const uint TRAIN_DETAILS_MAX_INDENT = 72;
191
193typedef std::vector<CargoSummaryItem> CargoSummary;
196
205static void TrainDetailsCargoTab(const CargoSummaryItem *item, int left, int right, int y)
206{
207 std::string str;
208 if (!IsValidCargoType(item->cargo)) {
209 str = GetString(STR_QUANTITY_N_A);
210 } else if (item->amount == 0) {
211 str = GetString(STR_VEHICLE_DETAILS_CARGO_EMPTY);
212 } else if (FreightWagonMult(item->cargo) > 1) {
213 str = GetString(STR_VEHICLE_DETAILS_CARGO_FROM_MULT, item->cargo, item->amount, item->source, _settings_game.vehicle.freight_trains);
214 } else {
215 str = GetString(STR_VEHICLE_DETAILS_CARGO_FROM, item->cargo, item->amount, item->source);
216 }
217 DrawString(left, right, y, str, TC_LIGHT_BLUE);
218}
219
228static void TrainDetailsInfoTab(const Vehicle *v, int left, int right, int y)
229{
230 std::string str;
231 if (RailVehInfo(v->engine_type)->railveh_type == RAILVEH_WAGON) {
232 str = GetString(STR_VEHICLE_DETAILS_TRAIN_WAGON_VALUE, PackEngineNameDParam(v->engine_type, EngineNameContext::VehicleDetails), v->value);
233 } else {
234 str = GetString(STR_VEHICLE_DETAILS_TRAIN_ENGINE_BUILT_AND_VALUE, PackEngineNameDParam(v->engine_type, EngineNameContext::VehicleDetails), v->build_year, v->value);
235 }
236 DrawString(left, right, y, str);
237}
238
247static void TrainDetailsCapacityTab(const CargoSummaryItem *item, int left, int right, int y)
248{
249 std::string str;
250 if (!IsValidCargoType(item->cargo)) {
251 /* Draw subtype only */
252 str = GetString(STR_VEHICLE_INFO_NO_CAPACITY, item->subtype);
253 } else if (FreightWagonMult(item->cargo) > 1) {
254 str = GetString(STR_VEHICLE_INFO_CAPACITY_MULT, item->cargo, item->capacity, item->subtype, _settings_game.vehicle.freight_trains);
255 } else {
256 str = GetString(STR_VEHICLE_INFO_CAPACITY, item->cargo, item->capacity, item->subtype);
257 }
258 DrawString(left, right, y, str);
259}
260
267{
268 summary.clear();
269 do {
270 if (!v->GetEngine()->CanCarryCargo()) continue;
271
272 CargoSummaryItem new_item;
273 new_item.cargo = v->cargo_cap > 0 ? v->cargo_type : INVALID_CARGO;
274 new_item.subtype = GetCargoSubtypeText(v);
275 if (!IsValidCargoType(new_item.cargo) && new_item.subtype == STR_EMPTY) continue;
276
277 auto item = std::ranges::find(summary, new_item);
278 if (item == std::end(summary)) {
279 item = summary.emplace(std::end(summary));
280 item->cargo = new_item.cargo;
281 item->subtype = new_item.subtype;
282 item->capacity = 0;
283 item->amount = 0;
284 item->source = StationID::Invalid();
285 }
286
287 item->capacity += v->cargo_cap;
288 item->amount += v->cargo.StoredCount();
289 if (item->source == StationID::Invalid()) item->source = v->cargo.GetFirstStation();
290 } while ((v = v->Next()) != nullptr && v->IsArticulatedPart());
291}
292
299{
300 uint length = 0;
301
302 do {
303 length += v->GetDisplayImageWidth();
304 } while ((v = v->Next()) != nullptr && v->IsArticulatedPart());
305
306 return length;
307}
308
316{
317 int num = 0;
318
319 if (det_tab == TDW_TAB_TOTALS) { // Total cargo tab
320 CargoArray max_cargo{};
321 for (const Vehicle *v = Vehicle::Get(veh_id); v != nullptr; v = v->Next()) {
322 max_cargo[v->cargo_type] += v->cargo_cap;
323 }
324
325 num = max_cargo.GetCount();
326 num++; // needs one more because first line is description string
327 } else {
328 for (const Train *v = Train::Get(veh_id); v != nullptr; v = v->GetNextVehicle()) {
330 num += std::max(1u, (unsigned)_cargo_summary.size());
331
332 uint length = GetLengthOfArticulatedVehicle(v);
333 if (length > (uint)ScaleSpriteTrad(TRAIN_DETAILS_MAX_INDENT)) num++;
334 }
335 }
336
337 return num;
338}
339
349void DrawTrainDetails(const Train *v, const Rect &r, int vscroll_pos, uint16_t vscroll_cap, TrainDetailsWindowTabs det_tab)
350{
351 bool rtl = _current_text_dir == TD_RTL;
352 int line_height = r.Height();
353 int sprite_y_offset = line_height / 2;
354 int text_y_offset = (line_height - GetCharacterHeight(FS_NORMAL)) / 2;
355
356 /* draw the first 3 details tabs */
357 if (det_tab != TDW_TAB_TOTALS) {
358 Direction dir = rtl ? DIR_E : DIR_W;
359 int x = rtl ? r.right : r.left;
360 for (; v != nullptr && vscroll_pos > -vscroll_cap; v = v->GetNextVehicle()) {
362
363 /* Draw sprites */
364 uint dx = 0;
365 int px = x;
366 const Train *u = v;
367 do {
368 Point offset;
369 int width = u->GetDisplayImageWidth(&offset);
370 if (vscroll_pos <= 0 && vscroll_pos > -vscroll_cap) {
371 int pitch = 0;
372 const Engine *e = Engine::Get(v->engine_type);
373 if (e->GetGRF() != nullptr) {
375 }
378 u->GetImage(dir, EIT_IN_DETAILS, &seq);
379 seq.Draw(px + (rtl ? -offset.x : offset.x), r.top - line_height * vscroll_pos + sprite_y_offset + pitch, pal, v->vehstatus.Test(VehState::Crashed));
380 }
381 px += rtl ? -width : width;
382 dx += width;
383 u = u->Next();
384 } while (u != nullptr && u->IsArticulatedPart());
385
386 bool separate_sprite_row = (dx > (uint)ScaleSpriteTrad(TRAIN_DETAILS_MAX_INDENT));
387 if (separate_sprite_row) {
388 vscroll_pos--;
389 dx = 0;
390 }
391
392 int sprite_width = std::max<int>(dx, ScaleSpriteTrad(TRAIN_DETAILS_MIN_INDENT)) + WidgetDimensions::scaled.hsep_normal;
393 Rect dr = r.Indent(sprite_width, rtl);
394 uint num_lines = std::max(1u, (unsigned)_cargo_summary.size());
395 for (uint i = 0; i < num_lines; i++) {
396 if (vscroll_pos <= 0 && vscroll_pos > -vscroll_cap) {
397 int py = r.top - line_height * vscroll_pos + text_y_offset;
398 if (i > 0 || separate_sprite_row) {
399 if (vscroll_pos != 0) GfxFillRect(r.left, py - WidgetDimensions::scaled.matrix.top - 1, r.right, py - WidgetDimensions::scaled.matrix.top, GetColourGradient(COLOUR_GREY, SHADE_LIGHT));
400 }
401 switch (det_tab) {
402 case TDW_TAB_CARGO:
403 if (i < _cargo_summary.size()) {
404 TrainDetailsCargoTab(&_cargo_summary[i], dr.left, dr.right, py);
405 } else {
406 DrawString(dr.left, dr.right, py, STR_QUANTITY_N_A, TC_LIGHT_BLUE);
407 }
408 break;
409
410 case TDW_TAB_INFO:
411 if (i == 0) TrainDetailsInfoTab(v, dr.left, dr.right, py);
412 break;
413
414 case TDW_TAB_CAPACITY:
415 if (i < _cargo_summary.size()) {
416 TrainDetailsCapacityTab(&_cargo_summary[i], dr.left, dr.right, py);
417 } else {
418 DrawString(dr.left, dr.right, py, GetString(STR_VEHICLE_INFO_NO_CAPACITY, STR_EMPTY));
419 }
420 break;
421
422 default: NOT_REACHED();
423 }
424 }
425 vscroll_pos--;
426 }
427 }
428 } else {
429 int y = r.top;
430 CargoArray act_cargo{};
431 CargoArray max_cargo{};
432 Money feeder_share = 0;
433
434 for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
435 act_cargo[u->cargo_type] += u->cargo.StoredCount();
436 max_cargo[u->cargo_type] += u->cargo_cap;
437 feeder_share += u->cargo.GetFeederShare();
438 }
439
440 /* draw total cargo tab */
441 DrawString(r.left, r.right, y + text_y_offset, STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_TEXT);
442 y += line_height;
443
444 /* Indent the total cargo capacity details */
445 Rect ir = r.Indent(WidgetDimensions::scaled.hsep_indent, rtl);
446 for (const CargoSpec *cs : _sorted_cargo_specs) {
447 CargoType cargo_type = cs->Index();
448 if (max_cargo[cargo_type] > 0 && --vscroll_pos < 0 && vscroll_pos > -vscroll_cap) {
449 std::string str;
450 if (FreightWagonMult(cargo_type) > 1) {
451 str = GetString(STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_MULT, cargo_type, act_cargo[cargo_type], cargo_type, max_cargo[cargo_type], _settings_game.vehicle.freight_trains);
452 } else {
453 str = GetString(STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY, cargo_type, act_cargo[cargo_type], cargo_type, max_cargo[cargo_type]);
454 }
455 DrawString(ir.left, ir.right, y + text_y_offset, str);
456 y += line_height;
457 }
458 }
459 DrawString(r.left, r.right, y + text_y_offset, GetString(STR_VEHICLE_INFO_FEEDER_CARGO_VALUE, feeder_share));
460 }
461}
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:23
bool IsValidCargoType(CargoType t)
Test whether cargo type is not INVALID_CARGO.
Definition cargo_type.h:106
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Common return value for all commands.
bool Failed() const
Did this command fail?
StationID GetFirstStation() const
Returns the first station of the first cargo packet in this list.
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:29
RectPadding matrix
Padding of WWT_MATRIX items.
Definition window_gui.h:42
int hsep_normal
Normal horizontal spacing.
Definition window_gui.h:61
RectPadding bevel
Bevel thickness, affected by "scaled bevels" game option.
Definition window_gui.h:38
Functions related to commands.
Commands
List of commands.
Direction
Defines the 8 directions on the map.
@ DIR_W
West.
@ DIR_E
East.
uint64_t PackEngineNameDParam(EngineID engine_id, EngineNameContext context, uint32_t extra_data=0)
Combine an engine ID and a name context to an engine name dparam.
@ VehicleDetails
Name is shown in the vehicle details GUI.
@ RAILVEH_WAGON
simple wagon, not motorized
Definition engine_type.h:33
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:77
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:658
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition gfx.cpp:115
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
Definition gfx.cpp:1519
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition gfx_func.h:166
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:243
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
ClientID
'Unique' identifier to be given to clients
uint8_t GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
Definition palette.cpp:387
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:58
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition sprites.h:1609
Definition of base types and functions in a cross-platform compatible way.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:426
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Class for storing amounts of cargo.
Definition cargo_type.h:113
uint GetCount() const
Get the amount of cargos that have an amount.
Definition cargo_type.h:128
Specification of a cargo type.
Definition cargotype.h:74
Helper struct for the cargo details information.
StringID subtype
STR_EMPTY if none.
bool operator==(const CargoSummaryItem &other) const
Used by std::find() and similar functions.
uint amount
Amount that is carried.
uint capacity
Amount that can be carried.
StationID source
One of the source stations.
CargoType cargo
The cargo that is carried.
bool vehchain
vehicle chain is dragged
Definition gfx_type.h:149
Data about how and where to blit pixels.
Definition gfx_type.h:156
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
bool CanCarryCargo() const
Determines whether an engine can carry something.
Definition engine.cpp:168
int traininfo_vehicle_pitch
Vertical offset for drawing train images in depot GUI and vehicle details.
Definition newgrf.h:151
VehicleSettings vehicle
options for vehicles
Coordinates of a point in 2D.
static Titem * Get(auto index)
Returns Titem with given index.
Tindex index
Index of this pool item.
Specification of a rectangle with absolute coordinates of all edges.
int Width() const
Get width of Rect.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
int Height() const
Get height of Rect.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Rect Expand(int s) const
Copy and expand Rect by s pixels.
T * Next() const
Get next vehicle in the chain.
static Pool::IterateWrapper< T > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
static T * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
T * GetNextVehicle() const
Get the next real (non-articulated part) vehicle in the consist.
static T * Get(auto index)
Gets vehicle with given index.
'Train' is either a loco or a wagon.
Definition train.h:90
void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const override
Get the sprite to display the train.
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a train vehicle image in the GUI.
uint8_t freight_trains
value to multiply the weight of cargo by
Sprite sequence for a vehicle part.
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
Definition vehicle.cpp:131
Vehicle data structure.
EngineID engine_type
The type of engine used for this vehicle.
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
Definition vehicle.cpp:744
VehicleCargoList cargo
The cargo this vehicle is carrying.
uint16_t cargo_cap
total capacity
Vehicle * Last()
Get the last vehicle of this vehicle chain.
VehStates vehstatus
Status.
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
CargoType cargo_type
type of cargo this vehicle is carrying
Vehicle * Next() const
Get the next vehicle of this vehicle.
Money value
Value of the vehicle.
TileIndex tile
Current tile index.
TimerGameCalendar::Year build_year
Year the vehicle has been built.
Base for the train class.
uint8_t FreightWagonMult(CargoType cargo)
Return the cargo weight multiplier to use for a rail vehicle.
Definition train_cmd.cpp:69
Command definitions related to trains.
void DrawTrainImage(const Train *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest)
Draws an image of a whole train.
Definition train_gui.cpp:93
static int HighlightDragPosition(int px, int max_width, int y, VehicleID selection, bool chain)
Highlight the position where a rail vehicle is dragged over by drawing a light gray background.
Definition train_gui.cpp:60
static void TrainDetailsInfoTab(const Vehicle *v, int left, int right, int y)
Draw the details info tab for the given vehicle at the given position.
static void TrainDetailsCapacityTab(const CargoSummaryItem *item, int left, int right, int y)
Draw the details capacity tab for the given vehicle at the given position.
static uint GetLengthOfArticulatedVehicle(const Train *v)
Get the length of an articulated vehicle.
void DrawTrainDetails(const Train *v, const Rect &r, int vscroll_pos, uint16_t vscroll_cap, TrainDetailsWindowTabs det_tab)
Draw the details for the given vehicle at the given position.
static void GetCargoSummaryOfArticulatedVehicle(const Train *v, CargoSummary &summary)
Collects the cargo transported.
static const uint TRAIN_DETAILS_MAX_INDENT
Maximum indent level in the train details window; wider than this and we start on a new line.
std::vector< CargoSummaryItem > CargoSummary
Container for the cargo summary information.
int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
Determines the number of lines in the train details window.
void CcBuildWagon(Commands, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray, TileIndex tile, EngineID, bool, CargoType, ClientID)
Callback for building wagons.
Definition train_gui.cpp:29
static CargoSummary _cargo_summary
Reused container of cargo details.
static const uint TRAIN_DETAILS_MIN_INDENT
Minimum indent level in the train details window.
static void TrainDetailsCargoTab(const CargoSummaryItem *item, int left, int right, int y)
Draw the details cargo tab for the given vehicle at the given position.
PaletteID GetVehiclePalette(const Vehicle *v)
Get the colour map for a vehicle.
Definition vehicle.cpp:2143
@ Crashed
Vehicle is crashed.
Functions related to vehicles.
StringID GetCargoSubtypeText(const Vehicle *v)
Get the cargo subtype text from NewGRF for the vehicle details window.
void DrawCargoIconOverlays(std::span< const CargoIconOverlay > overlays, int y)
Draw a list of cargo icon overlays.
void AddCargoIconOverlay(std::vector< CargoIconOverlay > &overlays, int x, int width, const Vehicle *v)
Add a cargo icon to the list of overlays.
bool ShowCargoIconOverlay()
Test if cargo icon overlays should be drawn.
TrainDetailsWindowTabs
The tabs in the train details window.
Definition vehicle_gui.h:25
@ TDW_TAB_CAPACITY
Tab with cargo capacity of the vehicles.
Definition vehicle_gui.h:28
@ TDW_TAB_TOTALS
Tab with sum of total cargo transported.
Definition vehicle_gui.h:29
@ TDW_TAB_INFO
Tab with name and value of the vehicles.
Definition vehicle_gui.h:27
@ TDW_TAB_CARGO
Tab with cargo carried by the vehicles.
Definition vehicle_gui.h:26
EngineImageType
Visualisation contexts of vehicles and engines.
@ EIT_IN_DETAILS
Vehicle drawn in vehicle details, refit window, ...
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition widget.cpp:296
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition window.cpp:3241
Functions, definitions and such used only by the GUI.
@ BorderOnly
Draw border only, no background.
@ WC_TRAINS_LIST
Trains list; Window numbers:
Functions related to zooming.
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition zoom_func.h:107