OpenTTD Source
12.0-beta2
|
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);
311 this->caller_grfid = grfid;
321 return f == GSF_TRAINS || f == GSF_ROADVEHICLES;
331 if (this->chain_index > 0) {
334 v = v->
Move(this->chain_index);
335 if (v !=
nullptr) index = v->
index;
345 if (this->chain_index == 0)
return;
350 v = v->
Move(this->chain_index);
351 if (v ==
nullptr) this->chain_index = 0;
398 void WARN_FORMAT(4, 5) DrawString(const
Rect &r,
int offset, const
char *format, ...)
const
403 va_start(va, format);
404 vseprintf(buf,
lastof(buf), format, va);
408 if (offset < 0 || offset >= this->vscroll->
GetCapacity())
return;
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 = std::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);
463 this->DrawString(r, i++,
"Variables:");
467 uint value = nih->
Resolve(index, niv->var, param, &avail);
469 if (!avail)
continue;
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 !=
nullptr) {
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]);
494 this->DrawString(r, i++,
"Properties:");
496 const void *ptr = nip->offset_proc(base);
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);
527 this->DrawString(r, i++,
"Callbacks:");
530 const void *ptr = nic->offset_proc(base_spec);
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) {
574 if (v !=
nullptr && v->
Next() !=
nullptr) {
588 if (line == INT_MAX)
return;
592 if (line != 1)
continue;
596 this->current_edit_param = niv->var;
623 if (!gui_scope)
return;
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 ==
nullptr)
return false;
780 case STATION_RAIL:
return GSF_STATIONS;
781 case STATION_AIRPORT:
return GSF_AIRPORTTILES;
796 case VEH_ROAD:
return GSF_ROADVEHICLES;
843 const auto key_offs_pair = this->offs_start_map.
Find(this->current_sprite);
844 if (key_offs_pair != this->offs_start_map.end()) {
868 fill->height =
resize->height;
891 DrawSprite(this->current_sprite, PAL_NONE, x, y,
nullptr, ZOOM_LVL_GUI);
899 const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
903 int max = std::min<int>(this->vscroll->
GetPosition() + this->vscroll->GetCapacity(), (uint)list.size());
906 for (
int i = this->vscroll->
GetPosition(); i < max; i++) {
932 this->current_sprite = (this->current_sprite + 1) %
GetMaxSpriteID();
939 _newgrf_debug_sprite_picker.
mode = SPM_WAIT_CLICK;
944 const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
976 if (!(this->offs_start_map.
Contains(this->current_sprite))) {
994 this->offs_start_map.
Erase(this->current_sprite);
1004 this->current_sprite = atoi(str);
1005 if (this->current_sprite >=
GetMaxSpriteID()) this->current_sprite = 0;
1007 this->current_sprite = (this->current_sprite + 1) %
GetMaxSpriteID();
1019 if (!gui_scope)
return;
1033 static const NWidgetPart _nested_sprite_aligner_widgets[] = {
1072 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),
1073 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),
1083 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_SA_LIST),
SetResize(1, 1),
SetMatrixDataTip(1, 0, STR_NULL),
SetFill(1, 1),
SetScrollbar(
WID_SA_SCROLLBAR),
1092 WDP_AUTO,
"sprite_aligner", 400, 300,
1095 _nested_sprite_aligner_widgets,
lengthof(_nested_sprite_aligner_widgets)
1103 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.
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.
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
uint32 TileIndex
The index/ID of a Tile.
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.
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:
@ 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 DrawVehicleImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip)
Draws an image of a vehicle chain.
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.
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.
static const int TOP_OFFSET
Position of top edge.
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.
static const int BOTTOM_OFFSET
Position of bottom edge.
NewGrfDebugSpritePicker _newgrf_debug_sprite_picker
The sprite picker.
int height
Height of the window (number of pixels down in y direction)
static const int LEFT_OFFSET
Position of left edge.
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)
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
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.
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
static StationType GetStationType(TileIndex t)
Get the station type of this tile.
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
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.
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.
@ WD_BEVEL_RIGHT
Width of right bevel border.
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.
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
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.
static const int RIGHT_OFFSET
Position of right edge.
@ WD_BEVEL_TOP
Height of top bevel border.
std::vector< Pair >::const_iterator Find(const T &key) const
Finds given key in this map.
@ WD_BEVEL_LEFT
Width of left bevel border.
#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).
@ 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.
@ 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.
@ WD_BEVEL_BOTTOM
Height of bottom bevel border.
#define lastof(x)
Get the last element of an fixed size array.
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.