26 #include "table/strings.h" 86 this->vscroll->
SetCount(ObjectClass::GetUIClassCount());
113 int size = spec == NULL ? 0 : spec->
size;
127 for (uint i = 0; i < ObjectClass::GetClassCount(); i++) {
132 size->width += padding.width;
149 if (spec->
views >= 2) size->width += resize->width;
150 if (spec->
views >= 4) size->height += resize->height;
158 bool two_wide =
false;
165 two_wide |= spec->
views >= 2;
170 for (
size_t i = 0; i <
lengthof(height); i++) {
179 size->height =
max(height[0], height[1] * 2 + 2);
189 if (spec->
views >= 2) size->width = size->width / 2 - 1;
190 if (spec->
views >= 4) size->height = size->height / 2 - 1;
215 switch (
GB(widget, 0, 16)) {
219 for (uint i = 0; i < ObjectClass::GetClassCount(); i++) {
222 if (!this->vscroll->
IsVisible(pos++))
continue;
232 if (spec == NULL)
break;
243 if (
FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left + 1, r.bottom - r.top + 1)) {
260 int obj_index = objclass->GetIndexFromUI(
GB(widget, 16, 16));
261 if (obj_index < 0)
break;
262 const ObjectSpec *spec = objclass->GetSpec(obj_index);
263 if (spec == NULL)
break;
270 if (
FillDrawPixelInfo(&tmp_dpi, r.left + 1, r.top, (r.right - 1) - (r.left + 1) + 1, r.bottom - r.top + 1)) {
288 if (spec == NULL)
break;
294 if (callback_res > 0x400) {
298 if (message != STR_NULL && message != STR_UNDEFINED) {
303 int y =
DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, message, TC_ORANGE) - r.top;
305 if (y > this->info_height) {
350 void UpdateSelectSize()
370 int view_number, object_number;
371 if (sel_index == -1) {
375 view_number = sel_view;
381 this->UpdateSelectSize();
392 switch (
GB(widget, 0, 16)) {
395 if (num_clicked >= (
int)ObjectClass::GetUIClassCount())
break;
404 int num_clicked = objclass->GetIndexFromUI(
GB(widget, 16, 16));
405 if (num_clicked >= 0 && objclass->GetSpec(num_clicked)->IsAvailable()) this->
SelectOtherObject(num_clicked);
438 for (uint i = 0; i < sel_objclass->
GetSpecCount(); i++) {
439 const ObjectSpec *spec = sel_objclass->GetSpec(i);
451 const ObjectSpec *spec = objclass->GetSpec(i);
474 static const NWidgetPart _nested_build_object_widgets[] = {
507 NWidget(
WWT_EMPTY, INVALID_COLOUR,
WID_BO_INFO),
SetPadding(2, 5, 0, 5),
SetFill(1, 0),
SetResize(1, 0),
520 _nested_build_object_widgets,
lengthof(_nested_build_object_widgets)
530 if (ObjectClass::GetUIClassCount() > 0) {
531 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.
virtual void OnPlaceObject(Point pt, TileIndex tile)
The user clicked some place on the map when a tile highlight mode has been set.
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.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
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.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
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.
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.
virtual void OnPlaceObjectAbort()
The user cancelled a tile highlight mode that has been set.
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.
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.
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
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.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
#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.
virtual void OnResize()
Called after the window got resized.
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.
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
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
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.
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.