src/news_gui.cpp
branchcpp_gui
changeset 6235 5077e6ed3788
parent 6144 5a0ffbf27ced
child 6237 bce32e54c993
equal deleted inserted replaced
6234:42bf2d268a86 6235:5077e6ed3788
   112 
   112 
   113 static void NewsWindowProc(Window *w, WindowEvent *e)
   113 static void NewsWindowProc(Window *w, WindowEvent *e)
   114 {
   114 {
   115 	switch (e->event) {
   115 	switch (e->event) {
   116 	case WE_CREATE: { /* If chatbar is open at creation time, we need to go above it */
   116 	case WE_CREATE: { /* If chatbar is open at creation time, we need to go above it */
   117 		const Window *w1 = FindWindowById(WC_SEND_NETWORK_MSG, 0);
   117 		const Window *w1 = Window::FindById(WC_SEND_NETWORK_MSG, 0);
   118 		w->message.msg = (w1 != NULL) ? w1->height : 0;
   118 		w->message.msg = (w1 != NULL) ? w1->height : 0;
   119 	} break;
   119 	} break;
   120 
   120 
   121 	case WE_PAINT: {
   121 	case WE_PAINT: {
   122 		const NewsItem *ni = WP(w, news_d).ni;
   122 		const NewsItem *ni = WP(w, news_d).ni;
   177 
   177 
   178 	case WE_CLICK: {
   178 	case WE_CLICK: {
   179 		switch (e->we.click.widget) {
   179 		switch (e->we.click.widget) {
   180 		case 1: {
   180 		case 1: {
   181 			NewsItem *ni = WP(w, news_d).ni;
   181 			NewsItem *ni = WP(w, news_d).ni;
   182 			DeleteWindow(w);
   182 			w->Close();
   183 			ni->duration = 0;
   183 			ni->duration = 0;
   184 			_forced_news = INVALID_NEWS;
   184 			_forced_news = INVALID_NEWS;
   185 		} break;
   185 		} break;
   186 		case 0: {
   186 		case 0: {
   187 			NewsItem *ni = WP(w, news_d).ni;
   187 			NewsItem *ni = WP(w, news_d).ni;
   198 
   198 
   199 	case WE_KEYPRESS:
   199 	case WE_KEYPRESS:
   200 		if (e->we.keypress.keycode == WKC_SPACE) {
   200 		if (e->we.keypress.keycode == WKC_SPACE) {
   201 			// Don't continue.
   201 			// Don't continue.
   202 			e->we.keypress.cont = false;
   202 			e->we.keypress.cont = false;
   203 			DeleteWindow(w);
   203 			w->Close();
   204 		}
   204 		}
   205 		break;
   205 		break;
   206 
   206 
   207 	case WE_MESSAGE: /* The chatbar has notified us that is was either created or closed */
   207 	case WE_MESSAGE: /* The chatbar has notified us that is was either created or closed */
   208 		switch (e->we.message.msg) {
   208 		switch (e->we.message.msg) {
   307 		ni->data_a = data_a;
   307 		ni->data_a = data_a;
   308 		ni->data_b = data_b;
   308 		ni->data_b = data_b;
   309 		ni->date = _date;
   309 		ni->date = _date;
   310 		COPY_OUT_DPARAM(ni->params, 0, lengthof(ni->params));
   310 		COPY_OUT_DPARAM(ni->params, 0, lengthof(ni->params));
   311 
   311 
   312 		w = FindWindowById(WC_MESSAGE_HISTORY, 0);
   312 		w = Window::FindById(WC_MESSAGE_HISTORY, 0);
   313 		if (w == NULL) return;
   313 		if (w == NULL) return;
   314 		SetWindowDirty(w);
   314 		w->SetDirty();
   315 		w->vscroll.count = _total_news;
   315 		w->vscroll.count = _total_news;
   316 	}
   316 	}
   317 }
   317 }
   318 
   318 
   319 
   319 
   455 	Window *w;
   455 	Window *w;
   456 
   456 
   457 	if (_news_ticker_sound) SndPlayFx(SND_16_MORSE);
   457 	if (_news_ticker_sound) SndPlayFx(SND_16_MORSE);
   458 
   458 
   459 	_statusbar_news_item = *ni;
   459 	_statusbar_news_item = *ni;
   460 	w = FindWindowById(WC_STATUS_BAR, 0);
   460 	w = Window::FindById(WC_STATUS_BAR, 0);
   461 	if (w != NULL) WP(w, def_d).data_1 = 360;
   461 	if (w != NULL) WP(w, def_d).data_1 = 360;
   462 }
   462 }
   463 
   463 
   464 
   464 
   465 // Are we ready to show another news item?
   465 // Are we ready to show another news item?
   473 	if (item >= MAX_NEWS) return true;
   473 	if (item >= MAX_NEWS) return true;
   474 	ni = &_news_items[item];
   474 	ni = &_news_items[item];
   475 
   475 
   476 	// Ticker message
   476 	// Ticker message
   477 	// Check if the status bar message is still being displayed?
   477 	// Check if the status bar message is still being displayed?
   478 	w = FindWindowById(WC_STATUS_BAR, 0);
   478 	w = Window::FindById(WC_STATUS_BAR, 0);
   479 	if (w != NULL && WP(w, const def_d).data_1 > -1280) return false;
   479 	if (w != NULL && WP(w, const def_d).data_1 > -1280) return false;
   480 
   480 
   481 	// Newspaper message, decrement duration counter
   481 	// Newspaper message, decrement duration counter
   482 	if (ni->duration != 0) ni->duration--;
   482 	if (ni->duration != 0) ni->duration--;
   483 
   483 
   484 	// neither newsticker nor newspaper are running
   484 	// neither newsticker nor newspaper are running
   485 	return (ni->duration == 0 || FindWindowById(WC_NEWS_WINDOW, 0) == NULL);
   485 	return (ni->duration == 0 || Window::FindById(WC_NEWS_WINDOW, 0) == NULL);
   486 }
   486 }
   487 
   487 
   488 static void MoveToNextItem(void)
   488 static void MoveToNextItem(void)
   489 {
   489 {
   490 	DeleteWindowById(WC_NEWS_WINDOW, 0);
   490 	DeleteWindowById(WC_NEWS_WINDOW, 0);
   500 		// check the date, don't show too old items
   500 		// check the date, don't show too old items
   501 		if (_date - _news_items_age[ni->type] > ni->date) return;
   501 		if (_date - _news_items_age[ni->type] > ni->date) return;
   502 
   502 
   503 		switch (GetNewsDisplayValue(ni->type)) {
   503 		switch (GetNewsDisplayValue(ni->type)) {
   504 		case 0: { /* Off - show nothing only a small reminder in the status bar */
   504 		case 0: { /* Off - show nothing only a small reminder in the status bar */
   505 			Window *w = FindWindowById(WC_STATUS_BAR, 0);
   505 			Window *w = Window::FindById(WC_STATUS_BAR, 0);
   506 
   506 
   507 			if (w != NULL) {
   507 			if (w != NULL) {
   508 				WP(w, def_d).data_2 = 91;
   508 				WP(w, def_d).data_2 = 91;
   509 				SetWindowDirty(w);
   509 				w->SetDirty();
   510 			}
   510 			}
   511 			break;
   511 			break;
   512 		}
   512 		}
   513 
   513 
   514 		case 1: /* Summary - show ticker, but if forced big, cascade to full */
   514 		case 1: /* Summary - show ticker, but if forced big, cascade to full */
   556 void ShowLastNewsMessage(void)
   556 void ShowLastNewsMessage(void)
   557 {
   557 {
   558 	if (_forced_news == INVALID_NEWS) {
   558 	if (_forced_news == INVALID_NEWS) {
   559 		/* Not forced any news yet, show the current one, unless a news window is
   559 		/* Not forced any news yet, show the current one, unless a news window is
   560 		 * open (which can only be the current one), then show the previous item */
   560 		 * open (which can only be the current one), then show the previous item */
   561 		const Window *w = FindWindowById(WC_NEWS_WINDOW, 0);
   561 		const Window *w = Window::FindById(WC_NEWS_WINDOW, 0);
   562 		ShowNewsMessage((w == NULL || (_current_news == _oldest_news)) ? _current_news : decreaseIndex(_current_news));
   562 		ShowNewsMessage((w == NULL || (_current_news == _oldest_news)) ? _current_news : decreaseIndex(_current_news));
   563 	} else if (_forced_news == _oldest_news) {
   563 	} else if (_forced_news == _oldest_news) {
   564 		/* We have reached the oldest news, start anew with the latest */
   564 		/* We have reached the oldest news, start anew with the latest */
   565 		ShowNewsMessage(_latest_news);
   565 		ShowNewsMessage(_latest_news);
   566 	} else {
   566 	} else {
   705 		w->vscroll.count = _total_news;
   705 		w->vscroll.count = _total_news;
   706 		w->resize.step_height = 12;
   706 		w->resize.step_height = 12;
   707 		w->resize.height = w->height - 12 * 6; // minimum of 4 items in the list, each item 12 high
   707 		w->resize.height = w->height - 12 * 6; // minimum of 4 items in the list, each item 12 high
   708 		w->resize.step_width = 1;
   708 		w->resize.step_width = 1;
   709 		w->resize.width = 200; // can't make window any smaller than 200 pixel
   709 		w->resize.width = 200; // can't make window any smaller than 200 pixel
   710 		SetWindowDirty(w);
   710 		w->SetDirty();
   711 	}
   711 	}
   712 }
   712 }
   713 
   713 
   714 /** Setup the disabled/enabled buttons in the message window
   714 /** Setup the disabled/enabled buttons in the message window
   715  * If the value is 'off' disable the [<] widget, and enable the [>] one
   715  * If the value is 'off' disable the [<] widget, and enable the [>] one
   774 				SetMessageButtonStates(w, val, element);
   774 				SetMessageButtonStates(w, val, element);
   775 				SetNewsDisplayValue(element, val);
   775 				SetNewsDisplayValue(element, val);
   776 
   776 
   777 				WP(w, def_d).data_1 |= (1 << element);
   777 				WP(w, def_d).data_1 |= (1 << element);
   778 				w->flags4 |= 5 << WF_TIMEOUT_SHL; // XXX - setup unclick (fake widget)
   778 				w->flags4 |= 5 << WF_TIMEOUT_SHL; // XXX - setup unclick (fake widget)
   779 				SetWindowDirty(w);
   779 				w->SetDirty();
   780 			}
   780 			}
   781 			break;
   781 			break;
   782 		case 23: case 24: /* Dropdown menu for all settings */
   782 		case 23: case 24: /* Dropdown menu for all settings */
   783 			ShowDropDownMenu(w, message_opt, WP(w, def_d).data_2, 24, 0, 0);
   783 			ShowDropDownMenu(w, message_opt, WP(w, def_d).data_2, 24, 0, 0);
   784 			break;
   784 			break;
   793 				int element = (wid - 3) / 2;
   793 				int element = (wid - 3) / 2;
   794 				byte val = (GetNewsDisplayValue(element) + ((wid & 1) ? -1 : 1)) % 3;
   794 				byte val = (GetNewsDisplayValue(element) + ((wid & 1) ? -1 : 1)) % 3;
   795 
   795 
   796 				SetMessageButtonStates(w, val, element);
   796 				SetMessageButtonStates(w, val, element);
   797 				SetNewsDisplayValue(element, val);
   797 				SetNewsDisplayValue(element, val);
   798 				SetWindowDirty(w);
   798 				w->SetDirty();
   799 			}
   799 			}
   800 		} break;
   800 		} break;
   801 		} break;
   801 		} break;
   802 
   802 
   803 	case WE_DROPDOWN_SELECT: {/* Select all settings for newsmessages */
   803 	case WE_DROPDOWN_SELECT: {/* Select all settings for newsmessages */
   807 
   807 
   808 		for (i = 0; i != 10; i++) {
   808 		for (i = 0; i != 10; i++) {
   809 			SB(_news_display_opt, i*2, 2, e->we.dropdown.index);
   809 			SB(_news_display_opt, i*2, 2, e->we.dropdown.index);
   810 			SetMessageButtonStates(w, e->we.dropdown.index, i);
   810 			SetMessageButtonStates(w, e->we.dropdown.index, i);
   811 		}
   811 		}
   812 		SetWindowDirty(w);
   812 		w->SetDirty();
   813 		break;
   813 		break;
   814 		}
   814 		}
   815 
   815 
   816 	case WE_TIMEOUT: /* XXX - Hack to animate 'fake' buttons */
   816 	case WE_TIMEOUT: /* XXX - Hack to animate 'fake' buttons */
   817 		WP(w, def_d).data_1 = 0;
   817 		WP(w, def_d).data_1 = 0;
   818 		SetWindowDirty(w);
   818 		w->SetDirty();
   819 		break;
   819 		break;
   820 	}
   820 	}
   821 }
   821 }
   822 
   822 
   823 static const Widget _message_options_widgets[] = {
   823 static const Widget _message_options_widgets[] = {
   910 			 * will become (change dramatized to make clear)
   910 			 * will become (change dramatized to make clear)
   911 			 * [---------O-----------L--]
   911 			 * [---------O-----------L--]
   912 			 * We also need an update of the current, forced and visible (open window)
   912 			 * We also need an update of the current, forced and visible (open window)
   913 			 * news's as this shifting could change the items they were pointing to */
   913 			 * news's as this shifting could change the items they were pointing to */
   914 			if (_total_news != 0) {
   914 			if (_total_news != 0) {
   915 				w = FindWindowById(WC_NEWS_WINDOW, 0);
   915 				w = Window::FindById(WC_NEWS_WINDOW, 0);
   916 				NewsID visible_news = (w != NULL) ? (NewsID)(WP(w, news_d).ni - _news_items) : INVALID_NEWS;
   916 				NewsID visible_news = (w != NULL) ? (NewsID)(WP(w, news_d).ni - _news_items) : INVALID_NEWS;
   917 
   917 
   918 				for (NewsID i = n;; i = decreaseIndex(i)) {
   918 				for (NewsID i = n;; i = decreaseIndex(i)) {
   919 					_news_items[i] = _news_items[decreaseIndex(i)];
   919 					_news_items[i] = _news_items[decreaseIndex(i)];
   920 
   920 
   930 			}
   930 			}
   931 
   931 
   932 			/*DEBUG(misc, 0, "-cur %3d, old %2d, lat %3d, for %3d, tot %2d",
   932 			/*DEBUG(misc, 0, "-cur %3d, old %2d, lat %3d, for %3d, tot %2d",
   933 			  _current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/
   933 			  _current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/
   934 
   934 
   935 			w = FindWindowById(WC_MESSAGE_HISTORY, 0);
   935 			w = Window::FindById(WC_MESSAGE_HISTORY, 0);
   936 			if (w != NULL) {
   936 			if (w != NULL) {
   937 				SetWindowDirty(w);
   937 				w->SetDirty();
   938 				w->vscroll.count = _total_news;
   938 				w->vscroll.count = _total_news;
   939 			}
   939 			}
   940 		}
   940 		}
   941 
   941 
   942 		if (n == _latest_news) break;
   942 		if (n == _latest_news) break;