|
OpenTTD Source
14.0-beta1
|
Go to the documentation of this file.
33 #include "table/strings.h"
69 for (
auto object_class_id : this->object_classes) {
99 this->object_classes.
SetListing(this->last_sorting);
100 this->object_classes.
SetFiltering(this->last_filtering);
118 this->vscroll->
SetCount(this->object_classes.size());
146 this->object_classes.clear();
148 for (uint i = 0; i < ObjectClass::GetClassCount(); i++) {
154 this->object_classes.
Filter(this->string_filter);
155 this->object_classes.shrink_to_fit();
157 this->object_classes.
Sort();
159 this->vscroll->
SetCount(this->object_classes.size());
168 assert(!this->object_classes.empty());
187 void SetStringParameters(
WidgetID widget)
const override
200 int size = spec ==
nullptr ? 0 : spec->
size;
219 for (
auto object_class_id : this->object_classes) {
240 if (spec !=
nullptr) {
241 if (spec->
views >= 2) size->width +=
resize->width;
242 if (spec->
views >= 4) size->height +=
resize->height;
250 bool two_wide =
false;
254 for (
const auto &spec : ObjectSpec::Specs()) {
256 two_wide |= spec.
views >= 2;
280 if (spec !=
nullptr) {
283 if (spec->
views >= 2) size->width /= 2;
284 if (spec->
views >= 4) size->height /= 2;
307 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
313 for (
auto object_class_id : this->object_classes) {
316 if (!this->vscroll->
IsVisible(pos++))
continue;
329 if (spec ==
nullptr)
break;
357 int obj_index = objclass->GetIndexFromUI(this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->GetCurrentElement());
358 if (obj_index < 0)
break;
359 const ObjectSpec *spec = objclass->GetSpec(obj_index);
360 if (spec ==
nullptr)
break;
385 if (spec ==
nullptr)
break;
391 if (callback_res > 0x400) {
395 if (message != STR_NULL && message != STR_UNDEFINED) {
400 int y =
DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, message, TC_ORANGE) - r.top - 1;
402 if (y > this->info_height) {
449 void UpdateSelectSize()
470 int view_number, object_number;
471 if (sel_index == -1) {
475 view_number = sel_view;
477 object_number = objclass->GetUIFromIndex(sel_index);
482 this->UpdateSelectSize();
486 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
488 if (!gui_scope)
return;
498 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
503 if (it == this->object_classes.end())
break;
512 int num_clicked = objclass->GetIndexFromUI(this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->GetCurrentElement());
513 if (num_clicked >= 0 && objclass->GetSpec(num_clicked)->IsAvailable()) this->
SelectOtherObject(num_clicked);
526 void OnPlaceObject([[maybe_unused]]
Point pt,
TileIndex tile)
override
544 if (pt.x == -1)
return;
579 void OnEditboxChanged(
WidgetID widget)
override
584 this->object_classes.ForceRebuild();
600 const ObjectSpec *spec = objclass->GetSpec(i);
609 for (
auto object_class_id : this->object_classes) {
612 const ObjectSpec *spec = objclass->GetSpec(i);
624 for (
auto object_class_id : this->object_classes) {
648 static inline HotkeyList hotkeys{
"buildobject", {
658 &ObjectClassIDSorter,
665 static constexpr
NWidgetPart _nested_build_object_widgets[] = {
680 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
712 static WindowDesc _build_object_desc(__FILE__, __LINE__,
716 std::begin(_nested_build_object_widgets), std::end(_nested_build_object_widgets),
717 &BuildObjectWindow::hotkeys
724 if (ObjectClass::GetUIClassCount() > 0) {
725 return AllocateWindowDescFront<BuildObjectWindow>(&_build_object_desc, 0);
@ ES_HANDLED
The passed event is handled.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
static int _selected_object_index
Index of the currently selected object if existing, else -1.
static const uint8_t OBJECT_SIZE_1X1
The value of a NewGRF's size property when the object is 1x1 tiles: low nibble for X,...
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.
bool CanRestoreSelectedObject()
Tests whether the previously selected object can be selected.
@ OBJECT_CLASS_BEGIN
The lowest valid value.
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.
List of hotkeys for a window.
void SetFocusedWindow(Window *w)
Set the window that has the focus.
BuildObjectHotkeys
Enum referring to the Hotkeys in the build object window.
Dimensions (a width and height) of a rectangle in 2D.
Allow incrementing of ObjectClassID variables.
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
uint16_t GetObjectCallback(CallbackID callback, uint32_t param1, uint32_t param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8_t view)
Perform a callback for an object.
@ 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.
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
void SetFilterTerm(const char *str)
Set the term to filter on.
uint GetSpecCount() const
Get the number of allocated specs within the class.
static EventState BuildObjectGlobalHotkeys(int hotkey)
Handler for global hotkeys of the BuildObjectWindow.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
void OnInit() override
Notification that the nested widget tree gets initialized.
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
The window used for building objects.
bool IsAvailable() const
Check whether the object is available at this time.
void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32_t *values)
Start using the TTDP compatible string code parsing.
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.
uint8_t height
The height of this structure, in heightlevels; max MAX_TILE_HEIGHT.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
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)
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
static GUIObjectClassList::FilterFunction *const filter_funcs[]
Filter functions of the GUIObjectClassList.
bool NeedRebuild() const
Check if a rebuild is needed.
Data stored about a string that can be modified in the GUI.
void OnResize() override
Called after the window got resized.
char *const buf
buffer in which text is saved
uint16_t callback_mask
Bitmask of requested/allowed callbacks.
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.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
@ CBM_OBJ_FUND_MORE_TEXT
additional text in fund window
uint8_t size
The size of this objects; low nibble for X, high nibble for Y.
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.
@ WDP_AUTO
Find a place automatically.
Data structure describing how to show the list (what sort direction and criteria).
ResizeInfo resize
Resize information.
int32_t WindowNumber
Number to differentiate different windows of the same class.
@ FS_NORMAL
Index of the normal font in the font tables.
ObjectClassID
Class IDs for objects.
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
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
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
std::conditional_t< std::is_same_v< P, std::nullptr_t >, bool(const T &, const T &), bool(const T &, const T &, const P)> SortFunction
Signature of sort function.
QueryString filter_editbox
Filter editbox.
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.
@ BOHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
GUIList< ObjectClassID, std::nullptr_t, StringFilter & > GUIObjectClassList
Type definition for the list to hold available object classes.
@ 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.
Struct containing information relating to NewGRF classes for stations and airports.
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
GameSettings _settings_game
Game settings of a running game or the scenario editor.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Data structure describing what to show in the list (filter criteria).
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
static ObjectClassID _selected_object_class
Currently selected available object class.
bool freeform_edges
allow terraforming the tiles at the map edges
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.
StringID GetGRFStringID(uint32_t grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
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)
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.
uint16_t local_id
id defined by the grf file for this entity
StringID name
The name for this object.
void ForceRebuild()
Force that a rebuild is needed.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Window * ShowBuildObjectPicker()
Show our object picker.
uint Index() const
Gets the index of this spec.
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
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.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
GUIObjectClassList object_classes
Available object classes.
void ResetState()
Reset the matching state to process a new item.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
EventState
State of handling an event.
@ HT_RECT
rectangle (stations, depots, ...)
@ VPM_X_AND_Y
area of land in X and Y directions
void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
Draw TTD sprite sequence in GUI.
bool GetState() const
Get the matching state of the current item.
StringID name
Name of this class.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
static const uint8_t PC_BLACK
Black palette colour.
int object_margin
The margin (in pixels) around an object.
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
void SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
void SelectFirstAvailableObject(bool change_class)
Select the first available object.
@ SA_CENTER
Center both horizontally and vertically.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
#define lengthof(x)
Return the length of an fixed size array.
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
void RebuildDone()
Notify the sortlist that the rebuild is done.
@ WC_BUILD_OBJECT
Build object; Window numbers:
bool CDECL FilterFunction(const ObjectClassID *, StringFilter &)
Signature of filter function.
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
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...
static uint8_t _selected_object_view
the view of the selected object
StringFilter string_filter
Filter for available objects.
static const uint EDITBOX_MAX_SIZE
The maximum number of characters for the filter edit box.
ConstructionSettings construction
construction of things in-game
void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8_t view)
Draw representation of an object (tile) for GUI purposes.
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.
const struct GRFFile * grffile
grf file that introduced this entity
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
static Listing last_sorting
Default sorting of GUIObjectClassList.
int Width() const
Get width of Rect.
Specification of a rectangle with absolute coordinates of all edges.
bool Sort(Comp compare)
Sort the list.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void SetFiltering(Filtering f)
Import filter conditions.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Data about how and where to blit pixels.
void SetListing(Listing l)
Import sort conditions.
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.
uint8_t views
The number of views.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.