src/news_gui.cpp
changeset 6247 7d81e3a5d803
parent 6209 3a1a90cd67f3
child 6279 fdae79bd4dc7
equal deleted inserted replaced
6246:75451000349d 6247:7d81e3a5d803
    53 
    53 
    54 static byte _total_news = 0; // total news count
    54 static byte _total_news = 0; // total news count
    55 
    55 
    56 void DrawNewsNewVehicleAvail(Window *w);
    56 void DrawNewsNewVehicleAvail(Window *w);
    57 void DrawNewsBankrupcy(Window *w);
    57 void DrawNewsBankrupcy(Window *w);
    58 static void MoveToNextItem(void);
    58 static void MoveToNextItem();
    59 
    59 
    60 StringID GetNewsStringNewVehicleAvail(const NewsItem *ni);
    60 StringID GetNewsStringNewVehicleAvail(const NewsItem *ni);
    61 StringID GetNewsStringBankrupcy(const NewsItem *ni);
    61 StringID GetNewsStringBankrupcy(const NewsItem *ni);
    62 
    62 
    63 static DrawNewsCallbackProc * const _draw_news_callback[] = {
    63 static DrawNewsCallbackProc * const _draw_news_callback[] = {
    69 GetNewsStringCallbackProc * const _get_news_string_callback[] = {
    69 GetNewsStringCallbackProc * const _get_news_string_callback[] = {
    70 	GetNewsStringNewVehicleAvail,  /* DNC_VEHICLEAVAIL */
    70 	GetNewsStringNewVehicleAvail,  /* DNC_VEHICLEAVAIL */
    71 	GetNewsStringBankrupcy,        /* DNC_BANKRUPCY */
    71 	GetNewsStringBankrupcy,        /* DNC_BANKRUPCY */
    72 };
    72 };
    73 
    73 
    74 void InitNewsItemStructs(void)
    74 void InitNewsItemStructs()
    75 {
    75 {
    76 	memset(_news_items, 0, sizeof(_news_items));
    76 	memset(_news_items, 0, sizeof(_news_items));
    77 	_current_news = INVALID_NEWS;
    77 	_current_news = INVALID_NEWS;
    78 	_oldest_news = 0;
    78 	_oldest_news = 0;
    79 	_latest_news = INVALID_NEWS;
    79 	_latest_news = INVALID_NEWS;
   450 }
   450 }
   451 
   451 
   452 
   452 
   453 // Are we ready to show another news item?
   453 // Are we ready to show another news item?
   454 // Only if nothing is in the newsticker and no newspaper is displayed
   454 // Only if nothing is in the newsticker and no newspaper is displayed
   455 static bool ReadyForNextItem(void)
   455 static bool ReadyForNextItem()
   456 {
   456 {
   457 	const Window *w;
   457 	const Window *w;
   458 	NewsID item = (_forced_news == INVALID_NEWS) ? _current_news : _forced_news;
   458 	NewsID item = (_forced_news == INVALID_NEWS) ? _current_news : _forced_news;
   459 	NewsItem *ni;
   459 	NewsItem *ni;
   460 
   460 
   471 
   471 
   472 	// neither newsticker nor newspaper are running
   472 	// neither newsticker nor newspaper are running
   473 	return (ni->duration == 0 || FindWindowById(WC_NEWS_WINDOW, 0) == NULL);
   473 	return (ni->duration == 0 || FindWindowById(WC_NEWS_WINDOW, 0) == NULL);
   474 }
   474 }
   475 
   475 
   476 static void MoveToNextItem(void)
   476 static void MoveToNextItem()
   477 {
   477 {
   478 	DeleteWindowById(WC_NEWS_WINDOW, 0);
   478 	DeleteWindowById(WC_NEWS_WINDOW, 0);
   479 	_forced_news = INVALID_NEWS;
   479 	_forced_news = INVALID_NEWS;
   480 
   480 
   481 	// if we're not at the last item, then move on
   481 	// if we're not at the last item, then move on
   511 			break;
   511 			break;
   512 		}
   512 		}
   513 	}
   513 	}
   514 }
   514 }
   515 
   515 
   516 void NewsLoop(void)
   516 void NewsLoop()
   517 {
   517 {
   518 	// no news item yet
   518 	// no news item yet
   519 	if (_total_news == 0) return;
   519 	if (_total_news == 0) return;
   520 
   520 
   521 	if (ReadyForNextItem()) MoveToNextItem();
   521 	if (ReadyForNextItem()) MoveToNextItem();
   539 		DeleteWindowById(WC_NEWS_WINDOW, 0);
   539 		DeleteWindowById(WC_NEWS_WINDOW, 0);
   540 		ShowNewspaper(ni);
   540 		ShowNewspaper(ni);
   541 	}
   541 	}
   542 }
   542 }
   543 
   543 
   544 void ShowLastNewsMessage(void)
   544 void ShowLastNewsMessage()
   545 {
   545 {
   546 	if (_forced_news == INVALID_NEWS) {
   546 	if (_forced_news == INVALID_NEWS) {
   547 		/* Not forced any news yet, show the current one, unless a news window is
   547 		/* Not forced any news yet, show the current one, unless a news window is
   548 		 * open (which can only be the current one), then show the previous item */
   548 		 * open (which can only be the current one), then show the previous item */
   549 		const Window *w = FindWindowById(WC_NEWS_WINDOW, 0);
   549 		const Window *w = FindWindowById(WC_NEWS_WINDOW, 0);
   679 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
   679 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
   680 	_message_history_widgets,
   680 	_message_history_widgets,
   681 	MessageHistoryWndProc
   681 	MessageHistoryWndProc
   682 };
   682 };
   683 
   683 
   684 void ShowMessageHistory(void)
   684 void ShowMessageHistory()
   685 {
   685 {
   686 	Window *w;
   686 	Window *w;
   687 
   687 
   688 	DeleteWindowById(WC_MESSAGE_HISTORY, 0);
   688 	DeleteWindowById(WC_MESSAGE_HISTORY, 0);
   689 	w = AllocateWindowDesc(&_message_history_desc);
   689 	w = AllocateWindowDesc(&_message_history_desc);
   857 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
   857 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
   858 	_message_options_widgets,
   858 	_message_options_widgets,
   859 	MessageOptionsWndProc
   859 	MessageOptionsWndProc
   860 };
   860 };
   861 
   861 
   862 void ShowMessageOptions(void)
   862 void ShowMessageOptions()
   863 {
   863 {
   864 	DeleteWindowById(WC_GAME_OPTIONS, 0);
   864 	DeleteWindowById(WC_GAME_OPTIONS, 0);
   865 	AllocateWindowDesc(&_message_options_desc);
   865 	AllocateWindowDesc(&_message_options_desc);
   866 }
   866 }
   867 
   867