OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
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();
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;
151 this->bridges->
SetListing(this->last_sorting);
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 = std::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);
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);
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),
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)) {
429 bool any_available =
false;
437 item.index = brd_type;
441 item.cost = ret.
GetCost() + (((int64)tot_bridgedata_len * _price[PR_BUILD_BRIDGE] * item.spec->
price) >> 8) + infra_cost;
442 any_available =
true;
452 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.
#define CMD_MSG(x)
Used to combine a StringID with the command.
uint32 TileIndex
The index/ID of a Tile.
void OnResize() override
Called after the window got resized.
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
uint8 SortType() const
Get the sorttype of the list.
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
@ WD_MATRIX_RIGHT
Offset at right of a matrix cell.
char32_t WChar
Type for wide characters, i.e.
int CalcBridgeLenCostFactor(int x)
Calculate the price factor for building a long bridge.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
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.
@ SND_27_CONSTRUCTION_BRIDGE
37 == 0x25 Construction: bridge
static const StringID sorter_names[]
Names of the sorting functions.
@ TRANSPORT_RAIL
Transport by train.
List template of 'things' T to sort in a GUI.
@ INVALID_ROADTYPE
flag for invalid roadtype
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.
@ CMD_BUILD_BRIDGE
build a bridge
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.
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
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.
TransportType
Available types of transport.
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.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
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.
void CcBuildBridge(const CommandCost &result, TileIndex end_tile, uint32 p1, uint32 p2, uint32 cmd)
Callback executed after a build Bridge CMD has been called.
High level window description.
Struct containing information about a single bridge type.
@ TRANSPORT_ROAD
Transport by road vehicle.
static const BridgeSpec * GetBridgeSpec(BridgeType i)
Get the specification of a bridge type.
SpriteID sprite
the sprite which is used in the GUI
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
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
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.
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:
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.
RoadType
The different roadtypes we support.
CommandFlags GetCommandFlags(uint32 cmd)
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
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.
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)
static DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
#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.
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.
@ WD_MATRIX_LEFT
Offset at left of a matrix cell.
@ 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.