OpenTTD Source 20260311-master-g511d3794ce
picker_gui.cpp File Reference

File for dealing with picker windows. More...

#include "stdafx.h"
#include "core/backup_type.hpp"
#include "company_func.h"
#include "dropdown_func.h"
#include "gui.h"
#include "hotkeys.h"
#include "ini_type.h"
#include "newgrf_badge.h"
#include "newgrf_badge_config.h"
#include "newgrf_badge_gui.h"
#include "picker_gui.h"
#include "querystring_gui.h"
#include "settings_type.h"
#include "sortlist_type.h"
#include "sound_func.h"
#include "sound_type.h"
#include "string_func.h"
#include "stringfilter_type.h"
#include "strings_func.h"
#include "widget_type.h"
#include "window_func.h"
#include "window_gui.h"
#include "window_type.h"
#include "zoom_func.h"
#include "widgets/picker_widget.h"
#include "table/sprites.h"
#include "table/strings.h"
#include <charconv>
#include "safeguards.h"

Go to the source code of this file.

Functions

static std::vector< PickerCallbacks * > & GetPickerCallbacks ()
static void PickerLoadConfig (const IniFile &ini, PickerCallbacks &callbacks)
 Load favourites of a picker from config.
static void PickerSaveConfig (IniFile &ini, const PickerCallbacks &callbacks)
 Save favourites of a picker to config.
void PickerLoadConfig (const IniFile &ini)
 Load favourites of all registered Pickers from config.
void PickerSaveConfig (IniFile &ini)
 Save favourites of all registered Pickers to config.
static bool ClassIDSorter (int const &a, int const &b)
 Sort classes by id.
static bool ClassTagNameFilter (int const *item, PickerFilterData &filter)
 Filter classes by class name.
static bool TypeIDSorter (PickerItem const &a, PickerItem const &b)
 Sort types by id.
static bool TypeTagNameFilter (PickerItem const *item, PickerFilterData &filter)
 Filter types by class name.
static bool CollectionIDSorter (std::string const &a, std::string const &b)
 Sort collections by id.
std::unique_ptr< NWidgetBaseMakePickerClassWidgets ()
 Create nested widgets for the class picker widgets.
std::unique_ptr< NWidgetBaseMakePickerTypeWidgets ()
 Create nested widgets for the type picker widgets.
void InvalidateAllPickerWindows ()

Variables

PickerWindowpicker_window
 Allow the collection sorter to test if the collection has inactive items.
static const std::initializer_list< PickerClassList::SortFunction *const > _class_sorter_funcs = { &ClassIDSorter }
 Sort functions of the PickerClassList.
static const std::initializer_list< PickerClassList::FilterFunction *const > _class_filter_funcs = { &ClassTagNameFilter }
 Filter functions of the PickerClassList.
static const std::initializer_list< PickerTypeList::SortFunction *const > _type_sorter_funcs = { TypeIDSorter }
 Sort functions of the PickerTypeList.
static const std::initializer_list< PickerTypeList::FilterFunction *const > _type_filter_funcs = { TypeTagNameFilter }
 Filter functions of the PickerTypeList.
static const std::initializer_list< PickerCollectionList::SortFunction *const > _collection_sorter_funcs = { &CollectionIDSorter }
 Sort functions of the PickerCollectionList.

Detailed Description

File for dealing with picker windows.

Definition in file picker_gui.cpp.

Function Documentation

◆ ClassIDSorter()

bool ClassIDSorter ( int const & a,
int const & b )
static

Sort classes by id.

Comparison helper for the sorter, comparing a to b.

Parameters
aThe first element.
bThe second element.
Returns
true if the first element is less than the second element.

Definition at line 147 of file picker_gui.cpp.

◆ ClassTagNameFilter()

bool ClassTagNameFilter ( int const * item,
PickerFilterData & filter )
static

Filter classes by class name.

Check whether an element should be kept in the list.

Parameters
itemThe element to check.
filterThe filter parameter.
Returns
true iff the element should be in the list. Signature of filter function.

Definition at line 153 of file picker_gui.cpp.

References PickerFilterData::callbacks, PickerCallbacks::GetClassName(), StringFilter::GetState(), GetString(), and StringFilter::ResetState().

◆ CollectionIDSorter()

bool CollectionIDSorter ( std::string const & a,
std::string const & b )
static

Sort collections by id.

Comparison helper for the sorter, comparing a to b.

Parameters
aThe first element.
bThe second element.
Returns
true if the first element is less than the second element.

Definition at line 184 of file picker_gui.cpp.

References GetString(), picker_window, and StrNaturalCompare().

