diff --git a/src/MetaData.cpp b/src/MetaData.cpp index 6b742af12..f812b7be9 100644 --- a/src/MetaData.cpp +++ b/src/MetaData.cpp @@ -3,19 +3,19 @@ #include "Log.h" MetaDataDecl gameDecls[] = { - // key, type, default, statistic, name in GuiMetaDataEd, prompt in GuiMetaDataEd - {"name", MD_STRING, "", false, "name", "enter game name"}, - {"desc", MD_MULTILINE_STRING, "", false, "description", "enter description"}, - {"image", MD_IMAGE_PATH, "", false, "image", "enter path to image"}, - {"thumbnail", MD_IMAGE_PATH, "", false, "thumbnail", "enter path to thumbnail"}, - {"rating", MD_RATING, "0", false, "rating", "enter rating"}, - {"releasedate", MD_DATE, "0", false, "release date", "enter release date"}, - {"developer", MD_STRING, "unknown", false, "developer", "enter game developer"}, - {"publisher", MD_STRING, "unknown", false, "publisher", "enter game publisher"}, - {"genre", MD_STRING, "unknown", false, "genre", "enter game genre"}, - {"players", MD_INT, "1", false, "players", "enter number of players"}, - {"playcount", MD_INT, "0", true, "play count", "enter number of times played"}, - {"lastplayed", MD_TIME, "0", true, "last played", "enter last played date"} + // key, type, default, statistic, name in GuiMetaDataEd, prompt in GuiMetaDataEd + {"name", MD_STRING, "", false, "name", "enter game name"}, + {"desc", MD_MULTILINE_STRING, "", false, "description", "enter description"}, + {"image", MD_IMAGE_PATH, "", false, "image", "enter path to image"}, + {"thumbnail", MD_IMAGE_PATH, "", false, "thumbnail", "enter path to thumbnail"}, + {"rating", MD_RATING, "0", false, "rating", "enter rating"}, + {"releasedate", MD_DATE, "not-a-date-time", false, "release date", "enter release date"}, + {"developer", MD_STRING, "unknown", false, "developer", "enter game developer"}, + {"publisher", MD_STRING, "unknown", false, "publisher", "enter game publisher"}, + {"genre", MD_STRING, "unknown", false, "genre", "enter game genre"}, + {"players", MD_INT, "1", false, "players", "enter number of players"}, + {"playcount", MD_INT, "0", true, "play count", "enter number of times played"}, + {"lastplayed", MD_TIME, "0", true, "last played", "enter last played date"} }; const std::vector gameMDD(gameDecls, gameDecls + sizeof(gameDecls) / sizeof(gameDecls[0])); diff --git a/src/guis/GuiMetaDataEd.cpp b/src/guis/GuiMetaDataEd.cpp index 36d2d3c28..1fe748b3b 100644 --- a/src/guis/GuiMetaDataEd.cpp +++ b/src/guis/GuiMetaDataEd.cpp @@ -195,15 +195,41 @@ void GuiMetaDataEd::fetchDone(const ScraperSearchResult& result) } } +void GuiMetaDataEd::close() +{ + // find out if the user made any changes + bool dirty = false; + for(unsigned int i = 0; i < mEditors.size(); i++) + { + const std::string& key = mMetaDataDecl.at(i).key; + if(mMetaData->get(key) != mEditors.at(i)->getValue()) + { + dirty = true; + break; + } + } + + if(dirty) + { + // changes were made, ask if the user wants to save them + mWindow->pushGui(new GuiMsgBox(mWindow, + "SAVE CHANGES?", + "YES", [&] { save(); delete this; }, + "NO", [&] { delete this; } + )); + }else{ + delete this; + } +} bool GuiMetaDataEd::input(InputConfig* config, Input input) { if(GuiComponent::input(config, input)) return true; - if(input.value != 0 && config->isMappedTo("b", input)) + if(input.value != 0 && (config->isMappedTo("b", input) || config->isMappedTo("start", input))) { - delete this; + close(); return true; } @@ -213,7 +239,7 @@ bool GuiMetaDataEd::input(InputConfig* config, Input input) std::vector GuiMetaDataEd::getHelpPrompts() { std::vector prompts = mGrid.getHelpPrompts(); - prompts.push_back(HelpPrompt("b", "discard")); + prompts.push_back(HelpPrompt("b", "close")); prompts.push_back(HelpPrompt("start", "close")); return prompts; } diff --git a/src/guis/GuiMetaDataEd.h b/src/guis/GuiMetaDataEd.h index 3b86772ab..ee1aca5c7 100644 --- a/src/guis/GuiMetaDataEd.h +++ b/src/guis/GuiMetaDataEd.h @@ -21,6 +21,7 @@ private: void save(); void fetch(); void fetchDone(const ScraperSearchResult& result); + void close(); NinePatchComponent mBackground; ComponentGrid mGrid;