OpenTTD Source 20260206-master-g4d4e37dbf1
train_gui.cpp File Reference

GUI for trains. More...

#include "stdafx.h"
#include "window_gui.h"
#include "command_func.h"
#include "train.h"
#include "strings_func.h"
#include "vehicle_func.h"
#include "zoom_func.h"
#include "train_cmd.h"
#include "table/strings.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  CargoSummaryItem
 Helper struct for the cargo details information. More...

Typedefs

typedef std::vector< CargoSummaryItemCargoSummary
 Container for the cargo summary information.

Functions

void CcBuildWagon (Commands, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray, TileIndex tile, EngineID, bool, CargoType, ClientID)
 Callback for building wagons.
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.
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.
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.
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 void GetCargoSummaryOfArticulatedVehicle (const Train *v, CargoSummary &summary)
 Collects the cargo transported.
static uint GetLengthOfArticulatedVehicle (const Train *v)
 Get the length of an articulated vehicle.
int GetTrainDetailsWndVScroll (VehicleID veh_id, TrainDetailsWindowTabs det_tab)
 Determines the number of lines in the train details window.
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.

Variables

static const uint TRAIN_DETAILS_MIN_INDENT = 32
 Minimum indent level in the train details window.
static const uint TRAIN_DETAILS_MAX_INDENT = 72
 Maximum indent level in the train details window; wider than this and we start on a new line.
static CargoSummary _cargo_summary
 Reused container of cargo details.

Detailed Description

GUI for trains.

Definition in file train_gui.cpp.

Typedef Documentation

◆ CargoSummary

typedef std::vector<CargoSummaryItem> CargoSummary

Container for the cargo summary information.

Definition at line 199 of file train_gui.cpp.

Function Documentation

◆ CcBuildWagon()

void CcBuildWagon ( Commands ,
const CommandCost & result,
VehicleID new_veh_id,
uint ,
uint16_t ,
CargoArray ,
TileIndex tile,
EngineID ,
bool ,
CargoType ,
ClientID  )

Callback for building wagons.

Parameters
resultThe result of the command.
new_veh_idID of the ne vehicle.
tileThe tile the command was executed on.

Definition at line 29 of file train_gui.cpp.

References CommandCost::Failed(), SpecializedVehicle< Train, Type >::From(), InvalidateWindowClassesData(), Vehicle::IsFrontEngine(), Vehicle::IsStoppedInDepot(), Vehicle::Last(), Vehicle::tile, VEH_TRAIN, and WC_TRAINS_LIST.

◆ DrawTrainDetails()

◆ DrawTrainImage()

void DrawTrainImage ( const Train * v,
const Rect & r,
VehicleID selection,
EngineImageType image_type,
int skip,
VehicleID drag_dest )

◆ GetCargoSummaryOfArticulatedVehicle()

◆ GetLengthOfArticulatedVehicle()

uint GetLengthOfArticulatedVehicle ( const Train * v)
static

Get the length of an articulated vehicle.

Parameters
vthe vehicle to get the length of.
Returns
the length in pixels.

Definition at line 304 of file train_gui.cpp.

References Train::GetDisplayImageWidth(), Vehicle::IsArticulatedPart(), and SpecializedVehicle< T, Type >::Next().

Referenced by GetTrainDetailsWndVScroll().

◆ GetTrainDetailsWndVScroll()

int GetTrainDetailsWndVScroll ( VehicleID veh_id,
TrainDetailsWindowTabs det_tab )

Determines the number of lines in the train details window.

Parameters
veh_idTrain
det_tabSelected details tab
Returns
Number of line

Definition at line 321 of file train_gui.cpp.

References _cargo_summary, GetCargoSummaryOfArticulatedVehicle(), CargoArray::GetCount(), GetLengthOfArticulatedVehicle(), ScaleSpriteTrad(), TDW_TAB_TOTALS, and TRAIN_DETAILS_MAX_INDENT.

Referenced by VehicleDetailsWindow::OnPaint().

◆ HighlightDragPosition()

int HighlightDragPosition ( int px,
int max_width,
int y,
VehicleID selection,
bool chain )
static

Highlight the position where a rail vehicle is dragged over by drawing a light gray background.

Parameters
pxThe current x position to draw from.
max_widthThe maximum space available to draw.
yThe vertical centre position to draw from.
selectionSelected vehicle that is dragged.
chainWhether a whole chain is dragged.
Returns
The width of the highlight mark.

Definition at line 65 of file train_gui.cpp.

References _current_text_dir, GetColourGradient(), GfxFillRect(), Rect, ScaleSpriteTrad(), Rect::Shrink(), and TD_RTL.

Referenced by DrawTrainImage().

◆ TrainDetailsCapacityTab()

void TrainDetailsCapacityTab ( const CargoSummaryItem * item,
int left,
int right,
int y )
static

Draw the details capacity tab for the given vehicle at the given position.

Parameters
itemData to draw
leftThe left most coordinate to draw
rightThe right most coordinate to draw
yThe y coordinate

Definition at line 253 of file train_gui.cpp.

References _settings_game, CargoSummaryItem::capacity, CargoSummaryItem::cargo, DrawString(), FreightWagonMult(), GetString(), IsValidCargoType(), and CargoSummaryItem::subtype.

Referenced by DrawTrainDetails().

◆ TrainDetailsCargoTab()

void TrainDetailsCargoTab ( const CargoSummaryItem * item,
int left,
int right,
int y )
static

Draw the details cargo tab for the given vehicle at the given position.

Parameters
itemData to draw
leftThe left most coordinate to draw
rightThe right most coordinate to draw
yThe y coordinate

Definition at line 211 of file train_gui.cpp.

References _settings_game, CargoSummaryItem::amount, CargoSummaryItem::cargo, DrawString(), FreightWagonMult(), GetString(), IsValidCargoType(), and CargoSummaryItem::source.

Referenced by DrawTrainDetails().

◆ TrainDetailsInfoTab()

void TrainDetailsInfoTab ( const Vehicle * v,
int left,
int right,
int y )
static

Draw the details info tab for the given vehicle at the given position.

Parameters
vcurrent vehicle
leftThe left most coordinate to draw
rightThe right most coordinate to draw
yThe y coordinate

Definition at line 234 of file train_gui.cpp.

References Vehicle::build_year, DrawString(), Vehicle::engine_type, GetString(), PackEngineNameDParam(), RAILVEH_WAGON, Vehicle::value, and VehicleDetails.

Referenced by DrawTrainDetails().

Variable Documentation

◆ _cargo_summary

CargoSummary _cargo_summary
static

Reused container of cargo details.

Definition at line 201 of file train_gui.cpp.

Referenced by DrawTrainDetails(), and GetTrainDetailsWndVScroll().

◆ TRAIN_DETAILS_MAX_INDENT

const uint TRAIN_DETAILS_MAX_INDENT = 72
static

Maximum indent level in the train details window; wider than this and we start on a new line.

Definition at line 196 of file train_gui.cpp.

Referenced by DrawTrainDetails(), and GetTrainDetailsWndVScroll().

◆ TRAIN_DETAILS_MIN_INDENT

const uint TRAIN_DETAILS_MIN_INDENT = 32
static

Minimum indent level in the train details window.

Definition at line 195 of file train_gui.cpp.

Referenced by DrawTrainDetails().