OpenTTD Source
20240915-master-g3784a3d3d6
|
Go to the documentation of this file.
29 inline auto operator<=>(
const PickerItem &other)
const
31 if (
auto cmp = this->grfid <=> other.grfid; cmp != 0)
return cmp;
32 return this->local_id <=> other.local_id;
42 virtual void Close(
int) { }
78 virtual void DrawType(
int x,
int y,
int cls_id,
int id)
const = 0;
83 virtual std::set<PickerItem>
UpdateSavedItems(
const std::set<PickerItem> &src) = 0;
104 inline typename T::index_type GetClassIndex(
int cls_id)
const {
return static_cast<typename T::index_type
>(cls_id); }
105 inline const T *GetClass(
int cls_id)
const {
return T::Get(this->GetClassIndex(cls_id)); }
106 inline const typename T::spec_type *GetSpec(
int cls_id,
int id)
const {
return this->GetClass(cls_id)->GetSpec(
id); }
111 int GetTypeCount(
int cls_id)
const override {
return this->GetClass(cls_id)->GetSpecCount(); }
113 PickerItem GetPickerItem(
const typename T::spec_type *spec,
int cls_id = -1,
int id = -1)
const
115 if (spec ==
nullptr)
return {0, 0, cls_id,
id};
116 return {spec->grf_prop.grffile ==
nullptr ? 0 : spec->grf_prop.grffile->grfid, spec->grf_prop.local_id, spec->class_index, spec->index};
121 return GetPickerItem(GetClass(cls_id)->GetSpec(
id), cls_id,
id);
126 if (src.empty())
return {};
128 std::set<PickerItem> dst;
129 for (
const auto &item : src) {
130 const auto *spec = T::GetByGrf(item.grfid, item.local_id);
131 if (spec ==
nullptr) {
132 dst.insert({item.grfid, item.local_id, -1, -1});
134 dst.insert(GetPickerItem(spec));
174 void Close(
int data = 0)
override;
176 void DrawWidget(
const Rect &r,
WidgetID widget)
const override;
178 void OnClick(
Point pt,
WidgetID widget,
int click_count)
override;
179 void OnInvalidateData(
int data = 0,
bool gui_scope =
true)
override;
181 void OnEditboxChanged(
WidgetID wid)
override;
189 void ConstructWindow();
199 void EnsureSelectedClassIsValid();
200 void EnsureSelectedClassIsVisible();
206 void RefreshUsedTypeList();
208 void EnsureSelectedTypeIsValid();
209 void EnsureSelectedTypeIsVisible();
216 RefreshUsedTypeList();
bool HasClassChoice() const override
Are there multiple classes to chose from?
bool has_type_picker
Set if this window has a type picker 'component'.
virtual StringID GetClassName(int id) const =0
Get the name of a class.
Filtering type_last_filtering
Default filtering of PickerTypeList.
static const int PREVIEW_HEIGHT
Height of each preview button.
static const int PREVIEW_WIDTH
Width of each preview button.
@ PFM_ALL
Show all classes.
const PickerCallbacks * callbacks
Callbacks for filter functions to access to callbacks.
@ PFM_USED
Show used types.
Class for PickerClassWindow to collect information and retain state.
Dimensions (a width and height) of a rectangle in 2D.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ PFI_POSITION
Update scroll positions.
virtual int GetTypeCount(int cls_id) const =0
Get the number of types in a class.
virtual void FillUsedItems(std::set< PickerItem > &items)=0
Fill a set with all items that are used by the current player.
Listing type_last_sorting
Default sorting of PickerTypeList.
@ PCWHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
virtual int GetSelectedClass() const =0
Get the index of the selected class.
virtual void SetSelectedType(int id) const =0
Set the selected type.
virtual StringID GetClassTooltip() const =0
Get the tooltip string for the class list.
Data stored about a string that can be modified in the GUI.
virtual int GetSelectedType() const =0
Get the selected type.
virtual void DrawType(int x, int y, int cls_id, int id) const =0
Draw preview image of an item.
virtual bool HasClassChoice() const =0
Are there multiple classes to chose from?
High level window description.
PickerItem GetPickerItem(int cls_id, int id) const override
Get data about an item.
uint8_t mode
Bitmask of PickerFilterModes.
Filtering class_last_filtering
Default filtering of PickerClassList.
Data structure describing how to show the list (what sort direction and criteria).
PickerClassList classes
List of classes.
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
ResizeInfo resize
Resize information.
std::unique_ptr< NWidgetBase > MakePickerTypeWidgets()
Create nested widgets for the type picker widgets.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
PickerClassWindowHotkeys
Enum referring to the Hotkeys in the picker window.
void BuildPickerClassList()
Builds the filter list of classes.
void OnResize() override
Called after the window got resized.
@ PFI_VALIDATE
Validate selected item.
void BuildPickerTypeList()
Builds the filter list of types.
virtual int GetClassCount() const =0
Get the number of classes.
static const int PREVIEW_LEFT
Offset from left edge to draw preview.
Data structure describing what to show in the list (filter criteria).
Window * parent
Parent window.
virtual bool IsTypeAvailable(int cls_id, int id) const =0
Test if an item is currently buildable.
virtual StringID GetTypeName(int cls_id, int id) const =0
Get the item of a type.
Listing class_last_sorting
Default sorting of PickerClassList.
@ PFI_CLASS
Refresh the class list.
int GetClassCount() const override
Get the number of classes.
QueryString class_editbox
Filter editbox.
Coordinates of a point in 2D.
virtual bool IsActive() const =0
Should picker class/type selection be enabled?
WindowNumber window_number
Window number within the window class.
virtual PickerItem GetPickerItem(int cls_id, int id) const =0
Get data about an item.
std::set< PickerItem > saved
Set of saved favourite items.
Helper for PickerCallbacks when the class system is based on NewGRFClass.
std::set< PickerItem > UpdateSavedItems(const std::set< PickerItem > &src) override
Update link between grfid/localidx and class_index/index in saved items.
std::unique_ptr< NWidgetBase > MakePickerClassWidgets()
Create nested widgets for the class picker widgets.
virtual void SetSelectedClass(int id) const =0
Set the selected class.
EventState
State of handling an event.
Base class for windows opened from a toolbar.
static const uint EDITBOX_MAX_SIZE
The maximum number of characters for the filter edit box.
virtual std::set< PickerItem > UpdateSavedItems(const std::set< PickerItem > &src)=0
Update link between grfid/localidx and class_index/index in saved items.
const std::string ini_group
Ini Group for saving favourites.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
static const int PREVIEW_BOTTOM
Offset from bottom edge to draw preview.
Data structure for an opened window.
bool has_class_picker
Set if this window has a class picker 'component'.
std::set< PickerItem > used
Set of items used in the current game by the current company.
QueryString type_editbox
Filter editbox.
Specification of a rectangle with absolute coordinates of all edges.
int GetTypeCount(int cls_id) const override
Get the number of types in a class.
@ PFM_SAVED
Show saved types.
virtual StringID GetTypeTooltip() const =0
Get the tooltip string for the type grid.
@ PFI_TYPE
Refresh the type list.
PickerTypeList types
List of types.