43 #include "table/strings.h" 57 return GB(window_number, 0, 24);
69 assert((index >> 24) == 0);
70 return (feature << 24) | index;
123 virtual bool IsInspectable(uint index)
const = 0;
130 virtual uint GetParent(uint index)
const = 0;
137 virtual const void *GetInstance(uint index)
const = 0;
144 virtual const void *GetSpec(uint index)
const = 0;
150 virtual void SetStringParameters(uint index)
const = 0;
157 virtual uint32 GetGRFID(uint index)
const = 0;
167 virtual uint Resolve(uint index, uint var, uint param,
bool *avail)
const = 0;
221 SetDParam(0, STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT);
274 static const int LEFT_OFFSET = 5;
275 static const int RIGHT_OFFSET = 5;
276 static const int TOP_OFFSET = 5;
277 static const int BOTTOM_OFFSET = 5;
309 this->caller_grfid = grfid;
319 return f == GSF_TRAINS || f == GSF_ROADVEHICLES;
329 if (this->chain_index > 0) {
330 assert(this->HasChainIndex());
332 v = v->
Move(this->chain_index);
333 if (v !=
nullptr) index = v->
index;
343 if (this->chain_index == 0)
return;
345 assert(this->HasChainIndex());
348 v = v->
Move(this->chain_index);
349 if (v ==
nullptr) this->chain_index = 0;
354 this->CreateNestedTree();
356 this->FinishInitNested(wno);
361 this->OnInvalidateData(0,
true);
375 assert(this->HasChainIndex());
385 size->height = 5 * resize->height + TOP_OFFSET + BOTTOM_OFFSET;
401 va_start(va, format);
406 if (offset < 0 || offset >= this->vscroll->
GetCapacity())
return;
408 ::DrawString(r.left + LEFT_OFFSET, r.right - RIGHT_OFFSET, r.top + TOP_OFFSET + (offset * this->resize.step_height), buf, TC_BLACK);
420 if (u == v) sel_start = total_width;
424 default: NOT_REACHED();
426 if (u == v) sel_end = total_width;
431 if (total_width > width) {
432 int sel_center = (sel_start + sel_end) / 2;
433 if (sel_center > width / 2) skip =
min(total_width - width, sel_center - width / 2);
438 int y = (r.top + r.bottom - h) / 2;
457 const void *base_spec = nih->
GetSpec(index);
465 uint value = nih->
Resolve(index, niv->var, param, &avail);
467 if (!avail)
continue;
469 if (HasVariableParameter(niv->var)) {
470 this->
DrawString(r, i++,
" %02x[%02x]: %08x (%s)", niv->var, param, value, niv->name);
472 this->
DrawString(r, i++,
" %02x: %08x (%s)", niv->var, value, niv->name);
477 uint psa_size = nih->
GetPSASize(index, this->caller_grfid);
479 if (psa_size != 0 && psa !=
nullptr) {
481 this->
DrawString(r, i++,
"Persistent storage [%08X]:",
BSWAP32(this->caller_grfid));
483 this->
DrawString(r, i++,
"Persistent storage:");
485 assert(psa_size % 4 == 0);
486 for (uint j = 0; j < psa_size; j += 4, psa += 4) {
487 this->
DrawString(r, i++,
" %i: %i %i %i %i", j, psa[0], psa[1], psa[2], psa[3]);
494 const void *ptr = (
const byte *)base + nip->offset;
496 switch (nip->read_size) {
497 case 1: value = *(
const uint8 *)ptr;
break;
498 case 2: value = *(
const uint16 *)ptr;
break;
499 case 4: value = *(
const uint32 *)ptr;
break;
500 default: NOT_REACHED();
507 string = STR_JUST_INT;
519 GetString(buffer,
string,
lastof(buffer));
520 this->
DrawString(r, i++,
" %02x: %s (%s)", nip->prop, buffer, nip->name);
528 const void *ptr = (
const byte *)base_spec + nic->offset;
530 switch (nic->read_size) {
531 case 1: value = *(
const uint8 *)ptr;
break;
532 case 2: value = *(
const uint16 *)ptr;
break;
533 case 4: value = *(
const uint32 *)ptr;
break;
534 default: NOT_REACHED();
537 if (!
HasBit(value, nic->cb_bit))
continue;
538 this->
DrawString(r, i++,
" %03x: %s", nic->cb_id, nic->name);
540 this->
DrawString(r, i++,
" %03x: %s (unmasked)", nic->cb_id, nic->name);
562 if (this->chain_index > 0) {
564 this->InvalidateData();
569 if (this->HasChainIndex()) {
572 if (v !=
nullptr && v->
Next() !=
nullptr) {
574 this->InvalidateData();
586 if (line == INT_MAX)
return;
590 if (line != 1)
continue;
592 if (!HasVariableParameter(niv->var))
break;
594 this->current_edit_param = niv->var;
621 if (!gui_scope)
return;
622 if (this->HasChainIndex()) {
623 this->ValidateChainIndex();
633 static const NWidgetPart _nested_newgrf_inspect_chain_widgets[] = {
657 static const NWidgetPart _nested_newgrf_inspect_widgets[] = {
676 WDP_AUTO,
"newgrf_inspect_chain", 400, 300,
679 _nested_newgrf_inspect_chain_widgets,
lengthof(_nested_newgrf_inspect_chain_widgets)
683 WDP_AUTO,
"newgrf_inspect", 400, 300,
686 _nested_newgrf_inspect_widgets,
lengthof(_nested_newgrf_inspect_widgets)
703 WindowDesc *desc = (feature == GSF_TRAINS || feature == GSF_ROADVEHICLES) ? &_newgrf_inspect_chain_desc : &_newgrf_inspect_desc;
757 if (nif ==
nullptr)
return false;
778 case STATION_RAIL:
return GSF_STATIONS;
779 case STATION_AIRPORT:
return GSF_AIRPORTTILES;
794 case VEH_ROAD:
return GSF_ROADVEHICLES;
815 this->CreateNestedTree();
817 this->FinishInitNested(wno);
841 const auto key_offs_pair = this->offs_start_map.
Find(this->current_sprite);
842 if (key_offs_pair != this->offs_start_map.end()) {
865 size->height = (1 + 200 / resize->height) * resize->height;
884 DrawSprite(this->current_sprite, PAL_NONE, x, y,
nullptr, ZOOM_LVL_GUI);
892 const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
895 std::vector<SpriteID> &list = _newgrf_debug_sprite_picker.
sprites;
914 this->current_sprite = (this->current_sprite == 0 ?
GetMaxSpriteID() : this->current_sprite) - 1;
925 this->current_sprite = (this->current_sprite + 1) %
GetMaxSpriteID();
932 _newgrf_debug_sprite_picker.
mode = SPM_WAIT_CLICK;
937 const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
941 if (i < _newgrf_debug_sprite_picker.
sprites.size()) {
969 if (!(this->offs_start_map.
Contains(this->current_sprite))) {
987 this->offs_start_map.
Erase(this->current_sprite);
997 this->current_sprite = atoi(str);
998 if (this->current_sprite >=
GetMaxSpriteID()) this->current_sprite = 0;
1000 this->current_sprite = (this->current_sprite + 1) %
GetMaxSpriteID();
1012 if (!gui_scope)
return;
1016 this->vscroll->
SetCount((uint)_newgrf_debug_sprite_picker.
sprites.size());
1026 static const NWidgetPart _nested_sprite_aligner_widgets[] = {
1065 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),
1066 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),
1076 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_SA_LIST),
SetResize(1, 1),
SetMatrixDataTip(1, 0, STR_NULL),
SetFill(1, 1),
SetScrollbar(
WID_SA_SCROLLBAR),
1085 WDP_AUTO,
"sprite_aligner", 400, 300,
1088 _nested_sprite_aligner_widgets,
lengthof(_nested_sprite_aligner_widgets)
1096 AllocateWindowDescFront<SpriteAlignerWindow>(&_sprite_aligner_desc, 0);
Functions related to OTTD's strings.
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Functions/types related to NewGRF debugging.
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a road vehicle image in the GUI.
NewGRF handling of rail types.
byte current_edit_param
The currently edited parameter, to update the right one.
Data about how and where to blit pixels.
uint GetOriginFileSlot(SpriteID sprite)
Get the (FIOS) file slot of a given sprite.
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.
virtual uint GetParent(uint index) const =0
Get the parent "window_number" of a given instance.
static int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
byte cb_bit
The bit that needs to be set for this callback to be enabled.
High level window description.
SmallMap< SpriteID, XyOffs > offs_start_map
Mapping of starting offsets for the sprites which have been aligned in the sprite aligner window...
NIType
The type of a property to show.
virtual bool IsInspectable(uint index) const =0
Is the item with the given index inspectable?
static Titem * Get(size_t index)
Returns Titem with given index.
ptrdiff_t offset
Offset of the variable in the class.
Width of left bevel border.
void DrawVehicleImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip)
Draws an image of a vehicle chain.
Functions for NewGRF industries.
Only hexadecimal characters.
const char * name
The human readable name of the callback.
Base for the train class.
void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Delete inspect window for a given feature and index.
Offset at top to draw the frame rectangular area.
NewGrfDebugSpritePicker _newgrf_debug_sprite_picker
The sprite picker.
std::vector< SpriteID > sprites
Sprites found.
A tile with road (or tram tracks)
void SetSimpleStringParameters(StringID string, uint32 index) const
Helper to make setting the strings easier.
Data structure describing a sprite.
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Representation on the NewGRF variables.
virtual uint32 GetGRFID(uint index) const =0
Get the GRFID of the file that includes this item.
std::vector< Pair >::const_iterator Find(const T &key) const
Finds given key in this map.
VehicleType
Available vehicle types.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
int CDECL vseprintf(char *str, const char *last, const char *format, va_list ap)
Safer implementation of vsnprintf; same as vsnprintf except:
byte read_size
Number of bytes (i.e. byte, word, dword etc)
uint16 cb_id
The number of the callback.
Implementation of simple mapping class.
VehicleCellSize GetVehicleImageCellSize(VehicleType type, EngineImageType image_type)
Get the GUI cell size for a vehicle image.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
uint height
Vehicle cell height.
static uint GetInspectWindowNumber(GrfSpecFeature feature, uint index)
Get the window number for the inspect window given a feature and index.
Tindex index
Index of this pool item.
Width of right bevel border.
Functions for Standard In/Out file operations.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
const char * FioGetFilename(uint8 slot)
Get the filename associated with a slot.
const NIHelper * helper
The class container all helper functions.
#define lastof(x)
Get the last element of an fixed size array.
Stuff related to the text buffer GUI.
Contains objects such as transmitters and owned land.
byte read_size
The number of bytes (i.e. byte, word, dword etc) to read.
const NICallback * callbacks
The callbacks associated with this feature.
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
static bool IsLevelCrossing(TileIndex t)
Return whether a tile is a level crossing.
static T max(const T a, const T b)
Returns the maximum of two values.
uint32 caller_grfid
GRFID of the caller of this window, 0 if it has no caller.
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Functions related to the vehicle's GUIs.
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
static StationType GetStationType(TileIndex t)
Get the station type of this tile.
static const NIHelper * GetFeatureHelper(uint window_number)
Get the NIHelper related to the window number.
StringID name
Name of this type of cargo.
SpriteType GetSpriteType(SpriteID sprite)
Get the sprite type of a given sprite.
Functions, definitions and such used only by the GUI.
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
Representation of the available callbacks with information on when they actually apply.
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.
Force the alignment, i.e. don't swap for RTL languages.
Sprite aligner (debug); Window numbers:
Functions related to NewGRF objects.
Data structure for an opened window.
Vehicle * Move(int n)
Get the vehicle at offset n of this vehicle chain.
bool _ctrl_pressed
Is Ctrl pressed?
virtual uint Resolve(uint index, uint var, uint param, bool *avail) const =0
Resolve (action2) variable for a given index.
void InvalidateNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Invalidate the inspect window for a given feature and index.
Vehicle drawn in vehicle details, refit window, ...
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Window used for inspecting NewGRFs.
static const NIFeature *const _nifeatures[]
Table with all NIFeatures.
Functions related to low-level strings.
static GrfSpecFeature GetFeatureNum(uint window_number)
Get the feature number related to the window number.
int16 y_offs
Number of pixels to shift the sprite downwards.
virtual ~NIHelper()
Silence a warning.
virtual void SetStringParameters(uint index) const =0
Set the string parameters to write the right data for a STRINGn.
NewGRF inspect (debug); Window numbers:
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
uint GetFeatureIndex() const
Get the feature index.
bool Contains(const T &key) const
Tests whether a key is assigned in this map.
SmallPair< int16, int16 > XyOffs
Pair for x and y offsets of the sprite before alignment. First value contains the x offset...
Definition of base types and functions in a cross-platform compatible way.
Height of bottom bevel border.
void SetCallerGRFID(uint32 grfid)
Set the GRFID of the item opening this window.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
A number of safeguards to prevent using unsafe methods.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
void SetObjectAtStringParameters(StringID string, uint32 index, TileIndex tile) const
Helper to make setting the strings easier for objects at a specific tile.
End of the fake features.
virtual const int32 * GetPSAFirstPosition(uint index, uint32 grfid) const
Gets the first position of the array containing the persistent storage.
The property is a simple integer.
uint chain_index
For ground vehicles: Index in vehicle chain.
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.
bool Insert(const T &key, const U &data)
Adds new item to this map.
void ShowNewGRFInspectWindow(GrfSpecFeature feature, uint index, const uint32 grfid)
Show the inspect window for a given feature and index.
GrfSpecFeature GetGrfSpecFeature(TileIndex tile)
Get the GrfSpecFeature associated with the tile.
#define lengthof(x)
Return the length of an fixed size array.
static T min(const T a, const T b)
Returns the minimum of two values.
Land info window; Window numbers:
virtual const void * GetInstance(uint index) const =0
Get the instance given an index.
virtual const void * GetSpec(uint index) const =0
Get (NewGRF) specs given an index.
const NIProperty * properties
The properties associated with this feature.
Functions to cache sprites in memory.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Vehicle * First() const
Get the first vehicle of this vehicle chain.
NewGRF handling of industry tiles.
void OnResize() override
Called after the window got resized.
const char * name
A (human readable) name for the property.
Draw border only, no background.
NewGRF handling of airport tiles.
const NIVariable * variables
The variables associated with this feature.
virtual uint GetPSASize(uint index, uint32 grfid) const
Allows to know the size of the persistent storage.
void Erase(Pair *pair)
Removes given pair from this map.
uint16 height
Height of the sprite.
The most basic (normal) sprite.
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
static const int CBM_NO_BIT
Mask to show no bit needs to be enabled for the callback.
void OnResize() override
Called after the window got resized.
No window, redirects to WC_MAIN_WINDOW.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
uint GetMaxSpriteID()
Get a reasonable (upper bound) estimate of the maximum SpriteID used in OpenTTD; there will be no spr...
uint16 width
Width of the sprite.
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a train vehicle image in the GUI.
SpriteID current_sprite
The currently shown sprite.
Header file for NewGRF stations.
static bool HasVariableParameter(uint variable)
Check whether the given variable has a parameter.
Height of top bevel border.
Base class for all vehicles.
static uint GetFeatureIndex(uint window_number)
Get the feature index related to the window number.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
virtual bool PSAWithParameter() const
Used to decide if the PSA needs a parameter or not.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
uint32 TileIndex
The index/ID of a Tile.
Vehicle * Next() const
Get the next vehicle of this vehicle.
TextDirection _current_text_dir
Text direction of the currently selected language.
Helper class to wrap some functionality/queries in.
ptrdiff_t offset
Offset of the variable in the class.
Window used for aligning sprites.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Functions related to zooming.
static const byte INVALID_CARGO
Constant representing invalid cargo.
int16 x_offs
Number of pixels to shift the sprite to the right.
bool HasChainIndex() const
Check whether this feature has chain index, i.e.
Coordinates of a point in 2D.
Spritepicker of SpriteAligner.
Offset at right to draw the frame rectangular area.
Representation of the data from a NewGRF property.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
void ValidateChainIndex()
Ensure that this->chain_index is in range.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Data 'tables' for NewGRF debugging.
Functions to handle the town part of NewGRF towns.
int32 WindowNumber
Number to differentiate different windows of the same class.
Specification of a rectangle with absolute coordinates of all edges.
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.
Text is written right-to-left by default.
Right align the text (must be a single bit).
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
Window functions not directly related to making/drawing windows.
Find a place automatically.
byte prop
The number of the property.
Base classes/functions for stations.
Container for all information for a given feature.
static const NIFeature * GetFeature(uint window_number)
Get the NIFeature related to the window number.
static uint32 var60params[GSF_FAKE_END][0x20]
The value for the variable 60 parameters.
Dimensions (a width and height) of a rectangle in 2D.
Offset at left to draw the frame rectangular area.
NewGrfDebugSpritePickerMode mode
Current state.
bool IsNewGRFInspectable(GrfSpecFeature feature, uint index)
Can we inspect the data given a certain feature and index.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
void ShowSpriteAlignerWindow()
Show the window for aligning sprites.
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-...
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.