OpenTTD Source 20261112-master-gbcbec5e63f
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
9
10#include "stdafx.h"
11#include "bridge.h"
12#include "error.h"
13#include "command_func.h"
14#include "rail.h"
15#include "road.h"
16#include "strings_func.h"
17#include "window_func.h"
18#include "sound_func.h"
19#include "gfx_func.h"
20#include "tunnelbridge.h"
21#include "sortlist_type.h"
22#include "dropdown_func.h"
24#include "tunnelbridge_map.h"
25#include "road_gui.h"
26#include "tunnelbridge_cmd.h"
27
29
30#include "table/strings.h"
31
32#include "safeguards.h"
33
38
43 BridgeType index;
44 const BridgeSpec *spec;
45 Money cost;
46};
47
49
58void CcBuildBridge(Commands, const CommandCost &result, TileIndex end_tile, TileIndex tile_start, TransportType transport_type, BridgeType, RailType, RoadType)
59{
60 if (result.Failed()) return;
61 if (_settings_client.sound.confirm) SndPlayTileFx(SND_27_CONSTRUCTION_BRIDGE, end_tile);
62
63 if (transport_type == TransportType::Road) {
64 DiagDirection end_direction = ReverseDiagDir(GetTunnelBridgeDirection(end_tile));
65 ConnectRoadToStructure(end_tile, end_direction);
66
67 DiagDirection start_direction = ReverseDiagDir(GetTunnelBridgeDirection(tile_start));
68 ConnectRoadToStructure(tile_start, start_direction);
69 }
70}
71
73class BuildBridgeWindow : public Window {
74private:
75 /* Runtime saved values */
76 static Listing last_sorting;
77
79 static inline const StringID sorter_names[] = {
80 STR_SORT_BY_NUMBER,
81 STR_SORT_BY_COST,
82 STR_SORT_BY_MAX_SPEED,
83 };
84 static const std::initializer_list<GUIBridgeList::SortFunction * const> sorter_funcs;
85
86 TileIndex start_tile = INVALID_TILE;
87 TileIndex end_tile = INVALID_TILE;
91 GUIBridgeList bridges{};
92 int icon_width = 0;
93 Scrollbar *vscroll = nullptr;
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(BridgeType type)
114 {
115 switch (this->transport_type) {
116 case TransportType::Rail: _last_railbridge_type = type; break;
117 case TransportType::Road: _last_roadbridge_type = type; break;
118 default: break;
119 }
120 Command<Commands::BuildBridge>::Post(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE, CcBuildBridge,
121 this->end_tile, this->start_tile, this->transport_type, type, this->railtype, this->roadtype);
122 }
123
126 {
127 this->bridges.Sort();
128
129 /* Display the current sort variant */
131
132 /* Set the modified widgets dirty */
135 }
136
142 std::string GetBridgeSelectString(const BuildBridgeData &bridge_data) const
143 {
144 /* If the bridge has no meaningful speed limit, don't display it. */
145 if (bridge_data.spec->speed == UINT16_MAX) {
146 return _game_mode == GameMode::Editor
147 ? GetString(STR_SELECT_BRIDGE_INFO_NAME, bridge_data.spec->material)
148 : GetString(STR_SELECT_BRIDGE_INFO_NAME_COST, bridge_data.spec->material, bridge_data.cost);
149 }
150
151 uint64_t packed_velocity = PackVelocity(bridge_data.spec->speed, static_cast<VehicleType>(this->transport_type));
152 return _game_mode == GameMode::Editor
153 ? GetString(STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED, bridge_data.spec->material, packed_velocity)
154 : GetString(STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED_COST, bridge_data.spec->material, packed_velocity, bridge_data.cost);
155 }
156
157public:
169 start_tile(start),
170 end_tile(end),
171 transport_type(transport_type),
174 bridges(std::move(bl))
175 {
176 this->CreateNestedTree();
177 this->vscroll = this->GetScrollbar(WID_BBS_SCROLLBAR);
178 /* Change the data, or the caption of the gui. Set it to road or rail, accordingly. */
179 this->GetWidget<NWidgetCore>(WID_BBS_CAPTION)->SetString((transport_type == TransportType::Road) ? STR_SELECT_ROAD_BRIDGE_CAPTION : STR_SELECT_RAIL_BRIDGE_CAPTION);
180 this->FinishInitNested(transport_type); // Initializes 'this->icon_width'.
181
182 this->parent = FindWindowById(WindowClass::BuildToolbar, transport_type);
185 this->bridges.NeedResort();
186 this->SortBridgeList();
187
188 this->vscroll->SetCount(this->bridges.size());
189 }
190
193 {
195 }
196
197 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
198 {
199 switch (widget) {
202 d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
203 d.height += padding.height;
204 size = maxdim(size, d);
205 break;
206 }
209 d.width += padding.width;
210 d.height += padding.height;
211 size = maxdim(size, d);
212 break;
213 }
214 case WID_BBS_BRIDGE_LIST: {
215 Dimension sprite_dim = {0, 0}; // Biggest bridge sprite dimension
216 Dimension text_dim = {0, 0}; // Biggest text dimension
217 for (const BuildBridgeData &bridge_data : this->bridges) {
218 sprite_dim = maxdim(sprite_dim, GetScaledSpriteSize(bridge_data.spec->sprite));
219 text_dim = maxdim(text_dim, GetStringBoundingBox(GetBridgeSelectString(bridge_data)));
220 }
221 fill.height = resize.height = std::max(sprite_dim.height, text_dim.height) + padding.height; // Max of both sizes + account for matrix edges.
222
223 this->icon_width = sprite_dim.width; // Width of bridge icon.
224 size.width = this->icon_width + WidgetDimensions::scaled.hsep_normal + text_dim.width + padding.width;
225 size.height = 4 * resize.height; // Smallest bridge gui is 4 entries high in the matrix.
226 break;
227 }
228 }
229 }
230
231 Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
232 {
233 /* Position the window so hopefully the first bridge from the list is under the mouse pointer. */
235 Point corner; // point of the top left corner of the window.
236 corner.y = Clamp(_cursor.pos.y - list->pos_y - 5, GetMainViewTop(), GetMainViewBottom() - sm_height);
237 corner.x = Clamp(_cursor.pos.x - list->pos_x - 5, 0, _screen.width - sm_width);
238 return corner;
239 }
240
241 void DrawWidget(const Rect &r, WidgetID widget) const override
242 {
243 switch (widget) {
245 this->DrawSortButton(widget, this->bridges.IsDescSortOrder());
246 break;
247
248 case WID_BBS_BRIDGE_LIST: {
249 Rect tr = r.WithHeight(this->resize.step_height).Shrink(WidgetDimensions::scaled.matrix);
250 bool rtl = _current_text_dir == TD_RTL;
251 auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->bridges);
252 for (auto it = first; it != last; ++it) {
253 const BridgeSpec *b = it->spec;
254 DrawSpriteIgnorePadding(b->sprite, b->pal, tr.WithWidth(this->icon_width, rtl), {AlignmentH::Centre, AlignmentV::Bottom});
255 DrawStringMultiLineWithClipping(tr.Indent(this->icon_width + WidgetDimensions::scaled.hsep_normal, rtl), GetBridgeSelectString(*it));
256 tr = tr.Translate(0, this->resize.step_height);
257 }
258 break;
259 }
260 }
261 }
262
263 EventState OnKeyPress([[maybe_unused]] char32_t key, uint16_t keycode) override
264 {
265 const uint8_t i = keycode - '1';
266 if (i < 9 && i < this->bridges.size()) {
267 /* Build the requested bridge */
268 this->BuildBridge(this->bridges[i].index);
269 this->Close();
270 return EventState::Handled;
271 }
273 }
274
275 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
276 {
277 switch (widget) {
278 default: break;
279 case WID_BBS_BRIDGE_LIST: {
280 auto it = this->vscroll->GetScrolledItemFromWidget(this->bridges, pt.y, this, WID_BBS_BRIDGE_LIST);
281 if (it != this->bridges.end()) {
282 this->BuildBridge(it->index);
283 this->Close();
284 }
285 break;
286 }
287
289 this->bridges.ToggleSortOrder();
290 this->SetDirty();
291 break;
292
295 break;
296 }
297 }
298
299 void OnDropdownSelect(WidgetID widget, int index, int) override
300 {
301 if (widget == WID_BBS_DROPDOWN_CRITERIA && this->bridges.SortType() != index) {
302 this->bridges.SetSortType(index);
303
304 this->SortBridgeList();
305 }
306 }
307
308 void OnResize() override
309 {
310 this->vscroll->SetCapacityFromWidget(this, WID_BBS_BRIDGE_LIST);
311 }
312};
313
316
318const std::initializer_list<GUIBridgeList::SortFunction * const> BuildBridgeWindow::sorter_funcs = {
322};
323
325static constexpr std::initializer_list<NWidgetPart> _nested_build_bridge_widgets = {
326 /* Header */
329 NWidget(WWT_CAPTION, Colours::DarkGreen, WID_BBS_CAPTION), SetStringTip(STR_SELECT_RAIL_BRIDGE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
331 EndContainer(),
332
335 /* Sort order + criteria buttons */
337 NWidget(WWT_TEXTBTN, Colours::DarkGreen, WID_BBS_DROPDOWN_ORDER), SetFill(1, 0), SetStringTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
339 EndContainer(),
340 /* Matrix. */
341 NWidget(WWT_MATRIX, Colours::DarkGreen, WID_BBS_BRIDGE_LIST), SetFill(1, 0), SetResize(0, 22), SetMatrixDataTip(1, 0, STR_SELECT_BRIDGE_SELECTION_TOOLTIP), SetScrollbar(WID_BBS_SCROLLBAR),
342 EndContainer(),
343
344 /* scrollbar + resize button */
348 EndContainer(),
349 EndContainer(),
350};
351
354 WindowPosition::Automatic, "build_bridge", 200, 114,
355 WindowClass::BuildBridge, WindowClass::BuildToolbar,
358);
359
371void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, RailType railtype, RoadType roadtype)
372{
373 CloseWindowByClass(WindowClass::BuildBridge);
374
375 /* The bridge length without ramps. */
376 const uint bridge_len = GetTunnelBridgeLength(start, end);
377
378 /* If Ctrl is being pressed, check whether the last bridge built is available
379 * If so, return this bridge type. Otherwise continue normally.
380 * We store bridge types for each transport type, so we have to check for
381 * the transport type beforehand.
382 */
383 BridgeType last_bridge_type = 0;
384 switch (transport_type) {
385 case TransportType::Road: last_bridge_type = _last_roadbridge_type; break;
386 case TransportType::Rail: last_bridge_type = _last_railbridge_type; break;
387 default: break; // water ways and air routes don't have bridge types
388 }
389 if (IsCtrlPressed() && CheckBridgeAvailability(last_bridge_type, bridge_len).Succeeded()) {
390 Command<Commands::BuildBridge>::Post(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE, CcBuildBridge, end, start, transport_type, last_bridge_type, railtype, roadtype);
391 return;
392 }
393
394 /* only query bridge building possibility once, result is the same for all bridges!
395 * returns CMD_ERROR on failure, and price on success */
396 CommandCost ret = Command<Commands::BuildBridge>::Do(CommandFlagsToDCFlags(GetCommandFlags<Commands::BuildBridge>()) | DoCommandFlag::QueryCost, end, start, transport_type, 0, railtype, roadtype);
397
398 GUIBridgeList bl;
399 if (!ret.Failed()) {
400 /* check which bridges can be built */
401 const uint tot_bridgedata_len = CalcBridgeLenCostFactor(bridge_len + 2);
402
403 Money infra_cost = 0;
404 switch (transport_type) {
405 case TransportType::Road: {
406 /* In case we add a new road type as well, we must be aware of those costs. */
407 RoadType road_rt = INVALID_ROADTYPE;
408 RoadType tram_rt = INVALID_ROADTYPE;
409 if (IsBridgeTile(start)) {
410 road_rt = GetRoadTypeRoad(start);
411 tram_rt = GetRoadTypeTram(start);
412 }
413 if (RoadTypeIsRoad(roadtype)) {
414 road_rt = roadtype;
415 } else {
416 tram_rt = roadtype;
417 }
418
419 if (road_rt != INVALID_ROADTYPE) infra_cost += (bridge_len + 2) * 2 * RoadBuildCost(road_rt);
420 if (tram_rt != INVALID_ROADTYPE) infra_cost += (bridge_len + 2) * 2 * RoadBuildCost(tram_rt);
421
422 break;
423 }
424 case TransportType::Rail: infra_cost = (bridge_len + 2) * RailBuildCost(railtype); break;
425 default: break;
426 }
427
428 bool any_available = false;
429 CommandCost type_check;
430 /* loop for all bridgetypes */
431 for (BridgeType brd_type = 0; brd_type != MAX_BRIDGES; brd_type++) {
432 type_check = CheckBridgeAvailability(brd_type, bridge_len);
433 if (type_check.Succeeded()) {
434 /* bridge is accepted, add to list */
435 BuildBridgeData &item = bl.emplace_back();
436 item.index = brd_type;
437 item.spec = GetBridgeSpec(brd_type);
438 /* Add to terraforming & bulldozing costs the cost of the
439 * bridge itself (not computed with DoCommandFlag::QueryCost) */
440 item.cost = ret.GetCost() + (((int64_t)tot_bridgedata_len * _price[Price::BuildBridge] * item.spec->price) >> 8) + infra_cost;
441 any_available = true;
442 }
443 }
444 /* give error cause if no bridges available here*/
445 if (!any_available) ret = std::move(type_check);
446 }
447
448 if (!bl.empty()) {
449 new BuildBridgeWindow(_build_bridge_desc, start, end, transport_type, railtype, roadtype, std::move(bl));
450 } else {
451 ShowErrorMessage(GetEncodedString(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE), TileX(end) * TILE_SIZE, TileY(end) * TILE_SIZE, ret);
452 }
453}
Header file for bridges.
int CalcBridgeLenCostFactor(int x)
Calculate the price factor for building a long bridge.
const BridgeSpec * GetBridgeSpec(BridgeType i)
Get the specification of a bridge type.
Definition bridge.h:63
static const uint MAX_BRIDGES
Maximal number of available bridge specs.
Definition bridge.h:18
CommandCost CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoCommandFlags flags={})
Is a bridge of the specified type and length available?
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, RailType railtype, RoadType roadtype)
Prepare the data for the build a bridge window.
static WindowDesc _build_bridge_desc(WindowPosition::Automatic, "build_bridge", 200, 114, WindowClass::BuildBridge, WindowClass::BuildToolbar, WindowDefaultFlag::Construction, _nested_build_bridge_widgets)
Window definition for the rail bridge selection window.
GUIList< BuildBridgeData > GUIBridgeList
List of bridges, used in BuildBridgeWindow.
static BridgeType _last_railbridge_type
The type of the last built rail bridge.
void CcBuildBridge(Commands, const CommandCost &result, TileIndex end_tile, TileIndex tile_start, TransportType transport_type, BridgeType, RailType, RoadType)
Callback executed after a build Bridge CMD has been called.
static constexpr std::initializer_list< NWidgetPart > _nested_build_bridge_widgets
Widgets of the bridge gui.
static BridgeType _last_roadbridge_type
The type of the last built road bridge.
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
Definition bridge_map.h:35
uint BridgeType
Bridge spec number.
Definition bridge_type.h:15
Types related to the bridge widgets.
@ WID_BBS_DROPDOWN_CRITERIA
Criteria of sort dropdown.
@ WID_BBS_BRIDGE_LIST
List of bridges.
@ WID_BBS_DROPDOWN_ORDER
Direction of sort dropdown.
@ WID_BBS_SCROLLBAR
Scrollbar of the list.
@ WID_BBS_CAPTION
Caption of the window.
Window class for handling the bridge-build GUI.
void OnResize() override
Called after the window got resized.
void SortBridgeList()
Sort the builable bridges.
RoadType roadtype
Road type to build if building a road bridge.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
std::string GetBridgeSelectString(const BuildBridgeData &bridge_data) const
Get the StringID to draw in the selection list and set the appropriate DParams.
static const StringID sorter_names[]
Strings describing how bridges are sorted.
static bool BridgePriceSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their price.
RailType railtype
Rail type to build if building a rail bridge.
EventState OnKeyPress(char32_t key, uint16_t keycode) override
A key has been pressed.
~BuildBridgeWindow() override
Save the last sorting state.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Point OnInitialPosition(int16_t sm_width, int16_t sm_height, int window_number) override
Compute the initial position of the window.
static bool BridgeSpeedSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their maximum speed.
static bool BridgeIndexSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their index.
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.
static const std::initializer_list< GUIBridgeList::SortFunction *const > sorter_funcs
Functions to sort bridges.
static Listing last_sorting
Last setting of the sort.
BuildBridgeWindow(WindowDesc &desc, TileIndex start, TileIndex end, TransportType transport_type, RailType railtype, RoadType roadtype, GUIBridgeList &&bl)
Create this BuildBridgeWindoow.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
int icon_width
Scaled width of the the bridge icon sprite.
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
Money GetCost() const
The costs as made up to this moment.
bool Failed() const
Did this command fail?
List template of 'things' T to sort in a GUI.
void SetListing(Listing l)
Import sort conditions.
bool IsDescSortOrder() const
Check if the sort order is descending.
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
bool Sort(Comp compare)
Sort the list.
uint8_t SortType() const
Get the sorttype of the list.
Listing GetListing() const
Export current sort conditions.
void SetSortFuncs(std::span< SortFunction *const > n_funcs)
Hand the sort function pointers to the GUIList.
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
void SetSortType(uint8_t n_type)
Set the sorttype of the list.
Baseclass for nested widgets.
int pos_y
Vertical position of top-left corner of the widget in the window.
int pos_x
Horizontal position of top-left corner of the widget in the window.
Scrollbar data structure.
void SetCount(size_t num)
Sets the number of elements in the list.
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.
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:2548
auto GetVisibleRangeIterators(Tcontainer &container) const
Get a pair of iterators for the range of visible elements in a container.
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
CommandFlags GetCommandFlags(Commands cmd)
Get the command flags associated with the given command.
Definition command.cpp:112
Functions related to commands.
static constexpr DoCommandFlags CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
@ QueryCost
query cost only, don't build.
Commands
List of commands.
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
DiagDirection
Enumeration for diagonal directions.
void ShowDropDownMenu(Window *w, std::span< const StringID > strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width, DropDownOptions options, std::string *const persistent_filter_text)
Show a dropdown menu window near a widget of the parent window.
Definition dropdown.cpp:633
Functions related to the drop down widget.
Prices _price
Prices and also the fractional part.
Definition economy.cpp:109
@ BuildBridge
Price for building bridges.
Functions related to errors.
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Geometry functions.
bool DrawStringMultiLineWithClipping(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour, Alignment 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
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:894
Dimension GetStringListBoundingBox(std::span< const StringID > list, FontSize fontsize)
Get maximum dimension of a list of strings.
Definition gfx.cpp:933
Functions related to the gfx engine.
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
Definition widget.cpp:70
bool IsCtrlPressed()
Test if the ctrl key is pressed.
Definition gfx_func.h:82
void DrawSpriteIgnorePadding(SpriteID img, PaletteID pal, const Rect &r, Alignment align)
Draw a sprite within a Rect, ignoring the sprite's padding.
Definition widget.cpp:350
@ DarkGreen
Dark green.
Definition gfx_type.h:292
constexpr NWidgetPart SetMatrixDataTip(uint32_t cols, uint32_t rows, StringID tip={})
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
Definition window.cpp:1013
#define Point
Macro that prevents name conflicts between included headers.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:429
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:419
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition math_func.hpp:79
@ Editor
In the scenario editor.
Definition openttd.h:21
Rail specific functions.
Money RailBuildCost(RailType railtype)
Returns the cost of building the specified railtype.
Definition rail.h:448
RailType
Enumeration for all possible railtypes.
Definition rail_type.h:26
@ INVALID_RAILTYPE
Flag for invalid railtype.
Definition rail_type.h:33
Road specific functions.
Money RoadBuildCost(RoadType roadtype)
Returns the cost of building the specified roadtype.
Definition road.h:242
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:166
Functions/types related to the road GUIs.
RoadType GetRoadTypeRoad(Tile t)
Get the road type for RoadTramType being RoadTramType::Road.
Definition road_map.h:152
RoadType GetRoadTypeTram(Tile t)
Get the road type for RoadTramType being RoadTramType::Tram.
Definition road_map.h:163
RoadType
The different roadtypes we support.
Definition road_type.h:24
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition road_type.h:29
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
Base types for having sorted lists in GUIs.
Functions related to sound.
@ SND_27_CONSTRUCTION_BRIDGE
37 == 0x25 Construction: bridge
Definition sound_type.h:84
Definition of base types and functions in a cross-platform compatible way.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:89
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:423
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:55
Functions related to OTTD's strings.
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
Struct containing information about a single bridge type.
Definition bridge.h:27
uint16_t price
the price multiplier
Definition bridge.h:40
PaletteID pal
the palette which is used in the GUI
Definition bridge.h:43
StringID material
the string that contains the bridge description
Definition bridge.h:44
SpriteID sprite
the sprite which is used in the GUI
Definition bridge.h:42
uint16_t speed
maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
Definition bridge.h:41
Carriage for the data we need if we want to build a bridge.
T y
Y coordinate.
T x
X coordinate.
Dimensions (a width and height) of a rectangle in 2D.
value_type height
The height of the rectangle.
value_type width
The width of the rectangle.
Data structure describing how to show the list (what sort direction and criteria).
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
High level window description.
Definition window_gui.h:171
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1150
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition widget.cpp:839
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1855
Window * parent
Parent window.
Definition window_gui.h:327
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:565
ResizeInfo resize
Resize information.
Definition window_gui.h:313
void DrawSortButton(WidgetID widget, bool descending) const
Draw a sort button's up or down arrow symbol.
Definition widget.cpp:824
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1845
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1879
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:322
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:301
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:100
static constexpr uint TILE_SIZE
Tile size in world coordinates.
Definition tile_type.h:15
TransportType
Available types of transport.
@ Invalid
Sentinel for invalid transport types.
@ Rail
Transport by train.
@ Road
Transport by road vehicle.
Header file for things common for tunnels and bridges.
uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles).
Command definitions related to tunnels and bridges.
Functions that have tunnels and bridges in common.
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
VehicleType
Available vehicle types.
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:44
@ WWT_MATRIX
Grid of rows and columns.
Definition widget_type.h:50
@ WWT_CAPTION
Window caption (window title between closebox and stickybox).
Definition widget_type.h:52
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
@ WWT_CLOSEBOX
Close box (at top-left of a window).
Definition widget_type.h:60
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window).
Definition widget_type.h:59
@ 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
Drop down list.
Definition widget_type.h:61
int GetMainViewTop()
Return the top of the main view available for general use.
Definition window.cpp:2186
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1255
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Definition window.cpp:2197
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition window.cpp:1199
Window functions not directly related to making/drawing windows.
@ Construction
This window is used for construction; close it whenever changing company.
Definition window_gui.h:154
@ Automatic
Find a place automatically.
Definition window_gui.h:145
int WidgetID
Widget ID.
Definition window_type.h:21
EventState
State of handling an event.
@ Handled
The passed event is handled.
@ NotHandled
The passed event is not handled.