From 640493e0a652ae9a77cd50af92e788a51e963340 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sun, 19 Jan 2014 16:06:13 -0600 Subject: [PATCH] Added more metadata to the detailed gamelist view. --- src/ThemeData.cpp | 6 + src/components/DateTimeComponent.cpp | 16 +++ src/components/DateTimeComponent.h | 2 + src/components/RatingComponent.cpp | 4 +- src/views/gamelist/DetailedGameListView.cpp | 137 +++++++++++++++++++- src/views/gamelist/DetailedGameListView.h | 17 ++- 6 files changed, 176 insertions(+), 6 deletions(-) diff --git a/src/ThemeData.cpp b/src/ThemeData.cpp index 75bc7e63f..0eb9d9795 100644 --- a/src/ThemeData.cpp +++ b/src/ThemeData.cpp @@ -44,6 +44,12 @@ std::map< std::string, std::map > T ("pos", NORMALIZED_PAIR) ("size", NORMALIZED_PAIR) ("path", PATH)) + ("datetime", boost::assign::map_list_of + ("pos", NORMALIZED_PAIR) + ("size", NORMALIZED_PAIR) + ("color", COLOR) + ("fontPath", PATH) + ("fontSize", FLOAT)) ("sound", boost::assign::map_list_of ("path", PATH)); diff --git a/src/components/DateTimeComponent.cpp b/src/components/DateTimeComponent.cpp index d501d666b..8c8d81492 100644 --- a/src/components/DateTimeComponent.cpp +++ b/src/components/DateTimeComponent.cpp @@ -289,3 +289,19 @@ void DateTimeComponent::setFont(std::shared_ptr font) updateTextCache(); } + +void DateTimeComponent::applyTheme(const std::shared_ptr& theme, const std::string& view, const std::string& element, unsigned int properties) +{ + GuiComponent::applyTheme(theme, view, element, properties); + + using namespace ThemeFlags; + + const ThemeData::ThemeElement* elem = theme->getElement(view, element, "datetime"); + if(!elem) + return; + + if(properties & COLOR && elem->has("color")) + setColor(elem->get("color")); + + setFont(Font::getFromTheme(elem, properties, mFont)); +} diff --git a/src/components/DateTimeComponent.h b/src/components/DateTimeComponent.h index bccb1a99b..13b5a5424 100644 --- a/src/components/DateTimeComponent.h +++ b/src/components/DateTimeComponent.h @@ -28,6 +28,8 @@ public: void setColor(unsigned int color); void setFont(std::shared_ptr font); + virtual void applyTheme(const std::shared_ptr& theme, const std::string& view, const std::string& element, unsigned int properties) override; + private: std::shared_ptr getFont() const; diff --git a/src/components/RatingComponent.cpp b/src/components/RatingComponent.cpp index 25c97d482..c49b6336f 100644 --- a/src/components/RatingComponent.cpp +++ b/src/components/RatingComponent.cpp @@ -4,8 +4,8 @@ RatingComponent::RatingComponent(Window* window) : GuiComponent(window) { - mFilledTexture = TextureResource::get(":/star_filled.png"); - mUnfilledTexture = TextureResource::get(":/star_unfilled.png"); + mFilledTexture = TextureResource::get(":/star_filled.png", true); + mUnfilledTexture = TextureResource::get(":/star_unfilled.png", true); mValue = 0.5f; mSize << 64 * 5.0f, 64; updateVertices(); diff --git a/src/views/gamelist/DetailedGameListView.cpp b/src/views/gamelist/DetailedGameListView.cpp index 4cafd64d3..ddd29d117 100644 --- a/src/views/gamelist/DetailedGameListView.cpp +++ b/src/views/gamelist/DetailedGameListView.cpp @@ -5,9 +5,12 @@ DetailedGameListView::DetailedGameListView(Window* window, FileData* root) : BasicGameListView(window, root), mDescContainer(window), mDescription(window), - mImage(window) + mImage(window), + + mLblRating(window), mLblReleaseDate(window), mLblLastPlayed(window), mLblPlayCount(window), + mRating(window), mReleaseDate(window), mLastPlayed(window), mPlayCount(window) { - mHeaderImage.setPosition(mSize.x() * 0.25f, 0); + //mHeaderImage.setPosition(mSize.x() * 0.25f, 0); const float padding = 0.01f; @@ -16,11 +19,27 @@ DetailedGameListView::DetailedGameListView(Window* window, FileData* root) : mList.setCentered(false); mList.setCursorChangedCallback([&](TextListComponent::CursorState state) { updateInfoPanel(); }); + // image mImage.setOrigin(0.5f, 0.5f); mImage.setPosition(mSize.x() * 0.25f, mList.getPosition().y() + mSize.y() * 0.2125f); - mImage.setMaxSize(mSize.x() * (0.50f - 2*padding), mSize.y() * 0.425f); + mImage.setMaxSize(mSize.x() * (0.50f - 2*padding), mSize.y() * 0.4f); addChild(&mImage); + // metadata labels + values + mLblRating.setText("Rating: "); + addChild(&mLblRating); + addChild(&mRating); + mLblReleaseDate.setText("Released: "); + addChild(&mLblReleaseDate); + addChild(&mReleaseDate); + mLblLastPlayed.setText("Last played: "); + addChild(&mLblLastPlayed); + mLastPlayed.setDisplayMode(DateTimeComponent::DISP_RELATIVE_TO_NOW); + addChild(&mLastPlayed); + mLblPlayCount.setText("Play count: "); + addChild(&mLblPlayCount); + addChild(&mPlayCount); + mDescContainer.setPosition(mSize.x() * padding, mSize.y() * 0.65f); mDescContainer.setSize(mSize.x() * (0.50f - 2*padding), mSize.y() - mDescContainer.getPosition().y()); mDescContainer.setAutoScroll((int)(1600 + mDescContainer.getSize().x()), 0.025f); @@ -30,6 +49,9 @@ DetailedGameListView::DetailedGameListView(Window* window, FileData* root) : mDescription.setSize(mDescContainer.getSize().x(), 0); mDescContainer.addChild(&mDescription); + + initMDLabels(); + initMDValues(); updateInfoPanel(); } @@ -40,11 +62,96 @@ void DetailedGameListView::onThemeChanged(const std::shared_ptr& them using namespace ThemeFlags; mImage.applyTheme(theme, getName(), "gameimage", POSITION | ThemeFlags::SIZE); + initMDLabels(); + std::vector labels = getMDLabels(); + assert(labels.size() == 4); + const char* lblElements[4] = { + "md_lbl_rating", "md_lbl_releasedate", "md_lbl_lastplayed", "md_lbl_playcount" + }; + + for(unsigned int i = 0; i < labels.size(); i++) + { + labels[i]->applyTheme(theme, getName(), lblElements[i], ALL ^ ThemeFlags::TEXT); + } + + + initMDValues(); + std::vector values = getMDValues(); + assert(values.size() == 4); + const char* valElements[4] = { + "md_rating", "md_releasedate", "md_lastplayed", "md_playcount" + }; + + for(unsigned int i = 0; i < values.size(); i++) + { + values[i]->applyTheme(theme, getName(), valElements[i], ALL ^ ThemeFlags::TEXT); + } + mDescContainer.applyTheme(theme, getName(), "description", POSITION | ThemeFlags::SIZE); mDescription.setSize(mDescContainer.getSize().x(), 0); mDescription.applyTheme(theme, getName(), "description", FONT_PATH | FONT_SIZE | COLOR); } +void DetailedGameListView::initMDLabels() +{ + using namespace Eigen; + + std::vector components = getMDLabels(); + + const unsigned int colCount = 2; + const unsigned int rowCount = components.size() / 2; + + Vector3f start(mSize.x() * 0.01f, mSize.y() * 0.625f, 0.0f); + + const float colSize = (mSize.x() * 0.48f) / colCount; + const float rowPadding = 0.01f * mSize.y(); + + for(unsigned int i = 0; i < components.size(); i++) + { + const unsigned int row = i % rowCount; + Vector3f pos(0.0f, 0.0f, 0.0f); + if(row == 0) + { + pos = start + Vector3f(colSize * (i / rowCount), 0, 0); + }else{ + // work from the last component + GuiComponent* lc = components[i-1]; + pos = lc->getPosition() + Vector3f(0, lc->getSize().y() + rowPadding, 0); + } + + components[i]->setFont(Font::get(FONT_SIZE_SMALL)); + components[i]->setPosition(pos); + } +} + +void DetailedGameListView::initMDValues() +{ + using namespace Eigen; + + std::vector labels = getMDLabels(); + std::vector values = getMDValues(); + + std::shared_ptr defaultFont = Font::get(FONT_SIZE_SMALL); + mRating.setSize(defaultFont->getHeight() * 5.0f, (float)defaultFont->getHeight()); + mReleaseDate.setFont(defaultFont); + mLastPlayed.setFont(defaultFont); + mPlayCount.setFont(defaultFont); + + float bottom = 0.0f; + for(unsigned int i = 0; i < labels.size(); i++) + { + const float heightDiff = (labels[i]->getSize().y() - values[i]->getSize().y()) / 2; + values[i]->setPosition(labels[i]->getPosition() + Vector3f(labels[i]->getSize().x(), heightDiff, 0)); + + float testBot = values[i]->getPosition().y() + values[i]->getSize().y(); + if(testBot > bottom) + bottom = testBot; + } + + mDescContainer.setPosition(mDescContainer.getPosition().x(), bottom + mSize.y() * 0.01f); + mDescContainer.setSize(mDescContainer.getSize().x(), mSize.y() - mDescContainer.getPosition().y()); +} + void DetailedGameListView::updateInfoPanel() { FileData* file = (mList.getList().size() == 0 || mList.isScrolling()) ? NULL : mList.getSelected(); @@ -55,6 +162,10 @@ void DetailedGameListView::updateInfoPanel() mDescription.setText(""); }else{ mImage.setImage(file->metadata.get("image")); + mRating.setValue(file->metadata.get("rating")); + mReleaseDate.setValue(file->metadata.get("releasedate")); + mLastPlayed.setValue(file->metadata.get("lastplayed")); + mPlayCount.setValue(file->metadata.get("playcount")); mDescription.setText(file->metadata.get("desc")); mDescContainer.resetAutoScrollTimer(); @@ -70,3 +181,23 @@ void DetailedGameListView::launch(FileData* game) mWindow->getViewController()->launch(game, target); } + +std::vector DetailedGameListView::getMDLabels() +{ + std::vector ret; + ret.push_back(&mLblRating); + ret.push_back(&mLblReleaseDate); + ret.push_back(&mLblLastPlayed); + ret.push_back(&mLblPlayCount); + return ret; +} + +std::vector DetailedGameListView::getMDValues() +{ + std::vector ret; + ret.push_back(&mRating); + ret.push_back(&mReleaseDate); + ret.push_back(&mLastPlayed); + ret.push_back(&mPlayCount); + return ret; +} diff --git a/src/views/gamelist/DetailedGameListView.h b/src/views/gamelist/DetailedGameListView.h index a2c08901c..7ba89dfca 100644 --- a/src/views/gamelist/DetailedGameListView.h +++ b/src/views/gamelist/DetailedGameListView.h @@ -2,6 +2,8 @@ #include "BasicGameListView.h" #include "../../components/ScrollableContainer.h" +#include "../../components/RatingComponent.h" +#include "../../components/DateTimeComponent.h" class DetailedGameListView : public BasicGameListView { @@ -18,8 +20,21 @@ protected: private: void updateInfoPanel(); + void initMDLabels(); + void initMDValues(); + ImageComponent mImage; - + + TextComponent mLblRating, mLblReleaseDate, mLblLastPlayed, mLblPlayCount; + + RatingComponent mRating; + DateTimeComponent mReleaseDate; + DateTimeComponent mLastPlayed; + TextComponent mPlayCount; + + std::vector getMDLabels(); + std::vector getMDValues(); + ScrollableContainer mDescContainer; TextComponent mDescription; };