From 3ae0726d1a2f67d53a8fbbd8b31d0d2f2cec83c0 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 2 Aug 2020 15:56:32 +0200 Subject: [PATCH] Improvements to the date and time handling. --- es-app/src/MetaData.cpp | 4 ++-- es-app/src/guis/GuiMetaDataEd.cpp | 6 +----- es-app/src/guis/GuiScraperSearch.cpp | 1 + .../src/components/DateTimeEditComponent.cpp | 19 ++++++++++++------- es-core/src/utils/TimeUtil.cpp | 2 +- es-core/src/utils/TimeUtil.h | 2 +- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/es-app/src/MetaData.cpp b/es-app/src/MetaData.cpp index 59b819f30..ab8083d6c 100644 --- a/es-app/src/MetaData.cpp +++ b/es-app/src/MetaData.cpp @@ -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}, diff --git a/es-app/src/guis/GuiMetaDataEd.cpp b/es-app/src/guis/GuiMetaDataEd.cpp index 621c32132..5c1e26cbb 100644 --- a/es-app/src/guis/GuiMetaDataEd.cpp +++ b/es-app/src/guis/GuiMetaDataEd.cpp @@ -128,6 +128,7 @@ GuiMetaDataEd::GuiMetaDataEd( row.addElement(spacer, false); ed = std::make_shared(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; diff --git a/es-app/src/guis/GuiScraperSearch.cpp b/es-app/src/guis/GuiScraperSearch.cpp index 598c22693..2db510dc1 100644 --- a/es-app/src/guis/GuiScraperSearch.cpp +++ b/es-app/src/guis/GuiScraperSearch.cpp @@ -73,6 +73,7 @@ GuiScraperSearch::GuiScraperSearch( mMD_Rating = std::make_shared(mWindow); mMD_ReleaseDate = std::make_shared(mWindow); mMD_ReleaseDate->setColor(mdColor); + mMD_ReleaseDate->setUppercase(true); mMD_Developer = std::make_shared(mWindow, "", font, mdColor); mMD_Publisher = std::make_shared(mWindow, "", font, mdColor); mMD_Genre = std::make_shared(mWindow, "", font, mdColor); diff --git a/es-core/src/components/DateTimeEditComponent.cpp b/es-core/src/components/DateTimeEditComponent.cpp index d162bdd07..5b3d9c9c4 100644 --- a/es-core/src/components/DateTimeEditComponent.cpp +++ b/es-core/src/components/DateTimeEditComponent.cpp @@ -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; } diff --git a/es-core/src/utils/TimeUtil.cpp b/es-core/src/utils/TimeUtil.cpp index 3a371aaaf..af6a5dab3 100644 --- a/es-core/src/utils/TimeUtil.cpp +++ b/es-core/src/utils/TimeUtil.cpp @@ -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())) { diff --git a/es-core/src/utils/TimeUtil.h b/es-core/src/utils/TimeUtil.h index 882b875f7..d2160a867 100644 --- a/es-core/src/utils/TimeUtil.h +++ b/es-core/src/utils/TimeUtil.h @@ -15,7 +15,7 @@ namespace Utils { namespace Time { - static int NOT_A_DATE_TIME = 0; + static int DEFAULT_TIMEVALUE = 0; class DateTime {