Added meta field support to reloadableScrollingText.

This commit is contained in:
Pieter Hulshoff 2017-05-10 10:56:01 +02:00
parent c01891d7b2
commit 3e6f67f0c8
4 changed files with 186 additions and 5 deletions

View File

@ -28,7 +28,7 @@
#include <algorithm>
ReloadableScrollingText::ReloadableScrollingText(Configuration &config, bool systemMode, bool layoutMode, std::string type, std::string textFormat, std::string alignment, Page &p, int displayOffset, Font *font, float scaleX, float scaleY, std::string direction, float scrollingSpeed, float startPosition, float startTime, float endTime )
ReloadableScrollingText::ReloadableScrollingText(Configuration &config, bool systemMode, bool layoutMode, std::string type, std::string textFormat, std::string singlePrefix, std::string singlePostfix, std::string pluralPrefix, std::string pluralPostfix, std::string alignment, Page &p, int displayOffset, Font *font, float scaleX, float scaleY, std::string direction, float scrollingSpeed, float startPosition, float startTime, float endTime )
: Component(p)
, config_(config)
, systemMode_(systemMode)
@ -36,6 +36,10 @@ ReloadableScrollingText::ReloadableScrollingText(Configuration &config, bool sys
, fontInst_(font)
, type_(type)
, textFormat_(textFormat)
, singlePrefix_(singlePrefix)
, singlePostfix_(singlePostfix)
, pluralPrefix_(pluralPrefix)
, pluralPostfix_(pluralPostfix)
, alignment_(alignment)
, scaleX_(scaleX)
, scaleY_(scaleY)
@ -203,6 +207,159 @@ void ReloadableScrollingText::reloadTexture( )
}
}
// Check for supported fields if text is still empty
if (text_.empty( ))
{
std::stringstream ss;
std::string text = "";
if (type_ == "numberButtons")
{
text = selectedItem->numberButtons;
}
else if (type_ == "numberPlayers")
{
text = selectedItem->numberPlayers;
}
else if (type_ == "ctrlType")
{
text = selectedItem->ctrlType;
}
else if (type_ == "numberJoyWays")
{
text = selectedItem->joyWays;
}
else if (type_ == "rating")
{
text = selectedItem->rating;
}
else if (type_ == "score")
{
text = selectedItem->score;
}
else if (type_ == "year")
{
if (selectedItem->leaf) // item is a leaf
text = selectedItem->year;
else // item is a collection
(void)config_.getProperty("collections." + selectedItem->name + ".year", text );
}
else if (type_ == "title")
{
text = selectedItem->title;
}
else if(type_ == "developer")
{
text = selectedItem->developer;
// Overwrite in case developer has not been specified
if (text == "")
{
text = selectedItem->manufacturer;
}
}
else if (type_ == "manufacturer")
{
if (selectedItem->leaf) // item is a leaf
text = selectedItem->manufacturer;
else // item is a collection
(void)config_.getProperty("collections." + selectedItem->name + ".manufacturer", text );
}
else if (type_ == "genre")
{
if (selectedItem->leaf) // item is a leaf
text = selectedItem->genre;
else // item is a collection
(void)config_.getProperty("collections." + selectedItem->name + ".genre", text );
}
else if (type_ == "playlist")
{
text = playlistName;
}
else if (type_ == "firstLetter")
{
text = selectedItem->fullTitle.at(0);
}
else if (type_ == "collectionName")
{
text = page.getCollectionName();
}
else if (type_ == "collectionSize")
{
if (page.getCollectionSize() == 0)
{
ss << singlePrefix_ << page.getCollectionSize() << pluralPostfix_;
}
else if (page.getCollectionSize() == 1)
{
ss << singlePrefix_ << page.getCollectionSize() << singlePostfix_;
}
else
{
ss << pluralPrefix_ << page.getCollectionSize() << pluralPostfix_;
}
}
else if (type_ == "collectionIndex")
{
if (page.getSelectedIndex() == 0)
{
ss << singlePrefix_ << (page.getSelectedIndex()+1) << pluralPostfix_;
}
else if (page.getSelectedIndex() == 1)
{
ss << singlePrefix_ << (page.getSelectedIndex()+1) << singlePostfix_;
}
else
{
ss << pluralPrefix_ << (page.getSelectedIndex()+1) << pluralPostfix_;
}
}
else if (type_ == "collectionIndexSize")
{
if (page.getSelectedIndex() == 0)
{
ss << singlePrefix_ << (page.getSelectedIndex()+1) << "/" << page.getCollectionSize() << pluralPostfix_;
}
else if (page.getSelectedIndex() == 1)
{
ss << singlePrefix_ << (page.getSelectedIndex()+1) << "/" << page.getCollectionSize() << singlePostfix_;
}
else
{
ss << pluralPrefix_ << (page.getSelectedIndex()+1) << "/" << page.getCollectionSize() << pluralPostfix_;
}
}
else if (!selectedItem->leaf) // item is not a leaf
{
(void)config_.getProperty("collections." + selectedItem->name + "." + type_, text );
}
if (text == "0")
{
text = singlePrefix_ + text + pluralPostfix_;
}
else if (text == "1")
{
text = singlePrefix_ + text + singlePostfix_;
}
else if (text != "")
{
text = pluralPrefix_ + text + pluralPostfix_;
}
if (text != "")
{
if (textFormat_ == "uppercase")
{
std::transform(text.begin(), text.end(), text.begin(), ::toupper);
}
if (textFormat_ == "lowercase")
{
std::transform(text.begin(), text.end(), text.begin(), ::tolower);
}
ss << text;
text_.push_back(ss.str());
}
}
}

