OpenTTD Source: src/bridge_gui.cpp Source File

OpenTTD Source 15.0-RC2

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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 "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, uint8_t)
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 {
73private:
74 /* Runtime saved values */
75 static Listing last_sorting;
76
77 /* Constants for sorting the bridges */
78 static inline const StringID sorter_names[] = {
79 STR_SORT_BY_NUMBER,
80 STR_SORT_BY_COST,
81 STR_SORT_BY_MAX_SPEED,
82 };
83 static const std::initializer_list<GUIBridgeList::SortFunction * const> sorter_funcs;
84
85 /* Internal variables */
86 TileIndex start_tile = INVALID_TILE;
87 TileIndex end_tile = INVALID_TILE;
88 TransportType transport_type = INVALID_TRANSPORT;
89 uint8_t road_rail_type = 0;
90 GUIBridgeList bridges{};
91 int icon_width = 0;
92 Scrollbar *vscroll = nullptr;
93
95 static bool BridgeIndexSorter(const BuildBridgeData &a, const BuildBridgeData &b)
96 {
97 return a.index < b.index;
98 }
99
101 static bool BridgePriceSorter(const BuildBridgeData &a, const BuildBridgeData &b)
102 {
103 return a.cost < b.cost;
104 }
105
107 static bool BridgeSpeedSorter(const BuildBridgeData &a, const BuildBridgeData &b)
108 {
109 return a.spec->speed < b.spec->speed;
110 }
111
112 void BuildBridge(BridgeType type)
113 {
114 switch (this->transport_type) {
115 case TRANSPORT_RAIL: _last_railbridge_type = type; break;
116 case TRANSPORT_ROAD: _last_roadbridge_type = type; break;
117 default: break;
118 }
119 Command<CMD_BUILD_BRIDGE>::Post(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE, CcBuildBridge,
120 this->end_tile, this->start_tile, this->transport_type, type, this->road_rail_type);
121 }
122
124 void SortBridgeList()
125 {
126 this->bridges.Sort();
127
128 /* Display the current sort variant */
129 this->GetWidget<NWidgetCore>(WID_BBS_DROPDOWN_CRITERIA)->SetString(BuildBridgeWindow::sorter_names[this->bridges.SortType()]);
130
131 /* Set the modified widgets dirty */
132 this->SetWidgetDirty(WID_BBS_DROPDOWN_CRITERIA);
133 this->SetWidgetDirty(WID_BBS_BRIDGE_LIST);
134 }
135
141 std::string GetBridgeSelectString(const BuildBridgeData &bridge_data) const
142 {
143 /* If the bridge has no meaningful speed limit, don't display it. */
144 if (bridge_data.spec->speed == UINT16_MAX) {
145 return _game_mode == GM_EDITOR
146 ? GetString(STR_SELECT_BRIDGE_INFO_NAME, bridge_data.spec->material)
147 : GetString(STR_SELECT_BRIDGE_INFO_NAME_COST, bridge_data.spec->material, bridge_data.cost);
148 }
149
150 uint64_t packed_velocity = PackVelocity(bridge_data.spec->speed, static_cast<VehicleType>(this->transport_type));
151 return _game_mode == GM_EDITOR
152 ? GetString(STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED, bridge_data.spec->material, packed_velocity)
153 : GetString(STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED_COST, bridge_data.spec->material, packed_velocity, bridge_data.cost);
154 }
155
156public:
157 BuildBridgeWindow(WindowDesc &desc, TileIndex start, TileIndex end, TransportType transport_type, uint8_t road_rail_type, GUIBridgeList &&bl) : Window(desc),
158 start_tile(start),
159 end_tile(end),
160 transport_type(transport_type),
161 road_rail_type(road_rail_type),
162 bridges(std::move(bl))
163 {
164 this->CreateNestedTree();
165 this->vscroll = this->GetScrollbar(WID_BBS_SCROLLBAR);
166 /* Change the data, or the caption of the gui. Set it to road or rail, accordingly. */
167 this->GetWidget<NWidgetCore>(WID_BBS_CAPTION)->SetString((transport_type == TRANSPORT_ROAD) ? STR_SELECT_ROAD_BRIDGE_CAPTION : STR_SELECT_RAIL_BRIDGE_CAPTION);
168 this->FinishInitNested(transport_type); // Initializes 'this->icon_width'.
169
170 this->parent = FindWindowById(WC_BUILD_TOOLBAR, transport_type);
171 this->bridges.SetListing(BuildBridgeWindow::last_sorting);
172 this->bridges.SetSortFuncs(BuildBridgeWindow::sorter_funcs);
173 this->bridges.NeedResort();
174 this->SortBridgeList();
175
176 this->vscroll->SetCount(this->bridges.size());
177 }
178
179 ~BuildBridgeWindow()
180 {
181 BuildBridgeWindow::last_sorting = this->bridges.GetListing();
182 }
183
184 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
185 {
186 switch (widget) {
187 case WID_BBS_DROPDOWN_ORDER: {
188 Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->GetString());
189 d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
190 d.height += padding.height;
191 size = maxdim(size, d);
192 break;
193 }
194 case WID_BBS_DROPDOWN_CRITERIA: {
195 Dimension d = GetStringListBoundingBox(BuildBridgeWindow::sorter_names);
196 d.width += padding.width;
197 d.height += padding.height;
198 size = maxdim(size, d);
199 break;
200 }
201 case WID_BBS_BRIDGE_LIST: {
202 Dimension sprite_dim = {0, 0}; // Biggest bridge sprite dimension
203 Dimension text_dim = {0, 0}; // Biggest text dimension
204 for (const BuildBridgeData &bridge_data : this->bridges) {
205 sprite_dim = maxdim(sprite_dim, GetScaledSpriteSize(bridge_data.spec->sprite));
206 text_dim = maxdim(text_dim, GetStringBoundingBox(GetBridgeSelectString(bridge_data)));
207 }
208 fill.height = resize.height = std::max(sprite_dim.height, text_dim.height) + padding.height; // Max of both sizes + account for matrix edges.
209
210 this->icon_width = sprite_dim.width; // Width of bridge icon.
211 size.width = this->icon_width + WidgetDimensions::scaled.hsep_normal + text_dim.width + padding.width;
212 size.height = 4 * resize.height; // Smallest bridge gui is 4 entries high in the matrix.
213 break;
214 }
215 }
216 }
217
218 Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
219 {
220 /* Position the window so hopefully the first bridge from the list is under the mouse pointer. */
221 NWidgetBase *list = this->GetWidget<NWidgetBase>(WID_BBS_BRIDGE_LIST);
222 Point corner; // point of the top left corner of the window.
223 corner.y = Clamp(_cursor.pos.y - list->pos_y - 5, GetMainViewTop(), GetMainViewBottom() - sm_height);
224 corner.x = Clamp(_cursor.pos.x - list->pos_x - 5, 0, _screen.width - sm_width);
225 return corner;
226 }
227
228 void DrawWidget(const Rect &r, WidgetID widget) const override
229 {
230 switch (widget) {
231 case WID_BBS_DROPDOWN_ORDER:
232 this->DrawSortButtonState(widget, this->bridges.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
233 break;
234
235 case WID_BBS_BRIDGE_LIST: {
236 Rect tr = r.WithHeight(this->resize.step_height).Shrink(WidgetDimensions::scaled.matrix);
237 bool rtl = _current_text_dir == TD_RTL;
238 auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->bridges);
239 for (auto it = first; it != last; ++it) {
240 const BridgeSpec *b = it->spec;
241 DrawSpriteIgnorePadding(b->sprite, b->pal, tr.WithWidth(this->icon_width, rtl), SA_HOR_CENTER | SA_BOTTOM);
242 DrawStringMultiLineWithClipping(tr.Indent(this->icon_width + WidgetDimensions::scaled.hsep_normal, rtl), GetBridgeSelectString(*it));
243 tr = tr.Translate(0, this->resize.step_height);
244 }
245 break;
246 }
247 }
248 }
249
250 EventState OnKeyPress([[maybe_unused]] char32_t key, uint16_t keycode) override
251 {
252 const uint8_t i = keycode - '1';
253 if (i < 9 && i < this->bridges.size()) {
254 /* Build the requested bridge */
255 this->BuildBridge(this->bridges[i].index);
256 this->Close();
257 return ES_HANDLED;
258 }
259 return ES_NOT_HANDLED;
260 }
261
262 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
263 {
264 switch (widget) {
265 default: break;
266 case WID_BBS_BRIDGE_LIST: {
267 auto it = this->vscroll->GetScrolledItemFromWidget(this->bridges, pt.y, this, WID_BBS_BRIDGE_LIST);
268 if (it != this->bridges.end()) {
269 this->BuildBridge(it->index);
270 this->Close();
271 }
272 break;
273 }
274
275 case WID_BBS_DROPDOWN_ORDER:
276 this->bridges.ToggleSortOrder();
277 this->SetDirty();
278 break;
279
280 case WID_BBS_DROPDOWN_CRITERIA:
281 ShowDropDownMenu(this, BuildBridgeWindow::sorter_names, this->bridges.SortType(), WID_BBS_DROPDOWN_CRITERIA, 0, 0);
282 break;
283 }
284 }
285
286 void OnDropdownSelect(WidgetID widget, int index, int) override
287 {
288 if (widget == WID_BBS_DROPDOWN_CRITERIA && this->bridges.SortType() != index) {
289 this->bridges.SetSortType(index);
290
291 this->SortBridgeList();
292 }
293 }
294
295 void OnResize() override
296 {
297 this->vscroll->SetCapacityFromWidget(this, WID_BBS_BRIDGE_LIST);
298 }
299};
300
302 Listing BuildBridgeWindow::last_sorting = {true, 2};
303
305 const std::initializer_list<GUIBridgeList::SortFunction * const> BuildBridgeWindow::sorter_funcs = {
306 &BridgeIndexSorter,
307 &BridgePriceSorter,
308 &BridgeSpeedSorter
309};
310
312 static constexpr std::initializer_list<NWidgetPart> _nested_build_bridge_widgets = {
313 /* Header */
314 NWidget(NWID_HORIZONTAL),
315 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
316 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_BBS_CAPTION), SetStringTip(STR_SELECT_RAIL_BRIDGE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
317 NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
318 EndContainer(),
319
320 NWidget(NWID_HORIZONTAL),
321 NWidget(NWID_VERTICAL),
322 /* Sort order + criteria buttons */
323 NWidget(NWID_HORIZONTAL),
324 NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_BBS_DROPDOWN_ORDER), SetFill(1, 0), SetStringTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
325 NWidget(WWT_DROPDOWN, COLOUR_DARK_GREEN, WID_BBS_DROPDOWN_CRITERIA), SetFill(1, 0), SetToolTip(STR_TOOLTIP_SORT_CRITERIA),
326 EndContainer(),
327 /* Matrix. */
328 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),
329 EndContainer(),
330
331 /* scrollbar + resize button */
332 NWidget(NWID_VERTICAL),
333 NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_BBS_SCROLLBAR),
334 NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
335 EndContainer(),
336 EndContainer(),
337};
338
340 static WindowDesc _build_bridge_desc(
341 WDP_AUTO, "build_bridge", 200, 114,
342 WC_BUILD_BRIDGE, WC_BUILD_TOOLBAR,
343 WindowDefaultFlag::Construction,
344 _nested_build_bridge_widgets
345);
346
357 void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, uint8_t road_rail_type)
358{
359 CloseWindowByClass(WC_BUILD_BRIDGE);
360
361 /* The bridge length without ramps. */
362 const uint bridge_len = GetTunnelBridgeLength(start, end);
363
364 /* If Ctrl is being pressed, check whether the last bridge built is available
365 * If so, return this bridge type. Otherwise continue normally.
366 * We store bridge types for each transport type, so we have to check for
367 * the transport type beforehand.
368 */
369 BridgeType last_bridge_type = 0;
370 switch (transport_type) {
371 case TRANSPORT_ROAD: last_bridge_type = _last_roadbridge_type; break;
372 case TRANSPORT_RAIL: last_bridge_type = _last_railbridge_type; break;
373 default: break; // water ways and air routes don't have bridge types
374 }
375 if (_ctrl_pressed && CheckBridgeAvailability(last_bridge_type, bridge_len).Succeeded()) {
376 Command<CMD_BUILD_BRIDGE>::Post(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE, CcBuildBridge, end, start, transport_type, last_bridge_type, road_rail_type);
377 return;
378 }
379
380 /* only query bridge building possibility once, result is the same for all bridges!
381 * returns CMD_ERROR on failure, and price on success */
382 CommandCost ret = Command<CMD_BUILD_BRIDGE>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_BRIDGE>()) | DoCommandFlag::QueryCost, end, start, transport_type, 0, road_rail_type);
383
384 GUIBridgeList bl;
385 if (!ret.Failed()) {
386 /* check which bridges can be built */
387 const uint tot_bridgedata_len = CalcBridgeLenCostFactor(bridge_len + 2);
388
389 Money infra_cost = 0;
390 switch (transport_type) {
391 case TRANSPORT_ROAD: {
392 /* In case we add a new road type as well, we must be aware of those costs. */
393 RoadType road_rt = INVALID_ROADTYPE;
394 RoadType tram_rt = INVALID_ROADTYPE;
395 if (IsBridgeTile(start)) {
396 road_rt = GetRoadTypeRoad(start);
397 tram_rt = GetRoadTypeTram(start);
398 }
399 if (RoadTypeIsRoad((RoadType)road_rail_type)) {
400 road_rt = (RoadType)road_rail_type;
401 } else {
402 tram_rt = (RoadType)road_rail_type;
403 }
404
405 if (road_rt != INVALID_ROADTYPE) infra_cost += (bridge_len + 2) * 2 * RoadBuildCost(road_rt);
406 if (tram_rt != INVALID_ROADTYPE) infra_cost += (bridge_len + 2) * 2 * RoadBuildCost(tram_rt);
407
408 break;
409 }
410 case TRANSPORT_RAIL: infra_cost = (bridge_len + 2) * RailBuildCost((RailType)road_rail_type); break;
411 default: break;
412 }
413
414 bool any_available = false;
415 CommandCost type_check;
416 /* loop for all bridgetypes */
417 for (BridgeType brd_type = 0; brd_type != MAX_BRIDGES; brd_type++) {
418 type_check = CheckBridgeAvailability(brd_type, bridge_len);
419 if (type_check.Succeeded()) {
420 /* bridge is accepted, add to list */
421 BuildBridgeData &item = bl.emplace_back();
422 item.index = brd_type;
423 item.spec = GetBridgeSpec(brd_type);
424 /* Add to terraforming & bulldozing costs the cost of the
425 * bridge itself (not computed with DoCommandFlag::QueryCost) */
426 item.cost = ret.GetCost() + (((int64_t)tot_bridgedata_len * _price[PR_BUILD_BRIDGE] * item.spec->price) >> 8) + infra_cost;
427 any_available = true;
428 }
429 }
430 /* give error cause if no bridges available here*/
431 if (!any_available) ret = type_check;
432 }
433
434 if (!bl.empty()) {
435 new BuildBridgeWindow(_build_bridge_desc, start, end, transport_type, road_rail_type, std::move(bl));
436 } else {
437 ShowErrorMessage(GetEncodedString(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE), TileX(end) * TILE_SIZE, TileY(end) * TILE_SIZE, ret);
438 }
439}
CalcBridgeLenCostFactor
int CalcBridgeLenCostFactor(int x)
Calculate the price factor for building a long bridge.
Definition tunnelbridge_cmd.cpp:94
GetBridgeSpec
const BridgeSpec * GetBridgeSpec(BridgeType i)
Get the specification of a bridge type.
Definition bridge.h:60
MAX_BRIDGES
static const uint MAX_BRIDGES
Maximal number of available bridge specs.
Definition bridge.h:18
CheckBridgeAvailability
CommandCost CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoCommandFlags flags={})
Is a bridge of the specified type and length available?
Definition tunnelbridge_cmd.cpp:240
ShowBuildBridgeWindow
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, uint8_t road_rail_type)
Prepare the data for the build a bridge window.
Definition bridge_gui.cpp:357
CcBuildBridge
void CcBuildBridge(Commands, const CommandCost &result, TileIndex end_tile, TileIndex tile_start, TransportType transport_type, BridgeType, uint8_t)
Callback executed after a build Bridge CMD has been called.
Definition bridge_gui.cpp:57
GUIBridgeList
GUIList< BuildBridgeData > GUIBridgeList
List of bridges, used in BuildBridgeWindow.
Definition bridge_gui.cpp:47
_last_railbridge_type
static BridgeType _last_railbridge_type
The type of the last built rail bridge.
Definition bridge_gui.cpp:34
_build_bridge_desc
static WindowDesc _build_bridge_desc(WDP_AUTO, "build_bridge", 200, 114, WC_BUILD_BRIDGE, WC_BUILD_TOOLBAR, WindowDefaultFlag::Construction, _nested_build_bridge_widgets)
Window definition for the rail bridge selection window.
_nested_build_bridge_widgets
static constexpr std::initializer_list< NWidgetPart > _nested_build_bridge_widgets
Widgets of the bridge gui.
Definition bridge_gui.cpp:312
_last_roadbridge_type
static BridgeType _last_roadbridge_type
The type of the last built road bridge.
Definition bridge_gui.cpp:36
IsBridgeTile
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
Definition bridge_map.h:35
BridgeType
uint BridgeType
Bridge spec number.
Definition bridge_type.h:15
bridge_widget.h
Types related to the bridge widgets.
WID_BBS_DROPDOWN_CRITERIA
@ WID_BBS_DROPDOWN_CRITERIA
Criteria of sort dropdown.
Definition bridge_widget.h:17
WID_BBS_BRIDGE_LIST
@ WID_BBS_BRIDGE_LIST
List of bridges.
Definition bridge_widget.h:18
WID_BBS_DROPDOWN_ORDER
@ WID_BBS_DROPDOWN_ORDER
Direction of sort dropdown.
Definition bridge_widget.h:16
WID_BBS_SCROLLBAR
@ WID_BBS_SCROLLBAR
Scrollbar of the list.
Definition bridge_widget.h:19
WID_BBS_CAPTION
@ WID_BBS_CAPTION
Caption of the window.
Definition bridge_widget.h:15
BuildBridgeWindow
Window class for handling the bridge-build GUI.
Definition bridge_gui.cpp:72
BuildBridgeWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition bridge_gui.cpp:295
BuildBridgeWindow::SortBridgeList
void SortBridgeList()
Sort the builable bridges.
Definition bridge_gui.cpp:124
BuildBridgeWindow::OnDropdownSelect
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
Definition bridge_gui.cpp:286
BuildBridgeWindow::GetBridgeSelectString
std::string GetBridgeSelectString(const BuildBridgeData &bridge_data) const
Get the StringID to draw in the selection list and set the appropriate DParams.
Definition bridge_gui.cpp:141
BuildBridgeWindow::BridgePriceSorter
static bool BridgePriceSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their price.
Definition bridge_gui.cpp:101
BuildBridgeWindow::OnKeyPress
EventState OnKeyPress(char32_t key, uint16_t keycode) override
A key has been pressed.
Definition bridge_gui.cpp:250
BuildBridgeWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition bridge_gui.cpp:262
BuildBridgeWindow::OnInitialPosition
Point OnInitialPosition(int16_t sm_width, int16_t sm_height, int window_number) override
Compute the initial position of the window.
Definition bridge_gui.cpp:218
BuildBridgeWindow::BridgeSpeedSorter
static bool BridgeSpeedSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their maximum speed.
Definition bridge_gui.cpp:107
BuildBridgeWindow::BridgeIndexSorter
static bool BridgeIndexSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their index.
Definition bridge_gui.cpp:95
BuildBridgeWindow::UpdateWidgetSize
void UpdateWidgetSize(WidgetID 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:184
BuildBridgeWindow::sorter_funcs
static const std::initializer_list< GUIBridgeList::SortFunction *const > sorter_funcs
Available bridge sorting functions.
Definition bridge_gui.cpp:305
BuildBridgeWindow::last_sorting
static Listing last_sorting
Last setting of the sort.
Definition bridge_gui.cpp:302
BuildBridgeWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition bridge_gui.cpp:228
BuildBridgeWindow::icon_width
int icon_width
Scaled width of the the bridge icon sprite.
Definition bridge_gui.cpp:91
CommandCost
Common return value for all commands.
Definition command_type.h:24
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition command_type.h:168
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition command_type.h:118
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition command_type.h:177
GUIList
List template of 'things' T to sort in a GUI.
Definition sortlist_type.h:43
GUIList::SetListing
void SetListing(Listing l)
Import sort conditions.
Definition sortlist_type.h:148
GUIList::IsDescSortOrder
bool IsDescSortOrder() const
Check if the sort order is descending.
Definition sortlist_type.h:242
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:252
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition sortlist_type.h:266
GUIList::SortType
uint8_t SortType() const
Get the sorttype of the list.
Definition sortlist_type.h:110
GUIList::GetListing
Listing GetListing() const
Export current sort conditions.
Definition sortlist_type.h:134
GUIList::SetSortFuncs
void SetSortFuncs(std::span< SortFunction *const > n_funcs)
Hand the sort function pointers to the GUIList.
Definition sortlist_type.h:293
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:218
GUIList::SetSortType
void SetSortType(uint8_t n_type)
Set the sorttype of the list.
Definition sortlist_type.h:120
NWidgetBase
Baseclass for nested widgets.
Definition widget_type.h:136
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition widget_type.h:243
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition widget_type.h:242
OverflowSafeInt< int64_t >
Scrollbar
Scrollbar data structure.
Definition widget_type.h:708
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition widget_type.h:792
Scrollbar::GetScrolledItemFromWidget
auto 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:891
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:2499
Scrollbar::GetVisibleRangeIterators
auto GetVisibleRangeIterators(Tcontainer &container) const
Get a pair of iterators for the range of visible elements in a container.
Definition widget_type.h:872
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition window_gui.h:61
command_func.h
Functions related to commands.
CommandFlagsToDCFlags
static constexpr DoCommandFlags CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
Definition command_func.h:48
DoCommandFlag::QueryCost
@ QueryCost
query cost only, don't build.
Commands
Commands
List of commands.
Definition command_type.h:196
ReverseDiagDir
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Definition direction_func.h:118
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition direction_type.h:78
ShowDropDownMenu
void ShowDropDownMenu(Window *w, std::span< 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:458
dropdown_func.h
Functions related to the drop down widget.
error.h
Functions related to errors.
ShowErrorMessage
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
Definition error_gui.cpp:290
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition geometry_func.cpp:22
geometry_func.hpp
Geometry functions.
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:894
GetStringListBoundingBox
Dimension GetStringListBoundingBox(std::span< const StringID > list, FontSize fontsize)
Get maximum dimension of a list of strings.
Definition gfx.cpp:932
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:38
DrawStringMultiLineWithClipping
bool DrawStringMultiLineWithClipping(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw a multiline string, possibly over multiple lines, if the region is within the current display cl...
Definition gfx.cpp:867
gfx_func.h
Functions related to the gfx engine.
GetScaledSpriteSize
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
Definition widget.cpp:68
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition gfx_type.h:389
SA_BOTTOM
@ SA_BOTTOM
Bottom align the text.
Definition gfx_type.h:395
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint32_t cols, uint32_t rows, StringID tip={})
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition widget_type.h:1308
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1219
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition widget_type.h:1399
SetStringTip
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
Definition widget_type.h:1240
SetToolTip
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
Definition widget_type.h:1318
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1229
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1424
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1145
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:966
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:437
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:427
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition math_func.hpp:79
rail.h
Rail specific functions.
RailBuildCost
Money RailBuildCost(RailType railtype)
Returns the cost of building the specified railtype.
Definition rail.h:428
RailType
RailType
Enumeration for all possible railtypes.
Definition rail_type.h:25
road.h
Road specific functions.
RoadBuildCost
Money RoadBuildCost(RoadType roadtype)
Returns the cost of building the specified roadtype.
Definition road.h:240
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:163
road_gui.h
Functions/types related to the road GUIs.
RoadType
RoadType
The different roadtypes we support.
Definition road_type.h:23
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition road_type.h:28
safeguards.h
A number of safeguards to prevent using unsafe methods.
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
sortlist_type.h
Base types for having sorted lists in GUIs.
sound_func.h
Functions related to sound.
SND_27_CONSTRUCTION_BRIDGE
@ SND_27_CONSTRUCTION_BRIDGE
37 == 0x25 Construction: bridge
Definition sound_type.h:84
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
GetEncodedString
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:90
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
strings_func.h
Functions related to OTTD's strings.
PackVelocity
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
Definition strings_func.h:83
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition strings_type.h:27
BridgeSpec
Struct containing information about a single bridge type.
Definition bridge.h:27
BridgeSpec::price
uint16_t price
the price multiplier
Definition bridge.h:38
BridgeSpec::pal
PaletteID pal
the palette which is used in the GUI
Definition bridge.h:41
BridgeSpec::material
StringID material
the string that contains the bridge description
Definition bridge.h:42
BridgeSpec::sprite
SpriteID sprite
the sprite which is used in the GUI
Definition bridge.h:40
BridgeSpec::speed
uint16_t speed
maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
Definition bridge.h:39
BuildBridgeData
Carriage for the data we need if we want to build a bridge.
Definition bridge_gui.cpp:41
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition settings_type.h:653
CommandHelper
Definition command_func.h:83
Coord2D< int >
Coord2D::y
T y
Y coordinate.
Definition geometry_type.hpp:35
Coord2D::x
T x
X coordinate.
Definition geometry_type.hpp:34
CursorVars::pos
Point pos
logical mouse position
Definition gfx_type.h:125
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:56
Listing
Data structure describing how to show the list (what sort direction and criteria).
Definition sortlist_type.h:26
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:101
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition geometry_type.hpp:211
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition geometry_type.hpp:124
Rect::WithHeight
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Definition geometry_type.hpp:237
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition geometry_type.hpp:224
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition geometry_type.hpp:200
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition window_gui.h:213
SoundSettings::confirm
bool confirm
Play sound effect on successful constructions or other actions.
Definition settings_type.h:275
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
WindowDesc
High level window description.
Definition window_gui.h:168
Window
Data structure for an opened window.
Definition window_gui.h:274
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:1102
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition widget.cpp:815
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1807
Window::parent
Window * parent
Parent window.
Definition window_gui.h:329
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:556
Window::DrawSortButtonState
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition widget.cpp:798
Window::resize
ResizeInfo resize
Resize information.
Definition window_gui.h:315
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1797
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:313
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:303
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
TILE_SIZE
static constexpr uint TILE_SIZE
Tile size in world coordinates.
Definition tile_type.h:15
TransportType
TransportType
Available types of transport.
Definition transport_type.h:17
TRANSPORT_RAIL
@ TRANSPORT_RAIL
Transport by train.
Definition transport_type.h:25
INVALID_TRANSPORT
@ INVALID_TRANSPORT
Sentinel for invalid transport types.
Definition transport_type.h:30
TRANSPORT_ROAD
@ TRANSPORT_ROAD
Transport by road vehicle.
Definition transport_type.h:26
tunnelbridge.h
Header file for things common for tunnels and bridges.
GetTunnelBridgeLength
uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
Definition tunnelbridge.h:25
tunnelbridge_cmd.h
Command definitions related to tunnels and bridges.
tunnelbridge_map.h
Functions that have tunnels and bridges in common.
GetTunnelBridgeDirection
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
Definition tunnelbridge_map.h:26
VehicleType
VehicleType
Available vehicle types.
Definition vehicle_type.h:22
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:44
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition widget_type.h:50
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:52
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:60
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition widget_type.h:59
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition widget_type.h:56
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition widget_type.h:61
GetMainViewTop
int GetMainViewTop()
Return the top of the main view available for general use.
Definition window.cpp:2136
CloseWindowByClass
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1205
GetMainViewBottom
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Definition window.cpp:2147
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition window.cpp:1151
window_func.h
Window functions not directly related to making/drawing windows.
WindowDefaultFlag::Construction
@ Construction
This window is used for construction; close it whenever changing company.
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition window_gui.h:219
SBS_UP
@ SBS_UP
Sort descending.
Definition window_gui.h:220
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:144
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:20
EventState
EventState
State of handling an event.
Definition window_type.h:780
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition window_type.h:781
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition window_type.h:782
WC_BUILD_TOOLBAR
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
Definition window_type.h:78
WC_BUILD_BRIDGE
@ WC_BUILD_BRIDGE
Build bridge; Window numbers:
Definition window_type.h:400