diff options
author | dominik <dominik@openttd.org> | 2004-12-19 09:39:19 +0000 |
---|---|---|
committer | dominik <dominik@openttd.org> | 2004-12-19 09:39:19 +0000 |
commit | bb5dca016ddbd7d21373c052cefa96f894e1e2fc (patch) | |
tree | 67065372ddab844b0eca1fb7b664f60f5c1d957a /news_gui.c | |
parent | cf89cb12cd49333fba3b72001f52f1032c036f62 (diff) | |
download | openttd-bb5dca016ddbd7d21373c052cefa96f894e1e2fc.tar.xz |
(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.
Diffstat (limited to 'news_gui.c')
-rw-r--r-- | news_gui.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/news_gui.c b/news_gui.c index af804f226..b9f7e8286 100644 --- a/news_gui.c +++ b/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); |