# road_gui.cpp File Reference

GUI for building roads. More...

`#include "stdafx.h"`
`#include "gui.h"`
`#include "window_gui.h"`
`#include "station_gui.h"`
`#include "terraform_gui.h"`
`#include "viewport_func.h"`
`#include "command_func.h"`
`#include "road_cmd.h"`
`#include "road_map.h"`
`#include "station_func.h"`
`#include "functions.h"`
`#include "window_func.h"`
`#include "vehicle_func.h"`
`#include "sound_func.h"`
`#include "company_func.h"`
`#include "tunnelbridge.h"`
`#include "tilehighlight_func.h"`
`#include "company_base.h"`
`#include "table/sprites.h"`
`#include "table/strings.h"`

Go to the source code of this file.

## Data Structures
struct | RoadTypeInfo
| Structure holding information per roadtype for several functions. More...
struct | BuildRoadToolbarWindow
struct | BuildRoadDepotWindow
struct | BuildRoadStationWindow
## Typedefs
typedef void | OnButtonClick (Window *w)
## Enumerations
enum | RoadFlags { RF_NONE = 0x00, RF_START_HALFROAD_Y = 0x01, RF_END_HALFROAD_Y = 0x02, RF_DIR_Y = 0x04, RF_DIR_X = RF_NONE, RF_START_HALFROAD_X = 0x08, RF_END_HALFROAD_X = 0x10 }
| Define the values of the RoadFlags. More...
enum | RoadToolbarWidgets { RTW_ROAD_X, RTW_ROAD_Y, RTW_AUTOROAD, RTW_DEMOLISH, RTW_DEPOT, RTW_BUS_STATION, RTW_TRUCK_STATION, RTW_ONE_WAY, RTW_BUILD_BRIDGE, RTW_BUILD_TUNNEL, RTW_REMOVE }
| Enum referring to the widgets of the build road toolbar.
enum | BuildRoadDepotWidgets { BRDW_CAPTION, BRDW_DEPOT_NE, BRDW_DEPOT_SE, BRDW_DEPOT_SW, BRDW_DEPOT_NW }
| Enum referring to the widgets of the build road depot window.
enum | BuildRoadStationWidgets { BRSW_CAPTION, BRSW_BACKGROUND, BRSW_STATION_NE, BRSW_STATION_SE, BRSW_STATION_SW, BRSW_STATION_NW, BRSW_STATION_X, BRSW_STATION_Y, BRSW_LT_OFF, BRSW_LT_ON, BRSW_INFO }
| Enum referring to the widgets of the build road station window.
## Functions
static void | ShowRVStationPicker (Window *parent, RoadStopType rs)
static void | ShowRoadDepotPicker (Window *parent)
| DECLARE_ENUM_AS_BIT_SET (RoadFlags)
void | CcPlaySound1D (const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
static void | PlaceRoad_X_Dir (TileIndex tile)
| Set the initial flags for the road constuction.
static void | PlaceRoad_Y_Dir (TileIndex tile)
| Set the initial flags for the road constuction.
static void | PlaceRoad_AutoRoad (TileIndex tile)
| Set the initial flags for the road constuction.
static void | PlaceRoad_Bridge (TileIndex tile)
void | CcBuildRoadTunnel (const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
static void | PlaceRoad_Tunnel (TileIndex tile)
static void | BuildRoadOutsideStation (TileIndex tile, DiagDirection direction)
void | CcRoadDepot (const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
static void | PlaceRoad_Depot (TileIndex tile)
static void | PlaceRoadStop (TileIndex tile, uint32 p2, uint32 cmd)
static void | PlaceRoad_BusStation (TileIndex tile)
static void | PlaceRoad_TruckStation (TileIndex tile)
static void | ToggleRoadButton_Remove (Window *w)
| Toogles state of the Remove button of Build road toolbar.
static bool | RoadToolbar_CtrlChanged (Window *w)
| Updates the Remove button because of Ctrl state change.
static void | BuildRoadClick_X_Dir (Window *w)
| Function that handles the click on the X road placement button.
static void | BuildRoadClick_Y_Dir (Window *w)
| Function that handles the click on the Y road placement button.
static void | BuildRoadClick_AutoRoad (Window *w)
| Function that handles the click on the autoroad placement button.
static void | BuildRoadClick_Demolish (Window *w)
static void | BuildRoadClick_Depot (Window *w)
static void | BuildRoadClick_BusStation (Window *w)
static void | BuildRoadClick_TruckStation (Window *w)
static void | BuildRoadClick_OneWay (Window *w)
| Function that handles the click on the one way road button.
static void | BuildRoadClick_Bridge (Window *w)
static void | BuildRoadClick_Tunnel (Window *w)
static void | BuildRoadClick_Remove (Window *w)
void | ShowBuildRoadToolbar (RoadType roadtype)
void | ShowBuildRoadScenToolbar ()
void | InitializeRoadGui ()
## Variables
static bool | _remove_button_clicked
static bool | _one_way_button_clicked
static RoadFlags | _place_road_flag
static RoadType | _cur_roadtype
static DiagDirection | _road_depot_orientation
static DiagDirection | _road_station_picker_orientation
static const RoadTypeInfo | _road_type_infos []
| What errors/cursors must be shown for several types of roads.
static OnButtonClick *const | _build_road_button_proc []
| Array with the handlers of the button-clicks for the road-toolbar.
static const uint16 | _road_keycodes []
| Array with the keycode of the button-clicks for the road-toolbar.
static const NWidgetPart | _nested_build_road_widgets []
static const WindowDesc | _build_road_desc (WDP_ALIGN_TOOLBAR, 0, 0, WC_BUILD_TOOLBAR, WC_NONE, WDF_CONSTRUCTION, _nested_build_road_widgets, lengthof(_nested_build_road_widgets))
static const NWidgetPart | _nested_build_tramway_widgets []
static const WindowDesc | _build_tramway_desc (WDP_ALIGN_TOOLBAR, 0, 0, WC_BUILD_TOOLBAR, WC_NONE, WDF_CONSTRUCTION, _nested_build_tramway_widgets, lengthof(_nested_build_tramway_widgets))
static const NWidgetPart | _nested_build_road_scen_widgets []
static const WindowDesc | _build_road_scen_desc (WDP_AUTO, 0, 0, WC_SCEN_BUILD_TOOLBAR, WC_NONE, WDF_CONSTRUCTION, _nested_build_road_scen_widgets, lengthof(_nested_build_road_scen_widgets))
static const NWidgetPart | _nested_build_road_depot_widgets []
static const WindowDesc | _build_road_depot_desc (WDP_AUTO, 0, 0, WC_BUILD_DEPOT, WC_BUILD_TOOLBAR, WDF_CONSTRUCTION, _nested_build_road_depot_widgets, lengthof(_nested_build_road_depot_widgets))
static const NWidgetPart | _nested_rv_station_picker_widgets []
| Widget definition of the build road station window.
static const WindowDesc | _rv_station_picker_desc (WDP_AUTO, 0, 0, WC_BUS_STATION, WC_BUILD_TOOLBAR, WDF_CONSTRUCTION, _nested_rv_station_picker_widgets, lengthof(_nested_rv_station_picker_widgets))

## Detailed Description

GUI for building roads.

Definition in file road_gui.cpp.

## Enumeration Type Documentation

enum RoadFlags

Define the values of the RoadFlags.

See also:
  CmdBuildLongRoad

Definition at line 44 of file road_gui.cpp.

## Function Documentation

static void BuildRoadClick_AutoRoad | ( | Window * | w | ) | `[static]`

Function that handles the click on the autoroad placement button.

Parameters:

  | w | The current window

Definition at line 316 of file road_gui.cpp.

References HandlePlacePushButton(), HT_RECT, and PlaceRoad_AutoRoad().

static void BuildRoadClick_OneWay | ( | Window * | w | ) | `[static]`

Function that handles the click on the one way road button.

Parameters:

  | w | The current window

Definition at line 350 of file road_gui.cpp.

References Window::IsWidgetDisabled(), Window::SetDirty(), and Window::ToggleWidgetLoweredState().

static void BuildRoadClick_X_Dir | ( | Window * | w | ) | `[static]`

Function that handles the click on the X road placement button.

Parameters:

  | w | The current window

Definition at line 294 of file road_gui.cpp.

References HandlePlacePushButton(), HT_RECT, and PlaceRoad_X_Dir().

static void BuildRoadClick_Y_Dir | ( | Window * | w | ) | `[static]`

Function that handles the click on the Y road placement button.

Parameters:

  | w | The current window

Definition at line 305 of file road_gui.cpp.

References HandlePlacePushButton(), HT_RECT, and PlaceRoad_Y_Dir().

static void PlaceRoad_AutoRoad | ( | TileIndex | tile | ) | `[static]`

Set the initial flags for the road constuction.

The flags are:

- The direction is not set.
- The first tile has a partitial RoadBit (true or false)

Parameters:

  | tile | The start tile

Definition at line 105 of file road_gui.cpp.

References DDSP_PLACE_AUTOROAD, VPM_X_OR_Y, and VpStartPlaceSizing().

Referenced by BuildRoadClick_AutoRoad().

static void PlaceRoad_X_Dir | ( | TileIndex | tile | ) | `[static]`

Set the initial flags for the road constuction.

The flags are:

- The direction is the X-dir
- The first tile has a partitial RoadBit (true or false)

Parameters:

  | tile | The start tile

Definition at line 75 of file road_gui.cpp.

References DDSP_PLACE_ROAD_X_DIR, VPM_FIX_Y, and VpStartPlaceSizing().

Referenced by BuildRoadClick_X_Dir().

static void PlaceRoad_Y_Dir | ( | TileIndex | tile | ) | `[static]`

Set the initial flags for the road constuction.

The flags are:

- The direction is the Y-dir
- The first tile has a partitial RoadBit (true or false)

Parameters:

  | tile | The start tile

Definition at line 90 of file road_gui.cpp.

References DDSP_PLACE_ROAD_Y_DIR, VPM_FIX_X, and VpStartPlaceSizing().

Referenced by BuildRoadClick_Y_Dir().

static bool RoadToolbar_CtrlChanged | ( | Window * | w | ) | `[static]`

Updates the Remove button because of Ctrl state change.

Parameters:

  | w | window the button belongs to

Returns:
  true iff the remove buton was changed

Definition at line 272 of file road_gui.cpp.

References Window::IsWidgetDisabled(), Window::IsWidgetLowered(), and ToggleRoadButton_Remove().

Referenced by BuildRoadToolbarWindow::OnClick(), BuildRoadToolbarWindow::OnCTRLStateChange(), and BuildRoadToolbarWindow::OnKeyPress().

static void ToggleRoadButton_Remove | ( | Window * | w | ) | `[static]`

Toogles state of the Remove button of Build road toolbar.

Parameters:

  | w | window the button belongs to

Definition at line 260 of file road_gui.cpp.

References _remove_button_clicked, Window::IsWidgetLowered(), Window::SetWidgetDirty(), and Window::ToggleWidgetLoweredState().

Referenced by RoadToolbar_CtrlChanged().

## Variable Documentation

OnButtonClick* const _build_road_button_proc[]`[static]`

Initial value:

     {
      BuildRoadClick_X_Dir,
      BuildRoadClick_Y_Dir,
      BuildRoadClick_AutoRoad,
      BuildRoadClick_Demolish,
      BuildRoadClick_Depot,
      BuildRoadClick_BusStation,
      BuildRoadClick_TruckStation,
      BuildRoadClick_OneWay,
      BuildRoadClick_Bridge,
      BuildRoadClick_Tunnel,
      BuildRoadClick_Remove
    }

Array with the handlers of the button-clicks for the road-toolbar.

Definition at line 378 of file road_gui.cpp.

const NWidgetPart _nested_build_road_depot_widgets[]`[static]`

Initial value:

     {
      NWidget(NWID_HORIZONTAL),
        NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
        NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, BRDW_CAPTION), SetDataTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
      EndContainer(),
      NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
        NWidget(NWID_SPACER), SetMinimalSize(0, 3),
        NWidget(NWID_HORIZONTAL_LTR),
          NWidget(NWID_SPACER), SetMinimalSize(3, 0), SetFill(1, 0),
          NWidget(NWID_VERTICAL),
            NWidget(WWT_PANEL, COLOUR_GREY, BRDW_DEPOT_NW), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
            EndContainer(),
            NWidget(NWID_SPACER), SetMinimalSize(0, 2),
            NWidget(WWT_PANEL, COLOUR_GREY, BRDW_DEPOT_SW), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
            EndContainer(),
          EndContainer(),
          NWidget(NWID_SPACER), SetMinimalSize(2, 0),
          NWidget(NWID_VERTICAL),
            NWidget(WWT_PANEL, COLOUR_GREY, BRDW_DEPOT_NE), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
            EndContainer(),
            NWidget(NWID_SPACER), SetMinimalSize(0, 2),
            NWidget(WWT_PANEL, COLOUR_GREY, BRDW_DEPOT_SE), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
            EndContainer(),
          EndContainer(),
          NWidget(NWID_SPACER), SetMinimalSize(3, 0), SetFill(1, 0),
        EndContainer(),
        NWidget(NWID_SPACER), SetMinimalSize(0, 3),
      EndContainer(),
    }

Definition at line 810 of file road_gui.cpp.

const NWidgetPart _nested_build_road_scen_widgets[]`[static]`

Initial value:

     {
      NWidget(NWID_HORIZONTAL),
        NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
        NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_ROAD_TOOLBAR_ROAD_CONSTRUCTION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
        NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
      EndContainer(),
      NWidget(NWID_HORIZONTAL),
        NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_ROAD_X),
                SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
        NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_ROAD_Y),
                SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
        NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_AUTOROAD),
                SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOROAD, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD),
        NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_DEMOLISH),
                SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
        NWidget(WWT_PANEL, COLOUR_DARK_GREEN, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
        NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_ONE_WAY),
                SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
        NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_BUILD_BRIDGE),
                SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE),
        NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_BUILD_TUNNEL),
                SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL),
        NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_REMOVE),
                SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD),
      EndContainer(),
    }

