Go to the documentation of this file.
43 #include "table/strings.h"
57 return GB(window_number, 0, 24);
69 assert((index >> 24) == 0);
70 return (feature << 24) | index;
82 typedef const void *NIOffsetProc(
const void *b);
132 virtual uint
GetParent(uint index)
const = 0;
139 virtual const void *
GetInstance(uint index)
const = 0;
146 virtual const void *
GetSpec(uint index)
const = 0;
159 virtual uint32
GetGRFID(uint index)
const = 0;
169 virtual uint
Resolve(uint index, uint var, uint param,
bool *avail)
const = 0;
223 SetDParam(0, STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT);
306 this->caller_grfid = grfid;
316 return f == GSF_TRAINS || f == GSF_ROADVEHICLES;
326 if (this->chain_index > 0) {
329 v = v->
Move(this->chain_index);
330 if (v !=
nullptr) index = v->
index;
340 if (this->chain_index == 0)
return;
345 v = v->
Move(this->chain_index);
346 if (v ==
nullptr) this->chain_index = 0;
393 void WARN_FORMAT(4, 5) DrawString(const
Rect &r,
int offset, const
char *format, ...)
const
398 va_start(va, format);
399 vseprintf(buf,
lastof(buf), format, va);
403 if (offset < 0 || offset >= this->vscroll->
GetCapacity())
return;
417 if (u == v) sel_start = total_width;
421 default: NOT_REACHED();
423 if (u == v) sel_end = total_width;
429 if (total_width >
width) {
430 int sel_center = (sel_start + sel_end) / 2;
431 if (sel_center >
width / 2) skip = std::min(total_width -
width, sel_center -
width / 2);
455 const void *base_spec = nih->
GetSpec(index);
459 this->DrawString(r, i++,
"Variables:");
463 uint value = nih->
Resolve(index, niv->var, param, &avail);
465 if (!avail)
continue;
468 this->DrawString(r, i++,
" %02x[%02x]: %08x (%s)", niv->var, param, value, niv->name);
470 this->DrawString(r, i++,
" %02x: %08x (%s)", niv->var, value, niv->name);
475 uint psa_size = nih->
GetPSASize(index, this->caller_grfid);
477 if (psa_size != 0 && psa !=
nullptr) {
479 this->DrawString(r, i++,
"Persistent storage [%08X]:",
BSWAP32(this->caller_grfid));
481 this->DrawString(r, i++,
"Persistent storage:");
483 assert(psa_size % 4 == 0);
484 for (uint j = 0; j < psa_size; j += 4, psa += 4) {
485 this->DrawString(r, i++,
" %i: %i %i %i %i", j, psa[0], psa[1], psa[2], psa[3]);
490 this->DrawString(r, i++,
"Properties:");
492 const void *ptr = nip->offset_proc(base);
494 switch (nip->read_size) {
495 case 1: value = *(
const uint8 *)ptr;
break;
496 case 2: value = *(
const uint16 *)ptr;
break;
497 case 4: value = *(
const uint32 *)ptr;
break;
498 default: NOT_REACHED();
505 string = STR_JUST_INT;
517 GetString(buffer,
string,
lastof(buffer));
518 this->DrawString(r, i++,
" %02x: %s (%s)", nip->prop, buffer, nip->name);
523 this->DrawString(r, i++,
"Callbacks:");
526 const void *ptr = nic->offset_proc(base_spec);
528 switch (nic->read_size) {
529 case 1: value = *(
const uint8 *)ptr;
break;
530 case 2: value = *(
const uint16 *)ptr;
break;
531 case 4: value = *(
const uint32 *)ptr;
break;
532 default: NOT_REACHED();
535 if (!
HasBit(value, nic->cb_bit))
continue;
536 this->DrawString(r, i++,
" %03x: %s", nic->cb_id, nic->name);
538 this->DrawString(r, i++,
" %03x: %s (unmasked)", nic->cb_id, nic->name);
560 if (this->chain_index > 0) {
570 if (v !=
nullptr && v->
Next() !=
nullptr) {
584 if (line == INT_MAX)
return;
588 if (line != 1)
continue;
592 this->current_edit_param = niv->var;
619 if (!gui_scope)
return;
631 static const NWidgetPart _nested_newgrf_inspect_chain_widgets[] = {
655 static const NWidgetPart _nested_newgrf_inspect_widgets[] = {
674 WDP_AUTO,
"newgrf_inspect_chain", 400, 300,
677 _nested_newgrf_inspect_chain_widgets,
lengthof(_nested_newgrf_inspect_chain_widgets)
681 WDP_AUTO,
"newgrf_inspect", 400, 300,
684 _nested_newgrf_inspect_widgets,
lengthof(_nested_newgrf_inspect_widgets)
701 WindowDesc *desc = (feature == GSF_TRAINS || feature == GSF_ROADVEHICLES) ? &_newgrf_inspect_chain_desc : &_newgrf_inspect_desc;
755 if (nif ==
nullptr)
return false;
776 case STATION_RAIL:
return GSF_STATIONS;
777 case STATION_AIRPORT:
return GSF_AIRPORTTILES;
792 case VEH_ROAD:
return GSF_ROADVEHICLES;
812 static bool crosshair;
845 const auto key_offs_pair = this->offs_start_map.
Find(this->current_sprite);
846 if (key_offs_pair != this->offs_start_map.end()) {
872 fill->height =
resize->height;
888 if (SpriteAlignerWindow::centre) {
901 DrawSprite(this->current_sprite, PAL_NONE, x, y,
nullptr, ZOOM_LVL_GUI);
902 if (this->crosshair) {
913 const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
917 int max = std::min<int>(this->vscroll->
GetPosition() + this->vscroll->GetCapacity(), (uint)list.size());
920 for (
int i = this->vscroll->
GetPosition(); i < max; i++) {
946 this->current_sprite = (this->current_sprite + 1) %
GetMaxSpriteID();
953 _newgrf_debug_sprite_picker.
mode = SPM_WAIT_CLICK;
958 const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
990 if (!(this->offs_start_map.
Contains(this->current_sprite))) {
1008 this->offs_start_map.
Erase(this->current_sprite);
1013 SpriteAlignerWindow::centre = !SpriteAlignerWindow::centre;
1019 SpriteAlignerWindow::crosshair = !SpriteAlignerWindow::crosshair;
1030 this->current_sprite = atoi(str);
1031 if (this->current_sprite >=
GetMaxSpriteID()) this->current_sprite = 0;
1033 this->current_sprite = (this->current_sprite + 1) %
GetMaxSpriteID();
1045 if (!gui_scope)
return;
1059 bool SpriteAlignerWindow::centre =
true;
1060 bool SpriteAlignerWindow::crosshair =
true;
1062 static const NWidgetPart _nested_sprite_aligner_widgets[] = {
1101 NWidget(
WWT_LABEL, COLOUR_GREY,
WID_SA_OFFSETS_ABS),
SetDataTip(STR_SPRITE_ALIGNER_OFFSETS_ABS, STR_NULL),
SetFill(1, 0),
SetPadding(0, 10, 0, 10),
1102 NWidget(
WWT_LABEL, COLOUR_GREY,
WID_SA_OFFSETS_REL),
SetDataTip(STR_SPRITE_ALIGNER_OFFSETS_REL, STR_NULL),
SetFill(1, 0),
SetPadding(0, 10, 0, 10),
1112 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_SA_LIST),
SetResize(1, 1),
SetMatrixDataTip(1, 0, STR_NULL),
SetFill(1, 1),
SetScrollbar(
WID_SA_SCROLLBAR),
1121 WDP_AUTO,
"sprite_aligner", 400, 300,
1124 _nested_sprite_aligner_widgets,
lengthof(_nested_sprite_aligner_widgets)
1132 AllocateWindowDescFront<SpriteAlignerWindow>(&_sprite_aligner_desc, 0);
@ VEH_AIRCRAFT
Aircraft vehicle type.
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a train vehicle image in the GUI.
static const uint8 PC_WHITE
White palette colour.
void OnResize() override
Called after the window got resized.
@ MP_HOUSE
A house by a town.
static const byte INVALID_CARGO
Constant representing invalid cargo.
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-...
uint height
Vehicle cell height.
int Height() const
Get height of Rect.
static Titem * Get(size_t index)
Returns Titem with given index.
uint chain_index
For ground vehicles: Index in vehicle chain.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Dimensions (a width and height) of a rectangle in 2D.
static const int CBM_NO_BIT
Mask to show no bit needs to be enabled for the callback.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
@ WC_LAND_INFO
Land info window; Window numbers:
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
@ NIT_INT
The property is a simple integer.
static uint32 var60params[GSF_FAKE_END][0x20]
The value for the variable 60 parameters.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Vehicle * Next() const
Get the next vehicle of this vehicle.
bool HasChainIndex() const
Check whether this feature has chain index, i.e.
Representation of the available callbacks with information on when they actually apply.
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
NIType
The type of a property to show.
std::vector< SpriteID > sprites
Sprites found.
NewGrfDebugSpritePickerMode mode
Current state.
Tindex index
Index of this pool item.
void InvalidateNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Invalidate the inspect window for a given feature and index.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
uint16 height
Height of the sprite.
bool _ctrl_pressed
Is Ctrl pressed?
int16 x_offs
Number of pixels to shift the sprite to the right.
static const NIHelper * GetFeatureHelper(uint window_number)
Get the NIHelper related to the window number.
const NIProperty * properties
The properties associated with this feature.
virtual uint Resolve(uint index, uint var, uint param, bool *avail) const =0
Resolve (action2) variable for a given index.
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
@ EIT_IN_DETAILS
Vehicle drawn in vehicle details, refit window, ...
@ MP_INDUSTRY
Part of an industry.
@ ST_NORMAL
The most basic (normal) sprite.
int32 WindowNumber
Number to differentiate different windows of the same class.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
uint16 cb_id
The number of the callback.
const char * name
The human readable name of the callback.
@ GSF_INVALID
An invalid spec feature.
@ SA_RIGHT
Right align the text (must be a single bit).
@ VEH_ROAD
Road vehicle type.
SpriteType GetSpriteType(SpriteID sprite)
Get the sprite type of a given sprite.
byte current_edit_param
The currently edited parameter, to update the right one.
const NIVariable * variables
The variables associated with this feature.
bool Insert(const T &key, const U &data)
Adds new item to this map.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
@ MP_ROAD
A tile with road (or tram tracks)
Helper class to wrap some functionality/queries in.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
VehicleCellSize GetVehicleImageCellSize(VehicleType type, EngineImageType image_type)
Get the GUI cell size for a vehicle image.
static bool IsLevelCrossing(TileIndex t)
Return whether a tile is a level crossing.
bool IsNewGRFInspectable(GrfSpecFeature feature, uint index)
Can we inspect the data given a certain feature and index.
Representation of the data from a NewGRF property.
byte read_size
Number of bytes (i.e. byte, word, dword etc)
void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Delete inspect window for a given feature and index.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
std::pair< int16, int16 > XyOffs
Pair for x and y offsets of the sprite before alignment. First value contains the x offset,...
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
SmallMap< SpriteID, XyOffs > offs_start_map
Mapping of starting offsets for the sprites which have been aligned in the sprite aligner window.
High level window description.
void ShowNewGRFInspectWindow(GrfSpecFeature feature, uint index, const uint32 grfid)
Show the inspect window for a given feature and index.
virtual bool IsInspectable(uint index) const =0
Is the item with the given index inspectable?
static const NIFeature * GetFeature(uint window_number)
Get the NIFeature related to the window number.
@ WDP_AUTO
Find a place automatically.
virtual uint32 GetGRFID(uint index) const =0
Get the GRFID of the file that includes this item.
ResizeInfo resize
Resize information.
virtual void SetStringParameters(uint index) const =0
Set the string parameters to write the right data for a STRINGn.
byte read_size
The number of bytes (i.e. byte, word, dword etc) to read.
NewGrfDebugSpritePicker _newgrf_debug_sprite_picker
The sprite picker.
int height
Height of the window (number of pixels down in y direction)
virtual uint GetPSASize(uint index, uint32 grfid) const
Allows to know the size of the persistent storage.
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
static const NIFeature *const _nifeatures[]
Table with all NIFeatures.
@ MP_OBJECT
Contains objects such as transmitters and owned land.
@ NIT_CARGO
The property is a cargo.
static 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.
static StationType GetStationType(TileIndex t)
Get the station type of this tile.
SpriteID current_sprite
The currently shown sprite.
@ GSF_FAKE_END
End of the fake features.
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
NIOffsetProc * offset_proc
Callback proc to get the actual variable address in memory.
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
uint16 width
Width of the sprite.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
virtual void ShowNewGRFInspectWindow() const
Show the NewGRF inspection window.
Container for all information for a given feature.
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
void Erase(Pair *pair)
Removes given pair from this map.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
virtual const void * GetSpec(uint index) const =0
Get (NewGRF) specs given an index.
uint32 caller_grfid
GRFID of the caller of this window, 0 if it has no caller.
Coordinates of a point in 2D.
virtual ~NIHelper()
Silence a warning.
uint GetFeatureIndex() const
Get the feature index.
WindowNumber window_number
Window number within the window class.
VehicleType
Available vehicle types.
uint Vertical() const
Get total vertical padding of RectPadding.
void OnResize() override
Called after the window got resized.
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
static uint GetInspectWindowNumber(GrfSpecFeature feature, uint index)
Get the window number for the inspect window given a feature and index.
void SetObjectAtStringParameters(StringID string, uint32 index, TileIndex tile) const
Helper to make setting the strings easier for objects at a specific tile.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ EIT_IN_DEPOT
Vehicle drawn in depot.
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
virtual const void * GetInstance(uint index) const =0
Get the instance given an index.
const NICallback * callbacks
The callbacks associated with this feature.
static uint GetFeatureIndex(uint window_number)
Get the feature index related to the window number.
virtual bool PSAWithParameter() const
Used to decide if the PSA needs a parameter or not.
Vehicle * Move(int n)
Get the vehicle at offset n of this vehicle chain.
static bool HasVariableParameter(uint variable)
Check whether the given variable has a parameter.
virtual const int32 * GetPSAFirstPosition(uint index, uint32 grfid) const
Gets the first position of the array containing the persistent storage.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Spritepicker of SpriteAligner.
static GrfSpecFeature GetFeatureNum(uint window_number)
Get the feature number related to the window number.
Vehicle * First() const
Get the first vehicle of this vehicle chain.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
SpriteFile * GetOriginFile(SpriteID sprite)
Get the SpriteFile of a given sprite.
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a road vehicle image in the GUI.
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
void ShowSpriteAlignerWindow()
Show the window for aligning sprites.
uint GetMaxSpriteID()
Get a reasonable (upper bound) estimate of the maximum SpriteID used in OpenTTD; there will be no spr...
const NIHelper * helper
The class container all helper functions.
virtual uint GetParent(uint index) const =0
Get the parent "window_number" of a given instance.
Window used for aligning sprites.
const char * name
A (human readable) name for the property.
@ MP_STATION
A tile of a station.
int16 y_offs
Number of pixels to shift the sprite downwards.
StringID name
Name of this type of cargo.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
std::vector< Pair >::const_iterator Find(const T &key) const
Finds given key in this map.
static int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
#define lengthof(x)
Return the length of an fixed size array.
int width
width of the window (number of pixels to the right in x direction)
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Representation on the NewGRF variables.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
void DrawVehicleImage(const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip)
Draws an image of a vehicle chain.
@ WC_NEWGRF_INSPECT
NewGRF inspect (debug); Window numbers:
Data structure for an opened window.
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
@ VEH_TRAIN
Train vehicle type.
void RaiseWidget(byte widget_index)
Marks a widget as raised.
NIOffsetProc * offset_proc
Callback proc to get the actual variable address in memory.
GrfSpecFeature GetGrfSpecFeature(TileIndex tile)
Get the GrfSpecFeature associated with the tile.
int Width() const
Get width of Rect.
@ CS_HEXADECIMAL
Only hexadecimal characters.
Window used for inspecting NewGRFs.
@ VEH_SHIP
Ship vehicle type.
Specification of a rectangle with absolute coordinates of all edges.
void LowerWidget(byte widget_index)
Marks a widget as lowered.
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
@ WC_SPRITE_ALIGNER
Sprite aligner (debug); Window numbers:
void WARN_FORMAT(4, 5) DrawString(const Rect &r
Helper function to draw a string (line) in the window.
Data structure describing a sprite.
void SetSimpleStringParameters(StringID string, uint32 index) const
Helper to make setting the strings easier.
#define lastof(x)
Get the last element of an fixed size array.
void SetDParamMaxDigits(uint n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
byte cb_bit
The bit that needs to be set for this callback to be enabled.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
@ CS_NUMERAL
Only numeric ones.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
void ValidateChainIndex()
Ensure that this->chain_index is in range.
@ FR_BORDERONLY
Draw border only, no background.
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Data about how and where to blit pixels.
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
void SetCallerGRFID(uint32 grfid)
Set the GRFID of the item opening this window.
byte prop
The number of the property.
bool Contains(const T &key) const
Tests whether a key is assigned in this map.