Updates to Random Collections

- Updated labels
- Add "Exclusion" collection setting
This commit is contained in:
pjft 2024-02-02 12:32:17 +00:00
parent c8bcfa4420
commit 4245966a0b
5 changed files with 70 additions and 17 deletions

View file

@ -627,11 +627,20 @@ SystemData* CollectionSystemManager::getSystemToView(SystemData* sys)
void CollectionSystemManager::recreateCollection(SystemData* sysData)
{
CollectionSystemData* colSysData = &mAutoCollectionSystemsData[sysData->getName()];
if (!colSysData)
CollectionSystemData* colSysData;
if (mAutoCollectionSystemsData.find(sysData->getName()) != mAutoCollectionSystemsData.end())
{
// it's an auto collection
colSysData = &mAutoCollectionSystemsData[sysData->getName()];
}
else if (mCustomCollectionSystemsData.find(sysData->getName()) != mCustomCollectionSystemsData.end())
{
// it's a custom collection
colSysData = &mCustomCollectionSystemsData[sysData->getName()];
if (!colSysData) {
LOG(LogDebug) << "Couldn't find collection: " << sysData->getName();
}
else
{
LOG(LogDebug) << "Couldn't find collection to recreate in either custom or auto collections: " << sysData->getName();
return;
}
@ -821,6 +830,20 @@ void CollectionSystemManager::addRandomGames(SystemData* newSys, SystemData* sou
gamesForSourceSystem = Math::min(RANDOM_SYSTEM_MAX, settingsValues[sourceSystem->getFullName()]);
}
// load exclusion collection
std::unordered_map<std::string,FileData*> exclusionMap;
std::string exclusionCollection = Settings::getInstance()->getString("RandomCollectionExclusionCollection");
auto sysDataIt = mCustomCollectionSystemsData.find(exclusionCollection);
if (!exclusionCollection.empty() && sysDataIt != mCustomCollectionSystemsData.end()) {
if (!sysDataIt->second.isPopulated) {
populateCustomCollection(&(sysDataIt->second));
}
exclusionMap = mCustomCollectionSystemsData[exclusionCollection].system->getRootFolder()->getChildrenByFilename();
}
// we do this to avoid trying to add more games than there are in the system
gamesForSourceSystem = Math::min(gamesForSourceSystem, sourceSystem->getRootFolder()->getFilesRecursive(GAME).size());
@ -831,9 +854,16 @@ void CollectionSystemManager::addRandomGames(SystemData* newSys, SystemData* sou
for (int iterCount = startCount; iterCount < endCount; )
{
FileData* randomGame = sourceSystem->getRandomGame()->getSourceFileData();
CollectionFileData* newGame = new CollectionFileData(randomGame, newSys);
rootFolder->addChild(newGame);
index->addToIndex(newGame);
CollectionFileData* newGame = NULL;
if(exclusionMap.find(randomGame->getFullPath()) == exclusionMap.end())
{
// Not in the exclusion collection
newGame = new CollectionFileData(randomGame, newSys);
rootFolder->addChild(newGame);
index->addToIndex(newGame);
}
if (rootFolder->getFilesRecursive(GAME).size() > iterCount)
{
// added game, proceed
@ -843,13 +873,13 @@ void CollectionSystemManager::addRandomGames(SystemData* newSys, SystemData* sou
else
{
// the game already exists in the collection, let's try again
LOG(LogDebug) << "Clash: " << newGame->getName() << " already exists. Deleting and trying again";
LOG(LogDebug) << "Clash: " << randomGame->getName() << " already exists or in exclusion list. Deleting and trying again";
delete newGame;
retryCount--;
if (retryCount == 0)
{
// we give up. Either we were very unlucky, or all the games in this system are already there.
LOG(LogDebug) << "Giving up retrying: game already exists. Deleting and moving on.";
LOG(LogDebug) << "Giving up retrying: cannot add this game. Deleting and moving on.";
return;
}
}

View file

@ -23,7 +23,7 @@ void GuiCollectionSystemsOptions::initializeMenu()
addSystemsToMenu();
// manage random collection
addEntry("RANDOM COLLECTION SETTINGS", 0x777777FF, true, [this] { openRandomCollectionSettings(); });
addEntry("RANDOM GAME COLL. SETTINGS", 0x777777FF, true, [this] { openRandomCollectionSettings(); });
// add "Create New Custom Collection from Theme"
std::vector<std::string> unusedFolders = CollectionSystemManager::get()->getUnusedSystemsFromTheme();

View file

@ -10,7 +10,7 @@
#include "SystemData.h"
#include "Window.h"
GuiRandomCollectionOptions::GuiRandomCollectionOptions(Window* window) : GuiComponent(window), mMenu(window, "RANDOM GAME COLLECTION SETTINGS")
GuiRandomCollectionOptions::GuiRandomCollectionOptions(Window* window) : GuiComponent(window), mMenu(window, "RANDOM COLLECTION")
{
customCollectionLists.clear();
autoCollectionLists.clear();
@ -23,12 +23,28 @@ GuiRandomCollectionOptions::GuiRandomCollectionOptions(Window* window) : GuiComp
void GuiRandomCollectionOptions::initializeMenu()
{
// get collections
addEntry("SYSTEMS", 0x777777FF, true, [this] { selectSystems(); });
addEntry("AUTOMATIC COLLECTIONS", 0x777777FF, true, [this] { selectAutoCollections(); });
addEntry("CUSTOM COLLECTIONS", 0x777777FF, true, [this] { selectCustomCollections(); });
addEntry("INCLUDED SYSTEMS", 0x777777FF, true, [this] { selectSystems(); });
addEntry("INCLUDED AUTO COLLECTIONS", 0x777777FF, true, [this] { selectAutoCollections(); });
addEntry("INCLUDED CUSTOM COLLECTIONS", 0x777777FF, true, [this] { selectCustomCollections(); });
// Add option to exclude games from a collection
exclusionCollection = std::make_shared< OptionListComponent<std::string> >(mWindow, "EXCLUDE GAMES FROM", false);
// Add default option
exclusionCollection->add("<NONE>", "", Settings::getInstance()->getString("RandomCollectionExclusionCollection") == "");
std::map<std::string, CollectionSystemData> customSystems = CollectionSystemManager::get()->getCustomCollectionSystems();
// add all enabled Custom Systems
for(std::map<std::string, CollectionSystemData>::const_iterator it = customSystems.cbegin() ; it != customSystems.cend() ; it++ )
{
exclusionCollection->add(it->second.decl.longName, it->second.decl.name, Settings::getInstance()->getString("RandomCollectionExclusionCollection") == it->second.decl.name);
}
mMenu.addWithLabel("EXCLUDE GAMES FROM", exclusionCollection);
// Add option to trim random collection items
trimRandom = std::make_shared< OptionListComponent<std::string> >(mWindow, "MAX ITEMS", false);
trimRandom = std::make_shared< OptionListComponent<std::string> >(mWindow, "MAX GAMES", false);
// Add default entry
trimRandom->add("ALL", "", Settings::getInstance()->getString("RandomCollectionMaxItems") == "");
@ -119,7 +135,7 @@ std::string GuiRandomCollectionOptions::collectionListsToString(std::vector< Sys
}
void GuiRandomCollectionOptions::selectEntries(std::map<std::string, CollectionSystemData> collection, std::string settingsLabel, int defaultValue, std::vector< SystemGames>* results) {
auto s = new GuiSettings(mWindow, "GAMES FROM SYSTEMS");
auto s = new GuiSettings(mWindow, "INCLUDE GAMES FROM");
std::map<std::string, int> settingsValues = stringToRandomSettingsMap(Settings::getInstance()->getString(settingsLabel));
@ -179,7 +195,12 @@ void GuiRandomCollectionOptions::saveSettings()
std::string prevTrim = Settings::getInstance()->getString("RandomCollectionMaxItems");
Settings::getInstance()->setString("RandomCollectionMaxItems", curTrim);
mNeedsCollectionRefresh |= (curTrim != prevTrim);
std::string curExclusion = exclusionCollection->getSelected();
std::string prevExclusion = Settings::getInstance()->getString("RandomCollectionExclusionCollection");
Settings::getInstance()->setString("RandomCollectionExclusionCollection", curExclusion);
mNeedsCollectionRefresh |= (curTrim != prevTrim || curExclusion != prevExclusion);
if (mNeedsCollectionRefresh)
{

View file

@ -47,6 +47,7 @@ private:
std::vector< SystemGames> autoCollectionLists;
std::vector< SystemGames> systemLists;
std::shared_ptr< OptionListComponent<std::string> > trimRandom;
std::shared_ptr< OptionListComponent<std::string> > exclusionCollection;
MenuComponent mMenu;
SystemData* mSystem;
};

View file

@ -143,6 +143,7 @@ void Settings::setDefaults()
mStringMap["RandomCollectionSystemsAuto"] = "";
mStringMap["RandomCollectionSystemsCustom"] = "";
mStringMap["RandomCollectionSystems"] = "";
mStringMap["RandomCollectionExclusionCollection"] = "";
mStringMap["CollectionSystemsAuto"] = "";
mStringMap["CollectionSystemsCustom"] = "";
mStringMap["DefaultScreenSaverCollection"] = "";