Improvements to the date and time handling.

This commit is contained in:
Leon Styhre 2020-08-02 15:56:32 +02:00
parent 3923ad32c6
commit 3ae0726d1a
6 changed files with 18 additions and 16 deletions

View file

@ -17,7 +17,7 @@ MetaDataDecl gameDecls[] = {
{"sortname", MD_STRING, "", false, "sortname", "enter game sort name", false},
{"desc", MD_MULTILINE_STRING, "", false, "description", "enter description", true},
{"rating", MD_RATING, "0", false, "rating", "enter rating", true},
{"releasedate", MD_DATE, "not-a-date-time", false, "release date", "enter release date", true},
{"releasedate", MD_DATE, "19700101T010000", false, "release date", "enter release date", true},
{"developer", MD_STRING, "unknown", false, "developer", "enter game developer", true},
{"publisher", MD_STRING, "unknown", false, "publisher", "enter game publisher", true},
{"genre", MD_STRING, "unknown", false, "genre", "enter game genre", true},
@ -41,7 +41,7 @@ MetaDataDecl folderDecls[] = {
{"name", MD_STRING, "", false, "name", "enter game name", true},
{"desc", MD_MULTILINE_STRING, "", false, "description", "enter description", true},
{"rating", MD_RATING, "0", false, "rating", "enter rating", true},
{"releasedate", MD_DATE, "not-a-date-time", false, "release date", "enter release date", true},
{"releasedate", MD_DATE, "19700101T010000", false, "release date", "enter release date", true},
{"developer", MD_STRING, "unknown", false, "developer", "enter game developer", true},
{"publisher", MD_STRING, "unknown", false, "publisher", "enter game publisher", true},
{"genre", MD_STRING, "unknown", false, "genre", "enter game genre", true},

View file

@ -128,6 +128,7 @@ GuiMetaDataEd::GuiMetaDataEd(
row.addElement(spacer, false);
ed = std::make_shared<DateTimeEditComponent>(window);
ed->setOriginalColor(DEFAULT_TEXTCOLOR);
ed->setChangedColor(TEXTCOLOR_USERMARKED);
row.addElement(ed, false);
@ -430,11 +431,6 @@ void GuiMetaDataEd::close()
std::string mMetaDataValue = mMetaData->get(key);
std::string mEditorsValue = mEditors.at(i)->getValue();
// Incredibly ugly workaround to avoid the "SAVE CHANGES?" window for games
// with missing release date metadata.
if (key == "releasedate" && (mMetaDataValue == "" || mMetaDataValue == "not-a-date-time"))
mMetaDataValue = "19700101T010000";
if (mMetaDataValue != mEditorsValue) {
metadataUpdated = true;
break;

View file

@ -73,6 +73,7 @@ GuiScraperSearch::GuiScraperSearch(
mMD_Rating = std::make_shared<RatingComponent>(mWindow);
mMD_ReleaseDate = std::make_shared<DateTimeEditComponent>(mWindow);
mMD_ReleaseDate->setColor(mdColor);
mMD_ReleaseDate->setUppercase(true);
mMD_Developer = std::make_shared<TextComponent>(mWindow, "", font, mdColor);
mMD_Publisher = std::make_shared<TextComponent>(mWindow, "", font, mdColor);
mMD_Genre = std::make_shared<TextComponent>(mWindow, "", font, mdColor);

View file

@ -40,12 +40,18 @@ bool DateTimeEditComponent::input(InputConfig* config, Input input)
if (mDisplayMode != DISP_RELATIVE_TO_NOW) // Don't allow editing for relative times.
mEditing = !mEditing;
// Change the color of the text to reflect the changes.
if (mTime == mOriginalValue)
setColor(mColorOriginalValue);
else
setColor(mColorChangedValue);
if (mEditing) {
// Started editing.
mTimeBeforeEdit = mTime;
// Initialize to now if unset.
if (mTime.getTime() == Utils::Time::NOT_A_DATE_TIME) {
if (mTime.getTime() == Utils::Time::DEFAULT_TIMEVALUE) {
mTime = Utils::Time::now();
updateTextCache();
}
@ -55,6 +61,11 @@ bool DateTimeEditComponent::input(InputConfig* config, Input input)
}
if (mEditing) {
if (config->isMappedLike("lefttrigger", input) ||
config->isMappedLike("righttrigger", input))
return true;
if (config->isMappedTo("b", input)) {
mEditing = false;
mTime = mTimeBeforeEdit;
@ -107,12 +118,6 @@ bool DateTimeEditComponent::input(InputConfig* config, Input input)
mTime = new_tm;
// Change the color of the text to reflect the changes.
if (mTime == mOriginalValue)
setColor(mColorOriginalValue);
else
setColor(mColorChangedValue);
updateTextCache();
return true;
}

View file

@ -83,7 +83,7 @@ namespace Utils
tm timeStruct = { 0, 0, 0, 1, 0, 0, 0, 0, -1 };
size_t parsedChars = 0;
if (_string == "not-a-date-time")
if (_string == "19700101T010000")
return mktime(&timeStruct);
while (*f && (parsedChars < _string.length())) {

View file

@ -15,7 +15,7 @@ namespace Utils
{
namespace Time
{
static int NOT_A_DATE_TIME = 0;
static int DEFAULT_TIMEVALUE = 0;
class DateTime
{