OpenTTD Source 20241224-master-gf74b0cf984
|
List template of 'things' T
to sort in a GUI.
More...
#include <sortlist_type.h>
Public Types | |
using | SortFunction = std::conditional_t< std::is_same_v< P, std::nullptr_t >, bool(const T &, const T &), bool(const T &, const T &, const P)> |
Signature of sort function. | |
using | FilterFunction = bool(const T *, F) |
Signature of filter function. | |
Public Member Functions | |
template<typename T_ = T, typename P_ = P, typename _F = F, std::enable_if_t<!std::is_same_v< P_, std::nullptr_t > > * = nullptr> | |
GUIList (const P ¶ms) | |
uint8_t | SortType () const |
Get the sorttype of the list. | |
void | SetSortType (uint8_t n_type) |
Set the sorttype of the list. | |
Listing | GetListing () const |
Export current sort conditions. | |
void | SetListing (Listing l) |
Import sort conditions. | |
uint8_t | FilterType () const |
Get the filtertype of the list. | |
void | SetFilterType (uint8_t n_type) |
Set the filtertype of the list. | |
Filtering | GetFiltering () const |
Export current filter conditions. | |
void | SetFiltering (Filtering f) |
Import filter conditions. | |
bool | NeedResort () |
Check if a resort is needed next loop If used the resort timer will decrease every call till 0. | |
void | ForceResort () |
Force a resort next Sort call Reset the resort timer if used too. | |
bool | IsDescSortOrder () const |
Check if the sort order is descending. | |
void | ToggleSortOrder () |
Toggle the sort order Since that is the worst condition for the sort function reverse the list here. | |
template<typename Comp > | |
bool | Sort (Comp compare) |
Sort the list. | |
void | SetSortFuncs (std::span< SortFunction *const > n_funcs) |
Hand the sort function pointers to the GUIList. | |
bool | Sort () |
Overload of #Sort(SortFunction *compare) Overloaded to reduce external code. | |
bool | IsFilterEnabled () const |
Check if the filter is enabled. | |
void | SetFilterState (bool state) |
Enable or disable the filter. | |
bool | Filter (FilterFunction *decide, F filter_data) |
Filter the list. | |
void | SetFilterFuncs (std::span< FilterFunction *const > n_funcs) |
Hand the filter function pointers to the GUIList. | |
bool | Filter (F filter_data) |
Filter the data with the currently selected filter. | |
bool | NeedRebuild () const |
Check if a rebuild is needed. | |
void | ForceRebuild () |
Force that a rebuild is needed. | |
void | RebuildDone () |
Notify the sortlist that the rebuild is done. | |
Protected Types | |
using | SortParameterReference = std::conditional_t< std::is_same_v< P, std::nullptr_t >, P, P & > |
Protected Member Functions | |
bool | IsSortable () const |
Check if the list is sortable. | |
void | ResetResortTimer () |
Reset the resort timer. | |
Protected Attributes | |
std::span< SortFunction *const > | sort_func_list |
the sort criteria functions | |
std::span< FilterFunction *const > | filter_func_list |
the filter criteria functions | |
SortListFlags | flags |
used to control sorting/resorting/etc. | |
uint8_t | sort_type |
what criteria to sort on | |
uint8_t | filter_type |
what criteria to filter on | |
uint16_t | resort_timer |
resort list after a given amount of ticks if set | |
const SortParameterReference | params |
List template of 'things' T
to sort in a GUI.
T | Type of data stored in the list to represent each item. |
P | Tyoe of data passed as additional parameter to the sort function. |
F | Type of data fed as additional value to the filter function. |
Definition at line 47 of file sortlist_type.h.
using GUIList< T, P, F >::FilterFunction = bool(const T*, F) |
Signature of filter function.
Definition at line 50 of file sortlist_type.h.
using GUIList< T, P, F >::SortFunction = std::conditional_t<std::is_same_v<P, std::nullptr_t>, bool (const T&, const T&), bool (const T&, const T&, const P)> |
Signature of sort function.
Definition at line 49 of file sortlist_type.h.
|
protected |
Definition at line 62 of file sortlist_type.h.
|
inline |
Definition at line 87 of file sortlist_type.h.
|
inline |
Definition at line 99 of file sortlist_type.h.
|
inline |
Filter the data with the currently selected filter.
filter_data | Additional data passed to the filter function. |
Definition at line 380 of file sortlist_type.h.
References GUIList< T, P, F >::Filter(), and GUIList< T, P, F >::filter_func_list.
|
inline |
Filter the list.
decide | The function to decide about an item |
filter_data | Additional data passed to the filter function |
Definition at line 346 of file sortlist_type.h.
References VL_FILTER.
Referenced by NetworkGameWindow::BuildGUINetworkGameList(), PickerWindow::BuildPickerClassList(), PickerWindow::BuildPickerTypeList(), IndustryDirectoryWindow::BuildSortIndustriesList(), GUIList< T, P, F >::Filter(), NetworkContentListWindow::FilterContentList(), BuildVehicleWindow::FilterEngineList(), SignList::FilterSignList(), and BaseVehicleListWindow::FilterVehicleList().
|
inline |
Get the filtertype of the list.
Definition at line 167 of file sortlist_type.h.
References GUIList< T, P, F >::filter_type.
|
inline |
Force that a rebuild is needed.
Definition at line 399 of file sortlist_type.h.
References SETBITS, and VL_REBUILD.
Referenced by NewGRFWindow::AddGRFToActive(), NetworkContentListWindow::NetworkContentListWindow(), NewGRFConfirmationCallback(), ReplaceVehicleWindow::OnClick(), BuildVehicleWindow::OnClick(), SelectCompanyLiveryWindow::OnClick(), VehicleGroupWindow::OnClick(), NetworkContentListWindow::OnClick(), NewGRFWindow::OnClick(), SignWindow::OnClick(), CompanyStationsWindow::OnClick(), CompanyStationsWindow::OnDropdownSelect(), ReplaceVehicleWindow::OnDropdownSelect(), BuildVehicleWindow::OnDropdownSelect(), NewGRFWindow::OnDropdownSelect(), NetworkContentListWindow::OnEditboxChanged(), NetworkGameWindow::OnEditboxChanged(), NewGRFWindow::OnEditboxChanged(), ReplaceVehicleWindow::OnInvalidateData(), BuildVehicleWindow::OnInvalidateData(), SelectCompanyLiveryWindow::OnInvalidateData(), VehicleGroupWindow::OnInvalidateData(), IndustryDirectoryWindow::OnInvalidateData(), PerformanceLeagueWindow::OnInvalidateData(), NetworkGameWindow::OnInvalidateData(), NewGRFWindow::OnInvalidateData(), PickerWindow::OnInvalidateData(), SignListWindow::OnInvalidateData(), CompanyStationsWindow::OnInvalidateData(), StoryBookWindow::OnInvalidateData(), TownDirectoryWindow::OnInvalidateData(), VehicleListWindow::OnInvalidateData(), NetworkContentListWindow::OnKeyPress(), NewGRFWindow::OnNewGRFsScanned(), ReplaceVehicleWindow::OnRailRoadTypeChange(), NetworkContentListWindow::OnReceiveContentInfo(), SignWindow::PrevNextSign(), StoryBookWindow::RefreshSelectedPage(), VehicleGroupWindow::SelectGroup(), IndustryDirectoryWindow::SetAcceptedCargoFilter(), BaseVehicleListWindow::SetCargoFilter(), and IndustryDirectoryWindow::SetProducedCargoFilter().
|
inline |
Force a resort next Sort call Reset the resort timer if used too.
Definition at line 236 of file sortlist_type.h.
References SETBITS, and VL_RESORT.
Referenced by BuildGuiGroupList(), NetworkContentListWindow::OnClick(), NetworkGameWindow::OnClick(), TownDirectoryWindow::OnClick(), NetworkContentListWindow::OnDownloadComplete(), SignListWindow::OnInit(), VehicleGroupWindow::OnInvalidateData(), IndustryDirectoryWindow::OnInvalidateData(), PerformanceLeagueWindow::OnInvalidateData(), SignListWindow::OnInvalidateData(), CompanyStationsWindow::OnInvalidateData(), TownDirectoryWindow::OnInvalidateData(), VehicleListWindow::OnInvalidateData(), and NetworkContentListWindow::OnKeyPress().
|
inline |
Export current filter conditions.
Definition at line 190 of file sortlist_type.h.
References Filtering::criteria, GUIList< T, P, F >::filter_type, Filtering::state, and VL_FILTER.
Referenced by NetworkContentListWindow::UpdateFilterState().
|
inline |
Export current sort conditions.
Definition at line 138 of file sortlist_type.h.
References Listing::criteria, Listing::order, GUIList< T, P, F >::sort_type, and VL_DESC.
Referenced by TownDirectoryWindow::OnClick(), and TownDirectoryWindow::OnDropdownSelect().
|
inline |
Check if the sort order is descending.
Definition at line 246 of file sortlist_type.h.
References VL_DESC.
Referenced by BuildBridgeWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), IndustryDirectoryWindow::DrawWidget(), NetworkGameWindow::DrawWidget(), CompanyStationsWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), VehicleListWindow::DrawWidget(), and NetworkContentListWindow::OnPaint().
|
inline |
Check if the filter is enabled.
Definition at line 320 of file sortlist_type.h.
References VL_FILTER.
|
inlineprotected |
Check if the list is sortable.
Definition at line 70 of file sortlist_type.h.
Referenced by GUIList< T, P, F >::Sort(), and GUIList< T, P, F >::ToggleSortOrder().
|
inline |
Check if a rebuild is needed.
Definition at line 391 of file sortlist_type.h.
References VL_REBUILD.
Referenced by PerformanceLeagueWindow::BuildCompanyList(), NetworkContentListWindow::BuildContentList(), VehicleGroupWindow::BuildGroupList(), NetworkGameWindow::BuildGUINetworkGameList(), PickerWindow::BuildPickerClassList(), PickerWindow::BuildPickerTypeList(), IndustryDirectoryWindow::BuildSortIndustriesList(), CompanyStationsWindow::BuildStationsList(), StoryBookWindow::BuildStoryPageElementList(), StoryBookWindow::BuildStoryPageList(), NetworkContentListWindow::OnInvalidateData(), IndustryDirectoryWindow::OnPaint(), NetworkContentListWindow::OnPaint(), NetworkGameWindow::OnPaint(), SignListWindow::OnPaint(), and TownDirectoryWindow::OnPaint().
|
inline |
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
If 0 reached the resort bit will be set and the timer will be reset.
Definition at line 222 of file sortlist_type.h.
References GUIList< T, P, F >::ResetResortTimer(), SETBITS, and VL_RESORT.
Referenced by SignWindow::OnClick(), VehicleGroupWindow::OnGameTick(), PerformanceLeagueWindow::OnGameTick(), CompanyStationsWindow::OnGameTick(), VehicleListWindow::OnGameTick(), NetworkGameWindow::OnPaint(), and SignWindow::PrevNextSign().
|
inline |
Notify the sortlist that the rebuild is done.
Definition at line 409 of file sortlist_type.h.
References CLRBITS, SETBITS, VL_REBUILD, and VL_RESORT.
Referenced by PerformanceLeagueWindow::BuildCompanyList(), NetworkContentListWindow::BuildContentList(), VehicleGroupWindow::BuildGroupList(), NetworkGameWindow::BuildGUINetworkGameList(), PickerWindow::BuildPickerClassList(), PickerWindow::BuildPickerTypeList(), IndustryDirectoryWindow::BuildSortIndustriesList(), CompanyStationsWindow::BuildStationsList(), StoryBookWindow::BuildStoryPageElementList(), StoryBookWindow::BuildStoryPageList(), and ReplaceVehicleWindow::GenerateLists().
|
inlineprotected |
Reset the resort timer.
Definition at line 78 of file sortlist_type.h.
References Ticks::DAY_TICKS.
Referenced by GUIList< T, P, F >::NeedResort(), and GUIList< T, P, F >::Sort().
|
inline |
Hand the filter function pointers to the GUIList.
n_funcs | Span covering the filter function pointers. |
Definition at line 369 of file sortlist_type.h.
Referenced by NetworkContentListWindow::NetworkContentListWindow(), BuildVehicleWindow::SetCargoFilterArray(), IndustryDirectoryWindow::SetCargoFilterArray(), and BaseVehicleListWindow::SetCargoFilterArray().
|
inline |
Import filter conditions.
f | The filter conditions we want to use |
Definition at line 204 of file sortlist_type.h.
References CLRBITS, Filtering::criteria, SETBITS, Filtering::state, and VL_FILTER.
Referenced by NetworkContentListWindow::NetworkContentListWindow().
|
inline |
Enable or disable the filter.
state | If filtering should be enabled or disabled |
Definition at line 330 of file sortlist_type.h.
References CLRBITS, SETBITS, and VL_FILTER.
Referenced by NetworkGameWindow::BuildGUINetworkGameList(), BuildVehicleWindow::OnDropdownSelect(), PickerWindow::OnEditboxChanged(), NewGRFWindow::OnEditboxChanged(), IndustryDirectoryWindow::SetAcceptedCargoFilter(), BaseVehicleListWindow::SetCargoFilter(), BuildVehicleWindow::SetCargoFilterArray(), IndustryDirectoryWindow::SetCargoFilterArray(), BaseVehicleListWindow::SetCargoFilterArray(), IndustryDirectoryWindow::SetProducedCargoFilter(), and NetworkContentListWindow::UpdateFilterState().
|
inline |
Set the filtertype of the list.
n_type | the new filter type |
Definition at line 177 of file sortlist_type.h.
Referenced by NetworkContentListWindow::FilterContentList(), IndustryDirectoryWindow::SetAcceptedCargoFilter(), BaseVehicleListWindow::SetCargoFilter(), and IndustryDirectoryWindow::SetProducedCargoFilter().
|
inline |
Import sort conditions.
l | The sort conditions we want to use |
Definition at line 152 of file sortlist_type.h.
References CLRBITS, Listing::criteria, Listing::order, SETBITS, and VL_DESC.
Referenced by NetworkContentListWindow::NetworkContentListWindow(), and TownDirectoryWindow::OnClick().
|
inline |
Hand the sort function pointers to the GUIList.
n_funcs | Span covering the sort function pointers. |
Definition at line 297 of file sortlist_type.h.
Referenced by NetworkContentListWindow::NetworkContentListWindow().
|
inline |
Set the sorttype of the list.
n_type | the new sort type |
Definition at line 124 of file sortlist_type.h.
References SETBITS, and VL_RESORT.
Referenced by NetworkContentListWindow::OnClick(), NetworkGameWindow::OnClick(), CompanyStationsWindow::OnDropdownSelect(), BuildBridgeWindow::OnDropdownSelect(), VehicleGroupWindow::OnDropdownSelect(), IndustryDirectoryWindow::OnDropdownSelect(), TownDirectoryWindow::OnDropdownSelect(), and VehicleListWindow::OnDropdownSelect().
|
inline |
Overload of #Sort(SortFunction *compare) Overloaded to reduce external code.
Definition at line 308 of file sortlist_type.h.
References GUIList< T, P, F >::Sort(), and GUIList< T, P, F >::sort_func_list.
Referenced by GUIList< T, P, F >::Sort().
|
inline |
Sort the list.
compare | The function to compare two list items |
Definition at line 270 of file sortlist_type.h.
References CLRBITS, GUIList< T, P, F >::IsSortable(), GUIList< T, P, F >::ResetResortTimer(), VL_DESC, and VL_RESORT.
Referenced by BuildGuiGroupList(), NetworkGameWindow::BuildGUINetworkGameList(), PickerWindow::BuildPickerClassList(), PickerWindow::BuildPickerTypeList(), IndustryDirectoryWindow::BuildSortIndustriesList(), StoryBookWindow::BuildStoryPageElementList(), StoryBookWindow::BuildStoryPageList(), TownDirectoryWindow::OnClick(), PerformanceLeagueWindow::OnPaint(), BuildBridgeWindow::SortBridgeList(), NetworkContentListWindow::SortContentList(), NetworkGameWindow::SortNetworkGameList(), and CompanyStationsWindow::SortStationsList().
|
inline |
Get the sorttype of the list.
Definition at line 114 of file sortlist_type.h.
References GUIList< T, P, F >::sort_type.
Referenced by NetworkGameWindow::DrawWidget(), IndustryDirectoryWindow::GetIndustryString(), BuildBridgeWindow::OnClick(), VehicleGroupWindow::OnClick(), IndustryDirectoryWindow::OnClick(), NetworkContentListWindow::OnClick(), NetworkGameWindow::OnClick(), CompanyStationsWindow::OnClick(), TownDirectoryWindow::OnClick(), VehicleListWindow::OnClick(), CompanyStationsWindow::OnDropdownSelect(), BuildBridgeWindow::OnDropdownSelect(), IndustryDirectoryWindow::OnDropdownSelect(), TownDirectoryWindow::OnDropdownSelect(), IndustryDirectoryWindow::OnInvalidateData(), TownDirectoryWindow::OnInvalidateData(), VehicleGroupWindow::OnPaint(), NetworkContentListWindow::OnPaint(), VehicleListWindow::OnPaint(), IndustryDirectoryWindow::SetStringParameters(), TownDirectoryWindow::SetStringParameters(), and BuildBridgeWindow::SortBridgeList().
|
inline |
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
Definition at line 256 of file sortlist_type.h.
References GUIList< T, P, F >::IsSortable(), and VL_DESC.
Referenced by BuildBridgeWindow::OnClick(), VehicleGroupWindow::OnClick(), IndustryDirectoryWindow::OnClick(), NetworkContentListWindow::OnClick(), NetworkGameWindow::OnClick(), CompanyStationsWindow::OnClick(), TownDirectoryWindow::OnClick(), and VehicleListWindow::OnClick().
|
protected |
the filter criteria functions
Definition at line 54 of file sortlist_type.h.
Referenced by GUIList< T, P, F >::Filter().
|
protected |
what criteria to filter on
Definition at line 57 of file sortlist_type.h.
Referenced by GUIList< T, P, F >::FilterType(), and GUIList< T, P, F >::GetFiltering().
|
protected |
used to control sorting/resorting/etc.
Definition at line 55 of file sortlist_type.h.
|
protected |
Definition at line 63 of file sortlist_type.h.
|
protected |
resort list after a given amount of ticks if set
Definition at line 58 of file sortlist_type.h.
|
protected |
the sort criteria functions
Definition at line 53 of file sortlist_type.h.
Referenced by GUIList< T, P, F >::Sort().
|
protected |
what criteria to sort on
Definition at line 56 of file sortlist_type.h.
Referenced by GUIList< T, P, F >::GetListing(), and GUIList< T, P, F >::SortType().