Added color/font settings for DateTimeComponent.

Added "release date" entry to GuiGameList.
This commit is contained in:
Aloshi 2013-10-16 18:11:43 -05:00
parent 89fca2b875
commit 36ecb83d8d
4 changed files with 68 additions and 9 deletions

View file

@ -5,7 +5,8 @@
#include "../Log.h"
DateTimeComponent::DateTimeComponent(Window* window) : GuiComponent(window),
mEditing(false), mEditIndex(0), mDisplayMode(DISP_DATE), mRelativeUpdateAccumulator(0)
mEditing(false), mEditIndex(0), mDisplayMode(DISP_DATE), mRelativeUpdateAccumulator(0),
mColor(0x000000FF)
{
mSize << 64, (float)getFont()->getHeight();
updateTextCache();
@ -231,6 +232,9 @@ std::string DateTimeComponent::getDisplayString(DisplayMode mode) const
std::shared_ptr<Font> DateTimeComponent::getFont() const
{
if(mFont)
return mFont;
return Font::get(FONT_SIZE_MEDIUM);
}
@ -239,7 +243,7 @@ void DateTimeComponent::updateTextCache()
DisplayMode mode = getCurrentDisplayMode();
const std::string dispString = getDisplayString(mode);
std::shared_ptr<Font> font = getFont();
mTextCache = std::unique_ptr<TextCache>(font->buildTextCache(dispString, 0, 0, 0x000000FF));
mTextCache = std::unique_ptr<TextCache>(font->buildTextCache(dispString, 0, 0, mColor));
//set up cursor positions
mCursorBoxes.clear();
@ -267,3 +271,20 @@ void DateTimeComponent::updateTextCache()
//if mode == DISP_DATE_TIME do times too but I don't wanna do the logic for editing times because no one will ever use it so screw it
}
void DateTimeComponent::setColor(unsigned int color)
{
mColor = color;
if(mTextCache)
mTextCache->setColor(color);
}
void DateTimeComponent::setFont(std::shared_ptr<Font> font)
{
mFont = font;
if(getSize().y() < mFont->getHeight())
setSize(getSize().x(), (float)mFont->getHeight());
updateTextCache();
}

View file

@ -25,6 +25,9 @@ public:
void setDisplayMode(DisplayMode mode);
void setColor(unsigned int color);
void setFont(std::shared_ptr<Font> font);
private:
std::shared_ptr<Font> getFont() const;
@ -44,4 +47,7 @@ private:
std::unique_ptr<TextCache> mTextCache;
std::vector<Eigen::Vector4f> mCursorBoxes;
unsigned int mColor;
std::shared_ptr<Font> mFont;
};

View file

@ -19,10 +19,21 @@ Eigen::Vector3f GuiGameList::getImagePos()
bool GuiGameList::isDetailed() const
{
if(mSystem == NULL)
if(!mFolder)
return false;
return mSystem->hasGamelist();
//return true if any game has an image specified
for(unsigned int i = 0; i < mFolder->getFileCount(); i++)
{
if(!mFolder->getFile(i)->isFolder())
{
GameData* game = (GameData*)(mFolder->getFile(i));
if(!game->metadata()->get("image").empty())
return true;
}
}
return false;
}
GuiGameList::GuiGameList(Window* window) : GuiComponent(window),
@ -31,6 +42,7 @@ GuiGameList::GuiGameList(Window* window) : GuiComponent(window),
mScreenshot(window),
mDescription(window),
mRating(window),
mReleaseDate(window),
mDescContainer(window),
mTransitionImage(window, 0.0f, 0.0f, "", (float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight(), true),
mHeaderText(mWindow),
@ -51,6 +63,7 @@ GuiGameList::GuiGameList(Window* window) : GuiComponent(window),
}
mImageAnimation.addChild(&mScreenshot);
mDescContainer.addChild(&mReleaseDate);
mDescContainer.addChild(&mRating);
mDescContainer.addChild(&mDescription);
@ -357,14 +370,15 @@ void GuiGameList::updateTheme()
mScreenshot.setOrigin(mTheme->getFloat("gameImageOriginX"), mTheme->getFloat("gameImageOriginY"));
mScreenshot.setResize(mTheme->getFloat("gameImageWidth") * Renderer::getScreenWidth(), mTheme->getFloat("gameImageHeight") * Renderer::getScreenHeight(), false);
mReleaseDate.setColor(mTheme->getColor("description"));
mReleaseDate.setFont(mTheme->getDescriptionFont());
mDescription.setColor(mTheme->getColor("description"));
mDescription.setFont(mTheme->getDescriptionFont());
}else{
mList.setCentered(true);
mList.setPosition(0, mList.getPosition().y());
mList.setTextOffsetX(0);
//mDescription.setFont(nullptr);
}
}
@ -378,11 +392,22 @@ void GuiGameList::updateDetailData()
addChild(&mDescContainer);
GameData* game = (GameData*)mList.getSelectedObject();
//set image to either "not found" image or metadata image
if(game->metadata()->get("image").empty())
mScreenshot.setImage(mTheme->getString("imageNotFoundPath"));
else
if(!boost::filesystem::exists(game->metadata()->get("image")))
{
//image doesn't exist
if(mTheme->getString("imageNotFoundPath").empty())
{
//"not found" image doesn't exist
mScreenshot.setImage("");
mScreenshot.setSize(0, 0); //clear old size
}else{
mScreenshot.setImage(mTheme->getString("imageNotFoundPath"));
}
}else{
mScreenshot.setImage(game->metadata()->get("image"));
}
Eigen::Vector3f imgOffset = Eigen::Vector3f(Renderer::getScreenWidth() * 0.10f, 0, 0);
mScreenshot.setPosition(getImagePos() - imgOffset);
@ -399,6 +424,9 @@ void GuiGameList::updateDetailData()
float ratingHeight = colwidth * 0.3f / 5.0f;
mRating.setSize(ratingHeight * 5.0f, ratingHeight);
mReleaseDate.setPosition(0, 0);
mReleaseDate.setValue(game->metadata()->get("releasedate"));
mRating.setPosition(colwidth - mRating.getSize().x() - 12, 0);
mRating.setValue(game->metadata()->get("rating"));

View file

@ -14,6 +14,7 @@
#include "../FolderData.h"
#include "ScrollableContainer.h"
#include "RatingComponent.h"
#include "DateTimeComponent.h"
//This is where the magic happens - GuiGameList is the parent of almost every graphical element in ES at the moment.
//It has a TextListComponent child that handles the game list, a ThemeComponent that handles the theming system, and an ImageComponent for game images.
@ -60,8 +61,11 @@ private:
TextListComponent<FileData*> mList;
ImageComponent mScreenshot;
TextComponent mDescription;
RatingComponent mRating;
DateTimeComponent mReleaseDate;
ScrollableContainer mDescContainer;
AnimationComponent mImageAnimation;
ThemeComponent* mTheme;