View File

@ -24,12 +24,12 @@
class ReloadableScrollingText : public Component
{
public:
ReloadableScrollingText(Configuration &config, bool systemMode, bool layoutMode, std::string type, std::string textFormat, std::string alignment, Page &page, int displayOffset, Font *font, float scaleX, float scaleY, std::string direction, float scrollingSpeed, float startPosition, float startTime, float endTime );
ReloadableScrollingText(Configuration &config, bool systemMode, bool layoutMode, std::string type, std::string textFormat, std::string singlePrefix, std::string singlePostfix, std::string pluralPrefix, std::string pluralPostfix, std::string alignment, Page &page, int displayOffset, Font *font, float scaleX, float scaleY, std::string direction, float scrollingSpeed, float startPosition, float startTime, float endTime );
virtual ~ReloadableScrollingText( );
void update(float dt);
void draw( );
void freeGraphicsMemory( );
void launchExit();
void launchExit();
private:
void reloadTexture( );
@ -40,6 +40,10 @@ private:
Font *fontInst_;
std::string type_;
std::string textFormat_;
std::string singlePrefix_;
std::string singlePostfix_;
std::string pluralPrefix_;
std::string pluralPostfix_;
std::string alignment_;
std::vector<std::string> text_;
float scaleX_;

View File

@ -600,7 +600,27 @@ void PageBuilder::loadReloadableImages(xml_node<> *layout, std::string tagName,
{
alignment = alignmentXml->value();
}
c = new ReloadableScrollingText(config_, systemMode, layoutMode, type->value(), textFormat, alignment, *page, selectedOffset, font, scaleX_, scaleY_, direction, scrollingSpeed, startPosition, startTime, endTime);
std::string singlePrefix = "";
if (singlePrefixXml)
{
singlePrefix = singlePrefixXml->value();
}
std::string singlePostfix = "";
if (singlePostfixXml)
{
singlePostfix = singlePostfixXml->value();
}
std::string pluralPrefix = "";
if (pluralPrefixXml)
{
pluralPrefix = pluralPrefixXml->value();
}
std::string pluralPostfix = "";
if (pluralPostfixXml)
{
pluralPostfix = pluralPostfixXml->value();
}
c = new ReloadableScrollingText(config_, systemMode, layoutMode, type->value(), singlePrefix, singlePostfix, pluralPrefix, pluralPostfix, textFormat, alignment, *page, selectedOffset, font, scaleX_, scaleY_, direction, scrollingSpeed, startPosition, startTime, endTime);
}
}
else

View File

@ -20,7 +20,7 @@
std::string retrofe_version_major = "0";
std::string retrofe_version_minor = "8";
std::string retrofe_version_build = "3";
std::string retrofe_version_build = "4";
std::string Version::getString()