◆ GetPickerCallbacks()

std::vector< PickerCallbacks * > & GetPickerCallbacks ( )
static

Definition at line 44 of file picker_gui.cpp.

◆ InvalidateAllPickerWindows()

void InvalidateAllPickerWindows ( )

Definition at line 1010 of file picker_gui.cpp.

◆ MakePickerClassWidgets()

◆ MakePickerTypeWidgets()

◆ PickerLoadConfig() [1/2]

void PickerLoadConfig ( const IniFile & ini)

Load favourites of all registered Pickers from config.

Parameters
iniIniFile to load to.

Definition at line 132 of file picker_gui.cpp.

References PickerLoadConfig().

Referenced by LoadFromConfig().

◆ PickerLoadConfig() [2/2]

void PickerLoadConfig ( const IniFile & ini,
PickerCallbacks & callbacks )
static

Load favourites of a picker from config.

Parameters
iniIniFile to load to.
callbacksPicker to load.

Definition at line 67 of file picker_gui.cpp.

References ConvertHexToBytes(), IniLoadFile::groups, PickerCallbacks::ini_group, IniGroup::items, IniGroup::name, IniItem::name, and PickerCallbacks::saved.

Referenced by PickerLoadConfig().

◆ PickerSaveConfig() [1/2]

void PickerSaveConfig ( IniFile & ini)

Save favourites of all registered Pickers to config.

Parameters
iniIniFile to save to.

Definition at line 141 of file picker_gui.cpp.

References PickerSaveConfig().

Referenced by SaveToConfig().

◆ PickerSaveConfig() [2/2]

void PickerSaveConfig ( IniFile & ini,
const PickerCallbacks & callbacks )
static

Save favourites of a picker to config.

Parameters
iniIniFile to save to.
callbacksPicker to save.

Definition at line 111 of file picker_gui.cpp.

References IniGroup::Clear(), IniGroup::CreateItem(), IniLoadFile::GetOrCreateGroup(), PickerCallbacks::ini_group, IniLoadFile::RemoveGroup(), PickerCallbacks::rm_collections, and PickerCallbacks::saved.

Referenced by PickerSaveConfig().

◆ TypeIDSorter()

bool TypeIDSorter ( PickerItem const & a,
PickerItem const & b )
static

Sort types by id.

Comparison helper for the sorter, comparing a to b.

Parameters
aThe first element.
bThe second element.
Returns
true if the first element is less than the second element.

Definition at line 161 of file picker_gui.cpp.

◆ TypeTagNameFilter()

bool TypeTagNameFilter ( PickerItem const * item,
PickerFilterData & filter )
static

Filter types by class name.

Check whether an element should be kept in the list.

Parameters
itemThe element to check.
filterThe filter parameter.
Returns
true iff the element should be in the list. Signature of filter function.

Definition at line 169 of file picker_gui.cpp.

References PickerFilterData::callbacks, StringFilter::GetState(), GetString(), PickerCallbacks::GetTypeBadges(), PickerCallbacks::GetTypeName(), and StringFilter::ResetState().

Variable Documentation

◆ _class_filter_funcs

const std::initializer_list<PickerClassList::FilterFunction * const> _class_filter_funcs = { &ClassTagNameFilter }
static

Filter functions of the PickerClassList.

Definition at line 192 of file picker_gui.cpp.

◆ _class_sorter_funcs

const std::initializer_list<PickerClassList::SortFunction * const> _class_sorter_funcs = { &ClassIDSorter }
static

Sort functions of the PickerClassList.

Definition at line 191 of file picker_gui.cpp.

◆ _collection_sorter_funcs

const std::initializer_list<PickerCollectionList::SortFunction * const> _collection_sorter_funcs = { &CollectionIDSorter }
static

Sort functions of the PickerCollectionList.

Definition at line 195 of file picker_gui.cpp.

◆ _type_filter_funcs

const std::initializer_list<PickerTypeList::FilterFunction * const> _type_filter_funcs = { TypeTagNameFilter }
static

Filter functions of the PickerTypeList.

Definition at line 194 of file picker_gui.cpp.

◆ _type_sorter_funcs

const std::initializer_list<PickerTypeList::SortFunction * const> _type_sorter_funcs = { TypeIDSorter }
static

Sort functions of the PickerTypeList.

Definition at line 193 of file picker_gui.cpp.

◆ picker_window

PickerWindow* picker_window

Allow the collection sorter to test if the collection has inactive items.

Definition at line 181 of file picker_gui.cpp.

Referenced by CollectionIDSorter(), and PickerWindow::OnQueryTextFinished().