|
OpenTTD Source
1.11.0-beta1
|
Go to the documentation of this file.
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;
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);
@ OBJECT_CLASS_BEGIN
The lowest valid value.
static int _selected_object_index
the index of the selected object in the current class or -1
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
#define CMD_MSG(x)
Used to combine a StringID with the command.
uint32 TileIndex
The index/ID of a Tile.
bool CanRestoreSelectedObject()
Tests whether the previously selected object can be selected.
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
void EnsureSelectedObjectClassIsVisible()
Scroll WID_BO_CLASS_LIST so that the selected object class is visible.
@ WD_MATRIX_RIGHT
Offset at right of a matrix cell.
uint GetUISpecCount() const
Get the number of potentially user-available specs within the class.
void UpdateButtons(ObjectClassID sel_class, int sel_index, uint sel_view)
Update buttons to show the selection to the user.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
static void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
Draw TTD sprite sequence in GUI.
Dimensions (a width and height) of a rectangle in 2D.
uint GetMatrixColumnCount()
Calculate the number of columns of the WID_BO_SELECT_MATRIX widget.
Allow incrementing of ObjectClassID variables.
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
@ WD_MATRIX_TOP
Offset at top of a matrix cell.
uint GetSpecCount() const
Get the number of allocated specs within the class.
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
The window used for building objects.
bool IsAvailable() const
Check whether the object is available at this time.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8 view)
Draw representation of an object (tile) for GUI purposes.
static const ObjectType NUM_OBJECTS
Number of supported objects overall.
void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32 *values)
Start using the TTDP compatible string code parsing.
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.
int32 WindowNumber
Number to differentiate different windows of the same class.
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
void InitializeObjectGui()
Reset all data of the object GUI.
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.
uint8 size
The size of this objects; low nibble for X, high nibble for Y.
uint16 callback_mask
Bitmask of requested/allowed callbacks.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
void OnResize() override
Called after the window got resized.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
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.
High level window description.
@ CBM_OBJ_FUND_MORE_TEXT
additional text in fund window
static uint8 _selected_object_view
the view of the selected object
@ WDP_AUTO
Find a place automatically.
ResizeInfo resize
Resize information.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
int height
Height of the window (number of pixels down in y direction)
ObjectClassID
Class IDs for objects.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
int info_height
The height of the info box.
Struct containing information relating to NewGRF classes for stations and airports.
static ObjectClassID _selected_object_class
the currently visible object class
StringID GetGRFStringID(uint32 grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
static const int OBJECT_MARGIN
The margin (in pixels) around an object.
void SelectOtherClass(ObjectClassID object_class_index)
Select the specified object class.
Ground palette sprite of a tile, together with its sprite layout.
int line_height
The height of a single line.
Coordinates of a point in 2D.
static const uint8 PC_BLACK
Black palette colour.
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.
NWidgetBase ** nested_array
Array of pointers into the tree. Do not access directly, use Window::GetWidget() instead.
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
StringID name
The name for this object.
@ OBJECT_CLASS_MAX
Maximum number of classes.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Scrollbar * vscroll
The scrollbar.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
uint8 views
The number of views.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view)
Perform a callback for an object.
@ HT_RECT
rectangle (stations, depots, ...)
@ CMD_BUILD_OBJECT
build an object
StringID name
Name of this class.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
void SelectFirstAvailableObject(bool change_class)
Select the first available object.
@ WD_MATRIX_BOTTOM
Offset at bottom of a matrix cell.
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.
#define lengthof(x)
Return the length of an fixed size array.
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
@ WC_BUILD_OBJECT
Build object; Window numbers:
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
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...
uint16 local_id
id defined by the grf file for this entity
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Data structure for an opened window.
static const uint TILE_PIXELS
Pixel distance between tile columns/rows in #ZOOM_LVL_BASE.
void SelectOtherObject(int object_index)
Select the specified object in _selected_object_class class.
@ WD_MATRIX_LEFT
Offset at left of a matrix cell.
const struct GRFFile * grffile
grf file that introduced this entity
Specification of a rectangle with absolute coordinates of all edges.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Data about how and where to blit pixels.
void ShowBuildObjectPicker()
Show our object picker.
@ CBID_OBJECT_FUND_MORE_TEXT
Called to determine more text in the fund object window.