OpenTTD Source: src/train_gui.cpp Source File

OpenTTD Source 1.11.0-RC1

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
18 #include "table/strings.h"
19
20 #include "safeguards.h"
21
30 void CcBuildWagon(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
31 {
32 if (result.Failed()) return;
33
34 /* find a locomotive in the depot. */
35 const Vehicle *found = nullptr;
36 for (const Train *t : Train::Iterate()) {
37 if (t->IsFrontEngine() && t->tile == tile && t->IsStoppedInDepot()) {
38 if (found != nullptr) return; // must be exactly one.
39 found = t;
40 }
41 }
42
43 /* if we found a loco, */
44 if (found != nullptr) {
45 found = found->Last();
46 /* put the new wagon at the end of the loco. */
47 DoCommandP(0, _new_vehicle_id, found->index, CMD_MOVE_RAIL_VEHICLE);
48 InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
49 }
50 }
51
60 static int HighlightDragPosition(int px, int max_width, VehicleID selection, bool chain)
61 {
62 bool rtl = _current_text_dir == TD_RTL;
63
64 assert(selection != INVALID_VEHICLE);
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 GfxFillRect(drag_hlight_left + WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP + 1,
76 drag_hlight_right - WD_FRAMERECT_RIGHT, ScaleGUITrad(13) - WD_FRAMERECT_BOTTOM, _colour_gradient[COLOUR_GREY][7]);
77 }
78
79 return drag_hlight_width;
80 }
81
92 void DrawTrainImage(const Train *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest)
93 {
94 bool rtl = _current_text_dir == TD_RTL;
95 Direction dir = rtl ? DIR_E : DIR_W;
96
97 DrawPixelInfo tmp_dpi, *old_dpi;
98 /* Position of highlight box */
99 int highlight_l = 0;
100 int highlight_r = 0;
101 int max_width = right - left + 1;
102 int height = ScaleGUITrad(14);
103
104 if (!FillDrawPixelInfo(&tmp_dpi, left, y, max_width, height)) return;
105
106 old_dpi = _cur_dpi;
107 _cur_dpi = &tmp_dpi;
108
109 int px = rtl ? max_width + skip : -skip;
110 bool sel_articulated = false;
111 bool dragging = (drag_dest != INVALID_VEHICLE);
112 bool drag_at_end_of_train = (drag_dest == v->index); // Head index is used to mark dragging at end of train.
113 for (; v != nullptr && (rtl ? px > 0 : px < max_width); v = v->Next()) {
114 if (dragging && !drag_at_end_of_train && drag_dest == v->index) {
115 /* Highlight the drag-and-drop destination inside the train. */
116 int drag_hlight_width = HighlightDragPosition(px, max_width, selection, _cursor.vehchain);
117 px += rtl ? -drag_hlight_width : drag_hlight_width;
118 }
119
120 Point offset;
121 int width = Train::From(v)->GetDisplayImageWidth(&offset);
122
123 if (rtl ? px + width > 0 : px - width < max_width) {
124 PaletteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
125 VehicleSpriteSeq seq;
126 v->GetImage(dir, image_type, &seq);
127 seq.Draw(px + (rtl ? -offset.x : offset.x), height / 2 + offset.y, pal, (v->vehstatus & VS_CRASHED) != 0);
128 }
129
130 if (!v->IsArticulatedPart()) sel_articulated = false;
131
132 if (v->index == selection) {
133 /* Set the highlight position */
134 highlight_l = rtl ? px - width : px;
135 highlight_r = rtl ? px - 1 : px + width - 1;
136 sel_articulated = true;
137 } else if ((_cursor.vehchain && highlight_r != 0) || sel_articulated) {
138 if (rtl) {
139 highlight_l -= width;
140 } else {
141 highlight_r += width;
142 }
143 }
144
145 px += rtl ? -width : width;
146 }
147
148 if (dragging && drag_at_end_of_train) {
149 /* Highlight the drag-and-drop destination at the end of the train. */
150 HighlightDragPosition(px, max_width, selection, _cursor.vehchain);
151 }
152
153 if (highlight_l != highlight_r) {
154 /* Draw the highlight. Now done after drawing all the engines, as
155 * the next engine after the highlight could overlap it. */
156 DrawFrameRect(highlight_l, 0, highlight_r, height - 1, COLOUR_WHITE, FR_BORDERONLY);
157 }
158
159 _cur_dpi = old_dpi;
160 }
161
163 struct CargoSummaryItem {
164 CargoID cargo;
165 StringID subtype;
166 uint capacity;
167 uint amount;
168 StationID source;
169
171 inline bool operator != (const CargoSummaryItem &other) const
172 {
173 return this->cargo != other.cargo || this->subtype != other.subtype;
174 }
175
177 inline bool operator == (const CargoSummaryItem &other) const
178 {
179 return !(this->cargo != other.cargo);
180 }
181 };
182
183 static const uint TRAIN_DETAILS_MIN_INDENT = 32;
184 static const uint TRAIN_DETAILS_MAX_INDENT = 72;
185
187 typedef std::vector<CargoSummaryItem> CargoSummary;
189 static CargoSummary _cargo_summary;
190
199 static void TrainDetailsCargoTab(const CargoSummaryItem *item, int left, int right, int y)
200 {
201 StringID str;
202 if (item->amount > 0) {
203 SetDParam(0, item->cargo);
204 SetDParam(1, item->amount);
205 SetDParam(2, item->source);
206 SetDParam(3, _settings_game.vehicle.freight_trains);
207 str = FreightWagonMult(item->cargo) > 1 ? STR_VEHICLE_DETAILS_CARGO_FROM_MULT : STR_VEHICLE_DETAILS_CARGO_FROM;
208 } else {
209 SetDParam(0, STR_QUANTITY_N_A);
210 str = item->cargo == INVALID_CARGO ? STR_LTBLUE_STRING : STR_VEHICLE_DETAILS_CARGO_EMPTY;
211 }
212
213 DrawString(left, right, y, str);
214 }
215
224 static void TrainDetailsInfoTab(const Vehicle *v, int left, int right, int y)
225 {
226 if (RailVehInfo(v->engine_type)->railveh_type == RAILVEH_WAGON) {
227 SetDParam(0, v->engine_type);
228 SetDParam(1, v->value);
229 DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_WAGON_VALUE);
230 } else {
231 SetDParam(0, v->engine_type);
232 SetDParam(1, v->build_year);
233 SetDParam(2, v->value);
234 DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_ENGINE_BUILT_AND_VALUE);
235 }
236 }
237
246 static void TrainDetailsCapacityTab(const CargoSummaryItem *item, int left, int right, int y)
247 {
248 StringID str;
249 if (item->cargo != INVALID_CARGO) {
250 SetDParam(0, item->cargo);
251 SetDParam(1, item->capacity);
252 SetDParam(4, item->subtype);
253 SetDParam(5, _settings_game.vehicle.freight_trains);
254 str = FreightWagonMult(item->cargo) > 1 ? STR_VEHICLE_INFO_CAPACITY_MULT : STR_VEHICLE_INFO_CAPACITY;
255 } else {
256 /* Draw subtype only */
257 SetDParam(0, item->subtype);
258 str = STR_VEHICLE_INFO_NO_CAPACITY;
259 }
260 DrawString(left, right, y, str);
261 }
262
268 static void GetCargoSummaryOfArticulatedVehicle(const Train *v, CargoSummary *summary)
269 {
270 summary->clear();
271 do {
272 if (!v->GetEngine()->CanCarryCargo()) continue;
273
274 CargoSummaryItem new_item;
275 new_item.cargo = v->cargo_cap > 0 ? v->cargo_type : INVALID_CARGO;
276 new_item.subtype = GetCargoSubtypeText(v);
277 if (new_item.cargo == INVALID_CARGO && new_item.subtype == STR_EMPTY) continue;
278
279 auto item = std::find(summary->begin(), summary->end(), new_item);
280 if (item == summary->end()) {
281 summary->emplace_back();
282 item = summary->end() - 1;
283 item->cargo = new_item.cargo;
284 item->subtype = new_item.subtype;
285 item->capacity = 0;
286 item->amount = 0;
287 item->source = INVALID_STATION;
288 }
289
290 item->capacity += v->cargo_cap;
291 item->amount += v->cargo.StoredCount();
292 if (item->source == INVALID_STATION) item->source = v->cargo.Source();
293 } while ((v = v->Next()) != nullptr && v->IsArticulatedPart());
294 }
295
301 static uint GetLengthOfArticulatedVehicle(const Train *v)
302 {
303 uint length = 0;
304
305 do {
306 length += v->GetDisplayImageWidth();
307 } while ((v = v->Next()) != nullptr && v->IsArticulatedPart());
308
309 return length;
310 }
311
318 int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
319 {
320 int num = 0;
321
322 if (det_tab == TDW_TAB_TOTALS) { // Total cargo tab
323 CargoArray act_cargo;
324 CargoArray max_cargo;
325 for (const Vehicle *v = Vehicle::Get(veh_id); v != nullptr; v = v->Next()) {
326 act_cargo[v->cargo_type] += v->cargo.StoredCount();
327 max_cargo[v->cargo_type] += v->cargo_cap;
328 }
329
330 /* Set scroll-amount separately from counting, as to not compute num double
331 * for more carriages of the same type
332 */
333 for (CargoID i = 0; i < NUM_CARGO; i++) {
334 if (max_cargo[i] > 0) num++; // only count carriages that the train has
335 }
336 num++; // needs one more because first line is description string
337 } else {
338 for (const Train *v = Train::Get(veh_id); v != nullptr; v = v->GetNextVehicle()) {
339 GetCargoSummaryOfArticulatedVehicle(v, &_cargo_summary);
340 num += std::max(1u, (unsigned)_cargo_summary.size());
341
342 uint length = GetLengthOfArticulatedVehicle(v);
343 if (length > TRAIN_DETAILS_MAX_INDENT) num++;
344 }
345 }
346
347 return num;
348 }
349
361 void DrawTrainDetails(const Train *v, int left, int right, int y, int vscroll_pos, uint16 vscroll_cap, TrainDetailsWindowTabs det_tab)
362 {
363 /* get rid of awkward offset */
364 y -= WD_MATRIX_TOP;
365
366 int sprite_height = ScaleGUITrad(GetVehicleHeight(VEH_TRAIN));
367 int line_height = std::max(sprite_height, WD_MATRIX_TOP + FONT_HEIGHT_NORMAL + WD_MATRIX_BOTTOM);
368 int sprite_y_offset = line_height / 2;
369 int text_y_offset = (line_height - FONT_HEIGHT_NORMAL) / 2;
370
371 /* draw the first 3 details tabs */
372 if (det_tab != TDW_TAB_TOTALS) {
373 bool rtl = _current_text_dir == TD_RTL;
374 Direction dir = rtl ? DIR_E : DIR_W;
375 int x = rtl ? right : left;
376 for (; v != nullptr && vscroll_pos > -vscroll_cap; v = v->GetNextVehicle()) {
377 GetCargoSummaryOfArticulatedVehicle(v, &_cargo_summary);
378
379 /* Draw sprites */
380 uint dx = 0;
381 int px = x;
382 const Train *u = v;
383 do {
384 Point offset;
385 int width = u->GetDisplayImageWidth(&offset);
386 if (vscroll_pos <= 0 && vscroll_pos > -vscroll_cap) {
387 int pitch = 0;
388 const Engine *e = Engine::Get(v->engine_type);
389 if (e->GetGRF() != nullptr) {
390 pitch = ScaleGUITrad(e->GetGRF()->traininfo_vehicle_pitch);
391 }
392 PaletteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
393 VehicleSpriteSeq seq;
394 u->GetImage(dir, EIT_IN_DETAILS, &seq);
395 seq.Draw(px + (rtl ? -offset.x : offset.x), y - line_height * vscroll_pos + sprite_y_offset + pitch, pal, (v->vehstatus & VS_CRASHED) != 0);
396 }
397 px += rtl ? -width : width;
398 dx += width;
399 u = u->Next();
400 } while (u != nullptr && u->IsArticulatedPart());
401
402 bool separate_sprite_row = (dx > (uint)ScaleGUITrad(TRAIN_DETAILS_MAX_INDENT));
403 if (separate_sprite_row) {
404 vscroll_pos--;
405 dx = 0;
406 }
407
408 uint num_lines = std::max(1u, (unsigned)_cargo_summary.size());
409 for (uint i = 0; i < num_lines; i++) {
410 int sprite_width = std::max<int>(dx, ScaleGUITrad(TRAIN_DETAILS_MIN_INDENT)) + 3;
411 int data_left = left + (rtl ? 0 : sprite_width);
412 int data_right = right - (rtl ? sprite_width : 0);
413 if (vscroll_pos <= 0 && vscroll_pos > -vscroll_cap) {
414 int py = y - line_height * vscroll_pos + text_y_offset;
415 if (i > 0 || separate_sprite_row) {
416 if (vscroll_pos != 0) GfxFillRect(left, py - WD_MATRIX_TOP - 1, right, py - WD_MATRIX_TOP, _colour_gradient[COLOUR_GREY][5]);
417 }
418 switch (det_tab) {
419 case TDW_TAB_CARGO:
420 if (i < _cargo_summary.size()) {
421 TrainDetailsCargoTab(&_cargo_summary[i], data_left, data_right, py);
422 } else {
423 DrawString(data_left, data_right, py, STR_QUANTITY_N_A, TC_LIGHT_BLUE);
424 }
425 break;
426
427 case TDW_TAB_INFO:
428 if (i == 0) TrainDetailsInfoTab(v, data_left, data_right, py);
429 break;
430
431 case TDW_TAB_CAPACITY:
432 if (i < _cargo_summary.size()) {
433 TrainDetailsCapacityTab(&_cargo_summary[i], data_left, data_right, py);
434 } else {
435 SetDParam(0, STR_EMPTY);
436 DrawString(data_left, data_right, py, STR_VEHICLE_INFO_NO_CAPACITY);
437 }
438 break;
439
440 default: NOT_REACHED();
441 }
442 }
443 vscroll_pos--;
444 }
445 }
446 } else {
447 CargoArray act_cargo;
448 CargoArray max_cargo;
449 Money feeder_share = 0;
450
451 for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
452 act_cargo[u->cargo_type] += u->cargo.StoredCount();
453 max_cargo[u->cargo_type] += u->cargo_cap;
454 feeder_share += u->cargo.FeederShare();
455 }
456
457 /* draw total cargo tab */
458 DrawString(left, right, y + text_y_offset, STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_TEXT);
459 y += line_height;
460
461 for (CargoID i = 0; i < NUM_CARGO; i++) {
462 if (max_cargo[i] > 0 && --vscroll_pos < 0 && vscroll_pos > -vscroll_cap) {
463 SetDParam(0, i); // {CARGO} #1
464 SetDParam(1, act_cargo[i]); // {CARGO} #2
465 SetDParam(2, i); // {SHORTCARGO} #1
466 SetDParam(3, max_cargo[i]); // {SHORTCARGO} #2
467 SetDParam(4, _settings_game.vehicle.freight_trains);
468 DrawString(left, right, y + text_y_offset, FreightWagonMult(i) > 1 ? STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_MULT : STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY);
469 y += line_height;
470 }
471 }
472 SetDParam(0, feeder_share);
473 DrawString(left, right, y + text_y_offset, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);
474 }
475 }
Train::GetDisplayImageWidth
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a train vehicle image in the GUI.
Definition: train_cmd.cpp:432
SpecializedVehicle::GetNextVehicle
T * GetNextVehicle() const
Get the next real (non-articulated part) vehicle in the consist.
Definition: vehicle_base.h:1121
Train::GetImage
void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
Get the sprite to display the train.
Definition: train_cmd.cpp:462
INVALID_CARGO
static const byte INVALID_CARGO
Constant representing invalid cargo.
Definition: cargotype.h:52
WD_FRAMERECT_TOP
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:62
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
VehicleCargoList::StoredCount
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
Definition: cargopacket.h:351
GetCargoSummaryOfArticulatedVehicle
static void GetCargoSummaryOfArticulatedVehicle(const Train *v, CargoSummary *summary)
Collects the cargo transported.
Definition: train_gui.cpp:268
Pool::PoolItem<&_vehicle_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:329
Direction
Direction
Defines the 8 directions on the map.
Definition: direction_type.h:24
TDW_TAB_INFO
@ TDW_TAB_INFO
Tab with name and value of the vehicles.
Definition: vehicle_gui.h:25
Vehicle::value
Money value
Value of the vehicle.
Definition: vehicle_base.h:251
CMD_MOVE_RAIL_VEHICLE
@ CMD_MOVE_RAIL_VEHICLE
move a rail vehicle (in the depot)
Definition: command_type.h:220
train.h
command_func.h
SpecializedVehicle::Next
T * Next() const
Get next vehicle in the chain.
Definition: vehicle_base.h:1077
WD_MATRIX_TOP
@ WD_MATRIX_TOP
Offset at top of a matrix cell.
Definition: window_gui.h:78
TrainDetailsWindowTabs
TrainDetailsWindowTabs
The tabs in the train details window.
Definition: vehicle_gui.h:23
CursorVars::vehchain
bool vehchain
vehicle chain is dragged
Definition: gfx_type.h:144
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:326
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:227
CargoArray
Class for storing amounts of cargo.
Definition: cargo_type.h:81
zoom_func.h
EIT_IN_DETAILS
@ EIT_IN_DETAILS
Vehicle drawn in vehicle details, refit window, ...
Definition: vehicle_type.h:88
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:640
DIR_W
@ DIR_W
West.
Definition: direction_type.h:32
EngineImageType
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:85
Engine
Definition: engine_base.h:21
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:222
TrainDetailsCapacityTab
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.
Definition: train_gui.cpp:246
VehicleSpriteSeq::Draw
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
Definition: vehicle.cpp:126
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:52
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:199
TRAIN_DETAILS_MIN_INDENT
static const uint TRAIN_DETAILS_MIN_INDENT
Minimum indent level in the train details window.
Definition: train_gui.cpp:183
Vehicle::IsArticulatedPart
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
Definition: vehicle_base.h:904
CargoSummaryItem::capacity
uint capacity
Amount that can be carried.
Definition: train_gui.cpp:166
TDW_TAB_TOTALS
@ TDW_TAB_TOTALS
Tab with sum of total cargo transported.
Definition: vehicle_gui.h:27
Engine::GetGRF
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
Definition: engine_base.h:138
GRFFile::traininfo_vehicle_pitch
int traininfo_vehicle_pitch
Vertical offset for drawing train images in depot GUI and vehicle details.
Definition: newgrf.h:142
window_gui.h
CargoSummary
std::vector< CargoSummaryItem > CargoSummary
Container for the cargo summary information.
Definition: train_gui.cpp:187
CargoSummaryItem::source
StationID source
One of the source stations.
Definition: train_gui.cpp:168
GetVehicleHeight
static uint GetVehicleHeight(VehicleType type)
Get the height of a single vehicle in the GUIs.
Definition: vehicle_gui.h:68
CommandCost
Common return value for all commands.
Definition: command_type.h:23
DoCommandP
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:541
DIR_E
@ DIR_E
East.
Definition: direction_type.h:28
DrawTrainDetails
void DrawTrainDetails(const Train *v, int left, int right, int y, int vscroll_pos, uint16 vscroll_cap, TrainDetailsWindowTabs det_tab)
Draw the details for the given vehicle at the given position.
Definition: train_gui.cpp:361
INVALID_VEHICLE
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
Definition: vehicle_type.h:55
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:297
WD_FRAMERECT_LEFT
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:60
VS_CRASHED
@ VS_CRASHED
Vehicle is crashed.
Definition: vehicle_base.h:37
VehicleSpriteSeq
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:128
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:61
Vehicle::cargo
VehicleCargoList cargo
The cargo this vehicle is carrying.
Definition: vehicle_base.h:318
DrawTrainImage
void DrawTrainImage(const Train *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest)
Draws an image of a whole train.
Definition: train_gui.cpp:92
WD_FRAMERECT_BOTTOM
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:63
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:159
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:80
SpecializedVehicle< Train, Type >::Get
static Train * Get(size_t index)
Gets vehicle with given index.
Definition: vehicle_base.h:1143
_cargo_summary
static CargoSummary _cargo_summary
Reused container of cargo details.
Definition: train_gui.cpp:189
Vehicle::GetEngine
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
Definition: vehicle.cpp:741
safeguards.h
Train
'Train' is either a loco or a wagon.
Definition: train.h:85
TRAIN_DETAILS_MAX_INDENT
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.
Definition: train_gui.cpp:184
TrainDetailsInfoTab
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.
Definition: train_gui.cpp:224
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
WC_TRAINS_LIST
@ WC_TRAINS_LIST
Trains list; Window numbers:
Definition: window_type.h:301
stdafx.h
GfxFillRect
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:114
CcBuildWagon
void CcBuildWagon(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Callback for building wagons.
Definition: train_gui.cpp:30
RAILVEH_WAGON
@ RAILVEH_WAGON
simple wagon, not motorized
Definition: engine_type.h:29
FillDrawPixelInfo
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:1616
GetCargoSubtypeText
StringID GetCargoSubtypeText(const Vehicle *v)
Get the cargo subtype text from NewGRF for the vehicle details window.
Definition: vehicle_gui.cpp:1152
HighlightDragPosition
static int HighlightDragPosition(int px, int max_width, 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
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
vehicle_func.h
CargoSummaryItem
Helper struct for the cargo details information.
Definition: train_gui.cpp:163
PALETTE_CRASH
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition: sprites.h:1594
strings_func.h
CargoSummaryItem::cargo
CargoID cargo
The cargo that is carried.
Definition: train_gui.cpp:164
TrainDetailsCargoTab
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.
Definition: train_gui.cpp:199
Vehicle::cargo_cap
uint16 cargo_cap
total capacity
Definition: vehicle_base.h:316
Engine::CanCarryCargo
bool CanCarryCargo() const
Determines whether an engine can carry something.
Definition: engine.cpp:169
TDW_TAB_CAPACITY
@ TDW_TAB_CAPACITY
Tab with cargo capacity of the vehicles.
Definition: vehicle_gui.h:26
SpecializedVehicle< Train, Type >::From
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1162
GetVehiclePalette
PaletteID GetVehiclePalette(const Vehicle *v)
Get the colour map for a vehicle.
Definition: vehicle.cpp:2041
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:179
ScaleGUITrad
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:76
PaletteID
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
InvalidateWindowClassesData
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:3339
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:64
Vehicle::build_year
Year build_year
Year the vehicle has been built.
Definition: vehicle_base.h:267
CargoSummaryItem::operator!=
bool operator!=(const CargoSummaryItem &other) const
Used by CargoSummary::Find() and similar functions.
Definition: train_gui.cpp:171
VehicleCargoList::Source
StationID Source() const
Returns source of the first cargo packet in this list.
Definition: cargopacket.h:322
SpecializedVehicle< Train, Type >::Iterate
static Pool::IterateWrapper< Train > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
Definition: vehicle_base.h:1231
Vehicle::Last
Vehicle * Last()
Get the last vehicle of this vehicle chain.
Definition: vehicle_base.h:611
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:175
WD_MATRIX_BOTTOM
@ WD_MATRIX_BOTTOM
Offset at bottom of a matrix cell.
Definition: window_gui.h:79
CargoSummaryItem::amount
uint amount
Amount that is carried.
Definition: train_gui.cpp:167
OverflowSafeInt< int64, INT64_MAX, INT64_MIN >
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
CargoSummaryItem::operator==
bool operator==(const CargoSummaryItem &other) const
Used by std::find() and similar functions.
Definition: train_gui.cpp:177
Vehicle::cargo_type
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:314
GetLengthOfArticulatedVehicle
static uint GetLengthOfArticulatedVehicle(const Train *v)
Get the length of an articulated vehicle.
Definition: train_gui.cpp:301
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition: settings_type.h:568
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
CargoSummaryItem::subtype
StringID subtype
STR_EMPTY if none.
Definition: train_gui.cpp:165
GetTrainDetailsWndVScroll
int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
Determines the number of lines in the train details window.
Definition: train_gui.cpp:318
VehicleSettings::freight_trains
uint8 freight_trains
value to multiply the weight of cargo by
Definition: settings_type.h:473
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:28
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:155
TDW_TAB_CARGO
@ TDW_TAB_CARGO
Tab with cargo carried by the vehicles.
Definition: vehicle_gui.h:24
FreightWagonMult
byte FreightWagonMult(CargoID cargo)
Return the cargo weight multiplier to use for a rail vehicle.
Definition: train_cmd.cpp:65