|
OpenTTD Source
14.0-beta1
|
Go to the documentation of this file.
29 #include "table/strings.h"
59 if (result.
Failed())
return;
93 return a.index < b.index;
99 return a.cost < b.cost;
110 switch (this->transport_type) {
116 this->end_tile, this->start_tile, this->transport_type, type, this->road_rail_type);
122 this->bridges.
Sort();
143 if (bridge_data.spec->
speed == UINT16_MAX) {
144 return _game_mode == GM_EDITOR ? STR_SELECT_BRIDGE_INFO_NAME : STR_SELECT_BRIDGE_INFO_NAME_COST;
146 return _game_mode == GM_EDITOR ? STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED : STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED_COST;
153 transport_type(transport_type),
154 road_rail_type(road_rail_type),
155 bridges(std::move(bl))
160 this->GetWidget<NWidgetCore>(
WID_BBS_CAPTION)->widget_data = (transport_type ==
TRANSPORT_ROAD) ? STR_SELECT_ROAD_BRIDGE_CAPTION : STR_SELECT_RAIL_BRIDGE_CAPTION;
169 this->vscroll->
SetCount(this->bridges.size());
174 this->last_sorting = this->bridges.
GetListing();
183 d.height += padding.height;
192 d.width += padding.width;
193 d.height += padding.height;
204 resize->height = std::max(sprite_dim.height, text_dim.height) + padding.height;
206 this->icon_width = sprite_dim.width;
208 size->height = 4 *
resize->height;
214 Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]]
int window_number)
override
220 corner.x =
Clamp(_cursor.
pos.x - list->
pos_x - 5, 0, _screen.width - sm_width);
224 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
234 for (
int i = this->vscroll->
GetPosition(); this->vscroll->IsVisible(i) && i < (
int)this->bridges.size(); i++) {
239 tr = tr.
Translate(0, this->resize.step_height);
246 EventState OnKeyPress([[maybe_unused]] char32_t key, uint16_t keycode)
override
248 const uint8_t i = keycode -
'1';
249 if (i < 9 && i < this->bridges.size()) {
251 this->BuildBridge(this->bridges[i].index);
258 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
264 if (it != this->bridges.end()) {
265 this->BuildBridge(it->index);
272 this->bridges.ToggleSortOrder();
282 void OnDropdownSelect(
WidgetID widget,
int index)
override
285 this->bridges.SetSortType(index);
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),
374 switch (transport_type) {
396 Money infra_cost = 0;
397 switch (transport_type) {
403 road_rt = GetRoadTypeRoad(start);
404 tram_rt = GetRoadTypeTram(start);
406 if (RoadTypeIsRoad((
RoadType)road_rail_type)) {
421 bool any_available =
false;
429 item.index = brd_type;
433 item.cost = ret.
GetCost() + (((int64_t)tot_bridgedata_len * _price[PR_BUILD_BRIDGE] * item.spec->
price) >> 8) + infra_cost;
434 any_available =
true;
@ ES_HANDLED
The passed event is handled.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
static WindowDesc _build_bridge_desc(__FILE__, __LINE__, WDP_AUTO, "build_bridge", 200, 114, WC_BUILD_BRIDGE, WC_BUILD_TOOLBAR, WDF_CONSTRUCTION, std::begin(_nested_build_bridge_widgets), std::end(_nested_build_bridge_widgets))
Window definition for the rail bridge selection window.
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
void OnResize() override
Called after the window got resized.
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
int CalcBridgeLenCostFactor(int x)
Calculate the price factor for building a long bridge.
Dimensions (a width and height) of a rectangle in 2D.
uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
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.
int icon_width
Scaled width of the the bridge icon sprite.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
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.
@ SA_BOTTOM
Bottom align the text.
ClientSettings _settings_client
The current settings for this game.
uint16_t speed
maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
static bool BridgePriceSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their price.
uint16_t price
the price multiplier
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
StringID GetErrorMessage() const
Returns the error message of a command.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
@ INVALID_ROADTYPE
flag for invalid roadtype
bool Succeeded() const
Did this command succeed?
High level window description.
Struct containing information about a single bridge type.
Money RoadBuildCost(RoadType roadtype)
Returns the cost of building the specified roadtype.
SpriteID sprite
the sprite which is used in the GUI
@ TRANSPORT_RAIL
Transport by train.
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
@ 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.
ResizeInfo resize
Resize information.
Common return value for all commands.
const BridgeSpec * GetBridgeSpec(BridgeType i)
Get the specification of a bridge type.
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.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
std::conditional_t< std::is_same_v< P, std::nullptr_t >, bool(const T &, const T &), bool(const T &, const T &, const P)> SortFunction
Signature of sort function.
TransportType
Available types of transport.
static BridgeType _last_railbridge_type
The type of the last built rail bridge.
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
@ 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.
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
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.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Coordinates of a point in 2D.
DiagDirection
Enumeration for diagonal directions.
void ShowDropDownMenu(Window *w, 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.
uint BridgeType
Bridge spec number.
WindowNumber window_number
Window number within the window class.
VehicleType
Available vehicle types.
Window class for handling the bridge-build GUI.
@ SA_HOR_CENTER
Horizontally center the text.
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, byte road_rail_type)
Prepare the data for the build a bridge window.
void CcBuildBridge(Commands, const CommandCost &result, TileIndex end_tile, TileIndex tile_start, TransportType transport_type, BridgeType, byte)
Callback executed after a build Bridge CMD has been called.
@ SBS_DOWN
Sort ascending.
bool confirm
Play sound effect on successful constructions or other actions.
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.
void SortBridgeList()
Sort the builable bridges.
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Listing GetListing() const
Export current sort conditions.
StringID GetBridgeSelectString(const BuildBridgeData &bridge_data) const
Get the StringID to draw in the selection list and set the appropriate DParams.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
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.
static constexpr NWidgetPart _nested_build_bridge_widgets[]
Widgets of the bridge gui.
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
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.
uint8_t SortType() const
Get the sorttype of the list.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
StringID material
the string that contains the bridge description
@ TRANSPORT_ROAD
Transport by road vehicle.
static GUIBridgeList::SortFunction *const sorter_funcs[]
Available bridge sorting functions.
Data structure for an opened window.
Commands
List of commands.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
@ 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.
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
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
bool Sort(Comp compare)
Sort the list.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Money RailBuildCost(RailType railtype)
Returns the cost of building the specified railtype.
GUIList< BuildBridgeData > GUIBridgeList
List of bridges, used in BuildBridgeWindow.
void SetListing(Listing l)
Import sort conditions.
static BridgeType _last_roadbridge_type
The type of the last built road bridge.
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.