# 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 "gfx_func.h"`
`#include "company_func.h"`
`#include "widgets/dropdown_type.h"`
`#include "engine_base.h"`
`#include "window_gui.h"`
`#include "engine_gui.h"`
`#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_LEFT_MATRIX = 3, 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_RESIZE, 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 }
## Functions
void | DrawEngineList (VehicleType type, int x, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, int count_location, GroupID selected_group)
| Engine drawing loop.
static int CDECL | EngineNumberSorter (const void *a, const void *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 Widget | _replace_vehicle_widgets []
static const WindowDesc | _replace_rail_vehicle_desc (WDP_AUTO, WDP_AUTO, 456, 140, 456, 140, WC_REPLACE_VEHICLE, WC_NONE, WDF_STD_TOOLTIPS|WDF_STD_BTN|WDF_DEF_WIDGET|WDF_UNCLICK_BUTTONS|WDF_STICKY_BUTTON|WDF_RESIZABLE|WDF_CONSTRUCTION, _replace_vehicle_widgets)
static const WindowDesc | _replace_vehicle_desc (WDP_AUTO, WDP_AUTO, 456, 118, 456, 118, WC_REPLACE_VEHICLE, WC_NONE, WDF_STD_TOOLTIPS|WDF_STD_BTN|WDF_DEF_WIDGET|WDF_UNCLICK_BUTTONS|WDF_STICKY_BUTTON|WDF_RESIZABLE|WDF_CONSTRUCTION, _replace_vehicle_widgets)

## Detailed Description

GUI for autoreplace handling.

Definition in 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 80 of file autoreplace_gui.cpp.

References InvalidateWindowClassesData(), and InvalidateWindowData().

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

Engine drawing loop.

Parameters:

  | type | Type of vehicle (VEH_*)
  | x,y | Where should the list start
  | 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
  | count_location | Offset to print the engine count (used by autoreplace). 0 means it's off

Definition at line 638 of file build_vehicle_gui.cpp.

References DrawStringRightAligned(), DrawStringTruncated(), GetEnginePalette(), and GetGroupNumEngines().

Referenced by ReplaceVehicleWindow::OnPaint().

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 64 of file autoreplace_gui.cpp.

References GetGroupNumEngines(), and InvalidateWindowData().

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

## Variable Documentation

const Widget _replace_vehicle_widgets[]`[static]`

Initial value:

     {
    {   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_GREY,     0,    10,     0,    13, STR_00C5,                        STR_018B_CLOSE_WINDOW},
    {    WWT_CAPTION,  RESIZE_RIGHT,  COLOUR_GREY,    11,   443,     0,    13, STR_REPLACE_VEHICLES_WHITE,      STR_018C_WINDOW_TITLE_DRAG_THIS},
    {  WWT_STICKYBOX,     RESIZE_LR,  COLOUR_GREY,   444,   455,     0,    13, STR_NULL,                        STR_STICKY_BUTTON},

    {     WWT_MATRIX, RESIZE_BOTTOM,  COLOUR_GREY,     0,   215,    14,    13, 0x1,                             STR_REPLACE_HELP_LEFT_ARRAY},
    {  WWT_SCROLLBAR, RESIZE_BOTTOM,  COLOUR_GREY,   216,   227,    14,    13, STR_NULL,                        STR_0190_SCROLL_BAR_SCROLLS_LIST},
    {     WWT_MATRIX,    RESIZE_LRB,  COLOUR_GREY,   228,   443,    14,    13, 0x1,                             STR_REPLACE_HELP_RIGHT_ARRAY},
    { WWT_SCROLL2BAR,    RESIZE_LRB,  COLOUR_GREY,   444,   455,    14,    13, STR_NULL,                        STR_0190_SCROLL_BAR_SCROLLS_LIST},
    {      WWT_PANEL,     RESIZE_TB,  COLOUR_GREY,     0,   227,    14,   105, 0x0,                             STR_NULL},
    {      WWT_PANEL,    RESIZE_RTB,  COLOUR_GREY,   228,   455,    14,   105, 0x0,                             STR_NULL},

    { WWT_PUSHTXTBTN,     RESIZE_TB,  COLOUR_GREY,     0,   138,   106,   117, STR_REPLACE_VEHICLES_START,      STR_REPLACE_HELP_START_BUTTON},
    {      WWT_PANEL,    RESIZE_RTB,  COLOUR_GREY,   139,   305,   106,   117, 0x0,                             STR_REPLACE_HELP_REPLACE_INFO_TAB},
    { WWT_PUSHTXTBTN,   RESIZE_LRTB,  COLOUR_GREY,   306,   443,   106,   117, STR_REPLACE_VEHICLES_STOP,       STR_REPLACE_HELP_STOP_BUTTON},
    {  WWT_RESIZEBOX,   RESIZE_LRTB,  COLOUR_GREY,   444,   455,   106,   117, STR_NULL,                        STR_RESIZE_BUTTON},

    { WWT_PUSHTXTBTN,     RESIZE_TB,  COLOUR_GREY,     0,   138,   128,   139, STR_REPLACE_ENGINE_WAGON_SELECT, STR_REPLACE_ENGINE_WAGON_SELECT_HELP},
    {      WWT_PANEL,     RESIZE_TB,  COLOUR_GREY,   139,   153,   128,   139, 0x0,                             STR_NULL},
    {   WWT_DROPDOWN,    RESIZE_RTB,  COLOUR_GREY,   154,   289,   128,   139, 0x0,                             STR_REPLACE_HELP_RAILTYPE},
    {      WWT_PANEL,   RESIZE_LRTB,  COLOUR_GREY,   290,   305,   128,   139, 0x0,                             STR_NULL},
    { WWT_PUSHTXTBTN,   RESIZE_LRTB,  COLOUR_GREY,   306,   443,   128,   139, STR_REPLACE_REMOVE_WAGON,        STR_REPLACE_REMOVE_WAGON_HELP},
    {   WIDGETS_END},
    }

Definition at line 448 of file autoreplace_gui.cpp.