OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
28 #include "table/strings.h"
59 for (
auto objclass : this->object_classes) {
98 this->object_classes.
SetListing(this->last_sorting);
117 this->vscroll->
SetCount((
int)this->object_classes.size());
128 GetString(buffer_a, a->
name,
lastof(buffer_a));
131 GetString(buffer_b, b->
name,
lastof(buffer_b));
133 return strnatcmp(buffer_a, buffer_b,
true) < 0;
140 GetString(buffer, (*oc)->name,
lastof(buffer));
152 this->object_classes.clear();
154 for (uint i = 0; i < ObjectClass::GetClassCount(); i++) {
160 this->object_classes.
Filter(this->string_filter);
161 this->object_classes.shrink_to_fit();
163 this->object_classes.
Sort();
165 this->vscroll->
SetCount((uint)this->object_classes.size());
174 assert(!this->object_classes.empty());
181 bool available =
false;
182 for (uint i = 0; ObjectClass::GetClassCount(); ++i) {
216 int size = spec ==
nullptr ? 0 : spec->
size;
230 for (
auto objclass : this->object_classes) {
231 if (objclass->GetUISpecCount() == 0)
continue;
234 size->width += padding.width;
250 if (spec !=
nullptr) {
251 if (spec->
views >= 2) size->width +=
resize->width;
252 if (spec->
views >= 4) size->height +=
resize->height;
260 bool two_wide =
false;
267 two_wide |= spec->
views >= 2;
290 if (spec !=
nullptr) {
291 if (spec->
views >= 2) size->width = size->width / 2 - 1;
292 if (spec->
views >= 4) size->height = size->height / 2 - 1;
317 switch (
GB(widget, 0, 16)) {
321 for (
auto objclass : this->object_classes) {
322 if (objclass->GetUISpecCount() == 0)
continue;
323 if (!this->vscroll->
IsVisible(pos++))
continue;
335 if (spec ==
nullptr)
break;
346 if (
FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left + 1, r.bottom - r.top + 1)) {
363 if (obj_index < 0)
break;
365 if (spec ==
nullptr)
break;
372 if (
FillDrawPixelInfo(&tmp_dpi, r.left + 1, r.top, (r.right - 1) - (r.left + 1) + 1, r.bottom - r.top + 1)) {
390 if (spec ==
nullptr)
break;
396 if (callback_res > 0x400) {
400 if (message != STR_NULL && message != STR_UNDEFINED) {
405 int y =
DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, message, TC_ORANGE) - r.top;
407 if (y > this->info_height) {
452 void UpdateSelectSize()
472 int view_number, object_number;
473 if (sel_index == -1) {
477 view_number = sel_view;
478 object_number = object_class->GetUIFromIndex(sel_index);
483 this->UpdateSelectSize();
489 if (!gui_scope)
return;
501 switch (
GB(widget, 0, 16)) {
504 if (num_clicked >= (
int)this->object_classes.size())
break;
563 for (
auto objclass : this->object_classes) {
564 for (uint i = 0; i < objclass->GetSpecCount(); i++) {
565 const ObjectSpec *spec = objclass->GetSpec(i);
577 for (
auto objclass : this->object_classes) {
578 if (objclass->GetUISpecCount() > 0) {
599 static const NWidgetPart _nested_build_object_widgets[] = {
611 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
637 NWidget(
WWT_EMPTY, INVALID_COLOUR,
WID_BO_INFO),
SetPadding(2, 5, 0, 5),
SetFill(1, 0),
SetResize(1, 0),
650 _nested_build_object_widgets,
lengthof(_nested_build_object_widgets)
657 if (ObjectClass::GetUIClassCount() > 0) {
658 AllocateWindowDescFront<BuildObjectWindow>(&_build_object_desc, 0);
static int _selected_object_index
Index of the currently selected object if existing, else -1.
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.
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.
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.
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.
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.
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
static bool NameSorter(const ObjectClass *const &a, const ObjectClass *const &b)
Sort 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.
void UpdateButtons(const ObjectClass *object_class, int sel_index, uint sel_view)
Update buttons to show the selection to the user.
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 const ObjectClass * &, const const ObjectClass * &)
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.
Struct containing information relating to NewGRF classes for stations and airports.
Data structure describing what to show in the list (filter criteria).
static bool CDECL TagNameFilter(const ObjectClass *const *oc, StringFilter &filter)
Filter object classes by class name.
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< const ObjectClass *, 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.
static const ObjectClass * _selected_object_class
Currently selected available object class.
void SelectOtherClass(const ObjectClass *object_class)
Select the specified object class.
bool NeedRebuild() const
Check if a rebuild is needed.
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.
bool CDECL FilterFunction(const const ObjectClass * *, StringFilter &)
Signature of filter function.
GUIObjectClassList object_classes
Available object classes.
void ResetState()
Reset the matching state to process a new item.
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...
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
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.
void ShowBuildObjectPicker()
Show our object picker.
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.