OpenTTD Source 20260421-master-gc2fbc6fdeb
PickerCallbacksNewGRFClass< T > Class Template Reference

Helper for PickerCallbacks when the class system is based on NewGRFClass. More...

#include <picker_gui.h>

Inheritance diagram for PickerCallbacksNewGRFClass< T >:
PickerCallbacks

Public Member Functions

 PickerCallbacksNewGRFClass (const std::string &ini_group)
 Create the callback instance.
T::index_type GetClassIndex (int cls_id) const
 Casts the given index to the right type.
const TGetClass (int cls_id) const
 Get the class with the given index.
const T::spec_type * GetSpec (int cls_id, int id) const
 Get the spec of an object within a class.
bool HasClassChoice () const override
 Are there multiple classes to chose from?
int GetClassCount () const override
 Get the number of classes.
int GetTypeCount (int cls_id) const override
 Get the number of types in a class.
PickerItem GetPickerItem (const typename T::spec_type *spec, int cls_id=-1, int id=-1) const
 Get the PickerItem for the given spec.
PickerItem GetPickerItem (int cls_id, int id) const override
 Get the PickerItem for the given index with the class.
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.
Public Member Functions inherited from PickerCallbacks
 PickerCallbacks (const std::string &ini_group)
virtual ~PickerCallbacks ()
 Ensure the destructor of the sub classes are called as well.
virtual void Close (int data)
 Hide the window and all its child windows, and mark them for a later deletion.
virtual GrfSpecFeature GetFeature () const =0
 NewGRF feature this picker is for.
virtual bool IsActive () const =0
 Should picker class/type selection be enabled?
virtual StringID GetClassTooltip () const =0
 Get the tooltip string for the class list.
virtual int GetSelectedClass () const =0
 Get the index of the selected class.
virtual void SetSelectedClass (int id) const =0
 Set the selected class.
virtual StringID GetClassName (int id) const =0
 Get the name of a class.
virtual StringID GetTypeTooltip () const =0
 Get the tooltip string for the type grid.
virtual int GetSelectedType () const =0
 Get the selected type.
virtual void SetSelectedType (int id) const =0
 Set the selected type.
virtual StringID GetTypeName (int cls_id, int id) const =0
 Get the item name of a type.
virtual std::span< const BadgeID > GetTypeBadges (int cls_id, int id) const =0
 Get the item's badges of a type.
virtual bool IsTypeAvailable (int cls_id, int id) const =0
 Test if an item is currently buildable.
virtual void DrawType (int x, int y, int cls_id, int id) const =0
 Draw preview image of an item.
virtual StringID GetCollectionTooltip () const =0
 Get the tooltip string for the collection list.
virtual void FillUsedItems (std::set< PickerItem > &items)=0
 Fill a set with all items that are used by the current player.
std::set< std::string > InitializeInactiveCollections (const std::map< std::string, std::set< PickerItem > > collections)
 Initialize the list of active collections for sorting purposes.

Additional Inherited Members

Data Fields inherited from PickerCallbacks
Listing class_last_sorting = { false, 0 }
 Default sorting of PickerClassList.
Filtering class_last_filtering = { false, 0 }
 Default filtering of PickerClassList.
Listing type_last_sorting = { false, 0 }
 Default sorting of PickerTypeList.
Filtering type_last_filtering = { false, 0 }
 Default filtering of PickerTypeList.
Listing collection_last_sorting = { false, 0 }
 Default sorting of PickerCollectionList.
const std::string ini_group
 Ini Group for saving favourites.
uint8_t mode = 0
 Bitmask of PickerFilterModes.
bool rename_collection = false
 Are we renaming a collection?
std::string sel_collection
 Currently selected collection of saved items.
std::string edit_collection
 Collection to rename or delete.
std::set< std::string > rm_collections
 Set of removed or renamed collections for updating ini file.
int preview_height = 0
 Previously adjusted height.
std::set< PickerItemused
 Set of items used in the current game by the current company.
std::map< std::string, std::set< PickerItem > > saved
 Set of saved collections of items.

Detailed Description

template<typename T>
class PickerCallbacksNewGRFClass< T >

Helper for PickerCallbacks when the class system is based on NewGRFClass.

Definition at line 219 of file picker_gui.h.

Constructor & Destructor Documentation

◆ PickerCallbacksNewGRFClass()

template<typename T>
PickerCallbacksNewGRFClass< T >::PickerCallbacksNewGRFClass ( const std::string & ini_group)
inlineexplicit

