29#include "table/strings.h"
59 if (result.
Failed())
return;
78 static inline const StringID sorter_names[] = {
83 static const std::initializer_list<GUIBridgeList::SortFunction * const>
sorter_funcs;
97 return a.index < b.index;
103 return a.cost < b.cost;
114 switch (this->transport_type) {
120 this->end_tile, this->start_tile, this->transport_type, type, this->road_rail_type);
126 this->bridges.
Sort();
157 transport_type(transport_type),
158 road_rail_type(road_rail_type),
173 this->vscroll->
SetCount(this->bridges.size());
187 d.height += padding.height;
193 d.width += padding.width;
194 d.height += padding.height;
209 size.height = 4 *
resize.height;
236 for (
auto it = first; it !=
last; ++it) {
249 const uint8_t i = keycode -
'1';
252 this->BuildBridge(this->bridges[i].index);
265 if (it != this->bridges.end()) {
266 this->BuildBridge(it->index);
325 NWidget(
WWT_MATRIX, COLOUR_DARK_GREEN,
WID_BBS_BRIDGE_LIST),
SetFill(1, 0),
SetResize(0, 22),
SetMatrixDataTip(1, 0, STR_SELECT_BRIDGE_SELECTION_TOOLTIP),
SetScrollbar(
WID_BBS_SCROLLBAR),
367 switch (transport_type) {
389 Money infra_cost = 0;
390 switch (transport_type) {
396 road_rt = GetRoadTypeRoad(start);
397 tram_rt = GetRoadTypeTram(start);
399 if (RoadTypeIsRoad((
RoadType)road_rail_type)) {
414 bool any_available =
false;
422 item.index = brd_type;
426 item.cost = ret.
GetCost() + (((int64_t)tot_bridgedata_len * _price[PR_BUILD_BRIDGE] * item.spec->
price) >> 8) + infra_cost;
427 any_available =
true;
int CalcBridgeLenCostFactor(int x)
Calculate the price factor for building a long bridge.
const BridgeSpec * GetBridgeSpec(BridgeType i)
Get the specification of a bridge type.
uint BridgeType
Bridge spec number.
static const uint MAX_BRIDGES
Maximal number of available bridge specs.
CommandCost CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoCommandFlag flags=DC_NONE)
Is a bridge of the specified type and length available?
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, uint8_t road_rail_type)
Prepare the data for the build a bridge window.
static WindowDesc _build_bridge_desc(WDP_AUTO, "build_bridge", 200, 114, WC_BUILD_BRIDGE, WC_BUILD_TOOLBAR, WDF_CONSTRUCTION, _nested_build_bridge_widgets)
Window definition for the rail bridge selection window.
void CcBuildBridge(Commands, const CommandCost &result, TileIndex end_tile, TileIndex tile_start, TransportType transport_type, BridgeType, uint8_t)
Callback executed after a build Bridge CMD has been called.
GUIList< BuildBridgeData > GUIBridgeList
List of bridges, used in BuildBridgeWindow.
static BridgeType _last_railbridge_type
The type of the last built rail bridge.
static constexpr NWidgetPart _nested_build_bridge_widgets[]
Widgets of the bridge gui.
static BridgeType _last_roadbridge_type
The type of the last built road bridge.
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
Window class for handling the bridge-build GUI.
void OnResize() override
Called after the window got resized.
void SortBridgeList()
Sort the builable bridges.
void OnDropdownSelect(WidgetID widget, int index) override
A dropdown option associated to this window has been selected.
static bool BridgePriceSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their price.
EventState OnKeyPress(char32_t key, uint16_t keycode) override
A key has been pressed.
StringID GetBridgeSelectString(const BuildBridgeData &bridge_data) const
Get the StringID to draw in the selection list and set the appropriate DParams.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Point OnInitialPosition(int16_t sm_width, int16_t sm_height, int window_number) override
Compute the initial position of the window.
static bool BridgeSpeedSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their maximum speed.
static bool BridgeIndexSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their index.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
static const std::initializer_list< GUIBridgeList::SortFunction *const > sorter_funcs
Available bridge sorting functions.
static Listing last_sorting
Last setting of the sort.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
int icon_width
Scaled width of the the bridge icon sprite.
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
Money GetCost() const
The costs as made up to this moment.
bool Failed() const
Did this command fail?
StringID GetErrorMessage() const
Returns the error message of a command.
List template of 'things' T to sort in a GUI.
void SetListing(Listing l)
Import sort conditions.
bool IsDescSortOrder() const
Check if the sort order is descending.
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
bool Sort(Comp compare)
Sort the list.
uint8_t SortType() const
Get the sorttype of the list.
Listing GetListing() const
Export current sort conditions.
void SetSortFuncs(std::span< SortFunction *const > n_funcs)
Hand the sort function pointers to the GUIList.
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
void SetSortType(uint8_t n_type)
Set the sorttype of the list.
Functions related to commands.
static constexpr DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
@ DC_QUERY_COST
query cost only, don't build.
Commands
List of commands.
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
DiagDirection
Enumeration for diagonal directions.
void ShowDropDownMenu(Window *w, std::span< const StringID > strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
Functions related to the drop down widget.
Functions related to errors.
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Dimension GetStringListBoundingBox(std::span< const StringID > list, FontSize fontsize)
Get maximum dimension of a list of strings.
bool _ctrl_pressed
Is Ctrl pressed?
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Functions related to the gfx engine.
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
@ SA_HOR_CENTER
Horizontally center the text.
@ SA_BOTTOM
Bottom align the text.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Money RailBuildCost(RailType railtype)
Returns the cost of building the specified railtype.
RailType
Enumeration for all possible railtypes.
Money RoadBuildCost(RoadType roadtype)
Returns the cost of building the specified roadtype.
void ConnectRoadToStructure(TileIndex tile, DiagDirection direction)
If required, connects a new structure to an existing road or tram by building the missing roadbit.
Functions/types related to the road GUIs.
RoadType
The different roadtypes we support.
@ INVALID_ROADTYPE
flag for invalid roadtype
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
Base types for having sorted lists in GUIs.
Functions related to sound.
@ SND_27_CONSTRUCTION_BRIDGE
37 == 0x25 Construction: bridge
Definition of base types and functions in a cross-platform compatible way.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
TextDirection _current_text_dir
Text direction of the currently selected language.
Functions related to OTTD's strings.
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
@ TD_RTL
Text is written right-to-left by default.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Struct containing information about a single bridge type.
uint16_t price
the price multiplier
PaletteID pal
the palette which is used in the GUI
SpriteID sprite
the sprite which is used in the GUI
uint16_t speed
maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
Carriage for the data we need if we want to build a bridge.
SoundSettings sound
sound effect settings
Point pos
logical mouse position
Dimensions (a width and height) of a rectangle in 2D.
Data structure describing how to show the list (what sort direction and criteria).
Coordinates of a point in 2D.
Specification of a rectangle with absolute coordinates of all edges.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
uint step_height
Step-size of height resize changes.
bool confirm
Play sound effect on successful constructions or other actions.
High level window description.
Data structure for an opened window.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Window * parent
Parent window.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
ResizeInfo resize
Resize information.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
WindowNumber window_number
Window number within the window class.
static const uint TILE_SIZE
Tile size in world coordinates.
TransportType
Available types of transport.
@ TRANSPORT_RAIL
Transport by train.
@ TRANSPORT_ROAD
Transport by road vehicle.
Header file for things common for tunnels and bridges.
uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
Command definitions related to tunnels and bridges.
Functions that have tunnels and bridges in common.
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
VehicleType
Available vehicle types.
int GetMainViewTop()
Return the top of the main view available for general use.
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Window functions not directly related to making/drawing windows.
@ SBS_DOWN
Sort ascending.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
@ WDP_AUTO
Find a place automatically.
EventState
State of handling an event.
@ ES_HANDLED
The passed event is handled.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
@ WC_BUILD_BRIDGE
Build bridge; Window numbers: