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 };
326 str = this->GetCompanyMessageString();
331 str = this->GetNewVehicleMessageString(widget);
346 d.width = (d.width >= padding.width) ? d.width - padding.width : 0;
347 d.height = (d.height >= padding.height) ? d.height - padding.height : 0;
349 d.width += padding.width;
350 d.height += padding.height;
367 this->DrawNewsBorder(r);
457 if (keycode == WKC_SPACE) {
472 if (!gui_scope)
return;
482 int newtop =
max(this->
top - 4, _screen.height - this->height - this->status_height - this->chat_height);
493 if (this->
top == newtop)
return;
495 int mintop =
min(newtop, this->
top);
496 int maxtop =
max(newtop, this->
top);
503 StringID GetCompanyMessageString()
const
510 StringID GetNewVehicleMessageString(
int widget)
const
518 return STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE;
522 return STR_NEWS_NEW_VEHICLE_TYPE;
547 _statusbar_news_item = ni;
554 for (
NewsItem *ni = _oldest_news; ni != NULL; ) {
564 _current_news = NULL;
565 _statusbar_news_item = NULL;
566 NewsWindow::duration = 0;
576 if (ni == NULL)
return true;
583 if (NewsWindow::duration != 0) NewsWindow::duration--;
595 _statusbar_news_item = NULL;
598 if (_current_news != _latest_news) {
599 _current_news = (_current_news == NULL) ? _oldest_news : _current_news->
next;
604 if (
_date - _news_type_data[type].age > ni->date)
return;
606 switch (_news_type_data[type].GetDisplay()) {
607 default: NOT_REACHED();
638 if (_game_mode == GM_MENU)
return;
659 assert(_oldest_news == NULL);
663 assert(_latest_news->
next == NULL);
664 _latest_news->
next = ni;
742 if (ni->
prev != NULL) {
745 assert(_oldest_news == ni);
746 _oldest_news = ni->
next;
749 if (ni->
next != NULL) {
752 assert(_latest_news == ni);
753 _latest_news = ni->
prev;
758 if (_forced_news == ni || _current_news == ni || _statusbar_news_item == ni) {
761 if (_current_news == ni) _current_news = ni->
prev;
845 static void RemoveOldNewsItems()
862 for (
NewsItem *ni = _oldest_news; ni != NULL; ni = ni->
next) {
863 if (ni->reftype1 ==
NR_VEHICLE && ni->ref1 == from_index) ni->ref1 = to_index;
864 if (ni->reftype2 ==
NR_VEHICLE && ni->ref2 == from_index) ni->ref2 = to_index;
865 if (ni->flags &
NF_VEHICLE_PARAM0 && ni->params[0] == from_index) ni->params[0] = to_index;
879 static byte _last_clean_month = 0;
882 RemoveOldNewsItems();
900 if (_forced_news != NULL) {
912 }
else if (_forced_news == NULL) {
915 if (_current_news == NULL) {
921 ni = (w == NULL || (_current_news ==
_oldest_news)) ? _current_news : _current_news->
prev;
923 }
else if (_forced_news == _oldest_news) {
928 ni = _forced_news->
prev;
960 char buffer[512], buffer2[512];
966 GetString(buffer, str,
lastof(buffer));
969 const char *ptr = buffer;
970 char *dest = buffer2;
973 WChar c = Utf8Consume(&ptr);
976 if (c ==
'\n' && c_last !=
'\n') {
979 }
else if (c ==
'\r') {
980 dest[0] = dest[1] = dest[2] = dest[3] =
' ';
982 }
else if (IsPrintable(c)) {
1014 resize->height = this->line_height;
1022 size->width =
max(200u, size->width);
1040 if (ni == NULL)
return;
1049 uint news_right = rtl ? r.right - WD_FRAMERECT_RIGHT - this->date_width - WD_FRAMERECT_RIGHT : r.right -
WD_FRAMERECT_RIGHT;
1052 DrawString(date_left, date_right, y, STR_SHORT_DATE);
1055 y += this->line_height;
1058 if (ni == NULL)
return;
1069 if (!gui_scope)
return;
1077 if (ni == NULL)
return;
1081 if (ni == NULL)
return;
1097 static const NWidgetPart _nested_message_history[] = {
1107 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_MH_BACKGROUND),
SetMinimalSize(200, 125),
SetDataTip(0x0, STR_MESSAGE_HISTORY_TOOLTIP),
SetResize(1, 12),
SetScrollbar(
WID_MH_SCROLLBAR),
1120 _nested_message_history,
lengthof(_nested_message_history)