Changeset - r5595:baebc9e54b71
[Not reviewed]
master
0 1 0
Darkvater - 17 years ago 2007-01-11 01:21:55
darkvater@openttd.org
(svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
one MoveToNextItem() in DeleteVehicleNews (added in r3757). To work correctly do not
reset _forced_news to INVALID_NEWS when a new item is added, but leave it.
-Codechange: ShowLastNewsMessage has been changed so that it actually works, wraps
around correctly (array as FIFO) and shows the previous news item if the current
news item is open (previously this was doubly shown).
1 file changed with 23 insertions and 21 deletions:
0 comments (0 inline, 0 general)
src/news_gui.cpp
Show inline comments
 
@@ -273,7 +273,6 @@ void AddNewsItem(StringID string, uint32
 
	if (_total_news == MAX_NEWS && (_oldest_news == _current_news || _oldest_news == _forced_news))
 
		MoveToNextItem();
 

	
 
	_forced_news = INVALID_NEWS;
 
	if (_total_news < MAX_NEWS) _total_news++;
 

	
 
	/* Increase _latest_news. If we have no news yet, use _oldest news as an
 
@@ -288,8 +287,8 @@ void AddNewsItem(StringID string, uint32
 
		_oldest_news = increaseIndex(_oldest_news);
 
	}
 

	
 
	/*DEBUG(misc, 0) ("+cur %3d, old %2d, lat %3d, for %3d, tot %2d",
 
	  _current_news, _oldest_news, _latest_news, _forced_news, _total_news); */
 
	/*DEBUG(misc, 0, "+cur %3d, old %2d, lat %3d, for %3d, tot %2d",
 
	  _current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/
 

	
 
	{ /* Add news to _latest_news */
 
		Window *w;
 
@@ -443,8 +442,8 @@ static void ShowNewspaper(NewsItem *ni)
 
		}
 
	}
 

	
 
	/*DEBUG(misc, 0) (" cur %3d, old %2d, lat %3d, for %3d, tot %2d",
 
	  _current_news, _oldest_news, _latest_news, _forced_news, _total_news); */
 
	/*DEBUG(misc, 0, " cur %3d, old %2d, lat %3d, for %3d, tot %2d",
 
	  _current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/
 

	
 
	WP(w, news_d).ni = &_news_items[_forced_news == INVALID_NEWS ? _current_news : _forced_news];
 
	w->flags4 |= WF_DISABLE_VP_SCROLL;
 
@@ -556,16 +555,17 @@ static void ShowNewsMessage(NewsID i)
 

	
 
void ShowLastNewsMessage(void)
 
{
 
	switch (_forced_news) {
 
		case INVALID_NEWS: // Not forced any news yet, show the current one
 
			ShowNewsMessage(_current_news);
 
			break;
 
		case 0: //
 
			ShowNewsMessage(_total_news != MAX_NEWS ? _latest_news : MAX_NEWS - 1);
 
			break;
 
		default: // 'Scrolling' through news history show each one in turn
 
			ShowNewsMessage(_forced_news - 1);
 
			break;
 
	if (_forced_news == INVALID_NEWS) {
 
		/* Not forced any news yet, show the current one, unless a news window is
 
		 * open (which can only be the current one), then show the previous item */
 
		const Window *w = FindWindowById(WC_NEWS_WINDOW, 0);
 
		ShowNewsMessage((w == NULL) ? _current_news : decreaseIndex(_current_news));
 
	} else if (_forced_news == _oldest_news) {
 
		/* We have reached the oldest news, start anew with the latest */
 
		ShowNewsMessage(_latest_news);
 
	} else {
 
		/* 'Scrolling' through news history show each one in turn */
 
		ShowNewsMessage(decreaseIndex(_forced_news));
 
	}
 
}
 

	
 
@@ -890,7 +890,10 @@ void DeleteVehicleNews(VehicleID vid, St
 
				(news == INVALID_STRING_ID || ni->string_id == news)) {
 
			Window *w;
 

	
 
			if (_forced_news == n || _current_news == n) MoveToNextItem();
 
			/* If we delete a forced news and it is just before the current news
 
			 * then we need to advance to the next news (if any) */
 
			if (_forced_news == n) MoveToNextItem();
 
			if (_forced_news == INVALID_NEWS && _current_news == n) MoveToNextItem();
 
			_total_news--;
 

	
 
			/* If this is the last news item, invalidate _latest_news */
 
@@ -909,11 +912,10 @@ void DeleteVehicleNews(VehicleID vid, St
 
			 * We also need an update of the current, forced and visible (open window)
 
			 * news's as this shifting could change the items they were pointing to */
 
			if (_total_news != 0) {
 
				NewsID i, visible_news;
 
				w = FindWindowById(WC_NEWS_WINDOW, 0);
 
				visible_news = (w != NULL) ? (NewsID)(WP(w, news_d).ni - _news_items) : INVALID_NEWS;
 
				NewsID visible_news = (w != NULL) ? (NewsID)(WP(w, news_d).ni - _news_items) : INVALID_NEWS;
 

	
 
				for (i = n;; i = decreaseIndex(i)) {
 
				for (NewsID i = n;; i = decreaseIndex(i)) {
 
					_news_items[i] = _news_items[decreaseIndex(i)];
 

	
 
					if (i == _current_news) _current_news = increaseIndex(_current_news);
 
@@ -925,8 +927,8 @@ void DeleteVehicleNews(VehicleID vid, St
 
				_oldest_news = increaseIndex(_oldest_news);
 
			}
 

	
 
			/*DEBUG(misc, 0) ("-cur %3d, old %2d, lat %3d, for %3d, tot %2d",
 
			  _current_news, _oldest_news, _latest_news, _forced_news, _total_news); */
 
			/*DEBUG(misc, 0, "-cur %3d, old %2d, lat %3d, for %3d, tot %2d",
 
			  _current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/
 

	
 
			w = FindWindowById(WC_MESSAGE_HISTORY, 0);
 
			if (w != NULL) {
0 comments (0 inline, 0 general)