Go to the documentation of this file.
29 #include "table/strings.h"
60 if (result.
Failed())
return;
94 return a.index < b.index;
100 return a.cost < b.cost;
109 void BuildBridge(uint8 i)
111 switch (this->transport_type) {
117 this->end_tile, this->start_tile, this->transport_type, this->bridges->at(i).index, this->road_rail_type);
123 this->bridges->
Sort();
144 if (bridge_data.spec->
speed == UINT16_MAX) {
145 return _game_mode == GM_EDITOR ? STR_SELECT_BRIDGE_INFO_NAME : STR_SELECT_BRIDGE_INFO_NAME_COST;
147 return _game_mode == GM_EDITOR ? STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED : STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED_COST;
154 transport_type(transport_type),
155 road_rail_type(road_rail_type),
161 this->GetWidget<NWidgetCore>(
WID_BBS_CAPTION)->widget_data = (transport_type ==
TRANSPORT_ROAD) ? STR_SELECT_ROAD_BRIDGE_CAPTION : STR_SELECT_RAIL_BRIDGE_CAPTION;
165 this->bridges->
SetListing(this->last_sorting);
170 this->vscroll->
SetCount((uint)bl->size());
175 this->last_sorting = this->bridges->
GetListing();
186 d.height += padding.height;
195 d.width += padding.width;
196 d.height += padding.height;
209 resize->height = std::max(sprite_dim.height, text_dim.height) + padding.height;
212 size->width = this->bridgetext_offset + text_dim.width + padding.width;
213 size->height = 4 *
resize->height;
225 corner.x =
Clamp(_cursor.
pos.x - list->
pos_x - 5, 0, _screen.width - sm_width);
238 for (
int i = this->vscroll->
GetPosition(); this->vscroll->IsVisible(i) && i < (
int)this->bridges->size(); i++) {
252 const uint8 i = keycode -
'1';
253 if (i < 9 && i < this->bridges->size()) {
255 this->BuildBridge(i);
268 if (i < this->bridges->size()) {
269 this->BuildBridge(i);
315 STR_SORT_BY_MAX_SPEED,
336 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),
378 switch (transport_type) {
402 Money infra_cost = 0;
403 switch (transport_type) {
409 road_rt = GetRoadTypeRoad(start);
410 tram_rt = GetRoadTypeTram(start);
412 if (RoadTypeIsRoad((
RoadType)road_rail_type)) {
427 bool any_available =
false;
435 item.index = brd_type;
439 item.cost = ret.
GetCost() + (((int64)tot_bridgedata_len * _price[PR_BUILD_BRIDGE] * item.spec->
price) >> 8) + infra_cost;
440 any_available =
true;
450 if (bl !=
nullptr && bl->size() != 0) {
@ ES_HANDLED
The passed event is handled.
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
Compute the initial position of the window.
void OnResize() override
Called after the window got resized.
uint8 SortType() const
Get the sorttype of the list.
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
char32_t WChar
Type for wide characters, i.e.
int CalcBridgeLenCostFactor(int x)
Calculate the price factor for building a long bridge.
EventState OnKeyPress(WChar key, uint16 keycode) override
A key has been pressed.
Dimensions (a width and height) of a rectangle in 2D.
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
bool Sort(Comp compare)
Sort the list.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Commands
List of commands.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
@ SND_27_CONSTRUCTION_BRIDGE
37 == 0x25 Construction: bridge
static const StringID sorter_names[]
Names of the sorting functions.
static constexpr DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
List template of 'things' T to sort in a GUI.
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
bool _ctrl_pressed
Is Ctrl pressed?
static Listing last_sorting
Last setting of the sort.
static const uint TILE_SIZE
Tile size in world coordinates.
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
ClientSettings _settings_client
The current settings for this game.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
static bool BridgePriceSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their price.
void SetSortType(uint8 n_type)
Set the sorttype of the list.
uint16 speed
maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
StringID GetErrorMessage() const
Returns the error message of a command.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
@ INVALID_ROADTYPE
flag for invalid roadtype
bool Succeeded() const
Did this command succeed?
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
static uint TileX(TileIndex tile)
Get the X component of a tile.
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
High level window description.
Struct containing information about a single bridge type.
static const BridgeSpec * GetBridgeSpec(BridgeType i)
Get the specification of a bridge type.
SpriteID sprite
the sprite which is used in the GUI
@ TRANSPORT_RAIL
Transport by train.
static const NWidgetPart _nested_build_bridge_widgets[]
Widgets of the bridge gui.
bool IsDescSortOrder() const
Check if the sort order is descending.
@ WDP_AUTO
Find a place automatically.
Data structure describing how to show the list (what sort direction and criteria).
RailType
Enumeration for all possible railtypes.
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
ResizeInfo resize
Resize information.
Common return value for all commands.
SoundSettings sound
sound effect settings
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
static const uint MAX_BRIDGES
Maximal number of available bridge specs.
bool SortFunction(const T &, const T &)
Signature of sort function.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
void SetListing(Listing l)
Import sort conditions.
TransportType
Available types of transport.
static BridgeType _last_railbridge_type
The type of the last built rail bridge.
@ ES_NOT_HANDLED
The passed event is not handled.
bool Failed() const
Did this command fail?
CommandCost CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoCommandFlag flags=DC_NONE)
Is a bridge of the specified type and length available?
int GetMainViewTop()
Return the top of the main view available for general use.
PaletteID pal
the palette which is used in the GUI
static bool BridgeIndexSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their index.
static Money RailBuildCost(RailType railtype)
Returns the cost of building the specified railtype.
Window * parent
Parent window.
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
@ WC_BUILD_BRIDGE
Build bridge; Window numbers:
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Money GetCost() const
The costs as made up to this moment.
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Coordinates of a point in 2D.
DiagDirection
Enumeration for diagonal directions.
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
uint BridgeType
Bridge spec number.
WindowNumber window_number
Window number within the window class.
uint step_height
Step-size of height resize changes.
Window class for handling the bridge-build GUI.
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
static WindowDesc _build_bridge_desc(WDP_AUTO, "build_bridge", 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.
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, byte road_rail_type)
Prepare the data for the build a bridge window.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
@ SBS_DOWN
Sort ascending.
bool confirm
Play sound effect on successful constructions or other actions.
void SortBridgeList()
Sort the builable bridges.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
uint16 price
the price multiplier
StringID GetBridgeSelectString(const BuildBridgeData &bridge_data) const
Get the StringID to draw in the selection list and set the appropriate DParams.
void CloseWindowByClass(WindowClass cls)
Close all windows of a given class.
Listing GetListing() const
Export current sort conditions.
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
EventState
State of handling an event.
static bool BridgeSpeedSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their maximum speed.
RoadType
The different roadtypes we support.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Carriage for the data we need if we want to build a bridge.
int bridgetext_offset
Horizontal offset of the text describing the bridge properties in WID_BBS_BRIDGE_LIST relative to the...
static uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
void CcBuildBridge(Commands cmd, const CommandCost &result, TileIndex end_tile, TileIndex tile_start, TransportType transport_type, BridgeType, byte)
Callback executed after a build Bridge CMD has been called.
#define lengthof(x)
Return the length of an fixed size array.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
StringID material
the string that contains the bridge description
static Money RoadBuildCost(RoadType roadtype)
Returns the cost of building the specified roadtype.
@ TRANSPORT_ROAD
Transport by road vehicle.
static GUIBridgeList::SortFunction *const sorter_funcs[]
Available bridge sorting functions.
Data structure for an opened window.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
@ DC_QUERY_COST
query cost only, don't build.
void ConnectRoadToStructure(TileIndex tile, DiagDirection direction)
If required, connects a new structure to an existing road or tram by building the missing roadbit.
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Specification of a rectangle with absolute coordinates of all edges.
Point pos
logical mouse position
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
GUIList< BuildBridgeData > GUIBridgeList
List of bridges, used in BuildBridgeWindow.
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
static BridgeType _last_roadbridge_type
The type of the last built road bridge.
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.