src/news_gui.cpp
branchnoai
changeset 10829 8a0ec0f0f928
parent 10776 07203fc29812
child 10867 5de2923d6e59
equal deleted inserted replaced
10804:a02ab0ca5ae9 10829:8a0ec0f0f928
   166 };
   166 };
   167 
   167 
   168 struct NewsWindow : Window {
   168 struct NewsWindow : Window {
   169 	uint16 chat_height;
   169 	uint16 chat_height;
   170 	NewsItem *ni;
   170 	NewsItem *ni;
       
   171 	static uint duration;
   171 
   172 
   172 	NewsWindow(const WindowDesc *desc, NewsItem *ni) : Window(desc), ni(ni)
   173 	NewsWindow(const WindowDesc *desc, NewsItem *ni) : Window(desc), ni(ni)
   173 	{
   174 	{
       
   175 		NewsWindow::duration = 555;
   174 		const Window *w = FindWindowById(WC_SEND_NETWORK_MSG, 0);
   176 		const Window *w = FindWindowById(WC_SEND_NETWORK_MSG, 0);
   175 		this->chat_height = (w != NULL) ? w->height : 0;
   177 		this->chat_height = (w != NULL) ? w->height : 0;
   176 
   178 
   177 		this->ni = _forced_news == NULL ? _current_news : _forced_news;
   179 		this->ni = _forced_news == NULL ? _current_news : _forced_news;
   178 		this->flags4 |= WF_DISABLE_VP_SCROLL;
   180 		this->flags4 |= WF_DISABLE_VP_SCROLL;
   256 
   258 
   257 	virtual void OnClick(Point pt, int widget)
   259 	virtual void OnClick(Point pt, int widget)
   258 	{
   260 	{
   259 		switch (widget) {
   261 		switch (widget) {
   260 			case 1:
   262 			case 1:
   261 				this->ni->duration = 0;
   263 				NewsWindow::duration = 0;
   262 				delete this;
   264 				delete this;
   263 				_forced_news = NULL;
   265 				_forced_news = NULL;
   264 				break;
   266 				break;
   265 
   267 
   266 			case 0:
   268 			case 0:
   312 
   314 
   313 		SetDirtyBlocks(this->left, this->top - diff, this->left + this->width, this->top + this->height);
   315 		SetDirtyBlocks(this->left, this->top - diff, this->left + this->width, this->top + this->height);
   314 	}
   316 	}
   315 };
   317 };
   316 
   318 
       
   319 /* static */ uint NewsWindow::duration; ///< Remaining time for showing current news message
       
   320 
   317 
   321 
   318 static const Widget _news_type13_widgets[] = {
   322 static const Widget _news_type13_widgets[] = {
   319 {      WWT_PANEL,   RESIZE_NONE,    15,     0,   429,     0,   169, 0x0, STR_NULL},
   323 {      WWT_PANEL,   RESIZE_NONE,    15,     0,   429,     0,   169, 0x0, STR_NULL},
   320 {      WWT_PANEL,   RESIZE_NONE,    15,     0,    10,     0,    11, 0x0, STR_NULL},
   324 {      WWT_PANEL,   RESIZE_NONE,    15,     0,    10,     0,    11, 0x0, STR_NULL},
   321 {   WIDGETS_END},
   325 {   WIDGETS_END},
   358 
   362 
   359 
   363 
   360 /** Open up an own newspaper window for the news item */
   364 /** Open up an own newspaper window for the news item */
   361 static void ShowNewspaper(NewsItem *ni)
   365 static void ShowNewspaper(NewsItem *ni)
   362 {
   366 {
   363 	ni->flags &= ~NF_FORCE_BIG;
       
   364 	ni->duration = 555;
       
   365 
       
   366 	SoundFx sound = _news_type_data[_news_subtype_data[ni->subtype].type].sound;
   367 	SoundFx sound = _news_type_data[_news_subtype_data[ni->subtype].type].sound;
   367 	if (sound != 0) SndPlayFx(sound);
   368 	if (sound != 0) SndPlayFx(sound);
   368 
   369 
   369 	int top = _screen.height;
   370 	int top = _screen.height;
   370 	Window *w;
   371 	Window *w;
   436 	/* Ticker message
   437 	/* Ticker message
   437 	 * Check if the status bar message is still being displayed? */
   438 	 * Check if the status bar message is still being displayed? */
   438 	if (IsNewsTickerShown()) return false;
   439 	if (IsNewsTickerShown()) return false;
   439 
   440 
   440 	/* Newspaper message, decrement duration counter */
   441 	/* Newspaper message, decrement duration counter */
   441 	if (ni->duration != 0) ni->duration--;
   442 	if (NewsWindow::duration != 0) NewsWindow::duration--;
   442 
   443 
   443 	/* neither newsticker nor newspaper are running */
   444 	/* neither newsticker nor newspaper are running */
   444 	return (ni->duration == 0 || FindWindowById(WC_NEWS_WINDOW, 0) == NULL);
   445 	return (NewsWindow::duration == 0 || FindWindowById(WC_NEWS_WINDOW, 0) == NULL);
   445 }
   446 }
   446 
   447 
   447 /** Move to the next news item */
   448 /** Move to the next news item */
   448 static void MoveToNextItem()
   449 static void MoveToNextItem()
   449 {
   450 {
   463 			default: NOT_REACHED();
   464 			default: NOT_REACHED();
   464 			case ND_OFF: // Off - show nothing only a small reminder in the status bar
   465 			case ND_OFF: // Off - show nothing only a small reminder in the status bar
   465 				InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_REMINDER);
   466 				InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_REMINDER);
   466 				break;
   467 				break;
   467 
   468 
   468 			case ND_SUMMARY: // Summary - show ticker, but if forced big, cascade to full
   469 			case ND_SUMMARY: // Summary - show ticker
   469 				if (!(ni->flags & NF_FORCE_BIG)) {
   470 				ShowTicker(ni);
   470 					ShowTicker(ni);
   471 				break;
   471 					break;
       
   472 				}
       
   473 				/* Fallthrough */
       
   474 
   472 
   475 			case ND_FULL: // Full - show newspaper
   473 			case ND_FULL: // Full - show newspaper
   476 				ShowNewspaper(ni);
   474 				ShowNewspaper(ni);
   477 				break;
   475 				break;
   478 		}
   476 		}
   611 
   609 
   612 	/* setup forced news item */
   610 	/* setup forced news item */
   613 	_forced_news = ni;
   611 	_forced_news = ni;
   614 
   612 
   615 	if (_forced_news != NULL) {
   613 	if (_forced_news != NULL) {
   616 		ni->duration = 555;
       
   617 		ni->flags |= NF_FORCE_BIG;
       
   618 		DeleteWindowById(WC_NEWS_WINDOW, 0);
   614 		DeleteWindowById(WC_NEWS_WINDOW, 0);
   619 		ShowNewspaper(ni);
   615 		ShowNewspaper(ni);
   620 	}
   616 	}
   621 }
   617 }
   622 
   618