OpenTTD Source  13.2.1
bridge_gui.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #include "stdafx.h"
11 #include "error.h"
12 #include "command_func.h"
13 #include "rail.h"
14 #include "road.h"
15 #include "strings_func.h"
16 #include "window_func.h"
17 #include "sound_func.h"
18 #include "gfx_func.h"
19 #include "tunnelbridge.h"
20 #include "sortlist_type.h"
21 #include "widgets/dropdown_func.h"
22 #include "core/geometry_func.hpp"
23 #include "tunnelbridge_map.h"
24 #include "road_gui.h"
25 #include "tunnelbridge_cmd.h"
26 
27 #include "widgets/bridge_widget.h"
28 
29 #include "table/strings.h"
30 
31 #include "safeguards.h"
32 
37 
42  BridgeType index;
43  const BridgeSpec *spec;
44  Money cost;
45 };
46 
48 
58 void CcBuildBridge(Commands cmd, const CommandCost &result, TileIndex end_tile, TileIndex tile_start, TransportType transport_type, BridgeType, byte)
59 {
60  if (result.Failed()) return;
61  if (_settings_client.sound.confirm) SndPlayTileFx(SND_27_CONSTRUCTION_BRIDGE, end_tile);
62 
63  if (transport_type == TRANSPORT_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 
73 class BuildBridgeWindow : public Window {
74 private:
75  /* Runtime saved values */
77 
78  /* Constants for sorting the bridges */
79  static const StringID sorter_names[];
81 
82  /* Internal variables */
83  TileIndex start_tile;
84  TileIndex end_tile;
85  TransportType transport_type;
86  byte road_rail_type;
87  GUIBridgeList *bridges;
89  Scrollbar *vscroll;
90 
92  static bool BridgeIndexSorter(const BuildBridgeData &a, const BuildBridgeData &b)
93  {
94  return a.index < b.index;
95  }
96 
98  static bool BridgePriceSorter(const BuildBridgeData &a, const BuildBridgeData &b)
99  {
100  return a.cost < b.cost;
101  }
102 
104  static bool BridgeSpeedSorter(const BuildBridgeData &a, const BuildBridgeData &b)
105  {
106  return a.spec->speed < b.spec->speed;
107  }
108 
109  void BuildBridge(uint8 i)
110  {
111  switch (this->transport_type) {
112  case TRANSPORT_RAIL: _last_railbridge_type = this->bridges->at(i).index; break;
113  case TRANSPORT_ROAD: _last_roadbridge_type = this->bridges->at(i).index; break;
114  default: break;
115  }
116  Command<CMD_BUILD_BRIDGE>::Post(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE, CcBuildBridge,
117  this->end_tile, this->start_tile, this->transport_type, this->bridges->at(i).index, this->road_rail_type);
118  }
119 
122  {
123  this->bridges->Sort();
124 
125  /* Display the current sort variant */
126  this->GetWidget<NWidgetCore>(WID_BBS_DROPDOWN_CRITERIA)->widget_data = this->sorter_names[this->bridges->SortType()];
127 
128  /* Set the modified widgets dirty */
131  }
132 
139  {
140  SetDParam(0, bridge_data.spec->material);
141  SetDParam(1, bridge_data.spec->speed);
142  SetDParam(2, bridge_data.cost);
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 ? STR_SELECT_BRIDGE_INFO_NAME : STR_SELECT_BRIDGE_INFO_NAME_COST;
146  }
147  return _game_mode == GM_EDITOR ? STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED : STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED_COST;
148  }
149 
150 public:
151  BuildBridgeWindow(WindowDesc *desc, TileIndex start, TileIndex end, TransportType transport_type, byte road_rail_type, GUIBridgeList *bl) : Window(desc),
152  start_tile(start),
153  end_tile(end),
154  transport_type(transport_type),
155  road_rail_type(road_rail_type),
156  bridges(bl)
157  {
158  this->CreateNestedTree();
159  this->vscroll = this->GetScrollbar(WID_BBS_SCROLLBAR);
160  /* Change the data, or the caption of the gui. Set it to road or rail, accordingly. */
161  this->GetWidget<NWidgetCore>(WID_BBS_CAPTION)->widget_data = (transport_type == TRANSPORT_ROAD) ? STR_SELECT_ROAD_BRIDGE_CAPTION : STR_SELECT_RAIL_BRIDGE_CAPTION;
162  this->FinishInitNested(transport_type); // Initializes 'this->bridgetext_offset'.
163 
164  this->parent = FindWindowById(WC_BUILD_TOOLBAR, transport_type);
165  this->bridges->SetListing(this->last_sorting);
166  this->bridges->SetSortFuncs(this->sorter_funcs);
167  this->bridges->NeedResort();
168  this->SortBridgeList();
169 
170  this->vscroll->SetCount((uint)bl->size());
171  }
172 
174  {
175  this->last_sorting = this->bridges->GetListing();
176 
177  delete bridges;
178  }
179 
180  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
181  {
182  switch (widget) {
183  case WID_BBS_DROPDOWN_ORDER: {
184  Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
185  d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
186  d.height += padding.height;
187  *size = maxdim(*size, d);
188  break;
189  }
191  Dimension d = {0, 0};
192  for (const StringID *str = this->sorter_names; *str != INVALID_STRING_ID; str++) {
193  d = maxdim(d, GetStringBoundingBox(*str));
194  }
195  d.width += padding.width;
196  d.height += padding.height;
197  *size = maxdim(*size, d);
198  break;
199  }
200  case WID_BBS_BRIDGE_LIST: {
201  Dimension sprite_dim = {0, 0}; // Biggest bridge sprite dimension
202  Dimension text_dim = {0, 0}; // Biggest text dimension
203  for (const BuildBridgeData &bridge_data : *this->bridges) {
204  sprite_dim = maxdim(sprite_dim, GetSpriteSize(bridge_data.spec->sprite));
205  text_dim = maxdim(text_dim, GetStringBoundingBox(GetBridgeSelectString(bridge_data)));
206  }
207  sprite_dim.height++; // Sprite is rendered one pixel down in the matrix field.
208  text_dim.height++; // Allowing the bottom row pixels to be rendered on the edge of the matrix field.
209  resize->height = std::max(sprite_dim.height, text_dim.height) + padding.height; // Max of both sizes + account for matrix edges.
210 
211  this->bridgetext_offset = sprite_dim.width + WidgetDimensions::scaled.hsep_normal; // Left edge of text, 1 pixel distance from the sprite.
212  size->width = this->bridgetext_offset + text_dim.width + padding.width;
213  size->height = 4 * resize->height; // Smallest bridge gui is 4 entries high in the matrix.
214  break;
215  }
216  }
217  }
218 
219  Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
220  {
221  /* Position the window so hopefully the first bridge from the list is under the mouse pointer. */
222  NWidgetBase *list = this->GetWidget<NWidgetBase>(WID_BBS_BRIDGE_LIST);
223  Point corner; // point of the top left corner of the window.
224  corner.y = Clamp(_cursor.pos.y - list->pos_y - 5, GetMainViewTop(), GetMainViewBottom() - sm_height);
225  corner.x = Clamp(_cursor.pos.x - list->pos_x - 5, 0, _screen.width - sm_width);
226  return corner;
227  }
228 
229  void DrawWidget(const Rect &r, int widget) const override
230  {
231  switch (widget) {
233  this->DrawSortButtonState(widget, this->bridges->IsDescSortOrder() ? SBS_DOWN : SBS_UP);
234  break;
235 
236  case WID_BBS_BRIDGE_LIST: {
238  for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < (int)this->bridges->size(); i++) {
239  const BuildBridgeData &bridge_data = this->bridges->at(i);
240  const BridgeSpec *b = bridge_data.spec;
241  DrawSprite(b->sprite, b->pal, tr.left, tr.bottom - GetSpriteSize(b->sprite).height);
242  DrawStringMultiLine(tr.Indent(this->bridgetext_offset, false), GetBridgeSelectString(bridge_data));
243  tr = tr.Translate(0, this->resize.step_height);
244  }
245  break;
246  }
247  }
248  }
249 
250  EventState OnKeyPress(WChar key, uint16 keycode) override
251  {
252  const uint8 i = keycode - '1';
253  if (i < 9 && i < this->bridges->size()) {
254  /* Build the requested bridge */
255  this->BuildBridge(i);
256  this->Close();
257  return ES_HANDLED;
258  }
259  return ES_NOT_HANDLED;
260  }
261 
262  void OnClick(Point pt, int widget, int click_count) override
263  {
264  switch (widget) {
265  default: break;
266  case WID_BBS_BRIDGE_LIST: {
267  uint i = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_BBS_BRIDGE_LIST);
268  if (i < this->bridges->size()) {
269  this->BuildBridge(i);
270  this->Close();
271  }
272  break;
273  }
274 
276  this->bridges->ToggleSortOrder();
277  this->SetDirty();
278  break;
279 
281  ShowDropDownMenu(this, this->sorter_names, this->bridges->SortType(), WID_BBS_DROPDOWN_CRITERIA, 0, 0);
282  break;
283  }
284  }
285 
286  void OnDropdownSelect(int widget, int index) 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 
303 
306  &BridgeIndexSorter,
307  &BridgePriceSorter,
308  &BridgeSpeedSorter
309 };
310 
313  STR_SORT_BY_NUMBER,
314  STR_SORT_BY_COST,
315  STR_SORT_BY_MAX_SPEED,
317 };
318 
321  /* Header */
323  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
324  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_BBS_CAPTION), SetDataTip(STR_SELECT_RAIL_BRIDGE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
325  NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
326  EndContainer(),
327 
330  /* Sort order + criteria buttons */
332  NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_BBS_DROPDOWN_ORDER), SetFill(1, 0), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
333  NWidget(WWT_DROPDOWN, COLOUR_DARK_GREEN, WID_BBS_DROPDOWN_CRITERIA), SetFill(1, 0), SetDataTip(0x0, STR_TOOLTIP_SORT_CRITERIA),
334  EndContainer(),
335  /* Matrix. */
336  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),
337  EndContainer(),
338 
339  /* scrollbar + resize button */
341  NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_BBS_SCROLLBAR),
342  NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
343  EndContainer(),
344  EndContainer(),
345 };
346 
349  WDP_AUTO, "build_bridge", 200, 114,
353 );
354 
365 void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, byte road_rail_type)
366 {
368 
369  /* The bridge length without ramps. */
370  const uint bridge_len = GetTunnelBridgeLength(start, end);
371 
372  /* If Ctrl is being pressed, check whether the last bridge built is available
373  * If so, return this bridge type. Otherwise continue normally.
374  * We store bridge types for each transport type, so we have to check for
375  * the transport type beforehand.
376  */
377  BridgeType last_bridge_type = 0;
378  switch (transport_type) {
379  case TRANSPORT_ROAD: last_bridge_type = _last_roadbridge_type; break;
380  case TRANSPORT_RAIL: last_bridge_type = _last_railbridge_type; break;
381  default: break; // water ways and air routes don't have bridge types
382  }
383  if (_ctrl_pressed && CheckBridgeAvailability(last_bridge_type, bridge_len).Succeeded()) {
384  Command<CMD_BUILD_BRIDGE>::Post(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE, CcBuildBridge, end, start, transport_type, last_bridge_type, road_rail_type);
385  return;
386  }
387 
388  /* only query bridge building possibility once, result is the same for all bridges!
389  * returns CMD_ERROR on failure, and price on success */
390  StringID errmsg = INVALID_STRING_ID;
391  CommandCost ret = Command<CMD_BUILD_BRIDGE>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_BRIDGE>()) | DC_QUERY_COST, end, start, transport_type, 0, road_rail_type);
392 
393  GUIBridgeList *bl = nullptr;
394  if (ret.Failed()) {
395  errmsg = ret.GetErrorMessage();
396  } else {
397  /* check which bridges can be built */
398  const uint tot_bridgedata_len = CalcBridgeLenCostFactor(bridge_len + 2);
399 
400  bl = new GUIBridgeList();
401 
402  Money infra_cost = 0;
403  switch (transport_type) {
404  case TRANSPORT_ROAD: {
405  /* In case we add a new road type as well, we must be aware of those costs. */
406  RoadType road_rt = INVALID_ROADTYPE;
407  RoadType tram_rt = INVALID_ROADTYPE;
408  if (IsBridgeTile(start)) {
409  road_rt = GetRoadTypeRoad(start);
410  tram_rt = GetRoadTypeTram(start);
411  }
412  if (RoadTypeIsRoad((RoadType)road_rail_type)) {
413  road_rt = (RoadType)road_rail_type;
414  } else {
415  tram_rt = (RoadType)road_rail_type;
416  }
417 
418  if (road_rt != INVALID_ROADTYPE) infra_cost += (bridge_len + 2) * 2 * RoadBuildCost(road_rt);
419  if (tram_rt != INVALID_ROADTYPE) infra_cost += (bridge_len + 2) * 2 * RoadBuildCost(tram_rt);
420 
421  break;
422  }
423  case TRANSPORT_RAIL: infra_cost = (bridge_len + 2) * RailBuildCost((RailType)road_rail_type); break;
424  default: break;
425  }
426 
427  bool any_available = false;
428  CommandCost type_check;
429  /* loop for all bridgetypes */
430  for (BridgeType brd_type = 0; brd_type != MAX_BRIDGES; brd_type++) {
431  type_check = CheckBridgeAvailability(brd_type, bridge_len);
432  if (type_check.Succeeded()) {
433  /* bridge is accepted, add to list */
434  BuildBridgeData &item = bl->emplace_back();
435  item.index = brd_type;
436  item.spec = GetBridgeSpec(brd_type);
437  /* Add to terraforming & bulldozing costs the cost of the
438  * bridge itself (not computed with DC_QUERY_COST) */
439  item.cost = ret.GetCost() + (((int64)tot_bridgedata_len * _price[PR_BUILD_BRIDGE] * item.spec->price) >> 8) + infra_cost;
440  any_available = true;
441  }
442  }
443  /* give error cause if no bridges available here*/
444  if (!any_available)
445  {
446  errmsg = type_check.GetErrorMessage();
447  }
448  }
449 
450  if (bl != nullptr && bl->size() != 0) {
451  new BuildBridgeWindow(&_build_bridge_desc, start, end, transport_type, road_rail_type, bl);
452  } else {
453  delete bl;
454  ShowErrorMessage(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE, errmsg, WL_INFO, TileX(end) * TILE_SIZE, TileY(end) * TILE_SIZE);
455  }
456 }
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:720
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:219
tunnelbridge.h
sound_func.h
BuildBridgeWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: bridge_gui.cpp:295
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:66
WChar
char32_t WChar
Type for wide characters, i.e.
Definition: string_type.h:36
CalcBridgeLenCostFactor
int CalcBridgeLenCostFactor(int x)
Calculate the price factor for building a long bridge.
Definition: tunnelbridge_cmd.cpp:107
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1210
BuildBridgeWindow::OnKeyPress
EventState OnKeyPress(WChar key, uint16 keycode) override
A key has been pressed.
Definition: bridge_gui.cpp:250
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:890
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:319
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:144
dropdown_func.h
Commands
Commands
List of commands.
Definition: command_type.h:176
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:92
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:79
tunnelbridge_map.h
CommandFlagsToDCFlags
static constexpr DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
Definition: command_func.h:59
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
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:1775
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:1161
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:717
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:38
BuildBridgeWindow::last_sorting
static Listing last_sorting
Last setting of the sort.
Definition: bridge_gui.cpp:76
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:997
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
BuildBridgeWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: bridge_gui.cpp:286
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
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:98
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:2353
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:636
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:141
Rect::WithHeight
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Definition: geometry_type.hpp:205
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:975
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition: road_type.h:27
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1111
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:151
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:890
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:377
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:789
gfx_func.h
WindowDesc
High level window description.
Definition: window_gui.h:102
BridgeSpec
Struct containing information about a single bridge type.
Definition: bridge.h:41
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
TRANSPORT_RAIL
@ TRANSPORT_RAIL
Transport by train.
Definition: transport_type.h:27
_nested_build_bridge_widgets
static const NWidgetPart _nested_build_bridge_widgets[]
Widgets of the bridge gui.
Definition: bridge_gui.cpp:320
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:90
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:251
CommandCost
Common return value for all commands.
Definition: command_type.h:24
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:607
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition: geometry_type.hpp:168
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
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:1008
GUIList::SetListing
void SetListing(Listing l)
Import sort conditions.
Definition: sortlist_type.h:130
TransportType
TransportType
Available types of transport.
Definition: transport_type.h:19
_last_railbridge_type
static BridgeType _last_railbridge_type
The type of the last built rail bridge.
Definition: bridge_gui.cpp:34
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:721
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:160
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:1129
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:199
road_gui.h
GetMainViewTop
int GetMainViewTop()
Return the top of the main view available for general use.
Definition: window.cpp:2124
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:92
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:266
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:382
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:192
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:83
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:1058
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:481
tunnelbridge_cmd.h
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:241
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition: window_gui.h:154
BuildBridgeWindow
Window class for handling the bridge-build GUI.
Definition: bridge_gui.cpp:73
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:993
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:365
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:160
SoundSettings::confirm
bool confirm
Play sound effect on successful constructions or other actions.
Definition: settings_type.h:216
BuildBridgeWindow::SortBridgeList
void SortBridgeList()
Sort the builable bridges.
Definition: bridge_gui.cpp:121
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1096
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:199
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:262
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:1229
BuildBridgeWindow::GetBridgeSelectString
StringID GetBridgeSelectString(const BuildBridgeData &bridge_data) const
Get the StringID to draw in the selection list and set the appropriate DParams.
Definition: bridge_gui.cpp:138
geometry_func.hpp
CloseWindowByClass
void CloseWindowByClass(WindowClass cls)
Close all windows of a given class.
Definition: window.cpp:1203
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:180
EventState
EventState
State of handling an event.
Definition: window_type.h:719
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:678
BuildBridgeWindow::BridgeSpeedSorter
static bool BridgeSpeedSorter(const BuildBridgeData &a, const BuildBridgeData &b)
Sort the bridges by their maximum speed.
Definition: bridge_gui.cpp:104
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:22
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1791
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:88
CommandHelper
Definition: command_func.h:94
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
CcBuildBridge
void CcBuildBridge(Commands cmd, const CommandCost &result, TileIndex end_tile, TileIndex tile_start, TransportType transport_type, BridgeType, byte)
Callback executed after a build Bridge CMD has been called.
Definition: bridge_gui.cpp:58
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
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:2427
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:907
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:200
RoadBuildCost
static Money RoadBuildCost(RoadType roadtype)
Returns the cost of building the specified roadtype.
Definition: road.h:250
TRANSPORT_ROAD
@ TRANSPORT_ROAD
Transport by road vehicle.
Definition: transport_type.h:28
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1080
BuildBridgeWindow::sorter_funcs
static GUIBridgeList::SortFunction *const sorter_funcs[]
Available bridge sorting functions.
Definition: bridge_gui.cpp:80
Window
Data structure for an opened window.
Definition: window_gui.h:213
BuildBridgeWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: bridge_gui.cpp:229
DC_QUERY_COST
@ DC_QUERY_COST
query cost only, don't build.
Definition: command_type.h:359
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:109
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:161
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:621
GetMainViewBottom
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Definition: window.cpp:2135
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:69
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:1107