From 3f8e5a001bd2f9d00d620aded33a46de88b102f4 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 2 Aug 2020 11:45:59 +0200 Subject: [PATCH] Changed the handling of blank game name entries in the metadata editor. --- es-app/src/guis/GuiMetaDataEd.cpp | 42 ++++++++++++---------- es-core/src/components/TextListComponent.h | 3 +- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/es-app/src/guis/GuiMetaDataEd.cpp b/es-app/src/guis/GuiMetaDataEd.cpp index 1dc12bbb2..621c32132 100644 --- a/es-app/src/guis/GuiMetaDataEd.cpp +++ b/es-app/src/guis/GuiMetaDataEd.cpp @@ -70,7 +70,9 @@ GuiMetaDataEd::GuiMetaDataEd( // Populate list. for (auto iter = mdd.cbegin(); iter != mdd.cend(); iter++) { std::shared_ptr ed; - std::string originalValue; + std::string currentKey = iter->key; + std::string originalValue = mMetaData->get(iter->key); + std::string gamePath; // Don't add statistics. if (iter->isStatistic) @@ -159,8 +161,6 @@ GuiMetaDataEd::GuiMetaDataEd( bool multiLine = false; const std::string title = iter->displayPrompt; - originalValue = mMetaData->get(iter->key); - // OK callback (apply new value to ed). auto updateVal = [ed, originalValue](const std::string& newVal) { ed->setValue(newVal); @@ -201,15 +201,27 @@ GuiMetaDataEd::GuiMetaDataEd( bool multiLine = iter->type == MD_MULTILINE_STRING; const std::string title = iter->displayPrompt; - originalValue = mMetaData->get(iter->key); + gamePath = Utils::FileSystem::getStem(mScraperParams.game->getPath()); // OK callback (apply new value to ed). - auto updateVal = [ed, originalValue](const std::string& newVal) { - ed->setValue(newVal); - if (newVal == originalValue) - ed->setColor(DEFAULT_TEXTCOLOR); - else - ed->setColor(TEXTCOLOR_USERMARKED); + auto updateVal = [ed, currentKey, originalValue, gamePath] + (const std::string& newVal) { + // If the user has entered a blank game name, then set the name to the ROM + // filename (minus the extension). + if (currentKey == "name" && newVal == "") { + ed->setValue(gamePath); + if (gamePath == originalValue) + ed->setColor(DEFAULT_TEXTCOLOR); + else + ed->setColor(TEXTCOLOR_USERMARKED); + } + else { + ed->setValue(newVal); + if (newVal == originalValue) + ed->setColor(DEFAULT_TEXTCOLOR); + else + ed->setColor(TEXTCOLOR_USERMARKED); + } }; row.makeAcceptInputHandler([this, title, ed, updateVal, multiLine] { @@ -342,15 +354,7 @@ void GuiMetaDataEd::save() mEditors.at(i)->getValue() != mMetaData->get("hidden")) hideGameWhileHidden = true; - // If the user has entered a blank game name, then set the name to the ROM - // filename (minus the extension). - if (mMetaDataDecl.at(i).key == "name" && mEditors.at(i)->getValue() == "") { - mMetaData->set(mMetaDataDecl.at(i).key, - Utils::FileSystem::getStem(mScraperParams.game->getPath())); - } - else { - mMetaData->set(mMetaDataDecl.at(i).key, mEditors.at(i)->getValue()); - } + mMetaData->set(mMetaDataDecl.at(i).key, mEditors.at(i)->getValue()); } // If hidden games are not shown and the hide flag was set for the game, then write the diff --git a/es-core/src/components/TextListComponent.h b/es-core/src/components/TextListComponent.h index 52f666ecc..667eb531a 100644 --- a/es-core/src/components/TextListComponent.h +++ b/es-core/src/components/TextListComponent.h @@ -160,8 +160,7 @@ void TextListComponent::render(const Transform4x4f& parentTrans) // Number of entries that can fit on the screen simultaniously. int screenCount = (int)(mSize.y() / entrySize + 0.5f); - if (size() >= screenCount) - { + if (size() >= screenCount) { startEntry = mCursor - screenCount/2; if (startEntry < 0) startEntry = 0;