33#include "table/strings.h"
54 for (
const auto *spec : cls.Specs()) {
55 if (spec !=
nullptr && spec->IsEverAvailable())
return true;
66 const auto *objclass = this->GetClass(
id);
68 return objclass->name;
76 const auto *spec = this->GetSpec(cls_id,
id);
77 return (spec ==
nullptr || !spec->IsEverAvailable()) ?
INVALID_STRING_ID : spec->name;
82 const auto *spec = this->GetSpec(cls_id,
id);
83 return spec->IsAvailable();
86 void DrawType(
int x,
int y,
int cls_id,
int id)
const override
88 const auto *spec = this->GetSpec(cls_id,
id);
89 if (!spec->grf_prop.HasGrfFile()) {
104 items.insert(GetPickerItem(spec));
120 this->ConstructWindow();
130 int size = spec ==
nullptr ? 0 : spec->
size;
160 if (spec !=
nullptr) {
162 if (spec->
views >= 4) size.height +=
resize.height;
175 if (spec !=
nullptr) {
198 if (spec ==
nullptr)
break;
224 if (spec ==
nullptr)
break;
241 if (y > this->info_height) {
261 if (spec ==
nullptr) {
281 this->UpdateSelectSize(spec);
334 if (
pt.x == -1)
return;
367 static inline HotkeyList hotkeys{
"buildobject", {
372static constexpr NWidgetPart _nested_build_object_widgets[] = {
404 _nested_build_object_widgets,
405 &BuildObjectWindow::hotkeys
412 if (ObjectPickerCallbacks::instance.IsActive()) {
413 return AllocateWindowDescFront<BuildObjectWindow>(_build_object_desc, 0);
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
The window used for building objects.
void SetStringParameters(WidgetID widget) const override
Initialize string parameters for a widget.
int info_height
The height of the info box.
static EventState BuildObjectGlobalHotkeys(int hotkey)
Handler for global hotkeys of the BuildObjectWindow.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) override
The user is dragging over the map when the tile highlight mode has been set.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
void OnInit() override
Notification that the nested widget tree gets initialized.
void UpdateButtons(const ObjectSpec *spec)
Update buttons to show the selection to the user.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) override
The user has dragged over the map when the tile highlight mode has been set.
constexpr bool Test(Tenum value) const
Test if the enum value is set.
Struct containing information relating to NewGRF classes for stations and airports.
static std::span< NewGRFClass< Tspec, Tindex, Tmax > const > Classes()
Get read-only span of all classes of this type.
static NewGRFClass * Get(Tindex class_index)
Get a particular class.
const Tspec * GetSpec(uint index) const
Get a spec from the class at a given index.
StringID GetClassName(int id) const override
Get the name of a class.
void DrawType(int x, int y, int cls_id, int id) const override
Draw preview image of an item.
void SetSelectedClass(int id) const override
Set the selected class.
StringID GetTypeTooltip() const override
Get the tooltip string for the type grid.
bool IsActive() const override
Should picker class/type selection be enabled?
StringID GetClassTooltip() const override
Get the tooltip string for the class list.
bool IsTypeAvailable(int cls_id, int id) const override
Test if an item is currently buildable.
int GetSelectedType() const override
Get the selected type.
void SetSelectedType(int id) const override
Set the selected type.
int GetSelectedClass() const override
Get the index of the selected class.
StringID GetTypeName(int cls_id, int id) const override
Get the item of a type.
void FillUsedItems(std::set< PickerItem > &items) override
Fill a set with all items that are used by the current player.
Helper for PickerCallbacks when the class system is based on NewGRFClass.
static const int PREVIEW_LEFT
Offset from left edge to draw preview.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
@ PCWHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
static const int PREVIEW_WIDTH
Width of each preview button.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
static const int PREVIEW_BOTTOM
Offset from bottom edge to draw preview.
@ PFI_POSITION
Update scroll positions.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
static const int PREVIEW_HEIGHT
Height of each preview button.
Functions related to commands.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
bool _ctrl_pressed
Is Ctrl pressed?
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
@ SA_CENTER
Center both horizontally and vertically.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Hotkey related functions.
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Base for the NewGRF implementation.
@ CBID_OBJECT_FUND_MORE_TEXT
Called to determine more text in the fund object window.
@ FundMoreText
additional text in fund window
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8_t view)
Draw representation of an object (tile) for GUI purposes.
uint16_t GetObjectCallback(CallbackID callback, uint32_t param1, uint32_t param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8_t view)
Perform a callback for an object.
Functions related to NewGRF objects.
static const uint8_t OBJECT_SIZE_1X1
The value of a NewGRF's size property when the object is 1x1 tiles: low nibble for X,...
ObjectClassID
Class IDs for objects.
@ INVALID_OBJECT_CLASS
Class for the less fortunate.
@ OBJECT_CLASS_BEGIN
The lowest valid value.
void StartTextRefStackUsage(const GRFFile *grffile, uint8_t numEntries, const uint32_t *values)
Start using the TTDP compatible string code parsing.
StringID GetGRFStringID(uint32_t grfid, GRFStringID stringid)
Returns the index for this stringid associated with its grfID.
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
Header of Action 04 "universal holder" structure and functions.
static constexpr GRFStringID GRFSTR_MISC_GRF_TEXT
Miscellaneous GRF text range.
Functions related to objects.
Command definitions related to objects.
Window * ShowBuildObjectPicker()
Show our object picker.
void InitializeObjectGui()
Reset all data of the object GUI.
static ObjectPickerSelection _object_gui
Settings of the object picker.
std::unique_ptr< NWidgetBase > MakePickerClassWidgets()
Create nested widgets for the class picker widgets.
std::unique_ptr< NWidgetBase > MakePickerTypeWidgets()
Create nested widgets for the type picker widgets.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
ClientSettings _settings_client
The current settings for this game.
Functions related to sound.
@ SND_15_BEEP
19 == 0x13 GUI button click
void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
Draw TTD sprite sequence in GUI.
Definition of base types and functions in a cross-platform compatible way.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
SoundSettings sound
sound effect settings
bool freeform_edges
allow terraforming the tiles at the map edges
Dimensions (a width and height) of a rectangle in 2D.
Data about how and where to blit pixels.
Ground palette sprite of a tile, together with its sprite layout.
bool HasGrfFile() const
Test if this entity was introduced by NewGRF.
uint16_t local_id
id defined by the grf file for this entity
uint32_t grfid
grfid that introduced this entity.
const struct GRFFile * grffile
grf file that introduced this entity
ConstructionSettings construction
construction of things in-game
List of hotkeys for a window.
All data for a single hotkey.
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Tindex class_index
Class index of this spec, invalid until class is allocated.
uint8_t sel_view
Selected view of the object.
ObjectClassID sel_class
Selected object class.
uint16_t sel_type
Selected object type within the class.
Allow incrementing of ObjectClassID variables.
bool IsEverAvailable() const
Check whether the object might be available at some point in this game with the current game mode.
static const ObjectSpec * Get(ObjectType index)
Get the specification associated with a specific ObjectType.
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
uint8_t size
The size of this objects; low nibble for X, high nibble for Y.
uint Index() const
Gets the index of this spec.
ObjectCallbackMasks callback_mask
Bitmask of requested/allowed callbacks.
uint8_t views
The number of views.
An object, such as transmitter, on the map.
Coordinates of a point in 2D.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Specification of a rectangle with absolute coordinates of all edges.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
bool click_beep
Beep on a random selection of buttons.
High level window description.
Number to differentiate different windows of the same class.
Data structure for an opened window.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
virtual void SetStringParameters(WidgetID widget) const
Initialize string parameters for a widget.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
ResizeInfo resize
Resize information.
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
virtual void OnInit()
Notification that the nested widget tree gets initialized.
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void SetObjectToPlaceWnd(CursorID icon, PaletteID pal, HighLightStyle mode, Window *w)
Change the cursor and mouse click/drag handling to a mode for performing special operations like tile...
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
highlighting tiles while only going over them with the mouse
@ HT_DIAGONAL
Also allow 'diagonal rectangles'. Only usable in combination with HT_RECT or HT_POINT.
@ HT_RECT
rectangle (stations, depots, ...)
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
Functions related to (drawing on) viewports.
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
@ VPM_X_AND_Y
area of land in X and Y directions
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
@ DDSP_BUILD_OBJECT
Build an object.
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ Construction
This window is used for construction; close it whenever changing company.
@ WDP_AUTO
Find a place automatically.
EventState
State of handling an event.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WC_BUILD_OBJECT
Build object; Window numbers:
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
Functions related to zooming.
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.