OpenTTD
object_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 "command_func.h"
12 #include "newgrf.h"
13 #include "newgrf_object.h"
14 #include "newgrf_text.h"
15 #include "strings_func.h"
16 #include "viewport_func.h"
17 #include "tilehighlight_func.h"
18 #include "window_gui.h"
19 #include "window_func.h"
20 #include "zoom_func.h"
21 
22 #include "widgets/object_widget.h"
23 
24 #include "table/strings.h"
25 
26 #include "safeguards.h"
27 
30 static uint8 _selected_object_view;
31 
33 class BuildObjectWindow : public Window {
34  static const int OBJECT_MARGIN = 4;
38 
41  {
42  uint pos = 0;
43  for (int i = 0; i < _selected_object_class; i++) {
44  if (ObjectClass::Get((ObjectClassID) i)->GetUISpecCount() == 0) continue;
45  pos++;
46  }
47  this->vscroll->ScrollTowards(pos);
48  }
49 
55  {
56  if (_selected_object_index == -1) return false;
57 
59  if ((int)sel_objclass->GetSpecCount() <= _selected_object_index) return false;
60 
61  return sel_objclass->GetSpec(_selected_object_index)->IsAvailable();
62  }
63 
69  {
70  const NWidgetBase *matrix = this->GetWidget<NWidgetBase>(WID_BO_SELECT_MATRIX);
71  return 1 + (matrix->current_x - matrix->smallest_x) / matrix->resize_x;
72  }
73 
74 public:
75  BuildObjectWindow(WindowDesc *desc, WindowNumber number) : Window(desc), info_height(1)
76  {
77  this->CreateNestedTree();
78  this->vscroll = this->GetScrollbar(WID_BO_SCROLLBAR);
79  this->FinishInitNested(number);
80 
82 
83  this->vscroll->SetPosition(0);
84  this->vscroll->SetCount(ObjectClass::GetUIClassCount());
85 
86  NWidgetMatrix *matrix = this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX);
88 
90  if (this->CanRestoreSelectedObject()) {
92  } else {
93  this->SelectFirstAvailableObject(true);
94  }
95  assert(ObjectClass::Get(_selected_object_class)->GetUISpecCount() > 0); // object GUI should be disables elsewise
97  this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->SetCount(4);
98  }
99 
100  void SetStringParameters(int widget) const override
101  {
102  switch (widget) {
103  case WID_BO_OBJECT_NAME: {
105  SetDParam(0, spec != nullptr ? spec->name : STR_EMPTY);
106  break;
107  }
108 
109  case WID_BO_OBJECT_SIZE: {
111  int size = spec == nullptr ? 0 : spec->size;
112  SetDParam(0, GB(size, HasBit(_selected_object_view, 0) ? 4 : 0, 4));
113  SetDParam(1, GB(size, HasBit(_selected_object_view, 0) ? 0 : 4, 4));
114  break;
115  }
116 
117  default: break;
118  }
119  }
120 
121  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
122  {
123  switch (widget) {
124  case WID_BO_CLASS_LIST: {
125  for (uint i = 0; i < ObjectClass::GetClassCount(); i++) {
127  if (objclass->GetUISpecCount() == 0) continue;
128  size->width = max(size->width, GetStringBoundingBox(objclass->name).width);
129  }
130  size->width += padding.width;
131  this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
132  resize->height = this->line_height;
133  size->height = 5 * this->line_height;
134  break;
135  }
136 
137  case WID_BO_OBJECT_NAME:
138  case WID_BO_OBJECT_SIZE:
139  /* We do not want the window to resize when selecting objects; better clip texts */
140  size->width = 0;
141  break;
142 
143  case WID_BO_OBJECT_MATRIX: {
144  /* Get the right amount of buttons based on the current spec. */
146  if (spec != nullptr) {
147  if (spec->views >= 2) size->width += resize->width;
148  if (spec->views >= 4) size->height += resize->height;
149  }
150  resize->width = 0;
151  resize->height = 0;
152  break;
153  }
154 
155  case WID_BO_OBJECT_SPRITE: {
156  bool two_wide = false; // Whether there will be two widgets next to each other in the matrix or not.
157  int height[2] = {0, 0}; // The height for the different views; in this case views 1/2 and 4.
158 
159  /* Get the height and view information. */
160  for (int i = 0; i < NUM_OBJECTS; i++) {
161  const ObjectSpec *spec = ObjectSpec::Get(i);
162  if (!spec->IsEverAvailable()) continue;
163  two_wide |= spec->views >= 2;
164  height[spec->views / 4] = max<int>(ObjectSpec::Get(i)->height, height[spec->views / 4]);
165  }
166 
167  /* Determine the pixel heights. */
168  for (size_t i = 0; i < lengthof(height); i++) {
169  height[i] *= ScaleGUITrad(TILE_HEIGHT);
170  height[i] += ScaleGUITrad(TILE_PIXELS) + 2 * OBJECT_MARGIN;
171  }
172 
173  /* Now determine the size of the minimum widgets. When there are two columns, then
174  * we want these columns to be slightly less wide. When there are two rows, then
175  * determine the size of the widgets based on the maximum size for a single row
176  * of widgets, or just the twice the widget height of the two row ones. */
177  size->height = max(height[0], height[1] * 2 + 2);
178  if (two_wide) {
179  size->width = (3 * ScaleGUITrad(TILE_PIXELS) + 2 * OBJECT_MARGIN) * 2 + 2;
180  } else {
181  size->width = 4 * ScaleGUITrad(TILE_PIXELS) + 2 * OBJECT_MARGIN;
182  }
183 
184  /* Get the right size for the single widget based on the current spec. */
186  if (spec != nullptr) {
187  if (spec->views >= 2) size->width = size->width / 2 - 1;
188  if (spec->views >= 4) size->height = size->height / 2 - 1;
189  }
190  break;
191  }
192 
193  case WID_BO_INFO:
194  size->height = this->info_height;
195  break;
196 
198  fill->height = 1;
199  resize->height = 1;
200  break;
201 
202  case WID_BO_SELECT_IMAGE:
203  size->width = ScaleGUITrad(64) + 2;
204  size->height = ScaleGUITrad(58) + 2;
205  break;
206 
207  default: break;
208  }
209  }
210 
211  void DrawWidget(const Rect &r, int widget) const override
212  {
213  switch (GB(widget, 0, 16)) {
214  case WID_BO_CLASS_LIST: {
215  int y = r.top;
216  uint pos = 0;
217  for (uint i = 0; i < ObjectClass::GetClassCount(); i++) {
219  if (objclass->GetUISpecCount() == 0) continue;
220  if (!this->vscroll->IsVisible(pos++)) continue;
221  DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, objclass->name,
222  ((int)i == _selected_object_class) ? TC_WHITE : TC_BLACK);
223  y += this->line_height;
224  }
225  break;
226  }
227 
228  case WID_BO_OBJECT_SPRITE: {
230  if (spec == nullptr) break;
231 
232  /* Height of the selection matrix.
233  * Depending on the number of views, the matrix has a 1x1, 1x2, 2x1 or 2x2 layout. To make the previews
234  * look nice in all layouts, we use the 4x4 layout (smallest previews) as starting point. For the bigger
235  * previews in the layouts with less views we add space homogeneously on all sides, so the 4x4 preview-rectangle
236  * is centered in the 2x1, 1x2 resp. 1x1 buttons. */
237  uint matrix_height = this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->current_y;
238 
239  DrawPixelInfo tmp_dpi;
240  /* Set up a clipping area for the preview. */
241  if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left + 1, r.bottom - r.top + 1)) {
242  DrawPixelInfo *old_dpi = _cur_dpi;
243  _cur_dpi = &tmp_dpi;
244  if (spec->grf_prop.grffile == nullptr) {
245  extern const DrawTileSprites _objects[];
246  const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
247  DrawOrigTileSeqInGUI((r.right - r.left) / 2 - 1, (r.bottom - r.top + matrix_height / 2) / 2 - OBJECT_MARGIN - ScaleGUITrad(TILE_PIXELS), dts, PAL_NONE);
248  } else {
249  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));
250  }
251  _cur_dpi = old_dpi;
252  }
253  break;
254  }
255 
256  case WID_BO_SELECT_IMAGE: {
258  int obj_index = objclass->GetIndexFromUI(GB(widget, 16, 16));
259  if (obj_index < 0) break;
260  const ObjectSpec *spec = objclass->GetSpec(obj_index);
261  if (spec == nullptr) break;
262 
263  if (!spec->IsAvailable()) {
264  GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK, FILLRECT_CHECKER);
265  }
266  DrawPixelInfo tmp_dpi;
267  /* Set up a clipping area for the preview. */
268  if (FillDrawPixelInfo(&tmp_dpi, r.left + 1, r.top, (r.right - 1) - (r.left + 1) + 1, r.bottom - r.top + 1)) {
269  DrawPixelInfo *old_dpi = _cur_dpi;
270  _cur_dpi = &tmp_dpi;
271  if (spec->grf_prop.grffile == nullptr) {
272  extern const DrawTileSprites _objects[];
273  const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
274  DrawOrigTileSeqInGUI((r.right - r.left) / 2 - 1, r.bottom - r.top - OBJECT_MARGIN - ScaleGUITrad(TILE_PIXELS), dts, PAL_NONE);
275  } else {
276  DrawNewObjectTileInGUI((r.right - r.left) / 2 - 1, r.bottom - r.top - OBJECT_MARGIN - ScaleGUITrad(TILE_PIXELS), spec,
277  min(_selected_object_view, spec->views - 1));
278  }
279  _cur_dpi = old_dpi;
280  }
281  break;
282  }
283 
284  case WID_BO_INFO: {
286  if (spec == nullptr) break;
287 
288  /* Get the extra message for the GUI */
290  uint16 callback_res = GetObjectCallback(CBID_OBJECT_FUND_MORE_TEXT, 0, 0, spec, nullptr, INVALID_TILE, _selected_object_view);
291  if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
292  if (callback_res > 0x400) {
294  } else {
295  StringID message = GetGRFStringID(spec->grf_prop.grffile->grfid, 0xD000 + callback_res);
296  if (message != STR_NULL && message != STR_UNDEFINED) {
298  /* Use all the available space left from where we stand up to the
299  * end of the window. We ALSO enlarge the window if needed, so we
300  * can 'go' wild with the bottom of the window. */
301  int y = DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, message, TC_ORANGE) - r.top;
303  if (y > this->info_height) {
304  BuildObjectWindow *bow = const_cast<BuildObjectWindow *>(this);
305  bow->info_height = y + 2;
306  bow->ReInit();
307  }
308  }
309  }
310  }
311  }
312  }
313  }
314  }
315 
320  void SelectOtherClass(ObjectClassID object_class_index)
321  {
322  _selected_object_class = object_class_index;
323  this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX)->SetCount(ObjectClass::Get(_selected_object_class)->GetUISpecCount());
324  }
325 
330  void SelectOtherObject(int object_index)
331  {
332  _selected_object_index = object_index;
333  if (_selected_object_index != -1) {
336  this->ReInit();
337  } else {
339  }
340 
341  if (_selected_object_index != -1) {
342  SetObjectToPlaceWnd(SPR_CURSOR_TRANSMITTER, PAL_NONE, HT_RECT, this);
343  }
344 
346  }
347 
348  void UpdateSelectSize()
349  {
350  if (_selected_object_index == -1) {
351  SetTileSelectSize(1, 1);
352  } else {
354  int w = GB(spec->size, HasBit(_selected_object_view, 0) ? 4 : 0, 4);
355  int h = GB(spec->size, HasBit(_selected_object_view, 0) ? 0 : 4, 4);
356  SetTileSelectSize(w, h);
357  }
358  }
359 
366  void UpdateButtons(ObjectClassID sel_class, int sel_index, uint sel_view)
367  {
368  int view_number, object_number;
369  if (sel_index == -1) {
370  view_number = -1; // If no object selected, also hide the selected view.
371  object_number = -1;
372  } else {
373  view_number = sel_view;
374  object_number = ObjectClass::Get(sel_class)->GetUIFromIndex(sel_index);
375  }
376 
377  this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->SetClicked(view_number);
378  this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX)->SetClicked(object_number);
379  this->UpdateSelectSize();
380  this->SetDirty();
381  }
382 
383  void OnResize() override
384  {
385  this->vscroll->SetCapacityFromWidget(this, WID_BO_CLASS_LIST);
386  }
387 
388  void OnClick(Point pt, int widget, int click_count) override
389  {
390  switch (GB(widget, 0, 16)) {
391  case WID_BO_CLASS_LIST: {
392  int num_clicked = this->vscroll->GetPosition() + (pt.y - this->nested_array[widget]->pos_y) / this->line_height;
393  if (num_clicked >= (int)ObjectClass::GetUIClassCount()) break;
394 
395  this->SelectOtherClass(ObjectClass::GetUIClass(num_clicked));
396  this->SelectFirstAvailableObject(false);
397  break;
398  }
399 
400  case WID_BO_SELECT_IMAGE: {
402  int num_clicked = objclass->GetIndexFromUI(GB(widget, 16, 16));
403  if (num_clicked >= 0 && objclass->GetSpec(num_clicked)->IsAvailable()) this->SelectOtherObject(num_clicked);
404  break;
405  }
406 
408  if (_selected_object_index != -1) {
409  _selected_object_view = GB(widget, 16, 16);
410  this->SelectOtherObject(_selected_object_index); // Re-select the object for a different view.
411  }
412  break;
413  }
414  }
415 
416  void OnPlaceObject(Point pt, TileIndex tile) override
417  {
419  _selected_object_view, CMD_BUILD_OBJECT | CMD_MSG(STR_ERROR_CAN_T_BUILD_OBJECT), CcTerraform);
420  }
421 
422  void OnPlaceObjectAbort() override
423  {
425  }
426 
432  void SelectFirstAvailableObject(bool change_class)
433  {
434  /* First try to select an object in the selected class. */
436  for (uint i = 0; i < sel_objclass->GetSpecCount(); i++) {
437  const ObjectSpec *spec = sel_objclass->GetSpec(i);
438  if (spec->IsAvailable()) {
439  this->SelectOtherObject(i);
440  return;
441  }
442  }
443  if (change_class) {
444  /* If that fails, select the first available object
445  * from a random class. */
447  ObjectClass *objclass = ObjectClass::Get(j);
448  for (uint i = 0; i < objclass->GetSpecCount(); i++) {
449  const ObjectSpec *spec = objclass->GetSpec(i);
450  if (spec->IsAvailable()) {
451  this->SelectOtherClass(j);
452  this->SelectOtherObject(i);
453  return;
454  }
455  }
456  }
457  }
458  /* If all objects are unavailable, select nothing... */
459  if (ObjectClass::Get(_selected_object_class)->GetUISpecCount() == 0) {
460  /* ... but make sure that the class is not empty. */
462  if (ObjectClass::Get(j)->GetUISpecCount() > 0) {
463  this->SelectOtherClass(j);
464  break;
465  }
466  }
467  }
468  this->SelectOtherObject(-1);
469  }
470 };
471 
472 static const NWidgetPart _nested_build_object_widgets[] = {
474  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
475  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_OBJECT_BUILD_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
476  NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
477  EndContainer(),
478  NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
479  NWidget(NWID_HORIZONTAL), SetPadding(2, 0, 0, 0),
481  NWidget(NWID_HORIZONTAL), SetPadding(0, 5, 2, 5),
482  NWidget(WWT_MATRIX, COLOUR_GREY, WID_BO_CLASS_LIST), SetFill(1, 0), SetMatrixDataTip(1, 0, STR_OBJECT_BUILD_CLASS_TOOLTIP), SetScrollbar(WID_BO_SCROLLBAR),
484  EndContainer(),
485  NWidget(NWID_HORIZONTAL), SetPadding(0, 5, 0, 5),
486  NWidget(NWID_MATRIX, COLOUR_DARK_GREEN, WID_BO_OBJECT_MATRIX), SetPIP(0, 2, 0),
487  NWidget(WWT_PANEL, COLOUR_GREY, WID_BO_OBJECT_SPRITE), SetDataTip(0x0, STR_OBJECT_BUILD_PREVIEW_TOOLTIP), EndContainer(),
488  EndContainer(),
489  EndContainer(),
490  NWidget(WWT_TEXT, COLOUR_DARK_GREEN, WID_BO_OBJECT_NAME), SetDataTip(STR_ORANGE_STRING, STR_NULL), SetPadding(2, 5, 2, 5),
491  NWidget(WWT_TEXT, COLOUR_DARK_GREEN, WID_BO_OBJECT_SIZE), SetDataTip(STR_OBJECT_BUILD_SIZE, STR_NULL), SetPadding(2, 5, 2, 5),
492  EndContainer(),
493  NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetScrollbar(WID_BO_SELECT_SCROLL),
495  NWidget(NWID_MATRIX, COLOUR_DARK_GREEN, WID_BO_SELECT_MATRIX), SetFill(0, 1), SetPIP(0, 2, 0),
496  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BO_SELECT_IMAGE), SetMinimalSize(66, 60), SetDataTip(0x0, STR_OBJECT_BUILD_TOOLTIP),
498  EndContainer(),
499  EndContainer(),
500  NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_BO_SELECT_SCROLL),
501  EndContainer(),
502  EndContainer(),
503  EndContainer(),
505  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BO_INFO), SetPadding(2, 5, 0, 5), SetFill(1, 0), SetResize(1, 0),
507  NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(0, 1), EndContainer(),
508  NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
509  EndContainer(),
510  EndContainer(),
511  EndContainer(),
512 };
513 
514 static WindowDesc _build_object_desc(
515  WDP_AUTO, "build_object", 0, 0,
518  _nested_build_object_widgets, lengthof(_nested_build_object_widgets)
519 );
520 
523 {
524  /* Don't show the place object button when there are no objects to place. */
525  if (ObjectClass::GetUIClassCount() > 0) {
526  AllocateWindowDescFront<BuildObjectWindow>(&_build_object_desc, 0);
527  }
528 }
529 
532 {
534 }
Matrix container with implicitly equal sized (virtual) sub-widgets.
Definition: widget_type.h:491
void EnsureSelectedObjectClassIsVisible()
Scroll WID_BO_CLASS_LIST so that the selected object class is visible.
Definition: object_gui.cpp:40
Functions related to OTTD&#39;s strings.
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
static const uint TILE_PIXELS
Pixel distance between tile columns/rows in #ZOOM_LVL_BASE.
Definition: tile_type.h:15
Maximum number of classes.
Definition: newgrf_object.h:48
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Data about how and where to blit pixels.
Definition: gfx_type.h:154
Matrix container.
Definition: widget_type.h:76
ResizeInfo resize
Resize information.
Definition: window_gui.h:322
static const ObjectType NUM_OBJECTS
Number of supported objects overall.
Definition: object_type.h:25
static void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
Draw TTD sprite sequence in GUI.
Definition: sprite.h:115
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:729
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:928
The scrollbar associated with the list.
Definition: object_widget.h:16
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:110
Offset at right of a matrix cell.
Definition: window_gui.h:77
uint resize_x
Horizontal resize step (0 means not resizable).
Definition: widget_type.h:164
High level window description.
Definition: window_gui.h:166
bool CanRestoreSelectedObject()
Tests whether the previously selected object can be selected.
Definition: object_gui.cpp:54
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:44
Scrollbar data structure.
Definition: widget_type.h:587
void UpdateButtons(ObjectClassID sel_class, int sel_index, uint sel_view)
Update buttons to show the selection to the user.
Definition: object_gui.cpp:366
Horizontal container.
Definition: widget_type.h:73
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
Definition: viewport.cpp:2423
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:76
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
Definition: newgrf_object.h:60
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:66
additional text in fund window
void SetPosition(int position)
Sets the position of the first visible element.
Definition: widget_type.h:699
Close box (at top-left of a window)
Definition: widget_type.h:67
Offset at top of a matrix cell.
Definition: window_gui.h:78
Allow incrementing of ObjectClassID variables.
Definition: newgrf_object.h:58
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:995
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
Definition: object_gui.cpp:416
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:169
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:24
void InitializeObjectGui()
Reset all data of the object GUI.
Definition: object_gui.cpp:531
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1828
Pure simple text.
Definition: widget_type.h:56
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:1481
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:668
uint GetUISpecCount() const
Get the number of potentially user-available specs within the class.
Definition: newgrf_class.h:46
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:908
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:65
Functions related to NewGRF objects.
Data structure for an opened window.
Definition: window_gui.h:276
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1844
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:1030
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:1044
void OnResize() override
Called after the window got resized.
Definition: object_gui.cpp:383
static ObjectClassID _selected_object_class
the currently visible object class
Definition: object_gui.cpp:28
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:73
static const int OBJECT_MARGIN
The margin (in pixels) around an object.
Definition: object_gui.cpp:34
Struct containing information relating to NewGRF classes for stations and airports.
Definition: newgrf_class.h:19
NWidgetBase ** nested_array
Array of pointers into the tree. Do not access directly, use Window::GetWidget() instead.
Definition: window_gui.h:330
int line_height
The height of a single line.
Definition: object_gui.cpp:35
int info_height
The height of the info box.
Definition: object_gui.cpp:36
Offset at bottom of a matrix cell.
Definition: window_gui.h:79
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:63
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:208
Ground palette sprite of a tile, together with its sprite layout.
Definition: sprite.h:58
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:176
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1012
Scrollbar next to the WID_BO_SELECT_MATRIX.
Definition: object_widget.h:25
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:945
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:320
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: object_gui.cpp:100
A number of safeguards to prevent using unsafe methods.
uint16 callback_mask
Bitmask of requested/allowed callbacks.
Definition: newgrf_object.h:72
The window used for building objects.
Definition: object_gui.cpp:33
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:48
uint8 views
The number of views.
Definition: newgrf_object.h:74
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
Definition: tile_type.h:16
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:309
Offset at left of a matrix cell.
Definition: window_gui.h:76
static uint8 _selected_object_view
the view of the selected object
Definition: object_gui.cpp:30
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition: object_gui.cpp:422
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:1112
Baseclass for nested widgets.
Definition: widget_type.h:124
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:498
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:532
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:40
Selection preview matrix of objects of a given class.
Definition: object_widget.h:23
Grid of rows and columns.
Definition: widget_type.h:57
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:40
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:16
The lowest valid value.
Definition: newgrf_object.h:47
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:203
Build object; Window numbers:
Definition: window_type.h:369
StringID name
The name for this object.
Definition: newgrf_object.h:62
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:984
bool IsVisible(uint16 item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:639
Build toolbar; Window numbers:
Definition: window_type.h:66
The size of the selected object.
Definition: object_widget.h:20
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:700
void SelectFirstAvailableObject(bool change_class)
Select the first available object.
Definition: object_gui.cpp:432
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:283
Preview image in the WID_BO_SELECT_MATRIX.
Definition: object_widget.h:24
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:3290
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:1526
Other information about the object (from the NewGRF).
Definition: object_widget.h:21
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
Scrollbar * vscroll
The scrollbar.
Definition: object_gui.cpp:37
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
Vertical container.
Definition: widget_type.h:75
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: object_gui.cpp:121
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:997
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:172
The list with classes.
Definition: object_widget.h:15
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
Functions related to commands.
Coordinates of a point in 2D.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: object_gui.cpp:211
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:330
The name of the selected object.
Definition: object_widget.h:19
const struct GRFFile * grffile
grf file that introduced this entity
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:981
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:83
#define CMD_MSG(x)
Used to combine a StringID with the command.
Definition: command_type.h:368
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:705
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:1971
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows)...
Definition: viewport.cpp:3353
Specification of a rectangle with absolute coordinates of all edges.
Vertical scrollbar.
Definition: widget_type.h:82
The matrix with preview sprites.
Definition: object_widget.h:17
Functions related to tile highlights.
Window functions not directly related to making/drawing windows.
Find a place automatically.
Definition: window_gui.h:154
uint GetMatrixColumnCount()
Calculate the number of columns of the WID_BO_SELECT_MATRIX widget.
Definition: object_gui.cpp:68
A preview sprite of the object.
Definition: object_widget.h:18
void ShowBuildObjectPicker()
Show our object picker.
Definition: object_gui.cpp:522
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1093
Dimensions (a width and height) of a rectangle in 2D.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: object_gui.cpp:388
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1074
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:176
static int _selected_object_index
the index of the selected object in the current class or -1
Definition: object_gui.cpp:29
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:320
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
build an object
Definition: command_type.h:187
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:629
ObjectClassID
Class IDs for objects.
Definition: newgrf_object.h:46
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:199
StringID name
Name of this class.
Definition: newgrf_class.h:39
Base for the NewGRF implementation.