# autoreplace_gui.cpp File Reference

GUI for autoreplace handling. More...

`#include "stdafx.h"`
`#include "command_func.h"`
`#include "vehicle_gui.h"`
`#include "newgrf_engine.h"`
`#include "group.h"`
`#include "rail.h"`
`#include "strings_func.h"`
`#include "window_func.h"`
`#include "autoreplace_func.h"`
`#include "company_func.h"`
`#include "widgets/dropdown_type.h"`
`#include "engine_base.h"`
`#include "window_gui.h"`
`#include "engine_gui.h"`
`#include "settings_func.h"`
`#include "core/geometry_func.hpp"`
`#include "table/strings.h"`

Go to the source code of this file.

## Data Structures
class | ReplaceVehicleWindow
| Window for the autoreplacing of vehicles. More...
## Enumerations
enum | ReplaceVehicleWindowWidgets { RVW_WIDGET_CAPTION, RVW_WIDGET_LEFT_MATRIX, RVW_WIDGET_LEFT_SCROLLBAR, RVW_WIDGET_RIGHT_MATRIX, RVW_WIDGET_RIGHT_SCROLLBAR, RVW_WIDGET_LEFT_DETAILS, RVW_WIDGET_RIGHT_DETAILS, RVW_WIDGET_START_REPLACE, RVW_WIDGET_INFO_TAB, RVW_WIDGET_STOP_REPLACE, RVW_WIDGET_TRAIN_ENGINEWAGON_TOGGLE, RVW_WIDGET_TRAIN_FLUFF_LEFT, RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN, RVW_WIDGET_TRAIN_FLUFF_RIGHT, RVW_WIDGET_TRAIN_WAGONREMOVE_TOGGLE }
| Widget numbers of the autoreplace GUI. More...
## Functions
uint | GetEngineListHeight (VehicleType type)
| Get the height of a single 'entry' in the engine lists.
void | DrawEngineList (VehicleType type, int x, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group)
| Engine drawing loop.
static int CDECL | EngineNumberSorter (const EngineID *a, const EngineID *b)
void | InvalidateAutoreplaceWindow (EngineID e, GroupID id_g)
| Rebuild the left autoreplace list if an engine is removed or added.
void | AddRemoveEngineFromAutoreplaceAndBuildWindows (VehicleType type)
| When an engine is made buildable or is removed from being buildable, add/remove it from the build/autoreplace lists.
void | ShowReplaceGroupVehicleWindow (GroupID id_g, VehicleType vehicletype)
## Variables
static const NWidgetPart | _nested_replace_rail_vehicle_widgets []
static const WindowDesc | _replace_rail_vehicle_desc (WDP_AUTO, 456, 140, WC_REPLACE_VEHICLE, WC_NONE, WDF_UNCLICK_BUTTONS|WDF_CONSTRUCTION, _nested_replace_rail_vehicle_widgets, lengthof(_nested_replace_rail_vehicle_widgets))
static const NWidgetPart | _nested_replace_vehicle_widgets []
static const WindowDesc | _replace_vehicle_desc (WDP_AUTO, 456, 118, WC_REPLACE_VEHICLE, WC_NONE, WDF_UNCLICK_BUTTONS|WDF_CONSTRUCTION, _nested_replace_vehicle_widgets, lengthof(_nested_replace_vehicle_widgets))

## Detailed Description

GUI for autoreplace handling.

Definition in file autoreplace_gui.cpp.

## Enumeration Type Documentation

enum ReplaceVehicleWindowWidgets

Widget numbers of the autoreplace GUI.

Definition at line 35 of file autoreplace_gui.cpp.

## Function Documentation

void AddRemoveEngineFromAutoreplaceAndBuildWindows | ( | VehicleType | type | ) |

When an engine is made buildable or is removed from being buildable, add/remove it from the build/autoreplace lists.

Parameters:

  | type | The type of engine

Definition at line 90 of file autoreplace_gui.cpp.

References InvalidateWindowClassesData(), and InvalidateWindowData().

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 697 of file build_vehicle_gui.cpp.

References _dynlang, assert_compile(), 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 ReplaceVehicleWindow::DrawWidget().

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 40 of file build_vehicle_gui.cpp.

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

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

void InvalidateAutoreplaceWindow | ( | EngineID | e,
|  | GroupID | id_g |
| ) |  |  |

Rebuild the left autoreplace list if an engine is removed or added.

Parameters:

  | e | Engine to check if it is removed or added
  | id_g | The group the engine belongs to Note: this function only works if it is called either when a new vehicle is build, but before it's counted in num_engines when a vehicle is deleted and after it's substracted from num_engines when not changing the count (used when changing replace orders)

Definition at line 74 of file autoreplace_gui.cpp.

References GetGroupNumEngines(), and InvalidateWindowData().

Referenced by CmdBuildAircraft(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdBuildRoadVeh(), CmdBuildShip(), and CmdSetAutoReplace().

## Variable Documentation

const NWidgetPart _nested_replace_vehicle_widgets[]`[static]`

Initial value:

     {
      NWidget(NWID_HORIZONTAL),
        NWidget(WWT_CLOSEBOX, COLOUR_GREY),
        NWidget(WWT_CAPTION, COLOUR_GREY, RVW_WIDGET_CAPTION), SetMinimalSize(433, 14), SetDataTip(STR_REPLACE_VEHICLES_WHITE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
        NWidget(WWT_SHADEBOX, COLOUR_GREY),
        NWidget(WWT_STICKYBOX, COLOUR_GREY),
      EndContainer(),
      NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
        NWidget(WWT_MATRIX, COLOUR_GREY, RVW_WIDGET_LEFT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetDataTip(0x1, STR_REPLACE_HELP_LEFT_ARRAY), SetResize(1, 1),
        NWidget(WWT_SCROLLBAR, COLOUR_GREY, RVW_WIDGET_LEFT_SCROLLBAR),
        NWidget(WWT_MATRIX, COLOUR_GREY, RVW_WIDGET_RIGHT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetDataTip(0x1, STR_REPLACE_HELP_RIGHT_ARRAY), SetResize(1, 1),
        NWidget(WWT_SCROLL2BAR, COLOUR_GREY, RVW_WIDGET_RIGHT_SCROLLBAR),
      EndContainer(),
      NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
        NWidget(WWT_PANEL, COLOUR_GREY, RVW_WIDGET_LEFT_DETAILS), SetMinimalSize(228, 92), SetResize(1, 0), EndContainer(),
        NWidget(WWT_PANEL, COLOUR_GREY, RVW_WIDGET_RIGHT_DETAILS), SetMinimalSize(228, 92), SetResize(1, 0), EndContainer(),
      EndContainer(),
      NWidget(NWID_HORIZONTAL),
        NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, RVW_WIDGET_START_REPLACE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON),
        NWidget(WWT_PANEL, COLOUR_GREY, RVW_WIDGET_INFO_TAB), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB), SetResize(1, 0), EndContainer(),
        NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, RVW_WIDGET_STOP_REPLACE), SetMinimalSize(138, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON),
        NWidget(WWT_RESIZEBOX, COLOUR_GREY),
      EndContainer(),
    }

Definition at line 540 of file autoreplace_gui.cpp.