Definition at line 715 of file road_gui.cpp.

const uint16 _road_keycodes[]`[static]`

Initial value:

     {
      '1',
      '2',
      '3',
      '4',
      '5',
      '6',
      '7',
      '8',
      'B',
      'T',
      'R',
    }

Array with the keycode of the button-clicks for the road-toolbar.

Definition at line 393 of file road_gui.cpp.

const RoadTypeInfo _road_type_infos[]`[static]`

Initial value:

     {
      {
        STR_ERROR_CAN_T_BUILD_ROAD_HERE,
        STR_ERROR_CAN_T_REMOVE_ROAD_FROM,
        STR_ERROR_CAN_T_BUILD_ROAD_DEPOT,
        { STR_ERROR_CAN_T_BUILD_BUS_STATION,         STR_ERROR_CAN_T_BUILD_TRUCK_STATION          },
        { STR_ERROR_CAN_T_REMOVE_BUS_STATION,        STR_ERROR_CAN_T_REMOVE_TRUCK_STATION         },
        { STR_STATION_BUILD_BUS_ORIENTATION,         STR_STATION_BUILD_TRUCK_ORIENTATION          },
        { STR_STATION_BUILD_BUS_ORIENTATION_TOOLTIP, STR_STATION_BUILD_TRUCK_ORIENTATION_TOOLTIP  },

        SPR_CURSOR_ROAD_NESW,
        SPR_CURSOR_ROAD_NWSE,
        SPR_CURSOR_AUTOROAD,
      },
      {
        STR_ERROR_CAN_T_BUILD_TRAMWAY_HERE,
        STR_ERROR_CAN_T_REMOVE_TRAMWAY_FROM,
        STR_ERROR_CAN_T_BUILD_TRAM_DEPOT,
        { STR_ERROR_CAN_T_BUILD_PASSENGER_TRAM_STATION,         STR_ERROR_CAN_T_BUILD_CARGO_TRAM_STATION         },
        { STR_ERROR_CAN_T_REMOVE_PASSENGER_TRAM_STATION,        STR_ERROR_CAN_T_REMOVE_CARGO_TRAM_STATION        },
        { STR_STATION_BUILD_PASSENGER_TRAM_ORIENTATION,         STR_STATION_BUILD_CARGO_TRAM_ORIENTATION         },
        { STR_STATION_BUILD_PASSENGER_TRAM_ORIENTATION_TOOLTIP, STR_STATION_BUILD_CARGO_TRAM_ORIENTATION_TOOLTIP },

        SPR_CURSOR_TRAMWAY_NESW,
        SPR_CURSOR_TRAMWAY_NWSE,
        SPR_CURSOR_AUTOTRAM,
      },
    }

What errors/cursors must be shown for several types of roads.

Definition at line 146 of file road_gui.cpp.