# bridge_gui.cpp File Reference

Graphical user interface for bridge construction. More...

`#include "stdafx.h"`
`#include "gui.h"`
`#include "command_func.h"`
`#include "rail.h"`
`#include "strings_func.h"`
`#include "window_func.h"`
`#include "sound_func.h"`
`#include "gfx_func.h"`
`#include "tunnelbridge.h"`
`#include "sortlist_type.h"`
`#include "widgets/dropdown_func.h"`
`#include "core/geometry_func.hpp"`
`#include "cmd_helper.h"`
`#include "tunnelbridge_map.h"`
`#include "road_gui.h"`
`#include "table/strings.h"`

Go to the source code of this file.

## Data Structures
struct | BuildBridgeData
| Carriage for the data we need if we want to build a bridge. More...
class | BuildBridgeWindow
| Window class for handling the bridge-build GUI. More...
## Typedefs
typedef GUIList< BuildBridgeData > | GUIBridgeList
| List of bridges, used in BuildBridgeWindow.
## Enumerations
enum | BuildBridgeSelectionWidgets { BBSW_CAPTION, BBSW_DROPDOWN_ORDER, BBSW_DROPDOWN_CRITERIA, BBSW_BRIDGE_LIST, BBSW_SCROLLBAR }
| Names of the widgets of the build-bridge selection window. More...
## Functions
void | CcBuildBridge (const CommandCost &result, TileIndex end_tile, uint32 p1, uint32 p2)
| Callback executed after a build Bridge CMD has been called.
void | ShowBuildBridgeWindow (TileIndex start, TileIndex end, TransportType transport_type, byte road_rail_type)
| Prepare the data for the build a bridge window.
## Variables
static BridgeType | _last_railbridge_type = 0
| The type of the last built rail bridge.
static BridgeType | _last_roadbridge_type = 0
| The type of the last built road bridge.
static const NWidgetPart | _nested_build_bridge_widgets []
| Widgets of the bridge gui.
static const WindowDesc | _build_bridge_desc (WDP_AUTO, 200, 114, WC_BUILD_BRIDGE, WC_BUILD_TOOLBAR, WDF_CONSTRUCTION, _nested_build_bridge_widgets, lengthof(_nested_build_bridge_widgets))
| Window definition for the rail bridge selection window.

## Detailed Description

Graphical user interface for bridge construction.

Definition in file bridge_gui.cpp.

## Enumeration Type Documentation

enum BuildBridgeSelectionWidgets

Names of the widgets of the build-bridge selection window.

Definition at line 74 of file bridge_gui.cpp.

## Function Documentation

void CcBuildBridge | ( | const CommandCost & | result,
|  | TileIndex | end_tile,
|  | uint32 | p1,
|  | uint32 | p2 |
| ) |  |  |

Callback executed after a build Bridge CMD has been called.

Parameters:

  | result | Whether the build succeeded
  | end_tile | End tile of the bridge.
  | p1 | packed start tile coords (~ dx)
  | p2 | various bitstuffed elements p2 = (bit 0- 7) - bridge type (hi bh) p2 = (bit 8-11) - rail type or road types. p2 = (bit 15-16) - transport type.

Definition at line 57 of file bridge_gui.cpp.

References ConnectRoadToStructure(), CommandCost::Failed(), GetTunnelBridgeDirection(), ReverseDiagDir(), and TRANSPORT_ROAD.

Referenced by BuildDocksToolbarWindow::OnPlaceObject(), and ShowBuildBridgeWindow().

void ShowBuildBridgeWindow | ( | TileIndex | start,
|  | TileIndex | end,
|  | TransportType | transport_type,
|  | byte | road_rail_type |
| ) |  |  |

Prepare the data for the build a bridge window.

If we can't build a bridge under the given conditions show an error message.

Parameters:

  | start | The start tile of the bridge
  | end | The end tile of the bridge
  | transport_type | The transport type
  | road_rail_type | The road/rail type

Definition at line 378 of file bridge_gui.cpp.

References _build_bridge_desc, _ctrl_pressed, _last_railbridge_type, _last_roadbridge_type, SmallVector< T, S >::Append(), CalcBridgeLenCostFactor(), CcBuildBridge(), CheckBridgeAvailability(), CMD_BUILD_BRIDGE, CMD_MSG, CommandFlagsToDCFlags(), DC_QUERY_COST, DeleteWindowByClass(), DoCommand(), DoCommandP(), CommandCost::Failed(), GetCommandFlags(), CommandCost::GetCost(), CommandCost::GetErrorMessage(), GetTunnelBridgeLength(), INVALID_STRING_ID, SmallVector< T, S >::Length(), MAX_BRIDGES, BridgeSpec::price, RailBuildCost(), ShowErrorMessage(), CommandCost::Succeeded(), TILE_SIZE, TileX(), TileY(), TRANSPORT_RAIL, TRANSPORT_ROAD, and WL_INFO.

Referenced by BuildRoadToolbarWindow::OnPlaceMouseUp(), and BuildRailToolbarWindow::OnPlaceMouseUp().

## Variable Documentation

const WindowDesc _build_bridge_desc(WDP_AUTO, 200, 114, WC_BUILD_BRIDGE, WC_BUILD_TOOLBAR, WDF_CONSTRUCTION, _nested_build_bridge_widgets, lengthof(_nested_build_bridge_widgets))`[static]`

Window definition for the rail bridge selection window.

Referenced by ShowBuildBridgeWindow().

const NWidgetPart _nested_build_bridge_widgets[]`[static]`

Initial value:

     {

      NWidget(NWID_HORIZONTAL),
        NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
        NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, BBSW_CAPTION), SetDataTip(STR_SELECT_RAIL_BRIDGE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
      EndContainer(),

      NWidget(NWID_HORIZONTAL),
        NWidget(NWID_VERTICAL),

          NWidget(NWID_HORIZONTAL),
            NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, BBSW_DROPDOWN_ORDER), SetFill(1, 0), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
            NWidget(WWT_DROPDOWN, COLOUR_DARK_GREEN, BBSW_DROPDOWN_CRITERIA), SetFill(1, 0), SetDataTip(0x0, STR_TOOLTIP_SORT_CRITERIA),
          EndContainer(),

          NWidget(WWT_MATRIX, COLOUR_DARK_GREEN, BBSW_BRIDGE_LIST), SetFill(1, 0), SetResize(0, 22), SetDataTip(0x401, STR_SELECT_BRIDGE_SELECTION_TOOLTIP), SetScrollbar(BBSW_SCROLLBAR),
        EndContainer(),

        NWidget(NWID_VERTICAL),
          NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, BBSW_SCROLLBAR),
          NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
        EndContainer(),
      EndContainer(),
    }

Widgets of the bridge gui.

Definition at line 334 of file bridge_gui.cpp.