Added the ability to set a sortname specifically for custom collections.

This commit is contained in:
Leon Styhre 2022-01-15 11:50:51 +01:00
parent 6ca4d6b96e
commit 65702b6689
5 changed files with 130 additions and 48 deletions

View file

@ -90,6 +90,15 @@ const std::string& FileData::getName()
const std::string& FileData::getSortName() const std::string& FileData::getSortName()
{ {
if (mSystem->isCustomCollection() && mType == GAME) {
if (!metadata.get("collectionsortname").empty())
return metadata.get("collectionsortname");
else if (!metadata.get("sortname").empty())
return metadata.get("sortname");
else
return metadata.get("name");
}
if (metadata.get("sortname").empty()) if (metadata.get("sortname").empty())
return metadata.get("name"); return metadata.get("name");
else else

View file

@ -9,6 +9,7 @@
#include "FileSorts.h" #include "FileSorts.h"
#include "SystemData.h"
#include "utils/StringUtil.h" #include "utils/StringUtil.h"
#include <algorithm> #include <algorithm>
@ -55,8 +56,28 @@ namespace FileSorts
{ {
// We compare the actual metadata name, as collection files have the system // We compare the actual metadata name, as collection files have the system
// appended which messes up the order. // appended which messes up the order.
std::string name1 = Utils::String::toUpper(file1->metadata.get("sortname")); std::string name1;
std::string name2 = Utils::String::toUpper(file2->metadata.get("sortname")); std::string name2;
if (file1->getSystem()->isCustomCollection()) {
if (Utils::String::toUpper(file1->metadata.get("collectionsortname")) != "")
name1 = Utils::String::toUpper(file1->metadata.get("collectionsortname"));
else if (Utils::String::toUpper(file1->metadata.get("sortname")) != "")
name1 = Utils::String::toUpper(file1->metadata.get("sortname"));
else
name1 = Utils::String::toUpper(file1->metadata.get("name"));
if (Utils::String::toUpper(file2->metadata.get("collectionsortname")) != "")
name2 = Utils::String::toUpper(file2->metadata.get("collectionsortname"));
else if (Utils::String::toUpper(file2->metadata.get("sortname")) != "")
name2 = Utils::String::toUpper(file2->metadata.get("sortname"));
else
name2 = Utils::String::toUpper(file2->metadata.get("name"));
return name1.compare(name2) < 0;
}
name1 = Utils::String::toUpper(file1->metadata.get("sortname"));
name2 = Utils::String::toUpper(file2->metadata.get("sortname"));
if (name1.empty()) if (name1.empty())
name1 = Utils::String::toUpper(file1->metadata.get("name")); name1 = Utils::String::toUpper(file1->metadata.get("name"));
if (name2.empty()) if (name2.empty())
@ -66,8 +87,28 @@ namespace FileSorts
bool compareNameDescending(const FileData* file1, const FileData* file2) bool compareNameDescending(const FileData* file1, const FileData* file2)
{ {
std::string name1 = Utils::String::toUpper(file1->metadata.get("sortname")); std::string name1;
std::string name2 = Utils::String::toUpper(file2->metadata.get("sortname")); std::string name2;
if (file1->getSystem()->isCustomCollection()) {
if (Utils::String::toUpper(file1->metadata.get("collectionsortname")) != "")
name1 = Utils::String::toUpper(file1->metadata.get("collectionsortname"));
else if (Utils::String::toUpper(file1->metadata.get("sortname")) != "")
name1 = Utils::String::toUpper(file1->metadata.get("sortname"));
else
name1 = Utils::String::toUpper(file1->metadata.get("name"));
if (Utils::String::toUpper(file2->metadata.get("collectionsortname")) != "")
name2 = Utils::String::toUpper(file2->metadata.get("collectionsortname"));
else if (Utils::String::toUpper(file2->metadata.get("sortname")) != "")
name2 = Utils::String::toUpper(file2->metadata.get("sortname"));
else
name2 = Utils::String::toUpper(file2->metadata.get("name"));
return name1.compare(name2) > 0;
}
name1 = Utils::String::toUpper(file1->metadata.get("sortname"));
name2 = Utils::String::toUpper(file2->metadata.get("sortname"));
if (name1.empty()) if (name1.empty())
name1 = Utils::String::toUpper(file1->metadata.get("name")); name1 = Utils::String::toUpper(file1->metadata.get("name"));
if (name2.empty()) if (name2.empty())

View file

@ -23,6 +23,7 @@ namespace
// key, type, default, statistic, name in GuiMetaDataEd, prompt in GuiMetaDataEd, shouldScrape // key, type, default, statistic, name in GuiMetaDataEd, prompt in GuiMetaDataEd, shouldScrape
{"name", MD_STRING, "", false, "name", "enter name", true}, {"name", MD_STRING, "", false, "name", "enter name", true},
{"sortname", MD_STRING, "", false, "sortname", "enter sortname", false}, {"sortname", MD_STRING, "", false, "sortname", "enter sortname", false},
{"collectionsortname", MD_STRING, "", false, "custom collections sortname", "enter collections sortname", false},
{"desc", MD_MULTILINE_STRING, "", false, "description", "enter description", true}, {"desc", MD_MULTILINE_STRING, "", false, "description", "enter description", true},
{"rating", MD_RATING, "0", false, "rating", "enter rating", true}, {"rating", MD_RATING, "0", false, "rating", "enter rating", true},
{"releasedate", MD_DATE, "19700101T000000", false, "release date", "enter release date", true}, {"releasedate", MD_DATE, "19700101T000000", false, "release date", "enter release date", true},

View file

@ -45,16 +45,21 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window,
, mBackground{window, ":/graphics/frame.svg"} , mBackground{window, ":/graphics/frame.svg"}
, mGrid{window, glm::ivec2{2, 6}} , mGrid{window, glm::ivec2{2, 6}}
, mScraperParams{scraperParams} , mScraperParams{scraperParams}
, mControllerBadges{BadgeComponent::getGameControllers()}
, mMetaDataDecl{mdd} , mMetaDataDecl{mdd}
, mMetaData{md} , mMetaData{md}
, mSavedCallback{saveCallback} , mSavedCallback{saveCallback}
, mClearGameFunc{clearGameFunc} , mClearGameFunc{clearGameFunc}
, mDeleteGameFunc{deleteGameFunc} , mDeleteGameFunc{deleteGameFunc}
, mIsCustomCollection{false}
, mMediaFilesUpdated{false} , mMediaFilesUpdated{false}
, mSavedMediaAndAborted{false} , mSavedMediaAndAborted{false}
, mInvalidEmulatorEntry{false} , mInvalidEmulatorEntry{false}
{ {
mControllerBadges = BadgeComponent::getGameControllers(); if (ViewController::getInstance()->getState().getSystem()->isCustomCollection() ||
ViewController::getInstance()->getState().getSystem()->getThemeFolder() ==
"custom-collections")
mIsCustomCollection = true;
// Remove the last "unknown" controller entry. // Remove the last "unknown" controller entry.
if (mControllerBadges.size() > 1) if (mControllerBadges.size() > 1)
@ -115,6 +120,11 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window,
std::string originalValue = mMetaData->get(it->key); std::string originalValue = mMetaData->get(it->key);
std::string gamePath; std::string gamePath;
// Only display the custom collections sortname entry if we're editing the game
// from within a custom collection.
if (currentKey == "collectionsortname" && !mIsCustomCollection)
continue;
// Don't add statistics. // Don't add statistics.
if (it->isStatistic) if (it->isStatistic)
continue; continue;
@ -619,36 +629,45 @@ void GuiMetaDataEd::save()
// We need this to handle the special situation where the user sets a game to hidden while // We need this to handle the special situation where the user sets a game to hidden while
// ShowHiddenGames is set to false, meaning it will immediately disappear from the gamelist. // ShowHiddenGames is set to false, meaning it will immediately disappear from the gamelist.
bool showHiddenGames = Settings::getInstance()->getBool("ShowHiddenGames"); bool showHiddenGames{Settings::getInstance()->getBool("ShowHiddenGames")};
bool hideGameWhileHidden = false; bool hideGameWhileHidden{false};
bool setGameAsCounted = false; bool setGameAsCounted{false};
int offset{0};
for (unsigned int i = 0; i < mEditors.size(); ++i) { for (unsigned int i = 0; i < mEditors.size(); ++i) {
if (mMetaDataDecl.at(i).isStatistic) // The offset is needed to make the editor and metadata fields match up if we're
continue; // skipping the custom collections sortname field (which we do if not editing the
// game from within a custom collection gamelist).
if (mMetaDataDecl.at(i).key == "altemulator" && mInvalidEmulatorEntry == true) if (mMetaDataDecl.at(i).key == "collectionsortname" && !mIsCustomCollection) {
continue; offset = 1;
if (mMetaDataDecl.at(i).key == "controller" && mEditors.at(i)->getValue() != "") {
std::string shortName = BadgeComponent::getShortName(mEditors.at(i)->getValue());
if (shortName != "unknown")
mMetaData->set(mMetaDataDecl.at(i).key, shortName);
continue; continue;
} }
if (!showHiddenGames && mMetaDataDecl.at(i).key == "hidden" && if (mMetaDataDecl.at(i + offset).isStatistic)
continue;
if (mMetaDataDecl.at(i + offset).key == "altemulator" && mInvalidEmulatorEntry == true)
continue;
if (mMetaDataDecl.at(i + offset).key == "controller" && mEditors.at(i)->getValue() != "") {
std::string shortName = BadgeComponent::getShortName(mEditors.at(i)->getValue());
if (shortName != "unknown")
mMetaData->set(mMetaDataDecl.at(i + offset).key, shortName);
continue;
}
if (!showHiddenGames && mMetaDataDecl.at(i + offset).key == "hidden" &&
mEditors.at(i)->getValue() != mMetaData->get("hidden")) mEditors.at(i)->getValue() != mMetaData->get("hidden"))
hideGameWhileHidden = true; hideGameWhileHidden = true;
// Check whether the flag to count the entry as a game was set to enabled. // Check whether the flag to count the entry as a game was set to enabled.
if (mMetaDataDecl.at(i).key == "nogamecount" && if (mMetaDataDecl.at(i + offset).key == "nogamecount" &&
mEditors.at(i)->getValue() != mMetaData->get("nogamecount") && mEditors.at(i)->getValue() != mMetaData->get("nogamecount") &&
mMetaData->get("nogamecount") == "true") { mMetaData->get("nogamecount") == "true") {
setGameAsCounted = true; setGameAsCounted = true;
} }
mMetaData->set(mMetaDataDecl.at(i).key, mEditors.at(i)->getValue()); mMetaData->set(mMetaDataDecl.at(i + offset).key, mEditors.at(i)->getValue());
} }
// If hidden games are not shown and the hide flag was set for the entry, then write the // If hidden games are not shown and the hide flag was set for the entry, then write the
@ -780,16 +799,27 @@ void GuiMetaDataEd::fetchDone(const ScraperSearchResult& result)
void GuiMetaDataEd::close() void GuiMetaDataEd::close()
{ {
// Find out if the user made any changes. // Find out if the user made any changes.
bool metadataUpdated = false; bool metadataUpdated{false};
int offset{0};
for (unsigned int i = 0; i < mEditors.size(); ++i) { for (unsigned int i = 0; i < mEditors.size(); ++i) {
const std::string& key = mMetaDataDecl.at(i).key; const std::string& key{mMetaDataDecl.at(i + offset).key};
std::string mMetaDataValue = mMetaData->get(key); // The offset is needed to make the editor and metadata fields match up if we're
std::string mEditorsValue = mEditors.at(i)->getValue(); // skipping the custom collections sortname field (which we do if not editing the
// game from within a custom collection gamelist).
if (key == "collectionsortname" && !mIsCustomCollection) {
offset = 1;
++i;
continue;
}
if (key == "altemulator" && mInvalidEmulatorEntry == true) if (key == "altemulator" && mInvalidEmulatorEntry == true)
continue; continue;
if (mMetaDataDecl.at(i).key == "controller" && mEditors.at(i)->getValue() != "") { std::string mMetaDataValue{mMetaData->get(key)};
std::string mEditorsValue{mEditors.at(i)->getValue()};
if (key == "controller" && mEditors.at(i)->getValue() != "") {
std::string shortName = BadgeComponent::getShortName(mEditors.at(i)->getValue()); std::string shortName = BadgeComponent::getShortName(mEditors.at(i)->getValue());
if (shortName == "unknown" || mMetaDataValue == shortName) if (shortName == "unknown" || mMetaDataValue == shortName)
continue; continue;

View file

@ -69,6 +69,7 @@ private:
std::function<void()> mClearGameFunc; std::function<void()> mClearGameFunc;
std::function<void()> mDeleteGameFunc; std::function<void()> mDeleteGameFunc;
bool mIsCustomCollection;
bool mMediaFilesUpdated; bool mMediaFilesUpdated;
bool mSavedMediaAndAborted; bool mSavedMediaAndAborted;
bool mInvalidEmulatorEntry; bool mInvalidEmulatorEntry;