OpenTTD Source  20241108-master-g80f628063a
vehicle_gui.cpp File Reference

The base GUI for all vehicles. More...

#include "stdafx.h"
#include "debug.h"
#include "company_func.h"
#include "gui.h"
#include "textbuf_gui.h"
#include "command_func.h"
#include "vehicle_gui_base.h"
#include "viewport_func.h"
#include "newgrf_text.h"
#include "newgrf_debug.h"
#include "roadveh.h"
#include "train.h"
#include "aircraft.h"
#include "depot_map.h"
#include "group_gui.h"
#include "strings_func.h"
#include "vehicle_func.h"
#include "autoreplace_gui.h"
#include "string_func.h"
#include "dropdown_type.h"
#include "dropdown_func.h"
#include "timetable.h"
#include "articulated_vehicles.h"
#include "spritecache.h"
#include "core/geometry_func.hpp"
#include "core/container_func.hpp"
#include "company_base.h"
#include "engine_func.h"
#include "station_base.h"
#include "tilehighlight_func.h"
#include "zoom_func.h"
#include "depot_cmd.h"
#include "vehicle_cmd.h"
#include "order_cmd.h"
#include "roadveh_cmd.h"
#include "train_cmd.h"
#include "hotkeys.h"
#include "group_cmd.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  RefitOption
 Option to refit a vehicle chain. More...
 
struct  RefitWindow
 Refit cargo window. More...
 
struct  VehicleListWindow
 Window for the (old) vehicle listing. More...
 
struct  VehicleDetailsWindow
 Class for managing the vehicle details window. More...
 
struct  VehicleViewWindow
 Window manager class for viewing a vehicle. More...
 

Typedefs

using RefitOptions = std::map< CargoID, std::vector< RefitOption >, CargoIDComparator >
 Available refit options (subtype and string) associated with each cargo type.
 

Enumerations

enum  VehicleCommandTranslation { VCT_CMD_START_STOP = 0 , VCT_CMD_CLONE_VEH , VCT_CMD_TURN_AROUND }
 Command indices for the _vehicle_command_translation_table.
 

Functions

template<BaseVehicleListWindow::VehicleIndividualSortFunction func>
static bool VehicleIndividualToGroupSorterWrapper (GUIVehicleGroup const &a, GUIVehicleGroup const &b)
 Wrapper to convert a VehicleIndividualSortFunction to a VehicleGroupSortFunction.
 
uint CountDigitsForAllocatingSpace (uint number)
 Get the number of digits of space required for the given number. More...
 
uint GetUnitNumberDigits (VehicleList &vehicles)
 Get the number of digits the biggest unit number of a set of vehicles has. More...
 
static bool CargoFilterSingle (const Vehicle *v, const CargoID cid)
 Check whether a single vehicle should pass the filter. More...
 
static bool CargoFilter (const GUIVehicleGroup *vehgroup, const CargoID cid)
 Check whether a vehicle can carry a specific cargo. More...
 
bool ShowCargoIconOverlay ()
 Test if cargo icon overlays should be drawn. More...
 
void AddCargoIconOverlay (std::vector< CargoIconOverlay > &overlays, int x, int width, const Vehicle *v)
 Add a cargo icon to the list of overlays. More...
 
void DrawCargoIconOverlay (int x, int y, CargoID cid)
 Draw a cargo icon overlaying an existing sprite, with a black contrast outline. More...
 
void DrawCargoIconOverlays (std::span< const CargoIconOverlay > overlays, int y)
 Draw a list of cargo icon overlays. More...
 
void DepotSortList (VehicleList *list)
 
static void DrawVehicleProfitButton (TimerGameEconomy::Date age, Money display_profit_last_year, uint num_vehicles, int x, int y)
 draw the vehicle profit button in the vehicle list window.
 
uint8_t GetBestFittingSubType (Vehicle *v_from, Vehicle *v_for, CargoID dest_cargo_type)
 Get the best fitting subtype when 'cloning'/'replacing' v_from with v_for. More...
 
static void DrawVehicleRefitWindow (const RefitOptions &refits, const RefitOption *sel, uint pos, uint rows, uint delta, const Rect &r)
 Draw the list of available refit options for a consist and highlight the selected refit option (if any). More...
 
void ShowVehicleRefitWindow (const Vehicle *v, VehicleOrderID order, Window *parent, bool auto_refit)
 Show the refit window for a vehicle. More...
 
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.
 
static bool VehicleGroupLengthSorter (const GUIVehicleGroup &a, const GUIVehicleGroup &b)
 Sort vehicle groups by the number of vehicles in the group.
 
static bool VehicleGroupTotalProfitThisYearSorter (const GUIVehicleGroup &a, const GUIVehicleGroup &b)
 Sort vehicle groups by the total profit this year.
 
static bool VehicleGroupTotalProfitLastYearSorter (const GUIVehicleGroup &a, const GUIVehicleGroup &b)
 Sort vehicle groups by the total profit last year.
 
static bool VehicleGroupAverageProfitThisYearSorter (const GUIVehicleGroup &a, const GUIVehicleGroup &b)
 Sort vehicle groups by the average profit this year.
 
static bool VehicleGroupAverageProfitLastYearSorter (const GUIVehicleGroup &a, const GUIVehicleGroup &b)
 Sort vehicle groups by the average profit last year.
 
static bool VehicleNumberSorter (const Vehicle *const &a, const Vehicle *const &b)
 Sort vehicles by their number.
 
static bool VehicleNameSorter (const Vehicle *const &a, const Vehicle *const &b)
 Sort vehicles by their name.
 
static bool VehicleAgeSorter (const Vehicle *const &a, const Vehicle *const &b)
 Sort vehicles by their age.
 
static bool VehicleProfitThisYearSorter (const Vehicle *const &a, const Vehicle *const &b)
 Sort vehicles by this year profit.
 
static bool VehicleProfitLastYearSorter (const Vehicle *const &a, const Vehicle *const &b)
 Sort vehicles by last year profit.
 
static bool VehicleCargoSorter (const Vehicle *const &a, const Vehicle *const &b)
 Sort vehicles by their cargo.
 
static bool VehicleReliabilitySorter (const Vehicle *const &a, const Vehicle *const &b)
 Sort vehicles by their reliability.
 
static bool VehicleMaxSpeedSorter (const Vehicle *const &a, const Vehicle *const &b)
 Sort vehicles by their max speed.
 
static bool VehicleModelSorter (const Vehicle *const &a, const Vehicle *const &b)
 Sort vehicles by model.
 
static bool VehicleValueSorter (const Vehicle *const &a, const Vehicle *const &b)
 Sort vehicles by their value.
 
static bool VehicleLengthSorter (const Vehicle *const &a, const Vehicle *const &b)
 Sort vehicles by their length.
 
static bool VehicleTimeToLiveSorter (const Vehicle *const &a, const Vehicle *const &b)
 Sort vehicles by the time they can still live.
 
static bool VehicleTimetableDelaySorter (const Vehicle *const &a, const Vehicle *const &b)
 Sort vehicles by the timetable delay.
 
void InitializeGUI ()
 
static void ChangeVehicleWindow (WindowClass window_class, VehicleID from_index, VehicleID to_index)
 Assign a vehicle window a new vehicle. More...
 
void ChangeVehicleViewWindow (VehicleID from_index, VehicleID to_index)
 Report a change in vehicle IDs (due to autoreplace) to affected vehicle windows. More...
 
static void DrawSmallOrderList (const Vehicle *v, int left, int right, int y, uint order_arrow_width, VehicleOrderID start)
 
static void DrawSmallOrderList (const Order *order, int left, int right, int y, uint order_arrow_width)
 Draw small order list in the vehicle GUI, but without the little black arrow. More...
 
void DrawVehicleImage (const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip)
 Draws an image of a vehicle chain. More...
 
uint GetVehicleListHeight (VehicleType type, uint divisor)
 Get the height of a vehicle in the vehicle list GUIs. More...
 
static int GetUnitNumberWidth (int digits)
 Get width required for the formatted unit number display. More...
 
static void ShowVehicleListWindowLocal (CompanyID company, VehicleListType vlt, VehicleType vehicle_type, uint32_t unique_number)
 
void ShowVehicleListWindow (CompanyID company, VehicleType vehicle_type)
 
void ShowVehicleListWindow (const Vehicle *v)
 
void ShowVehicleListWindow (CompanyID company, VehicleType vehicle_type, StationID station)
 
