45 #include "table/strings.h" 59 return GB(window_number, 0, 24);
71 assert((index >> 24) == 0);
72 return (feature << 24) | index;
125 virtual bool IsInspectable(uint index)
const = 0;
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;
152 virtual void SetStringParameters(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);
276 static const int LEFT_OFFSET = 5;
277 static const int RIGHT_OFFSET = 5;
278 static const int TOP_OFFSET = 5;
279 static const int BOTTOM_OFFSET = 5;
311 this->caller_grfid = grfid;
321 return f == GSF_TRAINS || f == GSF_ROADVEHICLES;
331 if (this->chain_index > 0) {
332 assert(this->HasChainIndex());
334 v = v->
Move(this->chain_index);
335 if (v != NULL) index = v->
index;
345 if (this->chain_index == 0)
return;
347 assert(this->HasChainIndex());
350 v = v->
Move(this->chain_index);
351 if (v == NULL) this->chain_index = 0;
356 this->CreateNestedTree();
358 this->FinishInitNested(wno);
363 this->OnInvalidateData(0,
true);
377 assert(this->HasChainIndex());
387 size->height = 5 * resize->height + TOP_OFFSET + BOTTOM_OFFSET;
403 va_start(va, format);
408 if (offset < 0 || offset >= this->vscroll->
GetCapacity())
return;
410 ::DrawString(r.left + LEFT_OFFSET, r.right - RIGHT_OFFSET, r.top + TOP_OFFSET + (offset * this->resize.step_height), buf, TC_BLACK);
422 if (u == v) sel_start = total_width;
426 default: NOT_REACHED();
428 if (u == v) sel_end = total_width;
433 if (total_width > width) {
434 int sel_center = (sel_start + sel_end) / 2;
435 if (sel_center > width / 2) skip =
min(total_width - width, sel_center - width / 2);
440 int y = (r.top + r.bottom - h) / 2;
459 const void *base_spec = nih->
GetSpec(index);
467 uint value = nih->
Resolve(index, niv->var, param, &avail);
469 if (!avail)
continue;
471 if (HasVariableParameter(niv->var)) {
472 this->
DrawString(r, i++,
" %02x[%02x]: %08x (%s)", niv->var, param, value, niv->name);
474 this->
DrawString(r, i++,
" %02x: %08x (%s)", niv->var, value, niv->name);
479 uint psa_size = nih->
GetPSASize(index, this->caller_grfid);
481 if (psa_size != 0 && psa != NULL) {
483 this->
DrawString(r, i++,
"Persistent storage [%08X]:",
BSWAP32(this->caller_grfid));
485 this->
DrawString(r, i++,
"Persistent storage:");
487 assert(psa_size % 4 == 0);
488 for (uint j = 0; j < psa_size; j += 4, psa += 4) {
489 this->
DrawString(r, i++,
" %i: %i %i %i %i", j, psa[0], psa[1], psa[2], psa[3]);
496 const void *ptr = (
const byte *)base + nip->offset;
498 switch (nip->read_size) {
499 case 1: value = *(
const uint8 *)ptr;
break;
500 case 2: value = *(
const uint16 *)ptr;
break;
501 case 4: value = *(
const uint32 *)ptr;
break;
502 default: NOT_REACHED();
509 string = STR_JUST_INT;
521 GetString(buffer,
string,
lastof(buffer));
522 this->
DrawString(r, i++,
" %02x: %s (%s)", nip->prop, buffer, nip->name);
530 const void *ptr = (
const byte *)base_spec + nic->offset;
532 switch (nic->read_size) {
533 case 1: value = *(
const uint8 *)ptr;
break;
534 case 2: value = *(
const uint16 *)ptr;
break;
535 case 4: value = *(
const uint32 *)ptr;
break;
536 default: NOT_REACHED();
539 if (!
HasBit(value, nic->cb_bit))
continue;
540 this->
DrawString(r, i++,
" %03x: %s", nic->cb_id, nic->name);
542 this->
DrawString(r, i++,
" %03x: %s (unmasked)", nic->cb_id, nic->name);
564 if (this->chain_index > 0) {
566 this->InvalidateData();
571 if (this->HasChainIndex()) {
574 if (v != NULL && v->
Next() != NULL) {
576 this->InvalidateData();
588 if (line == INT_MAX)
return;
592 if (line != 1)
continue;
594 if (!HasVariableParameter(niv->var))
break;
596 this->current_edit_param = niv->var;
623 if (!gui_scope)
return;
624 if (this->HasChainIndex()) {
625 this->ValidateChainIndex();
635 static const NWidgetPart _nested_newgrf_inspect_chain_widgets[] = {
659 static const NWidgetPart _nested_newgrf_inspect_widgets[] = {
678 WDP_AUTO,
"newgrf_inspect_chain", 400, 300,
681 _nested_newgrf_inspect_chain_widgets,
lengthof(_nested_newgrf_inspect_chain_widgets)
685 WDP_AUTO,
"newgrf_inspect", 400, 300,
688 _nested_newgrf_inspect_widgets,
lengthof(_nested_newgrf_inspect_widgets)
705 WindowDesc *desc = (feature == GSF_TRAINS || feature == GSF_ROADVEHICLES) ? &_newgrf_inspect_chain_desc : &_newgrf_inspect_desc;
759 if (nif == NULL)
return false;
780 case STATION_RAIL:
return GSF_STATIONS;
781 case STATION_AIRPORT:
return GSF_AIRPORTTILES;
796 case VEH_ROAD:
return GSF_ROADVEHICLES;
817 this->CreateNestedTree();
819 this->FinishInitNested(wno);
844 if (key_offs_pair != this->offs_start_map.
End()) {
867 size->height = (1 + 200 / resize->height) * resize->height;
886 DrawSprite(this->current_sprite, PAL_NONE, x, y, NULL, ZOOM_LVL_GUI);
894 const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
916 this->current_sprite = (this->current_sprite == 0 ?
GetMaxSpriteID() : this->current_sprite) - 1;
927 this->current_sprite = (this->current_sprite + 1) %
GetMaxSpriteID();
934 _newgrf_debug_sprite_picker.
mode = SPM_WAIT_CLICK;
939 const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
971 if (!(this->offs_start_map.
Contains(this->current_sprite))) {
989 this->offs_start_map.
Erase(this->current_sprite);
999 this->current_sprite = atoi(str);
1000 if (this->current_sprite >=
GetMaxSpriteID()) this->current_sprite = 0;
1002 this->current_sprite = (this->current_sprite + 1) %
GetMaxSpriteID();
1014 if (!gui_scope)
return;
1028 static const NWidgetPart _nested_sprite_aligner_widgets[] = {
1067 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),
1068 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),
1078 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_SA_LIST),
SetResize(1, 1),
SetMatrixDataTip(1, 0, STR_NULL),
SetFill(1, 1),
SetScrollbar(
WID_SA_SCROLLBAR),
1087 WDP_AUTO,
"sprite_aligner", 400, 300,
1090 _nested_sprite_aligner_widgets,
lengthof(_nested_sprite_aligner_widgets)
1098 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.
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.
bool Contains(const T &key) const
Tests whether a key is assigned in this map.
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.
const Pair * Find(const T &key) const
Finds given key in this map.
SmallMap< SpriteID, XyOffs > offs_start_map
Mapping of starting offsets for the sprites which have been aligned in the sprite aligner window...
virtual void OnQueryTextFinished(char *str)
The query window opened from this window has closed.
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.
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.
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.
static bool IsInsideBS(const T x, const uint base, const uint size)
Checks if a value is between a window started at some base point.
VehicleCellSize GetVehicleImageCellSize(VehicleType type, EngineImageType image_type)
Get the GUI cell size for a vehicle image.
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.
bool Insert(const T &key, const U &data)
Adds new item to this map.
Width of right bevel border.
Functions for Standard In/Out file operations.
const char * FioGetFilename(uint8 slot)
Get the filename associated with a slot.
const NIHelper * helper
The class container all helper functions.
virtual void OnQueryTextFinished(char *str)
The query window opened from this window has closed.
#define lastof(x)
Get the last element of an fixed size array.
Stuff related to the text buffer GUI.
The most basic (normal) sprite.
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.
virtual void OnResize()
Called after the window got resized.
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.
const SmallPair< T, U > * End() const
Get the pointer behind the last valid item (const)
Functions related to the vehicle's GUIs.
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.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
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.
virtual void OnResize()
Called after the window got resized.
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 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.
uint Length() const
Get the number of items in the list.
virtual void SetStringParameters(uint index) const =0
Set the string parameters to write the right data for a STRINGn.
VehicleType
Available vehicle types.
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.
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.
A number of safeguards to prevent using unsafe methods.
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 void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
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.
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
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.
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.
int GetDisplayImageWidth(Point *offset=NULL) const
Get the width of a road vehicle image in the GUI.
Vehicle * First() const
Get the first vehicle of this vehicle chain.
NewGRF handling of industry tiles.
const char * name
A (human readable) name for the property.
int GetDisplayImageWidth(Point *offset=NULL) const
Get the width of a train vehicle image in the GUI.
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.
uint16 height
Height of the sprite.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
static const int CBM_NO_BIT
Mask to show no bit needs to be enabled for the callback.
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.
void Erase(Pair *pair)
Removes given pair from this map.
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.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
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.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
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.
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.
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.
SmallVector< SpriteID, 256 > sprites
Sprites found.
Base classes/functions for stations.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
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.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
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-...
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.