39 #include "table/strings.h"
43 const NewsItem *_statusbar_news_item = NULL;
80 static const NWidgetPart _nested_normal_news_widgets[] = {
98 _nested_normal_news_widgets,
lengthof(_nested_normal_news_widgets)
102 static const NWidgetPart _nested_vehicle_news_widgets[] = {
125 _nested_vehicle_news_widgets,
lengthof(_nested_vehicle_news_widgets)
129 static const NWidgetPart _nested_company_news_widgets[] = {
153 _nested_company_news_widgets,
lengthof(_nested_company_news_widgets)
157 static const NWidgetPart _nested_thin_news_widgets[] = {
167 NWidget(
WWT_EMPTY, COLOUR_WHITE,
WID_N_MESSAGE),
SetMinimalSize(428, 48),
SetFill(1, 0),
SetPadding(0, 5, 0, 5),
176 _nested_thin_news_widgets,
lengthof(_nested_thin_news_widgets)
180 static const NWidgetPart _nested_small_news_widgets[] = {
190 NWidget(
NWID_VIEWPORT, INVALID_COLOUR,
WID_N_VIEWPORT),
SetPadding(1, 1, 1, 1),
SetMinimalSize(274, 47),
SetFill(1, 0),
192 NWidget(
WWT_EMPTY, COLOUR_WHITE,
WID_N_MESSAGE),
SetMinimalSize(275, 20),
SetFill(1, 0),
SetPadding(0, 5, 0, 5),
200 _nested_small_news_widgets,
lengthof(_nested_small_news_widgets)
217 assert(layout <
lengthof(_news_window_layout));
218 return _news_window_layout[layout];
226 NewsTypeData(
"news_display.arrival_player", 60, SND_1D_APPLAUSE ),
227 NewsTypeData(
"news_display.arrival_other", 60, SND_1D_APPLAUSE ),
229 NewsTypeData(
"news_display.company_info", 60, SND_BEGIN ),
233 NewsTypeData(
"news_display.production_player", 30, SND_BEGIN ),
234 NewsTypeData(
"news_display.production_other", 30, SND_BEGIN ),
235 NewsTypeData(
"news_display.production_nobody", 30, SND_BEGIN ),
237 NewsTypeData(
"news_display.new_vehicles", 30, SND_1E_OOOOH ),
238 NewsTypeData(
"news_display.acceptance", 90, SND_BEGIN ),
239 NewsTypeData(
"news_display.subsidies", 180, SND_BEGIN ),
277 if (desc == &_company_news_desc) this->GetWidget<NWidgetCore>(
WID_N_TITLE)->widget_data = this->ni->
params[0];
279 this->FinishInitNested(0);
296 void DrawNewsBorder(
const Rect &r)
const
308 Point pt = { 0, _screen.height };
321 *size =
maxdim(*size, d2);
335 str = this->GetCompanyMessageString();
340 str = this->GetNewVehicleMessageString(widget);
355 d.width = (d.width >= padding.width) ? d.width - padding.width : 0;
356 d.height = (d.height >= padding.height) ? d.height - padding.height : 0;
358 d.width += padding.width;
359 d.height += padding.height;
376 this->DrawNewsBorder(r);
466 if (keycode == WKC_SPACE) {
481 if (!gui_scope)
return;
491 int newtop =
max(this->
top - 4, _screen.height - this->height - this->status_height - this->chat_height);
502 if (this->
top == newtop)
return;
504 int mintop =
min(newtop, this->
top);
505 int maxtop =
max(newtop, this->
top);
512 StringID GetCompanyMessageString()
const
519 StringID GetNewVehicleMessageString(
int widget)
const
527 return STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE;
531 return STR_NEWS_NEW_VEHICLE_TYPE;
556 _statusbar_news_item = ni;
563 for (
NewsItem *ni = _oldest_news; ni != NULL; ) {
573 _current_news = NULL;
574 _statusbar_news_item = NULL;
575 NewsWindow::duration = 0;
585 if (ni == NULL)
return true;
592 if (NewsWindow::duration != 0) NewsWindow::duration--;
604 _statusbar_news_item = NULL;
607 if (_current_news != _latest_news) {
608 _current_news = (_current_news == NULL) ? _oldest_news : _current_news->
next;
613 if (
_date - _news_type_data[type].age > ni->date)
return;
615 switch (_news_type_data[type].GetDisplay()) {
616 default: NOT_REACHED();
647 if (_game_mode == GM_MENU)
return;
668 assert(_oldest_news == NULL);
672 assert(_latest_news->
next == NULL);
673 _latest_news->
next = ni;
751 if (ni->
prev != NULL) {
754 assert(_oldest_news == ni);
755 _oldest_news = ni->
next;
758 if (ni->
next != NULL) {
761 assert(_latest_news == ni);
762 _latest_news = ni->
prev;
767 if (_forced_news == ni || _current_news == ni || _statusbar_news_item == ni) {
770 if (_current_news == ni) _current_news = ni->
prev;
854 static void RemoveOldNewsItems()
871 for (
NewsItem *ni = _oldest_news; ni != NULL; ni = ni->
next) {
872 if (ni->reftype1 ==
NR_VEHICLE && ni->ref1 == from_index) ni->ref1 = to_index;
873 if (ni->reftype2 ==
NR_VEHICLE && ni->ref2 == from_index) ni->ref2 = to_index;
874 if (ni->flags &
NF_VEHICLE_PARAM0 && ni->params[0] == from_index) ni->params[0] = to_index;
888 static byte _last_clean_month = 0;
891 RemoveOldNewsItems();
909 if (_forced_news != NULL) {
921 }
else if (_forced_news == NULL) {
924 if (_current_news == NULL) {
930 ni = (w == NULL || (_current_news ==
_oldest_news)) ? _current_news : _current_news->
prev;
932 }
else if (_forced_news == _oldest_news) {
937 ni = _forced_news->
prev;
969 char buffer[512], buffer2[512];
975 GetString(buffer, str,
lastof(buffer));
978 const char *ptr = buffer;
979 char *dest = buffer2;
982 WChar c = Utf8Consume(&ptr);
985 if (c ==
'\n' && c_last !=
'\n') {
988 }
else if (c ==
'\r') {
989 dest[0] = dest[1] = dest[2] = dest[3] =
' ';
991 }
else if (IsPrintable(c)) {
1023 resize->height = this->line_height;
1031 size->width =
max(200u, size->width);
1049 if (ni == NULL)
return;
1058 uint news_right = rtl ? r.right - WD_FRAMERECT_RIGHT - this->date_width - WD_FRAMERECT_RIGHT : r.right -
WD_FRAMERECT_RIGHT;
1061 DrawString(date_left, date_right, y, STR_SHORT_DATE);
1064 y += this->line_height;
1067 if (ni == NULL)
return;
1078 if (!gui_scope)
return;
1086 if (ni == NULL)
return;
1090 if (ni == NULL)
return;
1106 static const NWidgetPart _nested_message_history[] = {
1116 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_MH_BACKGROUND),
SetMinimalSize(200, 125),
SetDataTip(0x0, STR_MESSAGE_HISTORY_TOOLTIP),
SetResize(1, 12),
SetScrollbar(
WID_MH_SCROLLBAR),
1129 _nested_message_history,
lengthof(_nested_message_history)