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;
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.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;
189 void ConstructWindow();
199 void EnsureSelectedClassIsValid();
200 void EnsureSelectedClassIsVisible();
206 void RefreshUsedTypeList();
208 void EnsureSelectedTypeIsValid();
209 void EnsureSelectedTypeIsVisible();
216 RefreshUsedTypeList();
An interval timer will fire every interval, and will continue to fire until it is deleted.
Helper for PickerCallbacks when the class system is based on NewGRFClass.
PickerItem GetPickerItem(int cls_id, int id) const override
Get data about an item.
int GetClassCount() const override
Get the number of classes.
std::set< PickerItem > UpdateSavedItems(const std::set< PickerItem > &src) override
Update link between grfid/localidx and class_index/index in saved items.
int GetTypeCount(int cls_id) const override
Get the number of types in a class.
bool HasClassChoice() const override
Are there multiple classes to chose from?
Class for PickerClassWindow to collect information and retain state.
virtual int GetSelectedClass() const =0
Get the index of the selected class.
Filtering type_last_filtering
Default filtering of PickerTypeList.
virtual PickerItem GetPickerItem(int cls_id, int id) const =0
Get data about an item.
const std::string ini_group
Ini Group for saving favourites.
virtual void SetSelectedClass(int id) const =0
Set the selected class.
virtual bool IsActive() const =0
Should picker class/type selection be enabled?
virtual StringID GetTypeName(int cls_id, int id) const =0
Get the item of a type.
virtual bool IsTypeAvailable(int cls_id, int id) const =0
Test if an item is currently buildable.
virtual void FillUsedItems(std::set< PickerItem > &items)=0
Fill a set with all items that are used by the current player.
virtual StringID GetTypeTooltip() const =0
Get the tooltip string for the type grid.
virtual bool HasClassChoice() const =0
Are there multiple classes to chose from?
Listing type_last_sorting
Default sorting of PickerTypeList.
std::set< PickerItem > used
Set of items used in the current game by the current company.
virtual StringID GetClassTooltip() const =0
Get the tooltip string for the class list.
virtual int GetTypeCount(int cls_id) const =0
Get the number of types in a class.
virtual int GetClassCount() const =0
Get the number of classes.
virtual void SetSelectedType(int id) const =0
Set the selected type.
virtual StringID GetClassName(int id) const =0
Get the name of a class.
virtual std::set< PickerItem > UpdateSavedItems(const std::set< PickerItem > &src)=0
Update link between grfid/localidx and class_index/index in saved items.
virtual void DrawType(int x, int y, int cls_id, int id) const =0
Draw preview image of an item.
Filtering class_last_filtering
Default filtering of PickerClassList.
virtual int GetSelectedType() const =0
Get the selected type.
uint8_t mode
Bitmask of PickerFilterModes.
std::set< PickerItem > saved
Set of saved favourite items.
Listing class_last_sorting
Default sorting of PickerClassList.
Base class for windows opened from a toolbar.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
bool has_class_picker
Set if this window has a class picker 'component'.
static const int PREVIEW_LEFT
Offset from left edge to draw preview.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
@ PFM_USED
Show used types.
@ PFM_ALL
Show all classes.
@ PFM_SAVED
Show saved types.
PickerTypeList types
List of types.
QueryString class_editbox
Filter editbox.
bool has_type_picker
Set if this window has a type picker 'component'.
void BuildPickerClassList()
Builds the filter list of classes.
PickerClassWindowHotkeys
Enum referring to the Hotkeys in the picker window.
@ PCWHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
void OnEditboxChanged(WidgetID wid) override
The text in an editbox has been edited.
void BuildPickerTypeList()
Builds the filter list of types.
void OnResize() override
Called after the window got resized.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
@ PFI_POSITION
Update scroll positions.
@ PFI_VALIDATE
Validate selected item.
@ PFI_CLASS
Refresh the class list.
@ PFI_TYPE
Refresh the type list.
static const int PREVIEW_WIDTH
Width of each preview button.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
QueryString type_editbox
Filter editbox.
static const int PREVIEW_BOTTOM
Offset from bottom edge to draw preview.
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
static const uint EDITBOX_MAX_SIZE
The maximum number of characters for the filter edit box.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
PickerClassList classes
List of classes.
static const int PREVIEW_HEIGHT
Height of each preview button.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
std::unique_ptr< NWidgetBase > MakePickerClassWidgets()
Create nested widgets for the class picker widgets.
std::unique_ptr< NWidgetBase > MakePickerTypeWidgets()
Create nested widgets for the type picker widgets.
Base for the GUIs that have an edit box in them.
Base types for having sorted lists in GUIs.
Searching and filtering using a stringterm.
Types related to strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Dimensions (a width and height) of a rectangle in 2D.
Data structure describing what to show in the list (filter criteria).
Data structure describing how to show the list (what sort direction and criteria).
const PickerCallbacks * callbacks
Callbacks for filter functions to access to callbacks.
Coordinates of a point in 2D.
Data stored about a string that can be modified in the GUI.
Specification of a rectangle with absolute coordinates of all edges.
High level window description.
Data structure for an opened window.
Window * parent
Parent window.
ResizeInfo resize
Resize information.
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
WindowNumber window_number
Window number within the window class.
Definition of Interval and OneShot timers.
Definition of the game-calendar-timer.
Definition of the Window system.
Functions, definitions and such used only by the GUI.
Types related to windows.
EventState
State of handling an event.