void ShowVehicleListWindow (CompanyID company, VehicleType vehicle_type, TileIndex depot_tile)
 
int GetTrainDetailsWndVScroll (VehicleID veh_id, TrainDetailsWindowTabs det_tab)
 Determines the number of lines in the train details window. More...
 
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. More...
 
void DrawRoadVehDetails (const Vehicle *v, const Rect &r)
 Draw the details for the given vehicle at the given position. More...
 
void DrawShipDetails (const Vehicle *v, const Rect &r)
 Draw the details for the given vehicle at the given position. More...
 
void DrawAircraftDetails (const Aircraft *v, const Rect &r)
 Draw the details for the given vehicle at the given position. More...
 
static void ShowVehicleDetailsWindow (const Vehicle *v)
 Shows the vehicle details window of the given vehicle.
 
void CcStartStopVehicle (Commands, const CommandCost &result, VehicleID veh_id, bool)
 This is the Callback method after attempting to start/stop a vehicle. More...
 
void StartStopVehicle (const Vehicle *v, bool texteffect)
 Executes CMD_START_STOP_VEHICLE for given vehicle. More...
 
static bool IsVehicleRefitable (const Vehicle *v)
 Checks whether the vehicle may be refitted at the moment.
 
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. More...
 
bool VehicleClicked (VehicleList::const_iterator begin, VehicleList::const_iterator end)
 Dispatch a "vehicle group selected" event if any window waits for it. More...
 
bool VehicleClicked (const GUIVehicleGroup &vehgroup)
 Dispatch a "vehicle group selected" event if any window waits for it. More...
 
void StopGlobalFollowVehicle (const Vehicle *v)
 
void CcBuildPrimaryVehicle (Commands, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray)
 This is the Callback method after the construction attempt of a primary vehicle. More...
 
int GetSingleVehicleWidth (const Vehicle *v, EngineImageType image_type)
 Get the width of a vehicle (part) in pixels. More...
 
int GetVehicleWidth (const Vehicle *v, EngineImageType image_type)
 Get the width of a vehicle (including all parts of the consist) in pixels. More...
 
void SetMouseCursorVehicle (const Vehicle *v, EngineImageType image_type)
 Set the mouse cursor to look like a vehicle. More...
 

Variables

BaseVehicleListWindow::GroupBy _grouping [VLT_END][VEH_COMPANY_END]
 
Sorting _sorting [BaseVehicleListWindow::GB_END]
 
static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleNumberSorter
 
static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleNameSorter
 
static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleAgeSorter
 
static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleProfitThisYearSorter
 
static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleProfitLastYearSorter
 
static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleCargoSorter
 
static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleReliabilitySorter
 
static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleMaxSpeedSorter
 
static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleModelSorter
 
static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleValueSorter
 
static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleLengthSorter
 
static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleTimeToLiveSorter
 
static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleTimetableDelaySorter
 
static BaseVehicleListWindow::VehicleGroupSortFunction VehicleGroupLengthSorter
 
static BaseVehicleListWindow::VehicleGroupSortFunction VehicleGroupTotalProfitThisYearSorter
 
static BaseVehicleListWindow::VehicleGroupSortFunction VehicleGroupTotalProfitLastYearSorter
 
static BaseVehicleListWindow::VehicleGroupSortFunction VehicleGroupAverageProfitThisYearSorter
 
static BaseVehicleListWindow::VehicleGroupSortFunction VehicleGroupAverageProfitLastYearSorter
 
static GUIVehicleGroupList::FilterFunction *const _vehicle_group_filter_funcs []
 
static const Vehicle_last_vehicle [2] = { nullptr, nullptr }
 
static const uint MAX_REFIT_CYCLE = 256
 Maximum number of refit cycles we try, to prevent infinite loops. More...
 
static constexpr NWidgetPart _nested_vehicle_refit_widgets []
 
static WindowDesc _vehicle_refit_desc (WDP_AUTO, "view_vehicle_refit", 240, 174, WC_VEHICLE_REFIT, WC_VEHICLE_VIEW, WDF_CONSTRUCTION, _nested_vehicle_refit_widgets)
 
static constexpr NWidgetPart _nested_vehicle_list []
 
