Go to the documentation of this file.
30 #include "table/strings.h"
66 for (
auto object_class_id : this->object_classes) {
106 this->object_classes.
SetListing(this->last_sorting);
107 this->object_classes.
SetFiltering(this->last_filtering);
125 this->vscroll->
SetCount((
int)this->object_classes.size());
143 GetString(buffer, objclass->
name,
lastof(buffer));
155 this->object_classes.clear();
157 for (uint i = 0; i < ObjectClass::GetClassCount(); i++) {
163 this->object_classes.
Filter(this->string_filter);
164 this->object_classes.shrink_to_fit();
166 this->object_classes.
Sort();
168 this->vscroll->
SetCount((uint)this->object_classes.size());
177 assert(!this->object_classes.empty());
184 bool available =
false;
185 for (uint i = 0; ObjectClass::GetClassCount(); ++i) {
220 int size = spec ==
nullptr ? 0 : spec->
size;
234 for (
auto object_class_id : this->object_classes) {
239 size->width += padding.width;
256 if (spec !=
nullptr) {
257 if (spec->
views >= 2) size->width +=
resize->width;
258 if (spec->
views >= 4) size->height +=
resize->height;
266 bool two_wide =
false;
273 two_wide |= spec->
views >= 2;
297 if (spec !=
nullptr) {
298 if (spec->
views >= 2) size->width = size->width / 2 - 1;
299 if (spec->
views >= 4) size->height = size->height / 2 - 1;
324 switch (
GB(widget, 0, 16)) {
328 for (
auto object_class_id : this->object_classes) {
331 if (!this->vscroll->
IsVisible(pos++))
continue;
344 if (spec ==
nullptr)
break;
355 if (
FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left + 1, r.bottom - r.top + 1)) {
372 int obj_index = objclass->GetIndexFromUI(
GB(widget, 16, 16));
373 if (obj_index < 0)
break;
374 const ObjectSpec *spec = objclass->GetSpec(obj_index);
375 if (spec ==
nullptr)
break;
382 if (
FillDrawPixelInfo(&tmp_dpi, r.left + 1, r.top, (r.right - 1) - (r.left + 1) + 1, r.bottom - r.top + 1)) {
401 if (spec ==
nullptr)
break;
407 if (callback_res > 0x400) {
411 if (message != STR_NULL && message != STR_UNDEFINED) {
416 int y =
DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, message, TC_ORANGE) - r.top;
418 if (y > this->info_height) {
465 void UpdateSelectSize()
486 int view_number, object_number;
487 if (sel_index == -1) {
491 view_number = sel_view;
493 object_number = objclass->GetUIFromIndex(sel_index);
498 this->UpdateSelectSize();
504 if (!gui_scope)
return;
516 switch (
GB(widget, 0, 16)) {
519 if (num_clicked >= (
int)this->object_classes.size())
break;
528 int num_clicked = objclass->GetIndexFromUI(
GB(widget, 16, 16));
529 if (num_clicked >= 0 && objclass->GetSpec(num_clicked)->IsAvailable()) this->
SelectOtherObject(num_clicked);
588 const ObjectSpec *spec = objclass->GetSpec(i);
597 for (
auto object_class_id : this->object_classes) {
600 const ObjectSpec *spec = objclass->GetSpec(i);
612 for (
auto object_class_id : this->object_classes) {
639 static Hotkey buildobject_hotkeys[] = {
649 &ObjectClassIDSorter,
656 static const NWidgetPart _nested_build_object_widgets[] = {
668 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
694 NWidget(
WWT_EMPTY, INVALID_COLOUR,
WID_BO_INFO),
SetPadding(0, 5, 0, 1),
SetFill(1, 0),
SetResize(1, 0),
707 _nested_build_object_widgets,
lengthof(_nested_build_object_widgets),
708 &BuildObjectWindow::hotkeys
715 if (ObjectClass::GetUIClassCount() > 0) {
716 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.
#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.
static Filtering last_filtering
Default filtering of GUIObjectClassList.
uint GetUISpecCount() const
Get the number of potentially user-available specs within the class.
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.
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.
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.
@ 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.
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.
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
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.
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.
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.
static EventState BuildObjectGlobalHotkeys(int hotkey)
Handler for global hotkeys of the BuildObjectWindow.
@ BOHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
@ ES_NOT_HANDLED
The passed event is not handled.
Struct containing information relating to NewGRF classes for stations and airports.
Data structure describing what to show in the list (filter criteria).
static ObjectClassID _selected_object_class
Currently selected available 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.
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.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
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.
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.
Scrollbar * vscroll
The scrollbar.
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
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.
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.
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, ...)
@ CMD_BUILD_OBJECT
build an object
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.
void SelectFirstAvailableObject(bool change_class)
Select the first available object.
@ WD_MATRIX_BOTTOM
Offset at bottom of a matrix cell.
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.
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...
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.
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.
@ WD_MATRIX_LEFT
Offset at left of a matrix cell.
const struct GRFFile * grffile
grf file that introduced this entity
static Listing last_sorting
Default sorting of GUIObjectClassList.
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.