OpenTTD
Data Structures | Enumerations | Functions | Variables
newgrf_debug_gui.cpp File Reference

GUIs for debugging NewGRFs. More...

#include "stdafx.h"
#include <stdarg.h>
#include "window_gui.h"
#include "window_func.h"
#include "fileio_func.h"
#include "spritecache.h"
#include "string_func.h"
#include "strings_func.h"
#include "textbuf_gui.h"
#include "vehicle_gui.h"
#include "zoom_func.h"
#include "engine_base.h"
#include "industry.h"
#include "object_base.h"
#include "station_base.h"
#include "town.h"
#include "vehicle_base.h"
#include "train.h"
#include "roadveh.h"
#include "newgrf_airporttiles.h"
#include "newgrf_debug.h"
#include "newgrf_object.h"
#include "newgrf_spritegroup.h"
#include "newgrf_station.h"
#include "newgrf_town.h"
#include "newgrf_railtype.h"
#include "newgrf_industries.h"
#include "newgrf_industrytiles.h"
#include "widgets/newgrf_debug_widget.h"
#include "table/strings.h"
#include "safeguards.h"
#include "table/newgrf_debug_data.h"

Go to the source code of this file.

Data Structures

struct  NIProperty
 Representation of the data from a NewGRF property. More...
 
struct  NICallback
 Representation of the available callbacks with information on when they actually apply. More...
 
struct  NIVariable
 Representation on the NewGRF variables. More...
 
class  NIHelper
 Helper class to wrap some functionality/queries in. More...
 
struct  NIFeature
 Container for all information for a given feature. More...
 
struct  NewGRFInspectWindow
 Window used for inspecting NewGRFs. More...
 
struct  SpriteAlignerWindow
 Window used for aligning sprites. More...
 

Enumerations

enum  NIType { NIT_INT, NIT_CARGO }
 The type of a property to show. More...
 

Functions

static uint GetFeatureIndex (uint window_number)
 Get the feature index related to the window number. More...
 
static uint GetInspectWindowNumber (GrfSpecFeature feature, uint index)
 Get the window number for the inspect window given a feature and index. More...
 
static GrfSpecFeature GetFeatureNum (uint window_number)
 Get the feature number related to the window number. More...
 
static const NIFeatureGetFeature (uint window_number)
 Get the NIFeature related to the window number. More...
 
static const NIHelperGetFeatureHelper (uint window_number)
 Get the NIHelper related to the window number. More...
 
void ShowNewGRFInspectWindow (GrfSpecFeature feature, uint index, const uint32 grfid)
 Show the inspect window for a given feature and index. More...
 
void InvalidateNewGRFInspectWindow (GrfSpecFeature feature, uint index)
 Invalidate the inspect window for a given feature and index. More...
 
void DeleteNewGRFInspectWindow (GrfSpecFeature feature, uint index)
 Delete inspect window for a given feature and index. More...
 
bool IsNewGRFInspectable (GrfSpecFeature feature, uint index)
 Can we inspect the data given a certain feature and index. More...
 
GrfSpecFeature GetGrfSpecFeature (TileIndex tile)
 Get the GrfSpecFeature associated with the tile. More...
 
GrfSpecFeature GetGrfSpecFeature (VehicleType type)
 Get the GrfSpecFeature associated with the vehicle. More...
 
void ShowSpriteAlignerWindow ()
 Show the window for aligning sprites.
 

Variables

NewGrfDebugSpritePicker _newgrf_debug_sprite_picker = { SPM_NONE, NULL, 0, SmallVector<SpriteID, 256>() }
 The sprite picker. More...
 
static const int CBM_NO_BIT = UINT8_MAX
 Mask to show no bit needs to be enabled for the callback. More...
 
static const NWidgetPart _nested_newgrf_inspect_chain_widgets []
 
static const NWidgetPart _nested_newgrf_inspect_widgets []
 
static WindowDesc _newgrf_inspect_chain_desc (WDP_AUTO, "newgrf_inspect_chain", 400, 300, WC_NEWGRF_INSPECT, WC_NONE, 0, _nested_newgrf_inspect_chain_widgets, lengthof(_nested_newgrf_inspect_chain_widgets))
 
static WindowDesc _newgrf_inspect_desc (WDP_AUTO, "newgrf_inspect", 400, 300, WC_NEWGRF_INSPECT, WC_NONE, 0, _nested_newgrf_inspect_widgets, lengthof(_nested_newgrf_inspect_widgets))
 
static const NWidgetPart _nested_sprite_aligner_widgets []
 
static WindowDesc _sprite_aligner_desc (WDP_AUTO, "sprite_aligner", 400, 300, WC_SPRITE_ALIGNER, WC_NONE, 0, _nested_sprite_aligner_widgets, lengthof(_nested_sprite_aligner_widgets))
 

Detailed Description

GUIs for debugging NewGRFs.

Definition in file newgrf_debug_gui.cpp.

Enumeration Type Documentation

◆ NIType

enum NIType

The type of a property to show.

This is used to provide an appropriate representation in the GUI.

