Hotfix: Conditional order comparator dropdown list was broken.
[openttd-joker.git] / src / object_gui.cpp
blobec66b3d1a58477c56a9ad8c1747f2db1e06c2dfa
1 /* $Id: object_gui.cpp 26241 2014-01-12 18:00:39Z frosch $ */
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 */
10 /** @file object_gui.cpp The GUI for objects. */
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"
24 #include "widgets/object_widget.h"
26 #include "table/strings.h"
28 #include "safeguards.h"
30 static ObjectClassID _selected_object_class; ///< the currently visible object class
31 static int _selected_object_index; ///< the index of the selected object in the current class or -1
32 static uint8 _selected_object_view; ///< the view of the selected object
34 /** The window used for building objects. */
35 class BuildObjectWindow : public Window {
36 static const int OBJECT_MARGIN = 4; ///< The margin (in pixels) around an object.
37 int line_height; ///< The height of a single line.
38 int info_height; ///< The height of the info box.
39 Scrollbar *vscroll; ///< The scrollbar.
41 /** Scroll #WID_BO_CLASS_LIST so that the selected object class is visible. */
42 void EnsureSelectedObjectClassIsVisible()
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++;
49 this->vscroll->ScrollTowards(pos);
52 /**
53 * Tests whether the previously selected object can be selected.
54 * @return \c true if the selected object is available, \c false otherwise.
56 bool CanRestoreSelectedObject()
58 if (_selected_object_index == -1) return false;
60 ObjectClass *sel_objclass = ObjectClass::Get(_selected_object_class);
61 if ((int)sel_objclass->GetSpecCount() <= _selected_object_index) return false;
63 return sel_objclass->GetSpec(_selected_object_index)->IsAvailable();
66 /**
67 * Calculate the number of columns of the #WID_BO_SELECT_MATRIX widget.
68 * @return Number of columns in the matrix.
70 uint GetMatrixColumnCount()
72 const NWidgetBase *matrix = this->GetWidget<NWidgetBase>(WID_BO_SELECT_MATRIX);
73 return 1 + (matrix->current_x - matrix->smallest_x) / matrix->resize_x;
76 public:
77 BuildObjectWindow(WindowDesc *desc, WindowNumber number) : Window(desc), info_height(1)
79 this->CreateNestedTree();
80 this->vscroll = this->GetScrollbar(WID_BO_SCROLLBAR);
81 this->FinishInitNested(number);
83 ResetObjectToPlace();
85 this->vscroll->SetPosition(0);
86 this->vscroll->SetCount(ObjectClass::GetUIClassCount());
88 NWidgetMatrix *matrix = this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX);
89 matrix->SetScrollbar(this->GetScrollbar(WID_BO_SELECT_SCROLL));
91 this->SelectOtherClass(_selected_object_class);
92 if (this->CanRestoreSelectedObject()) {
93 this->SelectOtherObject(_selected_object_index);
94 } else {
95 this->SelectFirstAvailableObject(true);
97 assert(ObjectClass::Get(_selected_object_class)->GetUISpecCount() > 0); // object GUI should be disables elsewise
98 this->EnsureSelectedObjectClassIsVisible();
99 this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->SetCount(4);
102 virtual void SetStringParameters(int widget) const
104 switch (widget) {
105 case WID_BO_OBJECT_NAME: {
106 const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
107 SetDParam(0, spec != NULL ? spec->name : STR_EMPTY);
108 break;
111 case WID_BO_OBJECT_SIZE: {
112 const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
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;
119 default: break;
123 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
125 switch (widget) {
126 case WID_BO_CLASS_LIST: {
127 for (uint i = 0; i < ObjectClass::GetClassCount(); i++) {
128 ObjectClass *objclass = ObjectClass::Get((ObjectClassID)i);
129 if (objclass->GetUISpecCount() == 0) continue;
130 size->width = max(size->width, GetStringBoundingBox(objclass->name).width);
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;
137 size->width = min(size->width, ScaleGUITrad(400));
138 break;
141 case WID_BO_OBJECT_NAME:
142 case WID_BO_OBJECT_SIZE:
143 /* We do not want the window to resize when selecting objects; better clip texts */
144 size->width = 0;
145 break;
147 case WID_BO_OBJECT_MATRIX: {
148 /* Get the right amount of buttons based on the current spec. */
149 const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
150 if (spec != NULL) {
151 if (spec->views >= 2) size->width += resize->width;
152 if (spec->views >= 4) size->height += resize->height;
154 resize->width = 0;
155 resize->height = 0;
156 break;
159 case WID_BO_OBJECT_SPRITE: {
160 bool two_wide = false; // Whether there will be two widgets next to each other in the matrix or not.
161 int height[2] = {0, 0}; // The height for the different views; in this case views 1/2 and 4.
163 /* Get the height and view information. */
164 for (int i = 0; i < NUM_OBJECTS; i++) {
165 const ObjectSpec *spec = ObjectSpec::Get(i);
166 if (!spec->IsEverAvailable()) continue;
167 two_wide |= spec->views >= 2;
168 height[spec->views / 4] = max<int>(ObjectSpec::Get(i)->height, height[spec->views / 4]);
171 /* Determine the pixel heights. */
172 for (size_t i = 0; i < lengthof(height); i++) {
173 height[i] *= ScaleGUITrad(TILE_HEIGHT);
174 height[i] += ScaleGUITrad(TILE_PIXELS) + 2 * OBJECT_MARGIN;
177 /* Now determine the size of the minimum widgets. When there are two columns, then
178 * we want these columns to be slightly less wide. When there are two rows, then
179 * determine the size of the widgets based on the maximum size for a single row
180 * of widgets, or just the twice the widget height of the two row ones. */
181 size->height = max(height[0], height[1] * 2 + 2);
182 if (two_wide) {
183 size->width = (3 * ScaleGUITrad(TILE_PIXELS) + 2 * OBJECT_MARGIN) * 2 + 2;
184 } else {
185 size->width = 4 * ScaleGUITrad(TILE_PIXELS) + 2 * OBJECT_MARGIN;
188 /* Get the right size for the single widget based on the current spec. */
189 const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
190 if (spec != NULL) {
191 if (spec->views >= 2) size->width = size->width / 2 - 1;
192 if (spec->views >= 4) size->height = size->height / 2 - 1;
194 break;
197 case WID_BO_INFO:
198 size->height = this->info_height;
199 break;
201 case WID_BO_SELECT_MATRIX:
202 fill->height = 1;
203 resize->height = 1;
204 break;
206 case WID_BO_SELECT_IMAGE:
207 size->width = ScaleGUITrad(64) + 2;
208 size->height = ScaleGUITrad(58) + 2;
209 break;
211 default: break;
215 virtual void DrawWidget(const Rect &r, int widget) const
217 switch (GB(widget, 0, 16)) {
218 case WID_BO_CLASS_LIST: {
219 int y = r.top;
220 uint pos = 0;
221 for (uint i = 0; i < ObjectClass::GetClassCount(); i++) {
222 ObjectClass *objclass = ObjectClass::Get((ObjectClassID)i);
223 if (objclass->GetUISpecCount() == 0) continue;
224 if (!this->vscroll->IsVisible(pos++)) continue;
225 DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, objclass->name,
226 ((int)i == _selected_object_class) ? TC_WHITE : TC_BLACK);
227 y += this->line_height;
229 break;
232 case WID_BO_OBJECT_SPRITE: {
233 const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
234 if (spec == NULL) break;
236 /* Height of the selection matrix.
237 * Depending on the number of views, the matrix has a 1x1, 1x2, 2x1 or 2x2 layout. To make the previews
238 * look nice in all layouts, we use the 4x4 layout (smallest previews) as starting point. For the bigger
239 * previews in the layouts with less views we add space homogeneously on all sides, so the 4x4 preview-rectangle
240 * is centered in the 2x1, 1x2 resp. 1x1 buttons. */
241 uint matrix_height = this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->current_y;
243 DrawPixelInfo tmp_dpi;
244 /* Set up a clipping area for the preview. */
245 if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left + 1, r.bottom - r.top + 1)) {
246 DrawPixelInfo *old_dpi = _cur_dpi;
247 _cur_dpi = &tmp_dpi;
248 if (spec->grf_prop.grffile == NULL) {
249 extern const DrawTileSprites _objects[];
250 const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
251 DrawOrigTileSeqInGUI((r.right - r.left) / 2 - 1, (r.bottom - r.top + matrix_height / 2) / 2 - OBJECT_MARGIN - ScaleGUITrad(TILE_PIXELS), dts, PAL_NONE);
252 } else {
253 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));
255 _cur_dpi = old_dpi;
257 break;
260 case WID_BO_SELECT_IMAGE: {
261 ObjectClass *objclass = ObjectClass::Get(_selected_object_class);
262 int obj_index = objclass->GetIndexFromUI(GB(widget, 16, 16));
263 if (obj_index < 0) break;
264 const ObjectSpec *spec = objclass->GetSpec(obj_index);
265 if (spec == NULL) break;
267 if (!spec->IsAvailable()) {
268 GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK, FILLRECT_CHECKER);
270 DrawPixelInfo tmp_dpi;
271 /* Set up a clipping area for the preview. */
272 if (FillDrawPixelInfo(&tmp_dpi, r.left + 1, r.top, (r.right - 1) - (r.left + 1) + 1, r.bottom - r.top + 1)) {
273 DrawPixelInfo *old_dpi = _cur_dpi;
274 _cur_dpi = &tmp_dpi;
275 if (spec->grf_prop.grffile == NULL) {
276 extern const DrawTileSprites _objects[];
277 const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
278 DrawOrigTileSeqInGUI((r.right - r.left) / 2 - 1, r.bottom - r.top - OBJECT_MARGIN - ScaleGUITrad(TILE_PIXELS), dts, PAL_NONE);
279 } else {
280 DrawNewObjectTileInGUI((r.right - r.left) / 2 - 1, r.bottom - r.top - OBJECT_MARGIN - ScaleGUITrad(TILE_PIXELS), spec,
281 min(_selected_object_view, spec->views - 1));
283 _cur_dpi = old_dpi;
285 break;
288 case WID_BO_INFO: {
289 const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
290 if (spec == NULL) break;
292 /* Get the extra message for the GUI */
293 if (HasBit(spec->callback_mask, CBM_OBJ_FUND_MORE_TEXT)) {
294 uint16 callback_res = GetObjectCallback(CBID_OBJECT_FUND_MORE_TEXT, 0, 0, spec, NULL, INVALID_TILE, _selected_object_view);
295 if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
296 if (callback_res > 0x400) {
297 ErrorUnknownCallbackResult(spec->grf_prop.grffile->grfid, CBID_OBJECT_FUND_MORE_TEXT, callback_res);
298 } else {
299 StringID message = GetGRFStringID(spec->grf_prop.grffile->grfid, 0xD000 + callback_res);
300 if (message != STR_NULL && message != STR_UNDEFINED) {
301 StartTextRefStackUsage(spec->grf_prop.grffile, 6);
302 /* Use all the available space left from where we stand up to the
303 * end of the window. We ALSO enlarge the window if needed, so we
304 * can 'go' wild with the bottom of the window. */
305 int y = DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, message, TC_ORANGE) - r.top;
306 StopTextRefStackUsage();
307 if (y > this->info_height) {
308 BuildObjectWindow *bow = const_cast<BuildObjectWindow *>(this);
309 bow->info_height = y + 2;
310 bow->ReInit();
321 * Select the specified object class.
322 * @param object_class_index Object class index to select.
324 void SelectOtherClass(ObjectClassID object_class_index)
326 _selected_object_class = object_class_index;
327 this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX)->SetCount(ObjectClass::Get(_selected_object_class)->GetUISpecCount());
331 * Select the specified object in #_selected_object_class class.
332 * @param object_index Object index to select, \c -1 means select nothing.
334 void SelectOtherObject(int object_index)
336 _selected_object_index = object_index;
337 if (_selected_object_index != -1) {
338 const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
339 _selected_object_view = min(_selected_object_view, spec->views - 1);
340 this->ReInit();
341 } else {
342 _selected_object_view = 0;
345 if (_selected_object_index != -1) {
346 SetObjectToPlaceWnd(SPR_CURSOR_TRANSMITTER, PAL_NONE, HT_RECT, this);
349 this->UpdateButtons(_selected_object_class, _selected_object_index, _selected_object_view);
352 void UpdateSelectSize()
354 if (_selected_object_index == -1) {
355 SetTileSelectSize(1, 1);
356 } else {
357 const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
358 int w = GB(spec->size, HasBit(_selected_object_view, 0) ? 4 : 0, 4);
359 int h = GB(spec->size, HasBit(_selected_object_view, 0) ? 0 : 4, 4);
360 SetTileSelectSize(w, h);
365 * Update buttons to show the selection to the user.
366 * @param sel_class The class of the selected object.
367 * @param sel_index Index of the object to select, or \c -1 .
368 * @param sel_view View of the object to select.
370 void UpdateButtons(ObjectClassID sel_class, int sel_index, uint sel_view)
372 int view_number, object_number;
373 if (sel_index == -1) {
374 view_number = -1; // If no object selected, also hide the selected view.
375 object_number = -1;
376 } else {
377 view_number = sel_view;
378 object_number = ObjectClass::Get(sel_class)->GetUIFromIndex(sel_index);
381 this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->SetClicked(view_number);
382 this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX)->SetClicked(object_number);
383 this->UpdateSelectSize();
384 this->SetDirty();
387 virtual void OnResize()
389 this->vscroll->SetCapacityFromWidget(this, WID_BO_CLASS_LIST);
392 virtual void OnClick(Point pt, int widget, int click_count)
394 switch (GB(widget, 0, 16)) {
395 case WID_BO_CLASS_LIST: {
396 int num_clicked = this->vscroll->GetPosition() + (pt.y - this->nested_array[widget]->pos_y) / this->line_height;
397 if (num_clicked >= (int)ObjectClass::GetUIClassCount()) break;
399 this->SelectOtherClass(ObjectClass::GetUIClass(num_clicked));
400 this->SelectFirstAvailableObject(false);
401 break;
404 case WID_BO_SELECT_IMAGE: {
405 ObjectClass *objclass = ObjectClass::Get(_selected_object_class);
406 int num_clicked = objclass->GetIndexFromUI(GB(widget, 16, 16));
407 if (num_clicked >= 0 && objclass->GetSpec(num_clicked)->IsAvailable()) this->SelectOtherObject(num_clicked);
408 break;
411 case WID_BO_OBJECT_SPRITE:
412 if (_selected_object_index != -1) {
413 _selected_object_view = GB(widget, 16, 16);
414 this->SelectOtherObject(_selected_object_index); // Re-select the object for a different view.
416 break;
420 virtual void OnPlaceObject(Point pt, TileIndex tile)
422 const ObjectSpec* spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
424 if (spec == nullptr) {
425 DoCommandP(tile, INVALID_OBJECT_TYPE, _selected_object_view, CMD_BUILD_OBJECT | CMD_MSG(STR_ERROR_CAN_T_BUILD_OBJECT), CcTerraform);
426 return;
429 int size_x = GB(spec->size, HasBit(_selected_object_view, 0) ? 4 : 0, 4);
430 int size_y = GB(spec->size, HasBit(_selected_object_view, 0) ? 0 : 4, 4);
431 ObjectType type = (ObjectType)GB(spec->Index(), 0, 16);
433 bool is_draggable = (size_x == 1 && size_y == 1 && type >= NEW_OBJECT_OFFSET);
435 if (is_draggable) {
436 VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_PLACE_OBJECT);
437 } else {
438 uint32 p2;
440 SB(p2, 0, 2, _selected_object_view);
441 SB(p2, 2, 30, tile);
443 DoCommandP(tile, spec->Index(), p2, CMD_BUILD_OBJECT | CMD_MSG(STR_ERROR_CAN_T_BUILD_OBJECT), CcTerraform);
447 virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
449 VpSelectTilesWithMethod(pt.x, pt.y, select_method);
452 virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
454 uint32 p2;
456 SB(p2, 0, 2, _selected_object_view);
457 SB(p2, 2, 30, start_tile);
459 if (pt.x != -1 && select_proc == DDSP_PLACE_OBJECT) {
460 DoCommandP(end_tile, ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index)->Index(),
461 p2, CMD_BUILD_OBJECT | CMD_MSG(STR_ERROR_CAN_T_BUILD_OBJECT), CcTerraform);
465 virtual void OnPlaceObjectAbort()
467 this->UpdateButtons(_selected_object_class, -1, _selected_object_view);
471 * Select the first available object.
472 * @param change_class If true, change the class if no object in the current
473 * class is available.
475 void SelectFirstAvailableObject(bool change_class)
477 /* First try to select an object in the selected class. */
478 ObjectClass *sel_objclass = ObjectClass::Get(_selected_object_class);
479 for (uint i = 0; i < sel_objclass->GetSpecCount(); i++) {
480 const ObjectSpec *spec = sel_objclass->GetSpec(i);
481 if (spec->IsAvailable()) {
482 this->SelectOtherObject(i);
483 return;
486 if (change_class) {
487 /* If that fails, select the first available object
488 * from a random class. */
489 for (ObjectClassID j = OBJECT_CLASS_BEGIN; j < OBJECT_CLASS_MAX; j++) {
490 ObjectClass *objclass = ObjectClass::Get(j);
491 for (uint i = 0; i < objclass->GetSpecCount(); i++) {
492 const ObjectSpec *spec = objclass->GetSpec(i);
493 if (spec->IsAvailable()) {
494 this->SelectOtherClass(j);
495 this->SelectOtherObject(i);
496 return;
501 /* If all objects are unavailable, select nothing... */
502 if (ObjectClass::Get(_selected_object_class)->GetUISpecCount() == 0) {
503 /* ... but make sure that the class is not empty. */
504 for (ObjectClassID j = OBJECT_CLASS_BEGIN; j < OBJECT_CLASS_MAX; j++) {
505 if (ObjectClass::Get(j)->GetUISpecCount() > 0) {
506 this->SelectOtherClass(j);
507 break;
511 this->SelectOtherObject(-1);
515 static const NWidgetPart _nested_build_object_widgets[] = {
516 NWidget(NWID_HORIZONTAL),
517 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
518 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_OBJECT_BUILD_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
519 NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
520 EndContainer(),
521 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
522 NWidget(NWID_HORIZONTAL), SetPadding(2, 0, 0, 0),
523 NWidget(NWID_VERTICAL),
524 NWidget(NWID_HORIZONTAL), SetPadding(0, 5, 2, 5),
525 NWidget(WWT_MATRIX, COLOUR_GREY, WID_BO_CLASS_LIST), SetFill(1, 0), SetMatrixDataTip(1, 0, STR_OBJECT_BUILD_CLASS_TOOLTIP), SetScrollbar(WID_BO_SCROLLBAR),
526 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_BO_SCROLLBAR),
527 EndContainer(),
528 NWidget(NWID_HORIZONTAL), SetPadding(0, 5, 0, 5),
529 NWidget(NWID_MATRIX, COLOUR_DARK_GREEN, WID_BO_OBJECT_MATRIX), SetPIP(0, 2, 0),
530 NWidget(WWT_PANEL, COLOUR_GREY, WID_BO_OBJECT_SPRITE), SetDataTip(0x0, STR_OBJECT_BUILD_PREVIEW_TOOLTIP), EndContainer(),
531 EndContainer(),
532 EndContainer(),
533 NWidget(WWT_TEXT, COLOUR_DARK_GREEN, WID_BO_OBJECT_NAME), SetDataTip(STR_ORANGE_STRING, STR_NULL), SetPadding(2, 5, 2, 5),
534 NWidget(WWT_TEXT, COLOUR_DARK_GREEN, WID_BO_OBJECT_SIZE), SetDataTip(STR_OBJECT_BUILD_SIZE, STR_NULL), SetPadding(2, 5, 2, 5),
535 EndContainer(),
536 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetScrollbar(WID_BO_SELECT_SCROLL),
537 NWidget(NWID_HORIZONTAL),
538 NWidget(NWID_MATRIX, COLOUR_DARK_GREEN, WID_BO_SELECT_MATRIX), SetFill(0, 1), SetPIP(0, 2, 0),
539 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BO_SELECT_IMAGE), SetMinimalSize(66, 60), SetDataTip(0x0, STR_OBJECT_BUILD_TOOLTIP),
540 SetFill(0, 0), SetResize(0, 0), SetScrollbar(WID_BO_SELECT_SCROLL),
541 EndContainer(),
542 EndContainer(),
543 NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_BO_SELECT_SCROLL),
544 EndContainer(),
545 EndContainer(),
546 EndContainer(),
547 NWidget(NWID_HORIZONTAL),
548 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BO_INFO), SetPadding(2, 5, 0, 5), SetFill(1, 0), SetResize(1, 0),
549 NWidget(NWID_VERTICAL),
550 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(0, 1), EndContainer(),
551 NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
552 EndContainer(),
553 EndContainer(),
554 EndContainer(),
557 static WindowDesc _build_object_desc(
558 WDP_AUTO, "build_object", 0, 0,
559 WC_BUILD_OBJECT, WC_BUILD_TOOLBAR,
560 WDF_CONSTRUCTION,
561 _nested_build_object_widgets, lengthof(_nested_build_object_widgets)
565 * Show our object picker.
566 * @param w The toolbar window we're associated with.
568 void ShowBuildObjectPicker()
570 /* Don't show the place object button when there are no objects to place. */
571 if (ObjectClass::GetUIClassCount() > 0) {
572 AllocateWindowDescFront<BuildObjectWindow>(&_build_object_desc, 0);
576 /** Reset all data of the object GUI. */
577 void InitializeObjectGui()
579 _selected_object_class = (ObjectClassID)0;