# build_vehicle_gui.cpp File Reference

GUI for building vehicles. More...

`#include "stdafx.h"`
`#include "engine_base.h"`
`#include "engine_func.h"`
`#include "station_base.h"`
`#include "articulated_vehicles.h"`
`#include "textbuf_gui.h"`
`#include "command_func.h"`
`#include "company_func.h"`
`#include "vehicle_gui.h"`
`#include "newgrf_engine.h"`
`#include "newgrf_text.h"`
`#include "group.h"`
`#include "strings_func.h"`
`#include "window_func.h"`
`#include "date_func.h"`
`#include "vehicle_func.h"`
`#include "widgets/dropdown_func.h"`
`#include "engine_gui.h"`
`#include "cargotype.h"`
`#include "core/geometry_func.hpp"`
`#include "table/sprites.h"`
`#include "table/strings.h"`

Go to the source code of this file.

## Data Structures

struct | BuildVehicleWindow

## Enumerations

enum | BuildVehicleWidgets { BUILD_VEHICLE_WIDGET_CAPTION, BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING, BUILD_VEHICLE_WIDGET_SORT_DROPDOWN, BUILD_VEHICLE_WIDGET_CARGO_FILTER_DROPDOWN, BUILD_VEHICLE_WIDGET_LIST, BUILD_VEHICLE_WIDGET_SCROLLBAR, BUILD_VEHICLE_WIDGET_PANEL, BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_BUILD_SEL, BUILD_VEHICLE_WIDGET_RENAME, BUILD_VEHICLE_WIDGET_END }
enum | { CF_ANY = CT_NO_REFIT, CF_NONE = CT_INVALID }
| Special cargo filter criteria. More...

## Functions

uint | GetEngineListHeight (VehicleType type)
| Get the height of a single 'entry' in the engine lists.
static int CDECL | EngineNumberSorter (const EngineID *a, const EngineID *b)
static int CDECL | EngineIntroDateSorter (const EngineID *a, const EngineID *b)
static int CDECL | EngineNameSorter (const EngineID *a, const EngineID *b)
static int CDECL | EngineReliabilitySorter (const EngineID *a, const EngineID *b)
static int CDECL | EngineCostSorter (const EngineID *a, const EngineID *b)
static int CDECL | EngineSpeedSorter (const EngineID *a, const EngineID *b)
static int CDECL | EnginePowerSorter (const EngineID *a, const EngineID *b)
static int CDECL | EngineRunningCostSorter (const EngineID *a, const EngineID *b)
static int CDECL | TrainEnginePowerVsRunningCostSorter (const EngineID *a, const EngineID *b)
static int CDECL | TrainEngineCapacitySorter (const EngineID *a, const EngineID *b)
static int CDECL | TrainEnginesThenWagonsSorter (const EngineID *a, const EngineID *b)
static int CDECL | RoadVehEngineCapacitySorter (const EngineID *a, const EngineID *b)
static int CDECL | ShipEngineCapacitySorter (const EngineID *a, const EngineID *b)
static int CDECL | AircraftEngineCargoSorter (const EngineID *a, const EngineID *b)
static bool CDECL | CargoFilter (const EngineID *eid, const CargoID cid)
| Cargo filter functions.
static int | DrawCargoCapacityInfo (int left, int right, int y, EngineID engine, bool refittable)
static int | DrawRailWagonPurchaseInfo (int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi)
static int | DrawRailEnginePurchaseInfo (int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi)
static int | DrawRoadVehPurchaseInfo (int left, int right, int y, EngineID engine_number)
static int | DrawShipPurchaseInfo (int left, int right, int y, EngineID engine_number, bool refittable)
static int | DrawAircraftPurchaseInfo (int left, int right, int y, EngineID engine_number, bool refittable)
static uint | ShowAdditionalText (int left, int right, int y, EngineID engine)
| Display additional text from NewGRF in the purchase information window.
int | DrawVehiclePurchaseInfo (int left, int right, int y, EngineID engine_number)
| Draw the purchase info details of a vehicle at a given location.
void | DrawEngineList (VehicleType type, int l, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group)
| Engine drawing loop.
void | ShowBuildVehicleWindow (TileIndex tile, VehicleType type)

## Variables

