OpenTTD Source 20261112-master-gbcbec5e63f
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
9
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 "zoom_func.h"
27#include "terraform_cmd.h"
28#include "object_cmd.h"
29#include "road_cmd.h"
30
32
33#include "table/strings.h"
34
35#include "safeguards.h"
36
43
44class ObjectPickerCallbacks : public PickerCallbacksNewGRFClass<ObjectClass> {
45public:
46 ObjectPickerCallbacks() : PickerCallbacksNewGRFClass<ObjectClass>("fav_objects") {}
47
49
50 StringID GetClassTooltip() const override { return STR_PICKER_OBJECT_CLASS_TOOLTIP; }
51 StringID GetTypeTooltip() const override { return STR_PICKER_OBJECT_TYPE_TOOLTIP; }
52 StringID GetCollectionTooltip() const override { return STR_PICKER_OBJECT_COLLECTION_TOOLTIP; }
53
54 bool IsActive() const override
55 {
56 for (const auto &cls : ObjectClass::Classes()) {
57 for (const auto *spec : cls.Specs()) {
58 if (spec != nullptr && spec->IsEverAvailable()) return true;
59 }
60 }
61 return false;
62 }
63
64 int GetSelectedClass() const override { return _object_gui.sel_class.base(); }
65 void SetSelectedClass(int id) const override { _object_gui.sel_class = this->GetClassIndex(id); }
66
67 StringID GetClassName(int id) const override
68 {
69 const auto *objclass = this->GetClass(id);
70 if (objclass->GetUISpecCount() == 0) return INVALID_STRING_ID;
71 return objclass->name;
72 }
73
74 int GetSelectedType() const override { return _object_gui.sel_type; }
75 void SetSelectedType(int id) const override { _object_gui.sel_type = id; }
76
77 StringID GetTypeName(int cls_id, int id) const override
78 {
79 const auto *spec = this->GetSpec(cls_id, id);
80 return (spec == nullptr || !spec->IsEverAvailable()) ? INVALID_STRING_ID : spec->name;
81 }
82
83 std::span<const BadgeID> GetTypeBadges(int cls_id, int id) const override
84 {
85 const auto *spec = this->GetSpec(cls_id, id);
86 if (spec == nullptr || !spec->IsEverAvailable()) return {};
87 return spec->badges;
88 }
89
90 bool IsTypeAvailable(int cls_id, int id) const override
91 {
92 const auto *spec = this->GetSpec(cls_id, id);
93 return spec->IsAvailable();
94 }
95
96 void DrawType(int x, int y, int cls_id, int id) const override
97 {
98 const auto *spec = this->GetSpec(cls_id, id);
99 if (!spec->grf_prop.HasGrfFile()) {
100 extern const DrawTileSpriteSpan _objects[];
101 const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
102 DrawOrigTileSeqInGUI(x, y, dts, PAL_NONE);
103 } else {
104 DrawNewObjectTileInGUI(x, y, spec, std::min<int>(_object_gui.sel_view, spec->views - 1));
105 }
106 }
107
108 void FillUsedItems(std::set<PickerItem> &items) override
109 {
110 for (const Object *o : Object::Iterate()) {
111 if (GetTileOwner(o->location.tile) != _current_company) continue;
112 const ObjectSpec *spec = ObjectSpec::Get(o->type);
113 if (spec == nullptr || spec->class_index == ObjectClassID::Invalid() || !spec->IsEverAvailable()) continue;
114 items.insert(GetPickerItem(spec));
115 }
116 }
117
118 static ObjectPickerCallbacks instance;
119};
120/* static */ ObjectPickerCallbacks ObjectPickerCallbacks::instance;
121
123class BuildObjectWindow : public PickerWindow {
124 int info_height = 1;
125
126public:
127 BuildObjectWindow(WindowDesc &desc, WindowNumber) : PickerWindow(desc, nullptr, 0, ObjectPickerCallbacks::instance)
128 {
130 this->ConstructWindow();
131 }
132
133 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
134 {
135 switch (widget) {
136 case WID_BO_OBJECT_SIZE: {
137 ObjectClass *objclass = ObjectClass::Get(_object_gui.sel_class);
138 const ObjectSpec *spec = objclass->GetSpec(_object_gui.sel_type);
139 int size = spec == nullptr ? 0 : spec->size;
140 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));
141 }
142
143 default:
144 return this->PickerWindow::GetWidgetString(widget, stringid);
145 }
146 }
147
148 void OnInit() override
149 {
151 this->PickerWindow::OnInit();
152 }
153
154 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
155 {
156 switch (widget) {
158 /* We do not want the window to resize when selecting objects; better clip texts */
159 size.width = 0;
160 break;
161
163 /* Get the right amount of buttons based on the current spec. */
164 const ObjectClass *objclass = ObjectClass::Get(_object_gui.sel_class);
165 const ObjectSpec *spec = objclass->GetSpec(_object_gui.sel_type);
166 if (spec != nullptr) {
167 if (spec->views >= 2) size.width += resize.width;
168 if (spec->views >= 4) size.height += resize.height;
169 }
170 resize.width = 0;
171 resize.height = 0;
172 break;
173 }
174
176 /* Get the right amount of buttons based on the current spec. */
177 const ObjectClass *objclass = ObjectClass::Get(_object_gui.sel_class);
178 const ObjectSpec *spec = objclass->GetSpec(_object_gui.sel_type);
179 size.width = ScaleGUITrad(PREVIEW_WIDTH) + WidgetDimensions::scaled.fullbevel.Horizontal();
180 size.height = ScaleGUITrad(PREVIEW_HEIGHT) + WidgetDimensions::scaled.fullbevel.Vertical();
181 if (spec != nullptr) {
182 if (spec->views <= 1) size.width = size.width * 2 + WidgetDimensions::scaled.hsep_normal;
183 if (spec->views <= 2) size.height = size.height * 2 + WidgetDimensions::scaled.vsep_normal;
184 }
185 break;
186 }
187
188 case WID_BO_INFO:
189 size.height = this->info_height;
190 fill.height = this->has_class_picker ? 0 : 1;
191 resize.height = this->has_class_picker ? 0 : 1;
192 break;
193
194 default:
195 this->PickerWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
196 break;
197 }
198 }
199
200 void DrawWidget(const Rect &r, WidgetID widget) const override
201 {
202 switch (widget) {
204 const ObjectClass *objclass = ObjectClass::Get(_object_gui.sel_class);
205 const ObjectSpec *spec = objclass->GetSpec(_object_gui.sel_type);
206 if (spec == nullptr) break;
207
208 const NWidgetMatrix *matrix = this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>();
209
210 DrawPixelInfo tmp_dpi;
211 /* Set up a clipping area for the preview. */
213 if (FillDrawPixelInfo(&tmp_dpi, ir)) {
214 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
217
218 if (!spec->grf_prop.HasGrfFile()) {
219 extern const DrawTileSpriteSpan _objects[];
220 const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
221 DrawOrigTileSeqInGUI(x, y, dts, PAL_NONE);
222 } else {
223 DrawNewObjectTileInGUI(x, y, spec, matrix->GetCurrentElement());
224 }
225 }
226 break;
227 }
228
229 case WID_BO_INFO: {
230 const ObjectClass *objclass = ObjectClass::Get(_object_gui.sel_class);
231 const ObjectSpec *spec = objclass->GetSpec(_object_gui.sel_type);
232 if (spec == nullptr) break;
233
234 Rect tr = r;
235 const int bottom = tr.bottom;
236 /* Use all the available space past the rect, so that we can enlarge the window if needed. */
237 tr.bottom = INT16_MAX;
238 tr.top = DrawBadgeNameList(tr, spec->badges, GrfSpecFeature::Objects);
239
240 /* Get the extra message for the GUI */
242 std::array<int32_t, 16> regs100;
243 uint16_t callback_res = GetObjectCallback(CBID_OBJECT_FUND_MORE_TEXT, 0, 0, spec, nullptr, INVALID_TILE, regs100, _object_gui.sel_view);
244 if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
245 std::string str;
246 if (callback_res == 0x40F) {
247 str = GetGRFStringWithTextStack(spec->grf_prop.grffile, static_cast<GRFStringID>(regs100[0]), std::span{regs100}.subspan(1));
248 } else if (callback_res > 0x400) {
250 } else {
251 str = GetGRFStringWithTextStack(spec->grf_prop.grffile, GRFSTR_MISC_GRF_TEXT + callback_res, regs100);
252 }
253 if (!str.empty()) {
254 tr.top = DrawStringMultiLine(tr, str, TextColour::Orange);
255 }
256 }
257 }
258
259 if (tr.top > bottom) {
260 BuildObjectWindow *bow = const_cast<BuildObjectWindow *>(this);
261 bow->info_height += tr.top - bottom;
262 bow->ReInit();
263 }
264
265 break;
266 }
267
268 default:
269 this->PickerWindow::DrawWidget(r, widget);
270 break;
271 }
272 }
273
274 void UpdateSelectSize(const ObjectSpec *spec)
275 {
276 if (spec == nullptr) {
277 SetTileSelectSize(1, 1);
279 } else {
280 _object_gui.sel_view = std::min<int>(_object_gui.sel_view, spec->views - 1);
282 int w = GB(spec->size, HasBit(_object_gui.sel_view, 0) ? 4 : 0, 4);
283 int h = GB(spec->size, HasBit(_object_gui.sel_view, 0) ? 0 : 4, 4);
284 SetTileSelectSize(w, h);
285 this->ReInit();
286 }
287 }
288
293 void UpdateButtons(const ObjectSpec *spec)
294 {
295 this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->SetClicked(_object_gui.sel_view);
296 this->UpdateSelectSize(spec);
297 this->SetDirty();
298 }
299
300 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
301 {
302 this->PickerWindow::OnInvalidateData(data, gui_scope);
303
304 if (!gui_scope) return;
305
306 PickerInvalidations pi(data);
308 const auto objclass = ObjectClass::Get(_object_gui.sel_class);
309 const auto spec = objclass->GetSpec(_object_gui.sel_type);
310 _object_gui.sel_view = std::min<int>(_object_gui.sel_view, spec->views - 1);
311 this->UpdateButtons(spec);
312 }
313 }
314
315 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
316 {
317 switch (widget) {
319 if (_object_gui.sel_type != std::numeric_limits<uint16_t>::max()) {
320 _object_gui.sel_view = this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->GetCurrentElement();
321 this->InvalidateData(PickerInvalidation::Position);
322 SndClickBeep();
323 }
324 break;
325
326 default:
327 this->PickerWindow::OnClick(pt, widget, click_count);
328 break;
329 }
330 }
331
332 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
333 {
334 const ObjectSpec *spec = ObjectClass::Get(_object_gui.sel_class)->GetSpec(_object_gui.sel_type);
335
336 if (spec->size == OBJECT_SIZE_1X1) {
338 } else {
339 Command<Commands::BuildObject>::Post(STR_ERROR_CAN_T_BUILD_OBJECT, CcPlaySound_CONSTRUCTION_OTHER, tile, spec->Index(), _object_gui.sel_view);
340 }
341 }
342
343 void OnPlaceDrag(ViewportPlaceMethod select_method, [[maybe_unused]] ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt) override
344 {
345 VpSelectTilesWithMethod(pt.x, pt.y, select_method);
346 }
347
348 void OnPlaceMouseUp([[maybe_unused]] ViewportPlaceMethod select_method, [[maybe_unused]] ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt, TileIndex start_tile, TileIndex end_tile) override
349 {
350 if (pt.x == -1) return;
351
352 assert(select_proc == DDSP_BUILD_OBJECT);
353
354 const ObjectSpec *spec = ObjectClass::Get(_object_gui.sel_class)->GetSpec(_object_gui.sel_type);
355 Command<Commands::BuildObjectArea>::Post(STR_ERROR_CAN_T_BUILD_OBJECT, CcPlaySound_CONSTRUCTION_OTHER,
356 end_tile, start_tile, spec->Index(), _object_gui.sel_view, IsCtrlPressed());
357 }
358
359 void OnPlaceObjectAbort() override
360 {
361 this->UpdateButtons(nullptr);
362 }
363
370 {
371 if (_game_mode == GameMode::Menu) return EventState::NotHandled;
373 if (w == nullptr) return EventState::NotHandled;
374 return w->OnHotkey(hotkey);
375 }
376
377 static inline HotkeyList hotkeys{"buildobject", {
378 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
380};
381
382static constexpr std::initializer_list<NWidgetPart> _nested_build_object_widgets = {
385 NWidget(WWT_CAPTION, Colours::DarkGreen), SetStringTip(STR_OBJECT_BUILD_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
389 EndContainer(),
395 NWidget(WWT_LABEL, Colours::Invalid), SetStringTip(STR_STATION_BUILD_ORIENTATION), SetFill(1, 0),
398 NWidget(WWT_PANEL, Colours::Grey, WID_BO_OBJECT_SPRITE), SetToolTip(STR_OBJECT_BUILD_PREVIEW_TOOLTIP), EndContainer(),
399 EndContainer(),
400 EndContainer(),
403 EndContainer(),
404 EndContainer(),
405 EndContainer(),
407 EndContainer(),
408};
409
412 WindowPosition::Automatic, "build_object", 0, 0,
413 WindowClass::BuildObject, WindowClass::BuildToolbar,
415 _nested_build_object_widgets,
416 &BuildObjectWindow::hotkeys
417);
418
424{
425 /* Don't show the place object button when there are no objects to place. */
426 if (ObjectPickerCallbacks::instance.IsActive()) {
428 }
429 return nullptr;
430}
431
434{
435 _object_gui.sel_class = ObjectClassID::Begin();
436}
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.
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.
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:2029
const Tspec * GetSpec(uint index) const
Get a spec from the class at a given index.
static std::span< NewGRFClass< ObjectSpec, ObjectClassID > const > Classes()
static NewGRFClass * Get(ObjectClassID class_index)
std::span< const BadgeID > GetTypeBadges(int cls_id, int id) const override
Get the item's badges 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.
GrfSpecFeature GetFeature() const override
NewGRF feature this picker is for.
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 name of a type.
void FillUsedItems(std::set< PickerItem > &items) override
Fill a set with all items that are used by the current player.
ObjectClass::index_type GetClassIndex(int cls_id) const
Definition picker_gui.h:242
const ObjectClass * GetClass(int cls_id) const
Definition picker_gui.h:249
PickerItem GetPickerItem(const typename ObjectClass::spec_type *spec, int cls_id=-1, int id=-1) const
Definition picker_gui.h:271
PickerCallbacksNewGRFClass(const std::string &ini_group)
Definition picker_gui.h:235
const ObjectClass::spec_type * GetSpec(int cls_id, int id) const
Definition picker_gui.h:257
static constexpr int PREVIEW_WIDTH
Width of each preview button.
Definition picker_gui.h:339
bool has_class_picker
Set if this window has a class picker 'component'.
Definition picker_gui.h:349
static constexpr int PREVIEW_HEIGHT
Height of each preview button.
Definition picker_gui.h:340
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
@ Position
Update scroll positions.
Definition picker_gui.h:329
static constexpr int PREVIEW_LEFT
Offset from left edge to draw preview.
Definition picker_gui.h:341
static constexpr int PREVIEW_BOTTOM
Offset from bottom edge to draw preview.
Definition picker_gui.h:342
@ PCWHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
Definition picker_gui.h:373
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.
EnumBitSet< PickerInvalidation, uint8_t > PickerInvalidations
Bitset of Pickerinvalidation elements.
Definition picker_gui.h:335
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
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:94
Functions related to commands.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
@ Centre
Align to the centre.
@ Middle
Align to the middle.
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition gfx.cpp:782
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:1567
bool IsCtrlPressed()
Test if the ctrl key is pressed.
Definition gfx_func.h:82
@ Invalid
Invalid marker.
Definition gfx_type.h:302
@ Grey
Grey.
Definition gfx_type.h:299
@ DarkGreen
Dark green.
Definition gfx_type.h:292
@ Orange
Orange colour.
Definition gfx_type.h:324
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(Alignment 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.
static const CursorID SPR_CURSOR_TRANSMITTER
Definition sprites.h:1584
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
Definition window.cpp:1013
Hotkey related functions.
#define Point
Macro that prevents name conflicts between included headers.
Base for the NewGRF implementation.
GrfSpecFeature
Definition newgrf.h:81
@ Objects
Objects feature.
Definition newgrf.h:97
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(GrfID 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,...
PoolID< uint16_t, struct ObjectClassIDTag, UINT16_MAX, UINT16_MAX > ObjectClassID
Class IDs for objects.
NewGRFClass< ObjectSpec, ObjectClassID > ObjectClass
Class containing information relating to object classes.
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.
StrongType::Typedef< uint32_t, struct GRFStringIDTag, StrongType::Compare, StrongType::Integer > GRFStringID
Type for GRF-internal string IDs.
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 WindowDesc _build_object_desc(WindowPosition::Automatic, "build_object", 0, 0, WindowClass::BuildObject, WindowClass::BuildToolbar, WindowDefaultFlag::Construction, _nested_build_object_widgets, &BuildObjectWindow::hotkeys)
Window definition for the build object window.
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.
@ Menu
In the main menu.
Definition openttd.h:19
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:252
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:146
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:423
Functions related to OTTD's strings.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
static constexpr 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.
value_type height
The height of the rectangle.
value_type width
The width of the rectangle.
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:76
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:55
GrfID grfid
grfid that introduced this entity.
const struct GRFFile * grffile
grf file that introduced this entity
uint16_t local_id
id defined by the grf file for this entity
bool HasGrfFile() const
Test if this entity was introduced by NewGRF.
List of hotkeys for a window.
Definition hotkeys.h:44
All data for a single hotkey.
Definition hotkeys.h:20
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.
An object that isn't use for transport, industries or houses.
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< Object > Iterate(size_t from=0)
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:171
Number to differentiate different windows of the same class.
Data structure for an opened window.
Definition window_gui.h:272
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:1025
ResizeInfo resize
Resize information.
Definition window_gui.h:313
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1879
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition window.cpp:579
Command definitions related to terraforming.
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition tile_map.h:178
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
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)
Prepare state for highlighting tiles while dragging 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
Functions, definitions and such used only by the GUI.
@ Construction
This window is used for construction; close it whenever changing company.
Definition window_gui.h:154
Twindow * AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
Open a new window.
@ Automatic
Find a place automatically.
Definition window_gui.h:145
int WidgetID
Widget ID.
Definition window_type.h:21
EventState
State of handling an event.
@ NotHandled
The passed event is not handled.
Functions related to zooming.
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition zoom_func.h:107