31 inline auto operator<=>(
const PickerItem &other)
const
33 if (
auto cmp = this->grfid <=> other.grfid; cmp != 0)
return cmp;
34 return this->local_id <=> other.local_id;
44 virtual void Close(
int) { }
78 virtual std::span<const BadgeID>
GetTypeBadges(
int cls_id,
int id)
const = 0;
82 virtual void DrawType(
int x,
int y,
int cls_id,
int id)
const = 0;
91 virtual std::map<std::string, std::set<PickerItem>>
UpdateSavedItems(
const std::map<std::string, std::set<PickerItem>> &src) = 0;
99 std::set<std::string> inactive;
101 for (
const auto &collection : collections) {
102 if ((collection.second.size() == 1 && collection.second.contains({})) || collection.first ==
"")
continue;
103 for (
const PickerItem &item : collection.second) {
104 if (item.class_index == -1 || item.index == -1) {
105 inactive.emplace(collection.first);
109 inactive.emplace(collection.first);
135 std::map<std::string, std::set<PickerItem>>
saved;
144 inline typename T::index_type GetClassIndex(
int cls_id)
const {
return static_cast<typename T::index_type
>(cls_id); }
145 inline const T *GetClass(
int cls_id)
const {
return T::Get(this->GetClassIndex(cls_id)); }
146 inline const typename T::spec_type *GetSpec(
int cls_id,
int id)
const {
return this->GetClass(cls_id)->GetSpec(
id); }
151 int GetTypeCount(
int cls_id)
const override {
return this->GetClass(cls_id)->GetSpecCount(); }
153 PickerItem GetPickerItem(
const typename T::spec_type *spec,
int cls_id = -1,
int id = -1)
const
155 if (spec ==
nullptr)
return {0, 0, cls_id,
id};
156 return {spec->grf_prop.grfid, spec->grf_prop.local_id, spec->class_index, spec->index};
161 return GetPickerItem(GetClass(cls_id)->GetSpec(
id), cls_id,
id);
164 std::map<std::string, std::set<PickerItem>>
UpdateSavedItems(
const std::map<std::string, std::set<PickerItem>> &src)
override
166 if (src.empty())
return {};
168 std::map<std::string, std::set<PickerItem>> dst;
169 for (
auto it = src.begin(); it != src.end(); it++) {
170 if (it->second.empty() || (it->second.size() == 1 && it->second.contains({}))) {
175 for (
const auto &item : it->second) {
176 const auto *spec = T::GetByGrf(item.grfid, item.local_id);
177 if (spec ==
nullptr) {
178 dst[it->first].emplace(item.grfid, item.local_id, -1, -1);
180 dst[it->first].emplace(GetPickerItem(spec));
190 std::optional<BadgeTextFilter> btf;
191 std::optional<BadgeDropdownFilter> bdf;
237 void Close(
int data = 0)
override;
244 void static DeletePickerCollectionCallback(
Window *win,
bool confirmed);
259 void ConstructWindow();
269 void EnsureSelectedClassIsValid();
270 void EnsureSelectedClassIsVisible();
276 void RefreshUsedTypeList();
278 void EnsureSelectedTypeIsValid();
279 void EnsureSelectedTypeIsVisible();
286 std::pair<WidgetID, WidgetID> badge_filters{};
287 BadgeFilterChoices badge_filter_choices{};
294 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.
std::map< std::string, std::set< PickerItem > > UpdateSavedItems(const std::map< std::string, std::set< PickerItem > > &src) override
Update link between grfid/localidx and class_index/index in saved items.
PickerItem GetPickerItem(int cls_id, int id) const override
Get data about an item.
int GetClassCount() const override
Get the number of classes.
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.
std::set< std::string > InitializeInactiveCollections(const std::map< std::string, std::set< PickerItem > > collections)
Initialize the list of active collections for sorting purposes.
virtual int GetSelectedClass() const =0
Get the index of the selected class.
std::string edit_collection
Collection to rename or delete.
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.
bool rename_collection
Are we renaming a collection?
Listing collection_last_sorting
Default sorting of PickerCollectionList.
virtual void SetSelectedClass(int id) const =0
Set the selected class.
std::string sel_collection
Currently selected collection of saved items.
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.
virtual StringID GetCollectionTooltip() const =0
Get the tooltip string for the collection list.
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.
int preview_height
Previously adjusted height.
virtual void DrawType(int x, int y, int cls_id, int id) const =0
Draw preview image of an item.
virtual std::span< const BadgeID > GetTypeBadges(int cls_id, int id) const =0
Get the item of a type.
virtual std::map< std::string, std::set< PickerItem > > UpdateSavedItems(const std::map< std::string, std::set< PickerItem > > &src)=0
Update link between grfid/localidx and class_index/index in saved items.
Filtering class_last_filtering
Default filtering of PickerClassList.
std::set< std::string > rm_collections
Set of removed or renamed collections for updating ini file.
std::map< std::string, std::set< PickerItem > > saved
Set of saved collections of items.
virtual int GetSelectedType() const =0
Get the selected type.
uint8_t mode
Bitmask of PickerFilterModes.
Listing class_last_sorting
Default sorting of PickerClassList.
Base class for windows opened from a toolbar.
static constexpr int MAX_PREVIEW_HEIGHT
Maximum height of each preview button.
static constexpr int PREVIEW_WIDTH
Width of each preview button.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
int preview_height
Height of preview images.
bool has_class_picker
Set if this window has a class picker 'component'.
static constexpr int PREVIEW_HEIGHT
Height of each preview button.
static constexpr uint EDITBOX_MAX_SIZE
The maximum number of characters for the filter edit box.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
PickerInvalidation
The things of a picker that can be invalidated.
@ Position
Update scroll positions.
@ Class
Refresh the class list.
@ Type
Refresh the type list.
@ Validate
Validate selected item.
@ Collection
Refresh the collection list.
@ Filter
Update filter state.
bool has_collection_picker
Set if this window has a collection picker 'component'.
static constexpr int PREVIEW_LEFT
Offset from left edge to draw preview.
PickerTypeList types
List of types.
std::set< std::string > inactive
Set of collections with inactive items.
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.
@ PFM_USED
Show used types.
@ PFM_ALL
Show all classes.
@ PFM_SAVED
Show saved types.
void BuildPickerCollectionList()
Builds the filter list of collections.
void OnEditboxChanged(WidgetID wid) override
The text in an editbox has been edited.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
void BuildPickerTypeList()
Builds the filter list of types.
void OnDropdownSelect(WidgetID widget, int index, int click_result) override
A dropdown option associated to this window has been selected.
void OnResize() override
Called after the window got resized.
static constexpr int PREVIEW_BOTTOM
Offset from bottom edge to draw preview.
PickerClassWindowHotkeys
Enum referring to the Hotkeys in the picker window.
@ PCWHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
PickerCollectionList collections
List of collections.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
QueryString type_editbox
Filter editbox.
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
void OnInit() override
Notification that the nested widget tree gets initialized.
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 constexpr int STEP_PREVIEW_HEIGHT
Step for decreasing or increase preview button height.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Functions related to NewGRF badges.
GUI functions related to NewGRF badges.
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.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
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.
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.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Window * parent
Parent window.
ResizeInfo resize
Resize information.
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.