(svn r1167) Feature: Added the possibility to add validation functions to NewsItems. This is now done for "Train in depot" messages. Before displaying such a message, it checks if the train really still is in the depot. Can be applied to other news items as well.
This commit is contained in:
13
news_gui.c
13
news_gui.c
@@ -210,7 +210,6 @@ byte increaseIndex(byte i)
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b)
|
||||
{
|
||||
NewsItem *ni;
|
||||
@@ -257,6 +256,14 @@ void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b)
|
||||
w->vscroll.count = _total_news;
|
||||
}
|
||||
|
||||
/* To add a news item with an attached validation function. This validation function
|
||||
* makes sure that the news item is not outdated when the newspaper pops up. */
|
||||
void AddValidatedNewsItem(StringID string, uint32 flags, uint data_a, uint data_b, ValidationProc validation)
|
||||
{
|
||||
AddNewsItem(string, flags, data_a, data_b);
|
||||
_news_items[_latest_news].isValid = validation;
|
||||
}
|
||||
|
||||
// don't show item if it's older than x days
|
||||
static const byte _news_items_age[] = {60, 60, 90, 60, 90, 30, 150, 30, 90, 180};
|
||||
|
||||
@@ -421,6 +428,10 @@ static void MoveToNexItem(void)
|
||||
if (_date - _news_items_age[ni->type] > ni->date)
|
||||
return;
|
||||
|
||||
// execute the validation function to see if this item is still valid
|
||||
if ( ni->isValid != NULL && !ni->isValid(ni->data_a, ni->data_b) )
|
||||
return;
|
||||
|
||||
// show newspaper or send to ticker?
|
||||
if (!HASBIT(_news_display_opt, ni->type) && !(ni->flags & NF_FORCE_BIG))
|
||||
ShowTicker(ni);
|
||||
|
||||
Reference in New Issue
Block a user