OpenTTD Source: src/object_gui.cpp Source File

OpenTTD Source 15.0-beta1

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 "company_func.h"
13#include "hotkeys.h"
14#include "newgrf.h"
15#include "newgrf_object.h"
16#include "newgrf_text.h"
17#include "object.h"
18#include "object_base.h"
19#include "picker_gui.h"
20#include "sound_func.h"
21#include "strings_func.h"
22#include "viewport_func.h"
23#include "tilehighlight_func.h"
24#include "window_gui.h"
25#include "window_func.h"
26#include "zoom_func.h"
27#include "terraform_cmd.h"
28#include "object_cmd.h"
29#include "road_cmd.h"
30
31#include "widgets/object_widget.h"
32
33#include "table/strings.h"
34
35#include "safeguards.h"
36
37 struct ObjectPickerSelection {
38 ObjectClassID sel_class;
39 uint16_t sel_type;
40 uint8_t sel_view;
41};
42 static ObjectPickerSelection _object_gui;
43
44 class ObjectPickerCallbacks : public PickerCallbacksNewGRFClass<ObjectClass> {
45public:
46 ObjectPickerCallbacks() : PickerCallbacksNewGRFClass<ObjectClass>("fav_objects") {}
47
48 StringID GetClassTooltip() const override { return STR_PICKER_OBJECT_CLASS_TOOLTIP; }
49 StringID GetTypeTooltip() const override { return STR_PICKER_OBJECT_TYPE_TOOLTIP; }
50
51 bool IsActive() const override
52 {
53 for (const auto &cls : ObjectClass::Classes()) {
54 for (const auto *spec : cls.Specs()) {
55 if (spec != nullptr && spec->IsEverAvailable()) return true;
56 }
57 }
58 return false;
59 }
60
61 int GetSelectedClass() const override { return _object_gui.sel_class; }
62 void SetSelectedClass(int id) const override { _object_gui.sel_class = this->GetClassIndex(id); }
63
64 StringID GetClassName(int id) const override
65 {
66 const auto *objclass = this->GetClass(id);
67 if (objclass->GetUISpecCount() == 0) return INVALID_STRING_ID;
68 return objclass->name;
69 }
70
71 int GetSelectedType() const override { return _object_gui.sel_type; }
72 void SetSelectedType(int id) const override { _object_gui.sel_type = id; }
73
74 StringID GetTypeName(int cls_id, int id) const override
75 {
76 const auto *spec = this->GetSpec(cls_id, id);
77 return (spec == nullptr || !spec->IsEverAvailable()) ? INVALID_STRING_ID : spec->name;
78 }
79
80 bool IsTypeAvailable(int cls_id, int id) const override
81 {
82 const auto *spec = this->GetSpec(cls_id, id);
83 return spec->IsAvailable();
84 }
85
86 void DrawType(int x, int y, int cls_id, int id) const override
87 {
88 const auto *spec = this->GetSpec(cls_id, id);
89 if (!spec->grf_prop.HasGrfFile()) {
90 extern const DrawTileSprites _objects[];
91 const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
92 DrawOrigTileSeqInGUI(x, y, dts, PAL_NONE);
93 } else {
94 DrawNewObjectTileInGUI(x, y, spec, std::min<int>(_object_gui.sel_view, spec->views - 1));
95 }
96 }
97
98 void FillUsedItems(std::set<PickerItem> &items) override
99 {
100 for (const Object *o : Object::Iterate()) {
101 if (GetTileOwner(o->location.tile) != _current_company) continue;
102 const ObjectSpec *spec = ObjectSpec::Get(o->type);
103 if (spec == nullptr || spec->class_index == INVALID_OBJECT_CLASS || !spec->IsEverAvailable()) continue;
104 items.insert(GetPickerItem(spec));
105 }
106 }
107
108 static ObjectPickerCallbacks instance;
109};
110/* static */ ObjectPickerCallbacks ObjectPickerCallbacks::instance;
111
113 class BuildObjectWindow : public PickerWindow {
114 int info_height;
115
116public:
117 BuildObjectWindow(WindowDesc &desc, WindowNumber) : PickerWindow(desc, nullptr, 0, ObjectPickerCallbacks::instance), info_height(1)
118 {
119 ResetObjectToPlace();
120 this->ConstructWindow();
121 this->InvalidateData();
122 }
123
124 void SetStringParameters(WidgetID widget) const override
125 {
126 switch (widget) {
127 case WID_BO_OBJECT_SIZE: {
128 ObjectClass *objclass = ObjectClass::Get(_object_gui.sel_class);
129 const ObjectSpec *spec = objclass->GetSpec(_object_gui.sel_type);
130 int size = spec == nullptr ? 0 : spec->size;
131 SetDParam(0, GB(size, HasBit(_object_gui.sel_view, 0) ? 4 : 0, 4));
132 SetDParam(1, GB(size, HasBit(_object_gui.sel_view, 0) ? 0 : 4, 4));
133 break;
134 }
135
136 default:
137 this->PickerWindow::SetStringParameters(widget);
138 break;
139 }
140 }
141
142 void OnInit() override
143 {
144 this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->SetCount(4);
145 this->PickerWindow::OnInit();
146 }
147
148 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
149 {
150 switch (widget) {
151 case WID_BO_OBJECT_SIZE:
152 /* We do not want the window to resize when selecting objects; better clip texts */
153 size.width = 0;
154 break;
155
156 case WID_BO_OBJECT_MATRIX: {
157 /* Get the right amount of buttons based on the current spec. */
158 const ObjectClass *objclass = ObjectClass::Get(_object_gui.sel_class);
159 const ObjectSpec *spec = objclass->GetSpec(_object_gui.sel_type);
160 if (spec != nullptr) {
161 if (spec->views >= 2) size.width += resize.width;
162 if (spec->views >= 4) size.height += resize.height;
163 }
164 resize.width = 0;
165 resize.height = 0;
166 break;
167 }
168
169 case WID_BO_OBJECT_SPRITE: {
170 /* Get the right amount of buttons based on the current spec. */
171 const ObjectClass *objclass = ObjectClass::Get(_object_gui.sel_class);
172 const ObjectSpec *spec = objclass->GetSpec(_object_gui.sel_type);
173 size.width = ScaleGUITrad(PREVIEW_WIDTH) + WidgetDimensions::scaled.fullbevel.Horizontal();
174 size.height = ScaleGUITrad(PREVIEW_HEIGHT) + WidgetDimensions::scaled.fullbevel.Vertical();
175 if (spec != nullptr) {
176 if (spec->views <= 1) size.width = size.width * 2 + WidgetDimensions::scaled.hsep_normal;
177 if (spec->views <= 2) size.height = size.height * 2 + WidgetDimensions::scaled.vsep_normal;
178 }
179 break;
180 }
181
182 case WID_BO_INFO:
183 size.height = this->info_height;
184 break;
185
186 default:
187 this->PickerWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
188 break;
189 }
190 }
191
192 void DrawWidget(const Rect &r, WidgetID widget) const override
193 {
194 switch (widget) {
195 case WID_BO_OBJECT_SPRITE: {
196 const ObjectClass *objclass = ObjectClass::Get(_object_gui.sel_class);
197 const ObjectSpec *spec = objclass->GetSpec(_object_gui.sel_type);
198 if (spec == nullptr) break;
199
200 const NWidgetMatrix *matrix = this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>();
201
202 DrawPixelInfo tmp_dpi;
203 /* Set up a clipping area for the preview. */
204 Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
205 if (FillDrawPixelInfo(&tmp_dpi, ir)) {
206 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
207 int x = (ir.Width() - ScaleSpriteTrad(PREVIEW_WIDTH)) / 2 + ScaleSpriteTrad(PREVIEW_LEFT);
208 int y = (ir.Height() + ScaleSpriteTrad(PREVIEW_HEIGHT)) / 2 - ScaleSpriteTrad(PREVIEW_BOTTOM);
209
210 if (!spec->grf_prop.HasGrfFile()) {
211 extern const DrawTileSprites _objects[];
212 const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
213 DrawOrigTileSeqInGUI(x, y, dts, PAL_NONE);
214 } else {
215 DrawNewObjectTileInGUI(x, y, spec, matrix->GetCurrentElement());
216 }
217 }
218 break;
219 }
220
221 case WID_BO_INFO: {
222 const ObjectClass *objclass = ObjectClass::Get(_object_gui.sel_class);
223 const ObjectSpec *spec = objclass->GetSpec(_object_gui.sel_type);
224 if (spec == nullptr) break;
225
226 /* Get the extra message for the GUI */
227 if (HasBit(spec->callback_mask, CBM_OBJ_FUND_MORE_TEXT)) {
228 uint16_t callback_res = GetObjectCallback(CBID_OBJECT_FUND_MORE_TEXT, 0, 0, spec, nullptr, INVALID_TILE, _object_gui.sel_view);
229 if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
230 if (callback_res > 0x400) {
231 ErrorUnknownCallbackResult(spec->grf_prop.grfid, CBID_OBJECT_FUND_MORE_TEXT, callback_res);
232 } else {
233 StringID message = GetGRFStringID(spec->grf_prop.grfid, 0xD000 + callback_res);
234 if (message != STR_NULL && message != STR_UNDEFINED) {
235 StartTextRefStackUsage(spec->grf_prop.grffile, 6);
236 /* Use all the available space left from where we stand up to the
237 * end of the window. We ALSO enlarge the window if needed, so we
238 * can 'go' wild with the bottom of the window. */
239 int y = DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, message, TC_ORANGE) - r.top - 1;
240 StopTextRefStackUsage();
241 if (y > this->info_height) {
242 BuildObjectWindow *bow = const_cast<BuildObjectWindow *>(this);
243 bow->info_height = y;
244 bow->ReInit();
245 }
246 }
247 }
248 }
249 }
250 break;
251 }
252
253 default:
254 this->PickerWindow::DrawWidget(r, widget);
255 break;
256 }
257 }
258
259 void UpdateSelectSize(const ObjectSpec *spec)
260 {
261 if (spec == nullptr) {
262 SetTileSelectSize(1, 1);
263 ResetObjectToPlace();
264 } else {
265 _object_gui.sel_view = std::min<int>(_object_gui.sel_view, spec->views - 1);
266 SetObjectToPlaceWnd(SPR_CURSOR_TRANSMITTER, PAL_NONE, HT_RECT | HT_DIAGONAL, this);
267 int w = GB(spec->size, HasBit(_object_gui.sel_view, 0) ? 4 : 0, 4);
268 int h = GB(spec->size, HasBit(_object_gui.sel_view, 0) ? 0 : 4, 4);
269 SetTileSelectSize(w, h);
270 this->ReInit();
271 }
272 }
273
278 void UpdateButtons(const ObjectSpec *spec)
279 {
280 this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->SetClicked(_object_gui.sel_view);
281 this->UpdateSelectSize(spec);
282 this->SetDirty();
283 }
284
285 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
286 {
287 this->PickerWindow::OnInvalidateData(data, gui_scope);
288
289 if (!gui_scope) return;
290
291 if ((data & PickerWindow::PFI_POSITION) != 0) {
292 const auto objclass = ObjectClass::Get(_object_gui.sel_class);
293 const auto spec = objclass->GetSpec(_object_gui.sel_type);
294 _object_gui.sel_view = std::min<int>(_object_gui.sel_view, spec->views - 1);
295 this->UpdateButtons(spec);
296 }
297 }
298
299 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
300 {
301 switch (widget) {
302 case WID_BO_OBJECT_SPRITE:
303 if (_object_gui.sel_type != MAX_UVALUE(uint16_t)) {
304 _object_gui.sel_view = this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->GetCurrentElement();
305 this->InvalidateData(PickerWindow::PFI_POSITION);
306 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
307 }
308 break;
309
310 default:
311 this->PickerWindow::OnClick(pt, widget, click_count);
312 break;
313 }
314 }
315
316 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
317 {
318 const ObjectSpec *spec = ObjectClass::Get(_object_gui.sel_class)->GetSpec(_object_gui.sel_type);
319
320 if (spec->size == OBJECT_SIZE_1X1) {
321 VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_BUILD_OBJECT);
322 } else {
323 Command<CMD_BUILD_OBJECT>::Post(STR_ERROR_CAN_T_BUILD_OBJECT, CcPlaySound_CONSTRUCTION_OTHER, tile, spec->Index(), _object_gui.sel_view);
324 }
325 }
326
327 void OnPlaceDrag(ViewportPlaceMethod select_method, [[maybe_unused]] ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt) override
328 {
329 VpSelectTilesWithMethod(pt.x, pt.y, select_method);
330 }
331
332 void OnPlaceMouseUp([[maybe_unused]] ViewportPlaceMethod select_method, [[maybe_unused]] ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt, TileIndex start_tile, TileIndex end_tile) override
333 {
334 if (pt.x == -1) return;
335
336 assert(select_proc == DDSP_BUILD_OBJECT);
337
338 if (!_settings_game.construction.freeform_edges) {
339 /* When end_tile is MP_VOID, the error tile will not be visible to the
340 * user. This happens when terraforming at the southern border. */
341 if (TileX(end_tile) == Map::MaxX()) end_tile += TileDiffXY(-1, 0);
342 if (TileY(end_tile) == Map::MaxY()) end_tile += TileDiffXY(0, -1);
343 }
344 const ObjectSpec *spec = ObjectClass::Get(_object_gui.sel_class)->GetSpec(_object_gui.sel_type);
345 Command<CMD_BUILD_OBJECT_AREA>::Post(STR_ERROR_CAN_T_BUILD_OBJECT, CcPlaySound_CONSTRUCTION_OTHER,
346 end_tile, start_tile, spec->Index(), _object_gui.sel_view, (_ctrl_pressed ? true : false));
347 }
348
349 void OnPlaceObjectAbort() override
350 {
351 this->UpdateButtons(nullptr);
352 }
353
359 static EventState BuildObjectGlobalHotkeys(int hotkey)
360 {
361 if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
362 Window *w = ShowBuildObjectPicker();
363 if (w == nullptr) return ES_NOT_HANDLED;
364 return w->OnHotkey(hotkey);
365 }
366
367 static inline HotkeyList hotkeys{"buildobject", {
368 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
369 }, BuildObjectGlobalHotkeys};
370};
371
372static constexpr NWidgetPart _nested_build_object_widgets[] = {
373 NWidget(NWID_HORIZONTAL),
374 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
375 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_OBJECT_BUILD_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
376 NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
377 NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
378 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
379 EndContainer(),
380 NWidget(NWID_HORIZONTAL),
381 NWidget(NWID_VERTICAL),
382 NWidgetFunction(MakePickerClassWidgets),
383 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
384 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_picker, 0), SetPadding(WidgetDimensions::unscaled.picker),
385 NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_ORIENTATION, STR_NULL), SetFill(1, 0),
386 NWidget(NWID_HORIZONTAL), SetPIPRatio(1, 0, 1),
387 NWidget(NWID_MATRIX, COLOUR_DARK_GREEN, WID_BO_OBJECT_MATRIX), SetPIP(0, 2, 0),
388 NWidget(WWT_PANEL, COLOUR_GREY, WID_BO_OBJECT_SPRITE), SetDataTip(0x0, STR_OBJECT_BUILD_PREVIEW_TOOLTIP), EndContainer(),
389 EndContainer(),
390 EndContainer(),
391 NWidget(WWT_TEXT, COLOUR_DARK_GREEN, WID_BO_OBJECT_SIZE), SetDataTip(STR_OBJECT_BUILD_SIZE, STR_NULL), SetAlignment(SA_CENTER),
392 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BO_INFO), SetFill(1, 0), SetResize(1, 0),
393 EndContainer(),
394 EndContainer(),
395 EndContainer(),
396 NWidgetFunction(MakePickerTypeWidgets),
397 EndContainer(),
398};
399
400static WindowDesc _build_object_desc(
401 WDP_AUTO, "build_object", 0, 0,
402 WC_BUILD_OBJECT, WC_BUILD_TOOLBAR,
403 WDF_CONSTRUCTION,
404 _nested_build_object_widgets,
405 &BuildObjectWindow::hotkeys
406);
407
409 Window *ShowBuildObjectPicker()
410{
411 /* Don't show the place object button when there are no objects to place. */
412 if (ObjectPickerCallbacks::instance.IsActive()) {
413 return AllocateWindowDescFront<BuildObjectWindow>(_build_object_desc, 0);
414 }
415 return nullptr;
416}
417
419 void InitializeObjectGui()
420{
421 _object_gui.sel_class = ObjectClassID::OBJECT_CLASS_BEGIN;
422}
HasBit
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
GB
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition bitmath_func.hpp:32
BuildObjectWindow
The window used for building objects.
Definition object_gui.cpp:113
BuildObjectWindow::SetStringParameters
void SetStringParameters(WidgetID widget) const override
Initialize string parameters for a widget.
Definition object_gui.cpp:124
BuildObjectWindow::info_height
int info_height
The height of the info box.
Definition object_gui.cpp:114
BuildObjectWindow::BuildObjectGlobalHotkeys
static EventState BuildObjectGlobalHotkeys(int hotkey)
Handler for global hotkeys of the BuildObjectWindow.
Definition object_gui.cpp:359
BuildObjectWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition object_gui.cpp:192
BuildObjectWindow::OnPlaceObjectAbort
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition object_gui.cpp:349
BuildObjectWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition object_gui.cpp:299
BuildObjectWindow::OnPlaceDrag
void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) override
The user is dragging over the map when the tile highlight mode has been set.
Definition object_gui.cpp:327
BuildObjectWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition object_gui.cpp:285
BuildObjectWindow::OnPlaceObject
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:316
BuildObjectWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition object_gui.cpp:142
BuildObjectWindow::UpdateButtons
void UpdateButtons(const ObjectSpec *spec)
Update buttons to show the selection to the user.
Definition object_gui.cpp:278
BuildObjectWindow::UpdateWidgetSize
void UpdateWidgetSize(WidgetID 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:148
BuildObjectWindow::OnPlaceMouseUp
void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) override
The user has dragged over the map when the tile highlight mode has been set.
Definition object_gui.cpp:332
NWidgetBase::GetParentWidget
NWID * GetParentWidget()
Get parent widget of type NWID.
Definition widget_type.h:165
NWidgetMatrix
Matrix container with implicitly equal sized (virtual) sub-widgets.
Definition widget_type.h:597
NWidgetMatrix::GetCurrentElement
int GetCurrentElement() const
Get current element.
Definition widget.cpp:1926
NewGRFClass
Struct containing information relating to NewGRF classes for stations and airports.
Definition newgrf_class.h:26
NewGRFClass::Classes
static std::span< NewGRFClass< Tspec, Tindex, Tmax > const > Classes()
Get read-only span of all classes of this type.
Definition newgrf_class.h:64
NewGRFClass::Get
static NewGRFClass * Get(Tindex class_index)
Get a particular class.
Definition newgrf_class_func.h:82
NewGRFClass::GetSpec
const Tspec * GetSpec(uint index) const
Get a spec from the class at a given index.
Definition newgrf_class_func.h:114
ObjectPickerCallbacks
Definition object_gui.cpp:44
ObjectPickerCallbacks::GetClassName
StringID GetClassName(int id) const override
Get the name of a class.
Definition object_gui.cpp:64
ObjectPickerCallbacks::DrawType
void DrawType(int x, int y, int cls_id, int id) const override
Draw preview image of an item.
Definition object_gui.cpp:86
ObjectPickerCallbacks::SetSelectedClass
void SetSelectedClass(int id) const override
Set the selected class.
Definition object_gui.cpp:62
ObjectPickerCallbacks::GetTypeTooltip
StringID GetTypeTooltip() const override
Get the tooltip string for the type grid.
Definition object_gui.cpp:49
ObjectPickerCallbacks::IsActive
bool IsActive() const override
Should picker class/type selection be enabled?
Definition object_gui.cpp:51
ObjectPickerCallbacks::GetClassTooltip
StringID GetClassTooltip() const override
Get the tooltip string for the class list.
Definition object_gui.cpp:48
ObjectPickerCallbacks::IsTypeAvailable
bool IsTypeAvailable(int cls_id, int id) const override
Test if an item is currently buildable.
Definition object_gui.cpp:80
ObjectPickerCallbacks::GetSelectedType
int GetSelectedType() const override
Get the selected type.
Definition object_gui.cpp:71
ObjectPickerCallbacks::SetSelectedType
void SetSelectedType(int id) const override
Set the selected type.
Definition object_gui.cpp:72
ObjectPickerCallbacks::GetSelectedClass
int GetSelectedClass() const override
Get the index of the selected class.
Definition object_gui.cpp:61
ObjectPickerCallbacks::GetTypeName
StringID GetTypeName(int cls_id, int id) const override
Get the item of a type.
Definition object_gui.cpp:74
ObjectPickerCallbacks::FillUsedItems
void FillUsedItems(std::set< PickerItem > &items) override
Fill a set with all items that are used by the current player.
Definition object_gui.cpp:98
PickerCallbacksNewGRFClass
Helper for PickerCallbacks when the class system is based on NewGRFClass.
Definition picker_gui.h:100
PickerWindow
Definition picker_gui.h:148
PickerWindow::PREVIEW_LEFT
static const int PREVIEW_LEFT
Offset from left edge to draw preview.
Definition picker_gui.h:165
PickerWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition picker_gui.cpp:274
PickerWindow::PCWHK_FOCUS_FILTER_BOX
@ PCWHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
Definition picker_gui.h:185
PickerWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition picker_gui.cpp:331
PickerWindow::PFI_POSITION
@ PFI_POSITION
Update scroll positions.
Definition picker_gui.h:159
PickerWindow::PREVIEW_WIDTH
static const int PREVIEW_WIDTH
Width of each preview button.
Definition picker_gui.h:163
PickerWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition picker_gui.cpp:390
PickerWindow::PREVIEW_BOTTOM
static const int PREVIEW_BOTTOM
Offset from bottom edge to draw preview.
Definition picker_gui.h:166
PickerWindow::UpdateWidgetSize
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Definition picker_gui.cpp:246
PickerWindow::PREVIEW_HEIGHT
static const int PREVIEW_HEIGHT
Height of each preview button.
Definition picker_gui.h:164
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:28
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition window_gui.h:60
WidgetDimensions::fullbevel
RectPadding fullbevel
Always-scaled bevel thickness.
Definition window_gui.h:41
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:96
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition window_gui.h:63
command_func.h
Functions related to commands.
_current_company
CompanyID _current_company
Company currently doing an action.
Definition company_cmd.cpp:53
company_func.h
Functions related to companies.
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:38
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition gfx.cpp:774
FillDrawPixelInfo
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:1548
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition gfx_type.h:353
NWidgetFunction
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition widget_type.h:1341
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1181
SetPIP
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
Definition widget_type.h:1271
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition widget_type.h:1228
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition widget_type.h:1202
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1320
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1191
SetAlignment
constexpr NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
Definition widget_type.h:1170
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1126
SetPIPRatio
constexpr NWidgetPart SetPIPRatio(uint8_t ratio_pre, uint8_t ratio_inter, uint8_t ratio_post)
Widget part function for setting a pre/inter/post ratio.
Definition widget_type.h:1283
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:940
hotkeys.h
Hotkey related functions.
TileDiffXY
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition map_func.h:389
TileY
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:425
TileX
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:415
newgrf.h
Base for the NewGRF implementation.
CBID_OBJECT_FUND_MORE_TEXT
@ CBID_OBJECT_FUND_MORE_TEXT
Called to determine more text in the fund object window.
Definition newgrf_callbacks.h:269
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition newgrf_callbacks.h:427
CBM_OBJ_FUND_MORE_TEXT
@ CBM_OBJ_FUND_MORE_TEXT
additional text in fund window
Definition newgrf_callbacks.h:409
ErrorUnknownCallbackResult
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
Definition newgrf_commons.cpp:505
DrawNewObjectTileInGUI
void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8_t view)
Draw representation of an object (tile) for GUI purposes.
Definition newgrf_object.cpp:482
GetObjectCallback
uint16_t GetObjectCallback(CallbackID callback, uint32_t param1, uint32_t param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8_t view)
Perform a callback for an object.
Definition newgrf_object.cpp:426
newgrf_object.h
Functions related to NewGRF objects.
OBJECT_SIZE_1X1
static const uint8_t OBJECT_SIZE_1X1
The value of a NewGRF's size property when the object is 1x1 tiles: low nibble for X,...
Definition newgrf_object.h:43
ObjectClassID
ObjectClassID
Class IDs for objects.
Definition newgrf_object.h:48
INVALID_OBJECT_CLASS
@ INVALID_OBJECT_CLASS
Class for the less fortunate.
Definition newgrf_object.h:51
OBJECT_CLASS_BEGIN
@ OBJECT_CLASS_BEGIN
The lowest valid value.
Definition newgrf_object.h:49
StartTextRefStackUsage
void StartTextRefStackUsage(const GRFFile *grffile, uint8_t numEntries, const uint32_t *values)
Start using the TTDP compatible string code parsing.
Definition newgrf_text.cpp:798
GetGRFStringID
StringID GetGRFStringID(uint32_t grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
Definition newgrf_text.cpp:587
StopTextRefStackUsage
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
Definition newgrf_text.cpp:815
newgrf_text.h
Header of Action 04 "universal holder" structure and functions.
object.h
Functions related to objects.
object_base.h
Base for all objects.
object_cmd.h
Command definitions related to objects.
ShowBuildObjectPicker
Window * ShowBuildObjectPicker()
Show our object picker.
Definition object_gui.cpp:409
InitializeObjectGui
void InitializeObjectGui()
Reset all data of the object GUI.
Definition object_gui.cpp:419
_object_gui
static ObjectPickerSelection _object_gui
Settings of the object picker.
Definition object_gui.cpp:42
object_widget.h
Types related to the object widgets.
WID_BO_OBJECT_SIZE
@ WID_BO_OBJECT_SIZE
The size of the selected object.
Definition object_widget.h:17
WID_BO_INFO
@ WID_BO_INFO
Other information about the object (from the NewGRF).
Definition object_widget.h:18
WID_BO_OBJECT_SPRITE
@ WID_BO_OBJECT_SPRITE
A preview sprite of the object.
Definition object_widget.h:16
WID_BO_OBJECT_MATRIX
@ WID_BO_OBJECT_MATRIX
The matrix with preview sprites.
Definition object_widget.h:15
MakePickerClassWidgets
std::unique_ptr< NWidgetBase > MakePickerClassWidgets()
Create nested widgets for the class picker widgets.
Definition picker_gui.cpp:623
MakePickerTypeWidgets
std::unique_ptr< NWidgetBase > MakePickerTypeWidgets()
Create nested widgets for the type picker widgets.
Definition picker_gui.cpp:646
picker_gui.h
Functions/types etc.
road_cmd.h
Road related functions.
safeguards.h
A number of safeguards to prevent using unsafe methods.
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:57
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:56
sound_func.h
Functions related to sound.
SND_15_BEEP
@ SND_15_BEEP
19 == 0x13 GUI button click
Definition sound_type.h:66
DrawOrigTileSeqInGUI
void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
Draw TTD sprite sequence in GUI.
Definition sprite.h:115
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
MAX_UVALUE
#define MAX_UVALUE(type)
The largest value that can be entered in a variable.
Definition stdafx.h:343
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition strings.cpp:104
strings_func.h
Functions related to OTTD's strings.
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:16
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition strings_type.h:17
AutoRestoreBackup
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Definition backup_type.hpp:150
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition settings_type.h:613
CommandHelper
Definition command_func.h:83
ConstructionSettings::freeform_edges
bool freeform_edges
allow terraforming the tiles at the map edges
Definition settings_type.h:395
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:30
DrawPixelInfo
Data about how and where to blit pixels.
Definition gfx_type.h:157
DrawTileSprites
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:58
GRFFilePropsBase::HasGrfFile
bool HasGrfFile() const
Test if this entity was introduced by NewGRF.
Definition newgrf_commons.h:320
GRFFilePropsBase::local_id
uint16_t local_id
id defined by the grf file for this entity
Definition newgrf_commons.h:311
GRFFilePropsBase::grfid
uint32_t grfid
grfid that introduced this entity.
Definition newgrf_commons.h:312
GRFFilePropsBase::grffile
const struct GRFFile * grffile
grf file that introduced this entity
Definition newgrf_commons.h:313
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition settings_type.h:594
HotkeyList
List of hotkeys for a window.
Definition hotkeys.h:37
Hotkey
All data for a single hotkey.
Definition hotkeys.h:21
Map::MaxY
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition map_func.h:306
Map::MaxX
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition map_func.h:297
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition widget_type.h:1075
NewGRFSpecBase::class_index
Tindex class_index
Class index of this spec, invalid until class is allocated.
Definition newgrf_class.h:18
ObjectPickerSelection
Definition object_gui.cpp:37
ObjectPickerSelection::sel_view
uint8_t sel_view
Selected view of the object.
Definition object_gui.cpp:40
ObjectPickerSelection::sel_class
ObjectClassID sel_class
Selected object class.
Definition object_gui.cpp:38
ObjectPickerSelection::sel_type
uint16_t sel_type
Selected object type within the class.
Definition object_gui.cpp:39
ObjectSpec
Allow incrementing of ObjectClassID variables.
Definition newgrf_object.h:60
ObjectSpec::IsEverAvailable
bool IsEverAvailable() const
Check whether the object might be available at some point in this game with the current game mode.
Definition newgrf_object.cpp:74
ObjectSpec::Get
static const ObjectSpec * Get(ObjectType index)
Get the specification associated with a specific ObjectType.
Definition newgrf_object.cpp:50
ObjectSpec::grf_prop
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
Definition newgrf_object.h:62
ObjectSpec::size
uint8_t size
The size of this objects; low nibble for X, high nibble for Y.
Definition newgrf_object.h:67
ObjectSpec::Index
uint Index() const
Gets the index of this spec.
Definition newgrf_object.cpp:103
ObjectSpec::views
uint8_t views
The number of views.
Definition newgrf_object.h:75
ObjectSpec::callback_mask
uint16_t callback_mask
Bitmask of requested/allowed callbacks.
Definition newgrf_object.h:73
Object
An object, such as transmitter, on the map.
Definition object_base.h:23
Point
Coordinates of a point in 2D.
Definition geometry_type.hpp:21
Pool::PoolItem<&_object_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition pool_type.hpp:388
RectPadding::Horizontal
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition geometry_type.hpp:63
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition geometry_type.hpp:69
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:75
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition geometry_type.hpp:98
SoundSettings::click_beep
bool click_beep
Beep on a random selection of buttons.
Definition settings_type.h:249
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
WindowDesc
High level window description.
Definition window_gui.h:159
Window
Data structure for an opened window.
Definition window_gui.h:273
Window::ReInit
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:952
Window::SetStringParameters
virtual void SetStringParameters(WidgetID widget) const
Initialize string parameters for a widget.
Definition window_gui.h:632
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition window.cpp:3159
Window::resize
ResizeInfo resize
Resize information.
Definition window_gui.h:314
Window::GetWidget
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:977
Window::OnHotkey
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition window.cpp:565
Window::OnInit
virtual void OnInit()
Notification that the nested widget tree gets initialized.
Definition window_gui.h:582
terraform_cmd.h
Command definitions related to terraforming.
GetTileOwner
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition tile_map.h:178
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
tilehighlight_func.h
Functions related to tile highlights.
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition viewport.cpp:3498
SetObjectToPlaceWnd
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:3435
VpSelectTilesWithMethod
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
Definition viewport.cpp:3216
VpStartPlaceSizing
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
highlighting tiles while only going over them with the mouse
Definition viewport.cpp:2722
HT_DIAGONAL
@ HT_DIAGONAL
Also allow 'diagonal rectangles'. Only usable in combination with HT_RECT or HT_POINT.
Definition tilehighlight_type.h:28
HT_RECT
@ HT_RECT
rectangle (stations, depots, ...)
Definition tilehighlight_type.h:21
SetTileSelectSize
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
Definition viewport.cpp:2542
viewport_func.h
Functions related to (drawing on) viewports.
ViewportDragDropSelectionProcess
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
Definition viewport_type.h:111
DDSP_BUILD_OBJECT
@ DDSP_BUILD_OBJECT
Build an object.
Definition viewport_type.h:122
ViewportPlaceMethod
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
Definition viewport_type.h:92
VPM_X_AND_Y
@ VPM_X_AND_Y
area of land in X and Y directions
Definition viewport_type.h:96
ScaleGUITrad
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition widget.cpp:35
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition widget_type.h:57
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:75
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:50
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:66
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:64
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:61
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:77
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:69
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:48
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition widget_type.h:65
NWID_MATRIX
@ NWID_MATRIX
Matrix container.
Definition widget_type.h:78
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:58
window_func.h
Window functions not directly related to making/drawing windows.
window_gui.h
Functions, definitions and such used only by the GUI.
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition window_gui.h:203
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:147
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:18
WindowNumber
int32_t WindowNumber
Number to differentiate different windows of the same class.
Definition window_type.h:740
EventState
EventState
State of handling an event.
Definition window_type.h:743
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition window_type.h:745
WC_BUILD_OBJECT
@ WC_BUILD_OBJECT
Build object; Window numbers:
Definition window_type.h:376
WC_BUILD_TOOLBAR
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
Definition window_type.h:73
zoom_func.h
Functions related to zooming.
ScaleSpriteTrad
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition zoom_func.h:107