news_gui.c
changeset 715 28dd55cc55ae
parent 541 625227bb2a3d
child 718 0bb3e204abb5
equal deleted inserted replaced
714:503e96f37d46 715:28dd55cc55ae
   208 	if (i >= MAX_NEWS)
   208 	if (i >= MAX_NEWS)
   209 		i = i % MAX_NEWS;
   209 		i = i % MAX_NEWS;
   210 	return i;
   210 	return i;
   211 }
   211 }
   212 
   212 
   213 
       
   214 void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b)
   213 void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b)
   215 {
   214 {
   216 	NewsItem *ni;
   215 	NewsItem *ni;
   217 	Window *w;
   216 	Window *w;
   218 
   217 
   253 
   252 
   254 	w = FindWindowById(WC_MESSAGE_HISTORY, 0);
   253 	w = FindWindowById(WC_MESSAGE_HISTORY, 0);
   255 	if (w == NULL) return;
   254 	if (w == NULL) return;
   256 	SetWindowDirty(w);
   255 	SetWindowDirty(w);
   257 	w->vscroll.count = _total_news;
   256 	w->vscroll.count = _total_news;
       
   257 }
       
   258 
       
   259 /* To add a news item with an attached validation function. This validation function
       
   260  * makes sure that the news item is not outdated when the newspaper pops up. */
       
   261 void AddValidatedNewsItem(StringID string, uint32 flags, uint data_a, uint data_b, ValidationProc validation)
       
   262 {
       
   263 	AddNewsItem(string, flags, data_a, data_b);
       
   264 	_news_items[_latest_news].isValid = validation;
   258 }
   265 }
   259 
   266 
   260 // don't show item if it's older than x days
   267 // don't show item if it's older than x days
   261 static const byte _news_items_age[] = {60, 60, 90, 60, 90, 30, 150, 30, 90, 180};
   268 static const byte _news_items_age[] = {60, 60, 90, 60, 90, 30, 150, 30, 90, 180};
   262 
   269 
   417 		_current_news = increaseIndex(_current_news);
   424 		_current_news = increaseIndex(_current_news);
   418 		ni = &_news_items[_current_news];
   425 		ni = &_news_items[_current_news];
   419 
   426 
   420 		// check the date, don't show too old items
   427 		// check the date, don't show too old items
   421 		if (_date - _news_items_age[ni->type] > ni->date)
   428 		if (_date - _news_items_age[ni->type] > ni->date)
       
   429 			return;
       
   430 
       
   431 		// execute the validation function to see if this item is still valid
       
   432 		if ( ni->isValid != NULL && !ni->isValid(ni->data_a, ni->data_b) )
   422 			return;
   433 			return;
   423 
   434 
   424 		// show newspaper or send to ticker?
   435 		// show newspaper or send to ticker?
   425 		if (!HASBIT(_news_display_opt, ni->type) && !(ni->flags & NF_FORCE_BIG))
   436 		if (!HASBIT(_news_display_opt, ni->type) && !(ni->flags & NF_FORCE_BIG))
   426 			ShowTicker(ni);
   437 			ShowTicker(ni);