static WindowDesc _vehicle_list_other_desc (WDP_AUTO, "list_vehicles", 260, 246, WC_INVALID, WC_NONE, 0, _nested_vehicle_list)
 
static WindowDesc _vehicle_list_train_desc (WDP_AUTO, "list_vehicles_train", 325, 246, WC_TRAINS_LIST, WC_NONE, 0, _nested_vehicle_list)
 
static constexpr NWidgetPart _nested_nontrain_vehicle_details_widgets []
 Vehicle details widgets (other than train). More...
 
static constexpr NWidgetPart _nested_train_vehicle_details_widgets []
 Train details widgets.
 
static StringID _service_interval_dropdown_calendar []
 
static StringID _service_interval_dropdown_wallclock []
 
static WindowDesc _train_vehicle_details_desc (WDP_AUTO, "view_vehicle_details_train", 405, 178, WC_VEHICLE_DETAILS, WC_VEHICLE_VIEW, 0, _nested_train_vehicle_details_widgets)
 Vehicle details window descriptor.
 
static WindowDesc _nontrain_vehicle_details_desc (WDP_AUTO, "view_vehicle_details", 405, 113, WC_VEHICLE_DETAILS, WC_VEHICLE_VIEW, 0, _nested_nontrain_vehicle_details_widgets)
 Vehicle details window descriptor for other vehicles than a train.
 
static constexpr NWidgetPart _nested_vehicle_view_widgets []
 Vehicle view widgets.
 
static const ZoomLevel _vehicle_view_zoom_levels []
 Zoom levels for vehicle views indexed by vehicle type. More...
 
static const int VV_INITIAL_VIEWPORT_WIDTH = 226
 
static const int VV_INITIAL_VIEWPORT_HEIGHT = 84
 
static const int VV_INITIAL_VIEWPORT_HEIGHT_TRAIN = 102
 
static const StringID _vehicle_msg_translation_table [][4]
 Command codes for the shared buttons indexed by VehicleCommandTranslation and vehicle type. More...
 
static WindowDesc _vehicle_view_desc (WDP_AUTO, "view_vehicle", 250, 116, WC_VEHICLE_VIEW, WC_NONE, 0, _nested_vehicle_view_widgets, &VehicleViewWindow::hotkeys)
 Vehicle view window descriptor for all vehicles but trains.
 
static WindowDesc _train_view_desc (WDP_AUTO, "view_vehicle_train", 250, 134, WC_VEHICLE_VIEW, WC_NONE, 0, _nested_vehicle_view_widgets, &VehicleViewWindow::hotkeys)
 Vehicle view window descriptor for trains. More...
 

Detailed Description

The base GUI for all vehicles.

Definition in file vehicle_gui.cpp.

Function Documentation

◆ AddCargoIconOverlay()

void AddCargoIconOverlay ( std::vector< CargoIconOverlay > &  overlays,
int  x,
int  width,
const Vehicle v 
)

Add a cargo icon to the list of overlays.

Parameters
overlaysList of overlays.
xHorizontal position.
widthWidth available.
vVehicle to add.

Definition at line 348 of file vehicle_gui.cpp.

◆ CargoFilter()

static bool CargoFilter ( const GUIVehicleGroup vehgroup,
const CargoID  cid 
)
static

Check whether a vehicle can carry a specific cargo.

Parameters
vehgroupThe vehicle group which contains the vehicle to be checked
cidThe cargo what we are looking for
Returns
Whether the vehicle can carry the specified cargo or not

Definition at line 320 of file vehicle_gui.cpp.

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

◆ CargoFilterSingle()

static bool CargoFilterSingle ( const Vehicle v,
const CargoID  cid 
)
static

Check whether a single vehicle should pass the filter.

Parameters
vThe vehicle to check.
cidThe cargo to filter for.
Returns
true iff the vehicle carries the cargo.

Definition at line 280 of file vehicle_gui.cpp.

References CC_PASSENGERS, CargoFilterCriteria::CF_ANY, CargoFilterCriteria::CF_FREIGHT, CargoFilterCriteria::CF_NONE, IsCargoInClass(), and Vehicle::Next().

Referenced by CargoFilter().

◆ CcBuildPrimaryVehicle()

void CcBuildPrimaryVehicle ( Commands  ,
const CommandCost result,
VehicleID  new_veh_id,
uint  ,
uint16_t  ,
CargoArray   
)

