24 #include "table/strings.h" 84 this->vscroll->
SetCount(ObjectClass::GetUIClassCount());
111 int size = spec ==
nullptr ? 0 : spec->
size;
125 for (uint i = 0; i < ObjectClass::GetClassCount(); i++) {
130 size->width += padding.width;
146 if (spec !=
nullptr) {
147 if (spec->
views >= 2) size->width += resize->width;
148 if (spec->
views >= 4) size->height += resize->height;
156 bool two_wide =
false;
163 two_wide |= spec->
views >= 2;
168 for (
size_t i = 0; i <
lengthof(height); i++) {
177 size->height =
max(height[0], height[1] * 2 + 2);
186 if (spec !=
nullptr) {
187 if (spec->
views >= 2) size->width = size->width / 2 - 1;
188 if (spec->
views >= 4) size->height = size->height / 2 - 1;
213 switch (
GB(widget, 0, 16)) {
217 for (uint i = 0; i < ObjectClass::GetClassCount(); i++) {
220 if (!this->vscroll->
IsVisible(pos++))
continue;
230 if (spec ==
nullptr)
break;
241 if (
FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left + 1, r.bottom - r.top + 1)) {
258 int obj_index = objclass->GetIndexFromUI(
GB(widget, 16, 16));
259 if (obj_index < 0)
break;
260 const ObjectSpec *spec = objclass->GetSpec(obj_index);
261 if (spec ==
nullptr)
break;
268 if (
FillDrawPixelInfo(&tmp_dpi, r.left + 1, r.top, (r.right - 1) - (r.left + 1) + 1, r.bottom - r.top + 1)) {
286 if (spec ==
nullptr)
break;
292 if (callback_res > 0x400) {
296 if (message != STR_NULL && message != STR_UNDEFINED) {
301 int y =
DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, message, TC_ORANGE) - r.top;
303 if (y > this->info_height) {
348 void UpdateSelectSize()
368 int view_number, object_number;
369 if (sel_index == -1) {
373 view_number = sel_view;
379 this->UpdateSelectSize();
390 switch (
GB(widget, 0, 16)) {
393 if (num_clicked >= (
int)ObjectClass::GetUIClassCount())
break;
402 int num_clicked = objclass->GetIndexFromUI(
GB(widget, 16, 16));
403 if (num_clicked >= 0 && objclass->GetSpec(num_clicked)->IsAvailable()) this->
SelectOtherObject(num_clicked);
436 for (uint i = 0; i < sel_objclass->
GetSpecCount(); i++) {
437 const ObjectSpec *spec = sel_objclass->GetSpec(i);
449 const ObjectSpec *spec = objclass->GetSpec(i);
472 static const NWidgetPart _nested_build_object_widgets[] = {
505 NWidget(
WWT_EMPTY, INVALID_COLOUR,
WID_BO_INFO),
SetPadding(2, 5, 0, 5),
SetFill(1, 0),
SetResize(1, 0),
518 _nested_build_object_widgets,
lengthof(_nested_build_object_widgets)
525 if (ObjectClass::GetUIClassCount() > 0) {
526 AllocateWindowDescFront<BuildObjectWindow>(&_build_object_desc, 0);
void EnsureSelectedObjectClassIsVisible()
Scroll WID_BO_CLASS_LIST so that the selected object class is visible.
Functions related to OTTD's strings.
static const uint TILE_PIXELS
Pixel distance between tile columns/rows in #ZOOM_LVL_BASE.
Maximum number of classes.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Data about how and where to blit pixels.
ResizeInfo resize
Resize information.
static const ObjectType NUM_OBJECTS
Number of supported objects overall.
static void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
Draw TTD sprite sequence in GUI.
bool IsAvailable() const
Check whether the object is available at this time.
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen...
Offset at right of a matrix cell.
High level window description.
bool CanRestoreSelectedObject()
Tests whether the previously selected object can be selected.
Called to determine more text in the fund object window.
uint GetSpecCount() const
Get the number of allocated specs within the class.
void UpdateButtons(ObjectClassID sel_class, int sel_index, uint sel_view)
Update buttons to show the selection to the user.
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
bool IsEverAvailable() const
Check whether the object might be available at some point in this game with the current game mode...
additional text in fund window
Offset at top of a matrix cell.
Allow incrementing of ObjectClassID variables.
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
StringID GetGRFStringID(uint32 grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
static T max(const T a, const T b)
Returns the maximum of two values.
void InitializeObjectGui()
Reset all data of the object GUI.
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
static const ObjectSpec * Get(ObjectType index)
Get the specification associated with a specific ObjectType.
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.
uint GetUISpecCount() const
Get the number of potentially user-available specs within the class.
Functions related to (drawing on) viewports.
uint8 size
The size of this objects; low nibble for X, high nibble for Y.
Functions related to NewGRF objects.
Data structure for an opened window.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
void OnResize() override
Called after the window got resized.
static ObjectClassID _selected_object_class
the currently visible object class
Header of Action 04 "universal holder" structure and functions.
uint8 height
The height of this structure, in heightlevels; max MAX_TILE_HEIGHT.
static const int OBJECT_MARGIN
The margin (in pixels) around an object.
Struct containing information relating to NewGRF classes for stations and airports.
NWidgetBase ** nested_array
Array of pointers into the tree. Do not access directly, use Window::GetWidget() instead.
int line_height
The height of a single line.
int info_height
The height of the info box.
Offset at bottom of a matrix cell.
This window is used for construction; close it whenever changing company.
Ground palette sprite of a tile, together with its sprite layout.
void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8 view)
Draw representation of an object (tile) for GUI purposes.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition of base types and functions in a cross-platform compatible way.
void SelectOtherClass(ObjectClassID object_class_index)
Select the specified object class.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
A number of safeguards to prevent using unsafe methods.
uint16 callback_mask
Bitmask of requested/allowed callbacks.
The window used for building objects.
uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view)
Perform a callback for an object.
rectangle (stations, depots, ...)
uint8 views
The number of views.
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Offset at left of a matrix cell.
static uint8 _selected_object_view
the view of the selected object
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
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 DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
#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.
void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32 *values)
Start using the TTDP compatible string code parsing.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
static const uint8 PC_BLACK
Black palette colour.
Build object; Window numbers:
StringID name
The name for this object.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Build toolbar; Window numbers:
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
void SelectFirstAvailableObject(bool change_class)
Select the first available object.
Draw only every second pixel, used for greying-out.
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 ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
Scrollbar * vscroll
The scrollbar.
uint32 TileIndex
The index/ID of a Tile.
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.
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 NewGRFClass * Get(Tid cls_id)
Get a particular class.
Functions related to commands.
Coordinates of a point in 2D.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
uint16 local_id
id defined by the grf file for this entity
void SelectOtherObject(int object_index)
Select the specified object in _selected_object_class class.
const struct GRFFile * grffile
grf file that introduced this entity
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
#define CMD_MSG(x)
Used to combine a StringID with the command.
int32 WindowNumber
Number to differentiate different windows of the same class.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows)...
Specification of a rectangle with absolute coordinates of all edges.
Functions related to tile highlights.
Window functions not directly related to making/drawing windows.
Find a place automatically.
uint GetMatrixColumnCount()
Calculate the number of columns of the WID_BO_SELECT_MATRIX widget.
void ShowBuildObjectPicker()
Show our object picker.
Dimensions (a width and height) of a rectangle in 2D.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
static int _selected_object_index
the index of the selected object in the current class or -1
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
int height
Height of the window (number of pixels down in y direction)
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
ObjectClassID
Class IDs for objects.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
StringID name
Name of this class.
Base for the NewGRF implementation.