OpenTTD Source 20250218-master-g53dd1258a7
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_badge.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
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; }
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 == INVALID_OBJECT_CLASS || !spec->IsEverAvailable()) continue;
114 items.insert(GetPickerItem(spec));
115 }
116 }
117
118 static ObjectPickerCallbacks instance;
119};
120/* static */ ObjectPickerCallbacks ObjectPickerCallbacks::instance;
121
125
126public:
128 {
130 this->ConstructWindow();
131 }
132
133 void SetStringParameters(WidgetID widget) const override
134 {
135 switch (widget) {
136 case WID_BO_OBJECT_SIZE: {
138 const ObjectSpec *spec = objclass->GetSpec(_object_gui.sel_type);
139 int size = spec == nullptr ? 0 : spec->size;
140 SetDParam(0, GB(size, HasBit(_object_gui.sel_view, 0) ? 4 : 0, 4));
141 SetDParam(1, GB(size, HasBit(_object_gui.sel_view, 0) ? 0 : 4, 4));
142 break;
143 }
144
145 default:
147 break;
148 }
149 }
150
151 void OnInit() override
152 {
154 this->PickerWindow::OnInit();
155 }
156
158 {
159 switch (widget) {
161 /* We do not want the window to resize when selecting objects; better clip texts */
162 size.width = 0;
163 break;
164
166 /* Get the right amount of buttons based on the current spec. */
168 const ObjectSpec *spec = objclass->GetSpec(_object_gui.sel_type);
169 if (spec != nullptr) {
170 if (spec->views >= 2) size.width += resize.width;
171 if (spec->views >= 4) size.height += resize.height;
172 }
173 resize.width = 0;
174 resize.height = 0;
175 break;
176 }
177
179 /* Get the right amount of buttons based on the current spec. */
181 const ObjectSpec *spec = objclass->GetSpec(_object_gui.sel_type);
184 if (spec != nullptr) {
185 if (spec->views <= 1) size.width = size.width * 2 + WidgetDimensions::scaled.hsep_normal;
186 if (spec->views <= 2) size.height = size.height * 2 + WidgetDimensions::scaled.vsep_normal;
187 }
188 break;
189 }
190
191 case WID_BO_INFO:
192 size.height = this->info_height;
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
212 /* Set up a clipping area for the preview. */
216 int x = (ir.Width() - ScaleSpriteTrad(PREVIEW_WIDTH)) / 2 + ScaleSpriteTrad(PREVIEW_LEFT);
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 tr.bottom = INT16_MAX;
238 tr.top = DrawBadgeNameList(tr, spec->badges, GSF_OBJECTS);
239
240 /* Get the extra message for the GUI */
243 if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
244 if (callback_res > 0x400) {
246 } else {
248 if (message != STR_NULL && message != STR_UNDEFINED) {
250 /* Use all the available space left from where we stand up to the
251 * end of the window. We ALSO enlarge the window if needed, so we
252 * can 'go' wild with the bottom of the window. */
253 tr.top = DrawStringMultiLine(tr, message, TC_ORANGE);
255 }
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 {
304
305 if (!gui_scope) return;
306
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);
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<CMD_BUILD_OBJECT>::Post(STR_ERROR_CAN_T_BUILD_OBJECT, CcPlaySound_CONSTRUCTION_OTHER, tile, spec->Index(), _object_gui.sel_view);
341 }
342 }
343
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 /* When end_tile is MP_VOID, the error tile will not be visible to the
357 * user. This happens when terraforming at the southern border. */
358 if (TileX(end_tile) == Map::MaxX()) end_tile += TileDiffXY(-1, 0);
359 if (TileY(end_tile) == Map::MaxY()) end_tile += TileDiffXY(0, -1);
360 }
363 end_tile, start_tile, spec->Index(), _object_gui.sel_view, (_ctrl_pressed ? true : false));
364 }
365
366 void OnPlaceObjectAbort() override
367 {
368 this->UpdateButtons(nullptr);
369 }
370
377 {
378 if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
380 if (w == nullptr) return ES_NOT_HANDLED;
381 return w->OnHotkey(hotkey);
382 }
383
384 static inline HotkeyList hotkeys{"buildobject", {
385 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
387};
388
389static constexpr NWidgetPart _nested_build_object_widgets[] = {
391 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
392 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetStringTip(STR_OBJECT_BUILD_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
393 NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
394 NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
395 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
396 EndContainer(),
400 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
402 NWidget(WWT_LABEL, INVALID_COLOUR), SetStringTip(STR_STATION_BUILD_ORIENTATION), SetFill(1, 0),
404 NWidget(NWID_MATRIX, COLOUR_DARK_GREEN, WID_BO_OBJECT_MATRIX), SetPIP(0, 2, 0),
405 NWidget(WWT_PANEL, COLOUR_GREY, WID_BO_OBJECT_SPRITE), SetToolTip(STR_OBJECT_BUILD_PREVIEW_TOOLTIP), EndContainer(),
406 EndContainer(),
407 EndContainer(),
408 NWidget(WWT_TEXT, INVALID_COLOUR, WID_BO_OBJECT_SIZE), SetStringTip(STR_OBJECT_BUILD_SIZE), SetAlignment(SA_CENTER),
409 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BO_INFO), SetFill(1, 0), SetResize(1, 0),
410 EndContainer(),
411 EndContainer(),
412 EndContainer(),
414 EndContainer(),
415};
416
417static WindowDesc _build_object_desc(
418 WDP_AUTO, "build_object", 0, 0,
421 _nested_build_object_widgets,
422 &BuildObjectWindow::hotkeys
423);
424
427{
428 /* Don't show the place object button when there are no objects to place. */
429 if (ObjectPickerCallbacks::instance.IsActive()) {
430 return AllocateWindowDescFront<BuildObjectWindow>(_build_object_desc, 0);
431 }
432 return nullptr;
433}
434
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
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.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
The window used for building objects.
void SetStringParameters(WidgetID widget) const override
Initialize string parameters for a widget.
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.
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:2009
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.
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:104
static const int PREVIEW_LEFT
Offset from left edge to draw preview.
Definition picker_gui.h:173
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
@ Position
Update scroll positions.
@ PCWHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
Definition picker_gui.h:193
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
static const int PREVIEW_WIDTH
Width of each preview button.
Definition picker_gui.h:171
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
static const int PREVIEW_BOTTOM
Offset from bottom edge to draw preview.
Definition picker_gui.h:174
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 const int PREVIEW_HEIGHT
Height of each preview button.
Definition picker_gui.h:172
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:28
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:94
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:774
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
Center both horizontally and vertically.
Definition gfx_type.h:385
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 NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
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 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:937
Hotkey related functions.
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition map_func.h:388
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:424
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:414
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.
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, 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.
void StartTextRefStackUsage(const GRFFile *grffile, uint8_t numEntries, const uint32_t *values)
Start using the TTDP compatible string code parsing.
StringID GetGRFStringID(uint32_t grfid, GRFStringID stringid)
Returns the index for this stringid associated with its grfID.
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
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.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:58
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:57
Functions related to sound.
@ SND_15_BEEP
19 == 0x13 GUI button click
Definition sound_type.h:66
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.
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:163
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...
SoundSettings sound
sound effect settings
bool freeform_edges
allow terraforming the tiles at the map edges
Dimensions (a width and height) of a rectangle in 2D.
Data about how and where to blit pixels.
Definition gfx_type.h:156
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:61
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:46
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.
ConstructionSettings construction
construction of things in-game
List of hotkeys for a window.
Definition hotkeys.h:37
All data for a single hotkey.
Definition hotkeys.h:21
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition map_func.h:305
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition map_func.h:296
Partial widget specification to allow NWidgets to be written nested.
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.
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.
FixedGRFFileProps< 2 > grf_prop
Properties related the the grf file.
uint8_t views
The number of views.
An object, such as transmitter, on the map.
Definition object_base.h:23
Coordinates of a point in 2D.
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.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
bool click_beep
Beep on a random selection of buttons.
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:272
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:949
virtual void SetStringParameters(WidgetID widget) const
Initialize string parameters for a widget.
Definition window_gui.h:625
ResizeInfo resize
Resize information.
Definition window_gui.h:313
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:969
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition window.cpp:562
virtual void OnInit()
Notification that the nested widget tree gets initialized.
Definition window_gui.h:575
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:95
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:35
@ 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:41
@ 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:39
@ 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:145
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:75
Functions related to zooming.
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition zoom_func.h:107