From 30ca0497aa6e772121c4921a2e9c42fd8b403da1 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sat, 1 Jul 2023 15:57:29 +0200 Subject: [PATCH] Added options to the video and slideshow screensavers to only include favorite games --- es-app/src/Screensaver.cpp | 18 ++++++++++++++- es-app/src/guis/GuiScreensaverOptions.cpp | 28 +++++++++++++++++++++++ es-core/src/Settings.cpp | 2 ++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/es-app/src/Screensaver.cpp b/es-app/src/Screensaver.cpp index fe7c77ed8..cc065902f 100644 --- a/es-app/src/Screensaver.cpp +++ b/es-app/src/Screensaver.cpp @@ -433,6 +433,9 @@ void Screensaver::update(int deltaTime) void Screensaver::generateImageList() { + const bool favoritesOnly { + Settings::getInstance()->getBool("ScreensaverSlideshowOnlyFavorites")}; + for (auto it = SystemData::sSystemVector.cbegin(); // Line break. it != SystemData::sSystemVector.cend(); ++it) { // We only want nodes from game systems that are not collections. @@ -445,6 +448,8 @@ void Screensaver::generateImageList() if (UIModeController::getInstance()->isUIModeKid() && (*it2)->metadata.get("kidgame") != "true") continue; + if (favoritesOnly && (*it2)->metadata.get("favorite") != "true") + continue; std::string imagePath {(*it2)->getImagePath()}; if (imagePath != "") mImageFiles.push_back((*it2)); @@ -454,6 +459,8 @@ void Screensaver::generateImageList() void Screensaver::generateVideoList() { + const bool favoritesOnly {Settings::getInstance()->getBool("ScreensaverVideoOnlyFavorites")}; + for (auto it = SystemData::sSystemVector.cbegin(); // Line break. it != SystemData::sSystemVector.cend(); ++it) { // We only want nodes from game systems that are not collections. @@ -466,6 +473,8 @@ void Screensaver::generateVideoList() if (UIModeController::getInstance()->isUIModeKid() && (*it2)->metadata.get("kidgame") != "true") continue; + if (favoritesOnly && (*it2)->metadata.get("favorite") != "true") + continue; std::string videoPath {(*it2)->getVideoPath()}; if (videoPath != "") mVideoFiles.push_back((*it2)); @@ -604,8 +613,15 @@ void Screensaver::generateOverlayInfo() float posX {mRenderer->getScreenWidth() * 0.023f}; float posY {mRenderer->getScreenHeight() * 0.02f}; + const bool favoritesOnly { + (mScreensaverType == "video" && + Settings::getInstance()->getBool("ScreensaverVideoOnlyFavorites")) || + (mScreensaverType == "slideshow" && + Settings::getInstance()->getBool("ScreensaverSlideshowOnlyFavorites"))}; + std::string favoriteChar; - if (mCurrentGame && mCurrentGame->getFavorite()) + // Don't add the favorites character if only displaying favorite games. + if (!favoritesOnly && mCurrentGame && mCurrentGame->getFavorite()) favoriteChar.append(" ").append(ViewController::FAVORITE_CHAR); const std::string gameName {Utils::String::toUpper(mGameName) + favoriteChar}; diff --git a/es-app/src/guis/GuiScreensaverOptions.cpp b/es-app/src/guis/GuiScreensaverOptions.cpp index 5820b53d8..7a7c08298 100644 --- a/es-app/src/guis/GuiScreensaverOptions.cpp +++ b/es-app/src/guis/GuiScreensaverOptions.cpp @@ -121,6 +121,20 @@ void GuiScreensaverOptions::openSlideshowScreensaverOptions() } }); + // Only include favorite games. + auto screensaverSlideshowOnlyFavorites = std::make_shared(); + screensaverSlideshowOnlyFavorites->setState( + Settings::getInstance()->getBool("ScreensaverSlideshowOnlyFavorites")); + s->addWithLabel("ONLY INCLUDE FAVORITE GAMES", screensaverSlideshowOnlyFavorites); + s->addSaveFunc([screensaverSlideshowOnlyFavorites, s] { + if (screensaverSlideshowOnlyFavorites->getState() != + Settings::getInstance()->getBool("ScreensaverSlideshowOnlyFavorites")) { + Settings::getInstance()->setBool("ScreensaverSlideshowOnlyFavorites", + screensaverSlideshowOnlyFavorites->getState()); + s->setNeedsSaving(); + } + }); + // Stretch images to screen resolution. auto screensaverStretchImages = std::make_shared(); screensaverStretchImages->setState( @@ -231,6 +245,20 @@ void GuiScreensaverOptions::openVideoScreensaverOptions() } }); + // Only include favorite games. + auto screensaverVideoOnlyFavorites = std::make_shared(); + screensaverVideoOnlyFavorites->setState( + Settings::getInstance()->getBool("ScreensaverVideoOnlyFavorites")); + s->addWithLabel("ONLY INCLUDE FAVORITE GAMES", screensaverVideoOnlyFavorites); + s->addSaveFunc([screensaverVideoOnlyFavorites, s] { + if (screensaverVideoOnlyFavorites->getState() != + Settings::getInstance()->getBool("ScreensaverVideoOnlyFavorites")) { + Settings::getInstance()->setBool("ScreensaverVideoOnlyFavorites", + screensaverVideoOnlyFavorites->getState()); + s->setNeedsSaving(); + } + }); + // Stretch videos to screen resolution. auto screensaverStretchVideos = std::make_shared(); screensaverStretchVideos->setState( diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index f99831b38..546e2d290 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -190,6 +190,7 @@ void Settings::setDefaults() // UI settings -> screensaver settings -> slideshow screensaver settings. mIntMap["ScreensaverSwapImageTimeout"] = {10000, 10000}; + mBoolMap["ScreensaverSlideshowOnlyFavorites"] = {false, false}; mBoolMap["ScreensaverStretchImages"] = {false, false}; mBoolMap["ScreensaverSlideshowGameInfo"] = {true, true}; mBoolMap["ScreensaverSlideshowScanlines"] = {true, true}; @@ -200,6 +201,7 @@ void Settings::setDefaults() // UI settings -> screensaver settings -> video screensaver settings. mIntMap["ScreensaverSwapVideoTimeout"] = {0, 0}; + mBoolMap["ScreensaverVideoOnlyFavorites"] = {false, false}; mBoolMap["ScreensaverStretchVideos"] = {false, false}; mBoolMap["ScreensaverVideoGameInfo"] = {true, true}; #if defined(RASPBERRY_PI)