Create the callback instance.

Parameters
ini_groupThe group in the configuration file to save/load state to/from.

Definition at line 225 of file picker_gui.h.

References PickerCallbacks::ini_group.

Member Function Documentation

◆ GetClass()

template<typename T>
const T * PickerCallbacksNewGRFClass< T >::GetClass ( int cls_id) const
inline

Get the class with the given index.

Parameters
cls_idThe index of the class to get.
Returns
The class instance.

Definition at line 239 of file picker_gui.h.

References GetClassIndex(), and T.

Referenced by GetPickerItem(), GetSpec(), and GetTypeCount().

◆ GetClassCount()

template<typename T>
int PickerCallbacksNewGRFClass< T >::GetClassCount ( ) const
inlineoverridevirtual

Get the number of classes.

Returns
Number of classes.
Note
Used only to estimate space requirements.

Implements PickerCallbacks.

Definition at line 251 of file picker_gui.h.

◆ GetClassIndex()

template<typename T>
T::index_type PickerCallbacksNewGRFClass< T >::GetClassIndex ( int cls_id) const
inline

Casts the given index to the right type.

Parameters
cls_idThe index to cast.
Returns
The index with the right type.

Definition at line 232 of file picker_gui.h.

Referenced by GetClass().

◆ GetPickerItem() [1/2]

template<typename T>
PickerItem PickerCallbacksNewGRFClass< T >::GetPickerItem ( const typename T::spec_type * spec,
int cls_id = -1,
int id = -1 ) const
inline

Get the PickerItem for the given spec.

Parameters
specThe spec to get the picker item to.
cls_idOptional index of the class, in case spec is nullptr.
idOptional index of the spec within the class, in case spec is nullptr.
Returns
The PickerItem with metadata.

Definition at line 261 of file picker_gui.h.

Referenced by GetPickerItem(), and UpdateSavedItems().

◆ GetPickerItem() [2/2]

template<typename T>
PickerItem PickerCallbacksNewGRFClass< T >::GetPickerItem ( int cls_id,
int id ) const
inlineoverridevirtual

Get the PickerItem for the given index with the class.

Parameters
cls_idThe index of the class.
idThe index of the spec within the class.
Returns
The PickerItem with metadata.

Implements PickerCallbacks.

Definition at line 273 of file picker_gui.h.

References GetClass(), GetPickerItem(), and GetSpec().

◆ GetSpec()

template<typename T>
const T::spec_type * PickerCallbacksNewGRFClass< T >::GetSpec ( int cls_id,
int id ) const
inline

Get the spec of an object within a class.

Parameters
cls_idThe index of the class.
idThe index of the spec within the class.
Returns
The spec.

Definition at line 247 of file picker_gui.h.

References GetClass().

Referenced by GetPickerItem().

◆ GetTypeCount()

template<typename T>
int PickerCallbacksNewGRFClass< T >::GetTypeCount ( int cls_id) const
inlineoverridevirtual

Get the number of types in a class.

Parameters
cls_idThe class' identifier.
Returns
The number of types.
Note
Used only to estimate space requirements.

Implements PickerCallbacks.

Definition at line 252 of file picker_gui.h.

References GetClass().

◆ HasClassChoice()

template<typename T>
bool PickerCallbacksNewGRFClass< T >::HasClassChoice ( ) const
inlineoverridevirtual

Are there multiple classes to chose from?

Returns
true when there are multiple classes for this picker.

Implements PickerCallbacks.

Reimplemented in RoadStopPickerCallbacks< roadstoptype >, RoadWaypointPickerCallbacks, StationPickerCallbacks, and WaypointPickerCallbacks.

Definition at line 249 of file picker_gui.h.

◆ UpdateSavedItems()

template<typename T>
std::map< std::string, std::set< PickerItem > > PickerCallbacksNewGRFClass< T >::UpdateSavedItems ( const std::map< std::string, std::set< PickerItem > > & src)
inlineoverridevirtual

Update link between grfid/localidx and class_index/index in saved items.

Parameters
srcMapping of name to set of PickerItems with only grfid and localidx set.
Returns
Mapping of name to fully populated PickerItems for loaded NewGRFs and 'src' items when the NewGRF is not loaded.

Implements PickerCallbacks.

Definition at line 278 of file picker_gui.h.

References GetPickerItem().


The documentation for this class was generated from the following file: