OpenTTD Source 20260206-master-g4d4e37dbf1
vehicle_gui.h File Reference

Functions related to the vehicle's GUIs. More...

#include "window_type.h"
#include "vehicle_type.h"
#include "vehicle_gui_base.h"
#include "vehiclelist.h"
#include "order_type.h"
#include "station_type.h"
#include "engine_type.h"
#include "company_type.h"

Go to the source code of this file.

Data Structures

struct  TestedEngineDetails
 Extra information about refitted cargo and capacity. More...
struct  VehicleCellSize
 Dimensions of a cell in the purchase/depot windows. More...

Enumerations

enum  TrainDetailsWindowTabs : uint8_t { TDW_TAB_CARGO = 0 , TDW_TAB_INFO , TDW_TAB_CAPACITY , TDW_TAB_TOTALS }
 The tabs in the train details window. More...
enum  VehicleInvalidateWindowData : int { VIWD_REMOVE_ALL_ORDERS = -1 , VIWD_MODIFY_ORDERS = -2 , VIWD_CONSIST_CHANGED = -3 , VIWD_AUTOREPLACE = -4 }
 Special values for vehicle-related windows for the data parameter of InvalidateWindowData. More...

Functions

void ShowVehicleRefitWindow (const Vehicle *v, VehicleOrderID order, Window *parent, bool auto_refit=false)
 Show the refit window for a vehicle.
int DrawVehiclePurchaseInfo (int left, int right, int y, EngineID engine_number, TestedEngineDetails &te)
 Draw the purchase info details of a vehicle at a given location.
void DrawTrainImage (const Train *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest=VehicleID::Invalid())
 Draws an image of a whole train.
void DrawRoadVehImage (const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip=0)
 Draws an image of a road vehicle chain.
void DrawShipImage (const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type)
 Draws an image of a ship.
void DrawAircraftImage (const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type)
 Draws an image of an aircraft.
void ShowBuildVehicleWindow (TileIndex tile, VehicleType type)
uint ShowRefitOptionsList (int left, int right, int y, EngineID engine)
 Display list of cargo types of the engine, for the purchase information window.
StringID GetCargoSubtypeText (const Vehicle *v)
 Get the cargo subtype text from NewGRF for the vehicle details window.
void ShowVehicleListWindow (const Vehicle *v)
void ShowVehicleListWindow (CompanyID company, VehicleType vehicle_type)
void ShowVehicleListWindow (CompanyID company, VehicleType vehicle_type, StationID station)
void ShowVehicleListWindow (CompanyID company, VehicleType vehicle_type, TileIndex depot_tile)
uint GetVehicleHeight (VehicleType type)
 Get the height of a single vehicle in the GUIs.
int GetSingleVehicleWidth (const Vehicle *v, EngineImageType image_type)
 Get the width of a vehicle (part) in pixels.
int GetVehicleWidth (const Vehicle *v, EngineImageType image_type)
 Get the width of a vehicle (including all parts of the consist) in pixels.
VehicleCellSize GetVehicleImageCellSize (VehicleType type, EngineImageType image_type)
 Get the GUI cell size for a vehicle image.
WindowClass GetWindowClassForVehicleType (VehicleType vt)
 Get WindowClass for vehicle list of given vehicle type.
void ShowVehicleViewWindow (const Vehicle *v)
 Shows the vehicle view window of the given vehicle.
bool VehicleClicked (const Vehicle *v)
 Dispatch a "vehicle selected" event if any window waits for it.
bool VehicleClicked (VehicleList::const_iterator begin, VehicleList::const_iterator end)
 Dispatch a "vehicle group selected" event if any window waits for it.
bool VehicleClicked (const GUIVehicleGroup &vehgroup)
 Dispatch a "vehicle group selected" event if any window waits for it.
void StartStopVehicle (const Vehicle *v, bool texteffect)
 Executes Commands::StartStopVehicle for given vehicle.
VehicleCheckClickOnVehicle (const struct Viewport &vp, int x, int y)
void StopGlobalFollowVehicle (const Vehicle *v)
void DrawVehicleImage (const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip)
 Draws an image of a vehicle chain.
void SetMouseCursorVehicle (const Vehicle *v, EngineImageType image_type)
 Set the mouse cursor to look like a vehicle.

Detailed Description

Functions related to the vehicle's GUIs.

Definition in file vehicle_gui.h.

Enumeration Type Documentation

◆ TrainDetailsWindowTabs

enum TrainDetailsWindowTabs : uint8_t

The tabs in the train details window.

Enumerator
TDW_TAB_CARGO 

Tab with cargo carried by the vehicles.

TDW_TAB_INFO 

Tab with name and value of the vehicles.

TDW_TAB_CAPACITY 

Tab with cargo capacity of the vehicles.

TDW_TAB_TOTALS 

Tab with sum of total cargo transported.

Definition at line 25 of file vehicle_gui.h.

◆ VehicleInvalidateWindowData

Special values for vehicle-related windows for the data parameter of InvalidateWindowData.

Enumerator
VIWD_REMOVE_ALL_ORDERS 

Removed / replaced all orders (after deleting / sharing).

