From ae6c0629848e1f6fa19f393aa38adcb49ed69e20 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Thu, 15 Dec 2022 18:23:48 +0100 Subject: [PATCH] Added gameselectorEntry properties to a number of elements. --- es-app/src/views/SystemView.cpp | 115 +++++++++++------- es-core/src/GuiComponent.cpp | 4 + es-core/src/GuiComponent.h | 4 +- es-core/src/ThemeData.cpp | 5 + .../src/components/GameSelectorComponent.h | 1 + es-core/src/components/IList.h | 6 +- 6 files changed, 85 insertions(+), 50 deletions(-) diff --git a/es-app/src/views/SystemView.cpp b/es-app/src/views/SystemView.cpp index 6f4e5fbe6..959c7dc2b 100644 --- a/es-app/src/views/SystemView.cpp +++ b/es-app/src/views/SystemView.cpp @@ -878,12 +878,12 @@ void SystemView::updateGameSelectors() if (mLegacyMode) return; - int cursor {mPrimary->getCursor()}; + const int cursor {mPrimary->getCursor()}; if (mSystemElements[cursor].gameSelectors.size() == 0) return; - bool multipleSelectors {mSystemElements[cursor].gameSelectors.size() > 1}; + const bool multipleSelectors {mSystemElements[cursor].gameSelectors.size() > 1}; for (auto& image : mSystemElements[cursor].imageComponents) { if (image->getThemeImageTypes().size() == 0) @@ -915,76 +915,79 @@ void SystemView::updateGameSelectors() else { gameSelector = mSystemElements[cursor].gameSelectors.front().get(); } + const size_t gameSelectorEntry {static_cast( + glm::clamp(image->getThemeGameSelectorEntry(), 0u, + static_cast(gameSelector->getGameCount() - 1)))}; gameSelector->refreshGames(); std::vector games {gameSelector->getGames()}; - if (!games.empty()) { + if (games.size() > gameSelectorEntry) { std::string path; for (auto& imageType : image->getThemeImageTypes()) { if (imageType == "image") { - path = games.front()->getImagePath(); + path = games.at(gameSelectorEntry)->getImagePath(); if (path != "") { image->setImage(path); break; } } else if (imageType == "miximage") { - path = games.front()->getMiximagePath(); + path = games.at(gameSelectorEntry)->getMiximagePath(); if (path != "") { image->setImage(path); break; } } else if (imageType == "marquee") { - path = games.front()->getMarqueePath(); + path = games.at(gameSelectorEntry)->getMarqueePath(); if (path != "") { image->setImage(path); break; } } else if (imageType == "screenshot") { - path = games.front()->getScreenshotPath(); + path = games.at(gameSelectorEntry)->getScreenshotPath(); if (path != "") { image->setImage(path); break; } } else if (imageType == "titlescreen") { - path = games.front()->getTitleScreenPath(); + path = games.at(gameSelectorEntry)->getTitleScreenPath(); if (path != "") { image->setImage(path); break; } } else if (imageType == "cover") { - path = games.front()->getCoverPath(); + path = games.at(gameSelectorEntry)->getCoverPath(); if (path != "") { image->setImage(path); break; } } else if (imageType == "backcover") { - path = games.front()->getBackCoverPath(); + path = games.at(gameSelectorEntry)->getBackCoverPath(); if (path != "") { image->setImage(path); break; } } else if (imageType == "3dbox") { - path = games.front()->get3DBoxPath(); + path = games.at(gameSelectorEntry)->get3DBoxPath(); if (path != "") { image->setImage(path); break; } } else if (imageType == "physicalmedia") { - path = games.front()->getPhysicalMediaPath(); + path = games.at(gameSelectorEntry)->getPhysicalMediaPath(); if (path != "") { image->setImage(path); break; } } else if (imageType == "fanart") { - path = games.front()->getFanArtPath(); + path = games.at(gameSelectorEntry)->getFanArtPath(); if (path != "") { image->setImage(path); break; @@ -1031,10 +1034,13 @@ void SystemView::updateGameSelectors() else { gameSelector = mSystemElements[cursor].gameSelectors.front().get(); } + const size_t gameSelectorEntry {static_cast( + glm::clamp(video->getThemeGameSelectorEntry(), 0u, + static_cast(gameSelector->getGameCount() - 1)))}; gameSelector->refreshGames(); std::vector games {gameSelector->getGames()}; - if (!games.empty()) { - if (!video->setVideo(games.front()->getVideoPath())) + if (games.size() > gameSelectorEntry) { + if (!video->setVideo(games.at(gameSelectorEntry)->getVideoPath())) video->setDefaultVideo(); } } @@ -1069,76 +1075,79 @@ void SystemView::updateGameSelectors() else { gameSelector = mSystemElements[cursor].gameSelectors.front().get(); } + const size_t gameSelectorEntry {static_cast( + glm::clamp(video->getThemeGameSelectorEntry(), 0u, + static_cast(gameSelector->getGameCount() - 1)))}; gameSelector->refreshGames(); std::vector games {gameSelector->getGames()}; - if (!games.empty()) { + if (games.size() > gameSelectorEntry) { std::string path; for (auto& imageType : video->getThemeImageTypes()) { if (imageType == "image") { - path = games.front()->getImagePath(); + path = games.at(gameSelectorEntry)->getImagePath(); if (path != "") { video->setImage(path); break; } } else if (imageType == "miximage") { - path = games.front()->getMiximagePath(); + path = games.at(gameSelectorEntry)->getMiximagePath(); if (path != "") { video->setImage(path); break; } } else if (imageType == "marquee") { - path = games.front()->getMarqueePath(); + path = games.at(gameSelectorEntry)->getMarqueePath(); if (path != "") { video->setImage(path); break; } } else if (imageType == "screenshot") { - path = games.front()->getScreenshotPath(); + path = games.at(gameSelectorEntry)->getScreenshotPath(); if (path != "") { video->setImage(path); break; } } else if (imageType == "titlescreen") { - path = games.front()->getTitleScreenPath(); + path = games.at(gameSelectorEntry)->getTitleScreenPath(); if (path != "") { video->setImage(path); break; } } else if (imageType == "cover") { - path = games.front()->getCoverPath(); + path = games.at(gameSelectorEntry)->getCoverPath(); if (path != "") { video->setImage(path); break; } } else if (imageType == "backcover") { - path = games.front()->getBackCoverPath(); + path = games.at(gameSelectorEntry)->getBackCoverPath(); if (path != "") { video->setImage(path); break; } } else if (imageType == "3dbox") { - path = games.front()->get3DBoxPath(); + path = games.at(gameSelectorEntry)->get3DBoxPath(); if (path != "") { video->setImage(path); break; } } else if (imageType == "physicalmedia") { - path = games.front()->getPhysicalMediaPath(); + path = games.at(gameSelectorEntry)->getPhysicalMediaPath(); if (path != "") { video->setImage(path); break; } } else if (imageType == "fanart") { - path = games.front()->getFanArtPath(); + path = games.at(gameSelectorEntry)->getFanArtPath(); if (path != "") { video->setImage(path); break; @@ -1184,37 +1193,45 @@ void SystemView::updateGameSelectors() else { gameSelector = mSystemElements[cursor].gameSelectors.front().get(); } + const size_t gameSelectorEntry {static_cast( + glm::clamp(text->getThemeGameSelectorEntry(), 0u, + static_cast(gameSelector->getGameCount() - 1)))}; gameSelector->refreshGames(); std::vector games {gameSelector->getGames()}; - if (!games.empty()) { + if (games.size() > gameSelectorEntry) { const std::string metadata {text->getThemeMetadata()}; if (metadata == "name") - text->setValue(games.front()->metadata.get("name")); + text->setValue(games.at(gameSelectorEntry)->metadata.get("name")); if (metadata == "description") - text->setValue(games.front()->metadata.get("desc")); + text->setValue(games.at(gameSelectorEntry)->metadata.get("desc")); if (metadata == "rating") - text->setValue( - RatingComponent::getRatingValue(games.front()->metadata.get("rating"))); + text->setValue(RatingComponent::getRatingValue( + games.at(gameSelectorEntry)->metadata.get("rating"))); if (metadata == "developer") - text->setValue(games.front()->metadata.get("developer")); + text->setValue(games.at(gameSelectorEntry)->metadata.get("developer")); if (metadata == "publisher") - text->setValue(games.front()->metadata.get("publisher")); + text->setValue(games.at(gameSelectorEntry)->metadata.get("publisher")); if (metadata == "genre") - text->setValue(games.front()->metadata.get("genre")); + text->setValue(games.at(gameSelectorEntry)->metadata.get("genre")); if (metadata == "players") - text->setValue(games.front()->metadata.get("players")); + text->setValue(games.at(gameSelectorEntry)->metadata.get("players")); if (metadata == "favorite") - text->setValue(games.front()->metadata.get("favorite") == "true" ? "yes" : "no"); + text->setValue( + games.at(gameSelectorEntry)->metadata.get("favorite") == "true" ? "yes" : "no"); if (metadata == "completed") - text->setValue(games.front()->metadata.get("completed") == "true" ? "yes" : "no"); + text->setValue(games.at(gameSelectorEntry)->metadata.get("completed") == "true" ? + "yes" : + "no"); if (metadata == "kidgame") - text->setValue(games.front()->metadata.get("kidgame") == "true" ? "yes" : "no"); + text->setValue( + games.at(gameSelectorEntry)->metadata.get("kidgame") == "true" ? "yes" : "no"); if (metadata == "broken") - text->setValue(games.front()->metadata.get("broken") == "true" ? "yes" : "no"); + text->setValue( + games.at(gameSelectorEntry)->metadata.get("broken") == "true" ? "yes" : "no"); if (metadata == "playcount") - text->setValue(games.front()->metadata.get("playcount")); + text->setValue(games.at(gameSelectorEntry)->metadata.get("playcount")); if (metadata == "altemulator") - text->setValue(games.front()->metadata.get("altemulator")); + text->setValue(games.at(gameSelectorEntry)->metadata.get("altemulator")); } else { text->setValue(""); @@ -1251,15 +1268,18 @@ void SystemView::updateGameSelectors() else { gameSelector = mSystemElements[cursor].gameSelectors.front().get(); } + const size_t gameSelectorEntry {static_cast( + glm::clamp(dateTime->getThemeGameSelectorEntry(), 0u, + static_cast(gameSelector->getGameCount() - 1)))}; gameSelector->refreshGames(); std::vector games {gameSelector->getGames()}; - if (!games.empty()) { + if (games.size() > gameSelectorEntry) { dateTime->setVisible(true); const std::string metadata {dateTime->getThemeMetadata()}; if (metadata == "releasedate") - dateTime->setValue(games.front()->metadata.get("releasedate")); + dateTime->setValue(games.at(gameSelectorEntry)->metadata.get("releasedate")); if (metadata == "lastplayed") - dateTime->setValue(games.front()->metadata.get("lastplayed")); + dateTime->setValue(games.at(gameSelectorEntry)->metadata.get("lastplayed")); } else { dateTime->setVisible(false); @@ -1295,11 +1315,14 @@ void SystemView::updateGameSelectors() else { gameSelector = mSystemElements[cursor].gameSelectors.front().get(); } + const size_t gameSelectorEntry {static_cast( + glm::clamp(rating->getThemeGameSelectorEntry(), 0u, + static_cast(gameSelector->getGameCount() - 1)))}; gameSelector->refreshGames(); std::vector games {gameSelector->getGames()}; - if (!games.empty()) { + if (games.size() > gameSelectorEntry) { rating->setVisible(true); - rating->setValue(games.front()->metadata.get("rating")); + rating->setValue(games.at(gameSelectorEntry)->metadata.get("rating")); } else { rating->setVisible(false); diff --git a/es-core/src/GuiComponent.cpp b/es-core/src/GuiComponent.cpp index 4edf89f6b..40fc0f84b 100644 --- a/es-core/src/GuiComponent.cpp +++ b/es-core/src/GuiComponent.cpp @@ -19,6 +19,7 @@ GuiComponent::GuiComponent() : mWindow {Window::getInstance()} , mParent {nullptr} + , mThemeGameSelectorEntry {0} , mColor {0} , mColorShift {0} , mColorShiftEnd {0} @@ -398,6 +399,9 @@ void GuiComponent::applyTheme(const std::shared_ptr& theme, if (properties && elem->has("gameselector")) mThemeGameSelector = elem->get("gameselector"); + + if (properties && elem->has("gameselectorEntry")) + mThemeGameSelectorEntry = elem->get("gameselectorEntry"); } void GuiComponent::updateHelpPrompts() diff --git a/es-core/src/GuiComponent.h b/es-core/src/GuiComponent.h index 968a5e9c3..62be22a5d 100644 --- a/es-core/src/GuiComponent.h +++ b/es-core/src/GuiComponent.h @@ -259,7 +259,8 @@ public: const std::string& getThemeMetadata() { return mThemeMetadata; } void setThemeMetadata(const std::string& text) { mThemeMetadata = text; } const std::vector& getThemeImageTypes() { return mThemeImageTypes; } - const std::string& getThemeGameSelector() { return mThemeGameSelector; } + const std::string& getThemeGameSelector() const { return mThemeGameSelector; } + const unsigned int getThemeGameSelectorEntry() const { return mThemeGameSelectorEntry; } virtual std::shared_ptr getFont() const { return nullptr; } @@ -325,6 +326,7 @@ protected: std::string mThemeSystemdata; std::string mThemeMetadata; std::string mThemeGameSelector; + unsigned int mThemeGameSelectorEntry; unsigned int mColor; unsigned int mColorShift; diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 3d25696c6..3de8c4faa 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -253,6 +253,7 @@ std::map> {"imageType", STRING}, {"metadataElement", BOOLEAN}, {"gameselector", STRING}, + {"gameselectorEntry", UNSIGNED_INTEGER}, {"tile", BOOLEAN}, {"tileSize", NORMALIZED_PAIR}, {"tileHorizontalAlignment", STRING}, @@ -278,6 +279,7 @@ std::map> {"imageType", STRING}, {"metadataElement", BOOLEAN}, {"gameselector", STRING}, + {"gameselectorEntry", UNSIGNED_INTEGER}, {"audio", BOOLEAN}, {"interpolation", STRING}, {"color", COLOR}, @@ -347,6 +349,7 @@ std::map> {"metadata", STRING}, {"metadataElement", BOOLEAN}, {"gameselector", STRING}, + {"gameselectorEntry", UNSIGNED_INTEGER}, {"container", BOOLEAN}, {"containerVerticalSnap", BOOLEAN}, {"containerScrollSpeed", FLOAT}, @@ -373,6 +376,7 @@ std::map> {"rotationOrigin", NORMALIZED_PAIR}, {"metadata", STRING}, {"gameselector", STRING}, + {"gameselectorEntry", UNSIGNED_INTEGER}, {"fontPath", PATH}, {"fontSize", FLOAT}, {"horizontalAlignment", STRING}, @@ -411,6 +415,7 @@ std::map> {"rotation", FLOAT}, {"rotationOrigin", NORMALIZED_PAIR}, {"gameselector", STRING}, + {"gameselectorEntry", UNSIGNED_INTEGER}, {"interpolation", STRING}, {"color", COLOR}, {"filledPath", PATH}, diff --git a/es-core/src/components/GameSelectorComponent.h b/es-core/src/components/GameSelectorComponent.h index b123e2a2d..d7368f731 100644 --- a/es-core/src/components/GameSelectorComponent.h +++ b/es-core/src/components/GameSelectorComponent.h @@ -45,6 +45,7 @@ public: const bool getNeedsRefresh() { return mNeedsRefresh; } const GameSelection getGameSelection() const { return mGameSelection; } const std::string& getSelectorName() const { return mSelectorName; } + const int getGameCount() const { return mGameCount; } void refreshGames() { diff --git a/es-core/src/components/IList.h b/es-core/src/components/IList.h index 5f0e02f3b..b80008805 100644 --- a/es-core/src/components/IList.h +++ b/es-core/src/components/IList.h @@ -3,7 +3,7 @@ // EmulationStation Desktop Edition // IList.h // -// List base class, used by both the gamelist views and the menu. +// List base class, used by the system view, gamelist view and menu system. // #ifndef ES_CORE_COMPONENTS_ILIST_H @@ -284,7 +284,7 @@ protected: } // Actually perform the scrolling. - for (int i = 0; i < scrollCount; ++i) + for (int i {0}; i < scrollCount; ++i) scroll(mScrollVelocity); } @@ -300,7 +300,7 @@ protected: } std::string titleIndex; - bool favoritesSorting; + bool favoritesSorting {true}; if (getSelected()->getSystem()->isCustomCollection()) favoritesSorting = Settings::getInstance()->getBool("FavFirstCustom");