This is the Callback method after the construction attempt of a primary vehicle.

Parameters
resultindicates completion (or not) of the operation
new_veh_idID of the new vehicle.

Definition at line 3561 of file vehicle_gui.cpp.

◆ CcStartStopVehicle()

void CcStartStopVehicle ( Commands  cmd,
const CommandCost result,
VehicleID  veh_id,
bool   
)

This is the Callback method after attempting to start/stop a vehicle.

Parameters
resultthe result of the start/stop command
veh_idVehicle ID.

Definition at line 2986 of file vehicle_gui.cpp.

◆ ChangeVehicleViewWindow()

void ChangeVehicleViewWindow ( VehicleID  from_index,
VehicleID  to_index 
)

Report a change in vehicle IDs (due to autoreplace) to affected vehicle windows.

Parameters
from_indexthe old vehicle ID
to_indexthe new vehicle ID

Definition at line 1608 of file vehicle_gui.cpp.

References ChangeVehicleWindow(), WC_VEHICLE_DETAILS, WC_VEHICLE_ORDERS, WC_VEHICLE_REFIT, WC_VEHICLE_TIMETABLE, and WC_VEHICLE_VIEW.

◆ ChangeVehicleWindow()

static void ChangeVehicleWindow ( WindowClass  window_class,
VehicleID  from_index,
VehicleID  to_index 
)
inlinestatic

Assign a vehicle window a new vehicle.

Parameters
window_classWindowClass to search for
from_indexthe old vehicle ID
to_indexthe new vehicle ID

Definition at line 1585 of file vehicle_gui.cpp.

References FindWindowById(), ViewportData::follow_vehicle, Window::viewport, and Window::window_number.

Referenced by ChangeVehicleViewWindow().

◆ CountDigitsForAllocatingSpace()

uint CountDigitsForAllocatingSpace ( uint  number)

Get the number of digits of space required for the given number.

Parameters
numberThe number.
Returns
The number of digits to allocate space for.

Definition at line 189 of file vehicle_gui.cpp.

Referenced by GetUnitNumberDigits().

◆ DrawAircraftDetails()

void DrawAircraftDetails ( const Aircraft v,
const Rect r 
)

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

Parameters
vcurrent vehicle
rthe Rect to draw within

Definition at line 30 of file aircraft_gui.cpp.

Referenced by VehicleDetailsWindow::DrawVehicleDetails().

◆ DrawCargoIconOverlay()

void DrawCargoIconOverlay ( int  x,
int  y,
CargoID  cid 
)

Draw a cargo icon overlaying an existing sprite, with a black contrast outline.

Parameters
xHorizontal position from left.
yVertical position from top.
cidCargo ID to draw icon for.

Definition at line 371 of file vehicle_gui.cpp.

◆ DrawCargoIconOverlays()

void DrawCargoIconOverlays ( std::span< const CargoIconOverlay overlays,
int  y 
)

Draw a list of cargo icon overlays.

Parameters
overlaysList of overlays.
yVertical position.

Definition at line 400 of file vehicle_gui.cpp.

◆ DrawRoadVehDetails()

void DrawRoadVehDetails ( const Vehicle v,
const Rect r 
)

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

Parameters
vcurrent vehicle
rthe Rect to draw within

Definition at line 29 of file roadveh_gui.cpp.

Referenced by VehicleDetailsWindow::DrawVehicleDetails().

◆ DrawShipDetails()

void DrawShipDetails ( const Vehicle v,
const Rect r 
)

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

Parameters
vcurrent vehicle
rthe Rect to draw within

Definition at line 63 of file ship_gui.cpp.

Referenced by VehicleDetailsWindow::DrawVehicleDetails().

◆ DrawSmallOrderList()

static void DrawSmallOrderList ( const Order order,
int  left,
int  right,
int  y,
uint  order_arrow_width 
)
static

Draw small order list in the vehicle GUI, but without the little black arrow.

This is used for shared order groups.

Definition at line 1709 of file vehicle_gui.cpp.

◆ DrawTrainDetails()

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.

Parameters
vcurrent vehicle
rthe Rect to draw within
vscroll_posPosition of scrollbar
vscroll_capNumber of lines currently displayed
det_tabSelected details tab

Definition at line 362 of file train_gui.cpp.

