OpenTTD Source: src/object_gui.cpp Source File

OpenTTD Source 15.0-RC2

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
32#include "widgets/object_widget.h"
33
34#include "table/strings.h"
35
36#include "safeguards.h"
37
38 struct ObjectPickerSelection {
39 ObjectClassID sel_class;
40 uint16_t sel_type;
41 uint8_t sel_view;
42};
43 static ObjectPickerSelection _object_gui;
44
45 class ObjectPickerCallbacks : public PickerCallbacksNewGRFClass<ObjectClass> {
46public:
47 ObjectPickerCallbacks() : PickerCallbacksNewGRFClass<ObjectClass>("fav_objects") {}
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
123 class BuildObjectWindow : public PickerWindow {
124 int info_height = 1;
125
126public:
127 BuildObjectWindow(WindowDesc &desc, WindowNumber) : PickerWindow(desc, nullptr, 0, ObjectPickerCallbacks::instance)
128 {
129 ResetObjectToPlace();
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 {
150 this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->SetCount(4);
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) {
157 case WID_BO_OBJECT_SIZE:
158 /* We do not want the window to resize when selecting objects; better clip texts */
159 size.width = 0;
160 break;
161
162 case WID_BO_OBJECT_MATRIX: {
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
175 case WID_BO_OBJECT_SPRITE: {
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) {
203 case WID_BO_OBJECT_SPRITE: {
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. */
212 Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
213 if (FillDrawPixelInfo(&tmp_dpi, ir)) {
214 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
215 int x = (ir.Width() - ScaleSpriteTrad(PREVIEW_WIDTH)) / 2 + ScaleSpriteTrad(PREVIEW_LEFT);
216 int y = (ir.Height() + ScaleSpriteTrad(PREVIEW_HEIGHT)) / 2 - ScaleSpriteTrad(PREVIEW_BOTTOM);
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, GSF_OBJECTS);
239
240 /* Get the extra message for the GUI */
241 if (spec->callback_mask.Test(ObjectCallbackMask::FundMoreText)) {
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) {
249 ErrorUnknownCallbackResult(spec->grf_prop.grfid, CBID_OBJECT_FUND_MORE_TEXT, callback_res);
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, TC_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);
278 ResetObjectToPlace();
279 } else {
280 _object_gui.sel_view = std::min<int>(_object_gui.sel_view, spec->views - 1);
281 SetObjectToPlaceWnd(SPR_CURSOR_TRANSMITTER, PAL_NONE, HT_RECT | HT_DIAGONAL, this);
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);
307 if (pi.Test(PickerInvalidation::Position)) {
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) {
318 case WID_BO_OBJECT_SPRITE:
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) {
337 VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_BUILD_OBJECT);
338 } else {
339 Command<CMD_BUILD_OBJECT>::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 if (!_settings_game.construction.freeform_edges) {
355 /* When end_tile is MP_VOID, the error tile will not be visible to the
356 * user. This happens when terraforming at the southern border. */
357 if (TileX(end_tile) == Map::MaxX()) end_tile += TileDiffXY(-1, 0);
358 if (TileY(end_tile) == Map::MaxY()) end_tile += TileDiffXY(0, -1);
359 }
360 const ObjectSpec *spec = ObjectClass::Get(_object_gui.sel_class)->GetSpec(_object_gui.sel_type);
361 Command<CMD_BUILD_OBJECT_AREA>::Post(STR_ERROR_CAN_T_BUILD_OBJECT, CcPlaySound_CONSTRUCTION_OTHER,
362 end_tile, start_tile, spec->Index(), _object_gui.sel_view, (_ctrl_pressed ? true : false));
363 }
364
365 void OnPlaceObjectAbort() override
366 {
367 this->UpdateButtons(nullptr);
368 }
369
375 static EventState BuildObjectGlobalHotkeys(int hotkey)
376 {
377 if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
378 Window *w = ShowBuildObjectPicker();
379 if (w == nullptr) return ES_NOT_HANDLED;
380 return w->OnHotkey(hotkey);
381 }
382
383 static inline HotkeyList hotkeys{"buildobject", {
384 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
385 }, BuildObjectGlobalHotkeys};
386};
387
388static constexpr std::initializer_list<NWidgetPart> _nested_build_object_widgets = {
389 NWidget(NWID_HORIZONTAL),
390 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
391 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetStringTip(STR_OBJECT_BUILD_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
392 NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
393 NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
394 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
395 EndContainer(),
396 NWidget(NWID_HORIZONTAL),
397 NWidget(NWID_VERTICAL),
398 NWidgetFunction(MakePickerClassWidgets),
399 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
400 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_picker, 0), SetPadding(WidgetDimensions::unscaled.picker),
401 NWidget(WWT_LABEL, INVALID_COLOUR), SetStringTip(STR_STATION_BUILD_ORIENTATION), SetFill(1, 0),
402 NWidget(NWID_HORIZONTAL), SetPIPRatio(1, 0, 1),
403 NWidget(NWID_MATRIX, COLOUR_DARK_GREEN, WID_BO_OBJECT_MATRIX), SetPIP(0, 2, 0),
404 NWidget(WWT_PANEL, COLOUR_GREY, WID_BO_OBJECT_SPRITE), SetToolTip(STR_OBJECT_BUILD_PREVIEW_TOOLTIP), EndContainer(),
405 EndContainer(),
406 EndContainer(),
407 NWidget(WWT_TEXT, INVALID_COLOUR, WID_BO_OBJECT_SIZE), SetAlignment(SA_CENTER),
408 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BO_INFO), SetFill(1, 0), SetResize(1, 0),
409 EndContainer(),
410 EndContainer(),
411 EndContainer(),
412 NWidgetFunction(MakePickerTypeWidgets),
413 EndContainer(),
414};
415
416static WindowDesc _build_object_desc(
417 WDP_AUTO, "build_object", 0, 0,
418 WC_BUILD_OBJECT, WC_BUILD_TOOLBAR,
419 WindowDefaultFlag::Construction,
420 _nested_build_object_widgets,
421 &BuildObjectWindow::hotkeys
422);
423
425 Window *ShowBuildObjectPicker()
426{
427 /* Don't show the place object button when there are no objects to place. */
428 if (ObjectPickerCallbacks::instance.IsActive()) {
429 return AllocateWindowDescFront<BuildObjectWindow>(_build_object_desc, 0);
430 }
431 return nullptr;
432}
433
435 void InitializeObjectGui()
436{
437 _object_gui.sel_class = ObjectClassID::OBJECT_CLASS_BEGIN;
438}
GB
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
HasBit
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
BuildObjectWindow
The window used for building objects.
Definition object_gui.cpp:123
BuildObjectWindow::info_height
int info_height
The height of the info box.
Definition object_gui.cpp:124
BuildObjectWindow::BuildObjectGlobalHotkeys
static EventState BuildObjectGlobalHotkeys(int hotkey)
Handler for global hotkeys of the BuildObjectWindow.
Definition object_gui.cpp:375
BuildObjectWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition object_gui.cpp:200
BuildObjectWindow::OnPlaceObjectAbort
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition object_gui.cpp:365
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:315
BuildObjectWindow::GetWidgetString
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition object_gui.cpp:133
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:343
BuildObjectWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition object_gui.cpp:300
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:332
BuildObjectWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition object_gui.cpp:148
BuildObjectWindow::UpdateButtons
void UpdateButtons(const ObjectSpec *spec)
Update buttons to show the selection to the user.
Definition object_gui.cpp:293
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:154
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:348
EnumBitSet
Enum-as-bit-set wrapper.
Definition enum_type.hpp:177
NWidgetBase::GetParentWidget
NWID * GetParentWidget()
Get parent widget of type NWID.
Definition widget_type.h:157
NWidgetMatrix
Matrix container with implicitly equal sized (virtual) sub-widgets.
Definition widget_type.h:614
NWidgetMatrix::GetCurrentElement
int GetCurrentElement() const
Get current element.
Definition widget.cpp:1979
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:45
ObjectPickerCallbacks::GetTypeBadges
std::span< const BadgeID > GetTypeBadges(int cls_id, int id) const override
Get the item of a type.
Definition object_gui.cpp:83
ObjectPickerCallbacks::GetClassName
StringID GetClassName(int id) const override
Get the name of a class.
Definition object_gui.cpp:67
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:96
ObjectPickerCallbacks::SetSelectedClass
void SetSelectedClass(int id) const override
Set the selected class.
Definition object_gui.cpp:65
ObjectPickerCallbacks::GetTypeTooltip
StringID GetTypeTooltip() const override
Get the tooltip string for the type grid.
Definition object_gui.cpp:52
ObjectPickerCallbacks::IsActive
bool IsActive() const override
Should picker class/type selection be enabled?
Definition object_gui.cpp:54
ObjectPickerCallbacks::GetClassTooltip
StringID GetClassTooltip() const override
Get the tooltip string for the class list.
Definition object_gui.cpp:51
ObjectPickerCallbacks::IsTypeAvailable
bool IsTypeAvailable(int cls_id, int id) const override
Test if an item is currently buildable.
Definition object_gui.cpp:90
ObjectPickerCallbacks::GetSelectedType
int GetSelectedType() const override
Get the selected type.
Definition object_gui.cpp:74
ObjectPickerCallbacks::SetSelectedType
void SetSelectedType(int id) const override
Set the selected type.
Definition object_gui.cpp:75
ObjectPickerCallbacks::GetSelectedClass
int GetSelectedClass() const override
Get the index of the selected class.
Definition object_gui.cpp:64
ObjectPickerCallbacks::GetTypeName
StringID GetTypeName(int cls_id, int id) const override
Get the item of a type.
Definition object_gui.cpp:77
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:108
PickerCallbacksNewGRFClass
Helper for PickerCallbacks when the class system is based on NewGRFClass.
Definition picker_gui.h:107
PickerWindow
Definition picker_gui.h:157
PickerWindow::PREVIEW_WIDTH
static constexpr int PREVIEW_WIDTH
Width of each preview button.
Definition picker_gui.h:176
PickerWindow::has_class_picker
bool has_class_picker
Set if this window has a class picker 'component'.
Definition picker_gui.h:186
PickerWindow::PREVIEW_HEIGHT
static constexpr int PREVIEW_HEIGHT
Height of each preview button.
Definition picker_gui.h:177
PickerWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition picker_gui.cpp:308
PickerWindow::PickerInvalidation::Position
@ Position
Update scroll positions.
PickerWindow::PREVIEW_LEFT
static constexpr int PREVIEW_LEFT
Offset from left edge to draw preview.
Definition picker_gui.h:178
PickerWindow::PREVIEW_BOTTOM
static constexpr int PREVIEW_BOTTOM
Offset from bottom edge to draw preview.
Definition picker_gui.h:179
PickerWindow::PCWHK_FOCUS_FILTER_BOX
@ PCWHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
Definition picker_gui.h:205
PickerWindow::GetWidgetString
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition picker_gui.cpp:299
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:373
PickerWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition picker_gui.cpp:490
PickerWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition picker_gui.cpp:251
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:266
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition window_gui.h:58
WidgetDimensions::fullbevel
RectPadding fullbevel
Always-scaled bevel thickness.
Definition window_gui.h:39
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:93
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition window_gui.h:61
command_func.h
Functions related to commands.
_current_company
CompanyID _current_company
Company currently doing an action.
Definition company_cmd.cpp:56
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:782
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:1565
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition gfx_type.h:398
NWidgetFunction
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition widget_type.h:1445
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1219
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:1375
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:1332
SetStringTip
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
Definition widget_type.h:1240
SetToolTip
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
Definition widget_type.h:1318
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1229
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1424
SetAlignment
constexpr NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
Definition widget_type.h:1208
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1145
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:1387
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:966
hotkeys.h
Hotkey related functions.
TileDiffXY
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition map_func.h:401
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:437
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:427
newgrf.h
Base for the NewGRF implementation.
GrfSpecFeature
GrfSpecFeature
Definition newgrf.h:68
newgrf_badge_gui.h
GUI functions related to NewGRF badges.
CBID_OBJECT_FUND_MORE_TEXT
@ CBID_OBJECT_FUND_MORE_TEXT
Called to determine more text in the fund object window.
Definition newgrf_callbacks.h:271
ObjectCallbackMask::FundMoreText
@ FundMoreText
additional text in fund window
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition newgrf_callbacks.h:439
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:517
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:492
GetObjectCallback
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.
Definition newgrf_object.cpp:435
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
GetGRFStringWithTextStack
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.
Definition newgrf_text.cpp:999
newgrf_text.h
Header of Action 04 "universal holder" structure and functions.
GRFSTR_MISC_GRF_TEXT
static constexpr GRFStringID GRFSTR_MISC_GRF_TEXT
Miscellaneous GRF text range.
Definition newgrf_text_type.h:18
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:425
InitializeObjectGui
void InitializeObjectGui()
Reset all data of the object GUI.
Definition object_gui.cpp:435
_object_gui
static ObjectPickerSelection _object_gui
Settings of the object picker.
Definition object_gui.cpp:43
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:743
MakePickerTypeWidgets
std::unique_ptr< NWidgetBase > MakePickerTypeWidgets()
Create nested widgets for the type picker widgets.
Definition picker_gui.cpp:766
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:61
SndClickBeep
void SndClickBeep()
Play a beep sound for a click event if enabled in settings.
Definition sound.cpp:253
sound_func.h
Functions related to sound.
DrawOrigTileSeqInGUI
void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
Draw TTD sprite sequence in GUI.
Definition sprite.h:121
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
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:19
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:20
AutoRestoreBackup
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Definition backup_type.hpp:150
CommandHelper
Definition command_func.h:83
ConstructionSettings::freeform_edges
bool freeform_edges
allow terraforming the tiles at the map edges
Definition settings_type.h:423
Coord2D< int >
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:56
DrawPixelInfo
Data about how and where to blit pixels.
Definition gfx_type.h:157
DrawTileSpriteSpan
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:67
DrawTileSprites
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:52
GRFFilePropsBase::grffile
const struct GRFFile * grffile
grf file that introduced this entity
Definition newgrf_commons.h:318
GRFFilePropsBase::local_id
uint16_t local_id
id defined by the grf file for this entity
Definition newgrf_commons.h:316
GRFFilePropsBase::grfid
uint32_t grfid
grfid that introduced this entity.
Definition newgrf_commons.h:317
GRFFilePropsBase::HasGrfFile
bool HasGrfFile() const
Test if this entity was introduced by NewGRF.
Definition newgrf_commons.h:326
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition settings_type.h:635
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:308
Map::MaxX
static uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition map_func.h:299
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:38
ObjectPickerSelection::sel_view
uint8_t sel_view
Selected view of the object.
Definition object_gui.cpp:41
ObjectPickerSelection::sel_class
ObjectClassID sel_class
Selected object class.
Definition object_gui.cpp:39
ObjectPickerSelection::sel_type
uint16_t sel_type
Selected object type within the class.
Definition object_gui.cpp:40
ObjectSpec
Allow incrementing of ObjectClassID variables.
Definition newgrf_object.h:60
ObjectSpec::grf_prop
StandardGRFFileProps grf_prop
Properties related the the grf file.
Definition newgrf_object.h:61
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:78
ObjectSpec::Get
static const ObjectSpec * Get(ObjectType index)
Get the specification associated with a specific ObjectType.
Definition newgrf_object.cpp:54
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:107
ObjectSpec::callback_mask
ObjectCallbackMasks callback_mask
Bitmask of requested/allowed callbacks.
Definition newgrf_object.h:73
ObjectSpec::views
uint8_t views
The number of views.
Definition newgrf_object.h:75
Object
An object, such as transmitter, on the map.
Definition object_base.h:23
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:436
RectPadding::Horizontal
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition geometry_type.hpp:89
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition geometry_type.hpp:95
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:101
Rect::Width
int Width() const
Get width of Rect.
Definition geometry_type.hpp:111
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition geometry_type.hpp:124
Rect::Height
int Height() const
Get height of Rect.
Definition geometry_type.hpp:117
StrongType::Typedef< uint32_t, struct GRFStringIDTag, StrongType::Compare, StrongType::Integer >
WindowDesc
High level window description.
Definition window_gui.h:168
WindowNumber
Number to differentiate different windows of the same class.
Definition window_type.h:760
Window
Data structure for an opened window.
Definition window_gui.h:274
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:978
Window::resize
ResizeInfo resize
Resize information.
Definition window_gui.h:315
Window::OnHotkey
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition window.cpp:570
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:3573
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:3510
VpSelectTilesWithMethod
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
Definition viewport.cpp:3291
VpStartPlaceSizing
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
highlighting tiles while only going over them with the mouse
Definition viewport.cpp:2798
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:2619
viewport_func.h
Functions related to (drawing on) viewports.
ViewportPlaceMethod
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
Definition viewport_type.h:96
VPM_X_AND_Y
@ VPM_X_AND_Y
area of land in X and Y directions
Definition viewport_type.h:100
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:115
DDSP_BUILD_OBJECT
@ DDSP_BUILD_OBJECT
Build an object.
Definition viewport_type.h:126
ScaleGUITrad
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition widget.cpp:49
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition widget_type.h:48
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:57
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:55
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:52
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:60
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:37
WWT_DEFSIZEBOX
@ 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
@ NWID_MATRIX
Matrix container.
Definition widget_type.h:69
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:49
window_func.h
Window functions not directly related to making/drawing windows.
window_gui.h
Functions, definitions and such used only by the GUI.
WindowDefaultFlag::Construction
@ Construction
This window is used for construction; close it whenever changing company.
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:144
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:20
EventState
EventState
State of handling an event.
Definition window_type.h:780
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition window_type.h:782
WC_BUILD_OBJECT
@ WC_BUILD_OBJECT
Build object; Window numbers:
Definition window_type.h:381
WC_BUILD_TOOLBAR
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
Definition window_type.h:78
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