30 #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->
Get(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();
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->
Length(); i++) {
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);
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->
Length()) {
251 this->BuildBridge(i);
264 if (i < this->bridges->
Length()) {
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) {
407 infra_cost = (bridge_len + 2) * _price[PR_BUILD_ROAD] * 2;
420 item->index = brd_type;
424 item->cost = ret.
GetCost() + (((int64)tot_bridgedata_len * _price[PR_BUILD_BRIDGE] * item->spec->
price) >> 8) + infra_cost;
429 if (bl != NULL && bl->
Length() != 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
RailType
Enumeration for all possible railtypes.
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...
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
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 uint TileX(TileIndex tile)
Get the X component of a tile.
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.
CommandFlags GetCommandFlags(uint32 cmd)
static T max(const T a, const T b)
Returns the maximum of two values.
Window class for handling the bridge-build GUI.
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
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.
T * Append(uint to_add=1)
Append an item and return it.
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Data structure for an opened window.
bool _ctrl_pressed
Is Ctrl pressed?
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=NULL, uint textref_stack_size=0, const uint32 *textref_stack=NULL)
Display an error message in a window.
static Listing last_sorting
Last setting of the sort.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
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.
uint Length() const
Get the number of items in the list.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
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.
virtual void OnDropdownSelect(int widget, int index)
A dropdown option associated to this window has been selected.
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.
virtual void OnResize()
Called after the window got resized.
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.
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.
DiagDirection
Enumeration for diagonal directions.
#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 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.
static int CDECL BridgeSpeedSorter(const BuildBridgeData *a, const BuildBridgeData *b)
Sort the bridges by their maximum speed.
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
bool Failed() const
Did this command fail?
RoadTypes
The different roadtypes we support, but then a bitmask of them.
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.
virtual EventState OnKeyPress(WChar key, uint16 keycode)
A key has been pressed.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
StringID material
the string that contains the bridge description
static int CDECL BridgeIndexSorter(const BuildBridgeData *a, const BuildBridgeData *b)
Sort the bridges by their index.
void CcBuildBridge(const CommandCost &result, TileIndex end_tile, uint32 p1, uint32 p2)
Callback executed after a build Bridge CMD has been called.
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.
virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
Compute the initial position of the window.
int CDECL SortFunction(const T *, const T *)
Signature of sort function.
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 succesful constructions or other actions.
static uint CountBits(T value)
Counts the number of set bits in a variable.
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).
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.
static RoadTypes GetRoadTypes(TileIndex t)
Get the present road types of a tile.
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
bool IsDescSortOrder() const
Check if the sort order is descending.
const T * Get(uint index) const
Get the pointer to item "number" (const)
#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.
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.
static int CDECL BridgePriceSorter(const BuildBridgeData *a, const BuildBridgeData *b)
Sort the bridges by their price.
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.