VIWD_MODIFY_ORDERS 

Other order modifications.

VIWD_CONSIST_CHANGED 

Vehicle composition was changed.

VIWD_AUTOREPLACE 

Autoreplace replaced the vehicle.

Definition at line 34 of file vehicle_gui.h.

Function Documentation

◆ DrawAircraftImage()

◆ DrawRoadVehImage()

◆ DrawShipImage()

void DrawShipImage ( const Vehicle * v,
const Rect & r,
VehicleID selection,
EngineImageType image_type )

Draws an image of a ship.

Parameters
vFront vehicle
rRect to draw at
selectionSelected vehicle to draw a frame around
image_typeContext where the image is being drawn.

Definition at line 30 of file ship_gui.cpp.

References _current_text_dir, BorderOnly, Vehicle::cargo_cap, Vehicle::cargo_type, CentreBounds(), DIR_E, DIR_W, VehicleSpriteSeq::Draw(), DrawCargoIconOverlay(), DrawFrameRect(), Rect::Expand(), VehicleSpriteSeq::GetBounds(), Vehicle::GetImage(), GetVehiclePalette(), Rect::Height(), Rect, WidgetDimensions::scaled, ScaleSpriteTrad(), TD_RTL, UnScaleGUI(), and Rect::Width().

Referenced by DrawVehicleImage(), and DepotWindow::DrawVehicleInDepot().

◆ DrawTrainImage()

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

◆ DrawVehicleImage()

void DrawVehicleImage ( const Vehicle * v,
const Rect & r,
VehicleID selection,
EngineImageType image_type,
int skip )

Draws an image of a vehicle chain.

Parameters
vFront vehicle
rRect to draw at
selectionSelected vehicle to draw a frame around
image_typeContext where the image is being drawn.
skipNumber of pixels to skip at the front (for scrolling)

Definition at line 1711 of file vehicle_gui.cpp.

References DrawAircraftImage(), DrawRoadVehImage(), DrawShipImage(), DrawTrainImage(), SpecializedVehicle< Train, Type >::From(), Rect, BaseVehicle::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

Referenced by NewGRFInspectWindow::DrawVehicleChainWidget(), BaseVehicleListWindow::DrawVehicleListItems(), RefitWindow::DrawWidget(), and VehicleDetailsWindow::DrawWidget().

◆ DrawVehiclePurchaseInfo()

int DrawVehiclePurchaseInfo ( int left,
int right,
int y,
EngineID engine_number,
TestedEngineDetails & te )

Draw the purchase info details of a vehicle at a given location.

Parameters
left,right,ylocation where to draw the info
engine_numberthe engine of which to draw the info of
teExtra information about refits and capacities.
Returns
y after drawing all the text

Definition at line 880 of file build_vehicle_gui.cpp.

References _settings_client, TimerGameCalendar::ConvertDateToYMD(), TimerGame< struct Calendar >::DateToYear(), DrawAircraftPurchaseInfo(), DrawBadgeNameList(), DrawString(), FS_NORMAL, GetCharacterHeight(), GetGRFConfig(), Engine::GetGRFID(), Engine::GetLifeLengthInDays(), GRFConfig::GetName(), GetString(), Engine::intro_date, IsArticulatedVehicleRefittable(), RAILVEH_WAGON, Engine::reliability, ShowAdditionalText(), ShowRefitOptionsList(), ToPercent16(), Engine::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

Referenced by BuildVehicleWindow::OnPaint(), and ReplaceVehicleWindow::OnPaint().

◆ GetCargoSubtypeText()

◆ GetSingleVehicleWidth()

int GetSingleVehicleWidth ( const Vehicle * v,
EngineImageType image_type )

◆ GetVehicleHeight()

uint GetVehicleHeight ( VehicleType type)
inline

Get the height of a single vehicle in the GUIs.

Parameters
typethe vehicle type to look at
Returns
the height

Definition at line 74 of file vehicle_gui.h.

References VEH_ROAD, and VEH_TRAIN.

Referenced by VehicleDetailsWindow::DrawWidget(), GetVehicleListHeight(), and RefitWindow::UpdateWidgetSize().

◆ GetVehicleImageCellSize()

VehicleCellSize GetVehicleImageCellSize ( VehicleType type,
EngineImageType image_type )

Get the GUI cell size for a vehicle image.

Parameters
typeVehicle type to get the size for.
image_typeImage type to get size for.
Precondition
image_type == EIT_IN_DEPOT || image_type == EIT_PURCHASE
Returns
Cell dimensions for the vehicle and image type.

Definition at line 162 of file depot_gui.cpp.

References _base_block_sizes_depot, _base_block_sizes_purchase, EIT_IN_DEPOT, and EIT_PURCHASE.

Referenced by DrawEngineList(), NewGRFInspectWindow::DrawVehicleChainWidget(), GetEngineListHeight(), DepotWindow::OnInit(), BuildVehicleWindow::UpdateWidgetSize(), and NewGRFInspectWindow::UpdateWidgetSize().

◆ GetVehicleWidth()

int GetVehicleWidth ( const Vehicle * v,
EngineImageType image_type )

Get the width of a vehicle (including all parts of the consist) in pixels.

Parameters
vVehicle to get the width for.
image_typeContext where the image is being drawn.
Returns
Width of the vehicle.

Definition at line 3543 of file vehicle_gui.cpp.

References GetSingleVehicleWidth(), SpecializedVehicle< T, Type >::Next(), BaseVehicle::type, VEH_ROAD, and VEH_TRAIN.

Referenced by RefitWindow::OnInvalidateData(), and RefitWindow::OnResize().

◆ GetWindowClassForVehicleType()

◆ SetMouseCursorVehicle()

◆ ShowBuildVehicleWindow()

void ShowBuildVehicleWindow ( TileIndex tile,
VehicleType type )

Definition at line 1980 of file build_vehicle_gui.cpp.

◆ ShowRefitOptionsList()

uint ShowRefitOptionsList ( int left,
int right,
int y,
EngineID engine )

Display list of cargo types of the engine, for the purchase information window.

Definition at line 1358 of file vehicle_gui.cpp.

References _cargo_mask, CountBits(), DrawStringMultiLine(), GetString(), GetUnionOfArticulatedRefitMasks(), and HasAtMostOneBit().

Referenced by DrawVehiclePurchaseInfo().

◆ ShowVehicleListWindow() [1/4]

void ShowVehicleListWindow ( CompanyID company,
VehicleType vehicle_type )

Definition at line 2290 of file vehicle_gui.cpp.

◆ ShowVehicleListWindow() [2/4]

void ShowVehicleListWindow ( CompanyID company,
VehicleType vehicle_type,
StationID station )

Definition at line 2309 of file vehicle_gui.cpp.

◆ ShowVehicleListWindow() [3/4]

void ShowVehicleListWindow ( CompanyID company,
VehicleType vehicle_type,
TileIndex depot_tile )

Definition at line 2314 of file vehicle_gui.cpp.

◆ ShowVehicleListWindow() [4/4]

void ShowVehicleListWindow ( const Vehicle * v)

Definition at line 2304 of file vehicle_gui.cpp.

◆ ShowVehicleRefitWindow()

void ShowVehicleRefitWindow ( const Vehicle * v,
VehicleOrderID order,
Window * parent,
bool auto_refit )

Show the refit window for a vehicle.

Parameters
*vThe vehicle to show the refit window for
orderof the vehicle to assign refit to, or INVALID_VEH_ORDER_ID to refit the vehicle now
parentthe parent window of the refit window
auto_refitChoose cargo for auto-refitting

Definition at line 1350 of file vehicle_gui.cpp.

References CloseWindowById(), Window::parent, and WC_VEHICLE_REFIT.

Referenced by VehicleViewWindow::OnClick(), and OrdersWindow::OrderClick_Refit().

◆ ShowVehicleViewWindow()

void ShowVehicleViewWindow ( const Vehicle * v)

◆ StartStopVehicle()

void StartStopVehicle ( const Vehicle * v,
bool texteffect )

Executes Commands::StartStopVehicle for given vehicle.

Parameters
vVehicle to start/stop
texteffectShould a texteffect be shown?

Definition at line 2939 of file vehicle_gui.cpp.

References _vehicle_msg_translation_table, CcStartStopVehicle(), Vehicle::IsPrimaryVehicle(), Vehicle::tile, and BaseVehicle::type.

Referenced by DepotWindow::DepotClick(), and VehicleViewWindow::OnClick().

◆ StopGlobalFollowVehicle()

void StopGlobalFollowVehicle ( const Vehicle * v)

Definition at line 3489 of file vehicle_gui.cpp.

◆ VehicleClicked() [1/3]

bool VehicleClicked ( const GUIVehicleGroup & vehgroup)

Dispatch a "vehicle group selected" event if any window waits for it.

Parameters
vehgroupthe GUIVehicleGroup representing the vehicle group
Returns
did any window accept vehicle group selection?

Definition at line 3484 of file vehicle_gui.cpp.

References VehicleClicked(), GUIVehicleGroup::vehicles_begin, and GUIVehicleGroup::vehicles_end.

◆ VehicleClicked() [2/3]

bool VehicleClicked ( const Vehicle * v)

Dispatch a "vehicle selected" event if any window waits for it.

Parameters
vselected vehicle;
Returns
did any window accept vehicle selection?

Definition at line 3451 of file vehicle_gui.cpp.

References Vehicle::First(), HT_VEHICLE, and Vehicle::IsPrimaryVehicle().

Referenced by DepotWindow::DepotClick(), VehicleGroupWindow::OnClick(), VehicleListWindow::OnClick(), and VehicleClicked().

◆ VehicleClicked() [3/3]

bool VehicleClicked ( VehicleList::const_iterator begin,
VehicleList::const_iterator end )

Dispatch a "vehicle group selected" event if any window waits for it.

Parameters
beginiterator to the start of the range of vehicles
enditerator to the end of the range of vehicles
Returns
did any window accept vehicle group selection?

Definition at line 3468 of file vehicle_gui.cpp.

References HT_VEHICLE.