OpenTTD Source: src/newgrf_debug_gui.cpp Source File

OpenTTD Source 15.0-RC2

newgrf_debug_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 "core/backup_type.hpp"
12#include "core/geometry_func.hpp"
13#include "window_gui.h"
14#include "window_func.h"
15#include "random_access_file_type.h"
16#include "spritecache.h"
17#include "string_func.h"
18#include "strings_func.h"
19#include "textbuf_gui.h"
20#include "vehicle_gui.h"
21#include "zoom_func.h"
22#include "core/string_consumer.hpp"
23
24#include "engine_base.h"
25#include "industry.h"
26#include "object_base.h"
27#include "station_base.h"
28#include "town.h"
29#include "vehicle_base.h"
30#include "train.h"
31#include "roadveh.h"
32
33#include "newgrf_act5.h"
34#include "newgrf_airport.h"
35#include "newgrf_airporttiles.h"
36#include "newgrf_badge.h"
37#include "newgrf_debug.h"
38#include "newgrf_object.h"
39#include "newgrf_spritegroup.h"
40#include "newgrf_station.h"
41#include "newgrf_town.h"
42#include "newgrf_railtype.h"
43#include "newgrf_industries.h"
44#include "newgrf_industrytiles.h"
45
46#include "widgets/newgrf_debug_widget.h"
47
48#include "table/strings.h"
49
50#include "safeguards.h"
51
53 NewGrfDebugSpritePicker _newgrf_debug_sprite_picker = { SPM_NONE, nullptr, {} };
54
60 static inline uint GetFeatureIndex(uint window_number)
61{
62 return GB(window_number, 0, 24);
63}
64
72 static inline uint GetInspectWindowNumber(GrfSpecFeature feature, uint index)
73{
74 assert((index >> 24) == 0);
75 return (feature << 24) | index;
76}
77
78static inline uint GetInspectWindowNumber(GrfSpecFeature feature, ConvertibleThroughBase auto index) { return GetInspectWindowNumber(feature, index.base()); }
79
84 enum NIType : uint8_t {
85 NIT_INT,
86 NIT_CARGO,
87};
88
89using NIReadProc = uint32_t(const void *b);
90
92 struct NIProperty {
93 std::string_view name;
94 NIReadProc *read_proc;
95 uint8_t prop;
96 uint8_t type;
97};
98
99
104 struct NICallback {
105 std::string_view name;
106 NIReadProc *read_proc;
107 std::variant<
108 std::monostate,
109 VehicleCallbackMask,
110 StationCallbackMask,
111 RoadStopCallbackMask,
112 HouseCallbackMask,
113 CanalCallbackMask,
114 CargoCallbackMask,
115 IndustryCallbackMask,
116 IndustryTileCallbackMask,
117 ObjectCallbackMask,
118 AirportTileCallbackMask> cb_bit;
119 uint16_t cb_id;
120};
121
123 struct NIVariable {
124 std::string_view name;
125 uint8_t var;
126};
127
129 class NIHelper {
130public:
132 virtual ~NIHelper() = default;
133
139 virtual bool IsInspectable(uint index) const = 0;
140
146 virtual uint GetParent(uint index) const = 0;
147
153 virtual const void *GetInstance(uint index) const = 0;
154
160 virtual const void *GetSpec(uint index) const = 0;
161
166 virtual std::string GetName(uint index) const = 0;
167
173 virtual uint32_t GetGRFID(uint index) const = 0;
174
180 virtual std::span<const BadgeID> GetBadges(uint index) const = 0;
181
190 virtual uint Resolve(uint index, uint var, uint param, bool &avail) const = 0;
191
196 virtual bool PSAWithParameter() const
197 {
198 return false;
199 }
200
207 virtual const std::span<int32_t> GetPSA([[maybe_unused]] uint index, [[maybe_unused]] uint32_t grfid) const
208 {
209 return {};
210 }
211};
212
213
215 struct NIFeature {
216 std::span<const NIProperty> properties;
217 std::span<const NICallback> callbacks;
218 std::span<const NIVariable> variables;
219 std::unique_ptr<const NIHelper> helper;
220};
221
222/* Load all the NewGRF debug data; externalised as it is just a huge bunch of tables. */
223#include "table/newgrf_debug_data.h"
224
230 static inline GrfSpecFeature GetFeatureNum(uint window_number)
231{
232 return (GrfSpecFeature)GB(window_number, 24, 8);
233}
234
240 static inline const NIFeature *GetFeature(uint window_number)
241{
242 GrfSpecFeature idx = GetFeatureNum(window_number);
243 return idx < GSF_FAKE_END ? _nifeatures[idx] : nullptr;
244}
245
252 static inline const NIHelper &GetFeatureHelper(uint window_number)
253{
254 return *GetFeature(window_number)->helper;
255}
256
258 struct NewGRFInspectWindow : Window {
260 static uint32_t var60params[GSF_FAKE_END][0x20];
261
263 uint32_t caller_grfid = 0;
264
266 uint chain_index = 0;
267
269 uint8_t current_edit_param = 0;
270
271 Scrollbar *vscroll = nullptr;
272
278 static bool HasVariableParameter(uint variable)
279 {
280 return IsInsideBS(variable, 0x60, 0x20);
281 }
282
287 void SetCallerGRFID(uint32_t grfid)
288 {
289 this->caller_grfid = grfid;
290 this->SetDirty();
291 }
292
296 bool HasChainIndex() const
297 {
298 GrfSpecFeature f = GetFeatureNum(this->window_number);
299 return f == GSF_TRAINS || f == GSF_ROADVEHICLES;
300 }
301
306 uint GetFeatureIndex() const
307 {
308 uint index = ::GetFeatureIndex(this->window_number);
309 if (this->chain_index > 0) {
310 assert(this->HasChainIndex());
311 const Vehicle *v = Vehicle::Get(index);
312 v = v->Move(this->chain_index);
313 if (v != nullptr) index = v->index.base();
314 }
315 return index;
316 }
317
321 void ValidateChainIndex()
322 {
323 if (this->chain_index == 0) return;
324
325 assert(this->HasChainIndex());
326
327 const Vehicle *v = Vehicle::Get(::GetFeatureIndex(this->window_number));
328 v = v->Move(this->chain_index);
329 if (v == nullptr) this->chain_index = 0;
330 }
331
332 NewGRFInspectWindow(WindowDesc &desc, WindowNumber wno) : Window(desc)
333 {
334 this->CreateNestedTree();
335 this->vscroll = this->GetScrollbar(WID_NGRFI_SCROLLBAR);
336 this->FinishInitNested(wno);
337
338 this->vscroll->SetCount(0);
339 this->SetWidgetDisabledState(WID_NGRFI_PARENT, GetFeatureHelper(this->window_number).GetParent(this->GetFeatureIndex()) == UINT32_MAX);
340
341 this->OnInvalidateData(0, true);
342 }
343
344 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
345 {
346 if (widget != WID_NGRFI_CAPTION) return this->Window::GetWidgetString(widget, stringid);
347
348 return GetFeatureHelper(this->window_number).GetName(this->GetFeatureIndex());
349 }
350
351 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
352 {
353 switch (widget) {
354 case WID_NGRFI_VEH_CHAIN: {
355 assert(this->HasChainIndex());
356 GrfSpecFeature f = GetFeatureNum(this->window_number);
357 size.height = std::max(size.height, GetVehicleImageCellSize((VehicleType)(VEH_TRAIN + (f - GSF_TRAINS)), EIT_IN_DEPOT).height + 2 + WidgetDimensions::scaled.bevel.Vertical());
358 break;
359 }
360
361 case WID_NGRFI_MAINPANEL:
362 fill.height = resize.height = std::max(11, GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal);
363 resize.width = 1;
364
365 size.height = 5 * resize.height + WidgetDimensions::scaled.frametext.Vertical();
366 break;
367 }
368 }
369
376 void DrawString(const Rect &r, int offset, const std::string &string) const
377 {
378 offset -= this->vscroll->GetPosition();
379 if (offset < 0 || offset >= this->vscroll->GetCapacity()) return;
380
381 ::DrawString(r.Shrink(WidgetDimensions::scaled.frametext).Shrink(0, offset * this->resize.step_height, 0, 0), string, TC_BLACK);
382 }
383
388 void DrawVehicleChainWidget(const Rect &r) const
389 {
390 const Vehicle *v = Vehicle::Get(this->GetFeatureIndex());
391 int total_width = 0;
392 int sel_start = 0;
393 int sel_end = 0;
394 for (const Vehicle *u = v->First(); u != nullptr; u = u->Next()) {
395 if (u == v) sel_start = total_width;
396 switch (u->type) {
397 case VEH_TRAIN: total_width += Train::From(u)->GetDisplayImageWidth(); break;
398 case VEH_ROAD: total_width += RoadVehicle::From(u)->GetDisplayImageWidth(); break;
399 default: NOT_REACHED();
400 }
401 if (u == v) sel_end = total_width;
402 }
403
404 Rect br = r.Shrink(WidgetDimensions::scaled.bevel);
405 int width = br.Width();
406 int skip = 0;
407 if (total_width > width) {
408 int sel_center = (sel_start + sel_end) / 2;
409 if (sel_center > width / 2) skip = std::min(total_width - width, sel_center - width / 2);
410 }
411
412 GrfSpecFeature f = GetFeatureNum(this->window_number);
413 int h = GetVehicleImageCellSize((VehicleType)(VEH_TRAIN + (f - GSF_TRAINS)), EIT_IN_DEPOT).height;
414 int y = CentreBounds(br.top, br.bottom, h);
415 DrawVehicleImage(v->First(), br, VehicleID::Invalid(), EIT_IN_DETAILS, skip);
416
417 /* Highlight the articulated part (this is different to the whole-vehicle highlighting of DrawVehicleImage */
418 if (_current_text_dir == TD_RTL) {
419 DrawFrameRect(r.right - sel_end + skip, y, r.right - sel_start + skip, y + h, COLOUR_WHITE, FrameFlag::BorderOnly);
420 } else {
421 DrawFrameRect(r.left + sel_start - skip, y, r.left + sel_end - skip, y + h, COLOUR_WHITE, FrameFlag::BorderOnly);
422 }
423 }
424
425 std::string GetPropertyString(const NIProperty &nip, uint value) const
426 {
427 switch (nip.type) {
428 case NIT_INT: return GetString(STR_JUST_INT, value);
429 case NIT_CARGO: return GetString(IsValidCargoType(value) ? CargoSpec::Get(value)->name : STR_QUANTITY_N_A);
430 default: NOT_REACHED();
431 }
432 }
433
438 void DrawMainPanelWidget(const Rect &r) const
439 {
440 uint index = this->GetFeatureIndex();
441 const NIFeature *nif = GetFeature(this->window_number);
442 const NIHelper &nih = *nif->helper;
443 const void *base = nih.GetInstance(index);
444 const void *base_spec = nih.GetSpec(index);
445
446 uint i = 0;
447 if (!nif->variables.empty()) {
448 this->DrawString(r, i++, "Variables:");
449 for (const NIVariable &niv : nif->variables) {
450 bool avail = true;
451 uint param = HasVariableParameter(niv.var) ? NewGRFInspectWindow::var60params[GetFeatureNum(this->window_number)][niv.var - 0x60] : 0;
452 uint value = nih.Resolve(index, niv.var, param, avail);
453
454 if (!avail) continue;
455
456 if (HasVariableParameter(niv.var)) {
457 this->DrawString(r, i++, fmt::format(" {:02x}[{:02x}]: {:08x} ({})", niv.var, param, value, niv.name));
458 } else {
459 this->DrawString(r, i++, fmt::format(" {:02x}: {:08x} ({})", niv.var, value, niv.name));
460 }
461 }
462 }
463
464 auto psa = nih.GetPSA(index, this->caller_grfid);
465 if (!psa.empty()) {
466 if (nih.PSAWithParameter()) {
467 this->DrawString(r, i++, fmt::format("Persistent storage [{:08X}]:", std::byteswap(this->caller_grfid)));
468 } else {
469 this->DrawString(r, i++, "Persistent storage:");
470 }
471 assert(psa.size() % 4 == 0);
472 for (size_t j = 0; j < psa.size(); j += 4) {
473 this->DrawString(r, i++, fmt::format(" {}: {} {} {} {}", j, psa[j], psa[j + 1], psa[j + 2], psa[j + 3]));
474 }
475 }
476
477 auto badges = nih.GetBadges(index);
478 if (!badges.empty()) {
479 this->DrawString(r, i++, "Badges:");
480 for (const BadgeID &badge_index : badges) {
481 const Badge *badge = GetBadge(badge_index);
482 this->DrawString(r, i++, fmt::format(" {}: {}", StrMakeValid(badge->label), GetString(badge->name)));
483 }
484 }
485
486 if (!nif->properties.empty()) {
487 this->DrawString(r, i++, "Properties:");
488 for (const NIProperty &nip : nif->properties) {
489 uint32_t value = nip.read_proc(base);
490 this->DrawString(r, i++, fmt::format(" {:02x}: {} ({})", nip.prop, this->GetPropertyString(nip, value), nip.name));
491 }
492 }
493
494 if (!nif->callbacks.empty()) {
495 this->DrawString(r, i++, "Callbacks:");
496 for (const NICallback &nic : nif->callbacks) {
497 if (!std::holds_alternative<std::monostate>(nic.cb_bit)) {
498 uint32_t value = nic.read_proc(base_spec);
499
500 struct visitor {
501 uint32_t value;
502
503 bool operator()(const std::monostate &) { return false; }
504 bool operator()(const VehicleCallbackMask &bit) { return static_cast<VehicleCallbackMasks>(this->value).Test(bit); }
505 bool operator()(const StationCallbackMask &bit) { return static_cast<StationCallbackMasks>(this->value).Test(bit); }
506 bool operator()(const RoadStopCallbackMask &bit) { return static_cast<RoadStopCallbackMasks>(this->value).Test(bit); }
507 bool operator()(const HouseCallbackMask &bit) { return static_cast<HouseCallbackMasks>(this->value).Test(bit); }
508 bool operator()(const CanalCallbackMask &bit) { return static_cast<CanalCallbackMasks>(this->value).Test(bit); }
509 bool operator()(const CargoCallbackMask &bit) { return static_cast<CargoCallbackMasks>(this->value).Test(bit); }
510 bool operator()(const IndustryCallbackMask &bit) { return static_cast<IndustryCallbackMasks>(this->value).Test(bit); }
511 bool operator()(const IndustryTileCallbackMask &bit) { return static_cast<IndustryTileCallbackMasks>(this->value).Test(bit); }
512 bool operator()(const ObjectCallbackMask &bit) { return static_cast<ObjectCallbackMasks>(this->value).Test(bit); }
513 bool operator()(const AirportTileCallbackMask &bit) { return static_cast<AirportTileCallbackMasks>(this->value).Test(bit); }
514 };
515
516 if (!std::visit(visitor{value}, nic.cb_bit)) continue;
517 this->DrawString(r, i++, fmt::format(" {:03x}: {}", nic.cb_id, nic.name));
518 } else {
519 this->DrawString(r, i++, fmt::format(" {:03x}: {} (unmasked)", nic.cb_id, nic.name));
520 }
521 }
522 }
523
524 /* Not nice and certainly a hack, but it beats duplicating
525 * this whole function just to count the actual number of
526 * elements. Especially because they need to be redrawn. */
527 const_cast<NewGRFInspectWindow*>(this)->vscroll->SetCount(i);
528 }
529
530 void DrawWidget(const Rect &r, WidgetID widget) const override
531 {
532 switch (widget) {
533 case WID_NGRFI_VEH_CHAIN:
534 this->DrawVehicleChainWidget(r);
535 break;
536
537 case WID_NGRFI_MAINPANEL:
538 this->DrawMainPanelWidget(r);
539 break;
540 }
541 }
542
543 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
544 {
545 switch (widget) {
546 case WID_NGRFI_PARENT: {
547 const NIHelper &nih = GetFeatureHelper(this->window_number);
548 uint index = nih.GetParent(this->GetFeatureIndex());
549 ::ShowNewGRFInspectWindow(GetFeatureNum(index), ::GetFeatureIndex(index), nih.GetGRFID(this->GetFeatureIndex()));
550 break;
551 }
552
553 case WID_NGRFI_VEH_PREV:
554 if (this->chain_index > 0) {
555 this->chain_index--;
556 this->InvalidateData();
557 }
558 break;
559
560 case WID_NGRFI_VEH_NEXT:
561 if (this->HasChainIndex()) {
562 uint index = this->GetFeatureIndex();
563 Vehicle *v = Vehicle::Get(index);
564 if (v != nullptr && v->Next() != nullptr) {
565 this->chain_index++;
566 this->InvalidateData();
567 }
568 }
569 break;
570
571 case WID_NGRFI_MAINPANEL: {
572 /* Does this feature have variables? */
573 const NIFeature *nif = GetFeature(this->window_number);
574 if (nif->variables.empty()) return;
575
576 /* Get the line, make sure it's within the boundaries. */
577 int32_t line = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NGRFI_MAINPANEL, WidgetDimensions::scaled.frametext.top);
578 if (line == INT32_MAX) return;
579
580 /* Find the variable related to the line */
581 for (const NIVariable &niv : nif->variables) {
582 if (--line != 0) continue; // 0 because of the "Variables:" line
583
584 if (!HasVariableParameter(niv.var)) break;
585
586 this->current_edit_param = niv.var;
587 ShowQueryString({}, STR_NEWGRF_INSPECT_QUERY_CAPTION, 9, this, CS_HEXADECIMAL, {});
588 }
589 }
590 }
591 }
592
593 void OnQueryTextFinished(std::optional<std::string> str) override
594 {
595 if (!str.has_value()) return;
596
597 auto val = ParseInteger<uint32_t>(*str, 16, true);
598 if (!val.has_value()) return;
599 NewGRFInspectWindow::var60params[GetFeatureNum(this->window_number)][this->current_edit_param - 0x60] = *val;
600 this->SetDirty();
601 }
602
603 void OnResize() override
604 {
605 this->vscroll->SetCapacityFromWidget(this, WID_NGRFI_MAINPANEL, WidgetDimensions::scaled.frametext.Vertical());
606 }
607
613 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
614 {
615 if (!gui_scope) return;
616 if (this->HasChainIndex()) {
617 this->ValidateChainIndex();
618 this->SetWidgetDisabledState(WID_NGRFI_VEH_PREV, this->chain_index == 0);
619 Vehicle *v = Vehicle::Get(this->GetFeatureIndex());
620 this->SetWidgetDisabledState(WID_NGRFI_VEH_NEXT, v == nullptr || v->Next() == nullptr);
621 }
622 }
623};
624
625/* static */ uint32_t NewGRFInspectWindow::var60params[GSF_FAKE_END][0x20] = { {0} }; // Use spec to have 0s in whole array
626
627static constexpr std::initializer_list<NWidgetPart> _nested_newgrf_inspect_chain_widgets = {
628 NWidget(NWID_HORIZONTAL),
629 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
630 NWidget(WWT_CAPTION, COLOUR_GREY, WID_NGRFI_CAPTION), SetStringTip(STR_NEWGRF_INSPECT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
631 NWidget(WWT_SHADEBOX, COLOUR_GREY),
632 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
633 NWidget(WWT_STICKYBOX, COLOUR_GREY),
634 EndContainer(),
635 NWidget(WWT_PANEL, COLOUR_GREY),
636 NWidget(NWID_HORIZONTAL),
637 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_NGRFI_VEH_PREV), SetArrowWidgetTypeTip(AWV_DECREASE),
638 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_NGRFI_VEH_NEXT), SetArrowWidgetTypeTip(AWV_INCREASE),
639 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_NGRFI_VEH_CHAIN), SetFill(1, 0), SetResize(1, 0),
640 EndContainer(),
641 EndContainer(),
642 NWidget(NWID_HORIZONTAL),
643 NWidget(WWT_PANEL, COLOUR_GREY, WID_NGRFI_MAINPANEL), SetMinimalSize(300, 0), SetScrollbar(WID_NGRFI_SCROLLBAR), EndContainer(),
644 NWidget(NWID_VERTICAL),
645 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_NGRFI_SCROLLBAR),
646 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
647 EndContainer(),
648 EndContainer(),
649};
650
651static constexpr std::initializer_list<NWidgetPart> _nested_newgrf_inspect_widgets = {
652 NWidget(NWID_HORIZONTAL),
653 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
654 NWidget(WWT_CAPTION, COLOUR_GREY, WID_NGRFI_CAPTION), SetStringTip(STR_NEWGRF_INSPECT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
655 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NGRFI_PARENT), SetStringTip(STR_NEWGRF_INSPECT_PARENT_BUTTON, STR_NEWGRF_INSPECT_PARENT_TOOLTIP),
656 NWidget(WWT_SHADEBOX, COLOUR_GREY),
657 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
658 NWidget(WWT_STICKYBOX, COLOUR_GREY),
659 EndContainer(),
660 NWidget(NWID_HORIZONTAL),
661 NWidget(WWT_PANEL, COLOUR_GREY, WID_NGRFI_MAINPANEL), SetMinimalSize(300, 0), SetScrollbar(WID_NGRFI_SCROLLBAR), EndContainer(),
662 NWidget(NWID_VERTICAL),
663 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_NGRFI_SCROLLBAR),
664 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
665 EndContainer(),
666 EndContainer(),
667};
668
669static WindowDesc _newgrf_inspect_chain_desc(
670 WDP_AUTO, "newgrf_inspect_chain", 400, 300,
671 WC_NEWGRF_INSPECT, WC_NONE,
672 {},
673 _nested_newgrf_inspect_chain_widgets
674);
675
676static WindowDesc _newgrf_inspect_desc(
677 WDP_AUTO, "newgrf_inspect", 400, 300,
678 WC_NEWGRF_INSPECT, WC_NONE,
679 {},
680 _nested_newgrf_inspect_widgets
681);
682
692 void ShowNewGRFInspectWindow(GrfSpecFeature feature, uint index, const uint32_t grfid)
693{
694 if (!IsNewGRFInspectable(feature, index)) return;
695
696 WindowNumber wno = GetInspectWindowNumber(feature, index);
697 WindowDesc &desc = (feature == GSF_TRAINS || feature == GSF_ROADVEHICLES) ? _newgrf_inspect_chain_desc : _newgrf_inspect_desc;
698 NewGRFInspectWindow *w = AllocateWindowDescFront<NewGRFInspectWindow, true>(desc, wno);
699 w->SetCallerGRFID(grfid);
700}
701
710 void InvalidateNewGRFInspectWindow(GrfSpecFeature feature, uint index)
711{
712 if (feature == GSF_INVALID) return;
713
714 WindowNumber wno = GetInspectWindowNumber(feature, index);
715 InvalidateWindowData(WC_NEWGRF_INSPECT, wno);
716}
717
726 void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
727{
728 if (feature == GSF_INVALID) return;
729
730 WindowNumber wno = GetInspectWindowNumber(feature, index);
731 CloseWindowById(WC_NEWGRF_INSPECT, wno);
732
733 /* Reinitialise the land information window to remove the "debug" sprite if needed.
734 * Note: Since we might be called from a command here, it is important to not execute
735 * the invalidation immediately. The landinfo window tests commands itself. */
736 InvalidateWindowData(WC_LAND_INFO, 0, 1);
737}
738
748 bool IsNewGRFInspectable(GrfSpecFeature feature, uint index)
749{
750 const NIFeature *nif = GetFeature(GetInspectWindowNumber(feature, index));
751 if (nif == nullptr) return false;
752 return nif->helper->IsInspectable(index);
753}
754
760 GrfSpecFeature GetGrfSpecFeature(TileIndex tile)
761{
762 switch (GetTileType(tile)) {
763 default: return GSF_INVALID;
764 case MP_RAILWAY: return GSF_RAILTYPES;
765 case MP_ROAD: return IsLevelCrossing(tile) ? GSF_RAILTYPES : GSF_ROADTYPES;
766 case MP_HOUSE: return GSF_HOUSES;
767 case MP_INDUSTRY: return GSF_INDUSTRYTILES;
768 case MP_OBJECT: return GSF_OBJECTS;
769
770 case MP_STATION:
771 switch (GetStationType(tile)) {
772 case StationType::Rail: return GSF_STATIONS;
773 case StationType::Airport: return GSF_AIRPORTTILES;
774 case StationType::Bus: return GSF_ROADSTOPS;
775 case StationType::Truck: return GSF_ROADSTOPS;
776 default: return GSF_INVALID;
777 }
778 }
779}
780
786 GrfSpecFeature GetGrfSpecFeature(VehicleType type)
787{
788 switch (type) {
789 case VEH_TRAIN: return GSF_TRAINS;
790 case VEH_ROAD: return GSF_ROADVEHICLES;
791 case VEH_SHIP: return GSF_SHIPS;
792 case VEH_AIRCRAFT: return GSF_AIRCRAFT;
793 default: return GSF_INVALID;
794 }
795}
796
797
798/**** Sprite Aligner ****/
799
801 struct SpriteAlignerWindow : Window {
802 typedef std::pair<int16_t, int16_t> XyOffs;
803
804 SpriteID current_sprite{};
805 Scrollbar *vscroll = nullptr;
806 std::map<SpriteID, XyOffs> offs_start_map{};
807
808 static inline ZoomLevel zoom = ZoomLevel::End;
809 static bool centre;
810 static bool crosshair;
811 const Action5Type *act5_type = nullptr;
812
813 SpriteAlignerWindow(WindowDesc &desc, WindowNumber wno) : Window(desc)
814 {
815 /* On first opening, set initial zoom to current zoom level. */
816 if (SpriteAlignerWindow::zoom == ZoomLevel::End) SpriteAlignerWindow::zoom = _gui_zoom;
817 SpriteAlignerWindow::zoom = Clamp(SpriteAlignerWindow::zoom, _settings_client.gui.zoom_min, _settings_client.gui.zoom_max);
818
819 /* Oh yes, we assume there is at least one normal sprite! */
820 while (GetSpriteType(this->current_sprite) != SpriteType::Normal) this->current_sprite++;
821 this->SelectAction5Type();
822
823 this->CreateNestedTree();
824 this->vscroll = this->GetScrollbar(WID_SA_SCROLLBAR);
825 this->vscroll->SetCount(_newgrf_debug_sprite_picker.sprites.size());
826 this->FinishInitNested(wno);
827
828 this->SetWidgetLoweredState(WID_SA_CENTRE, SpriteAlignerWindow::centre);
829 this->SetWidgetLoweredState(WID_SA_CROSSHAIR, SpriteAlignerWindow::crosshair);
830
831 this->InvalidateData(0, true);
832 }
833
834 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
835 {
836 const Sprite *spr = GetSprite(this->current_sprite, SpriteType::Normal);
837 switch (widget) {
838 case WID_SA_CAPTION:
839 if (this->act5_type != nullptr) {
840 return GetString(STR_SPRITE_ALIGNER_CAPTION_ACTION5,
841 this->act5_type - GetAction5Types().data(),
842 this->current_sprite - this->act5_type->sprite_base,
843 GetOriginFile(this->current_sprite)->GetSimplifiedFilename(),
844 GetSpriteLocalID(this->current_sprite));
845 }
846 if (this->current_sprite < SPR_OPENTTD_BASE) {
847 return GetString(STR_SPRITE_ALIGNER_CAPTION_ACTIONA,
848 this->current_sprite,
849 GetOriginFile(this->current_sprite)->GetSimplifiedFilename(),
850 GetSpriteLocalID(this->current_sprite));
851 }
852 return GetString(STR_SPRITE_ALIGNER_CAPTION_NO_ACTION,
853 GetOriginFile(this->current_sprite)->GetSimplifiedFilename(),
854 GetSpriteLocalID(this->current_sprite));
855
856 case WID_SA_OFFSETS_ABS:
857 return GetString(STR_SPRITE_ALIGNER_OFFSETS_ABS, UnScaleByZoom(spr->x_offs, SpriteAlignerWindow::zoom), UnScaleByZoom(spr->y_offs, SpriteAlignerWindow::zoom));
858
859 case WID_SA_OFFSETS_REL: {
860 /* Relative offset is new absolute offset - starting absolute offset.
861 * Show 0, 0 as the relative offsets if entry is not in the map (meaning they have not been changed yet).
862 */
863 const auto key_offs_pair = this->offs_start_map.find(this->current_sprite);
864 if (key_offs_pair != this->offs_start_map.end()) {
865 return GetString(STR_SPRITE_ALIGNER_OFFSETS_REL,
866 UnScaleByZoom(spr->x_offs - key_offs_pair->second.first, SpriteAlignerWindow::zoom),
867 UnScaleByZoom(spr->y_offs - key_offs_pair->second.second, SpriteAlignerWindow::zoom));
868 }
869
870 return GetString(STR_SPRITE_ALIGNER_OFFSETS_REL, 0, 0);
871 }
872
873 default:
874 return this->Window::GetWidgetString(widget, stringid);
875 }
876 }
877
878 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
879 {
880 switch (widget) {
881 case WID_SA_SPRITE:
882 size.height = ScaleGUITrad(200);
883 break;
884
885 case WID_SA_LIST: {
886 Dimension d = {};
887 for (const auto &spritefile : GetCachedSpriteFiles()) {
888 d = maxdim(d, GetStringBoundingBox(GetString(STR_SPRITE_ALIGNER_SPRITE, spritefile->GetSimplifiedFilename(), GetParamMaxDigits(6))));
889 }
890 size.width = d.width + padding.width;
891 fill.height = resize.height = GetCharacterHeight(FS_NORMAL) + padding.height;
892 resize.width = 1;
893 break;
894 }
895
896 default:
897 break;
898 }
899 }
900
901 void DrawWidget(const Rect &r, WidgetID widget) const override
902 {
903 switch (widget) {
904 case WID_SA_SPRITE: {
905 /* Center the sprite ourselves */
906 const Sprite *spr = GetSprite(this->current_sprite, SpriteType::Normal);
907 Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
908 int x;
909 int y;
910 if (SpriteAlignerWindow::centre) {
911 x = -UnScaleByZoom(spr->x_offs, SpriteAlignerWindow::zoom) + (ir.Width() - UnScaleByZoom(spr->width, SpriteAlignerWindow::zoom)) / 2;
912 y = -UnScaleByZoom(spr->y_offs, SpriteAlignerWindow::zoom) + (ir.Height() - UnScaleByZoom(spr->height, SpriteAlignerWindow::zoom)) / 2;
913 } else {
914 x = ir.Width() / 2;
915 y = ir.Height() / 2;
916 }
917
918 DrawPixelInfo new_dpi;
919 if (!FillDrawPixelInfo(&new_dpi, ir)) break;
920 AutoRestoreBackup dpi_backup(_cur_dpi, &new_dpi);
921
922 DrawSprite(this->current_sprite, PAL_NONE, x, y, nullptr, SpriteAlignerWindow::zoom);
923
924 Rect outline = {0, 0, UnScaleByZoom(spr->width, SpriteAlignerWindow::zoom) - 1, UnScaleByZoom(spr->height, SpriteAlignerWindow::zoom) - 1};
925 outline = outline.Translate(x + UnScaleByZoom(spr->x_offs, SpriteAlignerWindow::zoom), y + UnScaleByZoom(spr->y_offs, SpriteAlignerWindow::zoom));
926 DrawRectOutline(outline.Expand(1), PC_LIGHT_BLUE, 1, 1);
927
928 if (SpriteAlignerWindow::crosshair) {
929 GfxDrawLine(x, 0, x, ir.Height() - 1, PC_WHITE, 1, 1);
930 GfxDrawLine(0, y, ir.Width() - 1, y, PC_WHITE, 1, 1);
931 }
932 break;
933 }
934
935 case WID_SA_LIST: {
936 /* Don't redraw sprite list while it is still being filled by picker. */
937 if (_newgrf_debug_sprite_picker.mode == SPM_REDRAW) break;
938
939 const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
940 int step_size = nwid->resize_y;
941
942 const FlatSet<SpriteID> &list = _newgrf_debug_sprite_picker.sprites;
943
944 Rect ir = r.Shrink(WidgetDimensions::scaled.matrix);
945 auto [first, last] = this->vscroll->GetVisibleRangeIterators(list);
946 for (auto it = first; it != last; ++it) {
947 const SpriteFile *file = GetOriginFile(*it);
948 if (file == nullptr) {
949 DrawString(ir, GetString(STR_JUST_COMMA, *it), *it == this->current_sprite ? TC_WHITE : (TC_GREY | TC_NO_SHADE), SA_RIGHT | SA_FORCE);
950 } else {
951 DrawString(ir, GetString(STR_SPRITE_ALIGNER_SPRITE, file->GetSimplifiedFilename(), GetSpriteLocalID(*it)), *it == this->current_sprite ? TC_WHITE : TC_BLACK);
952 }
953 ir.top += step_size;
954 }
955 break;
956 }
957 }
958 }
959
960 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
961 {
962 switch (widget) {
963 case WID_SA_PREVIOUS:
964 do {
965 this->current_sprite = (this->current_sprite == 0 ? GetMaxSpriteID() : this->current_sprite) - 1;
966 } while (GetSpriteType(this->current_sprite) != SpriteType::Normal);
967 this->SelectAction5Type();
968 this->SetDirty();
969 break;
970
971 case WID_SA_GOTO:
972 ShowQueryString({}, STR_SPRITE_ALIGNER_GOTO_CAPTION, 7, this, CS_NUMERAL, {});
973 break;
974
975 case WID_SA_NEXT:
976 do {
977 this->current_sprite = (this->current_sprite + 1) % GetMaxSpriteID();
978 } while (GetSpriteType(this->current_sprite) != SpriteType::Normal);
979 this->SelectAction5Type();
980 this->SetDirty();
981 break;
982
983 case WID_SA_PICKER:
984 this->LowerWidget(WID_SA_PICKER);
985 _newgrf_debug_sprite_picker.mode = SPM_WAIT_CLICK;
986 this->SetDirty();
987 break;
988
989 case WID_SA_LIST: {
990 auto it = this->vscroll->GetScrolledItemFromWidget(_newgrf_debug_sprite_picker.sprites, pt.y, this, widget);
991 if (it != _newgrf_debug_sprite_picker.sprites.end()) {
992 SpriteID spr = *it;
993 if (GetSpriteType(spr) == SpriteType::Normal) this->current_sprite = spr;
994 }
995 this->SelectAction5Type();
996 this->SetDirty();
997 break;
998 }
999
1000 case WID_SA_UP:
1001 case WID_SA_DOWN:
1002 case WID_SA_LEFT:
1003 case WID_SA_RIGHT: {
1004 /*
1005 * Yes... this is a hack.
1006 *
1007 * No... I don't think it is useful to make this less of a hack.
1008 *
1009 * If you want to align sprites, you just need the number. Generally
1010 * the sprite caches are big enough to not remove the sprite from the
1011 * cache. If that's not the case, just let the NewGRF developer
1012 * increase the cache size instead of storing thousands of offsets
1013 * for the incredibly small chance that it's actually going to be
1014 * used by someone and the sprite cache isn't big enough for that
1015 * particular NewGRF developer.
1016 */
1017 Sprite *spr = const_cast<Sprite *>(GetSprite(this->current_sprite, SpriteType::Normal));
1018
1019 /* Remember the original offsets of the current sprite, if not already in mapping. */
1020 if (this->offs_start_map.count(this->current_sprite) == 0) {
1021 this->offs_start_map[this->current_sprite] = XyOffs(spr->x_offs, spr->y_offs);
1022 }
1023 int amt = ScaleByZoom(_ctrl_pressed ? 8 : 1, SpriteAlignerWindow::zoom);
1024 switch (widget) {
1025 /* Move eight units at a time if ctrl is pressed. */
1026 case WID_SA_UP: spr->y_offs -= amt; break;
1027 case WID_SA_DOWN: spr->y_offs += amt; break;
1028 case WID_SA_LEFT: spr->x_offs -= amt; break;
1029 case WID_SA_RIGHT: spr->x_offs += amt; break;
1030 }
1031 /* Of course, we need to redraw the sprite, but where is it used?
1032 * Everywhere is a safe bet. */
1033 MarkWholeScreenDirty();
1034 break;
1035 }
1036
1037 case WID_SA_RESET_REL:
1038 /* Reset the starting offsets for the current sprite. */
1039 this->offs_start_map.erase(this->current_sprite);
1040 this->SetDirty();
1041 break;
1042
1043 case WID_SA_CENTRE:
1044 SpriteAlignerWindow::centre = !SpriteAlignerWindow::centre;
1045 this->SetWidgetLoweredState(widget, SpriteAlignerWindow::centre);
1046 this->SetDirty();
1047 break;
1048
1049 case WID_SA_CROSSHAIR:
1050 SpriteAlignerWindow::crosshair = !SpriteAlignerWindow::crosshair;
1051 this->SetWidgetLoweredState(widget, SpriteAlignerWindow::crosshair);
1052 this->SetDirty();
1053 break;
1054
1055 default:
1056 if (IsInsideBS(widget, WID_SA_ZOOM, to_underlying(ZoomLevel::End))) {
1057 SpriteAlignerWindow::zoom = static_cast<ZoomLevel>(widget - WID_SA_ZOOM);
1058 this->InvalidateData(0, true);
1059 }
1060 break;
1061 }
1062 }
1063
1064 void OnQueryTextFinished(std::optional<std::string> str) override
1065 {
1066 if (!str.has_value()) return;
1067
1068 auto value = ParseInteger(*str, 10, true);
1069 if (!value.has_value()) return;
1070 this->current_sprite = *value;
1071 if (this->current_sprite >= GetMaxSpriteID()) this->current_sprite = 0;
1072 while (GetSpriteType(this->current_sprite) != SpriteType::Normal) {
1073 this->current_sprite = (this->current_sprite + 1) % GetMaxSpriteID();
1074 }
1075 this->SelectAction5Type();
1076 this->SetDirty();
1077 }
1078
1084 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1085 {
1086 if (!gui_scope) return;
1087 if (data == 1) {
1088 /* Sprite picker finished */
1089 this->RaiseWidget(WID_SA_PICKER);
1090 this->vscroll->SetCount(_newgrf_debug_sprite_picker.sprites.size());
1091 }
1092
1093 SpriteAlignerWindow::zoom = Clamp(SpriteAlignerWindow::zoom, _settings_client.gui.zoom_min, _settings_client.gui.zoom_max);
1094 for (ZoomLevel z = ZoomLevel::Begin; z < ZoomLevel::End; z++) {
1095 this->SetWidgetsDisabledState(z < _settings_client.gui.zoom_min || z > _settings_client.gui.zoom_max, WID_SA_ZOOM + to_underlying(z));
1096 this->SetWidgetsLoweredState(SpriteAlignerWindow::zoom == z, WID_SA_ZOOM + to_underlying(z));
1097 }
1098 }
1099
1100 void OnResize() override
1101 {
1102 this->vscroll->SetCapacityFromWidget(this, WID_SA_LIST);
1103 }
1104
1105private:
1106 void SelectAction5Type()
1107 {
1108 const auto act5types = GetAction5Types();
1109 for (auto it = std::begin(act5types); it != std::end(act5types); ++it) {
1110 if (it->sprite_base <= this->current_sprite && this->current_sprite < it->sprite_base + it->max_sprites) {
1111 this->act5_type = &*it;
1112 return;
1113 }
1114 }
1115 this->act5_type = nullptr;
1116 }
1117};
1118
1119bool SpriteAlignerWindow::centre = true;
1120bool SpriteAlignerWindow::crosshair = true;
1121
1122static constexpr std::initializer_list<NWidgetPart> _nested_sprite_aligner_widgets = {
1123 NWidget(NWID_HORIZONTAL),
1124 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1125 NWidget(WWT_CAPTION, COLOUR_GREY, WID_SA_CAPTION),
1126 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1127 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1128 EndContainer(),
1129 NWidget(WWT_PANEL, COLOUR_GREY),
1130 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0), SetPadding(WidgetDimensions::unscaled.sparse_resize),
1131 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0),
1132 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1133 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SA_PREVIOUS), SetStringTip(STR_SPRITE_ALIGNER_PREVIOUS_BUTTON, STR_SPRITE_ALIGNER_PREVIOUS_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1134 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SA_GOTO), SetStringTip(STR_SPRITE_ALIGNER_GOTO_BUTTON, STR_SPRITE_ALIGNER_GOTO_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1135 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SA_NEXT), SetStringTip(STR_SPRITE_ALIGNER_NEXT_BUTTON, STR_SPRITE_ALIGNER_NEXT_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1136 EndContainer(),
1137 NWidget(NWID_HORIZONTAL),
1138 NWidget(NWID_SPACER), SetFill(1, 1), SetResize(1, 0),
1139 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SA_UP), SetSpriteTip(SPR_ARROW_UP, STR_SPRITE_ALIGNER_MOVE_TOOLTIP), SetResize(0, 0), SetMinimalSize(11, 11),
1140 NWidget(NWID_SPACER), SetFill(1, 1), SetResize(1, 0),
1141 EndContainer(),
1142 NWidget(NWID_HORIZONTAL_LTR), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
1143 NWidget(NWID_VERTICAL),
1144 NWidget(NWID_SPACER), SetFill(1, 1), SetResize(0, 1),
1145 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SA_LEFT), SetSpriteTip(SPR_ARROW_LEFT, STR_SPRITE_ALIGNER_MOVE_TOOLTIP), SetResize(0, 0), SetMinimalSize(11, 11),
1146 NWidget(NWID_SPACER), SetFill(1, 1), SetResize(0, 1),
1147 EndContainer(),
1148 NWidget(WWT_PANEL, COLOUR_DARK_BLUE, WID_SA_SPRITE), SetToolTip(STR_SPRITE_ALIGNER_SPRITE_TOOLTIP), SetResize(1, 1), SetFill(1, 1),
1149 EndContainer(),
1150 NWidget(NWID_VERTICAL),
1151 NWidget(NWID_SPACER), SetFill(1, 1), SetResize(0, 1),
1152 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SA_RIGHT), SetSpriteTip(SPR_ARROW_RIGHT, STR_SPRITE_ALIGNER_MOVE_TOOLTIP), SetResize(0, 0), SetMinimalSize(11, 11),
1153 NWidget(NWID_SPACER), SetFill(1, 1), SetResize(0, 1),
1154 EndContainer(),
1155 EndContainer(),
1156 NWidget(NWID_HORIZONTAL),
1157 NWidget(NWID_SPACER), SetFill(1, 1), SetResize(1, 0),
1158 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SA_DOWN), SetSpriteTip(SPR_ARROW_DOWN, STR_SPRITE_ALIGNER_MOVE_TOOLTIP), SetResize(0, 0), SetMinimalSize(11, 11),
1159 NWidget(NWID_SPACER), SetFill(1, 1), SetResize(1, 0),
1160 EndContainer(),
1161 NWidget(WWT_LABEL, INVALID_COLOUR, WID_SA_OFFSETS_ABS), SetFill(1, 0), SetResize(1, 0),
1162 NWidget(WWT_LABEL, INVALID_COLOUR, WID_SA_OFFSETS_REL), SetFill(1, 0), SetResize(1, 0),
1163 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1164 NWidget(WWT_TEXTBTN_2, COLOUR_GREY, WID_SA_CENTRE), SetStringTip(STR_SPRITE_ALIGNER_CENTRE_OFFSET), SetFill(1, 0), SetResize(1, 0),
1165 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SA_RESET_REL), SetStringTip(STR_SPRITE_ALIGNER_RESET_BUTTON, STR_SPRITE_ALIGNER_RESET_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1166 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SA_CROSSHAIR), SetStringTip(STR_SPRITE_ALIGNER_CROSSHAIR), SetFill(1, 0), SetResize(1, 0),
1167 EndContainer(),
1168 EndContainer(),
1169 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0),
1170 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SA_PICKER), SetStringTip(STR_SPRITE_ALIGNER_PICKER_BUTTON, STR_SPRITE_ALIGNER_PICKER_TOOLTIP), SetFill(1, 0),
1171 NWidget(NWID_HORIZONTAL),
1172 NWidget(WWT_MATRIX, COLOUR_GREY, WID_SA_LIST), SetResize(1, 1), SetMatrixDataTip(1, 0), SetFill(1, 1), SetScrollbar(WID_SA_SCROLLBAR),
1173 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SA_SCROLLBAR),
1174 EndContainer(),
1175 NWidget(NWID_VERTICAL),
1176 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SA_ZOOM + to_underlying(ZoomLevel::In4x)), SetStringTip(STR_CONFIG_SETTING_ZOOM_LVL_MIN), SetFill(1, 0),
1177 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SA_ZOOM + to_underlying(ZoomLevel::In2x)), SetStringTip(STR_CONFIG_SETTING_ZOOM_LVL_IN_2X), SetFill(1, 0),
1178 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SA_ZOOM + to_underlying(ZoomLevel::Normal)), SetStringTip(STR_CONFIG_SETTING_ZOOM_LVL_NORMAL), SetFill(1, 0),
1179 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SA_ZOOM + to_underlying(ZoomLevel::Out2x)), SetStringTip(STR_CONFIG_SETTING_ZOOM_LVL_OUT_2X), SetFill(1, 0),
1180 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SA_ZOOM + to_underlying(ZoomLevel::Out4x)), SetStringTip(STR_CONFIG_SETTING_ZOOM_LVL_OUT_4X), SetFill(1, 0),
1181 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SA_ZOOM + to_underlying(ZoomLevel::Out8x)), SetStringTip(STR_CONFIG_SETTING_ZOOM_LVL_OUT_8X), SetFill(1, 0),
1182 EndContainer(),
1183 EndContainer(),
1184 EndContainer(),
1185 NWidget(NWID_HORIZONTAL),
1186 NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
1187 NWidget(WWT_RESIZEBOX, COLOUR_GREY), SetResizeWidgetTypeTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
1188 EndContainer(),
1189 EndContainer(),
1190};
1191
1192static WindowDesc _sprite_aligner_desc(
1193 WDP_AUTO, "sprite_aligner", 400, 300,
1194 WC_SPRITE_ALIGNER, WC_NONE,
1195 {},
1196 _nested_sprite_aligner_widgets
1197);
1198
1202 void ShowSpriteAlignerWindow()
1203{
1204 AllocateWindowDescFront<SpriteAlignerWindow>(_sprite_aligner_desc, 0);
1205}
backup_type.hpp
Class for backupping variables and making sure they are restored later.
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
IsValidCargoType
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
Definition cargo_type.h:104
Badge
Definition newgrf_badge.h:20
Badge::label
std::string label
Label of badge.
Definition newgrf_badge.h:22
Badge::name
StringID name
Short name.
Definition newgrf_badge.h:26
EnumBitSet< VehicleCallbackMask, uint16_t >
FlatSet
Flat set implementation that uses a sorted vector for storage.
Definition flatset_type.hpp:20
NIHelper
Helper class to wrap some functionality/queries in.
Definition newgrf_debug_gui.cpp:129
NIHelper::GetBadges
virtual std::span< const BadgeID > GetBadges(uint index) const =0
Get the list of badges of this item.
NIHelper::Resolve
virtual uint Resolve(uint index, uint var, uint param, bool &avail) const =0
Resolve (action2) variable for a given index.
NIHelper::GetSpec
virtual const void * GetSpec(uint index) const =0
Get (NewGRF) specs given an index.
NIHelper::IsInspectable
virtual bool IsInspectable(uint index) const =0
Is the item with the given index inspectable?
NIHelper::GetGRFID
virtual uint32_t GetGRFID(uint index) const =0
Get the GRFID of the file that includes this item.
NIHelper::GetInstance
virtual const void * GetInstance(uint index) const =0
Get the instance given an index.
NIHelper::GetPSA
virtual const std::span< int32_t > GetPSA(uint index, uint32_t grfid) const
Gets the span containing the persistent storage.
Definition newgrf_debug_gui.cpp:207
NIHelper::~NIHelper
virtual ~NIHelper()=default
Silence a warning.
NIHelper::GetName
virtual std::string GetName(uint index) const =0
Get the name of this item.
NIHelper::PSAWithParameter
virtual bool PSAWithParameter() const
Used to decide if the PSA needs a parameter or not.
Definition newgrf_debug_gui.cpp:196
NIHelper::GetParent
virtual uint GetParent(uint index) const =0
Get the parent "window_number" of a given instance.
NWidgetBase
Baseclass for nested widgets.
Definition widget_type.h:136
NWidgetBase::resize_y
uint resize_y
Vertical resize step (0 means not resizable).
Definition widget_type.h:230
RandomAccessFile::GetSimplifiedFilename
const std::string & GetSimplifiedFilename() const
Get the simplified filename of the opened file.
Definition random_access_file.cpp:62
Scrollbar
Scrollbar data structure.
Definition widget_type.h:708
Scrollbar::GetCapacity
size_type GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition widget_type.h:743
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition widget_type.h:792
Scrollbar::GetScrolledItemFromWidget
auto GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Return an iterator pointing to the element of a scrolled widget that a user clicked in.
Definition widget_type.h:891
Scrollbar::GetScrolledRowFromWidget
size_type GetScrolledRowFromWidget(int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition widget.cpp:2425
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition widget.cpp:2499
Scrollbar::GetVisibleRangeIterators
auto GetVisibleRangeIterators(Tcontainer &container) const
Get a pair of iterators for the range of visible elements in a container.
Definition widget_type.h:872
Scrollbar::GetPosition
size_type GetPosition() const
Gets the position of the first visible element in the list.
Definition widget_type.h:752
SpriteFile
RandomAccessFile with some extra information specific for sprite files.
Definition sprite_file_type.hpp:19
WidgetDimensions::frametext
RectPadding frametext
Padding inside frame with text.
Definition window_gui.h:41
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:93
ConvertibleThroughBase
A type is considered 'convertible through base()' when it has a 'base()' function that returns someth...
Definition convertible_through_base.hpp:19
GetVehicleImageCellSize
VehicleCellSize GetVehicleImageCellSize(VehicleType type, EngineImageType image_type)
Get the GUI cell size for a vehicle image.
Definition depot_gui.cpp:162
engine_base.h
Base class for engines.
to_underlying
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23)
Definition enum_type.hpp:17
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:87
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition geometry_func.cpp:22
geometry_func.hpp
Geometry functions.
CentreBounds
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
Definition geometry_type.hpp:26
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:894
DrawString
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:665
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:38
DrawRectOutline
void DrawRectOutline(const Rect &r, PixelColour colour, int width, int dash)
Draw the outline of a Rect.
Definition gfx.cpp:460
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition gfx.cpp:1031
_gui_zoom
ZoomLevel _gui_zoom
GUI Zoom level.
Definition gfx.cpp:61
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
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
SpriteType::Normal
@ Normal
The most basic (normal) sprite.
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:249
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition gfx_type.h:390
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition gfx_type.h:400
TC_NO_SHADE
@ TC_NO_SHADE
Do not add shading to this text colour.
Definition gfx_type.h:331
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint32_t cols, uint32_t rows, StringID tip={})
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition widget_type.h:1308
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1219
SetSpriteTip
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
Definition widget_type.h:1251
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
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition widget_type.h:1399
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
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition widget_type.h:1156
SetResizeWidgetTypeTip
constexpr NWidgetPart SetResizeWidgetTypeTip(ResizeWidgetValues widget_type, StringID tip)
Widget part function for setting the resize widget type and tooltip.
Definition widget_type.h:1285
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
SetArrowWidgetTypeTip
constexpr NWidgetPart SetArrowWidgetTypeTip(ArrowWidgetValues widget_type, StringID tip={})
Widget part function for setting the arrow widget type and tooltip.
Definition widget_type.h:1274
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
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1145
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:966
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1546
industry.h
Base of all industries.
IsInsideBS
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
Definition math_func.hpp:252
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition math_func.hpp:79
ShowQueryString
void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition misc_gui.cpp:1062
GrfSpecFeature
GrfSpecFeature
Definition newgrf.h:68
GSF_INVALID
@ GSF_INVALID
An invalid spec feature.
Definition newgrf.h:99
GSF_FAKE_END
@ GSF_FAKE_END
End of the fake features.
Definition newgrf.h:95
GetAction5Types
std::span< const Action5Type > GetAction5Types()
Get list of all action 5 types.
Definition newgrf_act5.cpp:88
newgrf_act5.h
Information about NewGRF Action 5.
newgrf_airport.h
NewGRF handling of airports.
newgrf_airporttiles.h
NewGRF handling of airport tiles.
GetBadge
Badge * GetBadge(BadgeID index)
Get a badge if it exists.
Definition newgrf_badge.cpp:113
newgrf_badge.h
Functions related to NewGRF badges.
AirportTileCallbackMask
AirportTileCallbackMask
Callback masks for airport tiles.
Definition newgrf_callbacks.h:427
StationCallbackMask
StationCallbackMask
Callback masks for stations.
Definition newgrf_callbacks.h:319
VehicleCallbackMask
VehicleCallbackMask
Callback masks for vehicles, indicates which callbacks are used by a vehicle.
Definition newgrf_callbacks.h:302
CargoCallbackMask
CargoCallbackMask
Callback masks for cargoes.
Definition newgrf_callbacks.h:369
IndustryCallbackMask
IndustryCallbackMask
Callback masks for Industries.
Definition newgrf_callbacks.h:378
CanalCallbackMask
CanalCallbackMask
Callback masks for canals.
Definition newgrf_callbacks.h:361
ObjectCallbackMask
ObjectCallbackMask
Callback masks for objects.
Definition newgrf_callbacks.h:414
RoadStopCallbackMask
RoadStopCallbackMask
Callback masks for road stops.
Definition newgrf_callbacks.h:331
IndustryTileCallbackMask
IndustryTileCallbackMask
Callback masks for industry tiles.
Definition newgrf_callbacks.h:400
HouseCallbackMask
HouseCallbackMask
Callback masks for houses.
Definition newgrf_callbacks.h:341
newgrf_debug.h
Functions/types related to NewGRF debugging.
newgrf_debug_data.h
Data 'tables' for NewGRF debugging.
_nifeatures
static const NIFeature *const _nifeatures[]
Table with all NIFeatures.
Definition newgrf_debug_data.h:724
GetInspectWindowNumber
static uint GetInspectWindowNumber(GrfSpecFeature feature, uint index)
Get the window number for the inspect window given a feature and index.
Definition newgrf_debug_gui.cpp:72
NIType
NIType
The type of a property to show.
Definition newgrf_debug_gui.cpp:84
NIT_INT
@ NIT_INT
The property is a simple integer.
Definition newgrf_debug_gui.cpp:85
NIT_CARGO
@ NIT_CARGO
The property is a cargo.
Definition newgrf_debug_gui.cpp:86
ShowSpriteAlignerWindow
void ShowSpriteAlignerWindow()
Show the window for aligning sprites.
Definition newgrf_debug_gui.cpp:1202
GetGrfSpecFeature
GrfSpecFeature GetGrfSpecFeature(TileIndex tile)
Get the GrfSpecFeature associated with the tile.
Definition newgrf_debug_gui.cpp:760
InvalidateNewGRFInspectWindow
void InvalidateNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Invalidate the inspect window for a given feature and index.
Definition newgrf_debug_gui.cpp:710
GetFeature
static const NIFeature * GetFeature(uint window_number)
Get the NIFeature related to the window number.
Definition newgrf_debug_gui.cpp:240
ShowNewGRFInspectWindow
void ShowNewGRFInspectWindow(GrfSpecFeature feature, uint index, const uint32_t grfid)
Show the inspect window for a given feature and index.
Definition newgrf_debug_gui.cpp:692
IsNewGRFInspectable
bool IsNewGRFInspectable(GrfSpecFeature feature, uint index)
Can we inspect the data given a certain feature and index.
Definition newgrf_debug_gui.cpp:748
GetFeatureHelper
static const NIHelper & GetFeatureHelper(uint window_number)
Get the NIHelper related to the window number.
Definition newgrf_debug_gui.cpp:252
GetFeatureIndex
static uint GetFeatureIndex(uint window_number)
Get the feature index related to the window number.
Definition newgrf_debug_gui.cpp:60
DeleteNewGRFInspectWindow
void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Delete inspect window for a given feature and index.
Definition newgrf_debug_gui.cpp:726
GetFeatureNum
static GrfSpecFeature GetFeatureNum(uint window_number)
Get the feature number related to the window number.
Definition newgrf_debug_gui.cpp:230
_newgrf_debug_sprite_picker
NewGrfDebugSpritePicker _newgrf_debug_sprite_picker
The sprite picker.
Definition newgrf_debug_gui.cpp:53
newgrf_debug_widget.h
Types related to the newgrf debug widgets.
WID_NGRFI_VEH_CHAIN
@ WID_NGRFI_VEH_CHAIN
Display for vehicle chain.
Definition newgrf_debug_widget.h:19
WID_NGRFI_PARENT
@ WID_NGRFI_PARENT
Inspect the parent.
Definition newgrf_debug_widget.h:16
WID_NGRFI_MAINPANEL
@ WID_NGRFI_MAINPANEL
Panel widget containing the actual data.
Definition newgrf_debug_widget.h:20
WID_NGRFI_VEH_NEXT
@ WID_NGRFI_VEH_NEXT
Go to next vehicle in chain.
Definition newgrf_debug_widget.h:18
WID_NGRFI_CAPTION
@ WID_NGRFI_CAPTION
The caption bar of course.
Definition newgrf_debug_widget.h:15
WID_NGRFI_VEH_PREV
@ WID_NGRFI_VEH_PREV
Go to previous vehicle in chain.
Definition newgrf_debug_widget.h:17
WID_NGRFI_SCROLLBAR
@ WID_NGRFI_SCROLLBAR
Scrollbar.
Definition newgrf_debug_widget.h:21
WID_SA_NEXT
@ WID_SA_NEXT
Skip to the next sprite.
Definition newgrf_debug_widget.h:29
WID_SA_CAPTION
@ WID_SA_CAPTION
Caption of the window.
Definition newgrf_debug_widget.h:26
WID_SA_SPRITE
@ WID_SA_SPRITE
The actual sprite.
Definition newgrf_debug_widget.h:34
WID_SA_PICKER
@ WID_SA_PICKER
Sprite picker.
Definition newgrf_debug_widget.h:37
WID_SA_SCROLLBAR
@ WID_SA_SCROLLBAR
Scrollbar for sprite list.
Definition newgrf_debug_widget.h:39
WID_SA_OFFSETS_ABS
@ WID_SA_OFFSETS_ABS
The sprite offsets (absolute).
Definition newgrf_debug_widget.h:35
WID_SA_PREVIOUS
@ WID_SA_PREVIOUS
Skip to the previous sprite.
Definition newgrf_debug_widget.h:27
WID_SA_OFFSETS_REL
@ WID_SA_OFFSETS_REL
The sprite offsets (relative).
Definition newgrf_debug_widget.h:36
WID_SA_CROSSHAIR
@ WID_SA_CROSSHAIR
Toggle crosshair.
Definition newgrf_debug_widget.h:44
WID_SA_GOTO
@ WID_SA_GOTO
Go to a given sprite.
Definition newgrf_debug_widget.h:28
WID_SA_DOWN
@ WID_SA_DOWN
Move the sprite down.
Definition newgrf_debug_widget.h:33
WID_SA_ZOOM
@ WID_SA_ZOOM
Zoom level buttons (from ZoomLevel::Begin to ZoomLevel::Max).
Definition newgrf_debug_widget.h:40
WID_SA_UP
@ WID_SA_UP
Move the sprite up.
Definition newgrf_debug_widget.h:30
WID_SA_RESET_REL
@ WID_SA_RESET_REL
Reset relative sprite offset.
Definition newgrf_debug_widget.h:42
WID_SA_LIST
@ WID_SA_LIST
Queried sprite list.
Definition newgrf_debug_widget.h:38
WID_SA_RIGHT
@ WID_SA_RIGHT
Move the sprite to the right.
Definition newgrf_debug_widget.h:32
WID_SA_LEFT
@ WID_SA_LEFT
Move the sprite to the left.
Definition newgrf_debug_widget.h:31
WID_SA_CENTRE
@ WID_SA_CENTRE
Toggle centre sprite.
Definition newgrf_debug_widget.h:43
newgrf_industries.h
Functions for NewGRF industries.
newgrf_industrytiles.h
NewGRF handling of industry tiles.
newgrf_object.h
Functions related to NewGRF objects.
newgrf_railtype.h
NewGRF handling of rail types.
newgrf_spritegroup.h
Action 2 handling.
newgrf_station.h
Header file for NewGRF stations.
newgrf_town.h
Functions to handle the town part of NewGRF towns.
object_base.h
Base for all objects.
PC_WHITE
static constexpr PixelColour PC_WHITE
White palette colour.
Definition palette_func.h:99
PC_LIGHT_BLUE
static constexpr PixelColour PC_LIGHT_BLUE
Light blue palette colour.
Definition palette_func.h:117
random_access_file_type.h
Class related to random access to files.
IsLevelCrossing
bool IsLevelCrossing(Tile t)
Return whether a tile is a level crossing.
Definition road_map.h:69
roadveh.h
Road vehicle states.
safeguards.h
A number of safeguards to prevent using unsafe methods.
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
GetSpriteType
SpriteType GetSpriteType(SpriteID sprite)
Get the sprite type of a given sprite.
Definition spritecache.cpp:141
GetMaxSpriteID
SpriteID GetMaxSpriteID()
Get a reasonable (upper bound) estimate of the maximum SpriteID used in OpenTTD; there will be no spr...
Definition spritecache.cpp:202
GetCachedSpriteFiles
std::span< const std::unique_ptr< SpriteFile > > GetCachedSpriteFiles()
Get the list of cached SpriteFiles.
Definition spritecache.cpp:75
GetOriginFile
SpriteFile * GetOriginFile(SpriteID sprite)
Get the SpriteFile of a given sprite.
Definition spritecache.cpp:152
GetSpriteLocalID
uint32_t GetSpriteLocalID(SpriteID sprite)
Get the GRF-local sprite id of a given sprite.
Definition spritecache.cpp:163
spritecache.h
Functions to cache sprites in memory.
SPR_OPENTTD_BASE
static const SpriteID SPR_OPENTTD_BASE
Extra graphic spritenumbers.
Definition sprites.h:56
station_base.h
Base classes/functions for stations.
GetStationType
StationType GetStationType(Tile t)
Get the station type of this tile.
Definition station_map.h:44
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
StrMakeValid
static void StrMakeValid(Builder &builder, StringConsumer &consumer, StringValidationSettings settings)
Copies the valid (UTF-8) characters from consumer to the builder.
Definition string.cpp:119
string_consumer.hpp
Parse strings.
ParseInteger
static std::optional< T > ParseInteger(std::string_view arg, int base=10, bool clamp=false)
Change a string into its number representation.
Definition string_consumer.hpp:917
string_func.h
Functions related to low-level strings.
CS_HEXADECIMAL
@ CS_HEXADECIMAL
Only hexadecimal characters.
Definition string_type.h:30
CS_NUMERAL
@ CS_NUMERAL
Only numeric ones.
Definition string_type.h:26
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
GetParamMaxDigits
uint64_t GetParamMaxDigits(uint count, FontSize size)
Get some number that is suitable for string size computations.
Definition strings.cpp:218
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
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition strings_type.h:27
Action5Type
Information about a single action 5 type.
Definition newgrf_act5.h:23
Action5Type::sprite_base
SpriteID sprite_base
Load the sprites starting from this sprite.
Definition newgrf_act5.h:25
AutoRestoreBackup
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Definition backup_type.hpp:150
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo type.
Definition cargotype.h:137
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition settings_type.h:650
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
GUISettings::zoom_min
ZoomLevel zoom_min
minimum zoom out level
Definition settings_type.h:191
GUISettings::zoom_max
ZoomLevel zoom_max
maximum zoom out level
Definition settings_type.h:192
NICallback
Representation of the available callbacks with information on when they actually apply.
Definition newgrf_debug_gui.cpp:104
NICallback::name
std::string_view name
The human readable name of the callback.
Definition newgrf_debug_gui.cpp:105
NICallback::cb_id
uint16_t cb_id
The number of the callback.
Definition newgrf_debug_gui.cpp:119
NICallback::read_proc
NIReadProc * read_proc
Callback proc to get the actual variable from memory.
Definition newgrf_debug_gui.cpp:106
NICallback::cb_bit
std::variant< std::monostate, VehicleCallbackMask, StationCallbackMask, RoadStopCallbackMask, HouseCallbackMask, CanalCallbackMask, CargoCallbackMask, IndustryCallbackMask, IndustryTileCallbackMask, ObjectCallbackMask, AirportTileCallbackMask > cb_bit
The bit that needs to be set for this callback to be enabled.
Definition newgrf_debug_gui.cpp:118
NIFeature
Container for all information for a given feature.
Definition newgrf_debug_gui.cpp:215
NIFeature::callbacks
std::span< const NICallback > callbacks
The callbacks associated with this feature.
Definition newgrf_debug_gui.cpp:217
NIFeature::variables
std::span< const NIVariable > variables
The variables associated with this feature.
Definition newgrf_debug_gui.cpp:218
NIFeature::properties
std::span< const NIProperty > properties
The properties associated with this feature.
Definition newgrf_debug_gui.cpp:216
NIFeature::helper
std::unique_ptr< const NIHelper > helper
The class container all helper functions.
Definition newgrf_debug_gui.cpp:219
NIProperty
Representation of the data from a NewGRF property.
Definition newgrf_debug_gui.cpp:92
NIProperty::read_proc
NIReadProc * read_proc
Callback proc to get the actual variable from memory.
Definition newgrf_debug_gui.cpp:94
NIProperty::name
std::string_view name
A (human readable) name for the property.
Definition newgrf_debug_gui.cpp:93
NIProperty::prop
uint8_t prop
The number of the property.
Definition newgrf_debug_gui.cpp:95
NIVariable
Representation on the NewGRF variables.
Definition newgrf_debug_gui.cpp:123
NewGRFInspectWindow
Window used for inspecting NewGRFs.
Definition newgrf_debug_gui.cpp:258
NewGRFInspectWindow::HasVariableParameter
static bool HasVariableParameter(uint variable)
Check whether the given variable has a parameter.
Definition newgrf_debug_gui.cpp:278
NewGRFInspectWindow::var60params
static uint32_t var60params[GSF_FAKE_END][0x20]
The value for the variable 60 parameters.
Definition newgrf_debug_gui.cpp:625
NewGRFInspectWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition newgrf_debug_gui.cpp:530
NewGRFInspectWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition newgrf_debug_gui.cpp:613
NewGRFInspectWindow::DrawMainPanelWidget
void DrawMainPanelWidget(const Rect &r) const
Helper function to draw the main panel widget.
Definition newgrf_debug_gui.cpp:438
NewGRFInspectWindow::ValidateChainIndex
void ValidateChainIndex()
Ensure that this->chain_index is in range.
Definition newgrf_debug_gui.cpp:321
NewGRFInspectWindow::OnQueryTextFinished
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
Definition newgrf_debug_gui.cpp:593
NewGRFInspectWindow::DrawString
void DrawString(const Rect &r, int offset, const std::string &string) const
Helper function to draw a string (line) in the window.
Definition newgrf_debug_gui.cpp:376
NewGRFInspectWindow::HasChainIndex
bool HasChainIndex() const
Check whether this feature has chain index, i.e.
Definition newgrf_debug_gui.cpp:296
NewGRFInspectWindow::caller_grfid
uint32_t caller_grfid
GRFID of the caller of this window, 0 if it has no caller.
Definition newgrf_debug_gui.cpp:263
NewGRFInspectWindow::GetWidgetString
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition newgrf_debug_gui.cpp:344
NewGRFInspectWindow::DrawVehicleChainWidget
void DrawVehicleChainWidget(const Rect &r) const
Helper function to draw the vehicle chain widget.
Definition newgrf_debug_gui.cpp:388
NewGRFInspectWindow::GetFeatureIndex
uint GetFeatureIndex() const
Get the feature index.
Definition newgrf_debug_gui.cpp:306
NewGRFInspectWindow::SetCallerGRFID
void SetCallerGRFID(uint32_t grfid)
Set the GRFID of the item opening this window.
Definition newgrf_debug_gui.cpp:287
NewGRFInspectWindow::current_edit_param
uint8_t current_edit_param
The currently edited parameter, to update the right one.
Definition newgrf_debug_gui.cpp:269
NewGRFInspectWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition newgrf_debug_gui.cpp:603
NewGRFInspectWindow::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 newgrf_debug_gui.cpp:351
NewGRFInspectWindow::chain_index
uint chain_index
For ground vehicles: Index in vehicle chain.
Definition newgrf_debug_gui.cpp:266
NewGRFInspectWindow::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 newgrf_debug_gui.cpp:543
NewGrfDebugSpritePicker
Spritepicker of SpriteAligner.
Definition newgrf_debug.h:26
NewGrfDebugSpritePicker::mode
NewGrfDebugSpritePickerMode mode
Current state.
Definition newgrf_debug.h:27
NewGrfDebugSpritePicker::sprites
FlatSet< SpriteID > sprites
Sprites found.
Definition newgrf_debug.h:29
Pool::PoolItem<&_vehicle_pool >::Get
static Titem * Get(auto index)
Returns Titem with given index.
Definition pool_type.hpp:387
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition pool_type.hpp:286
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
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition geometry_type.hpp:200
Rect::Expand
Rect Expand(int s) const
Copy and expand Rect by s pixels.
Definition geometry_type.hpp:179
SpecializedVehicle::From
static T * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition vehicle_base.h:1134
SpriteAlignerWindow
Window used for aligning sprites.
Definition newgrf_debug_gui.cpp:801
SpriteAlignerWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition newgrf_debug_gui.cpp:901
SpriteAlignerWindow::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 newgrf_debug_gui.cpp:878
SpriteAlignerWindow::XyOffs
std::pair< int16_t, int16_t > XyOffs
Pair for x and y offsets of the sprite before alignment. First value contains the x offset,...
Definition newgrf_debug_gui.cpp:802
SpriteAlignerWindow::act5_type
const Action5Type * act5_type
Sprite Area of current selected sprite.
Definition newgrf_debug_gui.cpp:811
SpriteAlignerWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition newgrf_debug_gui.cpp:1100
SpriteAlignerWindow::current_sprite
SpriteID current_sprite
The currently shown sprite.
Definition newgrf_debug_gui.cpp:804
SpriteAlignerWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition newgrf_debug_gui.cpp:1084
SpriteAlignerWindow::offs_start_map
std::map< SpriteID, XyOffs > offs_start_map
Mapping of starting offsets for the sprites which have been aligned in the sprite aligner window.
Definition newgrf_debug_gui.cpp:806
SpriteAlignerWindow::GetWidgetString
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition newgrf_debug_gui.cpp:834
SpriteAlignerWindow::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 newgrf_debug_gui.cpp:960
SpriteAlignerWindow::OnQueryTextFinished
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
Definition newgrf_debug_gui.cpp:1064
Sprite
Data structure describing a sprite.
Definition spritecache_type.h:16
Sprite::width
uint16_t width
Width of the sprite.
Definition spritecache_type.h:18
Sprite::height
uint16_t height
Height of the sprite.
Definition spritecache_type.h:17
Sprite::y_offs
int16_t y_offs
Number of pixels to shift the sprite downwards.
Definition spritecache_type.h:20
Sprite::x_offs
int16_t x_offs
Number of pixels to shift the sprite to the right.
Definition spritecache_type.h:19
StrongType::Typedef< uint16_t, struct BadgeIDTag, StrongType::Compare >
VehicleCellSize::height
uint height
Vehicle cell height.
Definition vehicle_gui.h:84
Vehicle
Vehicle data structure.
Definition vehicle_base.h:205
Vehicle::Move
Vehicle * Move(int n)
Get the vehicle at offset n of this vehicle chain.
Definition vehicle_base.h:629
Vehicle::First
Vehicle * First() const
Get the first vehicle of this vehicle chain.
Definition vehicle_base.h:600
Vehicle::Next
Vehicle * Next() const
Get the next vehicle of this vehicle.
Definition vehicle_base.h:587
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::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1807
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition window.cpp:3234
Window::RaiseWidget
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition window_gui.h:470
Window::GetWidgetString
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:504
Window::ShowNewGRFInspectWindow
virtual void ShowNewGRFInspectWindow() const
Show the NewGRF inspection window.
Definition window_gui.h:868
Window::resize
ResizeInfo resize
Resize information.
Definition window_gui.h:315
Window::SetWidgetsDisabledState
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition window_gui.h:516
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1797
Window::SetWidgetsLoweredState
void SetWidgetsLoweredState(bool lowered_stat, Args... widgets)
Sets the lowered/raised status of a list of widgets.
Definition window_gui.h:527
Window::SetWidgetLoweredState
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:442
Window::LowerWidget
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition window_gui.h:461
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:313
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:382
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition window_gui.h:313
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:312
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:303
textbuf_gui.h
Stuff related to the text buffer GUI.
GetTileType
static TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition tile_map.h:96
MP_ROAD
@ MP_ROAD
A tile with road (or tram tracks)
Definition tile_type.h:50
MP_STATION
@ MP_STATION
A tile of a station.
Definition tile_type.h:53
MP_HOUSE
@ MP_HOUSE
A house by a town.
Definition tile_type.h:51
MP_RAILWAY
@ MP_RAILWAY
A railway.
Definition tile_type.h:49
MP_INDUSTRY
@ MP_INDUSTRY
Part of an industry.
Definition tile_type.h:56
MP_OBJECT
@ MP_OBJECT
Contains objects such as transmitters and owned land.
Definition tile_type.h:58
town.h
Base of the town class.
train.h
Base for the train class.
vehicle_base.h
Base class for all vehicles.
DrawVehicleImage
void DrawVehicleImage(const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip)
Draws an image of a vehicle chain.
Definition vehicle_gui.cpp:1710
vehicle_gui.h
Functions related to the vehicle's GUIs.
EIT_IN_DEPOT
@ EIT_IN_DEPOT
Vehicle drawn in depot.
Definition vehicle_type.h:76
EIT_IN_DETAILS
@ EIT_IN_DETAILS
Vehicle drawn in vehicle details, refit window, ...
Definition vehicle_type.h:77
VehicleType
VehicleType
Available vehicle types.
Definition vehicle_type.h:22
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition vehicle_type.h:26
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition vehicle_type.h:28
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition vehicle_type.h:27
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition vehicle_type.h:25
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition widget.cpp:289
ScaleGUITrad
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition widget.cpp:49
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition widget_type.h:104
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition widget_type.h:105
WWT_PUSHARROWBTN
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
Definition widget_type.h:106
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition widget_type.h:48
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition widget_type.h:70
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:44
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_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition widget_type.h:50
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_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
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_TEXTBTN_2
@ WWT_TEXTBTN_2
(Toggle) Button with diff text when clicked
Definition widget_type.h:45
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:37
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition widget_type.h:59
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_HORIZONTAL_LTR
@ NWID_HORIZONTAL_LTR
Horizontal container that doesn't change the order of the widgets for RTL languages.
Definition widget_type.h:67
EqualSize
@ EqualSize
Containers should keep all their (resizing) children equally large.
Definition widget_type.h:541
AWV_DECREASE
@ AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition widget_type.h:20
AWV_INCREASE
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition widget_type.h:21
RWV_HIDE_BEVEL
@ RWV_HIDE_BEVEL
Bevel of resize box is hidden.
Definition widget_type.h:29
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition window.cpp:1193
InvalidateWindowData
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition window.cpp:3294
window_func.h
Window functions not directly related to making/drawing windows.
window_gui.h
Functions, definitions and such used only by the GUI.
FrameFlag::BorderOnly
@ BorderOnly
Draw border only, no background.
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:144
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:20
WC_LAND_INFO
@ WC_LAND_INFO
Land info window; Window numbers:
Definition window_type.h:155
WC_SPRITE_ALIGNER
@ WC_SPRITE_ALIGNER
Sprite aligner (debug); Window numbers:
Definition window_type.h:697
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:50
WC_NEWGRF_INSPECT
@ WC_NEWGRF_INSPECT
NewGRF inspect (debug); Window numbers:
Definition window_type.h:691
zoom_func.h
Functions related to zooming.
ScaleByZoom
int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZoomLevel::Min) When shifting right,...
Definition zoom_func.h:22
UnScaleByZoom
int UnScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZoomLevel::Min) When shifting right,...
Definition zoom_func.h:34
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition zoom_type.h:20
ZoomLevel::Begin
@ Begin
Begin for iteration.
ZoomLevel::In2x
@ In2x
Zoomed 2 times in.
ZoomLevel::End
@ End
End for iteration.
ZoomLevel::Out2x
@ Out2x
Zoomed 2 times out.
ZoomLevel::Normal
@ Normal
The normal zoom level.
ZoomLevel::In4x
@ In4x
Zoomed 4 times in.
ZoomLevel::Out8x
@ Out8x
Zoomed 8 times out.
ZoomLevel::Out4x
@ Out4x
Zoomed 4 times out.