Changeset - r24823:6a09ecd63560
[Not reviewed]
master
0 1 0
Jonathan G Rennison - 3 years ago 2021-02-18 11:17:51
j.g.rennison@gmail.com
Fix: Unnecessary status bar redraws when there is no news to show (#8691)

InvalidateWindowData with mode SBI_NEWS_DELETED was called on the
status bar when checking for a new item of news to be shown in the
ticker, even if there is no news queued and no change occurs.
1 file changed with 1 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/news_gui.cpp
Show inline comments
 
@@ -645,50 +645,48 @@ static bool ReadyForNextTickerItem()
 
	return true;
 
}
 

	
 
/**
 
 * Are we ready to show another news item?
 
 * Only if no newspaper is displayed
 
 */
 
static bool ReadyForNextNewsItem()
 
{
 
	const NewsItem *ni = _forced_news == nullptr ? _current_news : _forced_news;
 
	if (ni == nullptr) return true;
 

	
 
	/* neither newsticker nor newspaper are running */
 
	return (NewsWindow::duration <= 0 || FindWindowById(WC_NEWS_WINDOW, 0) == nullptr);
 
}
 

	
 
/** Move to the next ticker item */
 
static void MoveToNextTickerItem()
 
{
 
	/* There is no status bar, so no reason to show news;
 
	 * especially important with the end game screen when
 
	 * there is no status bar but possible news. */
 
	if (FindWindowById(WC_STATUS_BAR, 0) == nullptr) return;
 

	
 
	InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); // invalidate the statusbar
 

	
 
	/* if we're not at the last item, then move on */
 
	while (_statusbar_news_item != _latest_news) {
 
		_statusbar_news_item = (_statusbar_news_item == nullptr) ? _oldest_news : _statusbar_news_item->next;
 
		const NewsItem *ni = _statusbar_news_item;
 
		const NewsType type = ni->type;
 

	
 
		/* check the date, don't show too old items */
 
		if (_date - _news_type_data[type].age > ni->date) continue;
 

	
 
		switch (_news_type_data[type].GetDisplay()) {
 
			default: NOT_REACHED();
 
			case ND_OFF: // Off - show nothing only a small reminder in the status bar
 
				InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_REMINDER);
 
				break;
 

	
 
			case ND_SUMMARY: // Summary - show ticker
 
				ShowTicker(ni);
 
				break;
 

	
 
			case ND_FULL: // Full - show newspaper, skipped here
 
				continue;
 
		}
 
		return;
 
	}
 
@@ -745,48 +743,49 @@ static void DeleteNewsItem(NewsItem *ni)
 
		ni->next->prev = ni->prev;
 
	} else {
 
		assert(_latest_news == ni);
 
		_latest_news = ni->prev;
 
	}
 

	
 
	_total_news--;
 

	
 
	if (_forced_news == ni || _current_news == ni) {
 
		/* When we're the current news, go to the previous item first;
 
		 * we just possibly made that the last news item. */
 
		if (_current_news == ni) _current_news = ni->prev;
 

	
 
		/* About to remove the currently forced item (shown as newspapers) ||
 
		 * about to remove the currently displayed item (newspapers) */
 
		MoveToNextNewsItem();
 
	}
 

	
 
	if (_statusbar_news_item == ni) {
 
		/* When we're the current news, go to the previous item first;
 
		 * we just possibly made that the last news item. */
 
		_statusbar_news_item = ni->prev;
 

	
 
		/* About to remove the currently displayed item (ticker, or just a reminder) */
 
		InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); // invalidate the statusbar
 
		MoveToNextTickerItem();
 
	}
 

	
 
	delete ni;
 

	
 
	SetWindowDirty(WC_MESSAGE_HISTORY, 0);
 
}
 

	
 
/**
 
 * Add a new newsitem to be shown.
 
 * @param string String to display
 
 * @param type news category
 
 * @param flags display flags for the news
 
 * @param reftype1 Type of ref1
 
 * @param ref1     Reference 1 to some object: Used for a possible viewport, scrolling after clicking on the news, and for deleting the news when the object is deleted.
 
 * @param reftype2 Type of ref2
 
 * @param ref2     Reference 2 to some object: Used for scrolling after clicking on the news, and for deleting the news when the object is deleted.
 
 * @param free_data Pointer to data that must be freed once the news message is cleared
 
 *
 
 * @see NewsSubtype
 
 */
 
void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32 ref1, NewsReferenceType reftype2, uint32 ref2, void *free_data)
 
{
 
	if (_game_mode == GM_MENU) return;
0 comments (0 inline, 0 general)