Added a 'Systems sorting' option to the Other settings menu

This commit is contained in:
Leon Styhre 2023-08-13 21:32:54 +02:00
parent 39982f048d
commit 706dd767f1
3 changed files with 99 additions and 50 deletions

View file

@ -814,66 +814,89 @@ bool SystemData::loadConfig()
void SystemData::loadSortingConfig()
{
std::vector<std::string> paths;
std::string filePath {ResourceManager::getInstance().getResourcePath(
":/systems/sorting/es_systems_sorting.xml", false)};
const std::string sortSetting {Settings::getInstance()->getString("SystemsSorting")};
const std::string customFilePath {Utils::FileSystem::getHomePath() +
"/.emulationstation/custom_systems" +
"/es_systems_sorting.xml"};
const bool customFileExists {Utils::FileSystem::exists(customFilePath)};
if (Utils::FileSystem::exists(filePath))
paths.emplace_back(filePath);
std::string path;
bool bundledFile {false};
filePath = Utils::FileSystem::getHomePath() + "/.emulationstation/custom_systems" +
"/es_systems_sorting.xml";
if (sortSetting == "hwtype_year") {
path = ResourceManager::getInstance().getResourcePath(
":/sorting/hwtype_year/es_systems_sorting.xml", true);
bundledFile = true;
}
else if (sortSetting == "manufacturer_hwtype_year") {
path = ResourceManager::getInstance().getResourcePath(
":/sorting/manufacturer_hwtype_year/es_systems_sorting.xml", true);
bundledFile = true;
}
else if (sortSetting == "manufacturer_year") {
path = ResourceManager::getInstance().getResourcePath(
":/sorting/manufacturer_year/es_systems_sorting.xml", true);
bundledFile = true;
}
else if (sortSetting == "year") {
path = ResourceManager::getInstance().getResourcePath(
":/sorting/year/es_systems_sorting.xml", true);
bundledFile = true;
}
if (Utils::FileSystem::exists(filePath))
paths.emplace_back(filePath);
if (bundledFile && customFileExists) {
LOG(LogInfo) << "A custom systems sorting file was found but it will not get loaded as a "
"bundled file has been selected";
}
else if (!bundledFile && customFileExists) {
path = customFilePath;
}
if (paths.empty()) {
LOG(LogDebug) << "No systems sorting file found";
if (path == "") {
LOG(LogDebug) << "No systems sorting file loaded";
return;
}
for (auto& path : paths) {
#if defined(_WIN64)
LOG(LogInfo) << "Parsing systems sorting file \"" << Utils::String::replace(path, "/", "\\")
<< "\"...";
pugi::xml_document doc;
const pugi::xml_parse_result& res {
doc.load_file(Utils::String::stringToWideString(path).c_str())};
LOG(LogInfo) << "Parsing systems sorting file \"" << Utils::String::replace(path, "/", "\\")
<< "\"...";
pugi::xml_document doc;
const pugi::xml_parse_result& res {
doc.load_file(Utils::String::stringToWideString(path).c_str())};
#else
LOG(LogInfo) << "Parsing systems sorting file \"" << path << "\"...";
pugi::xml_document doc;
const pugi::xml_parse_result& res {doc.load_file(path.c_str())};
LOG(LogInfo) << "Parsing systems sorting file \"" << path << "\"...";
pugi::xml_document doc;
const pugi::xml_parse_result& res {doc.load_file(path.c_str())};
#endif
if (!res) {
LOG(LogError) << "Couldn't parse es_systems_sorting.xml: " << res.description();
if (!res) {
LOG(LogError) << "Couldn't parse es_systems_sorting.xml: " << res.description();
return;
}
const pugi::xml_node& systemList {doc.child("systemList")};
if (!systemList) {
LOG(LogError) << "es_systems_sorting.xml is missing the <systemList> tag";
return;
}
std::string systemName;
std::string sortName;
for (pugi::xml_node system {systemList.child("system")}; system;
system = system.next_sibling("system")) {
sortName = system.child("systemsortname").text().get();
if (sortName == "")
continue;
}
const pugi::xml_node& systemList {doc.child("systemList")};
if (!systemList) {
LOG(LogError) << "es_systems_sorting.xml is missing the <systemList> tag";
continue;
}
systemName = Utils::String::replace(system.child("name").text().get(), "\n", "");
std::string systemName;
std::string sortName;
auto systemEntry = std::find_if(
sSystemVector.begin(), sSystemVector.end(),
[systemName](SystemData* system) { return system->getName() == systemName; });
for (pugi::xml_node system {systemList.child("system")}; system;
system = system.next_sibling("system")) {
sortName = system.child("systemsortname").text().get();
if (sortName == "")
continue;
systemName = Utils::String::replace(system.child("name").text().get(), "\n", "");
auto systemEntry = std::find_if(
sSystemVector.begin(), sSystemVector.end(),
[systemName](SystemData* system) { return system->getName() == systemName; });
if (systemEntry != SystemData::sSystemVector.end())
(*systemEntry)->mSortName = sortName;
}
if (systemEntry != SystemData::sSystemVector.end())
(*systemEntry)->mSortName = sortName;
}
}

View file

@ -460,6 +460,31 @@ void GuiMenu::openUIOptions()
}
});
// Systems sorting.
auto systemsSorting = std::make_shared<OptionListComponent<std::string>>(
getHelpStyle(), "SYSTEMS SORTING", false);
std::string selectedSystemsSorting {Settings::getInstance()->getString("SystemsSorting")};
systemsSorting->add("FULL NAMES OR CUSTOM", "default", selectedSystemsSorting == "default");
systemsSorting->add("RELEASE YEAR", "year", selectedSystemsSorting == "year");
systemsSorting->add("MANUFACTURER, RELEASE YEAR", "manufacturer_year",
selectedSystemsSorting == "manufacturer_year");
systemsSorting->add("HW TYPE, RELEASE YEAR", "hwtype_year",
selectedSystemsSorting == "hwtype_year");
systemsSorting->add("MANUFACTURER, HW TYPE, REL. YEAR", "manufacturer_hwtype_year",
selectedSystemsSorting == "manufacturer_hwtype_year");
// If there are no objects returned, then there must be a manually modified entry in the
// configuration file. Simply set the systems sorting to "default" in this case.
if (systemsSorting->getSelectedObjects().size() == 0)
systemsSorting->selectEntry(0);
s->addWithLabel("SYSTEMS SORTING", systemsSorting);
s->addSaveFunc([this, systemsSorting, s] {
if (systemsSorting->getSelected() != Settings::getInstance()->getString("SystemsSorting")) {
Settings::getInstance()->setString("SystemsSorting", systemsSorting->getSelected());
s->setNeedsSaving();
s->setNeedsRescanROMDirectory();
}
});
// Default gamelist sort order.
std::string sortOrder;
auto defaultSortOrder = std::make_shared<OptionListComponent<const FileData::SortType*>>(
@ -487,7 +512,7 @@ void GuiMenu::openUIOptions()
else
defaultSortOrder->add(sort.description, &sort, false);
}
s->addWithLabel("DEFAULT SORT ORDER", defaultSortOrder);
s->addWithLabel("GAMES DEFAULT SORT ORDER", defaultSortOrder);
s->addSaveFunc([defaultSortOrder, sortOrder, s] {
std::string selectedSortOrder {defaultSortOrder.get()->getSelected()->description};
if (selectedSortOrder != sortOrder) {
@ -514,9 +539,9 @@ void GuiMenu::openUIOptions()
if (menuColorScheme->getSelected() !=
Settings::getInstance()->getString("MenuColorScheme")) {
Settings::getInstance()->setString("MenuColorScheme", menuColorScheme->getSelected());
s->setNeedsSaving();
ViewController::getInstance()->setMenuColors();
GuiMenu::close(false);
s->setNeedsSaving();
s->setNeedsCloseAllWindows();
}
});
@ -1542,7 +1567,7 @@ void GuiMenu::openOtherOptions()
if (showQuitMenu->getState() != Settings::getInstance()->getBool("ShowQuitMenu")) {
Settings::getInstance()->setBool("ShowQuitMenu", showQuitMenu->getState());
s->setNeedsSaving();
GuiMenu::close(false);
s->setNeedsCloseAllWindows();
}
});
#endif

View file

@ -164,6 +164,7 @@ void Settings::setDefaults()
mStringMap["ThemeTransitions"] = {"automatic", "automatic"};
mStringMap["QuickSystemSelect"] = {"leftrightshoulders", "leftrightshoulders"};
mStringMap["StartupSystem"] = {"", ""};
mStringMap["SystemsSorting"] = {"default", "default"};
mStringMap["DefaultSortOrder"] = {"name, ascending", "name, ascending"};
mStringMap["MenuColorScheme"] = {"dark", "dark"};
mStringMap["MenuOpeningEffect"] = {"scale-up", "scale-up"};