Merge pull request #415 from Koerty/grid-default-image

[GRID 5 & 6] Add grid default image and folder image
This commit is contained in:
John Rassa 2018-04-16 21:30:40 -04:00 committed by GitHub
commit 4a1e9d5f11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 1 deletions

View file

@ -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.

View file

@ -29,6 +29,8 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>> The
{ "pos", NORMALIZED_PAIR },
{ "size", NORMALIZED_PAIR },
{ "margin", NORMALIZED_PAIR },
{ "gameImage", PATH },
{ "folderImage", PATH },
{ "scrollDirection", STRING } } },
{ "gridtile", {
{ "size", NORMALIZED_PAIR },

View file

@ -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<TextureResource> mDefaultGameTexture;
std::shared_ptr<TextureResource> mDefaultFolderTexture;
// TILES
Vector2f mMargin;
@ -80,6 +83,8 @@ ImageGridComponent<T>::ImageGridComponent(Window* window) : IList<ImageGridData,
Vector2f screen = Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
mEntriesDirty = true;
mDefaultGameTexture = TextureResource::get(":/blank_game.png");
mDefaultFolderTexture = TextureResource::get(":/folder.png");
mSize = screen * 0.80f;
mMargin = screen * 0.07f;
@ -96,7 +101,21 @@ void ImageGridComponent<T>::add(const std::string& name, const std::string& imag
typename IList<ImageGridData, T>::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<IList< ImageGridData, T >*>(this)->add(entry);
mEntriesDirty = true;
}
@ -189,6 +208,50 @@ void ImageGridComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (elem->has("scrollDirection"))
mScrollDirection = (ScrollDirection)(elem->get<std::string>("scrollDirection") == "horizontal");
if (elem->has("gameImage"))
{
std::string path = elem->get<std::string>("gameImage");
if (!ResourceManager::getInstance()->fileExists(path))
LOG(LogWarning) << "Could not replace default game image, check path: " << path;
else
{
std::shared_ptr<TextureResource> 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<std::string>("folderImage");
if (!ResourceManager::getInstance()->fileExists(path))
LOG(LogWarning) << "Could not replace default folder image, check path: " << path;
else
{
std::shared_ptr<TextureResource> 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,

BIN
resources/blank_game.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
resources/folder.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 586 B