Changed the handling of blank game name entries in the metadata editor.

This commit is contained in:
Leon Styhre 2020-08-02 11:45:59 +02:00
parent 99b1acfb9f
commit 3f8e5a001b
2 changed files with 24 additions and 21 deletions

View file

@ -70,7 +70,9 @@ GuiMetaDataEd::GuiMetaDataEd(
// Populate list.
for (auto iter = mdd.cbegin(); iter != mdd.cend(); iter++) {
std::shared_ptr<GuiComponent> 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

View file

@ -160,8 +160,7 @@ void TextListComponent<T>::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;