Save number of times a message is displayed to the config file.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@8057 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2011-03-25 03:20:21 +00:00
parent 4af41ee77a
commit ff152bfeed
4 changed files with 35 additions and 8 deletions

View File

@ -320,6 +320,7 @@ const core::stringw NetworkHttp::getNextNewsMessage()
// Now we have a message that was finished being // Now we have a message that was finished being
// displayed --> increase display count. // displayed --> increase display count.
m_news.getData()[m_current_news_message].increaseDisplayCount(); m_news.getData()[m_current_news_message].increaseDisplayCount();
updateUserConfigFile();
} }
m_current_news_message++; m_current_news_message++;
if(m_current_news_message >= (int)m_news.getData().size()) if(m_current_news_message >= (int)m_news.getData().size())
@ -331,6 +332,23 @@ const core::stringw NetworkHttp::getNextNewsMessage()
return m; return m;
} // getNextNewsMessage } // getNextNewsMessage
// ----------------------------------------------------------------------------
/** Saves the information about which message was being displayed how often
* to the user config file.
* Note that this function assumes that m_news is already locked!
*/
void NetworkHttp::updateUserConfigFile() const
{
std::ostringstream o;
for(unsigned int i=0; i<m_news.getData().size(); i++)
{
const NewsMessage &n=m_news.getData()[i];
o << n.getMessageId() << ":"
<< n.getDisplayCount() << " ";
}
UserConfigParams::m_display_count = o.str();
} // updateUserConfigFile
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
size_t NetworkHttp::writeStr(char ptr [], size_t size, size_t nb_char, size_t NetworkHttp::writeStr(char ptr [], size_t size, size_t nb_char,

View File

@ -70,6 +70,10 @@ private:
const core::stringw& getNews() const {return m_news;} const core::stringw& getNews() const {return m_news;}
/** Increases how often this message was being displayed. */ /** Increases how often this message was being displayed. */
void increaseDisplayCount() {m_display_count++;} void increaseDisplayCount() {m_display_count++;}
/** Returns the news id. */
int getMessageId() const {return m_message_id;}
/** Returns the display count. */
int getDisplayCount() const {return m_display_count; }
}; // NewsMessage }; // NewsMessage
mutable Synchronised< std::vector<NewsMessage> > m_news; mutable Synchronised< std::vector<NewsMessage> > m_news;
@ -108,6 +112,7 @@ private:
void updateNews(const XMLNode *xml, void updateNews(const XMLNode *xml,
const std::string &filename); const std::string &filename);
void updateUserConfigFile() const;
void loadAddonsList(const XMLNode *xml, void loadAddonsList(const XMLNode *xml,
const std::string &filename); const std::string &filename);
std::string downloadToStrInternal(std::string url); std::string downloadToStrInternal(std::string url);

View File

@ -432,6 +432,11 @@ namespace UserConfigParams
&m_addon_group, &m_addon_group,
"How often news should be updated.") ); "How often news should be updated.") );
PARAM_PREFIX StringUserConfigParam m_display_count
PARAM_DEFAULT( StringUserConfigParam("", "news_display_count",
&m_addon_group,
"How often all news messages have been displayed") );
PARAM_PREFIX TimeUserConfigParam m_addons_last_updated PARAM_PREFIX TimeUserConfigParam m_addons_last_updated
PARAM_DEFAULT( TimeUserConfigParam(0, "addon_last_updated", PARAM_DEFAULT( TimeUserConfigParam(0, "addon_last_updated",
&m_addon_group, &m_addon_group,

View File

@ -107,7 +107,7 @@ void LabelWidget::add()
IGUIFont* font = m_title_font ? GUIEngine::getTitleFont() IGUIFont* font = m_title_font ? GUIEngine::getTitleFont()
: GUIEngine::getFont(); : GUIEngine::getFont();
core::dimension2du r = font->getDimension(getText().c_str()); core::dimension2du r = font->getDimension(getText().c_str());
m_scroll_offset = r.Width; m_scroll_offset = (float)r.Width;
} }
} // add } // add
@ -128,7 +128,7 @@ void LabelWidget::setText(const wchar_t *text)
if (m_scroll_speed > 0) if (m_scroll_speed > 0)
{ {
m_scroll_offset = m_element->getAbsolutePosition().getWidth(); m_scroll_offset = (float)m_element->getAbsolutePosition().getWidth();
} }
Widget::setText(text); Widget::setText(text);
@ -142,11 +142,9 @@ void LabelWidget::update(float dt)
{ {
if (m_scroll_speed != 0) if (m_scroll_speed != 0)
{ {
m_scroll_offset -= dt*m_scroll_speed*5.0f; m_scroll_offset -= dt*m_scroll_speed*5.0f;
m_element->setRelativePosition( core::position2di( /*m_x +*/ (int)m_scroll_offset,
//printf("m_scroll_offset = %f; x = %f\n", m_scroll_offset, m_x + m_scroll_offset); /*m_y*/ 0 ) );
m_element->setRelativePosition( core::position2di( /*m_x +*/ m_scroll_offset, /*m_y*/ 0 ) );
} }
} // update } // update
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -162,7 +160,8 @@ bool LabelWidget::scrolledOff() const
/** Sets horizontal scroll speed. */ /** Sets horizontal scroll speed. */
void LabelWidget::setScrollSpeed(float speed) void LabelWidget::setScrollSpeed(float speed)
{ {
m_scroll_offset = -m_element->getAbsolutePosition().getWidth() - 10; // start scrolled off // start scrolled off
m_scroll_offset = (float)(-m_element->getAbsolutePosition().getWidth()-10);
m_scroll_speed = speed; m_scroll_speed = speed;
} // setScrollSpeed } // setScrollSpeed