OpenTTD Source 20260129-master-g2bb01bd0e4
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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_badge_gui.h"
16#include "newgrf_object.h"
17#include "newgrf_text.h"
18#include "object.h"
19#include "object_base.h"
20#include "picker_gui.h"
21#include "sound_func.h"
22#include "strings_func.h"
23#include "viewport_func.h"
24#include "tilehighlight_func.h"
25#include "window_gui.h"
26#include "window_func.h"
27#include "zoom_func.h"
28#include "terraform_cmd.h"
29#include "object_cmd.h"
30#include "road_cmd.h"
31
33
34#include "table/strings.h"
35
36#include "safeguards.h"
37
44
46public:
48
49 GrfSpecFeature GetFeature() const override { return GSF_OBJECTS; }
50
51 StringID GetClassTooltip() const override { return STR_PICKER_OBJECT_CLASS_TOOLTIP; }
52 StringID GetTypeTooltip() const override { return STR_PICKER_OBJECT_TYPE_TOOLTIP; }
53 StringID GetCollectionTooltip() const override { return STR_PICKER_OBJECT_COLLECTION_TOOLTIP; }
54
55 bool IsActive() const override
56 {
57 for (const auto &cls : ObjectClass::Classes()) {
58 for (const auto *spec : cls.Specs()) {
59 if (spec != nullptr && spec->IsEverAvailable()) return true;
60 }
61 }
62 return false;
63 }
64
65 int GetSelectedClass() const override { return _object_gui.sel_class; }
66 void SetSelectedClass(int id) const override { _object_gui.sel_class = this->GetClassIndex(id); }
67
68 StringID GetClassName(int id) const override
69 {
70 const auto *objclass = this->GetClass(id);
71 if (objclass->GetUISpecCount() == 0) return INVALID_STRING_ID;
72 return objclass->name;
73 }
74
75 int GetSelectedType() const override { return _object_gui.sel_type; }
76 void SetSelectedType(int id) const override { _object_gui.sel_type = id; }
77
78 StringID GetTypeName(int cls_id, int id) const override
79 {
80 const auto *spec = this->GetSpec(cls_id, id);
81 return (spec == nullptr || !spec->IsEverAvailable()) ? INVALID_STRING_ID : spec->name;
82 }
83
84 std::span<const BadgeID> GetTypeBadges(int cls_id, int id) const override
85 {
86 const auto *spec = this->GetSpec(cls_id, id);
87 if (spec == nullptr || !spec->IsEverAvailable()) return {};
88 return spec->badges;
89 }
90
91 bool IsTypeAvailable(int cls_id, int id) const override
92 {
93 const auto *spec = this->GetSpec(cls_id, id);
94 return spec->IsAvailable();
95 }
96
97 void DrawType(int x, int y, int cls_id, int id) const override
98 {
99 const auto *spec = this->GetSpec(cls_id, id);
100 if (!spec->grf_prop.HasGrfFile()) {
101 extern const DrawTileSpriteSpan _objects[];
102 const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
103 DrawOrigTileSeqInGUI(x, y, dts, PAL_NONE);
104 } else {
105 DrawNewObjectTileInGUI(x, y, spec, std::min<int>(_object_gui.sel_view, spec->views - 1));
106 }
107 }
108
109 void FillUsedItems(std::set<PickerItem> &items) override
110 {
111 for (const Object *o : Object::Iterate()) {
112 if (GetTileOwner(o->location.tile) != _current_company) continue;
113 const ObjectSpec *spec = ObjectSpec::Get(o->type);
114 if (spec == nullptr || spec->class_index == INVALID_OBJECT_CLASS || !spec->IsEverAvailable()) continue;
115 items.insert(GetPickerItem(spec));
116 }
117 }
118
119 static ObjectPickerCallbacks instance;
120};
121/* static */ ObjectPickerCallbacks ObjectPickerCallbacks::instance;
122
125 int info_height = 1;
126
127public:
128 BuildObjectWindow(WindowDesc &desc, WindowNumber) : PickerWindow(desc, nullptr, 0, ObjectPickerCallbacks::instance)
129 {
131 this->ConstructWindow();
132 }
133
134 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
135 {
136 switch (widget) {
137 case WID_BO_OBJECT_SIZE: {
139 const ObjectSpec *spec = objclass->GetSpec(_object_gui.sel_type);
140 int size = spec == nullptr ? 0 : spec->size;
141 return GetString(STR_OBJECT_BUILD_SIZE, GB(size, HasBit(_object_gui.sel_view, 0) ? 4 : 0, 4), GB(size, HasBit(_object_gui.sel_view, 0) ? 0 : 4, 4));
142 }
143
144 default:
145 return this->PickerWindow::GetWidgetString(widget, stringid);
146 }
147 }
148
149 void OnInit() override
150 {
151 this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->SetCount(4);
152 this->PickerWindow::OnInit();
153 }
154
155 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
156 {
157 switch (widget) {
159 /* We do not want the window to resize when selecting objects; better clip texts */
160 size.width = 0;
161 break;
162
164 /* Get the right amount of buttons based on the current spec. */
166 const ObjectSpec *spec = objclass->GetSpec(_object_gui.sel_type);
167 if (spec != nullptr) {
168 if (spec->views >= 2) size.width += resize.width;
169 if (spec->views >= 4) size.height += resize.height;
170 }
171 resize.width = 0;
172 resize.height = 0;
173 break;
174 }
175
177 /* Get the right amount of buttons based on the current spec. */
179 const ObjectSpec *spec = objclass->GetSpec(_object_gui.sel_type);
182 if (spec != nullptr) {
183 if (spec->views <= 1) size.width = size.width * 2 + WidgetDimensions::scaled.hsep_normal;
184 if (spec->views <= 2) size.height = size.height * 2 + WidgetDimensions::scaled.vsep_normal;
185 }
186 break;
187 }
188
189 case WID_BO_INFO:
190 size.height = this->info_height;
191 fill.height = this->has_class_picker ? 0 : 1;
192 resize.height = this->has_class_picker ? 0 : 1;
193 break;
194
195 default:
196 this->PickerWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
197 break;
198 }
199 }
200
201 void DrawWidget(const Rect &r, WidgetID widget) const override
202 {
203 switch (widget) {
206 const ObjectSpec *spec = objclass->GetSpec(_object_gui.sel_type);
207 if (spec == nullptr) break;
208
209 const NWidgetMatrix *matrix = this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>();
210
211 DrawPixelInfo tmp_dpi;
212 /* Set up a clipping area for the preview. */
214 if (FillDrawPixelInfo(&tmp_dpi, ir)) {
215 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
218
219 if (!spec->grf_prop.HasGrfFile()) {
220 extern const DrawTileSpriteSpan _objects[];
221 const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
222 DrawOrigTileSeqInGUI(x, y, dts, PAL_NONE);
223 } else {
224 DrawNewObjectTileInGUI(x, y, spec, matrix->GetCurrentElement());
225 }
226 }
227 break;
228 }
229
230 case WID_BO_INFO: {
232 const ObjectSpec *spec = objclass->GetSpec(_object_gui.sel_type);
233 if (spec == nullptr) break;
234
235 Rect tr = r;
236 const int bottom = tr.bottom;
237 /* Use all the available space past the rect, so that we can enlarge the window if needed. */
238 tr.bottom = INT16_MAX;
239 tr.top = DrawBadgeNameList(tr, spec->badges, GSF_OBJECTS);
240
241 /* Get the extra message for the GUI */
243 std::array<int32_t, 16> regs100;
244 uint16_t callback_res = GetObjectCallback(CBID_OBJECT_FUND_MORE_TEXT, 0, 0, spec, nullptr, INVALID_TILE, regs100, _object_gui.sel_view);
245 if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
246 std::string str;
247 if (callback_res == 0x40F) {
248 str = GetGRFStringWithTextStack(spec->grf_prop.grffile, static_cast<GRFStringID>(regs100[0]), std::span{regs100}.subspan(1));
249 } else if (callback_res > 0x400) {
251 } else {
252 str = GetGRFStringWithTextStack(spec->grf_prop.grffile, GRFSTR_MISC_GRF_TEXT + callback_res, regs100);
253 }
254 if (!str.empty()) {
255 tr.top = DrawStringMultiLine(tr, str, TC_ORANGE);
256 }
257 }
258 }
259
260 if (tr.top > bottom) {
261 BuildObjectWindow *bow = const_cast<BuildObjectWindow *>(this);
262 bow->info_height += tr.top - bottom;
263 bow->ReInit();
264 }
265
266 break;
267 }
268
269 default:
270 this->PickerWindow::DrawWidget(r, widget);
271 break;
272 }
273 }
274
275 void UpdateSelectSize(const ObjectSpec *spec)
276 {
277 if (spec == nullptr) {
278 SetTileSelectSize(1, 1);
280 } else {
281 _object_gui.sel_view = std::min<int>(_object_gui.sel_view, spec->views - 1);
282 SetObjectToPlaceWnd(SPR_CURSOR_TRANSMITTER, PAL_NONE, HT_RECT | HT_DIAGONAL, this);
283 int w = GB(spec->size, HasBit(_object_gui.sel_view, 0) ? 4 : 0, 4);
284 int h = GB(spec->size, HasBit(_object_gui.sel_view, 0) ? 0 : 4, 4);
285 SetTileSelectSize(w, h);
286 this->ReInit();
287 }
288 }
289
294 void UpdateButtons(const ObjectSpec *spec)
295 {
296 this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->SetClicked(_object_gui.sel_view);
297 this->UpdateSelectSize(spec);
298 this->SetDirty();
299 }
300
301 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
302 {
303 this->PickerWindow::OnInvalidateData(data, gui_scope);
304
305 if (!gui_scope) return;
306
307 PickerInvalidations pi(data);
309 const auto objclass = ObjectClass::Get(_object_gui.sel_class);
310 const auto spec = objclass->GetSpec(_object_gui.sel_type);
311 _object_gui.sel_view = std::min<int>(_object_gui.sel_view, spec->views - 1);
312 this->UpdateButtons(spec);
313 }
314 }
315
316 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
317 {
318 switch (widget) {
320 if (_object_gui.sel_type != std::numeric_limits<uint16_t>::max()) {
321 _object_gui.sel_view = this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->GetCurrentElement();
322 this->InvalidateData(PickerInvalidation::Position);
323 SndClickBeep();
324 }
325 break;
326
327 default:
328 this->PickerWindow::OnClick(pt, widget, click_count);
329 break;
330 }
331 }
332
333 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
334 {
336
337 if (spec->size == OBJECT_SIZE_1X1) {
339 } else {
340 Command<Commands::BuildObject>::Post(STR_ERROR_CAN_T_BUILD_OBJECT, CcPlaySound_CONSTRUCTION_OTHER, tile, spec->Index(), _object_gui.sel_view);
341 }
342 }
343
344 void OnPlaceDrag(ViewportPlaceMethod select_method, [[maybe_unused]] ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt) override
345 {
346 VpSelectTilesWithMethod(pt.x, pt.y, select_method);
347 }
348
349 void OnPlaceMouseUp([[maybe_unused]] ViewportPlaceMethod select_method, [[maybe_unused]] ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt, TileIndex start_tile, TileIndex end_tile) override
350 {
351 if (pt.x == -1) return;
352
353 assert(select_proc == DDSP_BUILD_OBJECT);
354
356 Command<Commands::BuildObjectArea>::Post(STR_ERROR_CAN_T_BUILD_OBJECT, CcPlaySound_CONSTRUCTION_OTHER,
357 end_tile, start_tile, spec->Index(), _object_gui.sel_view, _ctrl_pressed);
358 }
359
360 void OnPlaceObjectAbort() override
361 {
362 this->UpdateButtons(nullptr);
363 }
364
371 {
372 if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
374 if (w == nullptr) return ES_NOT_HANDLED;
375 return w->OnHotkey(hotkey);
376 }
377
378 static inline HotkeyList hotkeys{"buildobject", {
379 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
381};
382
383static constexpr std::initializer_list<NWidgetPart> _nested_build_object_widgets = {
385 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
386 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetStringTip(STR_OBJECT_BUILD_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
387 NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
388 NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
389 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
390 EndContainer(),
394 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
396 NWidget(WWT_LABEL, INVALID_COLOUR), SetStringTip(STR_STATION_BUILD_ORIENTATION), SetFill(1, 0),
398 NWidget(NWID_MATRIX, COLOUR_DARK_GREEN, WID_BO_OBJECT_MATRIX), SetPIP(0, 2, 0),
399 NWidget(WWT_PANEL, COLOUR_GREY, WID_BO_OBJECT_SPRITE), SetToolTip(STR_OBJECT_BUILD_PREVIEW_TOOLTIP), EndContainer(),
400 EndContainer(),
401 EndContainer(),
403 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BO_INFO), SetFill(1, 0), SetResize(1, 0),
404 EndContainer(),
405 EndContainer(),
406 EndContainer(),
408 EndContainer(),
409};
410
411static WindowDesc _build_object_desc(
412 WDP_AUTO, "build_object", 0, 0,
415 _nested_build_object_widgets,
416 &BuildObjectWindow::hotkeys
417);
418
421{
422 /* Don't show the place object button when there are no objects to place. */
423 if (ObjectPickerCallbacks::instance.IsActive()) {
424 return AllocateWindowDescFront<BuildObjectWindow>(_build_object_desc, 0);
425 }
426 return nullptr;
427}
428
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
The window used for building objects.
int info_height
The height of the info box.
static EventState BuildObjectGlobalHotkeys(int hotkey)
Handler for global hotkeys of the BuildObjectWindow.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
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.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
void OnInit() override
Notification that the nested widget tree gets initialized.
void UpdateButtons(const ObjectSpec *spec)
Update buttons to show the selection to the user.
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.
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.
Enum-as-bit-set wrapper.
NWID * GetParentWidget()
Get parent widget of type NWID.
Matrix container with implicitly equal sized (virtual) sub-widgets.
int GetCurrentElement() const
Get current element.
Definition widget.cpp:1979
Struct containing information relating to NewGRF classes for stations and airports.
static std::span< NewGRFClass< Tspec, Tindex, Tmax > const > Classes()
Get read-only span of all classes of this type.
static NewGRFClass * Get(Tindex class_index)
Get a particular class.
const Tspec * GetSpec(uint index) const
Get a spec from the class at a given index.
std::span< const BadgeID > GetTypeBadges(int cls_id, int id) const override
Get the item of a type.
StringID GetClassName(int id) const override
Get the name of a class.
void DrawType(int x, int y, int cls_id, int id) const override
Draw preview image of an item.
void SetSelectedClass(int id) const override
Set the selected class.
StringID GetTypeTooltip() const override
Get the tooltip string for the type grid.
StringID GetCollectionTooltip() const override
Get the tooltip string for the collection list.
bool IsActive() const override
Should picker class/type selection be enabled?
StringID GetClassTooltip() const override
Get the tooltip string for the class list.
bool IsTypeAvailable(int cls_id, int id) const override
Test if an item is currently buildable.
int GetSelectedType() const override
Get the selected type.
void SetSelectedType(int id) const override
Set the selected type.
int GetSelectedClass() const override
Get the index of the selected class.
StringID GetTypeName(int cls_id, int id) const override
Get the item of a type.
void FillUsedItems(std::set< PickerItem > &items) override
Fill a set with all items that are used by the current player.
Helper for PickerCallbacks when the class system is based on NewGRFClass.
Definition picker_gui.h:140
static constexpr int PREVIEW_WIDTH
Width of each preview button.
Definition picker_gui.h:219
bool has_class_picker
Set if this window has a class picker 'component'.
Definition picker_gui.h:229
static constexpr int PREVIEW_HEIGHT
Height of each preview button.
Definition picker_gui.h:220
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
@ Position
Update scroll positions.
static constexpr int PREVIEW_LEFT
Offset from left edge to draw preview.
Definition picker_gui.h:221
static constexpr int PREVIEW_BOTTOM
Offset from bottom edge to draw preview.
Definition picker_gui.h:222
@ PCWHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
Definition picker_gui.h:253
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnInit() override
Notification that the nested widget tree gets initialized.
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.
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
int vsep_normal
Normal vertical spacing.
Definition window_gui.h:58
RectPadding fullbevel
Always-scaled bevel thickness.
Definition window_gui.h:39
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:93
int hsep_normal
Normal horizontal spacing.
Definition window_gui.h:61
Functions related to commands.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:38
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:785
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:1568
@ SA_CENTER
Center both horizontally and vertically.
Definition gfx_type.h:398
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
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.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
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.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:968
Hotkey related functions.
Base for the NewGRF implementation.
GrfSpecFeature
Definition newgrf.h:69
int DrawBadgeNameList(Rect r, std::span< const BadgeID > badges, GrfSpecFeature)
Draw names for a list of badge labels.
GUI functions related to NewGRF badges.
@ CBID_OBJECT_FUND_MORE_TEXT
Called to determine more text in the fund object window.
@ FundMoreText
additional text in fund window
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8_t view)
Draw representation of an object (tile) for GUI purposes.
uint16_t GetObjectCallback(CallbackID callback, uint32_t param1, uint32_t param2, const ObjectSpec *spec, Object *o, TileIndex tile, std::span< int32_t > regs100, uint8_t view)
Perform a callback for an object.
Functions related to NewGRF objects.
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,...
ObjectClassID
Class IDs for objects.
@ INVALID_OBJECT_CLASS
Class for the less fortunate.
@ OBJECT_CLASS_BEGIN
The lowest valid value.
std::string GetGRFStringWithTextStack(const struct GRFFile *grffile, GRFStringID grfstringid, std::span< const int32_t > textstack)
Format a GRF string using the text ref stack for parameters.
Header of Action 04 "universal holder" structure and functions.
static constexpr GRFStringID GRFSTR_MISC_GRF_TEXT
Miscellaneous GRF text range.
Functions related to objects.
Base for all objects.
Command definitions related to objects.
Window * ShowBuildObjectPicker()
Show our object picker.
void InitializeObjectGui()
Reset all data of the object GUI.
static ObjectPickerSelection _object_gui
Settings of the object picker.
Types related to the object widgets.
@ WID_BO_OBJECT_SIZE
The size of the selected object.
@ WID_BO_INFO
Other information about the object (from the NewGRF).
@ WID_BO_OBJECT_SPRITE
A preview sprite of the object.
@ WID_BO_OBJECT_MATRIX
The matrix with preview sprites.
std::unique_ptr< NWidgetBase > MakePickerClassWidgets()
Create nested widgets for the class picker widgets.
std::unique_ptr< NWidgetBase > MakePickerTypeWidgets()
Create nested widgets for the type picker widgets.
Functions/types etc.
Road related functions.
A number of safeguards to prevent using unsafe methods.
void SndClickBeep()
Play a beep sound for a click event if enabled in settings.
Definition sound.cpp:253
Functions related to sound.
void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
Draw TTD sprite sequence in GUI.
Definition sprite.h:121
Definition of base types and functions in a cross-platform compatible way.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Dimensions (a width and height) of a rectangle in 2D.
Data about how and where to blit pixels.
Definition gfx_type.h:157
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:67
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:52
const struct GRFFile * grffile
grf file that introduced this entity
uint16_t local_id
id defined by the grf file for this entity
uint32_t grfid
grfid that introduced this entity.
bool HasGrfFile() const
Test if this entity was introduced by NewGRF.
List of hotkeys for a window.
Definition hotkeys.h:37
All data for a single hotkey.
Definition hotkeys.h:21
Tindex class_index
Class index of this spec, invalid until class is allocated.
uint8_t sel_view
Selected view of the object.
ObjectClassID sel_class
Selected object class.
uint16_t sel_type
Selected object type within the class.
Allow incrementing of ObjectClassID variables.
StandardGRFFileProps grf_prop
Properties related the the grf file.
bool IsEverAvailable() const
Check whether the object might be available at some point in this game with the current game mode.
static const ObjectSpec * Get(ObjectType index)
Get the specification associated with a specific ObjectType.
uint8_t size
The size of this objects; low nibble for X, high nibble for Y.
uint Index() const
Gets the index of this spec.
ObjectCallbackMasks callback_mask
Bitmask of requested/allowed callbacks.
uint8_t views
The number of views.
An object, such as transmitter, on the map.
Definition object_base.h:23
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Specification of a rectangle with absolute coordinates of all edges.
int Width() const
Get width of Rect.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
int Height() const
Get height of Rect.
High level window description.
Definition window_gui.h:168
Number to differentiate different windows of the same class.
Data structure for an opened window.
Definition window_gui.h:274
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:980
ResizeInfo resize
Resize information.
Definition window_gui.h:315
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition window.cpp:572
Command definitions related to terraforming.
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition tile_map.h:178
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:100
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
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...
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
highlighting tiles while only going over them with the mouse
@ HT_DIAGONAL
Also allow 'diagonal rectangles'. Only usable in combination with HT_RECT or HT_POINT.
@ HT_RECT
rectangle (stations, depots, ...)
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
Functions related to (drawing on) viewports.
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
@ VPM_X_AND_Y
area of land in X and Y directions
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
@ DDSP_BUILD_OBJECT
Build an object.
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition widget.cpp:49
@ WWT_LABEL
Centered label.
Definition widget_type.h:48
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:57
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:55
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:52
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:60
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:37
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition widget_type.h:56
@ NWID_MATRIX
Matrix container.
Definition widget_type.h:69
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:49
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ Construction
This window is used for construction; close it whenever changing company.
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:144
int WidgetID
Widget ID.
Definition window_type.h:20
EventState
State of handling an event.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WC_BUILD_OBJECT
Build object; Window numbers:
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
Definition window_type.h:78
Functions related to zooming.
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition zoom_func.h:107