static const NWidgetPart | _nested_build_vehicle_widgets []
static bool | _internal_sort_order
static byte | _last_sort_criteria [] = {0, 0, 0, 0}
static bool | _last_sort_order [] = {false, false, false, false}
static byte | _last_filter_criteria [] = {0, 0, 0, 0}
static EngList_SortTypeFunction *const | _sorter [][10]
static const StringID | _sort_listing [][11]
static GUIEngineList::FilterFunction *const | _filter_funcs []
static const WindowDesc | _build_vehicle_desc (WDP_AUTO, 240, 268, WC_BUILD_VEHICLE, WC_NONE, WDF_UNCLICK_BUTTONS|WDF_CONSTRUCTION, _nested_build_vehicle_widgets, lengthof(_nested_build_vehicle_widgets))

## Detailed Description

GUI for building vehicles.

Definition in file build_vehicle_gui.cpp.

## Enumeration Type Documentation

anonymous enum

Special cargo filter criteria.

Enumerator:

  CF_ANY | Show all vehicles independent of carried cargo (i.e. no filtering).
  CF_NONE | Show only vehicles which do not carry cargo (e.g. train engines).

Definition at line 97 of file build_vehicle_gui.cpp.

## Function Documentation

void DrawEngineList | ( | VehicleType | type,
|  | int | l,
|  | int | r,
|  | int | y,
|  | const GUIEngineList * | eng_list,
|  | uint16 | min,
|  | uint16 | max,
|  | EngineID | selected_id,
|  | bool | show_count,
|  | GroupID | selected_group |
| ) |  |  |

Engine drawing loop.

Parameters:

  | type | Type of vehicle (VEH_*)
  | l | The left most location of the list
  | r | The right most location of the list
  | y | The top most location of teh list
  | eng_list | What engines to draw
  | min | where to start in the list
  | max | where in the list to end
  | selected_id | what engine to highlight as selected, if any
  | show_count | Whether to show the amount of engines or not
  | selected_group | the group to list the engines of

Definition at line 698 of file build_vehicle_gui.cpp.

References _dynlang, DrawString(), DrawVehicleEngine(), FONT_HEIGHT_NORMAL, FONT_HEIGHT_SMALL, GetEngineListHeight(), GetEnginePalette(), GetGroupNumEngines(), lengthof, SA_RIGHT, SetDParam(), TD_RTL, DynamicLanguages::text_dir, WD_FRAMERECT_BOTTOM, WD_FRAMERECT_LEFT, and WD_FRAMERECT_RIGHT.

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

int DrawVehiclePurchaseInfo | ( | int | left,
|  | int | right,
|  | int | y,
|  | EngineID | engine_number |
| ) |  |  |

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

Parameters:

  | left,right,y | location where to draw the info
  | engine_number | the engine of which to draw the info of

Returns:
  y after drawing all the text

Definition at line 618 of file build_vehicle_gui.cpp.

References ConvertDateToYMD(), CT_INVALID, DAYS_IN_LEAP_YEAR, DrawString(), FONT_HEIGHT_NORMAL, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Engine::GetLifeLengthInDays(), IsArticulatedVehicleRefittable(), RAILVEH_WAGON, SetDParam(), ShowAdditionalText(), ShowRefitOptionsList(), ToPercent16(), Engine::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, and YearMonthDay::year.

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

uint GetEngineListHeight | ( | VehicleType | type | ) |

Get the height of a single 'entry' in the engine lists.

Parameters:

  | type | the vehicle type to get the height of

Returns:
  the height for the entry

Definition at line 41 of file build_vehicle_gui.cpp.

References FONT_HEIGHT_NORMAL, GetVehicleHeight(), WD_MATRIX_BOTTOM, and WD_MATRIX_TOP.

Referenced by DrawEngineList(), BuildVehicleWindow::UpdateWidgetSize(), and ReplaceVehicleWindow::UpdateWidgetSize().

static uint ShowAdditionalText | ( | int | left,
|  | int | right,
|  | int | y,
|  | EngineID | engine |
| ) |  |  | `[static]`

Display additional text from NewGRF in the purchase information window.

Parameters:

  | left | Left border of text bounding box
  | right | Right border of text bounding box
  | y | Top border of text bounding box
  | engine | Engine to query the additional purchase information for

Returns:
  Bottom border of text bounding box

Definition at line 599 of file build_vehicle_gui.cpp.

References CALLBACK_FAILED, CBID_VEHICLE_ADDITIONAL_TEXT, DrawStringMultiLine(), GetEngineGRFID(), GetGRFStringID(), GetVehicleCallback(), PrepareTextRefStackUsage(), SetDParam(), and StopTextRefStackUsage().

Referenced by DrawVehiclePurchaseInfo().

## Variable Documentation

GUIEngineList::FilterFunction* const _filter_funcs[]`[static]`

Initial value:

     {
      &CargoFilter,
    }

Definition at line 403 of file build_vehicle_gui.cpp.