Added a prompt when you try to close GuiMetaDataEd with unsaved changes.

This commit is contained in:
Aloshi 2014-05-14 20:05:34 -05:00
parent f8355ef8b3
commit b8ebbc84bb
3 changed files with 43 additions and 16 deletions

View file

@ -3,19 +3,19 @@
#include "Log.h" #include "Log.h"
MetaDataDecl gameDecls[] = { MetaDataDecl gameDecls[] = {
// key, type, default, statistic, name in GuiMetaDataEd, prompt in GuiMetaDataEd // key, type, default, statistic, name in GuiMetaDataEd, prompt in GuiMetaDataEd
{"name", MD_STRING, "", false, "name", "enter game name"}, {"name", MD_STRING, "", false, "name", "enter game name"},
{"desc", MD_MULTILINE_STRING, "", false, "description", "enter description"}, {"desc", MD_MULTILINE_STRING, "", false, "description", "enter description"},
{"image", MD_IMAGE_PATH, "", false, "image", "enter path to image"}, {"image", MD_IMAGE_PATH, "", false, "image", "enter path to image"},
{"thumbnail", MD_IMAGE_PATH, "", false, "thumbnail", "enter path to thumbnail"}, {"thumbnail", MD_IMAGE_PATH, "", false, "thumbnail", "enter path to thumbnail"},
{"rating", MD_RATING, "0", false, "rating", "enter rating"}, {"rating", MD_RATING, "0", false, "rating", "enter rating"},
{"releasedate", MD_DATE, "0", false, "release date", "enter release date"}, {"releasedate", MD_DATE, "not-a-date-time", false, "release date", "enter release date"},
{"developer", MD_STRING, "unknown", false, "developer", "enter game developer"}, {"developer", MD_STRING, "unknown", false, "developer", "enter game developer"},
{"publisher", MD_STRING, "unknown", false, "publisher", "enter game publisher"}, {"publisher", MD_STRING, "unknown", false, "publisher", "enter game publisher"},
{"genre", MD_STRING, "unknown", false, "genre", "enter game genre"}, {"genre", MD_STRING, "unknown", false, "genre", "enter game genre"},
{"players", MD_INT, "1", false, "players", "enter number of players"}, {"players", MD_INT, "1", false, "players", "enter number of players"},
{"playcount", MD_INT, "0", true, "play count", "enter number of times played"}, {"playcount", MD_INT, "0", true, "play count", "enter number of times played"},
{"lastplayed", MD_TIME, "0", true, "last played", "enter last played date"} {"lastplayed", MD_TIME, "0", true, "last played", "enter last played date"}
}; };
const std::vector<MetaDataDecl> gameMDD(gameDecls, gameDecls + sizeof(gameDecls) / sizeof(gameDecls[0])); const std::vector<MetaDataDecl> gameMDD(gameDecls, gameDecls + sizeof(gameDecls) / sizeof(gameDecls[0]));

View file

@ -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) bool GuiMetaDataEd::input(InputConfig* config, Input input)
{ {
if(GuiComponent::input(config, input)) if(GuiComponent::input(config, input))
return true; 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; return true;
} }
@ -213,7 +239,7 @@ bool GuiMetaDataEd::input(InputConfig* config, Input input)
std::vector<HelpPrompt> GuiMetaDataEd::getHelpPrompts() std::vector<HelpPrompt> GuiMetaDataEd::getHelpPrompts()
{ {
std::vector<HelpPrompt> prompts = mGrid.getHelpPrompts(); std::vector<HelpPrompt> prompts = mGrid.getHelpPrompts();
prompts.push_back(HelpPrompt("b", "discard")); prompts.push_back(HelpPrompt("b", "close"));
prompts.push_back(HelpPrompt("start", "close")); prompts.push_back(HelpPrompt("start", "close"));
return prompts; return prompts;
} }

View file

@ -21,6 +21,7 @@ private:
void save(); void save();
void fetch(); void fetch();
void fetchDone(const ScraperSearchResult& result); void fetchDone(const ScraperSearchResult& result);
void close();
NinePatchComponent mBackground; NinePatchComponent mBackground;
ComponentGrid mGrid; ComponentGrid mGrid;