Go to the documentation of this file.
33 #include "table/strings.h"
69 for (
auto object_class_id : this->object_classes) {
109 this->object_classes.
SetListing(this->last_sorting);
110 this->object_classes.
SetFiltering(this->last_filtering);
128 this->vscroll->
SetCount((
int)this->object_classes.size());
146 GetString(buffer, objclass->
name,
lastof(buffer));
158 this->object_classes.clear();
160 for (uint i = 0; i < ObjectClass::GetClassCount(); i++) {
166 this->object_classes.
Filter(this->string_filter);
167 this->object_classes.shrink_to_fit();
169 this->object_classes.
Sort();
171 this->vscroll->
SetCount((uint)this->object_classes.size());
180 assert(!this->object_classes.empty());
187 bool available =
false;
188 for (uint i = 0; ObjectClass::GetClassCount(); ++i) {
223 int size = spec ==
nullptr ? 0 : spec->
size;
242 for (
auto object_class_id : this->object_classes) {
247 size->width += padding.width;
264 if (spec !=
nullptr) {
265 if (spec->
views >= 2) size->width +=
resize->width;
266 if (spec->
views >= 4) size->height +=
resize->height;
274 bool two_wide =
false;
281 two_wide |= spec->
views >= 2;
305 if (spec !=
nullptr) {
308 if (spec->
views >= 2) size->width /= 2;
309 if (spec->
views >= 4) size->height /= 2;
334 switch (
GB(widget, 0, 16)) {
338 for (
auto object_class_id : this->object_classes) {
341 if (!this->vscroll->
IsVisible(pos++))
continue;
354 if (spec ==
nullptr)
break;
382 int obj_index = objclass->GetIndexFromUI(
GB(widget, 16, 16));
383 if (obj_index < 0)
break;
384 const ObjectSpec *spec = objclass->GetSpec(obj_index);
385 if (spec ==
nullptr)
break;
411 if (spec ==
nullptr)
break;
417 if (callback_res > 0x400) {
421 if (message != STR_NULL && message != STR_UNDEFINED) {
426 int y =
DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, message, TC_ORANGE) - r.top - 1;
428 if (y > this->info_height) {
475 void UpdateSelectSize()
496 int view_number, object_number;
497 if (sel_index == -1) {
501 view_number = sel_view;
503 object_number = objclass->GetUIFromIndex(sel_index);
508 this->UpdateSelectSize();
514 if (!gui_scope)
return;
526 switch (
GB(widget, 0, 16)) {
528 int num_clicked = this->vscroll->
GetPosition() + (pt.y - this->GetWidget<NWidgetBase>(widget)->pos_y) / this->line_height;
529 if (num_clicked >= (
int)this->object_classes.size())
break;
538 int num_clicked = objclass->GetIndexFromUI(
GB(widget, 16, 16));
539 if (num_clicked >= 0 && objclass->GetSpec(num_clicked)->IsAvailable()) this->
SelectOtherObject(num_clicked);
570 if (pt.x == -1)
return;
572 switch (select_proc) {
573 default: NOT_REACHED();
627 const ObjectSpec *spec = objclass->GetSpec(i);
636 for (
auto object_class_id : this->object_classes) {
639 const ObjectSpec *spec = objclass->GetSpec(i);
651 for (
auto object_class_id : this->object_classes) {
678 static Hotkey buildobject_hotkeys[] = {
688 &ObjectClassIDSorter,
695 static const NWidgetPart _nested_build_object_widgets[] = {
709 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
735 NWidget(
WWT_EMPTY, INVALID_COLOUR,
WID_BO_INFO),
SetPadding(0, 5, 2, 2),
SetFill(1, 0),
SetResize(1, 0),
748 _nested_build_object_widgets,
lengthof(_nested_build_object_widgets),
749 &BuildObjectWindow::hotkeys
756 if (ObjectClass::GetUIClassCount() > 0) {
757 return AllocateWindowDescFront<BuildObjectWindow>(&_build_object_desc, 0);
@ ES_HANDLED
The passed event is handled.
@ OBJECT_CLASS_BEGIN
The lowest valid value.
static int _selected_object_index
Index of the currently selected object if existing, else -1.
static bool ObjectClassIDSorter(ObjectClassID const &a, ObjectClassID const &b)
Sort object classes by ObjectClassID.
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
bool CanRestoreSelectedObject()
Tests whether the previously selected object can be selected.
int Height() const
Get height of Rect.
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
void EnsureSelectedObjectClassIsVisible()
Scroll WID_BO_CLASS_LIST so that the selected object class is visible.
static Filtering last_filtering
Default filtering of GUIObjectClassList.
uint GetUISpecCount() const
Get the number of potentially user-available specs within the class.
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.
List of hotkeys for a window.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
void SetFocusedWindow(Window *w)
Set the window that has the focus.
BuildObjectHotkeys
Enum referring to the Hotkeys in the build object window.
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.
bool Sort(Comp compare)
Sort the list.
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.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
bool IsEmpty() const
Check whether any filter words were entered.
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
void SetFilterTerm(const char *str)
Set the term to filter on.
uint GetSpecCount() const
Get the number of allocated specs within the class.
void OnInit() override
Notification that the nested widget tree gets initialized.
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.
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
bool _ctrl_pressed
Is Ctrl pressed?
@ 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.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
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.
void SelectOtherClass(ObjectClassID object_class)
Select the specified object class.
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
static const ObjectSpec * Get(ObjectType index)
Get the specification associated with a specific ObjectType.
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
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.
static GUIObjectClassList::FilterFunction *const filter_funcs[]
Filter functions of the GUIObjectClassList.
Data stored about a string that can be modified in the GUI.
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 SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
char *const buf
buffer in which text is saved
static uint TileX(TileIndex tile)
Get the X component of a tile.
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
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.
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
void SelectClassAndObject()
Checks if the previously selected current object class and object can be shown as selected to the use...
High level window description.
@ CBM_OBJ_FUND_MORE_TEXT
additional text in fund window
void UpdateButtons(ObjectClassID object_class, int sel_index, uint sel_view)
Update buttons to show the selection to the user.
static bool CDECL TagNameFilter(ObjectClassID const *oc, StringFilter &filter)
Filter object classes by class name.
static uint8 _selected_object_view
the view of the selected object
@ WDP_AUTO
Find a place automatically.
Data structure describing how to show the list (what sort direction and criteria).
void SetFilterState(bool state)
Enable or disable the filter.
static const int DRAW_STRING_BUFFER
Size of the buffer used for drawing strings.
ResizeInfo resize
Resize information.
int height
Height of the window (number of pixels down in y direction)
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
highlighting tiles while only going over them with the mouse
ObjectClassID
Class IDs for objects.
bool SortFunction(const ObjectClassID &, const ObjectClassID &)
Signature of sort function.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
QueryString filter_editbox
Filter editbox.
void SetListing(Listing l)
Import sort conditions.
int info_height
The height of the info box.
@ HT_DIAGONAL
Also allow 'diagonal rectangles'. Only usable in combination with HT_RECT or HT_POINT.
static EventState BuildObjectGlobalHotkeys(int hotkey)
Handler for global hotkeys of the BuildObjectWindow.
uint Horizontal() const
Get total horizontal padding of RectPadding.
@ BOHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
@ DDSP_BUILD_OBJECT
Build an object.
@ ES_NOT_HANDLED
The passed event is not handled.
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
static int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Struct containing information relating to NewGRF classes for stations and airports.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Data structure describing what to show in the list (filter criteria).
static ObjectClassID _selected_object_class
Currently selected available object class.
bool freeform_edges
allow terraforming the tiles at the map edges
StringID GetGRFStringID(uint32 grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
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.
GUIList< ObjectClassID, StringFilter & > GUIObjectClassList
Type definition for the list to hold available object classes.
bool SetFocusedWidget(int widget_index)
Set focus within this window to the given widget.
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.
uint Vertical() const
Get total vertical padding of RectPadding.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
void BuildObjectClassesAvailable()
Builds the filter list of available object classes.
StringID name
The name for this object.
bool NeedRebuild() const
Check if a rebuild is needed.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Window * ShowBuildObjectPicker()
Show our object picker.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
uint Index() const
Gets the index of this spec.
Scrollbar * vscroll
The scrollbar.
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
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.
bool CDECL FilterFunction(const ObjectClassID *, StringFilter &)
Signature of filter function.
GUIObjectClassList object_classes
Available object classes.
void ResetState()
Reset the matching state to process a new item.
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
EventState
State of handling an event.
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, ...)
@ VPM_X_AND_Y
area of land in X and Y directions
void SetFiltering(Filtering f)
Import filter conditions.
bool GetState() const
Get the matching state of the current item.
StringID name
Name of this class.
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
int object_margin
The margin (in pixels) around an object.
void SelectFirstAvailableObject(bool change_class)
Select the first available object.
void ForceRebuild()
Force that a rebuild is needed.
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.
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 OnEditboxChanged(int wid) override
The text in an editbox has been edited.
StringFilter string_filter
Filter for available objects.
uint16 local_id
id defined by the grf file for this entity
static const uint EDITBOX_MAX_SIZE
The maximum number of characters for the filter edit box.
ConstructionSettings construction
construction of things in-game
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.
void RebuildDone()
Notify the sortlist that the rebuild is done.
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.
const struct GRFFile * grffile
grf file that introduced this entity
static Listing last_sorting
Default sorting of GUIObjectClassList.
static const uint8 OBJECT_SIZE_1X1
The value of a NewGRF's size property when the object is 1x1 tiles: low nibble for X,...
int Width() const
Get width of Rect.
Specification of a rectangle with absolute coordinates of all edges.
#define lastof(x)
Get the last element of an fixed size array.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
Data about how and where to blit pixels.
All data for a single hotkey.
static GUIObjectClassList::SortFunction *const sorter_funcs[]
Sort functions of the GUIObjectClassList.
@ CBID_OBJECT_FUND_MORE_TEXT
Called to determine more text in the fund object 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.