From 36ecb83d8d682af0c0c809d18dac27551b4cce84 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Wed, 16 Oct 2013 18:11:43 -0500 Subject: [PATCH] Added color/font settings for DateTimeComponent. Added "release date" entry to GuiGameList. --- src/components/DateTimeComponent.cpp | 25 +++++++++++++++-- src/components/DateTimeComponent.h | 6 ++++ src/components/GuiGameList.cpp | 42 +++++++++++++++++++++++----- src/components/GuiGameList.h | 4 +++ 4 files changed, 68 insertions(+), 9 deletions(-) diff --git a/src/components/DateTimeComponent.cpp b/src/components/DateTimeComponent.cpp index aaf624dfc..df31803fb 100644 --- a/src/components/DateTimeComponent.cpp +++ b/src/components/DateTimeComponent.cpp @@ -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 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 = getFont(); - mTextCache = std::unique_ptr(font->buildTextCache(dispString, 0, 0, 0x000000FF)); + mTextCache = std::unique_ptr(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) +{ + mFont = font; + + if(getSize().y() < mFont->getHeight()) + setSize(getSize().x(), (float)mFont->getHeight()); + + updateTextCache(); +} diff --git a/src/components/DateTimeComponent.h b/src/components/DateTimeComponent.h index 451e9fd3b..bccb1a99b 100644 --- a/src/components/DateTimeComponent.h +++ b/src/components/DateTimeComponent.h @@ -25,6 +25,9 @@ public: void setDisplayMode(DisplayMode mode); + void setColor(unsigned int color); + void setFont(std::shared_ptr font); + private: std::shared_ptr getFont() const; @@ -44,4 +47,7 @@ private: std::unique_ptr mTextCache; std::vector mCursorBoxes; + + unsigned int mColor; + std::shared_ptr mFont; }; diff --git a/src/components/GuiGameList.cpp b/src/components/GuiGameList.cpp index ed1668446..efbceb6a0 100644 --- a/src/components/GuiGameList.cpp +++ b/src/components/GuiGameList.cpp @@ -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")); diff --git a/src/components/GuiGameList.h b/src/components/GuiGameList.h index 77539e6af..87f5c359f 100644 --- a/src/components/GuiGameList.h +++ b/src/components/GuiGameList.h @@ -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 mList; ImageComponent mScreenshot; + TextComponent mDescription; RatingComponent mRating; + DateTimeComponent mReleaseDate; + ScrollableContainer mDescContainer; AnimationComponent mImageAnimation; ThemeComponent* mTheme;