(svn r13345) -Codechange: only one of all the NewsItem's instance duration variable, so move it so there is only once instance of that variable. Patch by Cirdan.
authorrubidium
Fri, 30 May 2008 20:57:19 +0000
changeset 9430 345e3005810d
parent 9429 5657213ac57f
child 9431 ce662bc7151b
(svn r13345) -Codechange: only one of all the NewsItem's instance duration variable, so move it so there is only once instance of that variable. Patch by Cirdan.
src/news_gui.cpp
src/news_type.h
--- a/src/news_gui.cpp	Fri May 30 20:08:32 2008 +0000
+++ b/src/news_gui.cpp	Fri May 30 20:57:19 2008 +0000
@@ -168,9 +168,11 @@
 struct NewsWindow : Window {
 	uint16 chat_height;
 	NewsItem *ni;
+	static uint duration;
 
 	NewsWindow(const WindowDesc *desc, NewsItem *ni) : Window(desc), ni(ni)
 	{
+		NewsWindow::duration = 555;
 		const Window *w = FindWindowById(WC_SEND_NETWORK_MSG, 0);
 		this->chat_height = (w != NULL) ? w->height : 0;
 
@@ -258,7 +260,7 @@
 	{
 		switch (widget) {
 			case 1:
-				this->ni->duration = 0;
+				NewsWindow::duration = 0;
 				delete this;
 				_forced_news = NULL;
 				break;
@@ -314,6 +316,8 @@
 	}
 };
 
+/* static */ uint NewsWindow::duration; ///< Remaining time for showing current news message
+
 
 static const Widget _news_type13_widgets[] = {
 {      WWT_PANEL,   RESIZE_NONE,    15,     0,   429,     0,   169, 0x0, STR_NULL},
@@ -361,7 +365,6 @@
 static void ShowNewspaper(NewsItem *ni)
 {
 	ni->flags &= ~NF_FORCE_BIG;
-	ni->duration = 555;
 
 	SoundFx sound = _news_type_data[_news_subtype_data[ni->subtype].type].sound;
 	if (sound != 0) SndPlayFx(sound);
@@ -438,10 +441,10 @@
 	if (IsNewsTickerShown()) return false;
 
 	/* Newspaper message, decrement duration counter */
-	if (ni->duration != 0) ni->duration--;
+	if (NewsWindow::duration != 0) NewsWindow::duration--;
 
 	/* neither newsticker nor newspaper are running */
-	return (ni->duration == 0 || FindWindowById(WC_NEWS_WINDOW, 0) == NULL);
+	return (NewsWindow::duration == 0 || FindWindowById(WC_NEWS_WINDOW, 0) == NULL);
 }
 
 /** Move to the next news item */
@@ -613,7 +616,7 @@
 	_forced_news = ni;
 
 	if (_forced_news != NULL) {
-		ni->duration = 555;
+		NewsWindow::duration = 555;
 		ni->flags |= NF_FORCE_BIG;
 		DeleteWindowById(WC_NEWS_WINDOW, 0);
 		ShowNewspaper(ni);
--- a/src/news_type.h	Fri May 30 20:08:32 2008 +0000
+++ b/src/news_type.h	Fri May 30 20:57:19 2008 +0000
@@ -104,7 +104,6 @@
 	NewsItem *prev;        ///< Previous news item
 	NewsItem *next;        ///< Next news item
 	StringID string_id;    ///< Message text
-	uint16 duration;       ///< Remaining time for showing this news message
 	Date date;             ///< Date of the news
 	NewsSubtype subtype;   ///< News subtype @see NewsSubtype
 	NewsFlag flags;        ///< NewsFlags bits @see NewsFlag