OpenTTD Source: src/bridge_gui.cpp Source File

OpenTTD Source 12.0-beta1

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 "cmd_helper.h"
24 #include "tunnelbridge_map.h"
25 #include "road_gui.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
61 void CcBuildBridge(const CommandCost &result, TileIndex end_tile, uint32 p1, uint32 p2, uint32 cmd)
62 {
63 if (result.Failed()) return;
64 if (_settings_client.sound.confirm) SndPlayTileFx(SND_27_CONSTRUCTION_BRIDGE, end_tile);
65
66 TransportType transport_type = Extract<TransportType, 15, 2>(p2);
67
68 if (transport_type == TRANSPORT_ROAD) {
69 DiagDirection end_direction = ReverseDiagDir(GetTunnelBridgeDirection(end_tile));
70 ConnectRoadToStructure(end_tile, end_direction);
71
72 DiagDirection start_direction = ReverseDiagDir(GetTunnelBridgeDirection(p1));
73 ConnectRoadToStructure(p1, start_direction);
74 }
75 }
76
78 class BuildBridgeWindow : public Window {
79 private:
80 /* Runtime saved values */
81 static Listing last_sorting;
82
83 /* Constants for sorting the bridges */
84 static const StringID sorter_names[];
85 static GUIBridgeList::SortFunction * const sorter_funcs[];
86
87 /* Internal variables */
88 TileIndex start_tile;
89 TileIndex end_tile;
90 uint32 type;
91 GUIBridgeList *bridges;
92 int bridgetext_offset;
93 Scrollbar *vscroll;
94
96 static bool BridgeIndexSorter(const BuildBridgeData &a, const BuildBridgeData &b)
97 {
98 return a.index < b.index;
99 }
100
102 static bool BridgePriceSorter(const BuildBridgeData &a, const BuildBridgeData &b)
103 {
104 return a.cost < b.cost;
105 }
106
108 static bool BridgeSpeedSorter(const BuildBridgeData &a, const BuildBridgeData &b)
109 {
110 return a.spec->speed < b.spec->speed;
111 }
112
113 void BuildBridge(uint8 i)
114 {
115 switch ((TransportType)(this->type >> 15)) {
116 case TRANSPORT_RAIL: _last_railbridge_type = this->bridges->at(i).index; break;
117 case TRANSPORT_ROAD: _last_roadbridge_type = this->bridges->at(i).index; break;
118 default: break;
119 }
120 DoCommandP(this->end_tile, this->start_tile, this->type | this->bridges->at(i).index,
121 CMD_BUILD_BRIDGE | CMD_MSG(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE), CcBuildBridge);
122 }
123
125 void SortBridgeList()
126 {
127 this->bridges->Sort();
128
129 /* Display the current sort variant */
130 this->GetWidget<NWidgetCore>(WID_BBS_DROPDOWN_CRITERIA)->widget_data = this->sorter_names[this->bridges->SortType()];
131
132 /* Set the modified widgets dirty */
133 this->SetWidgetDirty(WID_BBS_DROPDOWN_CRITERIA);
134 this->SetWidgetDirty(WID_BBS_BRIDGE_LIST);
135 }
136
137 public:
138 BuildBridgeWindow(WindowDesc *desc, TileIndex start, TileIndex end, uint32 br_type, GUIBridgeList *bl) : Window(desc),
139 start_tile(start),
140 end_tile(end),
141 type(br_type),
142 bridges(bl)
143 {
144 this->CreateNestedTree();
145 this->vscroll = this->GetScrollbar(WID_BBS_SCROLLBAR);
146 /* Change the data, or the caption of the gui. Set it to road or rail, accordingly. */
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)); // Initializes 'this->bridgetext_offset'.
149
150 this->parent = FindWindowById(WC_BUILD_TOOLBAR, GB(this->type, 15, 2));
151 this->bridges->SetListing(this->last_sorting);
152 this->bridges->SetSortFuncs(this->sorter_funcs);
153 this->bridges->NeedResort();
154 this->SortBridgeList();
155
156 this->vscroll->SetCount((uint)bl->size());
157 }
158
159 ~BuildBridgeWindow()
160 {
161 this->last_sorting = this->bridges->GetListing();
162
163 delete bridges;
164 }
165
166 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
167 {
168 switch (widget) {
169 case WID_BBS_DROPDOWN_ORDER: {
170 Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
171 d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
172 d.height += padding.height;
173 *size = maxdim(*size, d);
174 break;
175 }
176 case WID_BBS_DROPDOWN_CRITERIA: {
177 Dimension d = {0, 0};
178 for (const StringID *str = this->sorter_names; *str != INVALID_STRING_ID; str++) {
179 d = maxdim(d, GetStringBoundingBox(*str));
180 }
181 d.width += padding.width;
182 d.height += padding.height;
183 *size = maxdim(*size, d);
184 break;
185 }
186 case WID_BBS_BRIDGE_LIST: {
187 Dimension sprite_dim = {0, 0}; // Biggest bridge sprite dimension
188 Dimension text_dim = {0, 0}; // Biggest text dimension
189 for (int i = 0; i < (int)this->bridges->size(); i++) {
190 const BridgeSpec *b = this->bridges->at(i).spec;
191 sprite_dim = maxdim(sprite_dim, GetSpriteSize(b->sprite));
192
193 SetDParam(2, this->bridges->at(i).cost);
194 SetDParam(1, b->speed);
195 SetDParam(0, b->material);
196 text_dim = maxdim(text_dim, GetStringBoundingBox(_game_mode == GM_EDITOR ? STR_SELECT_BRIDGE_SCENEDIT_INFO : STR_SELECT_BRIDGE_INFO));
197 }
198 sprite_dim.height++; // Sprite is rendered one pixel down in the matrix field.
199 text_dim.height++; // Allowing the bottom row pixels to be rendered on the edge of the matrix field.
200 resize->height = std::max(sprite_dim.height, text_dim.height) + 2; // Max of both sizes + account for matrix edges.
201
202 this->bridgetext_offset = WD_MATRIX_LEFT + sprite_dim.width + 1; // Left edge of text, 1 pixel distance from the sprite.
203 size->width = this->bridgetext_offset + text_dim.width + WD_MATRIX_RIGHT;
204 size->height = 4 * resize->height; // Smallest bridge gui is 4 entries high in the matrix.
205 break;
206 }
207 }
208 }
209
210 Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
211 {
212 /* Position the window so hopefully the first bridge from the list is under the mouse pointer. */
213 NWidgetBase *list = this->GetWidget<NWidgetBase>(WID_BBS_BRIDGE_LIST);
214 Point corner; // point of the top left corner of the window.
215 corner.y = Clamp(_cursor.pos.y - list->pos_y - 5, GetMainViewTop(), GetMainViewBottom() - sm_height);
216 corner.x = Clamp(_cursor.pos.x - list->pos_x - 5, 0, _screen.width - sm_width);
217 return corner;
218 }
219
220 void DrawWidget(const Rect &r, int widget) const override
221 {
222 switch (widget) {
223 case WID_BBS_DROPDOWN_ORDER:
224 this->DrawSortButtonState(widget, this->bridges->IsDescSortOrder() ? SBS_DOWN : SBS_UP);
225 break;
226
227 case WID_BBS_BRIDGE_LIST: {
228 uint y = r.top;
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;
231
232 SetDParam(2, this->bridges->at(i).cost);
233 SetDParam(1, b->speed);
234 SetDParam(0, b->material);
235
236 DrawSprite(b->sprite, b->pal, r.left + WD_MATRIX_LEFT, y + this->resize.step_height - 1 - GetSpriteSize(b->sprite).height);
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;
240 }
241 break;
242 }
243 }
244 }
245
246 EventState OnKeyPress(WChar key, uint16 keycode) override
247 {
248 const uint8 i = keycode - '1';
249 if (i < 9 && i < this->bridges->size()) {
250 /* Build the requested bridge */
251 this->BuildBridge(i);
252 this->Close();
253 return ES_HANDLED;
254 }
255 return ES_NOT_HANDLED;
256 }
257
258 void OnClick(Point pt, int widget, int click_count) override
259 {
260 switch (widget) {
261 default: break;
262 case WID_BBS_BRIDGE_LIST: {
263 uint i = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_BBS_BRIDGE_LIST);
264 if (i < this->bridges->size()) {
265 this->BuildBridge(i);
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(int 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 const 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(
345 WDP_AUTO, "build_bridge", 200, 114,
346 WC_BUILD_BRIDGE, WC_BUILD_TOOLBAR,
347 WDF_CONSTRUCTION,
348 _nested_build_bridge_widgets, lengthof(_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 /* Data type for the bridge.
366 * Bit 16,15 = transport type,
367 * 14..8 = road/rail types,
368 * 7..0 = type of bridge */
369 uint32 type = (transport_type << 15) | (road_rail_type << 8);
370
371 /* The bridge length without ramps. */
372 const uint bridge_len = GetTunnelBridgeLength(start, end);
373
374 /* If Ctrl is being pressed, check whether the last bridge built is available
375 * If so, return this bridge type. Otherwise continue normally.
376 * We store bridge types for each transport type, so we have to check for
377 * the transport type beforehand.
378 */
379 BridgeType last_bridge_type = 0;
380 switch (transport_type) {
381 case TRANSPORT_ROAD: last_bridge_type = _last_roadbridge_type; break;
382 case TRANSPORT_RAIL: last_bridge_type = _last_railbridge_type; break;
383 default: break; // water ways and air routes don't have bridge types
384 }
385 if (_ctrl_pressed && CheckBridgeAvailability(last_bridge_type, bridge_len).Succeeded()) {
386 DoCommandP(end, start, type | last_bridge_type, CMD_BUILD_BRIDGE | CMD_MSG(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE), CcBuildBridge);
387 return;
388 }
389
390 /* only query bridge building possibility once, result is the same for all bridges!
391 * returns CMD_ERROR on failure, and price on success */
392 StringID errmsg = INVALID_STRING_ID;
393 CommandCost ret = DoCommand(end, start, type, CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_BRIDGE)) | DC_QUERY_COST, CMD_BUILD_BRIDGE);
394
395 GUIBridgeList *bl = nullptr;
396 if (ret.Failed()) {
397 errmsg = ret.GetErrorMessage();
398 } else {
399 /* check which bridges can be built */
400 const uint tot_bridgedata_len = CalcBridgeLenCostFactor(bridge_len + 2);
401
402 bl = new GUIBridgeList();
403
404 Money infra_cost = 0;
405 switch (transport_type) {
406 case TRANSPORT_ROAD: {
407 /* In case we add a new road type as well, we must be aware of those costs. */
408 RoadType road_rt = INVALID_ROADTYPE;
409 RoadType tram_rt = INVALID_ROADTYPE;
410 if (IsBridgeTile(start)) {
411 road_rt = GetRoadTypeRoad(start);
412 tram_rt = GetRoadTypeTram(start);
413 }
414 if (RoadTypeIsRoad((RoadType)road_rail_type)) {
415 road_rt = (RoadType)road_rail_type;
416 } else {
417 tram_rt = (RoadType)road_rail_type;
418 }
419
420 if (road_rt != INVALID_ROADTYPE) infra_cost += (bridge_len + 2) * 2 * RoadBuildCost(road_rt);
421 if (tram_rt != INVALID_ROADTYPE) infra_cost += (bridge_len + 2) * 2 * RoadBuildCost(tram_rt);
422
423 break;
424 }
425 case TRANSPORT_RAIL: infra_cost = (bridge_len + 2) * RailBuildCost((RailType)road_rail_type); break;
426 default: break;
427 }
428
429 bool any_available = false;
430 CommandCost type_check;
431 /* loop for all bridgetypes */
432 for (BridgeType brd_type = 0; brd_type != MAX_BRIDGES; brd_type++) {
433 type_check = CheckBridgeAvailability(brd_type, bridge_len);
434 if (type_check.Succeeded()) {
435 /* bridge is accepted, add to list */
436 BuildBridgeData &item = bl->emplace_back();
437 item.index = brd_type;
438 item.spec = GetBridgeSpec(brd_type);
439 /* Add to terraforming & bulldozing costs the cost of the
440 * bridge itself (not computed with DC_QUERY_COST) */
441 item.cost = ret.GetCost() + (((int64)tot_bridgedata_len * _price[PR_BUILD_BRIDGE] * item.spec->price) >> 8) + infra_cost;
442 any_available = true;
443 }
444 }
445 /* give error cause if no bridges available here*/
446 if (!any_available)
447 {
448 errmsg = type_check.GetErrorMessage();
449 }
450 }
451
452 if (bl != nullptr && bl->size() != 0) {
453 new BuildBridgeWindow(&_build_bridge_desc, start, end, type, bl);
454 } else {
455 delete bl;
456 ShowErrorMessage(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE, errmsg, WL_INFO, TileX(end) * TILE_SIZE, TileY(end) * TILE_SIZE);
457 }
458 }
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:718
BuildBridgeWindow::OnInitialPosition
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
Compute the initial position of the window.
Definition: bridge_gui.cpp:210
tunnelbridge.h
CMD_MSG
#define CMD_MSG(x)
Used to combine a StringID with the command.
Definition: command_type.h:372
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
sound_func.h
BuildBridgeWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: bridge_gui.cpp:291
DoCommand
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
Definition: command.cpp:450
GUIList::SortType
uint8 SortType() const
Get the sorttype of the list.
Definition: sortlist_type.h:93
WC_BUILD_TOOLBAR
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
Definition: window_type.h:65
WD_MATRIX_RIGHT
@ WD_MATRIX_RIGHT
Offset at right of a matrix cell.
Definition: window_gui.h:79
WChar
char32_t WChar
Type for wide characters, i.e.
Definition: string_type.h:35
CalcBridgeLenCostFactor
int CalcBridgeLenCostFactor(int x)
Calculate the price factor for building a long bridge.
Definition: tunnelbridge_cmd.cpp:105
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1188
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
BuildBridgeWindow::OnKeyPress
EventState OnKeyPress(WChar key, uint16 keycode) override
A key has been pressed.
Definition: bridge_gui.cpp:246
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
command_func.h
Window::DrawSortButtonState
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition: widget.cpp:670
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:247
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:320
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:210
dropdown_func.h
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:84
TRANSPORT_RAIL
@ TRANSPORT_RAIL
Transport by train.
Definition: transport_type.h:27
tunnelbridge_map.h
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
GUIList
List template of 'things' T to sort in a GUI.
Definition: sortlist_type.h:46
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition: road_type.h:27
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1760
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:57
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1146
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:710
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:35
BuildBridgeWindow::last_sorting
static Listing last_sorting
Last setting of the sort.
Definition: bridge_gui.cpp:81
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:993
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:13
CMD_BUILD_BRIDGE
@ CMD_BUILD_BRIDGE
build a bridge
Definition: command_type.h:181
BuildBridgeWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: bridge_gui.cpp:282
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:52
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
BuildBridgeWindow::BridgePriceSorter
static bool BridgePriceSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their price.
Definition: bridge_gui.cpp:102
TransportType
TransportType
Available types of transport.
Definition: transport_type.h:19
GUIList::SetSortType
void SetSortType(uint8 n_type)
Set the sorttype of the list.
Definition: sortlist_type.h:103
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:2098
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:629
BridgeSpec::speed
uint16 speed
maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
Definition: bridge.h:46
CommandCost::GetErrorMessage
StringID GetErrorMessage() const
Returns the error message of a command.
Definition: command_type.h:140
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:971
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1107
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:150
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:888
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
ShowErrorMessage
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.
Definition: error_gui.cpp:383
DrawStringMultiLine
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.
Definition: gfx.cpp:787
CcBuildBridge
void CcBuildBridge(const CommandCost &result, TileIndex end_tile, uint32 p1, uint32 p2, uint32 cmd)
Callback executed after a build Bridge CMD has been called.
Definition: bridge_gui.cpp:61
gfx_func.h
WindowDesc
High level window description.
Definition: window_gui.h:168
BridgeSpec
Struct containing information about a single bridge type.
Definition: bridge.h:41
TRANSPORT_ROAD
@ TRANSPORT_ROAD
Transport by road vehicle.
Definition: transport_type.h:28
GetBridgeSpec
static const BridgeSpec * GetBridgeSpec(BridgeType i)
Get the specification of a bridge type.
Definition: bridge.h:65
BridgeSpec::sprite
SpriteID sprite
the sprite which is used in the GUI
Definition: bridge.h:47
_nested_build_bridge_widgets
static const NWidgetPart _nested_build_bridge_widgets[]
Widgets of the bridge gui.
Definition: bridge_gui.cpp:316
GUIList::IsDescSortOrder
bool IsDescSortOrder() const
Check if the sort order is descending.
Definition: sortlist_type.h:223
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:156
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
IsBridgeTile
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
Definition: bridge_map.h:35
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:317
CommandCost
Common return value for all commands.
Definition: command_type.h:23
cmd_helper.h
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:596
DoCommandP
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:541
MAX_BRIDGES
static const uint MAX_BRIDGES
Maximal number of available bridge specs.
Definition: bridge.h:34
GUIList::SortFunction
bool SortFunction(const T &, const T &)
Signature of sort function.
Definition: sortlist_type.h:48
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:993
GUIList::SetListing
void SetListing(Listing l)
Import sort conditions.
Definition: sortlist_type.h:130
_last_railbridge_type
static BridgeType _last_railbridge_type
The type of the last built rail bridge.
Definition: bridge_gui.cpp:34
WID_BBS_SCROLLBAR
@ WID_BBS_SCROLLBAR
Scrollbar of the list.
Definition: bridge_widget.h:19
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:719
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:159
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:126
SetMatrixDataTip
static NWidgetPart SetMatrixDataTip(uint8 cols, uint8 rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1125
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:197
road_gui.h
GetMainViewTop
int GetMainViewTop()
Return the top of the main view available for general use.
Definition: window.cpp:2105
BridgeSpec::pal
PaletteID pal
the palette which is used in the GUI
Definition: bridge.h:48
BuildBridgeWindow::BridgeIndexSorter
static bool BridgeIndexSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their index.
Definition: bridge_gui.cpp:96
WID_BBS_DROPDOWN_CRITERIA
@ WID_BBS_DROPDOWN_CRITERIA
Criteria of sort dropdown.
Definition: bridge_widget.h:17
RailBuildCost
static Money RailBuildCost(RailType railtype)
Returns the cost of building the specified railtype.
Definition: rail.h:372
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:332
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:22
safeguards.h
sortlist_type.h
WC_BUILD_BRIDGE
@ WC_BUILD_BRIDGE
Build bridge; Window numbers:
Definition: window_type.h:381
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:82
ReverseDiagDir
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Definition: direction_func.h:118
rail.h
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:1041
road.h
WID_BBS_BRIDGE_LIST
@ WID_BBS_BRIDGE_LIST
List of bridges.
Definition: bridge_widget.h:18
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
error.h
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:77
ShowDropDownMenu
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.
Definition: dropdown.cpp:480
BridgeType
uint BridgeType
Bridge spec number.
Definition: bridge.h:36
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:307
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:22
GetCommandFlags
CommandFlags GetCommandFlags(uint32 cmd)
Definition: command.cpp:393
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition: window_gui.h:220
BuildBridgeWindow
Window class for handling the bridge-build GUI.
Definition: bridge_gui.cpp:78
GUIList::ToggleSortOrder
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
Definition: sortlist_type.h:233
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:199
_build_bridge_desc
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.
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
GetTunnelBridgeDirection
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
Definition: tunnelbridge_map.h:26
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:976
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
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
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:226
SoundSettings::confirm
bool confirm
Play sound effect on successful constructions or other actions.
Definition: settings_type.h:208
BuildBridgeWindow::SortBridgeList
void SortBridgeList()
Sort the builable bridges.
Definition: bridge_gui.cpp:125
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1092
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:189
BuildBridgeWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: bridge_gui.cpp:258
BridgeSpec::price
uint16 price
the price multiplier
Definition: bridge.h:45
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1207
geometry_func.hpp
CloseWindowByClass
void CloseWindowByClass(WindowClass cls)
Close all windows of a given class.
Definition: window.cpp:1188
GUIList::GetListing
Listing GetListing() const
Export current sort conditions.
Definition: sortlist_type.h:116
BuildBridgeWindow::UpdateWidgetSize
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.
Definition: bridge_gui.cpp:166
EventState
EventState
State of handling an event.
Definition: window_type.h:717
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:671
BuildBridgeWindow::BridgeSpeedSorter
static bool BridgeSpeedSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their maximum speed.
Definition: bridge_gui.cpp:108
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1776
BuildBridgeData
Carriage for the data we need if we want to build a bridge.
Definition: bridge_gui.cpp:41
BuildBridgeWindow::bridgetext_offset
int bridgetext_offset
Horizontal offset of the text describing the bridge properties in WID_BBS_BRIDGE_LIST relative to the...
Definition: bridge_gui.cpp:92
window_func.h
GetTunnelBridgeLength
static uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
Definition: tunnelbridge.h:25
CommandFlagsToDCFlags
static DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
Definition: command_func.h:58
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:378
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:2172
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:690
BridgeSpec::material
StringID material
the string that contains the bridge description
Definition: bridge.h:49
OverflowSafeInt< int64 >
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:190
RoadBuildCost
static Money RoadBuildCost(RoadType roadtype)
Returns the cost of building the specified roadtype.
Definition: road.h:249
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1076
BuildBridgeWindow::sorter_funcs
static GUIBridgeList::SortFunction *const sorter_funcs[]
Available bridge sorting functions.
Definition: bridge_gui.cpp:85
Window
Data structure for an opened window.
Definition: window_gui.h:279
BuildBridgeWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: bridge_gui.cpp:220
WD_MATRIX_LEFT
@ WD_MATRIX_LEFT
Offset at left of a matrix cell.
Definition: window_gui.h:78
DC_QUERY_COST
@ DC_QUERY_COST
query cost only, don't build.
Definition: command_type.h:350
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:121
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:227
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:608
GetMainViewBottom
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Definition: window.cpp:2116
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
CursorVars::pos
Point pos
logical mouse position
Definition: gfx_type.h:117
WID_BBS_CAPTION
@ WID_BBS_CAPTION
Caption of the window.
Definition: bridge_widget.h:15
bridge_widget.h
WID_BBS_DROPDOWN_ORDER
@ WID_BBS_DROPDOWN_ORDER
Direction of sort dropdown.
Definition: bridge_widget.h:16
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:53
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
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:68
GUIList::SetSortFuncs
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
Definition: sortlist_type.h:270
_last_roadbridge_type
static BridgeType _last_roadbridge_type
The type of the last built road bridge.
Definition: bridge_gui.cpp:36
Window::Close
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1092