diff --git a/THEMES.md b/THEMES.md index 2646ed949..970bd47cb 100644 --- a/THEMES.md +++ b/THEMES.md @@ -585,6 +585,10 @@ Can be created as an extra. * `size` - type: NORMALIZED_PAIR. - The size of the grid. Take care the selected tile can go out of the grid size, so don't position the grid too close to another element or the screen border. * `margin` - type: NORMALIZED_PAIR. +* `gameImage` - type: PATH. + - The default image used for games which doesn't have an image. +* `folderImage` - type: PATH. + - The default image used for folders which doesn't have an image. * `scrollDirection` - type: STRING. - `vertical` by default, can also be set to `horizontal`. Not that in `horizontal` mod, the tiles are ordered from top to bottom, then from left to right. diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 4a4f0d512..cad63b0f6 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -29,6 +29,8 @@ std::map> The { "pos", NORMALIZED_PAIR }, { "size", NORMALIZED_PAIR }, { "margin", NORMALIZED_PAIR }, + { "gameImage", PATH }, + { "folderImage", PATH }, { "scrollDirection", STRING } } }, { "gridtile", { { "size", NORMALIZED_PAIR }, diff --git a/es-core/src/components/ImageGridComponent.h b/es-core/src/components/ImageGridComponent.h index d53b60dff..da5769cdc 100644 --- a/es-core/src/components/ImageGridComponent.h +++ b/es-core/src/components/ImageGridComponent.h @@ -2,6 +2,7 @@ #ifndef ES_CORE_COMPONENTS_IMAGE_GRID_COMPONENT_H #define ES_CORE_COMPONENTS_IMAGE_GRID_COMPONENT_H +#include "Log.h" #include "components/IList.h" #include "resources/TextureResource.h" #include "GridTileComponent.h" @@ -61,6 +62,8 @@ private: // IMAGES & ENTRIES bool mEntriesDirty; + std::shared_ptr mDefaultGameTexture; + std::shared_ptr mDefaultFolderTexture; // TILES Vector2f mMargin; @@ -80,6 +83,8 @@ ImageGridComponent::ImageGridComponent(Window* window) : IList::add(const std::string& name, const std::string& imag typename IList::Entry entry; entry.name = name; entry.object = obj; - entry.data.texture = ResourceManager::getInstance()->fileExists(imagePath) ? TextureResource::get(imagePath) : TextureResource::get(":/button.png"); + + if (ResourceManager::getInstance()->fileExists(imagePath)) + { + entry.data.texture = TextureResource::get(imagePath); + } + else + { + // FileType::FOLDER = 2, but FileData is our template parameter T, + // so we don't want to bring that dependence to FileData here + if (obj->getType() == 2) + entry.data.texture = mDefaultFolderTexture; + else + entry.data.texture = mDefaultGameTexture; + } + static_cast*>(this)->add(entry); mEntriesDirty = true; } @@ -189,6 +208,50 @@ void ImageGridComponent::applyTheme(const std::shared_ptr& theme, if (elem->has("scrollDirection")) mScrollDirection = (ScrollDirection)(elem->get("scrollDirection") == "horizontal"); + + if (elem->has("gameImage")) + { + std::string path = elem->get("gameImage"); + + if (!ResourceManager::getInstance()->fileExists(path)) + LOG(LogWarning) << "Could not replace default game image, check path: " << path; + else + { + std::shared_ptr oldDefaultGameTexture = mDefaultGameTexture; + + mDefaultGameTexture = TextureResource::get(path); + + // mEntries are already loaded at this point, + // so we need to update them with new game image texture + for (auto it = mEntries.begin(); it != mEntries.end(); it++) + { + if ((*it).data.texture == oldDefaultGameTexture) + (*it).data.texture = mDefaultGameTexture; + } + } + } + + if (elem->has("folderImage")) + { + std::string path = elem->get("folderImage"); + + if (!ResourceManager::getInstance()->fileExists(path)) + LOG(LogWarning) << "Could not replace default folder image, check path: " << path; + else + { + std::shared_ptr oldDefaultFolderTexture = mDefaultFolderTexture; + + mDefaultFolderTexture = TextureResource::get(path); + + // mEntries are already loaded at this point, + // so we need to update them with new folder image texture + for (auto it = mEntries.begin(); it != mEntries.end(); it++) + { + if ((*it).data.texture == oldDefaultFolderTexture) + (*it).data.texture = mDefaultFolderTexture; + } + } + } } // We still need to manually get the grid tile size here, diff --git a/resources/blank_game.png b/resources/blank_game.png new file mode 100644 index 000000000..23b293063 Binary files /dev/null and b/resources/blank_game.png differ diff --git a/resources/folder.png b/resources/folder.png new file mode 100644 index 000000000..7582a4a27 Binary files /dev/null and b/resources/folder.png differ