OpenTTD Source: src/bridge_gui.cpp Source File

OpenTTD Source 14.0-beta3

bridge_gui.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "stdafx.h"
11 #include "error.h"
12 #include "command_func.h"
13 #include "rail.h"
14 #include "road.h"
15 #include "strings_func.h"
16 #include "window_func.h"
17 #include "sound_func.h"
18 #include "gfx_func.h"
19 #include "tunnelbridge.h"
20 #include "sortlist_type.h"
21 #include "widgets/dropdown_func.h"
22 #include "core/geometry_func.hpp"
23 #include "tunnelbridge_map.h"
24 #include "road_gui.h"
25 #include "tunnelbridge_cmd.h"
26
27 #include "widgets/bridge_widget.h"
28
29 #include "table/strings.h"
30
31 #include "safeguards.h"
32
34 static BridgeType _last_railbridge_type = 0;
36 static BridgeType _last_roadbridge_type = 0;
37
41 struct BuildBridgeData {
42 BridgeType index;
43 const BridgeSpec *spec;
44 Money cost;
45 };
46
47 typedef GUIList<BuildBridgeData> GUIBridgeList;
48
57 void CcBuildBridge(Commands, const CommandCost &result, TileIndex end_tile, TileIndex tile_start, TransportType transport_type, BridgeType, byte)
58 {
59 if (result.Failed()) return;
60 if (_settings_client.sound.confirm) SndPlayTileFx(SND_27_CONSTRUCTION_BRIDGE, end_tile);
61
62 if (transport_type == TRANSPORT_ROAD) {
63 DiagDirection end_direction = ReverseDiagDir(GetTunnelBridgeDirection(end_tile));
64 ConnectRoadToStructure(end_tile, end_direction);
65
66 DiagDirection start_direction = ReverseDiagDir(GetTunnelBridgeDirection(tile_start));
67 ConnectRoadToStructure(tile_start, start_direction);
68 }
69 }
70
72 class BuildBridgeWindow : public Window {
73 private:
74 /* Runtime saved values */
75 static Listing last_sorting;
76
77 /* Constants for sorting the bridges */
78 static const StringID sorter_names[];
79 static GUIBridgeList::SortFunction * const sorter_funcs[];
80
81 /* Internal variables */
82 TileIndex start_tile;
83 TileIndex end_tile;
84 TransportType transport_type;
85 byte road_rail_type;
86 GUIBridgeList bridges;
87 int icon_width;
88 Scrollbar *vscroll;
89
91 static bool BridgeIndexSorter(const BuildBridgeData &a, const BuildBridgeData &b)
92 {
93 return a.index < b.index;
94 }
95
97 static bool BridgePriceSorter(const BuildBridgeData &a, const BuildBridgeData &b)
98 {
99 return a.cost < b.cost;
100 }
101
103 static bool BridgeSpeedSorter(const BuildBridgeData &a, const BuildBridgeData &b)
104 {
105 return a.spec->speed < b.spec->speed;
106 }
107
108 void BuildBridge(BridgeType type)
109 {
110 switch (this->transport_type) {
111 case TRANSPORT_RAIL: _last_railbridge_type = type; break;
112 case TRANSPORT_ROAD: _last_roadbridge_type = type; break;
113 default: break;
114 }
115 Command<CMD_BUILD_BRIDGE>::Post(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE, CcBuildBridge,
116 this->end_tile, this->start_tile, this->transport_type, type, this->road_rail_type);
117 }
118
120 void SortBridgeList()
121 {
122 this->bridges.Sort();
123
124 /* Display the current sort variant */
125 this->GetWidget<NWidgetCore>(WID_BBS_DROPDOWN_CRITERIA)->widget_data = this->sorter_names[this->bridges.SortType()];
126
127 /* Set the modified widgets dirty */
128 this->SetWidgetDirty(WID_BBS_DROPDOWN_CRITERIA);
129 this->SetWidgetDirty(WID_BBS_BRIDGE_LIST);
130 }
131
137 StringID GetBridgeSelectString(const BuildBridgeData &bridge_data) const
138 {
139 SetDParam(0, bridge_data.spec->material);
140 SetDParam(1, PackVelocity(bridge_data.spec->speed, static_cast<VehicleType>(this->transport_type)));
141 SetDParam(2, bridge_data.cost);
142 /* If the bridge has no meaningful speed limit, don't display it. */
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;
145 }
146 return _game_mode == GM_EDITOR ? STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED : STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED_COST;
147 }
148
149 public:
150 BuildBridgeWindow(WindowDesc *desc, TileIndex start, TileIndex end, TransportType transport_type, byte road_rail_type, GUIBridgeList &&bl) : Window(desc),
151 start_tile(start),
152 end_tile(end),
153 transport_type(transport_type),
154 road_rail_type(road_rail_type),
155 bridges(std::move(bl))
156 {
157 this->CreateNestedTree();
158 this->vscroll = this->GetScrollbar(WID_BBS_SCROLLBAR);
159 /* Change the data, or the caption of the gui. Set it to road or rail, accordingly. */
160 this->GetWidget<NWidgetCore>(WID_BBS_CAPTION)->widget_data = (transport_type == TRANSPORT_ROAD) ? STR_SELECT_ROAD_BRIDGE_CAPTION : STR_SELECT_RAIL_BRIDGE_CAPTION;
161 this->FinishInitNested(transport_type); // Initializes 'this->icon_width'.
162
163 this->parent = FindWindowById(WC_BUILD_TOOLBAR, transport_type);
164 this->bridges.SetListing(this->last_sorting);
165 this->bridges.SetSortFuncs(this->sorter_funcs);
166 this->bridges.NeedResort();
167 this->SortBridgeList();
168
169 this->vscroll->SetCount(this->bridges.size());
170 }
171
172 ~BuildBridgeWindow()
173 {
174 this->last_sorting = this->bridges.GetListing();
175 }
176
177 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
178 {
179 switch (widget) {
180 case WID_BBS_DROPDOWN_ORDER: {
181 Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
182 d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
183 d.height += padding.height;
184 *size = maxdim(*size, d);
185 break;
186 }
187 case WID_BBS_DROPDOWN_CRITERIA: {
188 Dimension d = {0, 0};
189 for (const StringID *str = this->sorter_names; *str != INVALID_STRING_ID; str++) {
190 d = maxdim(d, GetStringBoundingBox(*str));
191 }
192 d.width += padding.width;
193 d.height += padding.height;
194 *size = maxdim(*size, d);
195 break;
196 }
197 case WID_BBS_BRIDGE_LIST: {
198 Dimension sprite_dim = {0, 0}; // Biggest bridge sprite dimension
199 Dimension text_dim = {0, 0}; // Biggest text dimension
200 for (const BuildBridgeData &bridge_data : this->bridges) {
201 sprite_dim = maxdim(sprite_dim, GetScaledSpriteSize(bridge_data.spec->sprite));
202 text_dim = maxdim(text_dim, GetStringBoundingBox(GetBridgeSelectString(bridge_data)));
203 }
204 resize->height = std::max(sprite_dim.height, text_dim.height) + padding.height; // Max of both sizes + account for matrix edges.
205
206 this->icon_width = sprite_dim.width; // Width of bridge icon.
207 size->width = this->icon_width + WidgetDimensions::scaled.hsep_normal + text_dim.width + padding.width;
208 size->height = 4 * resize->height; // Smallest bridge gui is 4 entries high in the matrix.
209 break;
210 }
211 }
212 }
213
214 Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
215 {
216 /* Position the window so hopefully the first bridge from the list is under the mouse pointer. */
217 NWidgetBase *list = this->GetWidget<NWidgetBase>(WID_BBS_BRIDGE_LIST);
218 Point corner; // point of the top left corner of the window.
219 corner.y = Clamp(_cursor.pos.y - list->pos_y - 5, GetMainViewTop(), GetMainViewBottom() - sm_height);
220 corner.x = Clamp(_cursor.pos.x - list->pos_x - 5, 0, _screen.width - sm_width);
221 return corner;
222 }
223
224 void DrawWidget(const Rect &r, WidgetID widget) const override
225 {
226 switch (widget) {
227 case WID_BBS_DROPDOWN_ORDER:
228 this->DrawSortButtonState(widget, this->bridges.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
229 break;
230
231 case WID_BBS_BRIDGE_LIST: {
232 Rect tr = r.WithHeight(this->resize.step_height).Shrink(WidgetDimensions::scaled.matrix);
233 bool rtl = _current_text_dir == TD_RTL;
234 for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < (int)this->bridges.size(); i++) {
235 const BuildBridgeData &bridge_data = this->bridges.at(i);
236 const BridgeSpec *b = bridge_data.spec;
237 DrawSpriteIgnorePadding(b->sprite, b->pal, tr.WithWidth(this->icon_width, rtl), SA_HOR_CENTER | SA_BOTTOM);
238 DrawStringMultiLine(tr.Indent(this->icon_width + WidgetDimensions::scaled.hsep_normal, rtl), GetBridgeSelectString(bridge_data));
239 tr = tr.Translate(0, this->resize.step_height);
240 }
241 break;
242 }
243 }
244 }
245
246 EventState OnKeyPress([[maybe_unused]] char32_t key, uint16_t keycode) override
247 {
248 const uint8_t i = keycode - '1';
249 if (i < 9 && i < this->bridges.size()) {
250 /* Build the requested bridge */
251 this->BuildBridge(this->bridges[i].index);
252 this->Close();
253 return ES_HANDLED;
254 }
255 return ES_NOT_HANDLED;
256 }
257
258 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
259 {
260 switch (widget) {
261 default: break;
262 case WID_BBS_BRIDGE_LIST: {
263 auto it = this->vscroll->GetScrolledItemFromWidget(this->bridges, pt.y, this, WID_BBS_BRIDGE_LIST);
264 if (it != this->bridges.end()) {
265 this->BuildBridge(it->index);
266 this->Close();
267 }
268 break;
269 }
270
271 case WID_BBS_DROPDOWN_ORDER:
272 this->bridges.ToggleSortOrder();
273 this->SetDirty();
274 break;
275
276 case WID_BBS_DROPDOWN_CRITERIA:
277 ShowDropDownMenu(this, this->sorter_names, this->bridges.SortType(), WID_BBS_DROPDOWN_CRITERIA, 0, 0);
278 break;
279 }
280 }
281
282 void OnDropdownSelect(WidgetID widget, int index) override
283 {
284 if (widget == WID_BBS_DROPDOWN_CRITERIA && this->bridges.SortType() != index) {
285 this->bridges.SetSortType(index);
286
287 this->SortBridgeList();
288 }
289 }
290
291 void OnResize() override
292 {
293 this->vscroll->SetCapacityFromWidget(this, WID_BBS_BRIDGE_LIST);
294 }
295 };
296
298 Listing BuildBridgeWindow::last_sorting = {true, 2};
299
301 GUIBridgeList::SortFunction * const BuildBridgeWindow::sorter_funcs[] = {
302 &BridgeIndexSorter,
303 &BridgePriceSorter,
304 &BridgeSpeedSorter
305 };
306
308 const StringID BuildBridgeWindow::sorter_names[] = {
309 STR_SORT_BY_NUMBER,
310 STR_SORT_BY_COST,
311 STR_SORT_BY_MAX_SPEED,
312 INVALID_STRING_ID
313 };
314
316 static constexpr NWidgetPart _nested_build_bridge_widgets[] = {
317 /* Header */
318 NWidget(NWID_HORIZONTAL),
319 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
320 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_BBS_CAPTION), SetDataTip(STR_SELECT_RAIL_BRIDGE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
321 NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
322 EndContainer(),
323
324 NWidget(NWID_HORIZONTAL),
325 NWidget(NWID_VERTICAL),
326 /* Sort order + criteria buttons */
327 NWidget(NWID_HORIZONTAL),
328 NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_BBS_DROPDOWN_ORDER), SetFill(1, 0), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
329 NWidget(WWT_DROPDOWN, COLOUR_DARK_GREEN, WID_BBS_DROPDOWN_CRITERIA), SetFill(1, 0), SetDataTip(0x0, STR_TOOLTIP_SORT_CRITERIA),
330 EndContainer(),
331 /* Matrix. */
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),
333 EndContainer(),
334
335 /* scrollbar + resize button */
336 NWidget(NWID_VERTICAL),
337 NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_BBS_SCROLLBAR),
338 NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
339 EndContainer(),
340 EndContainer(),
341 };
342
344 static WindowDesc _build_bridge_desc(__FILE__, __LINE__,
345 WDP_AUTO, "build_bridge", 200, 114,
346 WC_BUILD_BRIDGE, WC_BUILD_TOOLBAR,
347 WDF_CONSTRUCTION,
348 std::begin(_nested_build_bridge_widgets), std::end(_nested_build_bridge_widgets)
349 );
350
361 void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, byte road_rail_type)
362 {
363 CloseWindowByClass(WC_BUILD_BRIDGE);
364
365 /* The bridge length without ramps. */
366 const uint bridge_len = GetTunnelBridgeLength(start, end);
367
368 /* If Ctrl is being pressed, check whether the last bridge built is available
369 * If so, return this bridge type. Otherwise continue normally.
370 * We store bridge types for each transport type, so we have to check for
371 * the transport type beforehand.
372 */
373 BridgeType last_bridge_type = 0;
374 switch (transport_type) {
375 case TRANSPORT_ROAD: last_bridge_type = _last_roadbridge_type; break;
376 case TRANSPORT_RAIL: last_bridge_type = _last_railbridge_type; break;
377 default: break; // water ways and air routes don't have bridge types
378 }
379 if (_ctrl_pressed && CheckBridgeAvailability(last_bridge_type, bridge_len).Succeeded()) {
380 Command<CMD_BUILD_BRIDGE>::Post(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE, CcBuildBridge, end, start, transport_type, last_bridge_type, road_rail_type);
381 return;
382 }
383
384 /* only query bridge building possibility once, result is the same for all bridges!
385 * returns CMD_ERROR on failure, and price on success */
386 StringID errmsg = INVALID_STRING_ID;
387 CommandCost ret = Command<CMD_BUILD_BRIDGE>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_BRIDGE>()) | DC_QUERY_COST, end, start, transport_type, 0, road_rail_type);
388
389 GUIBridgeList bl;
390 if (ret.Failed()) {
391 errmsg = ret.GetErrorMessage();
392 } else {
393 /* check which bridges can be built */
394 const uint tot_bridgedata_len = CalcBridgeLenCostFactor(bridge_len + 2);
395
396 Money infra_cost = 0;
397 switch (transport_type) {
398 case TRANSPORT_ROAD: {
399 /* In case we add a new road type as well, we must be aware of those costs. */
400 RoadType road_rt = INVALID_ROADTYPE;
401 RoadType tram_rt = INVALID_ROADTYPE;
402 if (IsBridgeTile(start)) {
403 road_rt = GetRoadTypeRoad(start);
404 tram_rt = GetRoadTypeTram(start);
405 }
406 if (RoadTypeIsRoad((RoadType)road_rail_type)) {
407 road_rt = (RoadType)road_rail_type;
408 } else {
409 tram_rt = (RoadType)road_rail_type;
410 }
411
412 if (road_rt != INVALID_ROADTYPE) infra_cost += (bridge_len + 2) * 2 * RoadBuildCost(road_rt);
413 if (tram_rt != INVALID_ROADTYPE) infra_cost += (bridge_len + 2) * 2 * RoadBuildCost(tram_rt);
414
415 break;
416 }
417 case TRANSPORT_RAIL: infra_cost = (bridge_len + 2) * RailBuildCost((RailType)road_rail_type); break;
418 default: break;
419 }
420
421 bool any_available = false;
422 CommandCost type_check;
423 /* loop for all bridgetypes */
424 for (BridgeType brd_type = 0; brd_type != MAX_BRIDGES; brd_type++) {
425 type_check = CheckBridgeAvailability(brd_type, bridge_len);
426 if (type_check.Succeeded()) {
427 /* bridge is accepted, add to list */
428 BuildBridgeData &item = bl.emplace_back();
429 item.index = brd_type;
430 item.spec = GetBridgeSpec(brd_type);
431 /* Add to terraforming & bulldozing costs the cost of the
432 * bridge itself (not computed with DC_QUERY_COST) */
433 item.cost = ret.GetCost() + (((int64_t)tot_bridgedata_len * _price[PR_BUILD_BRIDGE] * item.spec->price) >> 8) + infra_cost;
434 any_available = true;
435 }
436 }
437 /* give error cause if no bridges available here*/
438 if (!any_available)
439 {
440 errmsg = type_check.GetErrorMessage();
441 }
442 }
443
444 if (!bl.empty()) {
445 new BuildBridgeWindow(&_build_bridge_desc, start, end, transport_type, road_rail_type, std::move(bl));
446 } else {
447 ShowErrorMessage(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE, errmsg, WL_INFO, TileX(end) * TILE_SIZE, TileY(end) * TILE_SIZE);
448 }
449 }
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:739
TileY
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:437
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1141
_build_bridge_desc
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.
tunnelbridge.h
CloseWindowByClass
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition: window.cpp:1153
sound_func.h
BuildBridgeWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: bridge_gui.cpp:291
WC_BUILD_TOOLBAR
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
Definition: window_type.h:73
CalcBridgeLenCostFactor
int CalcBridgeLenCostFactor(int x)
Calculate the price factor for building a long bridge.
Definition: tunnelbridge_cmd.cpp:108
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
command_func.h
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
GetTunnelBridgeLength
uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
Definition: tunnelbridge.h:25
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
Definition: error_gui.cpp:367
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:197
dropdown_func.h
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
SND_27_CONSTRUCTION_BRIDGE
@ SND_27_CONSTRUCTION_BRIDGE
37 == 0x25 Construction: bridge
Definition: sound_type.h:76
BuildBridgeWindow::sorter_names
static const StringID sorter_names[]
Names of the sorting functions.
Definition: bridge_gui.cpp:78
tunnelbridge_map.h
CommandFlagsToDCFlags
static constexpr DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
Definition: command_func.h:58
BuildBridgeWindow::icon_width
int icon_width
Scaled width of the the bridge icon sprite.
Definition: bridge_gui.cpp:87
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:552
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
GUIList< BuildBridgeData >
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:67
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1048
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:61
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1099
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1151
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1174
WID_BBS_DROPDOWN_ORDER
@ WID_BBS_DROPDOWN_ORDER
Direction of sort dropdown.
Definition: bridge_widget.h:16
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:37
BuildBridgeWindow::last_sorting
static Listing last_sorting
Last setting of the sort.
Definition: bridge_gui.cpp:75
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:2334
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
SA_BOTTOM
@ SA_BOTTOM
Bottom align the text.
Definition: gfx_type.h:345
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
BridgeSpec::speed
uint16_t speed
maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
Definition: bridge.h:47
BuildBridgeWindow::BridgePriceSorter
static bool BridgePriceSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their price.
Definition: bridge_gui.cpp:97
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
BridgeSpec::price
uint16_t price
the price multiplier
Definition: bridge.h:46
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:678
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:315
CommandCost::GetErrorMessage
StringID GetErrorMessage() const
Returns the error message of a command.
Definition: command_type.h:142
Rect::WithHeight
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Definition: geometry_type.hpp:211
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1038
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition: road_type.h:30
Scrollbar::GetPosition
uint16_t GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:720
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:162
gfx_func.h
WindowDesc
High level window description.
Definition: window_gui.h:153
BridgeSpec
Struct containing information about a single bridge type.
Definition: bridge.h:42
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
RoadBuildCost
Money RoadBuildCost(RoadType roadtype)
Returns the cost of building the specified roadtype.
Definition: road.h:252
BridgeSpec::sprite
SpriteID sprite
the sprite which is used in the GUI
Definition: bridge.h:48
TRANSPORT_RAIL
@ TRANSPORT_RAIL
Transport by train.
Definition: transport_type.h:27
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1086
GUIList::NeedResort
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
Definition: sortlist_type.h:220
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:141
Listing
Data structure describing how to show the list (what sort direction and criteria).
Definition: sortlist_type.h:30
RailType
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:308
CommandCost
Common return value for all commands.
Definition: command_type.h:23
GetBridgeSpec
const BridgeSpec * GetBridgeSpec(BridgeType i)
Get the specification of a bridge type.
Definition: bridge.h:66
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:639
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition: geometry_type.hpp:174
MAX_BRIDGES
static const uint MAX_BRIDGES
Maximal number of available bridge specs.
Definition: bridge.h:35
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1244
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:941
GUIList::SortFunction
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.
Definition: sortlist_type.h:49
TransportType
TransportType
Available types of transport.
Definition: transport_type.h:19
_last_railbridge_type
static BridgeType _last_railbridge_type
The type of the last built rail bridge.
Definition: bridge_gui.cpp:34
ReverseDiagDir
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Definition: direction_func.h:118
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:740
WID_BBS_BRIDGE_LIST
@ WID_BBS_BRIDGE_LIST
List of bridges.
Definition: bridge_widget.h:18
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:171
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:135
CheckBridgeAvailability
CommandCost CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoCommandFlag flags=DC_NONE)
Is a bridge of the specified type and length available?
Definition: tunnelbridge_cmd.cpp:200
road_gui.h
GetMainViewTop
int GetMainViewTop()
Return the top of the main view available for general use.
Definition: window.cpp:2063
BridgeSpec::pal
PaletteID pal
the palette which is used in the GUI
Definition: bridge.h:49
BuildBridgeWindow::BridgeIndexSorter
static bool BridgeIndexSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their index.
Definition: bridge_gui.cpp:91
IsBridgeTile
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
Definition: bridge_map.h:35
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:322
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:24
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1258
safeguards.h
sortlist_type.h
WC_BUILD_BRIDGE
@ WC_BUILD_BRIDGE
Build bridge; Window numbers:
Definition: window_type.h:389
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:198
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:83
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:185
rail.h
road.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
error.h
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:73
Scrollbar::GetScrolledItemFromWidget
Tcontainer::iterator GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Return an iterator pointing to the element of a scrolled widget that a user clicked in.
Definition: widget_type.h:845
ShowDropDownMenu
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.
Definition: dropdown.cpp:386
tunnelbridge_cmd.h
WID_BBS_SCROLLBAR
@ WID_BBS_SCROLLBAR
Scrollbar of the list.
Definition: bridge_widget.h:19
BridgeType
uint BridgeType
Bridge spec number.
Definition: bridge.h:37
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:296
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
BuildBridgeWindow
Window class for handling the bridge-build GUI.
Definition: bridge_gui.cpp:72
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:339
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:70
ShowBuildBridgeWindow
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, byte road_rail_type)
Prepare the data for the build a bridge window.
Definition: bridge_gui.cpp:361
CcBuildBridge
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.
Definition: bridge_gui.cpp:57
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:214
SoundSettings::confirm
bool confirm
Play sound effect on successful constructions or other actions.
Definition: settings_type.h:240
DrawStringMultiLine
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.
Definition: gfx.cpp:775
BuildBridgeWindow::SortBridgeList
void SortBridgeList()
Sort the builable bridges.
Definition: bridge_gui.cpp:120
Window::DrawSortButtonState
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition: widget.cpp:763
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1724
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:236
GUIList::GetListing
Listing GetListing() const
Export current sort conditions.
Definition: sortlist_type.h:137
BuildBridgeWindow::GetBridgeSelectString
StringID GetBridgeSelectString(const BuildBridgeData &bridge_data) const
Get the StringID to draw in the selection list and set the appropriate DParams.
Definition: bridge_gui.cpp:137
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
geometry_func.hpp
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:760
EventState
EventState
State of handling an event.
Definition: window_type.h:738
BuildBridgeWindow::BridgeSpeedSorter
static bool BridgeSpeedSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their maximum speed.
Definition: bridge_gui.cpp:103
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:25
_nested_build_bridge_widgets
static constexpr NWidgetPart _nested_build_bridge_widgets[]
Widgets of the bridge gui.
Definition: bridge_gui.cpp:316
PackVelocity
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
Definition: strings_func.h:74
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1734
BuildBridgeData
Carriage for the data we need if we want to build a bridge.
Definition: bridge_gui.cpp:41
CommandHelper
Definition: command_func.h:93
GUIList::SortType
uint8_t SortType() const
Get the sorttype of the list.
Definition: sortlist_type.h:114
window_func.h
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:780
GUIList::SetSortFuncs
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
Definition: sortlist_type.h:295
BridgeSpec::material
StringID material
the string that contains the bridge description
Definition: bridge.h:50
OverflowSafeInt< int64_t >
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:237
WID_BBS_CAPTION
@ WID_BBS_CAPTION
Caption of the window.
Definition: bridge_widget.h:15
TRANSPORT_ROAD
@ TRANSPORT_ROAD
Transport by road vehicle.
Definition: transport_type.h:28
BuildBridgeWindow::sorter_funcs
static GUIBridgeList::SortFunction *const sorter_funcs[]
Available bridge sorting functions.
Definition: bridge_gui.cpp:79
Window
Data structure for an opened window.
Definition: window_gui.h:267
Commands
Commands
List of commands.
Definition: command_type.h:187
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:79
TileX
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:427
DC_QUERY_COST
@ DC_QUERY_COST
query cost only, don't build.
Definition: command_type.h:373
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1162
ConnectRoadToStructure
void ConnectRoadToStructure(TileIndex tile, DiagDirection direction)
If required, connects a new structure to an existing road or tram by building the missing roadbit.
Definition: road_gui.cpp:149
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:215
GetScaledSpriteSize
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
Definition: widget.cpp:54
GetMainViewBottom
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Definition: window.cpp:2074
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
CursorVars::pos
Point pos
logical mouse position
Definition: gfx_type.h:117
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:268
bridge_widget.h
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:852
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:57
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
RailBuildCost
Money RailBuildCost(RailType railtype)
Returns the cost of building the specified railtype.
Definition: rail.h:375
GUIBridgeList
GUIList< BuildBridgeData > GUIBridgeList
List of bridges, used in BuildBridgeWindow.
Definition: bridge_gui.cpp:47
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:72
GUIList::SetListing
void SetListing(Listing l)
Import sort conditions.
Definition: sortlist_type.h:151
_last_roadbridge_type
static BridgeType _last_roadbridge_type
The type of the last built road bridge.
Definition: bridge_gui.cpp:36
WID_BBS_DROPDOWN_CRITERIA
@ WID_BBS_DROPDOWN_CRITERIA
Criteria of sort dropdown.
Definition: bridge_widget.h:17
GetTunnelBridgeDirection
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
Definition: tunnelbridge_map.h:26