OpenTTD Source: src/newgrf_debug_gui.cpp Source File

OpenTTD Source 14.0-beta1

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 <http://www.gnu.org/licenses/>.
6 */
7
10 #include "stdafx.h"
11 #include "core/backup_type.hpp"
12 #include "window_gui.h"
13 #include "window_func.h"
14 #include "random_access_file_type.h"
15 #include "spritecache.h"
16 #include "string_func.h"
17 #include "strings_func.h"
18 #include "textbuf_gui.h"
19 #include "vehicle_gui.h"
20 #include "zoom_func.h"
21
22 #include "engine_base.h"
23 #include "industry.h"
24 #include "object_base.h"
25 #include "station_base.h"
26 #include "town.h"
27 #include "vehicle_base.h"
28 #include "train.h"
29 #include "roadveh.h"
30
31 #include "newgrf_airport.h"
32 #include "newgrf_airporttiles.h"
33 #include "newgrf_debug.h"
34 #include "newgrf_object.h"
35 #include "newgrf_spritegroup.h"
36 #include "newgrf_station.h"
37 #include "newgrf_town.h"
38 #include "newgrf_railtype.h"
39 #include "newgrf_industries.h"
40 #include "newgrf_industrytiles.h"
41
42 #include "widgets/newgrf_debug_widget.h"
43
44 #include "table/strings.h"
45
46 #include "safeguards.h"
47
49 NewGrfDebugSpritePicker _newgrf_debug_sprite_picker = { SPM_NONE, nullptr, std::vector<SpriteID>() };
50
56 static inline uint GetFeatureIndex(uint window_number)
57 {
58 return GB(window_number, 0, 24);
59 }
60
68 static inline uint GetInspectWindowNumber(GrfSpecFeature feature, uint index)
69 {
70 assert((index >> 24) == 0);
71 return (feature << 24) | index;
72 }
73
78 enum NIType {
79 NIT_INT,
80 NIT_CARGO,
81 };
82
83 typedef const void *NIOffsetProc(const void *b);
84
86 struct NIProperty {
87 const char *name;
88 NIOffsetProc *offset_proc;
89 byte read_size;
90 byte prop;
91 byte type;
92 };
93
94
99 struct NICallback {
100 const char *name;
101 NIOffsetProc *offset_proc;
102 byte read_size;
103 byte cb_bit;
104 uint16_t cb_id;
105 };
107 static const int CBM_NO_BIT = UINT8_MAX;
108
110 struct NIVariable {
111 const char *name;
112 byte var;
113 };
114
116 class NIHelper {
117 public:
119 virtual ~NIHelper() = default;
120
126 virtual bool IsInspectable(uint index) const = 0;
127
133 virtual uint GetParent(uint index) const = 0;
134
140 virtual const void *GetInstance(uint index) const = 0;
141
147 virtual const void *GetSpec(uint index) const = 0;
148
153 virtual void SetStringParameters(uint index) const = 0;
154
160 virtual uint32_t GetGRFID(uint index) const = 0;
161
170 virtual uint Resolve(uint index, uint var, uint param, bool *avail) const = 0;
171
176 virtual bool PSAWithParameter() const
177 {
178 return false;
179 }
180
187 virtual uint GetPSASize([[maybe_unused]] uint index, [[maybe_unused]] uint32_t grfid) const
188 {
189 return 0;
190 }
191
198 virtual const int32_t *GetPSAFirstPosition([[maybe_unused]] uint index, [[maybe_unused]] uint32_t grfid) const
199 {
200 return nullptr;
201 }
202
203 protected:
209 void SetSimpleStringParameters(StringID string, uint32_t index) const
210 {
211 SetDParam(0, string);
212 SetDParam(1, index);
213 }
214
215
222 void SetObjectAtStringParameters(StringID string, uint32_t index, TileIndex tile) const
223 {
224 SetDParam(0, STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT);
225 SetDParam(1, string);
226 SetDParam(2, index);
227 SetDParam(3, tile);
228 }
229 };
230
231
233 struct NIFeature {
234 const NIProperty *properties;
235 const NICallback *callbacks;
236 const NIVariable *variables;
237 const NIHelper *helper;
238 };
239
240 /* Load all the NewGRF debug data; externalised as it is just a huge bunch of tables. */
241 #include "table/newgrf_debug_data.h"
242
248 static inline GrfSpecFeature GetFeatureNum(uint window_number)
249 {
250 return (GrfSpecFeature)GB(window_number, 24, 8);
251 }
252
258 static inline const NIFeature *GetFeature(uint window_number)
259 {
260 GrfSpecFeature idx = GetFeatureNum(window_number);
261 return idx < GSF_FAKE_END ? _nifeatures[idx] : nullptr;
262 }
263
270 static inline const NIHelper *GetFeatureHelper(uint window_number)
271 {
272 return GetFeature(window_number)->helper;
273 }
274
276 struct NewGRFInspectWindow : Window {
278 static uint32_t var60params[GSF_FAKE_END][0x20];
279
281 uint32_t caller_grfid;
282
284 uint chain_index;
285
287 byte current_edit_param;
288
289 Scrollbar *vscroll;
290
296 static bool HasVariableParameter(uint variable)
297 {
298 return IsInsideBS(variable, 0x60, 0x20);
299 }
300
305 void SetCallerGRFID(uint32_t grfid)
306 {
307 this->caller_grfid = grfid;
308 this->SetDirty();
309 }
310
314 bool HasChainIndex() const
315 {
316 GrfSpecFeature f = GetFeatureNum(this->window_number);
317 return f == GSF_TRAINS || f == GSF_ROADVEHICLES;
318 }
319
324 uint GetFeatureIndex() const
325 {
326 uint index = ::GetFeatureIndex(this->window_number);
327 if (this->chain_index > 0) {
328 assert(this->HasChainIndex());
329 const Vehicle *v = Vehicle::Get(index);
330 v = v->Move(this->chain_index);
331 if (v != nullptr) index = v->index;
332 }
333 return index;
334 }
335
339 void ValidateChainIndex()
340 {
341 if (this->chain_index == 0) return;
342
343 assert(this->HasChainIndex());
344
345 const Vehicle *v = Vehicle::Get(::GetFeatureIndex(this->window_number));
346 v = v->Move(this->chain_index);
347 if (v == nullptr) this->chain_index = 0;
348 }
349
350 NewGRFInspectWindow(WindowDesc *desc, WindowNumber wno) : Window(desc)
351 {
352 this->CreateNestedTree();
353 this->vscroll = this->GetScrollbar(WID_NGRFI_SCROLLBAR);
354 this->FinishInitNested(wno);
355
356 this->vscroll->SetCount(0);
357 this->SetWidgetDisabledState(WID_NGRFI_PARENT, GetFeatureHelper(this->window_number)->GetParent(this->GetFeatureIndex()) == UINT32_MAX);
358
359 this->OnInvalidateData(0, true);
360 }
361
362 void SetStringParameters(WidgetID widget) const override
363 {
364 if (widget != WID_NGRFI_CAPTION) return;
365
366 GetFeatureHelper(this->window_number)->SetStringParameters(this->GetFeatureIndex());
367 }
368
369 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
370 {
371 switch (widget) {
372 case WID_NGRFI_VEH_CHAIN: {
373 assert(this->HasChainIndex());
374 GrfSpecFeature f = GetFeatureNum(this->window_number);
375 size->height = std::max(size->height, GetVehicleImageCellSize((VehicleType)(VEH_TRAIN + (f - GSF_TRAINS)), EIT_IN_DEPOT).height + 2 + WidgetDimensions::scaled.bevel.Vertical());
376 break;
377 }
378
379 case WID_NGRFI_MAINPANEL:
380 resize->height = std::max(11, GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal);
381 resize->width = 1;
382
383 size->height = 5 * resize->height + WidgetDimensions::scaled.frametext.Vertical();
384 break;
385 }
386 }
387
394 void DrawString(const Rect &r, int offset, const std::string &string) const
395 {
396 offset -= this->vscroll->GetPosition();
397 if (offset < 0 || offset >= this->vscroll->GetCapacity()) return;
398
399 ::DrawString(r.Shrink(WidgetDimensions::scaled.frametext).Shrink(0, offset * this->resize.step_height, 0, 0), string, TC_BLACK);
400 }
401
406 void DrawVehicleChainWidget(const Rect &r) const
407 {
408 const Vehicle *v = Vehicle::Get(this->GetFeatureIndex());
409 int total_width = 0;
410 int sel_start = 0;
411 int sel_end = 0;
412 for (const Vehicle *u = v->First(); u != nullptr; u = u->Next()) {
413 if (u == v) sel_start = total_width;
414 switch (u->type) {
415 case VEH_TRAIN: total_width += Train::From(u)->GetDisplayImageWidth(); break;
416 case VEH_ROAD: total_width += RoadVehicle::From(u)->GetDisplayImageWidth(); break;
417 default: NOT_REACHED();
418 }
419 if (u == v) sel_end = total_width;
420 }
421
422 Rect br = r.Shrink(WidgetDimensions::scaled.bevel);
423 int width = br.Width();
424 int skip = 0;
425 if (total_width > width) {
426 int sel_center = (sel_start + sel_end) / 2;
427 if (sel_center > width / 2) skip = std::min(total_width - width, sel_center - width / 2);
428 }
429
430 GrfSpecFeature f = GetFeatureNum(this->window_number);
431 int h = GetVehicleImageCellSize((VehicleType)(VEH_TRAIN + (f - GSF_TRAINS)), EIT_IN_DEPOT).height;
432 int y = CenterBounds(br.top, br.bottom, h);
433 DrawVehicleImage(v->First(), br, INVALID_VEHICLE, EIT_IN_DETAILS, skip);
434
435 /* Highlight the articulated part (this is different to the whole-vehicle highlighting of DrawVehicleImage */
436 if (_current_text_dir == TD_RTL) {
437 DrawFrameRect(r.right - sel_end + skip, y, r.right - sel_start + skip, y + h, COLOUR_WHITE, FR_BORDERONLY);
438 } else {
439 DrawFrameRect(r.left + sel_start - skip, y, r.left + sel_end - skip, y + h, COLOUR_WHITE, FR_BORDERONLY);
440 }
441 }
442
447 void DrawMainPanelWidget(const Rect &r) const
448 {
449 uint index = this->GetFeatureIndex();
450 const NIFeature *nif = GetFeature(this->window_number);
451 const NIHelper *nih = nif->helper;
452 const void *base = nih->GetInstance(index);
453 const void *base_spec = nih->GetSpec(index);
454
455 uint i = 0;
456 if (nif->variables != nullptr) {
457 this->DrawString(r, i++, "Variables:");
458 for (const NIVariable *niv = nif->variables; niv->name != nullptr; niv++) {
459 bool avail = true;
460 uint param = HasVariableParameter(niv->var) ? NewGRFInspectWindow::var60params[GetFeatureNum(this->window_number)][niv->var - 0x60] : 0;
461 uint value = nih->Resolve(index, niv->var, param, &avail);
462
463 if (!avail) continue;
464
465 if (HasVariableParameter(niv->var)) {
466 this->DrawString(r, i++, fmt::format(" {:02x}[{:02x}]: {:08x} ({})", niv->var, param, value, niv->name));
467 } else {
468 this->DrawString(r, i++, fmt::format(" {:02x}: {:08x} ({})", niv->var, value, niv->name));
469 }
470 }
471 }
472
473 uint psa_size = nih->GetPSASize(index, this->caller_grfid);
474 const int32_t *psa = nih->GetPSAFirstPosition(index, this->caller_grfid);
475 if (psa_size != 0 && psa != nullptr) {
476 if (nih->PSAWithParameter()) {
477 this->DrawString(r, i++, fmt::format("Persistent storage [{:08X}]:", BSWAP32(this->caller_grfid)));
478 } else {
479 this->DrawString(r, i++, "Persistent storage:");
480 }
481 assert(psa_size % 4 == 0);
482 for (uint j = 0; j < psa_size; j += 4, psa += 4) {
483 this->DrawString(r, i++, fmt::format(" {}: {} {} {} {}", j, psa[0], psa[1], psa[2], psa[3]));
484 }
485 }
486
487 if (nif->properties != nullptr) {
488 this->DrawString(r, i++, "Properties:");
489 for (const NIProperty *nip = nif->properties; nip->name != nullptr; nip++) {
490 const void *ptr = nip->offset_proc(base);
491 uint value;
492 switch (nip->read_size) {
493 case 1: value = *(const uint8_t *)ptr; break;
494 case 2: value = *(const uint16_t *)ptr; break;
495 case 4: value = *(const uint32_t *)ptr; break;
496 default: NOT_REACHED();
497 }
498
499 StringID string;
500 SetDParam(0, value);
501 switch (nip->type) {
502 case NIT_INT:
503 string = STR_JUST_INT;
504 break;
505
506 case NIT_CARGO:
507 string = IsValidCargoID(value) ? CargoSpec::Get(value)->name : STR_QUANTITY_N_A;
508 break;
509
510 default:
511 NOT_REACHED();
512 }
513
514 this->DrawString(r, i++, fmt::format(" {:02x}: {} ({})", nip->prop, GetString(string), nip->name));
515 }
516 }
517
518 if (nif->callbacks != nullptr) {
519 this->DrawString(r, i++, "Callbacks:");
520 for (const NICallback *nic = nif->callbacks; nic->name != nullptr; nic++) {
521 if (nic->cb_bit != CBM_NO_BIT) {
522 const void *ptr = nic->offset_proc(base_spec);
523 uint value;
524 switch (nic->read_size) {
525 case 1: value = *(const uint8_t *)ptr; break;
526 case 2: value = *(const uint16_t *)ptr; break;
527 case 4: value = *(const uint32_t *)ptr; break;
528 default: NOT_REACHED();
529 }
530
531 if (!HasBit(value, nic->cb_bit)) continue;
532 this->DrawString(r, i++, fmt::format(" {:03x}: {}", nic->cb_id, nic->name));
533 } else {
534 this->DrawString(r, i++, fmt::format(" {:03x}: {} (unmasked)", nic->cb_id, nic->name));
535 }
536 }
537 }
538
539 /* Not nice and certainly a hack, but it beats duplicating
540 * this whole function just to count the actual number of
541 * elements. Especially because they need to be redrawn. */
542 const_cast<NewGRFInspectWindow*>(this)->vscroll->SetCount(i);
543 }
544
545 void DrawWidget(const Rect &r, WidgetID widget) const override
546 {
547 switch (widget) {
548 case WID_NGRFI_VEH_CHAIN:
549 this->DrawVehicleChainWidget(r);
550 break;
551
552 case WID_NGRFI_MAINPANEL:
553 this->DrawMainPanelWidget(r);
554 break;
555 }
556 }
557
558 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
559 {
560 switch (widget) {
561 case WID_NGRFI_PARENT: {
562 const NIHelper *nih = GetFeatureHelper(this->window_number);
563 uint index = nih->GetParent(this->GetFeatureIndex());
564 ::ShowNewGRFInspectWindow(GetFeatureNum(index), ::GetFeatureIndex(index), nih->GetGRFID(this->GetFeatureIndex()));
565 break;
566 }
567
568 case WID_NGRFI_VEH_PREV:
569 if (this->chain_index > 0) {
570 this->chain_index--;
571 this->InvalidateData();
572 }
573 break;
574
575 case WID_NGRFI_VEH_NEXT:
576 if (this->HasChainIndex()) {
577 uint index = this->GetFeatureIndex();
578 Vehicle *v = Vehicle::Get(index);
579 if (v != nullptr && v->Next() != nullptr) {
580 this->chain_index++;
581 this->InvalidateData();
582 }
583 }
584 break;
585
586 case WID_NGRFI_MAINPANEL: {
587 /* Does this feature have variables? */
588 const NIFeature *nif = GetFeature(this->window_number);
589 if (nif->variables == nullptr) return;
590
591 /* Get the line, make sure it's within the boundaries. */
592 int line = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NGRFI_MAINPANEL, WidgetDimensions::scaled.frametext.top);
593 if (line == INT_MAX) return;
594
595 /* Find the variable related to the line */
596 for (const NIVariable *niv = nif->variables; niv->name != nullptr; niv++, line--) {
597 if (line != 1) continue; // 1 because of the "Variables:" line
598
599 if (!HasVariableParameter(niv->var)) break;
600
601 this->current_edit_param = niv->var;
602 ShowQueryString(STR_EMPTY, STR_NEWGRF_INSPECT_QUERY_CAPTION, 9, this, CS_HEXADECIMAL, QSF_NONE);
603 }
604 }
605 }
606 }
607
608 void OnQueryTextFinished(char *str) override
609 {
610 if (StrEmpty(str)) return;
611
612 NewGRFInspectWindow::var60params[GetFeatureNum(this->window_number)][this->current_edit_param - 0x60] = std::strtol(str, nullptr, 16);
613 this->SetDirty();
614 }
615
616 void OnResize() override
617 {
618 this->vscroll->SetCapacityFromWidget(this, WID_NGRFI_MAINPANEL, WidgetDimensions::scaled.frametext.Vertical());
619 }
620
626 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
627 {
628 if (!gui_scope) return;
629 if (this->HasChainIndex()) {
630 this->ValidateChainIndex();
631 this->SetWidgetDisabledState(WID_NGRFI_VEH_PREV, this->chain_index == 0);
632 Vehicle *v = Vehicle::Get(this->GetFeatureIndex());
633 this->SetWidgetDisabledState(WID_NGRFI_VEH_NEXT, v == nullptr || v->Next() == nullptr);
634 }
635 }
636 };
637
638 /* static */ uint32_t NewGRFInspectWindow::var60params[GSF_FAKE_END][0x20] = { {0} }; // Use spec to have 0s in whole array
639
640 static constexpr NWidgetPart _nested_newgrf_inspect_chain_widgets[] = {
641 NWidget(NWID_HORIZONTAL),
642 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
643 NWidget(WWT_CAPTION, COLOUR_GREY, WID_NGRFI_CAPTION), SetDataTip(STR_NEWGRF_INSPECT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
644 NWidget(WWT_SHADEBOX, COLOUR_GREY),
645 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
646 NWidget(WWT_STICKYBOX, COLOUR_GREY),
647 EndContainer(),
648 NWidget(WWT_PANEL, COLOUR_GREY),
649 NWidget(NWID_HORIZONTAL),
650 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_NGRFI_VEH_PREV), SetDataTip(AWV_DECREASE, STR_NULL),
651 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_NGRFI_VEH_NEXT), SetDataTip(AWV_INCREASE, STR_NULL),
652 NWidget(WWT_EMPTY, COLOUR_GREY, WID_NGRFI_VEH_CHAIN), SetFill(1, 0), SetResize(1, 0),
653 EndContainer(),
654 EndContainer(),
655 NWidget(NWID_HORIZONTAL),
656 NWidget(WWT_PANEL, COLOUR_GREY, WID_NGRFI_MAINPANEL), SetMinimalSize(300, 0), SetScrollbar(WID_NGRFI_SCROLLBAR), EndContainer(),
657 NWidget(NWID_VERTICAL),
658 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_NGRFI_SCROLLBAR),
659 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
660 EndContainer(),
661 EndContainer(),
662 };
663
664 static constexpr NWidgetPart _nested_newgrf_inspect_widgets[] = {
665 NWidget(NWID_HORIZONTAL),
666 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
667 NWidget(WWT_CAPTION, COLOUR_GREY, WID_NGRFI_CAPTION), SetDataTip(STR_NEWGRF_INSPECT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
668 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NGRFI_PARENT), SetDataTip(STR_NEWGRF_INSPECT_PARENT_BUTTON, STR_NEWGRF_INSPECT_PARENT_TOOLTIP),
669 NWidget(WWT_SHADEBOX, COLOUR_GREY),
670 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
671 NWidget(WWT_STICKYBOX, COLOUR_GREY),
672 EndContainer(),
673 NWidget(NWID_HORIZONTAL),
674 NWidget(WWT_PANEL, COLOUR_GREY, WID_NGRFI_MAINPANEL), SetMinimalSize(300, 0), SetScrollbar(WID_NGRFI_SCROLLBAR), EndContainer(),
675 NWidget(NWID_VERTICAL),
676 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_NGRFI_SCROLLBAR),
677 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
678 EndContainer(),
679 EndContainer(),
680 };
681
682 static WindowDesc _newgrf_inspect_chain_desc(__FILE__, __LINE__,
683 WDP_AUTO, "newgrf_inspect_chain", 400, 300,
684 WC_NEWGRF_INSPECT, WC_NONE,
685 0,
686 std::begin(_nested_newgrf_inspect_chain_widgets), std::end(_nested_newgrf_inspect_chain_widgets)
687 );
688
689 static WindowDesc _newgrf_inspect_desc(__FILE__, __LINE__,
690 WDP_AUTO, "newgrf_inspect", 400, 300,
691 WC_NEWGRF_INSPECT, WC_NONE,
692 0,
693 std::begin(_nested_newgrf_inspect_widgets), std::end(_nested_newgrf_inspect_widgets)
694 );
695
705 void ShowNewGRFInspectWindow(GrfSpecFeature feature, uint index, const uint32_t grfid)
706 {
707 if (!IsNewGRFInspectable(feature, index)) return;
708
709 WindowNumber wno = GetInspectWindowNumber(feature, index);
710 WindowDesc *desc = (feature == GSF_TRAINS || feature == GSF_ROADVEHICLES) ? &_newgrf_inspect_chain_desc : &_newgrf_inspect_desc;
711 NewGRFInspectWindow *w = AllocateWindowDescFront<NewGRFInspectWindow>(desc, wno, true);
712 w->SetCallerGRFID(grfid);
713 }
714
723 void InvalidateNewGRFInspectWindow(GrfSpecFeature feature, uint index)
724 {
725 if (feature == GSF_INVALID) return;
726
727 WindowNumber wno = GetInspectWindowNumber(feature, index);
728 InvalidateWindowData(WC_NEWGRF_INSPECT, wno);
729 }
730
739 void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
740 {
741 if (feature == GSF_INVALID) return;
742
743 WindowNumber wno = GetInspectWindowNumber(feature, index);
744 CloseWindowById(WC_NEWGRF_INSPECT, wno);
745
746 /* Reinitialise the land information window to remove the "debug" sprite if needed.
747 * Note: Since we might be called from a command here, it is important to not execute
748 * the invalidation immediately. The landinfo window tests commands itself. */
749 InvalidateWindowData(WC_LAND_INFO, 0, 1);
750 }
751
761 bool IsNewGRFInspectable(GrfSpecFeature feature, uint index)
762 {
763 const NIFeature *nif = GetFeature(GetInspectWindowNumber(feature, index));
764 if (nif == nullptr) return false;
765 return nif->helper->IsInspectable(index);
766 }
767
773 GrfSpecFeature GetGrfSpecFeature(TileIndex tile)
774 {
775 switch (GetTileType(tile)) {
776 default: return GSF_INVALID;
777 case MP_RAILWAY: return GSF_RAILTYPES;
778 case MP_ROAD: return IsLevelCrossing(tile) ? GSF_RAILTYPES : GSF_ROADTYPES;
779 case MP_HOUSE: return GSF_HOUSES;
780 case MP_INDUSTRY: return GSF_INDUSTRYTILES;
781 case MP_OBJECT: return GSF_OBJECTS;
782
783 case MP_STATION:
784 switch (GetStationType(tile)) {
785 case STATION_RAIL: return GSF_STATIONS;
786 case STATION_AIRPORT: return GSF_AIRPORTTILES;
787 case STATION_BUS: return GSF_ROADSTOPS;
788 case STATION_TRUCK: return GSF_ROADSTOPS;
789 default: return GSF_INVALID;
790 }
791 }
792 }
793
799 GrfSpecFeature GetGrfSpecFeature(VehicleType type)
800 {
801 switch (type) {
802 case VEH_TRAIN: return GSF_TRAINS;
803 case VEH_ROAD: return GSF_ROADVEHICLES;
804 case VEH_SHIP: return GSF_SHIPS;
805 case VEH_AIRCRAFT: return GSF_AIRCRAFT;
806 default: return GSF_INVALID;
807 }
808 }
809
810
811
812 /**** Sprite Aligner ****/
813
815 struct SpriteAlignerWindow : Window {
816 typedef std::pair<int16_t, int16_t> XyOffs;
817
818 SpriteID current_sprite;
819 Scrollbar *vscroll;
820 std::map<SpriteID, XyOffs> offs_start_map;
821
822 static inline ZoomLevel zoom = ZOOM_LVL_END;
823 static bool centre;
824 static bool crosshair;
825
826 SpriteAlignerWindow(WindowDesc *desc, WindowNumber wno) : Window(desc)
827 {
828 /* On first opening, set initial zoom to current zoom level. */
829 if (SpriteAlignerWindow::zoom == ZOOM_LVL_END) SpriteAlignerWindow::zoom = _gui_zoom;
830 SpriteAlignerWindow::zoom = Clamp(SpriteAlignerWindow::zoom, _settings_client.gui.zoom_min, _settings_client.gui.zoom_max);
831
832 this->CreateNestedTree();
833 this->vscroll = this->GetScrollbar(WID_SA_SCROLLBAR);
834 this->vscroll->SetCount(_newgrf_debug_sprite_picker.sprites.size());
835 this->FinishInitNested(wno);
836
837 this->SetWidgetLoweredState(WID_SA_CENTRE, SpriteAlignerWindow::centre);
838 this->SetWidgetLoweredState(WID_SA_CROSSHAIR, SpriteAlignerWindow::crosshair);
839
840 /* Oh yes, we assume there is at least one normal sprite! */
841 while (GetSpriteType(this->current_sprite) != SpriteType::Normal) this->current_sprite++;
842
843 this->InvalidateData(0, true);
844 }
845
846 void SetStringParameters(WidgetID widget) const override
847 {
848 const Sprite *spr = GetSprite(this->current_sprite, SpriteType::Normal);
849 switch (widget) {
850 case WID_SA_CAPTION:
851 SetDParam(0, this->current_sprite);
852 SetDParamStr(1, GetOriginFile(this->current_sprite)->GetSimplifiedFilename());
853 break;
854
855 case WID_SA_OFFSETS_ABS:
856 SetDParam(0, UnScaleByZoom(spr->x_offs, SpriteAlignerWindow::zoom));
857 SetDParam(1, UnScaleByZoom(spr->y_offs, SpriteAlignerWindow::zoom));
858 break;
859
860 case WID_SA_OFFSETS_REL: {
861 /* Relative offset is new absolute offset - starting absolute offset.
862 * Show 0, 0 as the relative offsets if entry is not in the map (meaning they have not been changed yet).
863 */
864 const auto key_offs_pair = this->offs_start_map.find(this->current_sprite);
865 if (key_offs_pair != this->offs_start_map.end()) {
866 SetDParam(0, UnScaleByZoom(spr->x_offs - key_offs_pair->second.first, SpriteAlignerWindow::zoom));
867 SetDParam(1, UnScaleByZoom(spr->y_offs - key_offs_pair->second.second, SpriteAlignerWindow::zoom));
868 } else {
869 SetDParam(0, 0);
870 SetDParam(1, 0);
871 }
872 break;
873 }
874
875 default:
876 break;
877 }
878 }
879
880 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
881 {
882 switch (widget) {
883 case WID_SA_SPRITE:
884 size->height = ScaleGUITrad(200);
885 break;
886 case WID_SA_LIST:
887 SetDParamMaxDigits(0, 6);
888 size->width = GetStringBoundingBox(STR_JUST_COMMA).width + padding.width;
889 resize->height = GetCharacterHeight(FS_NORMAL) + padding.height;
890 resize->width = 1;
891 fill->height = resize->height;
892 break;
893 default:
894 break;
895 }
896 }
897
898 void DrawWidget(const Rect &r, WidgetID widget) const override
899 {
900 switch (widget) {
901 case WID_SA_SPRITE: {
902 /* Center the sprite ourselves */
903 const Sprite *spr = GetSprite(this->current_sprite, SpriteType::Normal);
904 Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
905 int x;
906 int y;
907 if (SpriteAlignerWindow::centre) {
908 x = -UnScaleByZoom(spr->x_offs, SpriteAlignerWindow::zoom) + (ir.Width() - UnScaleByZoom(spr->width, SpriteAlignerWindow::zoom)) / 2;
909 y = -UnScaleByZoom(spr->y_offs, SpriteAlignerWindow::zoom) + (ir.Height() - UnScaleByZoom(spr->height, SpriteAlignerWindow::zoom)) / 2;
910 } else {
911 x = ir.Width() / 2;
912 y = ir.Height() / 2;
913 }
914
915 DrawPixelInfo new_dpi;
916 if (!FillDrawPixelInfo(&new_dpi, ir)) break;
917 AutoRestoreBackup dpi_backup(_cur_dpi, &new_dpi);
918
919 DrawSprite(this->current_sprite, PAL_NONE, x, y, nullptr, SpriteAlignerWindow::zoom);
920
921 Rect outline = {0, 0, UnScaleByZoom(spr->width, SpriteAlignerWindow::zoom) - 1, UnScaleByZoom(spr->height, SpriteAlignerWindow::zoom) - 1};
922 outline = outline.Translate(x + UnScaleByZoom(spr->x_offs, SpriteAlignerWindow::zoom), y + UnScaleByZoom(spr->y_offs, SpriteAlignerWindow::zoom));
923 DrawRectOutline(outline.Expand(1), PC_LIGHT_BLUE, 1, 1);
924
925 if (SpriteAlignerWindow::crosshair) {
926 GfxDrawLine(x, 0, x, ir.Height() - 1, PC_WHITE, 1, 1);
927 GfxDrawLine(0, y, ir.Width() - 1, y, PC_WHITE, 1, 1);
928 }
929 break;
930 }
931
932 case WID_SA_LIST: {
933 const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
934 int step_size = nwid->resize_y;
935
936 std::vector<SpriteID> &list = _newgrf_debug_sprite_picker.sprites;
937 int max = std::min<int>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), (uint)list.size());
938
939 Rect ir = r.Shrink(WidgetDimensions::scaled.matrix);
940 for (int i = this->vscroll->GetPosition(); i < max; i++) {
941 SetDParam(0, list[i]);
942 DrawString(ir, STR_JUST_COMMA, list[i] == this->current_sprite ? TC_WHITE : TC_BLACK, SA_RIGHT | SA_FORCE);
943 ir.top += step_size;
944 }
945 break;
946 }
947 }
948 }
949
950 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
951 {
952 switch (widget) {
953 case WID_SA_PREVIOUS:
954 do {
955 this->current_sprite = (this->current_sprite == 0 ? GetMaxSpriteID() : this->current_sprite) - 1;
956 } while (GetSpriteType(this->current_sprite) != SpriteType::Normal);
957 this->SetDirty();
958 break;
959
960 case WID_SA_GOTO:
961 ShowQueryString(STR_EMPTY, STR_SPRITE_ALIGNER_GOTO_CAPTION, 7, this, CS_NUMERAL, QSF_NONE);
962 break;
963
964 case WID_SA_NEXT:
965 do {
966 this->current_sprite = (this->current_sprite + 1) % GetMaxSpriteID();
967 } while (GetSpriteType(this->current_sprite) != SpriteType::Normal);
968 this->SetDirty();
969 break;
970
971 case WID_SA_PICKER:
972 this->LowerWidget(WID_SA_PICKER);
973 _newgrf_debug_sprite_picker.mode = SPM_WAIT_CLICK;
974 this->SetDirty();
975 break;
976
977 case WID_SA_LIST: {
978 auto it = this->vscroll->GetScrolledItemFromWidget(_newgrf_debug_sprite_picker.sprites, pt.y, this, widget);
979 if (it != _newgrf_debug_sprite_picker.sprites.end()) {
980 SpriteID spr = *it;
981 if (GetSpriteType(spr) == SpriteType::Normal) this->current_sprite = spr;
982 }
983 this->SetDirty();
984 break;
985 }
986
987 case WID_SA_UP:
988 case WID_SA_DOWN:
989 case WID_SA_LEFT:
990 case WID_SA_RIGHT: {
991 /*
992 * Yes... this is a hack.
993 *
994 * No... I don't think it is useful to make this less of a hack.
995 *
996 * If you want to align sprites, you just need the number. Generally
997 * the sprite caches are big enough to not remove the sprite from the
998 * cache. If that's not the case, just let the NewGRF developer
999 * increase the cache size instead of storing thousands of offsets
1000 * for the incredibly small chance that it's actually going to be
1001 * used by someone and the sprite cache isn't big enough for that
1002 * particular NewGRF developer.
1003 */
1004 Sprite *spr = const_cast<Sprite *>(GetSprite(this->current_sprite, SpriteType::Normal));
1005
1006 /* Remember the original offsets of the current sprite, if not already in mapping. */
1007 if (this->offs_start_map.count(this->current_sprite) == 0) {
1008 this->offs_start_map[this->current_sprite] = XyOffs(spr->x_offs, spr->y_offs);
1009 }
1010 int amt = ScaleByZoom(_ctrl_pressed ? 8 : 1, SpriteAlignerWindow::zoom);
1011 switch (widget) {
1012 /* Move eight units at a time if ctrl is pressed. */
1013 case WID_SA_UP: spr->y_offs -= amt; break;
1014 case WID_SA_DOWN: spr->y_offs += amt; break;
1015 case WID_SA_LEFT: spr->x_offs -= amt; break;
1016 case WID_SA_RIGHT: spr->x_offs += amt; break;
1017 }
1018 /* Of course, we need to redraw the sprite, but where is it used?
1019 * Everywhere is a safe bet. */
1020 MarkWholeScreenDirty();
1021 break;
1022 }
1023
1024 case WID_SA_RESET_REL:
1025 /* Reset the starting offsets for the current sprite. */
1026 this->offs_start_map.erase(this->current_sprite);
1027 this->SetDirty();
1028 break;
1029
1030 case WID_SA_CENTRE:
1031 SpriteAlignerWindow::centre = !SpriteAlignerWindow::centre;
1032 this->SetWidgetLoweredState(widget, SpriteAlignerWindow::centre);
1033 this->SetDirty();
1034 break;
1035
1036 case WID_SA_CROSSHAIR:
1037 SpriteAlignerWindow::crosshair = !SpriteAlignerWindow::crosshair;
1038 this->SetWidgetLoweredState(widget, SpriteAlignerWindow::crosshair);
1039 this->SetDirty();
1040 break;
1041
1042 default:
1043 if (IsInsideBS(widget, WID_SA_ZOOM, ZOOM_LVL_END)) {
1044 SpriteAlignerWindow::zoom = ZoomLevel(widget - WID_SA_ZOOM);
1045 this->InvalidateData(0, true);
1046 }
1047 break;
1048 }
1049 }
1050
1051 void OnQueryTextFinished(char *str) override
1052 {
1053 if (StrEmpty(str)) return;
1054
1055 this->current_sprite = atoi(str);
1056 if (this->current_sprite >= GetMaxSpriteID()) this->current_sprite = 0;
1057 while (GetSpriteType(this->current_sprite) != SpriteType::Normal) {
1058 this->current_sprite = (this->current_sprite + 1) % GetMaxSpriteID();
1059 }
1060 this->SetDirty();
1061 }
1062
1068 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1069 {
1070 if (!gui_scope) return;
1071 if (data == 1) {
1072 /* Sprite picker finished */
1073 this->RaiseWidget(WID_SA_PICKER);
1074 this->vscroll->SetCount(_newgrf_debug_sprite_picker.sprites.size());
1075 }
1076
1077 SpriteAlignerWindow::zoom = Clamp(SpriteAlignerWindow::zoom, _settings_client.gui.zoom_min, _settings_client.gui.zoom_max);
1078 for (ZoomLevel z = ZOOM_LVL_NORMAL; z < ZOOM_LVL_END; z++) {
1079 this->SetWidgetsDisabledState(z < _settings_client.gui.zoom_min || z > _settings_client.gui.zoom_max, WID_SA_ZOOM + z);
1080 this->SetWidgetsLoweredState(SpriteAlignerWindow::zoom == z, WID_SA_ZOOM + z);
1081 }
1082 }
1083
1084 void OnResize() override
1085 {
1086 this->vscroll->SetCapacityFromWidget(this, WID_SA_LIST);
1087 }
1088 };
1089
1090 bool SpriteAlignerWindow::centre = true;
1091 bool SpriteAlignerWindow::crosshair = true;
1092
1093 static constexpr NWidgetPart _nested_sprite_aligner_widgets[] = {
1094 NWidget(NWID_HORIZONTAL),
1095 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1096 NWidget(WWT_CAPTION, COLOUR_GREY, WID_SA_CAPTION), SetDataTip(STR_SPRITE_ALIGNER_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1097 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1098 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1099 EndContainer(),
1100 NWidget(WWT_PANEL, COLOUR_GREY),
1101 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0), SetPadding(WidgetDimensions::unscaled.sparse_resize),
1102 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0),
1103 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1104 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SA_PREVIOUS), SetDataTip(STR_SPRITE_ALIGNER_PREVIOUS_BUTTON, STR_SPRITE_ALIGNER_PREVIOUS_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1105 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SA_GOTO), SetDataTip(STR_SPRITE_ALIGNER_GOTO_BUTTON, STR_SPRITE_ALIGNER_GOTO_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1106 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SA_NEXT), SetDataTip(STR_SPRITE_ALIGNER_NEXT_BUTTON, STR_SPRITE_ALIGNER_NEXT_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1107 EndContainer(),
1108 NWidget(NWID_HORIZONTAL),
1109 NWidget(NWID_SPACER), SetFill(1, 1), SetResize(1, 0),
1110 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SA_UP), SetDataTip(SPR_ARROW_UP, STR_SPRITE_ALIGNER_MOVE_TOOLTIP), SetResize(0, 0), SetMinimalSize(11, 11),
1111 NWidget(NWID_SPACER), SetFill(1, 1), SetResize(1, 0),
1112 EndContainer(),
1113 NWidget(NWID_HORIZONTAL_LTR), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
1114 NWidget(NWID_VERTICAL),
1115 NWidget(NWID_SPACER), SetFill(1, 1), SetResize(0, 1),
1116 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SA_LEFT), SetDataTip(SPR_ARROW_LEFT, STR_SPRITE_ALIGNER_MOVE_TOOLTIP), SetResize(0, 0), SetMinimalSize(11, 11),
1117 NWidget(NWID_SPACER), SetFill(1, 1), SetResize(0, 1),
1118 EndContainer(),
1119 NWidget(WWT_PANEL, COLOUR_DARK_BLUE, WID_SA_SPRITE), SetDataTip(STR_NULL, STR_SPRITE_ALIGNER_SPRITE_TOOLTIP), SetResize(1, 1), SetFill(1, 1),
1120 EndContainer(),
1121 NWidget(NWID_VERTICAL),
1122 NWidget(NWID_SPACER), SetFill(1, 1), SetResize(0, 1),
1123 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SA_RIGHT), SetDataTip(SPR_ARROW_RIGHT, STR_SPRITE_ALIGNER_MOVE_TOOLTIP), SetResize(0, 0), SetMinimalSize(11, 11),
1124 NWidget(NWID_SPACER), SetFill(1, 1), SetResize(0, 1),
1125 EndContainer(),
1126 EndContainer(),
1127 NWidget(NWID_HORIZONTAL),
1128 NWidget(NWID_SPACER), SetFill(1, 1), SetResize(1, 0),
1129 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SA_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_SPRITE_ALIGNER_MOVE_TOOLTIP), SetResize(0, 0), SetMinimalSize(11, 11),
1130 NWidget(NWID_SPACER), SetFill(1, 1), SetResize(1, 0),
1131 EndContainer(),
1132 NWidget(WWT_LABEL, COLOUR_GREY, WID_SA_OFFSETS_ABS), SetDataTip(STR_SPRITE_ALIGNER_OFFSETS_ABS, STR_NULL), SetFill(1, 0), SetResize(1, 0),
1133 NWidget(WWT_LABEL, COLOUR_GREY, WID_SA_OFFSETS_REL), SetDataTip(STR_SPRITE_ALIGNER_OFFSETS_REL, STR_NULL), SetFill(1, 0), SetResize(1, 0),
1134 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1135 NWidget(WWT_TEXTBTN_2, COLOUR_GREY, WID_SA_CENTRE), SetDataTip(STR_SPRITE_ALIGNER_CENTRE_OFFSET, STR_NULL), SetFill(1, 0), SetResize(1, 0),
1136 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SA_RESET_REL), SetDataTip(STR_SPRITE_ALIGNER_RESET_BUTTON, STR_SPRITE_ALIGNER_RESET_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1137 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SA_CROSSHAIR), SetDataTip(STR_SPRITE_ALIGNER_CROSSHAIR, STR_NULL), SetFill(1, 0), SetResize(1, 0),
1138 EndContainer(),
1139 EndContainer(),
1140 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0),
1141 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SA_PICKER), SetDataTip(STR_SPRITE_ALIGNER_PICKER_BUTTON, STR_SPRITE_ALIGNER_PICKER_TOOLTIP), SetFill(1, 0),
1142 NWidget(NWID_HORIZONTAL),
1143 NWidget(WWT_MATRIX, COLOUR_GREY, WID_SA_LIST), SetResize(1, 1), SetMatrixDataTip(1, 0, STR_NULL), SetFill(1, 1), SetScrollbar(WID_SA_SCROLLBAR),
1144 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SA_SCROLLBAR),
1145 EndContainer(),
1146 NWidget(NWID_VERTICAL),
1147 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SA_ZOOM + ZOOM_LVL_NORMAL), SetDataTip(STR_CONFIG_SETTING_ZOOM_LVL_MIN, STR_NULL), SetFill(1, 0),
1148 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SA_ZOOM + ZOOM_LVL_OUT_2X), SetDataTip(STR_CONFIG_SETTING_ZOOM_LVL_IN_2X, STR_NULL), SetFill(1, 0),
1149 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SA_ZOOM + ZOOM_LVL_OUT_4X), SetDataTip(STR_CONFIG_SETTING_ZOOM_LVL_NORMAL, STR_NULL), SetFill(1, 0),
1150 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SA_ZOOM + ZOOM_LVL_OUT_8X), SetDataTip(STR_CONFIG_SETTING_ZOOM_LVL_OUT_2X, STR_NULL), SetFill(1, 0),
1151 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SA_ZOOM + ZOOM_LVL_OUT_16X), SetDataTip(STR_CONFIG_SETTING_ZOOM_LVL_OUT_4X, STR_NULL), SetFill(1, 0),
1152 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SA_ZOOM + ZOOM_LVL_OUT_32X), SetDataTip(STR_CONFIG_SETTING_ZOOM_LVL_OUT_8X, STR_NULL), SetFill(1, 0),
1153 EndContainer(),
1154 EndContainer(),
1155 EndContainer(),
1156 NWidget(NWID_HORIZONTAL),
1157 NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
1158 NWidget(WWT_RESIZEBOX, COLOUR_GREY), SetDataTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
1159 EndContainer(),
1160 EndContainer(),
1161 };
1162
1163 static WindowDesc _sprite_aligner_desc(__FILE__, __LINE__,
1164 WDP_AUTO, "sprite_aligner", 400, 300,
1165 WC_SPRITE_ALIGNER, WC_NONE,
1166 0,
1167 std::begin(_nested_sprite_aligner_widgets), std::end(_nested_sprite_aligner_widgets)
1168 );
1169
1173 void ShowSpriteAlignerWindow()
1174 {
1175 AllocateWindowDescFront<SpriteAlignerWindow>(&_sprite_aligner_desc, 0);
1176 }
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
Train::GetDisplayImageWidth
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a train vehicle image in the GUI.
Definition: train_cmd.cpp:460
Sprite::height
uint16_t height
Height of the sprite.
Definition: spritecache.h:18
SpriteAlignerWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: newgrf_debug_gui.cpp:1084
MP_HOUSE
@ MP_HOUSE
A house by a town.
Definition: tile_type.h:51
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1141
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:3200
newgrf_station.h
VehicleCellSize::height
uint height
Vehicle cell height.
Definition: vehicle_gui.h:84
Rect::Height
int Height() const
Get height of Rect.
Definition: geometry_type.hpp:91
Pool::PoolItem<&_vehicle_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:335
vehicle_gui.h
NewGRFInspectWindow::chain_index
uint chain_index
For ground vehicles: Index in vehicle chain.
Definition: newgrf_debug_gui.cpp:284
ZOOM_LVL_OUT_2X
@ ZOOM_LVL_OUT_2X
Zoomed 2 times out.
Definition: zoom_type.h:23
WID_SA_NEXT
@ WID_SA_NEXT
Skip to the next sprite.
Definition: newgrf_debug_widget.h:29
Sprite::x_offs
int16_t x_offs
Number of pixels to shift the sprite to the right.
Definition: spritecache.h:20
SetDParamMaxDigits
void SetDParamMaxDigits(size_t n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:143
train.h
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
newgrf_debug_widget.h
CBM_NO_BIT
static const int CBM_NO_BIT
Mask to show no bit needs to be enabled for the callback.
Definition: newgrf_debug_gui.cpp:107
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:68
NewGRFInspectWindow::DrawVehicleChainWidget
void DrawVehicleChainWidget(const Rect &r) const
Helper function to draw the vehicle chain widget.
Definition: newgrf_debug_gui.cpp:406
WC_LAND_INFO
@ WC_LAND_INFO
Land info window; Window numbers:
Definition: window_type.h:150
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
NIT_INT
@ NIT_INT
The property is a simple integer.
Definition: newgrf_debug_gui.cpp:79
Vehicle::Next
Vehicle * Next() const
Get the next vehicle of this vehicle.
Definition: vehicle_base.h:627
ZOOM_LVL_END
@ ZOOM_LVL_END
End for iteration.
Definition: zoom_type.h:28
ZOOM_LVL_OUT_16X
@ ZOOM_LVL_OUT_16X
Zoomed 16 times out.
Definition: zoom_type.h:26
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
PC_WHITE
static const uint8_t PC_WHITE
White palette colour.
Definition: palette_func.h:58
NewGRFInspectWindow::HasChainIndex
bool HasChainIndex() const
Check whether this feature has chain index, i.e.
Definition: newgrf_debug_gui.cpp:314
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition: widget_type.h:59
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:1141
NICallback
Representation of the available callbacks with information on when they actually apply.
Definition: newgrf_debug_gui.cpp:99
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:67
GB
constexpr static debug_inline 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
NIType
NIType
The type of a property to show.
Definition: newgrf_debug_gui.cpp:78
NewGrfDebugSpritePicker::sprites
std::vector< SpriteID > sprites
Sprites found.
Definition: newgrf_debug.h:28
NewGrfDebugSpritePicker::mode
NewGrfDebugSpritePickerMode mode
Current state.
Definition: newgrf_debug.h:26
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:234
InvalidateNewGRFInspectWindow
void InvalidateNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Invalidate the inspect window for a given feature and index.
Definition: newgrf_debug_gui.cpp:723
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:134
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
RWV_HIDE_BEVEL
@ RWV_HIDE_BEVEL
Bevel of resize box is hidden.
Definition: widget_type.h:42
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:61
NWID_HORIZONTAL_LTR
@ NWID_HORIZONTAL_LTR
Horizontal container that doesn't change the order of the widgets for RTL languages.
Definition: widget_type.h:78
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1151
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1174
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:37
MP_RAILWAY
@ MP_RAILWAY
A railway.
Definition: tile_type.h:49
vehicle_base.h
zoom_func.h
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:2334
GetFeatureHelper
static const NIHelper * GetFeatureHelper(uint window_number)
Get the NIHelper related to the window number.
Definition: newgrf_debug_gui.cpp:270
NIFeature::properties
const NIProperty * properties
The properties associated with this feature.
Definition: newgrf_debug_gui.cpp:234
newgrf_airport.h
NIHelper::Resolve
virtual uint Resolve(uint index, uint var, uint param, bool *avail) const =0
Resolve (action2) variable for a given index.
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:19
IsLevelCrossing
bool IsLevelCrossing(Tile t)
Return whether a tile is a level crossing.
Definition: road_map.h:85
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
EIT_IN_DETAILS
@ EIT_IN_DETAILS
Vehicle drawn in vehicle details, refit window, ...
Definition: vehicle_type.h:88
WID_SA_DOWN
@ WID_SA_DOWN
Move the sprite down.
Definition: newgrf_debug_widget.h:33
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:281
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition: widget_type.h:50
MP_INDUSTRY
@ MP_INDUSTRY
Part of an industry.
Definition: tile_type.h:56
newgrf_debug.h
town.h
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:69
WWT_PUSHARROWBTN
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:112
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
NICallback::name
const char * name
The human readable name of the callback.
Definition: newgrf_debug_gui.cpp:100
GSF_INVALID
@ GSF_INVALID
An invalid spec feature.
Definition: newgrf.h:93
Rect::Expand
Rect Expand(int s) const
Copy and expand Rect by s pixels.
Definition: geometry_type.hpp:153
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:340
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:240
GetSpriteType
SpriteType GetSpriteType(SpriteID sprite)
Get the sprite type of a given sprite.
Definition: spritecache.cpp:150
WID_SA_LEFT
@ WID_SA_LEFT
Move the sprite to the left.
Definition: newgrf_debug_widget.h:31
_gui_zoom
ZoomLevel _gui_zoom
GUI Zoom level.
Definition: gfx.cpp:60
NewGRFInspectWindow::current_edit_param
byte current_edit_param
The currently edited parameter, to update the right one.
Definition: newgrf_debug_gui.cpp:287
WID_NGRFI_PARENT
@ WID_NGRFI_PARENT
Inspect the parent.
Definition: newgrf_debug_widget.h:16
NIFeature::variables
const NIVariable * variables
The variables associated with this feature.
Definition: newgrf_debug_gui.cpp:236
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:678
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:315
StrEmpty
bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:56
WID_SA_SPRITE
@ WID_SA_SPRITE
The actual sprite.
Definition: newgrf_debug_widget.h:34
GUISettings::zoom_max
ZoomLevel zoom_max
maximum zoom out level
Definition: settings_type.h:158
MP_ROAD
@ MP_ROAD
A tile with road (or tram tracks)
Definition: tile_type.h:50
NIHelper
Helper class to wrap some functionality/queries in.
Definition: newgrf_debug_gui.cpp:116
GetVehicleImageCellSize
VehicleCellSize GetVehicleImageCellSize(VehicleType type, EngineImageType image_type)
Get the GUI cell size for a vehicle image.
Definition: depot_gui.cpp:161
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1038
Scrollbar::GetPosition
uint16_t GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:720
IsNewGRFInspectable
bool IsNewGRFInspectable(GrfSpecFeature feature, uint index)
Can we inspect the data given a certain feature and index.
Definition: newgrf_debug_gui.cpp:761
NIProperty
Representation of the data from a NewGRF property.
Definition: newgrf_debug_gui.cpp:86
NIProperty::read_size
byte read_size
Number of bytes (i.e. byte, word, dword etc)
Definition: newgrf_debug_gui.cpp:89
DeleteNewGRFInspectWindow
void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Delete inspect window for a given feature and index.
Definition: newgrf_debug_gui.cpp:739
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:820
textbuf_gui.h
object_base.h
random_access_file_type.h
GetTileType
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition: tile_map.h:96
WindowDesc
High level window description.
Definition: window_gui.h:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
NICallback::cb_id
uint16_t cb_id
The number of the callback.
Definition: newgrf_debug_gui.cpp:104
ScaleGUITrad
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:117
window_gui.h
newgrf_airporttiles.h
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:508
NIHelper::GetPSASize
virtual uint GetPSASize([[maybe_unused]] uint index, [[maybe_unused]] uint32_t grfid) const
Allows to know the size of the persistent storage.
Definition: newgrf_debug_gui.cpp:187
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:1188
NIHelper::IsInspectable
virtual bool IsInspectable(uint index) const =0
Is the item with the given index inspectable?
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
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1086
GetFeature
static const NIFeature * GetFeature(uint window_number)
Get the NIFeature related to the window number.
Definition: newgrf_debug_gui.cpp:258
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:141
WID_SA_RESET_REL
@ WID_SA_RESET_REL
Reset relative sprite offset.
Definition: newgrf_debug_widget.h:42
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:308
BSWAP32
static uint32_t BSWAP32(uint32_t x)
Perform a 32 bits endianness bitswap on x.
Definition: bitmath_func.hpp:345
NIHelper::SetStringParameters
virtual void SetStringParameters(uint index) const =0
Set the string parameters to write the right data for a STRINGn.
NICallback::read_size
byte read_size
The number of bytes (i.e. byte, word, dword etc) to read.
Definition: newgrf_debug_gui.cpp:102
WindowNumber
int32_t WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:732
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition: geometry_type.hpp:174
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1244
_newgrf_debug_sprite_picker
NewGrfDebugSpritePicker _newgrf_debug_sprite_picker
The sprite picker.
Definition: newgrf_debug_gui.cpp:49
WID_SA_PICKER
@ WID_SA_PICKER
Sprite picker.
Definition: newgrf_debug_widget.h:37
WID_SA_PREVIOUS
@ WID_SA_PREVIOUS
Skip to the previous sprite.
Definition: newgrf_debug_widget.h:27
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:306
INVALID_VEHICLE
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
Definition: vehicle_type.h:54
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:941
WID_SA_CENTRE
@ WID_SA_CENTRE
Toggle centre sprite.
Definition: newgrf_debug_widget.h:43
_nifeatures
static const NIFeature *const _nifeatures[]
Table with all NIFeatures.
Definition: newgrf_debug_data.h:722
MP_OBJECT
@ MP_OBJECT
Contains objects such as transmitters and owned land.
Definition: tile_type.h:58
NIT_CARGO
@ NIT_CARGO
The property is a cargo.
Definition: newgrf_debug_gui.cpp:80
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:110
Sprite::width
uint16_t width
Width of the sprite.
Definition: spritecache.h:19
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:135
SpriteAlignerWindow::current_sprite
SpriteID current_sprite
The currently shown sprite.
Definition: newgrf_debug_gui.cpp:818
GSF_FAKE_END
@ GSF_FAKE_END
End of the fake features.
Definition: newgrf.h:91
Scrollbar::GetCapacity
uint16_t GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:711
NIHelper::SetObjectAtStringParameters
void SetObjectAtStringParameters(StringID string, uint32_t index, TileIndex tile) const
Helper to make setting the strings easier for objects at a specific tile.
Definition: newgrf_debug_gui.cpp:222
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_type.h:350
NICallback::offset_proc
NIOffsetProc * offset_proc
Callback proc to get the actual variable address in memory.
Definition: newgrf_debug_gui.cpp:101
NewGRFInspectWindow::DrawMainPanelWidget
void DrawMainPanelWidget(const Rect &r) const
Helper function to draw the main panel widget.
Definition: newgrf_debug_gui.cpp:447
ZOOM_LVL_OUT_8X
@ ZOOM_LVL_OUT_8X
Zoomed 8 times out.
Definition: zoom_type.h:25
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1258
industry.h
safeguards.h
ShowQueryString
void ShowQueryString(StringID 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:1083
Window::LowerWidget
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition: window_gui.h:460
NIHelper::GetPSAFirstPosition
virtual const int32_t * GetPSAFirstPosition([[maybe_unused]] uint index, [[maybe_unused]] uint32_t grfid) const
Gets the first position of the array containing the persistent storage.
Definition: newgrf_debug_gui.cpp:198
Window::ShowNewGRFInspectWindow
virtual void ShowNewGRFInspectWindow() const
Show the NewGRF inspection window.
Definition: window_gui.h:854
NIFeature
Container for all information for a given feature.
Definition: newgrf_debug_gui.cpp:233
NewGRFInspectWindow::SetCallerGRFID
void SetCallerGRFID(uint32_t grfid)
Set the GRFID of the item opening this window.
Definition: newgrf_debug_gui.cpp:305
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:1007
NIHelper::GetSpec
virtual const void * GetSpec(uint index) const =0
Get (NewGRF) specs given an index.
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
CenterBounds
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition: gfx_func.h:166
NewGRFInspectWindow::GetFeatureIndex
uint GetFeatureIndex() const
Get the feature index.
Definition: newgrf_debug_gui.cpp:324
Scrollbar::GetScrolledItemFromWidget
Tcontainer::iterator 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:845
SpriteAlignerWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: newgrf_debug_gui.cpp:1068
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:296
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
NewGRFInspectWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: newgrf_debug_gui.cpp:616
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:68
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:3140
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
GetStationType
StationType GetStationType(Tile t)
Get the station type of this tile.
Definition: station_map.h:44
Window::SetWidgetLoweredState
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:441
WID_SA_SCROLLBAR
@ WID_SA_SCROLLBAR
Scrollbar for sprite list.
Definition: newgrf_debug_widget.h:39
EIT_IN_DEPOT
@ EIT_IN_DEPOT
Vehicle drawn in depot.
Definition: vehicle_type.h:87
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
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:1571
NIHelper::GetInstance
virtual const void * GetInstance(uint index) const =0
Get the instance given an index.
newgrf_object.h
Scrollbar::GetScrolledRowFromWidget
int 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:2260
WWT_TEXTBTN_2
@ WWT_TEXTBTN_2
(Toggle) Button with diff text when clicked
Definition: widget_type.h:58
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:381
newgrf_spritegroup.h
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:70
GUISettings::zoom_min
ZoomLevel zoom_min
minimum zoom out level
Definition: settings_type.h:157
NIFeature::callbacks
const NICallback * callbacks
The callbacks associated with this feature.
Definition: newgrf_debug_gui.cpp:235
GetFeatureIndex
static uint GetFeatureIndex(uint window_number)
Get the feature index related to the window number.
Definition: newgrf_debug_gui.cpp:56
newgrf_town.h
GrfSpecFeature
GrfSpecFeature
Definition: newgrf.h:66
string_func.h
spritecache.h
NIHelper::PSAWithParameter
virtual bool PSAWithParameter() const
Used to decide if the PSA needs a parameter or not.
Definition: newgrf_debug_gui.cpp:176
Vehicle::Move
Vehicle * Move(int n)
Get the vehicle at offset n of this vehicle chain.
Definition: vehicle_base.h:669
NewGRFInspectWindow::HasVariableParameter
static bool HasVariableParameter(uint variable)
Check whether the given variable has a parameter.
Definition: newgrf_debug_gui.cpp:296
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:111
NewGRFInspectWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: newgrf_debug_gui.cpp:626
NewGrfDebugSpritePicker
Spritepicker of SpriteAligner.
Definition: newgrf_debug.h:25
newgrf_debug_data.h
station_base.h
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1724
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
GetFeatureNum
static GrfSpecFeature GetFeatureNum(uint window_number)
Get the feature number related to the window number.
Definition: newgrf_debug_gui.cpp:248
WID_SA_UP
@ WID_SA_UP
Move the sprite up.
Definition: newgrf_debug_widget.h:30
UnScaleByZoom
int UnScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
Definition: zoom_func.h:34
Vehicle::First
Vehicle * First() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:640
GetOriginFile
SpriteFile * GetOriginFile(SpriteID sprite)
Get the SpriteFile of a given sprite.
Definition: spritecache.cpp:161
newgrf_industrytiles.h
WID_SA_LIST
@ WID_SA_LIST
Queried sprite list.
Definition: newgrf_debug_widget.h:38
RoadVehicle::GetDisplayImageWidth
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a road vehicle image in the GUI.
Definition: roadveh_cmd.cpp:94
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:1220
SpecializedVehicle< Train, Type >::From
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1201
NIHelper::~NIHelper
virtual ~NIHelper()=default
Silence a warning.
WID_SA_OFFSETS_REL
@ WID_SA_OFFSETS_REL
The sprite offsets (relative).
Definition: newgrf_debug_widget.h:36
ShowSpriteAlignerWindow
void ShowSpriteAlignerWindow()
Show the window for aligning sprites.
Definition: newgrf_debug_gui.cpp:1173
GetMaxSpriteID
uint GetMaxSpriteID()
Get a reasonable (upper bound) estimate of the maximum SpriteID used in OpenTTD; there will be no spr...
Definition: spritecache.cpp:211
NIFeature::helper
const NIHelper * helper
The class container all helper functions.
Definition: newgrf_debug_gui.cpp:237
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
Sprite::y_offs
int16_t y_offs
Number of pixels to shift the sprite downwards.
Definition: spritecache.h:21
NIHelper::GetParent
virtual uint GetParent(uint index) const =0
Get the parent "window_number" of a given instance.
NIHelper::SetSimpleStringParameters
void SetSimpleStringParameters(StringID string, uint32_t index) const
Helper to make setting the strings easier.
Definition: newgrf_debug_gui.cpp:209
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
SpriteAlignerWindow
Window used for aligning sprites.
Definition: newgrf_debug_gui.cpp:815
AutoRestoreBackup
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Definition: backup_type.hpp:153
NWidgetBase::resize_y
uint resize_y
Vertical resize step (0 means not resizable).
Definition: widget_type.h:226
NIProperty::name
const char * name
A (human readable) name for the property.
Definition: newgrf_debug_gui.cpp:87
MP_STATION
@ MP_STATION
A tile of a station.
Definition: tile_type.h:53
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:760
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
Definition: strings.cpp:327
WID_NGRFI_VEH_PREV
@ WID_NGRFI_VEH_PREV
Go to previous vehicle in chain.
Definition: newgrf_debug_widget.h:17
WID_NGRFI_VEH_CHAIN
@ WID_NGRFI_VEH_CHAIN
Display for vehicle chain.
Definition: newgrf_debug_widget.h:19
WID_NGRFI_SCROLLBAR
@ WID_NGRFI_SCROLLBAR
Scrollbar.
Definition: newgrf_debug_widget.h:21
SetDParamStr
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:352
CargoSpec::name
StringID name
Name of this type of cargo.
Definition: cargotype.h:88
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1734
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:81
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:816
WID_SA_CROSSHAIR
@ WID_SA_CROSSHAIR
Toggle crosshair.
Definition: newgrf_debug_widget.h:44
ZOOM_LVL_OUT_32X
@ ZOOM_LVL_OUT_32X
Zoomed 32 times out.
Definition: zoom_type.h:27
Window::SetWidgetsLoweredState
void SetWidgetsLoweredState(bool lowered_stat, Args... widgets)
Sets the lowered/raised status of a list of widgets.
Definition: window_gui.h:526
Window::RaiseWidget
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition: window_gui.h:469
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:281
WID_SA_OFFSETS_ABS
@ WID_SA_OFFSETS_ABS
The sprite offsets (absolute).
Definition: newgrf_debug_widget.h:35
window_func.h
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:305
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1097
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1552
DrawRectOutline
void DrawRectOutline(const Rect &r, int colour, int width, int dash)
Draw the outline of a Rect.
Definition: gfx.cpp:455
NIVariable
Representation on the NewGRF variables.
Definition: newgrf_debug_gui.cpp:110
WID_SA_RIGHT
@ WID_SA_RIGHT
Move the sprite to the right.
Definition: newgrf_debug_widget.h:32
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:658
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:1653
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:705
engine_base.h
IsValidCargoID
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
Definition: cargo_type.h:90
WID_SA_CAPTION
@ WID_SA_CAPTION
Caption of the window.
Definition: newgrf_debug_widget.h:26
WC_NEWGRF_INSPECT
@ WC_NEWGRF_INSPECT
NewGRF inspect (debug); Window numbers:
Definition: window_type.h:675
ZOOM_LVL_NORMAL
@ ZOOM_LVL_NORMAL
The normal zoom level.
Definition: zoom_type.h:22
newgrf_industries.h
WidgetDimensions::frametext
RectPadding frametext
Padding inside frame with text.
Definition: window_gui.h:43
WID_NGRFI_CAPTION
@ WID_NGRFI_CAPTION
The caption bar of course.
Definition: newgrf_debug_widget.h:15
Window
Data structure for an opened window.
Definition: window_gui.h:267
NIHelper::GetGRFID
virtual uint32_t GetGRFID(uint index) const =0
Get the GRFID of the file that includes this item.
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
NIProperty::offset_proc
NIOffsetProc * offset_proc
Callback proc to get the actual variable address in memory.
Definition: newgrf_debug_gui.cpp:88
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:394
NewGRFInspectWindow::var60params
static uint32_t var60params[GSF_FAKE_END][0x20]
The value for the variable 60 parameters.
Definition: newgrf_debug_gui.cpp:278
WID_SA_GOTO
@ WID_SA_GOTO
Go to a given sprite.
Definition: newgrf_debug_widget.h:28
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:79
ZOOM_LVL_OUT_4X
@ ZOOM_LVL_OUT_4X
Zoomed 4 times out.
Definition: zoom_type.h:24
GetGrfSpecFeature
GrfSpecFeature GetGrfSpecFeature(TileIndex tile)
Get the GrfSpecFeature associated with the tile.
Definition: newgrf_debug_gui.cpp:773
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1162
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:85
CS_HEXADECIMAL
@ CS_HEXADECIMAL
Only hexadecimal characters.
Definition: string_type.h:30
WID_NGRFI_VEH_NEXT
@ WID_NGRFI_VEH_NEXT
Go to next vehicle in chain.
Definition: newgrf_debug_widget.h:18
NewGRFInspectWindow
Window used for inspecting NewGRFs.
Definition: newgrf_debug_gui.cpp:276
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
ScaleByZoom
int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
Definition: zoom_func.h:22
WC_SPRITE_ALIGNER
@ WC_SPRITE_ALIGNER
Sprite aligner (debug); Window numbers:
Definition: window_type.h:681
AWV_INCREASE
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition: widget_type.h:34
WID_NGRFI_MAINPANEL
@ WID_NGRFI_MAINPANEL
Panel widget containing the actual data.
Definition: newgrf_debug_widget.h:20
Window::SetWidgetsDisabledState
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition: window_gui.h:515
Sprite
Data structure describing a sprite.
Definition: spritecache.h:17
WID_SA_ZOOM
@ WID_SA_ZOOM
Zoom level buttons (from ZOOM_LVL_BEGIN to ZOOM_LVL_END).
Definition: newgrf_debug_widget.h:40
NICallback::cb_bit
byte cb_bit
The bit that needs to be set for this callback to be enabled.
Definition: newgrf_debug_gui.cpp:103
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
CS_NUMERAL
@ CS_NUMERAL
Only numeric ones.
Definition: string_type.h:26
PC_LIGHT_BLUE
static const uint8_t PC_LIGHT_BLUE
Light blue palette colour.
Definition: palette_func.h:76
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:852
SpriteType::Normal
@ Normal
The most basic (normal) sprite.
newgrf_railtype.h
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:57
NewGRFInspectWindow::ValidateChainIndex
void ValidateChainIndex()
Ensure that this->chain_index is in range.
Definition: newgrf_debug_gui.cpp:339
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:636
FR_BORDERONLY
@ FR_BORDERONLY
Draw border only, no background.
Definition: window_gui.h:27
AWV_DECREASE
@ AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition: widget_type.h:33
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:151
roadveh.h
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:66
NIProperty::prop
byte prop
The number of the property.
Definition: newgrf_debug_gui.cpp:90
backup_type.hpp
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103