Enumerator
NIT_INT 

The property is a simple integer.

NIT_CARGO 

The property is a cargo.

Definition at line 79 of file newgrf_debug_gui.cpp.

Function Documentation

◆ DeleteNewGRFInspectWindow()

void DeleteNewGRFInspectWindow ( GrfSpecFeature  feature,
uint  index 
)

Delete inspect window for a given feature and index.

The index is normally an in-game location/identifier, such as a TileIndex or an IndustryID depending on the feature we want to inspect.

Parameters
featureThe feature we want to delete the window for.
indexThe index/identifier of the feature to delete.

Definition at line 734 of file newgrf_debug_gui.cpp.

References DeleteWindowById(), GetInspectWindowNumber(), GSF_INVALID, InvalidateWindowData(), WC_LAND_INFO, and WC_NEWGRF_INSPECT.

Referenced by ReallyClearObjectTile().

◆ GetFeature()

static const NIFeature* GetFeature ( uint  window_number)
inlinestatic

Get the NIFeature related to the window number.

Parameters
window_numberThe window to get the NIFeature for.
Returns
the NIFeature, or NULL is there isn't one.

Definition at line 257 of file newgrf_debug_gui.cpp.

References _nifeatures, GetFeatureNum(), and GSF_FAKE_END.

Referenced by GetFeatureHelper(), IsNewGRFInspectable(), and NewGRFInspectWindow::OnClick().

◆ GetFeatureHelper()

static const NIHelper* GetFeatureHelper ( uint  window_number)
inlinestatic

Get the NIHelper related to the window number.

Parameters
window_numberThe window to get the NIHelper for.
Precondition
GetFeature(window_number) != NULL
Returns
the NIHelper

Definition at line 269 of file newgrf_debug_gui.cpp.

References GetFeature(), and NIFeature::helper.

Referenced by NewGRFInspectWindow::OnClick(), and NewGRFInspectWindow::SetStringParameters().

◆ GetFeatureIndex()

static uint GetFeatureIndex ( uint  window_number)
inlinestatic

Get the feature index related to the window number.

Parameters
window_numberThe window to get the feature index from.
Returns
the feature index

Definition at line 57 of file newgrf_debug_gui.cpp.

References GB().

Referenced by NewGRFInspectWindow::DrawWidget(), NewGRFInspectWindow::GetFeatureIndex(), NewGRFInspectWindow::OnClick(), NewGRFInspectWindow::OnInvalidateData(), and NewGRFInspectWindow::SetStringParameters().

◆ GetFeatureNum()

static GrfSpecFeature GetFeatureNum ( uint  window_number)
inlinestatic

Get the feature number related to the window number.

Parameters
window_numberThe window to get the feature number for.
Returns
The feature number.

Definition at line 247 of file newgrf_debug_gui.cpp.

References GB().

Referenced by GetFeature(), NewGRFInspectWindow::HasChainIndex(), NewGRFInspectWindow::OnClick(), and NewGRFInspectWindow::OnQueryTextFinished().

◆ GetGrfSpecFeature() [1/2]

GrfSpecFeature GetGrfSpecFeature ( TileIndex  tile)

Get the GrfSpecFeature associated with the tile.

Parameters
tileThe tile to get the feature from.
Returns
the GrfSpecFeature.

Definition at line 768 of file newgrf_debug_gui.cpp.

References GetTileType(), GSF_INVALID, and MP_RAILWAY.

Referenced by NIHVehicle::GetParent(), LandInfoWindow::IsNewGRFInspectable(), VehicleViewWindow::IsNewGRFInspectable(), LandInfoWindow::ShowNewGRFInspectWindow(), and VehicleViewWindow::ShowNewGRFInspectWindow().

◆ GetGrfSpecFeature() [2/2]

GrfSpecFeature GetGrfSpecFeature ( VehicleType  type)

Get the GrfSpecFeature associated with the vehicle.

Parameters
typeThe vehicle type to get the feature from.
Returns
the GrfSpecFeature.

Definition at line 792 of file newgrf_debug_gui.cpp.

References VEH_TRAIN.

◆ GetInspectWindowNumber()

static uint GetInspectWindowNumber ( GrfSpecFeature  feature,
uint  index 
)
inlinestatic

Get the window number for the inspect window given a feature and index.

Parameters
featureThe feature we want to inspect.
indexThe index/identifier of the feature to inspect.
Returns
the InspectWindow (Window)Number

Definition at line 69 of file newgrf_debug_gui.cpp.

Referenced by DeleteNewGRFInspectWindow(), NIHVehicle::GetParent(), NIHStation::GetParent(), NIHHouse::GetParent(), NIHIndustryTile::GetParent(), NIHIndustry::GetParent(), NIHObject::GetParent(), NIHAirportTile::GetParent(), InvalidateNewGRFInspectWindow(), IsNewGRFInspectable(), and ShowNewGRFInspectWindow().

◆ InvalidateNewGRFInspectWindow()

void InvalidateNewGRFInspectWindow ( GrfSpecFeature  feature,
uint  index 
)