Referenced by VehicleDetailsWindow::DrawVehicleDetails().

◆ 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
skipNumber of pixels to skip at the front (for scrolling)

Definition at line 1734 of file vehicle_gui.cpp.

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

◆ DrawVehicleRefitWindow()

static void DrawVehicleRefitWindow ( const RefitOptions refits,
const RefitOption sel,
uint  pos,
uint  rows,
uint  delta,
const Rect r 
)
static

Draw the list of available refit options for a consist and highlight the selected refit option (if any).

Parameters
refitsAvailable refit options for each (sorted) cargo.
selSelected refit option in the window
posPosition of the selected item in caller widow
rowsNumber of rows(capacity) in caller window
deltaStep height in caller window
rRectangle of the matrix widget.

Definition at line 700 of file vehicle_gui.cpp.

References _current_text_dir, GetSpriteSize(), WidgetDimensions::scaled, Rect::Shrink(), and TD_RTL.

◆ GetBestFittingSubType()

uint8_t GetBestFittingSubType ( Vehicle v_from,
Vehicle v_for,
CargoID  dest_cargo_type 
)

Get the best fitting subtype when 'cloning'/'replacing' v_from with v_for.

All articulated parts of both vehicles are tested to find a possibly shared subtype. For v_for only vehicle refittable to dest_cargo_type are considered.

Parameters
v_fromthe vehicle to match the subtype from
v_forthe vehicle to get the subtype for
dest_cargo_typeDestination cargo type.
Returns
the best sub type

Definition at line 599 of file vehicle_gui.cpp.

References EngineInfo::callback_mask, Engine::CanCarryCargo(), CBM_VEHICLE_CARGO_SUFFIX, GetCargoSubtypeText(), Vehicle::GetEngine(), Vehicle::GetFirstEnginePart(), Vehicle::GetNextArticulatedPart(), Vehicle::HasArticulatedPart(), HasBit(), include(), and MAX_REFIT_CYCLE.

Referenced by LinkRefresher::HandleRefit(), and RefitVehicle().

◆ GetSingleVehicleWidth()

int GetSingleVehicleWidth ( const Vehicle v,
EngineImageType  image_type 
)

Get the width of a vehicle (part) in pixels.

Parameters
vVehicle to get the width for.
Returns
Width of the vehicle.

Definition at line 3574 of file vehicle_gui.cpp.

References _current_text_dir, DIR_E, DIR_W, SpecializedVehicle< T, Type >::From(), VehicleSpriteSeq::GetBounds(), Vehicle::GetImage(), TD_RTL, BaseVehicle::type, UnScaleGUI(), VEH_ROAD, VEH_TRAIN, and Rect::Width().

Referenced by GetVehicleWidth().

◆ GetTrainDetailsWndVScroll()

int GetTrainDetailsWndVScroll ( VehicleID  veh_id,
TrainDetailsWindowTabs  det_tab 
)

◆ GetUnitNumberDigits()

uint GetUnitNumberDigits ( VehicleList vehicles)

Get the number of digits the biggest unit number of a set of vehicles has.

Parameters
vehiclesThe list of vehicles.
Returns
The number of digits to allocate space for.

Definition at line 208 of file vehicle_gui.cpp.

References CountDigitsForAllocatingSpace().

Referenced by DepotWindow::OnPaint().

◆ GetUnitNumberWidth()

static int GetUnitNumberWidth ( int  digits)
static

Get width required for the formatted unit number display.

Parameters
digitsNumber of digits required for unit number.
Returns
Required width in pixels.

Definition at line 1770 of file vehicle_gui.cpp.

References GetStringBoundingBox(), and SetDParamMaxDigits().

◆ GetVehicleListHeight()

uint GetVehicleListHeight ( VehicleType  type,
uint  divisor 
)

Get the height of a vehicle in the vehicle list GUIs.

Parameters
typethe vehicle type to look at
divisorthe resulting height must be dividable by this
Returns
the height

Definition at line 1751 of file vehicle_gui.cpp.

References FS_SMALL, GetCharacterHeight(), GetVehicleHeight(), WidgetDimensions::matrix, WidgetDimensions::scaled, ScaleGUITrad(), VEH_SHIP, and RectPadding::Vertical().

◆ 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.
Returns
Width of the vehicle.

