Added popup window to show a news message that has
'important="true"' specified. The message is only shown once. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@12345 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
24bb92f761
commit
57a29ff15c
@ -109,6 +109,8 @@ void NewsManager::updateNews(const XMLNode *xml, const std::string &filename)
|
|||||||
node->get("content", &news);
|
node->get("content", &news);
|
||||||
int id=-1;
|
int id=-1;
|
||||||
node->get("id", &id);
|
node->get("id", &id);
|
||||||
|
bool important=false;
|
||||||
|
node->get("important", &important);
|
||||||
|
|
||||||
std::string cond;
|
std::string cond;
|
||||||
node->get("condition", &cond);
|
node->get("condition", &cond);
|
||||||
@ -125,7 +127,7 @@ void NewsManager::updateNews(const XMLNode *xml, const std::string &filename)
|
|||||||
if(id>UserConfigParams::m_ignore_message_id)
|
if(id>UserConfigParams::m_ignore_message_id)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
NewsMessage n(core::stringw(news.c_str()), id);
|
NewsMessage n(core::stringw(news.c_str()), id, important);
|
||||||
m_news.getData().push_back(n);
|
m_news.getData().push_back(n);
|
||||||
}
|
}
|
||||||
} // m_news.lock()
|
} // m_news.lock()
|
||||||
@ -165,6 +167,40 @@ void NewsManager::addNewsMessage(const core::stringw &s)
|
|||||||
m_news.getData().push_back(n);
|
m_news.getData().push_back(n);
|
||||||
m_news.unlock();
|
m_news.unlock();
|
||||||
} // addNewsMessage
|
} // addNewsMessage
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
/** Returns the important message with the smallest id that has not been
|
||||||
|
* shown, or NULL if no important (not shown before) message exists atm. The
|
||||||
|
* user config is updated to store the last important message id shown.
|
||||||
|
*/
|
||||||
|
const core::stringw NewsManager::getImportantMessage()
|
||||||
|
{
|
||||||
|
int index = -1;
|
||||||
|
m_news.lock();
|
||||||
|
for(unsigned int i=0; i<m_news.getData().size(); i++)
|
||||||
|
{
|
||||||
|
const NewsMessage &m = m_news.getData()[i];
|
||||||
|
//
|
||||||
|
if(m.isImportant() &&
|
||||||
|
m.getMessageId()>UserConfigParams::m_last_important_message_id &&
|
||||||
|
(index == -1 ||
|
||||||
|
m.getMessageId() < m_news.getData()[index].getMessageId() ) )
|
||||||
|
{
|
||||||
|
index = i;
|
||||||
|
} // if new unshown important message with smaller message id
|
||||||
|
}
|
||||||
|
core::stringw message("");
|
||||||
|
if(index>=0)
|
||||||
|
{
|
||||||
|
const NewsMessage &m = m_news.getData()[index];
|
||||||
|
message = m.getNews();
|
||||||
|
UserConfigParams::m_last_important_message_id = m.getMessageId();
|
||||||
|
|
||||||
|
}
|
||||||
|
m_news.unlock();
|
||||||
|
|
||||||
|
return message;
|
||||||
|
} // getImportantMessage
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
/** Returns the next loaded news message. It will 'wrap around', i.e.
|
/** Returns the next loaded news message. It will 'wrap around', i.e.
|
||||||
* if there is only one message it will be returned over and over again.
|
* if there is only one message it will be returned over and over again.
|
||||||
|
@ -39,19 +39,23 @@ private:
|
|||||||
// a message id and a display count.
|
// a message id and a display count.
|
||||||
class NewsMessage
|
class NewsMessage
|
||||||
{
|
{
|
||||||
// The actual news message
|
/** The actual news message. */
|
||||||
core::stringw m_news;
|
core::stringw m_news;
|
||||||
// A message id used to store some information in the
|
/** A message id used to store some information in the
|
||||||
// user config file.
|
* user config file. */
|
||||||
int m_message_id;
|
int m_message_id;
|
||||||
// Counts how often a message has been displayed.
|
/** Counts how often a message has been displayed. */
|
||||||
int m_display_count;
|
int m_display_count;
|
||||||
|
/** True if this is an important (i.e. popup) message. */
|
||||||
|
bool m_important;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NewsMessage(const core::stringw &m, int id)
|
NewsMessage(const core::stringw &m, int id, bool important=false)
|
||||||
{
|
{
|
||||||
m_news = m;
|
m_news = m;
|
||||||
m_message_id = id;
|
m_message_id = id;
|
||||||
m_display_count = 0;
|
m_display_count = 0;
|
||||||
|
m_important = important;
|
||||||
} // NewsMessage
|
} // NewsMessage
|
||||||
/** Returns the news message. */
|
/** Returns the news message. */
|
||||||
const core::stringw& getNews() const {return m_news;}
|
const core::stringw& getNews() const {return m_news;}
|
||||||
@ -63,6 +67,8 @@ private:
|
|||||||
int getDisplayCount() const {return m_display_count; }
|
int getDisplayCount() const {return m_display_count; }
|
||||||
/** Sets the display count for this message. */
|
/** Sets the display count for this message. */
|
||||||
void setDisplayCount(int n) {m_display_count = n; }
|
void setDisplayCount(int n) {m_display_count = n; }
|
||||||
|
/** Returns if this is an important message. */
|
||||||
|
bool isImportant() const { return m_important; }
|
||||||
}; // NewsMessage
|
}; // NewsMessage
|
||||||
|
|
||||||
mutable Synchronised< std::vector<NewsMessage> > m_news;
|
mutable Synchronised< std::vector<NewsMessage> > m_news;
|
||||||
@ -90,6 +96,8 @@ public:
|
|||||||
~NewsManager();
|
~NewsManager();
|
||||||
const core::stringw
|
const core::stringw
|
||||||
getNextNewsMessage();
|
getNextNewsMessage();
|
||||||
|
const core::stringw
|
||||||
|
getImportantMessage();
|
||||||
void init();
|
void init();
|
||||||
void addNewsMessage(const core::stringw &s);
|
void addNewsMessage(const core::stringw &s);
|
||||||
|
|
||||||
|
@ -586,6 +586,12 @@ namespace UserConfigParams
|
|||||||
"Ignore all messages with this "
|
"Ignore all messages with this "
|
||||||
"id and lower") );
|
"id and lower") );
|
||||||
|
|
||||||
|
PARAM_PREFIX IntUserConfigParam m_last_important_message_id
|
||||||
|
PARAM_DEFAULT( IntUserConfigParam(-1, "last_important_message_id",
|
||||||
|
&m_addon_group,
|
||||||
|
"Don't show important message "
|
||||||
|
"with this or a lower id again") );
|
||||||
|
|
||||||
PARAM_PREFIX IntUserConfigParam m_internet_status
|
PARAM_PREFIX IntUserConfigParam m_internet_status
|
||||||
PARAM_DEFAULT( IntUserConfigParam(0, "enable_internet",
|
PARAM_DEFAULT( IntUserConfigParam(0, "enable_internet",
|
||||||
&m_addon_group,
|
&m_addon_group,
|
||||||
|
12
src/main.cpp
12
src/main.cpp
@ -1387,6 +1387,18 @@ int main(int argc, char *argv[] )
|
|||||||
StateManager::get()->enterGameState();
|
StateManager::get()->enterGameState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// If an important news message exists it is shown in a popup dialog.
|
||||||
|
const core::stringw important_message =
|
||||||
|
news_manager->getImportantMessage();
|
||||||
|
if(important_message!="")
|
||||||
|
{
|
||||||
|
new MessageDialog(important_message,
|
||||||
|
MessageDialog::MESSAGE_DIALOG_OK,
|
||||||
|
NULL, true);
|
||||||
|
} // if important_message
|
||||||
|
|
||||||
|
|
||||||
// Replay a race
|
// Replay a race
|
||||||
// =============
|
// =============
|
||||||
if(history->replayHistory())
|
if(history->replayHistory())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user