Invalidate the inspect window for a given feature and index.

The index is normally an in-game location/identifier, such as a TileIndex or an IndustryID depending on the feature we want to inspect.

Parameters
featureThe feature we want to invalidate the window for.
indexThe index/identifier of the feature to invalidate.

Definition at line 718 of file newgrf_debug_gui.cpp.

References GetInspectWindowNumber(), GSF_INVALID, InvalidateWindowData(), and WC_NEWGRF_INSPECT.

◆ IsNewGRFInspectable()

bool IsNewGRFInspectable ( GrfSpecFeature  feature,
uint  index 
)

Can we inspect the data given a certain feature and index.

The index is normally an in-game location/identifier, such as a TileIndex or an IndustryID depending on the feature we want to inspect.

Parameters
featureThe feature we want to inspect.
indexThe index/identifier of the feature to inspect.
Returns
true if there is something to show.

Definition at line 756 of file newgrf_debug_gui.cpp.

References GetFeature(), GetInspectWindowNumber(), NIFeature::helper, and NIHelper::IsInspectable().

Referenced by LandInfoWindow::IsNewGRFInspectable(), IndustryViewWindow::IsNewGRFInspectable(), VehicleViewWindow::IsNewGRFInspectable(), and ShowNewGRFInspectWindow().

◆ ShowNewGRFInspectWindow()

void ShowNewGRFInspectWindow ( GrfSpecFeature  feature,
uint  index,
const uint32  grfid 
)

Show the inspect window for a given feature and index.

The index is normally an in-game location/identifier, such as a TileIndex or an IndustryID depending on the feature we want to inspect.

Parameters
featureThe feature we want to inspect.
indexThe index/identifier of the feature to inspect.
grfidGRFID of the item opening this window, or 0 if not opened by other window.

Definition at line 700 of file newgrf_debug_gui.cpp.

References GetInspectWindowNumber(), and IsNewGRFInspectable().

Referenced by NewGRFInspectWindow::OnClick(), and IndustryViewWindow::ShowNewGRFInspectWindow().

Variable Documentation

◆ _nested_newgrf_inspect_chain_widgets

const NWidgetPart _nested_newgrf_inspect_chain_widgets[]
static
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
NWidget(WWT_CAPTION, COLOUR_GREY, WID_NGRFI_CAPTION), SetDataTip(STR_NEWGRF_INSPECT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_SHADEBOX, COLOUR_GREY),
NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
NWidget(WWT_STICKYBOX, COLOUR_GREY),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(WWT_EMPTY, COLOUR_GREY, WID_NGRFI_VEH_CHAIN), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
}
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:48
The caption bar of course.
Display for vehicle chain.
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:930
Horizontal container.
Definition: widget_type.h:75
Arrow to the right or in case of RTL to the left.
Definition: widget_type.h:38
Arrow to the left or in case of RTL to the right.
Definition: widget_type.h:37
Go to previous vehicle in chain.
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
Panel widget containing the actual data.
Close box (at top-left of a window)
Definition: widget_type.h:69
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:65
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:947
Simple depressed panel.
Definition: widget_type.h:50
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1114
Go to next vehicle in chain.
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
Vertical container.
Definition: widget_type.h:77
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:999
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:106
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:66
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:983
Vertical scrollbar.
Definition: widget_type.h:84
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1095
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:64

Definition at line 635 of file newgrf_debug_gui.cpp.

◆ _nested_newgrf_inspect_widgets

const NWidgetPart _nested_newgrf_inspect_widgets[]
static
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
NWidget(WWT_CAPTION, COLOUR_GREY, WID_NGRFI_CAPTION), SetDataTip(STR_NEWGRF_INSPECT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NGRFI_PARENT), SetDataTip(STR_NEWGRF_INSPECT_PARENT_BUTTON, STR_NEWGRF_INSPECT_PARENT_TOOLTIP),
NWidget(WWT_SHADEBOX, COLOUR_GREY),
NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
NWidget(WWT_STICKYBOX, COLOUR_GREY),
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
}
The caption bar of course.
Horizontal container.
Definition: widget_type.h:75
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
Panel widget containing the actual data.
Close box (at top-left of a window)
Definition: widget_type.h:69
Inspect the parent.
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:65
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:947
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
Simple depressed panel.
Definition: widget_type.h:50
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1114
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
Vertical container.
Definition: widget_type.h:77
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:999
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:66
Vertical scrollbar.
Definition: widget_type.h:84
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1095
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:64

Definition at line 659 of file newgrf_debug_gui.cpp.

◆ _newgrf_debug_sprite_picker

NewGrfDebugSpritePicker _newgrf_debug_sprite_picker = { SPM_NONE, NULL, 0, SmallVector<SpriteID, 256>() }

The sprite picker.

Definition at line 50 of file newgrf_debug_gui.cpp.

◆ CBM_NO_BIT

const int CBM_NO_BIT = UINT8_MAX
static

Mask to show no bit needs to be enabled for the callback.

Definition at line 106 of file newgrf_debug_gui.cpp.