OpenTTD
object_gui.cpp
Go to the documentation of this file.
1 /* $Id: object_gui.cpp 27438 2015-11-07 15:07:18Z frosch $ */
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 "command_func.h"
14 #include "newgrf.h"
15 #include "newgrf_object.h"
16 #include "newgrf_text.h"
17 #include "strings_func.h"
18 #include "viewport_func.h"
19 #include "tilehighlight_func.h"
20 #include "window_gui.h"
21 #include "window_func.h"
22 #include "zoom_func.h"
23 
24 #include "widgets/object_widget.h"
25 
26 #include "table/strings.h"
27 
28 #include "safeguards.h"
29 
32 static uint8 _selected_object_view;
33 
35 class BuildObjectWindow : public Window {
36  static const int OBJECT_MARGIN = 4;
40 
43  {
44  uint pos = 0;
45  for (int i = 0; i < _selected_object_class; i++) {
46  if (ObjectClass::Get((ObjectClassID) i)->GetUISpecCount() == 0) continue;
47  pos++;
48  }
49  this->vscroll->ScrollTowards(pos);
50  }
51 
57  {
58  if (_selected_object_index == -1) return false;
59 
61  if ((int)sel_objclass->GetSpecCount() <= _selected_object_index) return false;
62 
63  return sel_objclass->GetSpec(_selected_object_index)->IsAvailable();
64  }
65 
71  {
72  const NWidgetBase *matrix = this->GetWidget<NWidgetBase>(WID_BO_SELECT_MATRIX);
73  return 1 + (matrix->current_x - matrix->smallest_x) / matrix->resize_x;
74  }
75 
76 public:
77  BuildObjectWindow(WindowDesc *desc, WindowNumber number) : Window(desc), info_height(1)
78  {
79  this->CreateNestedTree();
80  this->vscroll = this->GetScrollbar(WID_BO_SCROLLBAR);
81  this->FinishInitNested(number);
82 
84 
85  this->vscroll->SetPosition(0);
86  this->vscroll->SetCount(ObjectClass::GetUIClassCount());
87 
88  NWidgetMatrix *matrix = this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX);
90 
92  if (this->CanRestoreSelectedObject()) {
94  } else {
95  this->SelectFirstAvailableObject(true);
96  }
97  assert(ObjectClass::Get(_selected_object_class)->GetUISpecCount() > 0); // object GUI should be disables elsewise
99  this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->SetCount(4);
100  }
101 
102  virtual void SetStringParameters(int widget) const
103  {
104  switch (widget) {
105  case WID_BO_OBJECT_NAME: {
107  SetDParam(0, spec != NULL ? spec->name : STR_EMPTY);
108  break;
109  }
110 
111  case WID_BO_OBJECT_SIZE: {
113  int size = spec == NULL ? 0 : spec->size;
114  SetDParam(0, GB(size, HasBit(_selected_object_view, 0) ? 4 : 0, 4));
115  SetDParam(1, GB(size, HasBit(_selected_object_view, 0) ? 0 : 4, 4));
116  break;
117  }
118 
119  default: break;
120  }
121  }
122 
123  virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
124  {
125  switch (widget) {
126  case WID_BO_CLASS_LIST: {
127  for (uint i = 0; i < ObjectClass::GetClassCount(); i++) {
129  if (objclass->GetUISpecCount() == 0) continue;
130  size->width = max(size->width, GetStringBoundingBox(objclass->name).width);
131  }
132  size->width += padding.width;
133  this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
134  resize->height = this->line_height;
135  size->height = 5 * this->line_height;
136  break;
137  }
138 
139  case WID_BO_OBJECT_NAME:
140  case WID_BO_OBJECT_SIZE:
141  /* We do not want the window to resize when selecting objects; better clip texts */
142  size->width = 0;
143  break;
144 
145  case WID_BO_OBJECT_MATRIX: {
146  /* Get the right amount of buttons based on the current spec. */
148  if (spec != NULL) {
149  if (spec->views >= 2) size->width += resize->width;
150  if (spec->views >= 4) size->height += resize->height;
151  }
152  resize->width = 0;
153  resize->height = 0;
154  break;
155  }
156 
157  case WID_BO_OBJECT_SPRITE: {
158  bool two_wide = false; // Whether there will be two widgets next to each other in the matrix or not.
159  int height[2] = {0, 0}; // The height for the different views; in this case views 1/2 and 4.
160 
161  /* Get the height and view information. */
162  for (int i = 0; i < NUM_OBJECTS; i++) {
163  const ObjectSpec *spec = ObjectSpec::Get(i);
164  if (!spec->IsEverAvailable()) continue;
165  two_wide |= spec->views >= 2;
166  height[spec->views / 4] = max<int>(ObjectSpec::Get(i)->height, height[spec->views / 4]);
167  }
168 
169  /* Determine the pixel heights. */
170  for (size_t i = 0; i < lengthof(height); i++) {
171  height[i] *= ScaleGUITrad(TILE_HEIGHT);
172  height[i] += ScaleGUITrad(TILE_PIXELS) + 2 * OBJECT_MARGIN;
173  }
174 
175  /* Now determine the size of the minimum widgets. When there are two columns, then
176  * we want these columns to be slightly less wide. When there are two rows, then
177  * determine the size of the widgets based on the maximum size for a single row
178  * of widgets, or just the twice the widget height of the two row ones. */
179  size->height = max(height[0], height[1] * 2 + 2);
180  if (two_wide) {
181  size->width = (3 * ScaleGUITrad(TILE_PIXELS) + 2 * OBJECT_MARGIN) * 2 + 2;
182  } else {
183  size->width = 4 * ScaleGUITrad(TILE_PIXELS) + 2 * OBJECT_MARGIN;
184  }
185 
186  /* Get the right size for the single widget based on the current spec. */
188  if (spec != NULL) {
189  if (spec->views >= 2) size->width = size->width / 2 - 1;
190  if (spec->views >= 4) size->height = size->height / 2 - 1;
191  }
192  break;
193  }
194 
195  case WID_BO_INFO:
196  size->height = this->info_height;
197  break;
198 
200  fill->height = 1;
201  resize->height = 1;
202  break;
203 
204  case WID_BO_SELECT_IMAGE:
205  size->width = ScaleGUITrad(64) + 2;
206  size->height = ScaleGUITrad(58) + 2;
207  break;
208 
209  default: break;
210  }
211  }
212 
213  virtual void DrawWidget(const Rect &r, int widget) const
214  {
215  switch (GB(widget, 0, 16)) {
216  case WID_BO_CLASS_LIST: {
217  int y = r.top;
218  uint pos = 0;
219  for (uint i = 0; i < ObjectClass::GetClassCount(); i++) {
221  if (objclass->GetUISpecCount() == 0) continue;
222  if (!this->vscroll->IsVisible(pos++)) continue;
223  DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, objclass->name,
224  ((int)i == _selected_object_class) ? TC_WHITE : TC_BLACK);
225  y += this->line_height;
226  }
227  break;
228  }
229 
230  case WID_BO_OBJECT_SPRITE: {
232  if (spec == NULL) break;
233 
234  /* Height of the selection matrix.
235  * Depending on the number of views, the matrix has a 1x1, 1x2, 2x1 or 2x2 layout. To make the previews
236  * look nice in all layouts, we use the 4x4 layout (smallest previews) as starting point. For the bigger
237  * previews in the layouts with less views we add space homogeneously on all sides, so the 4x4 preview-rectangle
238  * is centered in the 2x1, 1x2 resp. 1x1 buttons. */
239  uint matrix_height = this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->current_y;
240 
241  DrawPixelInfo tmp_dpi;
242  /* Set up a clipping area for the preview. */
243  if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left + 1, r.bottom - r.top + 1)) {
244  DrawPixelInfo *old_dpi = _cur_dpi;
245  _cur_dpi = &tmp_dpi;
246  if (spec->grf_prop.grffile == NULL) {
247  extern const DrawTileSprites _objects[];
248  const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
249  DrawOrigTileSeqInGUI((r.right - r.left) / 2 - 1, (r.bottom - r.top + matrix_height / 2) / 2 - OBJECT_MARGIN - ScaleGUITrad(TILE_PIXELS), dts, PAL_NONE);
250  } else {
251  DrawNewObjectTileInGUI((r.right - r.left) / 2 - 1, (r.bottom - r.top + matrix_height / 2) / 2 - OBJECT_MARGIN - ScaleGUITrad(TILE_PIXELS), spec, GB(widget, 16, 16));
252  }
253  _cur_dpi = old_dpi;
254  }
255  break;
256  }
257 
258  case WID_BO_SELECT_IMAGE: {
260  int obj_index = objclass->GetIndexFromUI(GB(widget, 16, 16));
261  if (obj_index < 0) break;
262  const ObjectSpec *spec = objclass->GetSpec(obj_index);
263  if (spec == NULL) break;
264 
265  if (!spec->IsAvailable()) {
266  GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK, FILLRECT_CHECKER);
267  }
268  DrawPixelInfo tmp_dpi;
269  /* Set up a clipping area for the preview. */
270  if (FillDrawPixelInfo(&tmp_dpi, r.left + 1, r.top, (r.right - 1) - (r.left + 1) + 1, r.bottom - r.top + 1)) {
271  DrawPixelInfo *old_dpi = _cur_dpi;
272  _cur_dpi = &tmp_dpi;
273  if (spec->grf_prop.grffile == NULL) {
274  extern const DrawTileSprites _objects[];
275  const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
276  DrawOrigTileSeqInGUI((r.right - r.left) / 2 - 1, r.bottom - r.top - OBJECT_MARGIN - ScaleGUITrad(TILE_PIXELS), dts, PAL_NONE);
277  } else {
278  DrawNewObjectTileInGUI((r.right - r.left) / 2 - 1, r.bottom - r.top - OBJECT_MARGIN - ScaleGUITrad(TILE_PIXELS), spec,
279  min(_selected_object_view, spec->views - 1));
280  }
281  _cur_dpi = old_dpi;
282  }
283  break;
284  }
285 
286  case WID_BO_INFO: {
288  if (spec == NULL) break;
289 
290  /* Get the extra message for the GUI */
292  uint16 callback_res = GetObjectCallback(CBID_OBJECT_FUND_MORE_TEXT, 0, 0, spec, NULL, INVALID_TILE, _selected_object_view);
293  if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
294  if (callback_res > 0x400) {
296  } else {
297  StringID message = GetGRFStringID(spec->grf_prop.grffile->grfid, 0xD000 + callback_res);
298  if (message != STR_NULL && message != STR_UNDEFINED) {
300  /* Use all the available space left from where we stand up to the
301  * end of the window. We ALSO enlarge the window if needed, so we
302  * can 'go' wild with the bottom of the window. */
303  int y = DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, message, TC_ORANGE) - r.top;
305  if (y > this->info_height) {
306  BuildObjectWindow *bow = const_cast<BuildObjectWindow *>(this);
307  bow->info_height = y + 2;
308  bow->ReInit();
309  }
310  }
311  }
312  }
313  }
314  }
315  }
316  }
317 
322  void SelectOtherClass(ObjectClassID object_class_index)
323  {
324  _selected_object_class = object_class_index;
325  this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX)->SetCount(ObjectClass::Get(_selected_object_class)->GetUISpecCount());
326  }
327 
332  void SelectOtherObject(int object_index)
333  {
334  _selected_object_index = object_index;
335  if (_selected_object_index != -1) {
338  this->ReInit();
339  } else {
341  }
342 
343  if (_selected_object_index != -1) {
344  SetObjectToPlaceWnd(SPR_CURSOR_TRANSMITTER, PAL_NONE, HT_RECT, this);
345  }
346 
348  }
349 
350  void UpdateSelectSize()
351  {
352  if (_selected_object_index == -1) {
353  SetTileSelectSize(1, 1);
354  } else {
356  int w = GB(spec->size, HasBit(_selected_object_view, 0) ? 4 : 0, 4);
357  int h = GB(spec->size, HasBit(_selected_object_view, 0) ? 0 : 4, 4);
358  SetTileSelectSize(w, h);
359  }
360  }
361 
368  void UpdateButtons(ObjectClassID sel_class, int sel_index, uint sel_view)
369  {
370  int view_number, object_number;
371  if (sel_index == -1) {
372  view_number = -1; // If no object selected, also hide the selected view.
373  object_number = -1;
374  } else {
375  view_number = sel_view;
376  object_number = ObjectClass::Get(sel_class)->GetUIFromIndex(sel_index);
377  }
378 
379  this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->SetClicked(view_number);
380  this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX)->SetClicked(object_number);
381  this->UpdateSelectSize();
382  this->SetDirty();
383  }
384 
385  virtual void OnResize()
386  {
387  this->vscroll->SetCapacityFromWidget(this, WID_BO_CLASS_LIST);
388  }
389 
390  virtual void OnClick(Point pt, int widget, int click_count)
391  {
392  switch (GB(widget, 0, 16)) {
393  case WID_BO_CLASS_LIST: {
394  int num_clicked = this->vscroll->GetPosition() + (pt.y - this->nested_array[widget]->pos_y) / this->line_height;
395  if (num_clicked >= (int)ObjectClass::GetUIClassCount()) break;
396 
397  this->SelectOtherClass(ObjectClass::GetUIClass(num_clicked));
398  this->SelectFirstAvailableObject(false);
399  break;
400  }
401 
402  case WID_BO_SELECT_IMAGE: {
404  int num_clicked = objclass->GetIndexFromUI(GB(widget, 16, 16));
405  if (num_clicked >= 0 && objclass->GetSpec(num_clicked)->IsAvailable()) this->SelectOtherObject(num_clicked);
406  break;
407  }
408 
410  if (_selected_object_index != -1) {
411  _selected_object_view = GB(widget, 16, 16);
412  this->SelectOtherObject(_selected_object_index); // Re-select the object for a different view.
413  }
414  break;
415  }
416  }
417 
418  virtual void OnPlaceObject(Point pt, TileIndex tile)
419  {
421  _selected_object_view, CMD_BUILD_OBJECT | CMD_MSG(STR_ERROR_CAN_T_BUILD_OBJECT), CcTerraform);
422  }
423 
424  virtual void OnPlaceObjectAbort()
425  {
427  }
428 
434  void SelectFirstAvailableObject(bool change_class)
435  {
436  /* First try to select an object in the selected class. */
438  for (uint i = 0; i < sel_objclass->GetSpecCount(); i++) {
439  const ObjectSpec *spec = sel_objclass->GetSpec(i);
440  if (spec->IsAvailable()) {
441  this->SelectOtherObject(i);
442  return;
443  }
444  }
445  if (change_class) {
446  /* If that fails, select the first available object
447  * from a random class. */
449  ObjectClass *objclass = ObjectClass::Get(j);
450  for (uint i = 0; i < objclass->GetSpecCount(); i++) {
451  const ObjectSpec *spec = objclass->GetSpec(i);
452  if (spec->IsAvailable()) {
453  this->SelectOtherClass(j);
454  this->SelectOtherObject(i);
455  return;
456  }
457  }
458  }
459  }
460  /* If all objects are unavailable, select nothing... */
461  if (ObjectClass::Get(_selected_object_class)->GetUISpecCount() == 0) {
462  /* ... but make sure that the class is not empty. */
464  if (ObjectClass::Get(j)->GetUISpecCount() > 0) {
465  this->SelectOtherClass(j);
466  break;
467  }
468  }
469  }
470  this->SelectOtherObject(-1);
471  }
472 };
473 
474 static const NWidgetPart _nested_build_object_widgets[] = {
476  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
477  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_OBJECT_BUILD_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
478  NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
479  EndContainer(),
480  NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
481  NWidget(NWID_HORIZONTAL), SetPadding(2, 0, 0, 0),
483  NWidget(NWID_HORIZONTAL), SetPadding(0, 5, 2, 5),
484  NWidget(WWT_MATRIX, COLOUR_GREY, WID_BO_CLASS_LIST), SetFill(1, 0), SetMatrixDataTip(1, 0, STR_OBJECT_BUILD_CLASS_TOOLTIP), SetScrollbar(WID_BO_SCROLLBAR),
486  EndContainer(),
487  NWidget(NWID_HORIZONTAL), SetPadding(0, 5, 0, 5),
488  NWidget(NWID_MATRIX, COLOUR_DARK_GREEN, WID_BO_OBJECT_MATRIX), SetPIP(0, 2, 0),
489  NWidget(WWT_PANEL, COLOUR_GREY, WID_BO_OBJECT_SPRITE), SetDataTip(0x0, STR_OBJECT_BUILD_PREVIEW_TOOLTIP), EndContainer(),
490  EndContainer(),
491  EndContainer(),
492  NWidget(WWT_TEXT, COLOUR_DARK_GREEN, WID_BO_OBJECT_NAME), SetDataTip(STR_ORANGE_STRING, STR_NULL), SetPadding(2, 5, 2, 5),
493  NWidget(WWT_TEXT, COLOUR_DARK_GREEN, WID_BO_OBJECT_SIZE), SetDataTip(STR_OBJECT_BUILD_SIZE, STR_NULL), SetPadding(2, 5, 2, 5),
494  EndContainer(),
495  NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetScrollbar(WID_BO_SELECT_SCROLL),
497  NWidget(NWID_MATRIX, COLOUR_DARK_GREEN, WID_BO_SELECT_MATRIX), SetFill(0, 1), SetPIP(0, 2, 0),
498  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BO_SELECT_IMAGE), SetMinimalSize(66, 60), SetDataTip(0x0, STR_OBJECT_BUILD_TOOLTIP),
500  EndContainer(),
501  EndContainer(),
502  NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_BO_SELECT_SCROLL),
503  EndContainer(),
504  EndContainer(),
505  EndContainer(),
507  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BO_INFO), SetPadding(2, 5, 0, 5), SetFill(1, 0), SetResize(1, 0),
509  NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(0, 1), EndContainer(),
510  NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
511  EndContainer(),
512  EndContainer(),
513  EndContainer(),
514 };
515 
516 static WindowDesc _build_object_desc(
517  WDP_AUTO, "build_object", 0, 0,
520  _nested_build_object_widgets, lengthof(_nested_build_object_widgets)
521 );
522 
528 {
529  /* Don't show the place object button when there are no objects to place. */
530  if (ObjectClass::GetUIClassCount() > 0) {
531  AllocateWindowDescFront<BuildObjectWindow>(&_build_object_desc, 0);
532  }
533 }
534 
537 {
539 }
Matrix container with implicitly equal sized (virtual) sub-widgets.
Definition: widget_type.h:493
void EnsureSelectedObjectClassIsVisible()
Scroll WID_BO_CLASS_LIST so that the selected object class is visible.
Definition: object_gui.cpp:42
Functions related to OTTD&#39;s strings.
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:48
static const uint TILE_PIXELS
Pixel distance between tile columns/rows in #ZOOM_LVL_BASE.
Definition: tile_type.h:17
virtual void OnPlaceObject(Point pt, TileIndex tile)
The user clicked some place on the map when a tile highlight mode has been set.
Definition: object_gui.cpp:418
Maximum number of classes.
Definition: newgrf_object.h:50
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Data about how and where to blit pixels.
Definition: gfx_type.h:156
Matrix container.
Definition: widget_type.h:78
ResizeInfo resize
Resize information.
Definition: window_gui.h:317
static const ObjectType NUM_OBJECTS
Number of supported objects overall.
Definition: object_type.h:27
static void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
Draw TTD sprite sequence in GUI.
Definition: sprite.h:117
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: object_gui.cpp:213
void ScrollTowards(int position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
Definition: widget_type.h:731
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:930
The scrollbar associated with the list.
Definition: object_widget.h:18
bool IsAvailable() const
Check whether the object is available at this time.
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen...
Definition: gfx.cpp:112
Offset at right of a matrix cell.
Definition: window_gui.h:79
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Definition: object_gui.cpp:390
uint resize_x
Horizontal resize step (0 means not resizable).
Definition: widget_type.h:166
High level window description.
Definition: window_gui.h:168
bool CanRestoreSelectedObject()
Tests whether the previously selected object can be selected.
Definition: object_gui.cpp:56
Called to determine more text in the fund object window.
Types related to the object widgets.
uint GetSpecCount() const
Get the number of allocated specs within the class.
Definition: newgrf_class.h:46
Scrollbar data structure.
Definition: widget_type.h:589
void UpdateButtons(ObjectClassID sel_class, int sel_index, uint sel_view)
Update buttons to show the selection to the user.
Definition: object_gui.cpp:368
Horizontal container.
Definition: widget_type.h:75
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
Definition: viewport.cpp:2295
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:82
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
Definition: newgrf_object.h:62
bool IsEverAvailable() const
Check whether the object might be available at some point in this game with the current game mode...
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
additional text in fund window
void SetPosition(int position)
Sets the position of the first visible element.
Definition: widget_type.h:701
Close box (at top-left of a window)
Definition: widget_type.h:69
Offset at top of a matrix cell.
Definition: window_gui.h:80
Allow incrementing of ObjectClassID variables.
Definition: newgrf_object.h:60
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:970
StringID GetGRFStringID(uint32 grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
uint smallest_x
Smallest horizontal size of the widget in a filled window.
Definition: widget_type.h:171
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:26
void InitializeObjectGui()
Reset all data of the object GUI.
Definition: object_gui.cpp:536
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1804
Pure simple text.
Definition: widget_type.h:58
virtual void OnPlaceObjectAbort()
The user cancelled a tile highlight mode that has been set.
Definition: object_gui.cpp:424
static const ObjectSpec * Get(ObjectType index)
Get the specification associated with a specific ObjectType.
Functions, definitions and such used only by the GUI.
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
Definition: gfx.cpp:1480
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:670
uint GetUISpecCount() const
Get the number of potentially user-available specs within the class.
Definition: newgrf_class.h:48
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:910
Functions related to (drawing on) viewports.
uint8 size
The size of this objects; low nibble for X, high nibble for Y.
Definition: newgrf_object.h:67
Functions related to NewGRF objects.
Data structure for an opened window.
Definition: window_gui.h:271
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1820
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
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1046
static ObjectClassID _selected_object_class
the currently visible object class
Definition: object_gui.cpp:30
Header of Action 04 "universal holder" structure and functions.
uint8 height
The height of this structure, in heightlevels; max MAX_TILE_HEIGHT.
Definition: newgrf_object.h:75
static const int OBJECT_MARGIN
The margin (in pixels) around an object.
Definition: object_gui.cpp:36
Struct containing information relating to NewGRF classes for stations and airports.
Definition: newgrf_class.h:21
NWidgetBase ** nested_array
Array of pointers into the tree. Do not access directly, use Window::GetWidget() instead.
Definition: window_gui.h:325
int line_height
The height of a single line.
Definition: object_gui.cpp:37
int info_height
The height of the info box.
Definition: object_gui.cpp:38
Offset at bottom of a matrix cell.
Definition: window_gui.h:81
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:65
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
Ground palette sprite of a tile, together with its sprite layout.
Definition: sprite.h:60
void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8 view)
Draw representation of an object (tile) for GUI purposes.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:180
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
Scrollbar next to the WID_BO_SELECT_MATRIX.
Definition: object_widget.h:27
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:947
Definition of base types and functions in a cross-platform compatible way.
void SelectOtherClass(ObjectClassID object_class_index)
Select the specified object class.
Definition: object_gui.cpp:322
A number of safeguards to prevent using unsafe methods.
uint16 callback_mask
Bitmask of requested/allowed callbacks.
Definition: newgrf_object.h:74
The window used for building objects.
Definition: object_gui.cpp:35
uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view)
Perform a callback for an object.
rectangle (stations, depots, ...)
Simple depressed panel.
Definition: widget_type.h:50
uint8 views
The number of views.
Definition: newgrf_object.h:76
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
Definition: tile_type.h:18
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:307
Offset at left of a matrix cell.
Definition: window_gui.h:78
static uint8 _selected_object_view
the view of the selected object
Definition: object_gui.cpp:32
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
Baseclass for nested widgets.
Definition: widget_type.h:126
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:499
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:527
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
Definition: object_gui.cpp:102
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
Selection preview matrix of objects of a given class.
Definition: object_widget.h:25
Grid of rows and columns.
Definition: widget_type.h:59
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32 *values)
Start using the TTDP compatible string code parsing.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
The lowest valid value.
Definition: newgrf_object.h:49
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:207
Build object; Window numbers:
Definition: window_type.h:371
StringID name
The name for this object.
Definition: newgrf_object.h:64
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:959
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
The size of the selected object.
Definition: object_widget.h:22
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:699
void SelectFirstAvailableObject(bool change_class)
Select the first available object.
Definition: object_gui.cpp:434
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:284
Preview image in the WID_BO_SELECT_MATRIX.
Definition: object_widget.h:26
void SetObjectToPlaceWnd(CursorID icon, PaletteID pal, HighLightStyle mode, Window *w)
Change the cursor and mouse click/drag handling to a mode for performing special operations like tile...
Definition: viewport.cpp:3151
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
void SetScrollbar(Scrollbar *sb)
Assign a scrollbar to this matrix.
Definition: widget.cpp:1528
Other information about the object (from the NewGRF).
Definition: object_widget.h:23
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
Scrollbar * vscroll
The scrollbar.
Definition: object_gui.cpp:39
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
virtual void OnResize()
Called after the window got resized.
Definition: object_gui.cpp:385
Vertical container.
Definition: widget_type.h:77
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 uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Functions related to zooming.
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:174
The list with classes.
Definition: object_widget.h:17
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
Functions related to commands.
Coordinates of a point in 2D.
uint16 local_id
id defined by the grf file for this entity
void SelectOtherObject(int object_index)
Select the specified object in _selected_object_class class.
Definition: object_gui.cpp:332
The name of the selected object.
Definition: object_widget.h:21
const struct GRFFile * grffile
grf file that introduced this entity
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: object_gui.cpp:123
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:983
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:85
#define CMD_MSG(x)
Used to combine a StringID with the command.
Definition: command_type.h:366
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:695
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
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows)...
Definition: viewport.cpp:3211
Specification of a rectangle with absolute coordinates of all edges.
Vertical scrollbar.
Definition: widget_type.h:84
The matrix with preview sprites.
Definition: object_widget.h:19
Functions related to tile highlights.
Window functions not directly related to making/drawing windows.
Find a place automatically.
Definition: window_gui.h:156
uint GetMatrixColumnCount()
Calculate the number of columns of the WID_BO_SELECT_MATRIX widget.
Definition: object_gui.cpp:70
A preview sprite of the object.
Definition: object_widget.h:20
void ShowBuildObjectPicker()
Show our object picker.
Definition: object_gui.cpp:527
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.
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1076
static int _selected_object_index
the index of the selected object in the current class or -1
Definition: object_gui.cpp:31
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:315
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:620
build an object
Definition: command_type.h:189
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:631
ObjectClassID
Class IDs for objects.
Definition: newgrf_object.h:48
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
StringID name
Name of this class.
Definition: newgrf_class.h:41
Base for the NewGRF implementation.