|
OpenTTD Source
14.0-beta1
|
Go to the documentation of this file.
44 #include "table/strings.h"
58 return GB(window_number, 0, 24);
70 assert((index >> 24) == 0);
71 return (feature << 24) | index;
83 typedef const void *NIOffsetProc(
const void *b);
133 virtual uint
GetParent(uint index)
const = 0;
140 virtual const void *
GetInstance(uint index)
const = 0;
147 virtual const void *
GetSpec(uint index)
const = 0;
160 virtual uint32_t
GetGRFID(uint index)
const = 0;
170 virtual uint
Resolve(uint index, uint var, uint param,
bool *avail)
const = 0;
187 virtual uint
GetPSASize([[maybe_unused]] uint index, [[maybe_unused]] uint32_t grfid)
const
198 virtual const int32_t *
GetPSAFirstPosition([[maybe_unused]] uint index, [[maybe_unused]] uint32_t grfid)
const
224 SetDParam(0, STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT);
307 this->caller_grfid = grfid;
317 return f == GSF_TRAINS || f == GSF_ROADVEHICLES;
327 if (this->chain_index > 0) {
330 v = v->
Move(this->chain_index);
331 if (v !=
nullptr) index = v->
index;
341 if (this->chain_index == 0)
return;
346 v = v->
Move(this->chain_index);
347 if (v ==
nullptr) this->chain_index = 0;
362 void SetStringParameters(
WidgetID widget)
const override
397 if (offset < 0 || offset >= this->vscroll->
GetCapacity())
return;
413 if (u == v) sel_start = total_width;
417 default: NOT_REACHED();
419 if (u == v) sel_end = total_width;
425 if (total_width >
width) {
426 int sel_center = (sel_start + sel_end) / 2;
427 if (sel_center >
width / 2) skip = std::min(total_width -
width, sel_center -
width / 2);
453 const void *base_spec = nih->
GetSpec(index);
461 uint value = nih->
Resolve(index, niv->var, param, &avail);
463 if (!avail)
continue;
466 this->
DrawString(r, i++, fmt::format(
" {:02x}[{:02x}]: {:08x} ({})", niv->var, param, value, niv->name));
468 this->
DrawString(r, i++, fmt::format(
" {:02x}: {:08x} ({})", niv->var, value, niv->name));
473 uint psa_size = nih->
GetPSASize(index, this->caller_grfid);
475 if (psa_size != 0 && psa !=
nullptr) {
477 this->
DrawString(r, i++, fmt::format(
"Persistent storage [{:08X}]:",
BSWAP32(this->caller_grfid)));
479 this->
DrawString(r, i++,
"Persistent storage:");
481 assert(psa_size % 4 == 0);
482 for (uint j = 0; j < psa_size; j += 4, psa += 4) {
483 this->
DrawString(r, i++, fmt::format(
" {}: {} {} {} {}", j, psa[0], psa[1], psa[2], psa[3]));
490 const void *ptr = nip->offset_proc(base);
492 switch (nip->read_size) {
493 case 1: value = *(
const uint8_t *)ptr;
break;
494 case 2: value = *(
const uint16_t *)ptr;
break;
495 case 4: value = *(
const uint32_t *)ptr;
break;
496 default: NOT_REACHED();
503 string = STR_JUST_INT;
514 this->
DrawString(r, i++, fmt::format(
" {:02x}: {} ({})", nip->prop,
GetString(
string), nip->name));
522 const void *ptr = nic->offset_proc(base_spec);
524 switch (nic->read_size) {
525 case 1: value = *(
const uint8_t *)ptr;
break;
526 case 2: value = *(
const uint16_t *)ptr;
break;
527 case 4: value = *(
const uint32_t *)ptr;
break;
528 default: NOT_REACHED();
531 if (!
HasBit(value, nic->cb_bit))
continue;
532 this->
DrawString(r, i++, fmt::format(
" {:03x}: {}", nic->cb_id, nic->name));
534 this->
DrawString(r, i++, fmt::format(
" {:03x}: {} (unmasked)", nic->cb_id, nic->name));
545 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
558 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
569 if (this->chain_index > 0) {
579 if (v !=
nullptr && v->
Next() !=
nullptr) {
593 if (line == INT_MAX)
return;
597 if (line != 1)
continue;
601 this->current_edit_param = niv->var;
608 void OnQueryTextFinished(
char *str)
override
626 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
628 if (!gui_scope)
return;
640 static constexpr
NWidgetPart _nested_newgrf_inspect_chain_widgets[] = {
664 static constexpr
NWidgetPart _nested_newgrf_inspect_widgets[] = {
682 static WindowDesc _newgrf_inspect_chain_desc(__FILE__, __LINE__,
683 WDP_AUTO,
"newgrf_inspect_chain", 400, 300,
686 std::begin(_nested_newgrf_inspect_chain_widgets), std::end(_nested_newgrf_inspect_chain_widgets)
689 static WindowDesc _newgrf_inspect_desc(__FILE__, __LINE__,
690 WDP_AUTO,
"newgrf_inspect", 400, 300,
693 std::begin(_nested_newgrf_inspect_widgets), std::end(_nested_newgrf_inspect_widgets)
710 WindowDesc *desc = (feature == GSF_TRAINS || feature == GSF_ROADVEHICLES) ? &_newgrf_inspect_chain_desc : &_newgrf_inspect_desc;
764 if (nif ==
nullptr)
return false;
785 case STATION_RAIL:
return GSF_STATIONS;
786 case STATION_AIRPORT:
return GSF_AIRPORTTILES;
787 case STATION_BUS:
return GSF_ROADSTOPS;
788 case STATION_TRUCK:
return GSF_ROADSTOPS;
803 case VEH_ROAD:
return GSF_ROADVEHICLES;
816 typedef std::pair<int16_t, int16_t>
XyOffs;
824 static bool crosshair;
846 void SetStringParameters(
WidgetID widget)
const override
864 const auto key_offs_pair = this->offs_start_map.find(this->current_sprite);
865 if (key_offs_pair != this->offs_start_map.end()) {
891 fill->height =
resize->height;
898 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
907 if (SpriteAlignerWindow::centre) {
919 DrawSprite(this->current_sprite, PAL_NONE, x, y,
nullptr, SpriteAlignerWindow::zoom);
925 if (SpriteAlignerWindow::crosshair) {
933 const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
937 int max = std::min<int>(this->vscroll->
GetPosition() + this->vscroll->GetCapacity(), (uint)list.size());
940 for (
int i = this->vscroll->
GetPosition(); i < max; i++) {
950 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
966 this->current_sprite = (this->current_sprite + 1) %
GetMaxSpriteID();
973 _newgrf_debug_sprite_picker.
mode = SPM_WAIT_CLICK;
1007 if (this->offs_start_map.count(this->current_sprite) == 0) {
1026 this->offs_start_map.erase(this->current_sprite);
1031 SpriteAlignerWindow::centre = !SpriteAlignerWindow::centre;
1037 SpriteAlignerWindow::crosshair = !SpriteAlignerWindow::crosshair;
1051 void OnQueryTextFinished(
char *str)
override
1055 this->current_sprite = atoi(str);
1056 if (this->current_sprite >=
GetMaxSpriteID()) this->current_sprite = 0;
1058 this->current_sprite = (this->current_sprite + 1) %
GetMaxSpriteID();
1068 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1070 if (!gui_scope)
return;
1090 bool SpriteAlignerWindow::centre =
true;
1091 bool SpriteAlignerWindow::crosshair =
true;
1093 static constexpr
NWidgetPart _nested_sprite_aligner_widgets[] = {
1143 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_SA_LIST),
SetResize(1, 1),
SetMatrixDataTip(1, 0, STR_NULL),
SetFill(1, 1),
SetScrollbar(
WID_SA_SCROLLBAR),
1163 static WindowDesc _sprite_aligner_desc(__FILE__, __LINE__,
1164 WDP_AUTO,
"sprite_aligner", 400, 300,
1167 std::begin(_nested_sprite_aligner_widgets), std::end(_nested_sprite_aligner_widgets)
1175 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.
uint16_t height
Height of the sprite.
void OnResize() override
Called after the window got resized.
@ MP_HOUSE
A house by a town.
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.
@ ZOOM_LVL_OUT_2X
Zoomed 2 times out.
int16_t x_offs
Number of pixels to shift the sprite to the right.
void SetDParamMaxDigits(size_t n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
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.
void DrawVehicleChainWidget(const Rect &r) const
Helper function to draw the vehicle chain widget.
@ 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.
Vehicle * Next() const
Get the next vehicle of this vehicle.
@ ZOOM_LVL_END
End for iteration.
@ ZOOM_LVL_OUT_16X
Zoomed 16 times out.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
static const uint8_t PC_WHITE
White palette colour.
bool HasChainIndex() const
Check whether this feature has chain index, i.e.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Representation of the available callbacks with information on when they actually apply.
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
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.
bool _ctrl_pressed
Is Ctrl pressed?
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.
ZoomLevel
All zoom levels we know.
bool IsLevelCrossing(Tile t)
Return whether a tile is a level crossing.
ClientSettings _settings_client
The current settings for this game.
@ EIT_IN_DETAILS
Vehicle drawn in vehicle details, refit window, ...
uint32_t caller_grfid
GRFID of the caller of this window, 0 if it has no caller.
@ MP_INDUSTRY
Part of an industry.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
const char * name
The human readable name of the callback.
@ GSF_INVALID
An invalid spec feature.
Rect Expand(int s) const
Copy and expand Rect by s pixels.
@ 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.
ZoomLevel _gui_zoom
GUI Zoom level.
byte current_edit_param
The currently edited parameter, to update the right one.
const NIVariable * variables
The variables associated with this feature.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
bool StrEmpty(const char *s)
Check if a string buffer is empty.
ZoomLevel zoom_max
maximum zoom out level
@ MP_ROAD
A tile with road (or tram tracks)
Helper class to wrap some functionality/queries in.
VehicleCellSize GetVehicleImageCellSize(VehicleType type, EngineImageType image_type)
Get the GUI cell size for a vehicle image.
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::map< SpriteID, XyOffs > offs_start_map
Mapping of starting offsets for the sprites which have been aligned in the sprite aligner window.
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
High level window description.
uint16_t cb_id
The number of the callback.
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
virtual uint GetPSASize([[maybe_unused]] uint index, [[maybe_unused]] uint32_t grfid) const
Allows to know the size of the persistent storage.
virtual bool IsInspectable(uint index) const =0
Is the item with the given index inspectable?
constexpr 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 const NIFeature * GetFeature(uint window_number)
Get the NIFeature related to the window number.
@ WDP_AUTO
Find a place automatically.
ResizeInfo resize
Resize information.
static uint32_t BSWAP32(uint32_t x)
Perform a 32 bits endianness bitswap on x.
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.
int32_t WindowNumber
Number to differentiate different windows of the same class.
@ FS_NORMAL
Index of the normal font in the font tables.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
NewGrfDebugSpritePicker _newgrf_debug_sprite_picker
The sprite picker.
int height
Height of the window (number of pixels down in y direction)
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.
uint16_t width
Width of the sprite.
SpriteID current_sprite
The currently shown sprite.
@ GSF_FAKE_END
End of the fake features.
void SetObjectAtStringParameters(StringID string, uint32_t index, TileIndex tile) const
Helper to make setting the strings easier for objects at a specific tile.
@ 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 DrawMainPanelWidget(const Rect &r) const
Helper function to draw the main panel widget.
@ ZOOM_LVL_OUT_8X
Zoomed 8 times out.
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
virtual const int32_t * GetPSAFirstPosition([[maybe_unused]] uint index, [[maybe_unused]] uint32_t grfid) const
Gets the first position of the array containing the persistent storage.
virtual void ShowNewGRFInspectWindow() const
Show the NewGRF inspection window.
Container for all information for a given feature.
void SetCallerGRFID(uint32_t grfid)
Set the GRFID of the item opening this window.
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.
Coordinates of a point in 2D.
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
uint GetFeatureIndex() const
Get the feature index.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
WindowNumber window_number
Window number within the window class.
VehicleType
Available vehicle types.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
void OnResize() override
Called after the window got resized.
static uint GetInspectWindowNumber(GrfSpecFeature feature, uint index)
Get the window number for the inspect window given a feature and index.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
StationType GetStationType(Tile t)
Get the station type of this tile.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
@ 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.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
ZoomLevel zoom_min
minimum zoom out level
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.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Spritepicker of SpriteAligner.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
static GrfSpecFeature GetFeatureNum(uint window_number)
Get the feature number related to the window number.
int UnScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
Vehicle * First() const
Get the first vehicle of this vehicle chain.
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.
virtual ~NIHelper()=default
Silence a warning.
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.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
int16_t y_offs
Number of pixels to shift the sprite downwards.
virtual uint GetParent(uint index) const =0
Get the parent "window_number" of a given instance.
void SetSimpleStringParameters(StringID string, uint32_t index) const
Helper to make setting the strings easier.
Window used for aligning sprites.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
const char * name
A (human readable) name for the property.
@ MP_STATION
A tile of a station.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
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::pair< int16_t, int16_t > XyOffs
Pair for x and y offsets of the sprite before alignment. First value contains the x offset,...
@ ZOOM_LVL_OUT_32X
Zoomed 32 times out.
void SetWidgetsLoweredState(bool lowered_stat, Args... widgets)
Sets the lowered/raised status of a list of widgets.
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
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.
void DrawRectOutline(const Rect &r, int colour, int width, int dash)
Draw the outline of a Rect.
Representation on the NewGRF variables.
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
void DrawVehicleImage(const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip)
Draws an image of a vehicle chain.
void ShowNewGRFInspectWindow(GrfSpecFeature feature, uint index, const uint32_t grfid)
Show the inspect window for a given feature and index.
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
@ WC_NEWGRF_INSPECT
NewGRF inspect (debug); Window numbers:
@ ZOOM_LVL_NORMAL
The normal zoom level.
Data structure for an opened window.
virtual uint32_t GetGRFID(uint index) const =0
Get the GRFID of the file that includes this item.
@ VEH_TRAIN
Train vehicle type.
NIOffsetProc * offset_proc
Callback proc to get the actual variable address in memory.
void DrawString(const Rect &r, int offset, const std::string &string) const
Helper function to draw a string (line) in the window.
static uint32_t var60params[GSF_FAKE_END][0x20]
The value for the variable 60 parameters.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
@ ZOOM_LVL_OUT_4X
Zoomed 4 times out.
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.
int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
@ WC_SPRITE_ALIGNER
Sprite aligner (debug); Window numbers:
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Data structure describing a sprite.
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.
static const uint8_t PC_LIGHT_BLUE
Light blue palette colour.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
@ Normal
The most basic (normal) sprite.
void ValidateChainIndex()
Ensure that this->chain_index is in range.
GUISettings gui
settings related to the GUI
@ FR_BORDERONLY
Draw border only, no background.
Data about how and where to blit pixels.
byte prop
The number of the property.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.