Commit e816cf72 authored by Jean-Baptiste Demonte's avatar Jean-Baptiste Demonte

feat(favorites): add sort on system name for favorites system

parent bfa5341d
This diff is collapsed.
No preview for this file type
#include "FileSorts.h"
#include "Locale.h"
#include "SystemData.h"
namespace FileSorts
{
std::vector<SortType> SortTypes;
std::vector<SortType> SortTypesForFavorites;
void init()
{
SortTypes.push_back(SortType(&compareFileName, true, "\uF15d " + _("FILENAME")));
SortTypes.push_back(SortType(&compareFileName, false, "\uF15e " + _("FILENAME")));
SortTypes.push_back(SortType(&compareRating, true, "\uF165 " + _("RATING")));
SortTypes.push_back(SortType(&compareRating, false, "\uF164 " + _("RATING")));
SortTypes.push_back(SortType(&compareTimesPlayed, true, "\uF160 " + _("TIMES PLAYED")));
SortTypes.push_back(SortType(&compareTimesPlayed, false, "\uF161 " + _("TIMES PLAYED")));
SortTypes.push_back(SortType(&compareLastPlayed, true, "\uF160 " + _("LAST PLAYED")));
SortTypes.push_back(SortType(&compareLastPlayed, false, "\uF161 " + _("LAST PLAYED")));
SortTypes.push_back(SortType(&compareNumberPlayers, true, "\uF162 " + _("NUMBER OF PLAYERS")));
SortTypes.push_back(SortType(&compareNumberPlayers, false, "\uF163 " + _("NUMBER OF PLAYERS")));
SortTypes.push_back(SortType(&compareDevelopper, true, "\uF15d " + _("DEVELOPER")));
SortTypes.push_back(SortType(&compareDevelopper, false, "\uF15e " + _("DEVELOPER")));
SortTypes.push_back(SortType(&compareGenre, true, "\uF15d " + _("GENRE")));
SortTypes.push_back(SortType(&compareGenre, false, "\uF15e " + _("GENRE")));
void init() {
SortTypes.push_back(SortType(&compareFileName, true, "\uF15d " + _("FILENAME")));
SortTypes.push_back(SortType(&compareFileName, false, "\uF15e " + _("FILENAME")));
SortTypes.push_back(SortType(&compareRating, true, "\uF165 " + _("RATING")));
SortTypes.push_back(SortType(&compareRating, false, "\uF164 " + _("RATING")));
SortTypes.push_back(SortType(&compareTimesPlayed, true, "\uF160 " + _("TIMES PLAYED")));
SortTypes.push_back(SortType(&compareTimesPlayed, false, "\uF161 " + _("TIMES PLAYED")));
SortTypes.push_back(SortType(&compareLastPlayed, true, "\uF160 " + _("LAST PLAYED")));
SortTypes.push_back(SortType(&compareLastPlayed, false, "\uF161 " + _("LAST PLAYED")));
SortTypes.push_back(SortType(&compareNumberPlayers, true, "\uF162 " + _("NUMBER OF PLAYERS")));
SortTypes.push_back(SortType(&compareNumberPlayers, false, "\uF163 " + _("NUMBER OF PLAYERS")));
SortTypes.push_back(SortType(&compareDevelopper, true, "\uF15d " + _("DEVELOPER")));
SortTypes.push_back(SortType(&compareDevelopper, false, "\uF15e " + _("DEVELOPER")));
SortTypes.push_back(SortType(&compareGenre, true, "\uF15d " + _("GENRE")));
SortTypes.push_back(SortType(&compareGenre, false, "\uF15e " + _("GENRE")));
// Keep FILENAME sort at the begining to keep the Jump to next / previous letter working the same way
SortTypesForFavorites.insert(SortTypesForFavorites.end(), SortTypes.begin(), SortTypes.begin() + 2);
SortTypesForFavorites.push_back(SortType(&compareSystemName, true, "\uF166 " + _("SYSTEM NAME")));
SortTypesForFavorites.push_back(SortType(&compareSystemName, false, "\uF167 " + _("SYSTEM NAME")));
SortTypesForFavorites.insert(SortTypesForFavorites.end(), SortTypes.begin() + 2, SortTypes.end());
}
static int simpleCompareUppercase(const std::string& a, const std::string& b)
......@@ -46,7 +54,17 @@ namespace FileSorts
#define CheckFoldersAndGames(f1, f2) { int folderComparison = compareFoldersAndGames(f1, f2); if (folderComparison != 0) return folderComparison; }
//returns if file1 should come before file2
//returns if file1 should come before file2
ImplementSortMethod(compareSystemName)
{
const SystemData * system1 = file1->getSystem();
const SystemData * system2 = file2->getSystem();
const int result = simpleCompareUppercase(system1->getName(), system2->getName());
if (result) { return result; }
return simpleCompareUppercase(file1->getName(), file2->getName());
}
ImplementSortMethod(compareFileName)
{
CheckFoldersAndGames(file1, file2);
......
......@@ -18,6 +18,7 @@ namespace FileSorts
#define DeclareSortMethodPrototype(x) int x(FileData* const file1, FileData* const file2);
#define ImplementSortMethod(x) int x(FileData* const file1, FileData* const file2)
DeclareSortMethodPrototype(compareSystemName)
DeclareSortMethodPrototype(compareFileName)
DeclareSortMethodPrototype(compareRating)
DeclareSortMethodPrototype(compareTimesPlayed)
......@@ -27,5 +28,6 @@ namespace FileSorts
DeclareSortMethodPrototype(compareGenre)
extern std::vector<SortType> SortTypes;
extern std::vector<SortType> SortTypesForFavorites;
void init();
};
......@@ -98,7 +98,7 @@ class SystemData
inline bool isFavorite() const { return mIsFavorite; }
inline FileData::List getFavorites() const { return mRootFolder.getAllFavoritesRecursively(false); }
inline unsigned int getSortId() const { return mSortId; };
inline FileSorts::SortType getSortType() const { return FileSorts::SortTypes.at(mSortId); };
inline FileSorts::SortType getSortType(bool forFavorites) const { return forFavorites ? FileSorts::SortTypesForFavorites.at(mSortId) : FileSorts::SortTypes.at(mSortId); };
inline void setSortId(const unsigned int sortId = 0) { mSortId = sortId; };
inline const std::vector<PlatformIds::PlatformId>& getPlatformIds() const { return mPlatformIds; }
......
......@@ -24,6 +24,8 @@ GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system)
mJumpToLetterList = std::make_shared<LetterList>(mWindow, _("JUMP TO LETTER"), false);
std::vector<FileSorts::SortType> & sortTypes = system->isFavorite() ? FileSorts::SortTypesForFavorites : FileSorts::SortTypes;
std::vector<std::string> letters = getGamelist()->getAvailableLetters();
if (!letters.empty()) { // may happen if only contains folders
......@@ -56,12 +58,12 @@ GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system)
// sort list by
unsigned int currentSortId = mSystem->getSortId();
if (currentSortId > FileSorts::SortTypes.size()) {
if (currentSortId > sortTypes.size()) {
currentSortId = 0;
}
mListSort = std::make_shared<SortList>(mWindow, _("SORT GAMES BY"), false);
for (unsigned int i = 0; i < FileSorts::SortTypes.size(); i++) {
const FileSorts::SortType& sortType = FileSorts::SortTypes.at(i);
for (unsigned int i = 0; i < sortTypes.size(); i++) {
const FileSorts::SortType& sortType = sortTypes.at(i);
mListSort->add(sortType.description, i, i == currentSortId);
}
......
......@@ -149,7 +149,7 @@ void BasicGameListView::populateList(const FolderData* folder)
}
// Sort
const FileSorts::SortType& sortType = mSystem->getSortType();
const FileSorts::SortType& sortType = mSystem->getSortType(mSystem->isFavorite());
FolderData::Sort(items, sortType.comparisonFunction, sortType.ascending);
// Add to list
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment