OpenTTD
bridge_gui.cpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #include "stdafx.h"
13 #include "error.h"
14 #include "command_func.h"
15 #include "rail.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 "widgets/dropdown_func.h"
23 #include "core/geometry_func.hpp"
24 #include "cmd_helper.h"
25 #include "tunnelbridge_map.h"
26 #include "road_gui.h"
27 
28 #include "widgets/bridge_widget.h"
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 
62 void CcBuildBridge(const CommandCost &result, TileIndex end_tile, uint32 p1, uint32 p2, uint32 cmd)
63 {
64  if (result.Failed()) return;
65  if (_settings_client.sound.confirm) SndPlayTileFx(SND_27_BLACKSMITH_ANVIL, end_tile);
66 
67  TransportType transport_type = Extract<TransportType, 15, 2>(p2);
68 
69  if (transport_type == TRANSPORT_ROAD) {
70  DiagDirection end_direction = ReverseDiagDir(GetTunnelBridgeDirection(end_tile));
71  ConnectRoadToStructure(end_tile, end_direction);
72 
74  ConnectRoadToStructure(p1, start_direction);
75  }
76 }
77 
79 class BuildBridgeWindow : public Window {
80 private:
81  /* Runtime saved values */
83 
84  /* Constants for sorting the bridges */
85  static const StringID sorter_names[];
86  static GUIBridgeList::SortFunction * const sorter_funcs[];
87 
88  /* Internal variables */
89  TileIndex start_tile;
90  TileIndex end_tile;
91  uint32 type;
92  GUIBridgeList *bridges;
94  Scrollbar *vscroll;
95 
97  static int CDECL BridgeIndexSorter(const BuildBridgeData *a, const BuildBridgeData *b)
98  {
99  return a->index - b->index;
100  }
101 
103  static int CDECL BridgePriceSorter(const BuildBridgeData *a, const BuildBridgeData *b)
104  {
105  return a->cost - b->cost;
106  }
107 
109  static int CDECL BridgeSpeedSorter(const BuildBridgeData *a, const BuildBridgeData *b)
110  {
111  return a->spec->speed - b->spec->speed;
112  }
113 
114  void BuildBridge(uint8 i)
115  {
116  switch ((TransportType)(this->type >> 15)) {
117  case TRANSPORT_RAIL: _last_railbridge_type = this->bridges->Get(i)->index; break;
118  case TRANSPORT_ROAD: _last_roadbridge_type = this->bridges->Get(i)->index; break;
119  default: break;
120  }
121  DoCommandP(this->end_tile, this->start_tile, this->type | this->bridges->Get(i)->index,
122  CMD_BUILD_BRIDGE | CMD_MSG(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE), CcBuildBridge);
123  }
124 
127  {
128  this->bridges->Sort();
129 
130  /* Display the current sort variant */
131  this->GetWidget<NWidgetCore>(WID_BBS_DROPDOWN_CRITERIA)->widget_data = this->sorter_names[this->bridges->SortType()];
132 
133  /* Set the modified widgets dirty */
134  this->SetWidgetDirty(WID_BBS_DROPDOWN_CRITERIA);
135  this->SetWidgetDirty(WID_BBS_BRIDGE_LIST);
136  }
137 
138 public:
139  BuildBridgeWindow(WindowDesc *desc, TileIndex start, TileIndex end, uint32 br_type, GUIBridgeList *bl) : Window(desc),
140  start_tile(start),
141  end_tile(end),
142  type(br_type),
143  bridges(bl)
144  {
145  this->CreateNestedTree();
146  this->vscroll = this->GetScrollbar(WID_BBS_SCROLLBAR);
147  /* Change the data, or the caption of the gui. Set it to road or rail, accordingly. */
148  this->GetWidget<NWidgetCore>(WID_BBS_CAPTION)->widget_data = (GB(this->type, 15, 2) == TRANSPORT_ROAD) ? STR_SELECT_ROAD_BRIDGE_CAPTION : STR_SELECT_RAIL_BRIDGE_CAPTION;
149  this->FinishInitNested(GB(br_type, 15, 2)); // Initializes 'this->bridgetext_offset'.
150 
151  this->parent = FindWindowById(WC_BUILD_TOOLBAR, GB(this->type, 15, 2));
152  this->bridges->SetListing(this->last_sorting);
153  this->bridges->SetSortFuncs(this->sorter_funcs);
154  this->bridges->NeedResort();
155  this->SortBridgeList();
156 
157  this->vscroll->SetCount(bl->Length());
158  }
159 
161  {
162  this->last_sorting = this->bridges->GetListing();
163 
164  delete bridges;
165  }
166 
167  virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
168  {
169  switch (widget) {
170  case WID_BBS_DROPDOWN_ORDER: {
171  Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
172  d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
173  d.height += padding.height;
174  *size = maxdim(*size, d);
175  break;
176  }
178  Dimension d = {0, 0};
179  for (const StringID *str = this->sorter_names; *str != INVALID_STRING_ID; str++) {
180  d = maxdim(d, GetStringBoundingBox(*str));
181  }
182  d.width += padding.width;
183  d.height += padding.height;
184  *size = maxdim(*size, d);
185  break;
186  }
187  case WID_BBS_BRIDGE_LIST: {
188  Dimension sprite_dim = {0, 0}; // Biggest bridge sprite dimension
189  Dimension text_dim = {0, 0}; // Biggest text dimension
190  for (int i = 0; i < (int)this->bridges->Length(); i++) {
191  const BridgeSpec *b = this->bridges->Get(i)->spec;
192  sprite_dim = maxdim(sprite_dim, GetSpriteSize(b->sprite));
193 
194  SetDParam(2, this->bridges->Get(i)->cost);
195  SetDParam(1, b->speed);
196  SetDParam(0, b->material);
197  text_dim = maxdim(text_dim, GetStringBoundingBox(_game_mode == GM_EDITOR ? STR_SELECT_BRIDGE_SCENEDIT_INFO : STR_SELECT_BRIDGE_INFO));
198  }
199  sprite_dim.height++; // Sprite is rendered one pixel down in the matrix field.
200  text_dim.height++; // Allowing the bottom row pixels to be rendered on the edge of the matrix field.
201  resize->height = max(sprite_dim.height, text_dim.height) + 2; // Max of both sizes + account for matrix edges.
202 
203  this->bridgetext_offset = WD_MATRIX_LEFT + sprite_dim.width + 1; // Left edge of text, 1 pixel distance from the sprite.
204  size->width = this->bridgetext_offset + text_dim.width + WD_MATRIX_RIGHT;
205  size->height = 4 * resize->height; // Smallest bridge gui is 4 entries high in the matrix.
206  break;
207  }
208  }
209  }
210 
211  virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
212  {
213  /* Position the window so hopefully the first bridge from the list is under the mouse pointer. */
214  NWidgetBase *list = this->GetWidget<NWidgetBase>(WID_BBS_BRIDGE_LIST);
215  Point corner; // point of the top left corner of the window.
216  corner.y = Clamp(_cursor.pos.y - list->pos_y - 5, GetMainViewTop(), GetMainViewBottom() - sm_height);
217  corner.x = Clamp(_cursor.pos.x - list->pos_x - 5, 0, _screen.width - sm_width);
218  return corner;
219  }
220 
221  virtual void DrawWidget(const Rect &r, int widget) const
222  {
223  switch (widget) {
225  this->DrawSortButtonState(widget, this->bridges->IsDescSortOrder() ? SBS_DOWN : SBS_UP);
226  break;
227 
228  case WID_BBS_BRIDGE_LIST: {
229  uint y = r.top;
230  for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < (int)this->bridges->Length(); i++) {
231  const BridgeSpec *b = this->bridges->Get(i)->spec;
232 
233  SetDParam(2, this->bridges->Get(i)->cost);
234  SetDParam(1, b->speed);
235  SetDParam(0, b->material);
236 
237  DrawSprite(b->sprite, b->pal, r.left + WD_MATRIX_LEFT, y + this->resize.step_height - 1 - GetSpriteSize(b->sprite).height);
238  DrawStringMultiLine(r.left + this->bridgetext_offset, r.right, y + 2, y + this->resize.step_height,
239  _game_mode == GM_EDITOR ? STR_SELECT_BRIDGE_SCENEDIT_INFO : STR_SELECT_BRIDGE_INFO);
240  y += this->resize.step_height;
241  }
242  break;
243  }
244  }
245  }
246 
247  virtual EventState OnKeyPress(WChar key, uint16 keycode)
248  {
249  const uint8 i = keycode - '1';
250  if (i < 9 && i < this->bridges->Length()) {
251  /* Build the requested bridge */
252  this->BuildBridge(i);
253  delete this;
254  return ES_HANDLED;
255  }
256  return ES_NOT_HANDLED;
257  }
258 
259  virtual void OnClick(Point pt, int widget, int click_count)
260  {
261  switch (widget) {
262  default: break;
263  case WID_BBS_BRIDGE_LIST: {
264  uint i = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_BBS_BRIDGE_LIST);
265  if (i < this->bridges->Length()) {
266  this->BuildBridge(i);
267  delete this;
268  }
269  break;
270  }
271 
273  this->bridges->ToggleSortOrder();
274  this->SetDirty();
275  break;
276 
278  ShowDropDownMenu(this, this->sorter_names, this->bridges->SortType(), WID_BBS_DROPDOWN_CRITERIA, 0, 0);
279  break;
280  }
281  }
282 
283  virtual void OnDropdownSelect(int widget, int index)
284  {
285  if (widget == WID_BBS_DROPDOWN_CRITERIA && this->bridges->SortType() != index) {
286  this->bridges->SetSortType(index);
287 
288  this->SortBridgeList();
289  }
290  }
291 
292  virtual void OnResize()
293  {
294  this->vscroll->SetCapacityFromWidget(this, WID_BBS_BRIDGE_LIST);
295  }
296 };
297 
300 
303  &BridgeIndexSorter,
304  &BridgePriceSorter,
305  &BridgeSpeedSorter
306 };
307 
310  STR_SORT_BY_NUMBER,
311  STR_SORT_BY_COST,
312  STR_SORT_BY_MAX_SPEED,
314 };
315 
318  /* Header */
320  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
321  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_BBS_CAPTION), SetDataTip(STR_SELECT_RAIL_BRIDGE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
322  NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
323  EndContainer(),
324 
327  /* Sort order + criteria buttons */
329  NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_BBS_DROPDOWN_ORDER), SetFill(1, 0), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
330  NWidget(WWT_DROPDOWN, COLOUR_DARK_GREEN, WID_BBS_DROPDOWN_CRITERIA), SetFill(1, 0), SetDataTip(0x0, STR_TOOLTIP_SORT_CRITERIA),
331  EndContainer(),
332  /* Matrix. */
333  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),
334  EndContainer(),
335 
336  /* scrollbar + resize button */
338  NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_BBS_SCROLLBAR),
339  NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
340  EndContainer(),
341  EndContainer(),
342 };
343 
346  WDP_AUTO, "build_bridge", 200, 114,
349  _nested_build_bridge_widgets, lengthof(_nested_build_bridge_widgets)
350 );
351 
362 void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, byte road_rail_type)
363 {
365 
366  /* Data type for the bridge.
367  * Bit 16,15 = transport type,
368  * 14..8 = road/rail types,
369  * 7..0 = type of bridge */
370  uint32 type = (transport_type << 15) | (road_rail_type << 8);
371 
372  /* The bridge length without ramps. */
373  const uint bridge_len = GetTunnelBridgeLength(start, end);
374 
375  /* If Ctrl is being pressed, check whether the last bridge built is available
376  * If so, return this bridge type. Otherwise continue normally.
377  * We store bridge types for each transport type, so we have to check for
378  * the transport type beforehand.
379  */
380  BridgeType last_bridge_type = 0;
381  switch (transport_type) {
382  case TRANSPORT_ROAD: last_bridge_type = _last_roadbridge_type; break;
383  case TRANSPORT_RAIL: last_bridge_type = _last_railbridge_type; break;
384  default: break; // water ways and air routes don't have bridge types
385  }
386  if (_ctrl_pressed && CheckBridgeAvailability(last_bridge_type, bridge_len).Succeeded()) {
387  DoCommandP(end, start, type | last_bridge_type, CMD_BUILD_BRIDGE | CMD_MSG(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE), CcBuildBridge);
388  return;
389  }
390 
391  /* only query bridge building possibility once, result is the same for all bridges!
392  * returns CMD_ERROR on failure, and price on success */
393  StringID errmsg = INVALID_STRING_ID;
395 
396  GUIBridgeList *bl = NULL;
397  if (ret.Failed()) {
398  errmsg = ret.GetErrorMessage();
399  } else {
400  /* check which bridges can be built */
401  const uint tot_bridgedata_len = CalcBridgeLenCostFactor(bridge_len + 2);
402 
403  bl = new GUIBridgeList();
404 
405  Money infra_cost = 0;
406  switch (transport_type) {
407  case TRANSPORT_ROAD:
408  infra_cost = (bridge_len + 2) * _price[PR_BUILD_ROAD] * 2;
409  /* In case we add a new road type as well, we must be aware of those costs. */
410  if (IsBridgeTile(start)) infra_cost *= CountBits(GetRoadTypes(start) | (RoadTypes)road_rail_type);
411  break;
412  case TRANSPORT_RAIL: infra_cost = (bridge_len + 2) * RailBuildCost((RailType)road_rail_type); break;
413  default: break;
414  }
415 
416  /* loop for all bridgetypes */
417  for (BridgeType brd_type = 0; brd_type != MAX_BRIDGES; brd_type++) {
418  if (CheckBridgeAvailability(brd_type, bridge_len).Succeeded()) {
419  /* bridge is accepted, add to list */
420  BuildBridgeData *item = bl->Append();
421  item->index = brd_type;
422  item->spec = GetBridgeSpec(brd_type);
423  /* Add to terraforming & bulldozing costs the cost of the
424  * bridge itself (not computed with DC_QUERY_COST) */
425  item->cost = ret.GetCost() + (((int64)tot_bridgedata_len * _price[PR_BUILD_BRIDGE] * item->spec->price) >> 8) + infra_cost;
426  }
427  }
428  }
429 
430  if (bl != NULL && bl->Length() != 0) {
431  new BuildBridgeWindow(&_build_bridge_desc, start, end, type, bl);
432  } else {
433  delete bl;
434  ShowErrorMessage(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE, errmsg, WL_INFO, TileX(end) * TILE_SIZE, TileY(end) * TILE_SIZE);
435  }
436 }
EventState
State of handling an event.
Definition: window_type.h:713
static GUIBridgeList::SortFunction *const sorter_funcs[]
Available bridge sorting functions.
Definition: bridge_gui.cpp:86
Functions related to OTTD&#39;s strings.
Base types for having sorted lists in GUIs.
List template of &#39;things&#39; T to sort in a GUI.
Definition: sortlist_type.h:50
Direction of sort dropdown.
Definition: bridge_widget.h:18
GUIList< BuildBridgeData > GUIBridgeList
List of bridges, used in BuildBridgeWindow.
Definition: bridge_gui.cpp:48
static BridgeType _last_roadbridge_type
The type of the last built road bridge.
Definition: bridge_gui.cpp:37
int CalcBridgeLenCostFactor(int x)
Calculate the price factor for building a long bridge.
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:930
Offset at right of a matrix cell.
Definition: window_gui.h:79
Point pos
logical mouse position
Definition: gfx_type.h:119
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:29
High level window description.
Definition: window_gui.h:168
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:165
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
Definition: bridge_map.h:35
Scrollbar data structure.
Definition: widget_type.h:589
Horizontal container.
Definition: widget_type.h:75
Functions/types related to the road GUIs.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1114
The passed event is not handled.
Definition: window_type.h:715
query cost only, don&#39;t build.
Definition: command_type.h:347
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
Rail specific functions.
static const StringID sorter_names[]
Names of the sorting functions.
Definition: bridge_gui.cpp:85
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:207
Close box (at top-left of a window)
Definition: widget_type.h:69
uint16 speed
maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
Definition: bridge.h:48
Helper functions to extract data from command parameters.
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0...
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:84
Common return value for all commands.
Definition: command_type.h:25
void CcBuildBridge(const CommandCost &result, TileIndex end_tile, uint32 p1, uint32 p2, uint32 cmd)
Callback executed after a build Bridge CMD has been called.
Definition: bridge_gui.cpp:62
CommandFlags GetCommandFlags(uint32 cmd)
Definition: command.cpp:383
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:26
Window class for handling the bridge-build GUI.
Definition: bridge_gui.cpp:79
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
Definition: bridge_gui.cpp:167
Struct containing information about a single bridge type.
Definition: bridge.h:43
Caption of the window.
Definition: bridge_widget.h:17
void SetListing(Listing l)
Import sort conditions.
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
T * Append(uint to_add=1)
Append an item and return it.
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:670
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Definition: window.cpp:2173
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:910
Data structure for an opened window.
Definition: window_gui.h:278
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:36
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:1032
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=NULL, uint textref_stack_size=0, const uint32 *textref_stack=NULL)
Display an error message in a window.
Definition: error_gui.cpp:378
static Listing last_sorting
Last setting of the sort.
Definition: bridge_gui.cpp:82
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Definition: bridge_gui.cpp:259
Functions related to errors.
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
Definition: command.cpp:440
static BridgeType _last_railbridge_type
The type of the last built rail bridge.
Definition: bridge_gui.cpp:35
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:65
uint Length() const
Get the number of items in the list.
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:1959
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: bridge_gui.cpp:221
uint pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:178
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:210
SoundSettings sound
sound effect settings
Header file for things common for tunnels and bridges.
static const NWidgetPart _nested_build_bridge_widgets[]
Widgets of the bridge gui.
Definition: bridge_gui.cpp:317
Listing GetListing() const
Export current sort conditions.
virtual void OnDropdownSelect(int widget, int index)
A dropdown option associated to this window has been selected.
Definition: bridge_gui.cpp:283
Sort descending.
Definition: window_gui.h:227
StringID GetErrorMessage() const
Returns the error message of a command.
Definition: command_type.h:142
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
static uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
Definition: tunnelbridge.h:26
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
Functions related to the gfx engine.
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:76
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:152
Definition of base types and functions in a cross-platform compatible way.
virtual void OnResize()
Called after the window got resized.
Definition: bridge_gui.cpp:292
int GetMainViewTop()
Return the top of the main view available for general use.
Definition: window.cpp:2162
static const BridgeSpec * GetBridgeSpec(BridgeType i)
Get the specification of a bridge type.
Definition: bridge.h:67
A number of safeguards to prevent using unsafe methods.
Geometry functions.
void SortBridgeList()
Sort the builable bridges.
Definition: bridge_gui.cpp:126
Offset at left of a matrix cell.
Definition: window_gui.h:78
SpriteID sprite
the sprite which is used in the GUI
Definition: bridge.h:49
Carriage for the data we need if we want to build a bridge.
Definition: bridge_gui.cpp:42
PaletteID pal
the palette which is used in the GUI
Definition: bridge.h:50
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1114
static DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
Definition: command_func.h:62
Baseclass for nested widgets.
Definition: widget_type.h:126
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:531
DiagDirection
Enumeration for diagonal directions.
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
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:362
Build bridge; Window numbers:
Definition: window_type.h:384
Grid of rows and columns.
Definition: widget_type.h:59
uint pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:177
CommandCost CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoCommandFlag flags=DC_NONE)
Is a bridge of the specified type and length available?
Functions related to sound.
void SetSortType(uint8 n_type)
Set the sorttype of the list.
bool Sort(SortFunction *compare)
Sort the list.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:658
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
static int CDECL BridgeSpeedSorter(const BuildBridgeData *a, const BuildBridgeData *b)
Sort the bridges by their maximum speed.
Definition: bridge_gui.cpp:109
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
Definition: window.cpp:1159
bool Failed() const
Did this command fail?
Definition: command_type.h:161
List of bridges.
Definition: bridge_widget.h:20
RoadTypes
The different roadtypes we support, but then a bitmask of them.
Definition: road_type.h:36
uint16 price
the price multiplier
Definition: bridge.h:47
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:139
bool IsVisible(uint16 item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:641
Build toolbar; Window numbers:
Definition: window_type.h:68
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.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:700
virtual EventState OnKeyPress(WChar key, uint16 keycode)
A key has been pressed.
Definition: bridge_gui.cpp:247
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Transport by train.
StringID material
the string that contains the bridge description
Definition: bridge.h:51
static int CDECL BridgeIndexSorter(const BuildBridgeData *a, const BuildBridgeData *b)
Sort the bridges by their index.
Definition: bridge_gui.cpp:97
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here...
static Money RailBuildCost(RailType railtype)
Returns the cost of building the specified railtype.
Definition: rail.h:346
Sort ascending.
Definition: window_gui.h:226
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:217
Scrollbar of the list.
Definition: bridge_widget.h:21
virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
Compute the initial position of the window.
Definition: bridge_gui.cpp:211
Vertical container.
Definition: widget_type.h:77
int CDECL SortFunction(const T *, const T *)
Signature of sort function.
Definition: sortlist_type.h:52
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:999
static const uint MAX_BRIDGES
Maximal number of available bridge specs.
Definition: bridge.h:36
TransportType
Available types of transport.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Transport by road vehicle.
bool confirm
Play sound effect on succesful constructions or other actions.
static uint CountBits(T value)
Counts the number of set bits in a variable.
Functions related to commands.
Coordinates of a point in 2D.
Types related to the bridge widgets.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:769
uint BridgeType
Bridge spec number.
Definition: bridge.h:38
Data structure describing how to show the list (what sort direction and criteria).
Definition: sortlist_type.h:34
Drop down list.
Definition: widget_type.h:70
build a bridge
Definition: command_type.h:183
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:19
Functions that have tunnels and bridges in common.
static RoadTypes GetRoadTypes(TileIndex t)
Get the present road types of a tile.
Definition: road_map.h:166
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:23
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:983
bool IsDescSortOrder() const
Check if the sort order is descending.
const T * Get(uint index) const
Get the pointer to item "number" (const)
#define CMD_MSG(x)
Used to combine a StringID with the command.
Definition: command_type.h:369
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:1973
Specification of a rectangle with absolute coordinates of all edges.
Vertical scrollbar.
Definition: widget_type.h:84
The passed event is handled.
Definition: window_type.h:714
Window functions not directly related to making/drawing windows.
Find a place automatically.
Definition: window_gui.h:156
uint32 WChar
Type for wide characters, i.e.
Definition: string_type.h:35
int bridgetext_offset
Horizontal offset of the text describing the bridge properties in WID_BBS_BRIDGE_LIST relative to the...
Definition: bridge_gui.cpp:93
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1095
Dimensions (a width and height) of a rectangle in 2D.
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:834
static int CDECL BridgePriceSorter(const BuildBridgeData *a, const BuildBridgeData *b)
Sort the bridges by their price.
Definition: bridge_gui.cpp:103
Criteria of sort dropdown.
Definition: bridge_widget.h:19
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:621
(Toggle) Button with text
Definition: widget_type.h:55
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:631
uint8 SortType() const
Get the sorttype of the list.
Definition: sortlist_type.h:97
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:201