OpenTTD Source 20241224-master-gf74b0cf984
engine_gui.h File Reference

Engine GUI functions, used by build_vehicle_gui and autoreplace_gui More...

#include "engine_type.h"
#include "group_type.h"
#include "sortlist_type.h"
#include "gfx_type.h"
#include "vehicle_type.h"
#include "engine_base.h"

Go to the source code of this file.

Data Structures

struct  GUIEngineListItem
 

Typedefs

typedef GUIList< GUIEngineListItem, std::nullptr_t, CargoIDGUIEngineList
 
typedef bool EngList_SortTypeFunction(const GUIEngineListItem &, const GUIEngineListItem &)
 argument type for EngList_Sort.
 

Functions

void EngList_Sort (GUIEngineList &el, EngList_SortTypeFunction compare)
 Sort all items using quick sort and given 'CompareItems' function.
 
void EngList_SortPartial (GUIEngineList &el, EngList_SortTypeFunction compare, size_t begin, size_t num_items)
 Sort selected range of items (on indices @ <begin, begin+num_items-1>)
 
StringID GetEngineCategoryName (EngineID engine)
 Return the category of an engine.
 
StringID GetEngineInfoString (EngineID engine)
 Get a multi-line string with some technical data, describing the engine.
 
void DrawVehicleEngine (int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
 Draw an engine.
 
void DrawTrainEngine (int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
 
void DrawRoadVehEngine (int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
 Draw a road vehicle engine.
 
void DrawShipEngine (int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
 
void DrawAircraftEngine (int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
 
uint GetEngineListHeight (VehicleType type)
 Get the height of a single 'entry' in the engine lists.
 
void DisplayVehicleSortDropDown (Window *w, VehicleType vehicle_type, int selected, WidgetID button)
 Display the dropdown for the vehicle sort criteria.
 
void DrawEngineList (VehicleType type, const Rect &r, const GUIEngineList &eng_list, const Scrollbar &sb, EngineID selected_id, bool show_count, GroupID selected_group)
 Engine drawing loop.
 
void GUIEngineListAddChildren (GUIEngineList &dst, const GUIEngineList &src, EngineID parent=INVALID_ENGINE, uint8_t indent=0)
 Add children to GUI engine list to build a hierarchical tree.
 

Variables

bool _engine_sort_direction
 false = descending, true = ascending.
 
uint8_t _engine_sort_last_criteria []
 Last set sort criteria, for each vehicle type.
 
bool _engine_sort_last_order []
 Last set direction of the sort order, for each vehicle type.
 
bool _engine_sort_show_hidden_engines []
 Last set 'show hidden engines' setting for each vehicle type.
 
const std::initializer_list< const StringID_engine_sort_listing []
 Dropdown menu strings for the vehicle sort criteria.
 
EngList_SortTypeFunction *const _engine_sort_functions [][11]
 Sort functions for the vehicle sort criteria, for each vehicle type.
 

Detailed Description

Engine GUI functions, used by build_vehicle_gui and autoreplace_gui

Definition in file engine_gui.h.

Typedef Documentation

◆ EngList_SortTypeFunction

typedef bool EngList_SortTypeFunction(const GUIEngineListItem &, const GUIEngineListItem &)

argument type for EngList_Sort.

Definition at line 32 of file engine_gui.h.

◆ GUIEngineList

typedef GUIList<GUIEngineListItem, std::nullptr_t, CargoID> GUIEngineList

Definition at line 30 of file engine_gui.h.

Function Documentation

◆ DisplayVehicleSortDropDown()

void DisplayVehicleSortDropDown ( Window w,
VehicleType  vehicle_type,
int  selected,
WidgetID  button 
)

Display the dropdown for the vehicle sort criteria.

Parameters
wParent window (holds the dropdown button).
vehicle_typeVehicle type being sorted.
selectedCurrently selected sort criterium.
buttonWidget button.

Definition at line 1107 of file build_vehicle_gui.cpp.

References _engine_sort_listing, _settings_game, VehicleSettings::roadveh_acceleration_model, SetBit(), ShowDropDownMenu(), VehicleSettings::train_acceleration_model, VEH_ROAD, VEH_TRAIN, and GameSettings::vehicle.

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

◆ DrawAircraftEngine()

void DrawAircraftEngine ( int  left,
int  right,
int  preferred_x,
int  y,
EngineID  engine,
PaletteID  pal,
EngineImageType  image_type 
)

Definition at line 219 of file aircraft_cmd.cpp.

◆ DrawEngineList()

void DrawEngineList ( VehicleType  type,
const Rect r,
const GUIEngineList eng_list,
const Scrollbar sb,
EngineID  selected_id,
bool  show_count,
GroupID  selected_group 
)

Engine drawing loop.

Parameters
typeType of vehicle (VEH_*)
rThe Rect of the list
eng_listWhat engines to draw
sbScrollbar of list.
selected_idwhat engine to highlight as selected, if any
show_countWhether to show the amount of engines or not
selected_groupthe group to list the engines of

Definition at line 1003 of file build_vehicle_gui.cpp.

References _current_text_dir, _local_company, AutoreplaceVehicleInUse, Engine::company_hidden, DrawSprite(), DrawString(), DrawVehicleEngine(), EIT_PURCHASE, EngineHasReplacementForCompany(), VehicleCellSize::extend_left, VehicleCellSize::extend_right, FS_NORMAL, FS_SMALL, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), GetCharacterHeight(), GetColourGradient(), GetEngineListHeight(), GetEnginePalette(), GetGroupNumEngines(), GetScaledSpriteSize(), GetSpriteSize(), GetStringBoundingBox(), GetVehicleImageCellSize(), Scrollbar::GetVisibleRangeIterators(), HasBit(), HasFlag(), HasVariants, Rect::Height(), WidgetDimensions::hsep_indent, WidgetDimensions::hsep_wide, Rect::Indent(), IsFolded, WidgetDimensions::matrix, PackEngineNameDParam(), PALETTE_CRASH, PurchaseList, SA_CENTER, SA_FORCE, SA_RIGHT, WidgetDimensions::scaled, ScaleSpriteTrad(), SetDParam(), Shaded, Rect::Shrink(), TC_FORCED, TC_NO_SHADE, TD_RTL, Rect::WithHeight(), and Rect::WithWidth().

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

◆ DrawRoadVehEngine()

void DrawRoadVehEngine ( int  left,
int  right,
int  preferred_x,
int  y,
EngineID  engine,
PaletteID  pal,
EngineImageType  image_type 
)

Draw a road vehicle engine.

Parameters
leftLeft edge to draw within.
rightRight edge to draw within.
preferred_xPreferred position of the engine.
yVertical position of the engine.
engineEngine to draw
palPalette to use.

Definition at line 148 of file roadveh_cmd.cpp.

References Clamp(), VehicleSpriteSeq::Draw(), VehicleSpriteSeq::GetBounds(), PALETTE_CRASH, and UnScaleGUI().

Referenced by DrawVehicleEngine().

◆ DrawShipEngine()

void DrawShipEngine ( int  left,
int  right,
int  preferred_x,
int  y,
EngineID  engine,
PaletteID  pal,
EngineImageType  image_type 
)

Definition at line 97 of file ship_cmd.cpp.

◆ DrawTrainEngine()

void DrawTrainEngine ( int  left,
int  right,
int  preferred_x,
int  y,
EngineID  engine,
PaletteID  pal,
EngineImageType  image_type 
)

Definition at line 538 of file train_cmd.cpp.

◆ DrawVehicleEngine()

void DrawVehicleEngine ( int  left,
int  right,
int  preferred_x,
int  y,
EngineID  engine,
PaletteID  pal,
EngineImageType  image_type 
)

Draw an engine.

Parameters
leftMinimum horizontal position to use for drawing the engine
rightMaximum horizontal position to use for drawing the engine
preferred_xHorizontal position to use for drawing the engine.
yVertical position to use for drawing the engine.
engineEngine to draw.
palPalette to use for drawing.

Definition at line 303 of file engine_gui.cpp.

References DrawRoadVehEngine(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Engine::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

Referenced by DrawEngineList(), EnginePreviewWindow::DrawWidget(), and NewsWindow::DrawWidget().

◆ EngList_Sort()

void EngList_Sort ( GUIEngineList el,
EngList_SortTypeFunction  compare 
)

Sort all items using quick sort and given 'CompareItems' function.

Parameters
ellist to be sorted
comparefunction for evaluation of the quicksort

Definition at line 333 of file engine_gui.cpp.

Referenced by ReplaceVehicleWindow::GenerateReplaceVehList().

◆ EngList_SortPartial()

void EngList_SortPartial ( GUIEngineList el,
EngList_SortTypeFunction  compare,
size_t  begin,
size_t  num_items 
)

Sort selected range of items (on indices @ <begin, begin+num_items-1>)

Parameters
ellist to be sorted
comparefunction for evaluation of the quicksort
beginstart of sorting
num_itemscount of items to be sorted

Definition at line 346 of file engine_gui.cpp.

◆ GetEngineCategoryName()

◆ GetEngineInfoString()

StringID GetEngineInfoString ( EngineID  engine)

Get a multi-line string with some technical data, describing the engine.

Parameters
engineEngine to describe.
Returns
String describing the engine.
Postcondition
DParam array is set up for printing the string.

Definition at line 273 of file engine_gui.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Engine::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

Referenced by EnginePreviewWindow::DrawWidget(), NewsWindow::DrawWidget(), EnginePreviewWindow::UpdateWidgetSize(), and NewsWindow::UpdateWidgetSize().

◆ GetEngineListHeight()

uint GetEngineListHeight ( VehicleType  type)

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

Parameters
typethe vehicle type to get the height of
Returns
the height for the entry

Definition at line 53 of file build_vehicle_gui.cpp.

References EIT_PURCHASE, FS_NORMAL, GetCharacterHeight(), GetVehicleImageCellSize(), and WidgetDimensions::scaled.

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

◆ GUIEngineListAddChildren()

void GUIEngineListAddChildren ( GUIEngineList dst,
const GUIEngineList src,
EngineID  parent,
uint8_t  indent 
)

Add children to GUI engine list to build a hierarchical tree.

Parameters
dstDestination list.
srcSource list.
parentCurrent tree parent (set by self with recursion).
indentCurrent tree indentation level (set by self with recursion).

Definition at line 1130 of file build_vehicle_gui.cpp.

References Engine::display_last_variant, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), GUIEngineListAddChildren(), HasFlag(), HasVariants, INVALID_ENGINE, IsFolded, None, SB(), and Shaded.

Referenced by ReplaceVehicleWindow::GenerateReplaceVehList(), and GUIEngineListAddChildren().

Variable Documentation

◆ _engine_sort_direction

◆ _engine_sort_functions

EngList_SortTypeFunction* const _engine_sort_functions[][11]
extern

Sort functions for the vehicle sort criteria, for each vehicle type.

Definition at line 437 of file build_vehicle_gui.cpp.

Referenced by ReplaceVehicleWindow::GenerateReplaceVehList().

◆ _engine_sort_last_criteria

uint8_t _engine_sort_last_criteria[]
extern

Last set sort criteria, for each vehicle type.

Definition at line 99 of file build_vehicle_gui.cpp.

Referenced by ReplaceVehicleWindow::OnDropdownSelect(), BuildVehicleWindow::OnDropdownSelect(), and BuildVehicleWindow::OnInvalidateData().

◆ _engine_sort_last_order

bool _engine_sort_last_order[]
extern

Last set direction of the sort order, for each vehicle type.

Definition at line 100 of file build_vehicle_gui.cpp.

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

◆ _engine_sort_listing

const std::initializer_list<const StringID> _engine_sort_listing[]
extern

Dropdown menu strings for the vehicle sort criteria.

Definition at line 487 of file build_vehicle_gui.cpp.

Referenced by DisplayVehicleSortDropDown(), ReplaceVehicleWindow::SetStringParameters(), and BuildVehicleWindow::SetStringParameters().

◆ _engine_sort_show_hidden_engines

bool _engine_sort_show_hidden_engines[]
extern

Last set 'show hidden engines' setting for each vehicle type.

Definition at line 101 of file build_vehicle_gui.cpp.

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