29 #include "table/strings.h" 63 if (result.
Failed())
return;
66 TransportType transport_type = Extract<TransportType, 15, 2>(p2);
98 return a.index < b.index;
104 return a.cost < b.cost;
113 void BuildBridge(uint8 i)
120 DoCommandP(this->end_tile, this->start_tile, this->type | this->bridges->at(i).index,
127 this->bridges->
Sort();
144 this->CreateNestedTree();
147 this->GetWidget<NWidgetCore>(
WID_BBS_CAPTION)->widget_data = (
GB(this->type, 15, 2) ==
TRANSPORT_ROAD) ? STR_SELECT_ROAD_BRIDGE_CAPTION : STR_SELECT_RAIL_BRIDGE_CAPTION;
148 this->FinishInitNested(
GB(br_type, 15, 2));
151 this->bridges->
SetListing(this->last_sorting);
154 this->SortBridgeList();
156 this->vscroll->
SetCount((uint)bl->size());
161 this->last_sorting = this->bridges->
GetListing();
172 d.height += padding.height;
181 d.width += padding.width;
182 d.height += padding.height;
189 for (
int i = 0; i < (int)this->bridges->size(); i++) {
190 const BridgeSpec *b = this->bridges->at(i).spec;
196 text_dim =
maxdim(text_dim,
GetStringBoundingBox(_game_mode == GM_EDITOR ? STR_SELECT_BRIDGE_SCENEDIT_INFO : STR_SELECT_BRIDGE_INFO));
200 resize->height =
max(sprite_dim.height, text_dim.height) + 2;
203 size->width = this->bridgetext_offset + text_dim.width +
WD_MATRIX_RIGHT;
204 size->height = 4 * resize->height;
216 corner.x =
Clamp(_cursor.
pos.x - list->
pos_x - 5, 0, _screen.width - sm_width);
229 for (
int i = this->vscroll->
GetPosition(); this->vscroll->
IsVisible(i) && i < (int)this->bridges->size(); i++) {
230 const BridgeSpec *b = this->bridges->at(i).spec;
237 DrawStringMultiLine(r.left + this->bridgetext_offset, r.right, y + 2, y + this->resize.step_height,
238 _game_mode == GM_EDITOR ? STR_SELECT_BRIDGE_SCENEDIT_INFO : STR_SELECT_BRIDGE_INFO);
239 y += this->resize.step_height;
248 const uint8 i = keycode -
'1';
249 if (i < 9 && i < this->bridges->size()) {
251 this->BuildBridge(i);
264 if (i < this->bridges->size()) {
265 this->BuildBridge(i);
287 this->SortBridgeList();
311 STR_SORT_BY_MAX_SPEED,
332 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),
348 _nested_build_bridge_widgets,
lengthof(_nested_build_bridge_widgets)
369 uint32 type = (transport_type << 15) | (road_rail_type << 8);
380 switch (transport_type) {
404 Money infra_cost = 0;
405 switch (transport_type) {
411 road_rt = GetRoadTypeRoad(start);
412 tram_rt = GetRoadTypeTram(start);
414 if (RoadTypeIsRoad((
RoadType)road_rail_type)) {
435 item.index = brd_type;
439 item.cost = ret.
GetCost() + (((int64)tot_bridgedata_len * _price[PR_BUILD_BRIDGE] * item.spec->
price) >> 8) + infra_cost;
444 if (bl !=
nullptr && bl->size() != 0) {
EventState
State of handling an event.
static GUIBridgeList::SortFunction *const sorter_funcs[]
Available bridge sorting functions.
Functions related to OTTD's strings.
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.
Base types for having sorted lists in GUIs.
List template of 'things' T to sort in a GUI.
GUIList< BuildBridgeData > GUIBridgeList
List of bridges, used in BuildBridgeWindow.
static BridgeType _last_roadbridge_type
The type of the last built road bridge.
int CalcBridgeLenCostFactor(int x)
Calculate the price factor for building a long bridge.
Offset at right of a matrix cell.
Point pos
logical mouse position
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
High level window description.
void ConnectRoadToStructure(TileIndex tile, DiagDirection direction)
If required, connects a new structure to an existing road or tram by building the missing roadbit...
void OnResize() override
Called after the window got resized.
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
EventState OnKeyPress(WChar key, uint16 keycode) override
A key has been pressed.
Functions/types related to the road GUIs.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
The passed event is not handled.
query cost only, don't build.
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
static const StringID sorter_names[]
Names of the sorting functions.
static bool BridgePriceSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their price.
static uint TileX(TileIndex tile)
Get the X component of a tile.
flag for invalid roadtype
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.
uint16 speed
maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
Helper functions to extract data from command parameters.
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0...
Money GetCost() const
The costs as made up to this moment.
Common return value for all commands.
void CcBuildBridge(const CommandCost &result, TileIndex end_tile, uint32 p1, uint32 p2, uint32 cmd)
Callback executed after a build Bridge CMD has been called.
CommandFlags GetCommandFlags(uint32 cmd)
RoadType
The different roadtypes we support.
static T max(const T a, const T b)
Returns the maximum of two values.
Window class for handling the bridge-build GUI.
Struct containing information about a single bridge type.
void SetListing(Listing l)
Import sort conditions.
static const uint TILE_SIZE
Tile size in world coordinates.
int GetMainViewBottom()
Return the bottom of the main view available for general use.
static bool BridgeIndexSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their index.
Data structure for an opened window.
bool _ctrl_pressed
Is Ctrl pressed?
static Listing last_sorting
Last setting of the sort.
Functions related to errors.
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
static BridgeType _last_railbridge_type
The type of the last built rail bridge.
This window is used for construction; close it whenever changing company.
SoundSettings sound
sound effect settings
Header file for things common for tunnels and bridges.
static const NWidgetPart _nested_build_bridge_widgets[]
Widgets of the bridge gui.
Listing GetListing() const
Export current sort conditions.
StringID GetErrorMessage() const
Returns the error message of a command.
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
static uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
Functions related to the gfx engine.
ClientSettings _settings_client
The current settings for this game.
bool Succeeded() const
Did this command succeed?
Definition of base types and functions in a cross-platform compatible way.
int GetMainViewTop()
Return the top of the main view available for general use.
static const BridgeSpec * GetBridgeSpec(BridgeType i)
Get the specification of a bridge type.
A number of safeguards to prevent using unsafe methods.
void SortBridgeList()
Sort the builable bridges.
Offset at left of a matrix cell.
SpriteID sprite
the sprite which is used in the GUI
Carriage for the data we need if we want to build a bridge.
static Money RoadBuildCost(RoadType roadtype)
Returns the cost of building the specified roadtype.
PaletteID pal
the palette which is used in the GUI
static DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
#define lengthof(x)
Return the length of an fixed size array.
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, byte road_rail_type)
Prepare the data for the build a bridge window.
Build bridge; Window numbers:
CommandCost CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoCommandFlag flags=DC_NONE)
Is a bridge of the specified type and length available?
Functions related to sound.
void SetSortType(uint8 n_type)
Set the sorttype of the list.
bool Sort(SortFunction *compare)
Sort the list.
static bool BridgeSpeedSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their maximum speed.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
bool Failed() const
Did this command fail?
uint16 price
the price multiplier
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Build toolbar; Window numbers:
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.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
StringID material
the string that contains the bridge description
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.
RailType
Enumeration for all possible railtypes.
uint32 TileIndex
The index/ID of a Tile.
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here...
static Money RailBuildCost(RailType railtype)
Returns the cost of building the specified railtype.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
static const uint MAX_BRIDGES
Maximal number of available bridge specs.
TransportType
Available types of transport.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Functions related to the drop down widget.
Transport by road vehicle.
bool confirm
Play sound effect on successful constructions or other actions.
Functions related to commands.
Coordinates of a point in 2D.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
uint BridgeType
Bridge spec number.
Data structure describing how to show the list (what sort direction and criteria).
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Functions that have tunnels and bridges in common.
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
Compute the initial position of the window.
DiagDirection
Enumeration for diagonal directions.
bool IsDescSortOrder() const
Check if the sort order is descending.
#define CMD_MSG(x)
Used to combine a StringID with the command.
Specification of a rectangle with absolute coordinates of all edges.
The passed event is handled.
Window functions not directly related to making/drawing windows.
Find a place automatically.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
bool SortFunction(const T &, const T &)
Signature of sort function.
uint32 WChar
Type for wide characters, i.e.
int bridgetext_offset
Horizontal offset of the text describing the bridge properties in WID_BBS_BRIDGE_LIST relative to the...
Dimensions (a width and height) of a rectangle in 2D.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
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.
uint8 SortType() const
Get the sorttype of the list.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.