Definition at line 3598 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().

◆ SetMouseCursorVehicle()

void SetMouseCursorVehicle ( const Vehicle v,
EngineImageType  image_type 
)

Set the mouse cursor to look like a vehicle.

Parameters
vVehicle
image_typeType of vehicle image to use.

Definition at line 3616 of file vehicle_gui.cpp.

References _current_text_dir, and TD_RTL.

◆ ShowCargoIconOverlay()

bool ShowCargoIconOverlay ( )

Test if cargo icon overlays should be drawn.

Returns
true iff cargo icon overlays should be drawn.

Definition at line 336 of file vehicle_gui.cpp.

References _ctrl_pressed, and _shift_pressed.

Referenced by DepotWindow::OnMouseLoop(), VehicleGroupWindow::OnMouseLoop(), and VehicleListWindow::OnMouseLoop().

◆ 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 1369 of file vehicle_gui.cpp.

References CloseWindowById(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, and WC_VEHICLE_REFIT.

Referenced by OrdersWindow::OrderClick_Refit().

◆ StartStopVehicle()

void StartStopVehicle ( const Vehicle v,
bool  texteffect 
)

Executes CMD_START_STOP_VEHICLE for given vehicle.

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

Definition at line 3003 of file vehicle_gui.cpp.

References _vehicle_msg_translation_table, and Vehicle::IsPrimaryVehicle().

◆ 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 3541 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 3508 of file vehicle_gui.cpp.

Referenced by 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 3525 of file vehicle_gui.cpp.

Variable Documentation

◆ _nested_nontrain_vehicle_details_widgets

constexpr NWidgetPart _nested_nontrain_vehicle_details_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
NWidget(WWT_CAPTION, COLOUR_GREY, WID_VD_CAPTION), SetDataTip(STR_VEHICLE_DETAILS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_SHADEBOX, COLOUR_GREY),
NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
NWidget(WWT_STICKYBOX, COLOUR_GREY),
SetDataTip(STR_EMPTY, STR_SERVICE_INTERVAL_DROPDOWN_TOOLTIP),
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
}
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1181
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1202
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1137
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1309
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1191
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1126
@ WID_VD_DECREASE_SERVICING_INTERVAL
Decrease the servicing interval.
@ WID_VD_CAPTION
Caption of window.
@ WID_VD_SERVICE_INTERVAL_DROPDOWN
Dropdown to select default/days/percent service interval.
@ WID_VD_INCREASE_SERVICING_INTERVAL
Increase the servicing interval.
@ WID_VD_SERVICING_INTERVAL
Information about the servicing interval.
@ WID_VD_TOP_DETAILS
Panel with generic details.
@ WID_VD_MIDDLE_DETAILS
Details for non-trains.
@ AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition: widget_type.h:31
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition: widget_type.h:32
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:114
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:75
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:50
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:66
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:64
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:69
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:65
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:70

Vehicle details widgets (other than train).

Definition at line 2376 of file vehicle_gui.cpp.

◆ _nested_vehicle_refit_widgets

constexpr NWidgetPart _nested_vehicle_refit_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
NWidget(WWT_CAPTION, COLOUR_GREY, WID_VR_CAPTION), SetDataTip(STR_REFIT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_VR_SELECT_HEADER), SetDataTip(STR_REFIT_TITLE, STR_NULL), SetResize(1, 0),
NWidget(WWT_MATRIX, COLOUR_GREY, WID_VR_MATRIX), SetMinimalSize(228, 112), SetResize(1, 14), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_NULL), SetScrollbar(WID_VR_SCROLLBAR),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VR_REFIT), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
}
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1284
constexpr NWidgetPart SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1214
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition: widget_type.h:1149
@ WID_VR_MATRIX
Options to refit to.
@ WID_VR_SCROLLBAR
Scrollbar for the refit options.
@ WID_VR_SHOW_HSCROLLBAR
Selection widget for the horizontal scrollbar.
@ WID_VR_VEHICLE_PANEL_DISPLAY
Display with a representation of the vehicle to refit.
@ WID_VR_HSCROLLBAR
Horizontal scrollbar or the vehicle display.
@ WID_VR_REFIT
Perform the refit.
@ WID_VR_SELECT_HEADER
Header with question about the cargo to carry.
@ WID_VR_INFO
Information about the currently selected refit option.
@ WID_VR_CAPTION
Caption of window.
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:112
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:55
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:59
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:84
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:77
@ NWID_HSCROLLBAR
Horizontal scrollbar.
Definition: widget_type.h:83
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:80

Definition at line 1329 of file vehicle_gui.cpp.

◆ _service_interval_dropdown_calendar

StringID _service_interval_dropdown_calendar[]
static
Initial value:
= {
STR_VEHICLE_DETAILS_DEFAULT,
STR_VEHICLE_DETAILS_DAYS,
STR_VEHICLE_DETAILS_PERCENT,
}

Definition at line 2441 of file vehicle_gui.cpp.

◆ _service_interval_dropdown_wallclock

StringID _service_interval_dropdown_wallclock[]
static
Initial value:
= {
STR_VEHICLE_DETAILS_DEFAULT,
STR_VEHICLE_DETAILS_MINUTES,
STR_VEHICLE_DETAILS_PERCENT,
}

Definition at line 2447 of file vehicle_gui.cpp.

◆ _train_view_desc

WindowDesc _train_view_desc(WDP_AUTO, "view_vehicle_train", 250, 134, WC_VEHICLE_VIEW, WC_NONE, 0, _nested_vehicle_view_widgets, &VehicleViewWindow::hotkeys) ( WDP_AUTO  ,
"view_vehicle_train"  ,
250  ,
134  ,
WC_VEHICLE_VIEW  ,
WC_NONE  ,
,
_nested_vehicle_view_widgets  ,
&VehicleViewWindow::hotkeys   
)
static

Vehicle view window descriptor for trains.

Only minimum_height and default_height are different for train view.

Referenced by ShowVehicleViewWindow().

◆ _vehicle_group_filter_funcs

GUIVehicleGroupList::FilterFunction* const _vehicle_group_filter_funcs[]
static
Initial value:
= {
}
static bool CargoFilter(const GUIVehicleGroup *vehgroup, const CargoID cid)
Check whether a vehicle can carry a specific cargo.

Definition at line 408 of file vehicle_gui.cpp.

◆ _vehicle_msg_translation_table

const StringID _vehicle_msg_translation_table[][4]
static
Initial value:
= {
{
STR_ERROR_CAN_T_STOP_START_TRAIN,
STR_ERROR_CAN_T_STOP_START_ROAD_VEHICLE,
STR_ERROR_CAN_T_STOP_START_SHIP,
STR_ERROR_CAN_T_STOP_START_AIRCRAFT
},
{
STR_ERROR_CAN_T_BUY_TRAIN,
STR_ERROR_CAN_T_BUY_ROAD_VEHICLE,
STR_ERROR_CAN_T_BUY_SHIP,
STR_ERROR_CAN_T_BUY_AIRCRAFT
},
{
STR_ERROR_CAN_T_REVERSE_DIRECTION_TRAIN,
STR_ERROR_CAN_T_MAKE_ROAD_VEHICLE_TURN,
},
}
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17

Command codes for the shared buttons indexed by VehicleCommandTranslation and vehicle type.

Definition at line 2960 of file vehicle_gui.cpp.

Referenced by StartStopVehicle().

◆ _vehicle_view_zoom_levels

const ZoomLevel _vehicle_view_zoom_levels[]
static
Initial value:
= {
}
@ ZOOM_LVL_ROADVEH
Default zoom level for the road vehicle view.
Definition: zoom_type.h:35
@ ZOOM_LVL_AIRCRAFT
Default zoom level for the aircraft view.
Definition: zoom_type.h:32
@ ZOOM_LVL_TRAIN
Default zoom level for the train view.
Definition: zoom_type.h:34
@ ZOOM_LVL_SHIP
Default zoom level for the ship view.
Definition: zoom_type.h:33

Zoom levels for vehicle views indexed by vehicle type.

Definition at line 2940 of file vehicle_gui.cpp.

◆ MAX_REFIT_CYCLE

const uint MAX_REFIT_CYCLE = 256
static

Maximum number of refit cycles we try, to prevent infinite loops.

And we store only a byte anyway

Definition at line 588 of file vehicle_gui.cpp.

Referenced by RefitWindow::BuildRefitList(), and GetBestFittingSubType().