Update: Translations from eints
[openttd-github.git] / src / news_gui.cpp
blob3ba464b0e501d4e3f69c73f9bba7452eac30d1f8
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /** @file news_gui.cpp GUI functions related to news messages. */
10 #include "stdafx.h"
11 #include "gui.h"
12 #include "viewport_func.h"
13 #include "strings_func.h"
14 #include "window_func.h"
15 #include "vehicle_base.h"
16 #include "vehicle_func.h"
17 #include "vehicle_gui.h"
18 #include "roadveh.h"
19 #include "station_base.h"
20 #include "industry.h"
21 #include "town.h"
22 #include "sound_func.h"
23 #include "string_func.h"
24 #include "statusbar_gui.h"
25 #include "company_manager_face.h"
26 #include "company_func.h"
27 #include "engine_base.h"
28 #include "engine_gui.h"
29 #include "core/geometry_func.hpp"
30 #include "command_func.h"
31 #include "company_base.h"
32 #include "settings_internal.h"
33 #include "group_gui.h"
34 #include "zoom_func.h"
35 #include "news_cmd.h"
36 #include "timer/timer.h"
37 #include "timer/timer_window.h"
38 #include "timer/timer_game_calendar.h"
40 #include "widgets/news_widget.h"
42 #include "table/strings.h"
44 #include "safeguards.h"
46 static const uint MIN_NEWS_AMOUNT = 30; ///< preferred minimum amount of news messages.
47 static const uint MAX_NEWS_AMOUNT = 1U << 10; ///< Do not exceed this number of news messages.
49 static NewsContainer _news; ///< List of news, with newest items at the start.
51 /**
52 * Forced news item.
53 * Users can force an item by accessing the history or "last message".
54 * If the message being shown was forced by the user, an iterater is stored
55 * in _forced_news. Otherwise, \a _forced_news variable is the end of \a _news.
57 static NewsIterator _forced_news = std::end(_news);
59 /** Current news item (last item shown regularly). */
60 static NewsIterator _current_news = std::end(_news);
62 /** Current status bar news item. */
63 static NewsIterator _statusbar_news = std::end(_news);
65 /**
66 * Get pointer to the current status bar news item.
67 * @return Pointer to the current status bar news item, or nullptr if there is none.
69 const NewsItem *GetStatusbarNews()
71 return (_statusbar_news == std::end(_news)) ? nullptr : &*_statusbar_news;
74 /**
75 * Get read-only reference to all news items.
76 * @return Read-only reference to all news items.
78 const NewsContainer &GetNews()
80 return _news;
83 /**
84 * Get the position a news-reference is referencing.
85 * @param reftype The type of reference.
86 * @param ref The reference.
87 * @return A tile for the referenced object, or INVALID_TILE if none.
89 static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32_t ref)
91 switch (reftype) {
92 case NR_TILE: return (TileIndex)ref;
93 case NR_STATION: return Station::Get((StationID)ref)->xy;
94 case NR_INDUSTRY: return Industry::Get((IndustryID)ref)->location.tile + TileDiffXY(1, 1);
95 case NR_TOWN: return Town::Get((TownID)ref)->xy;
96 default: return INVALID_TILE;
100 /* Normal news items. */
101 static constexpr NWidgetPart _nested_normal_news_widgets[] = {
102 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
103 NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
104 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
105 NWidget(NWID_SPACER), SetFill(1, 0),
106 NWidget(NWID_VERTICAL),
107 NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_JUST_DATE_LONG, STR_NULL), SetTextStyle(TC_BLACK, FS_SMALL),
108 NWidget(NWID_SPACER), SetFill(0, 1),
109 EndContainer(),
110 EndContainer(),
111 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(428, 154), SetPadding(0, 5, 1, 5),
112 EndContainer(),
115 static WindowDesc _normal_news_desc(
116 WDP_MANUAL, nullptr, 0, 0,
117 WC_NEWS_WINDOW, WC_NONE,
119 _nested_normal_news_widgets
122 /* New vehicles news items. */
123 static constexpr NWidgetPart _nested_vehicle_news_widgets[] = {
124 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
125 NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
126 NWidget(NWID_VERTICAL),
127 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
128 NWidget(NWID_SPACER), SetFill(0, 1),
129 EndContainer(),
130 NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_VEH_TITLE), SetFill(1, 1), SetMinimalSize(419, 55), SetDataTip(STR_EMPTY, STR_NULL),
131 EndContainer(),
132 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_VEH_BKGND), SetPadding(0, 25, 1, 25),
133 NWidget(NWID_VERTICAL),
134 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_NAME), SetMinimalSize(369, 33), SetFill(1, 0),
135 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_SPR), SetMinimalSize(369, 32), SetFill(1, 0),
136 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_INFO), SetMinimalSize(369, 46), SetFill(1, 0),
137 EndContainer(),
138 EndContainer(),
139 EndContainer(),
142 static WindowDesc _vehicle_news_desc(
143 WDP_MANUAL, nullptr, 0, 0,
144 WC_NEWS_WINDOW, WC_NONE,
146 _nested_vehicle_news_widgets
149 /* Company news items. */
150 static constexpr NWidgetPart _nested_company_news_widgets[] = {
151 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
152 NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
153 NWidget(NWID_VERTICAL),
154 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
155 NWidget(NWID_SPACER), SetFill(0, 1),
156 EndContainer(),
157 NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_TITLE), SetFill(1, 1), SetMinimalSize(410, 20), SetDataTip(STR_EMPTY, STR_NULL),
158 EndContainer(),
159 NWidget(NWID_HORIZONTAL), SetPadding(0, 1, 1, 1),
160 NWidget(NWID_VERTICAL),
161 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MGR_FACE), SetMinimalSize(93, 119), SetPadding(2, 6, 2, 1),
162 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MGR_NAME), SetMinimalSize(93, 24), SetPadding(0, 0, 0, 1),
163 NWidget(NWID_SPACER), SetFill(0, 1),
164 EndContainer(),
165 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_COMPANY_MSG), SetFill(1, 1), SetMinimalSize(328, 150),
166 EndContainer(),
167 EndContainer(),
170 static WindowDesc _company_news_desc(
171 WDP_MANUAL, nullptr, 0, 0,
172 WC_NEWS_WINDOW, WC_NONE,
174 _nested_company_news_widgets
177 /* Thin news items. */
178 static constexpr NWidgetPart _nested_thin_news_widgets[] = {
179 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
180 NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
181 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
182 NWidget(NWID_SPACER), SetFill(1, 0),
183 NWidget(NWID_VERTICAL),
184 NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_JUST_DATE_LONG, STR_NULL), SetTextStyle(TC_BLACK, FS_SMALL),
185 NWidget(NWID_SPACER), SetFill(0, 1),
186 EndContainer(),
187 EndContainer(),
188 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(428, 48), SetFill(1, 0), SetPadding(0, 5, 0, 5),
189 NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetMinimalSize(426, 70), SetPadding(1, 2, 2, 2),
190 EndContainer(),
193 static WindowDesc _thin_news_desc(
194 WDP_MANUAL, nullptr, 0, 0,
195 WC_NEWS_WINDOW, WC_NONE,
197 _nested_thin_news_widgets
200 /* Small news items. */
201 static constexpr NWidgetPart _nested_small_news_widgets[] = {
202 /* Caption + close box. The caption is no WWT_CAPTION as the window shall not be moveable and so on. */
203 NWidget(NWID_HORIZONTAL),
204 NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE, WID_N_CLOSEBOX),
205 NWidget(WWT_EMPTY, COLOUR_LIGHT_BLUE, WID_N_CAPTION), SetFill(1, 0),
206 NWidget(WWT_TEXTBTN, COLOUR_LIGHT_BLUE, WID_N_SHOW_GROUP), SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON), SetResize(1, 0),
207 SetDataTip(STR_NULL /* filled in later */, STR_NEWS_SHOW_VEHICLE_GROUP_TOOLTIP),
208 EndContainer(),
210 /* Main part */
211 NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_N_HEADLINE),
212 NWidget(WWT_INSET, COLOUR_LIGHT_BLUE, WID_N_INSET), SetPadding(2, 2, 2, 2),
213 NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetMinimalSize(274, 47), SetFill(1, 0),
214 EndContainer(),
215 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(275, 20), SetFill(1, 0), SetPadding(0, 5, 0, 5),
216 EndContainer(),
219 static WindowDesc _small_news_desc(
220 WDP_MANUAL, nullptr, 0, 0,
221 WC_NEWS_WINDOW, WC_NONE,
223 _nested_small_news_widgets
227 * Window layouts for news items.
229 static WindowDesc *_news_window_layout[] = {
230 &_thin_news_desc, ///< NF_THIN
231 &_small_news_desc, ///< NF_SMALL
232 &_normal_news_desc, ///< NF_NORMAL
233 &_vehicle_news_desc, ///< NF_VEHICLE
234 &_company_news_desc, ///< NF_COMPANY
237 WindowDesc &GetNewsWindowLayout(NewsFlag flags)
239 uint layout = GB(flags, NFB_WINDOW_LAYOUT, NFB_WINDOW_LAYOUT_COUNT);
240 assert(layout < lengthof(_news_window_layout));
241 return *_news_window_layout[layout];
245 * Per-NewsType data
247 static NewsTypeData _news_type_data[] = {
248 /* name, age, sound, */
249 NewsTypeData("news_display.arrival_player", 60, SND_1D_APPLAUSE ), ///< NT_ARRIVAL_COMPANY
250 NewsTypeData("news_display.arrival_other", 60, SND_1D_APPLAUSE ), ///< NT_ARRIVAL_OTHER
251 NewsTypeData("news_display.accident", 90, SND_BEGIN ), ///< NT_ACCIDENT
252 NewsTypeData("news_display.accident_other", 90, SND_BEGIN ), ///< NT_ACCIDENT_OTHER
253 NewsTypeData("news_display.company_info", 60, SND_BEGIN ), ///< NT_COMPANY_INFO
254 NewsTypeData("news_display.open", 90, SND_BEGIN ), ///< NT_INDUSTRY_OPEN
255 NewsTypeData("news_display.close", 90, SND_BEGIN ), ///< NT_INDUSTRY_CLOSE
256 NewsTypeData("news_display.economy", 30, SND_BEGIN ), ///< NT_ECONOMY
257 NewsTypeData("news_display.production_player", 30, SND_BEGIN ), ///< NT_INDUSTRY_COMPANY
258 NewsTypeData("news_display.production_other", 30, SND_BEGIN ), ///< NT_INDUSTRY_OTHER
259 NewsTypeData("news_display.production_nobody", 30, SND_BEGIN ), ///< NT_INDUSTRY_NOBODY
260 NewsTypeData("news_display.advice", 150, SND_BEGIN ), ///< NT_ADVICE
261 NewsTypeData("news_display.new_vehicles", 30, SND_1E_NEW_ENGINE), ///< NT_NEW_VEHICLES
262 NewsTypeData("news_display.acceptance", 90, SND_BEGIN ), ///< NT_ACCEPTANCE
263 NewsTypeData("news_display.subsidies", 180, SND_BEGIN ), ///< NT_SUBSIDIES
264 NewsTypeData("news_display.general", 60, SND_BEGIN ), ///< NT_GENERAL
267 static_assert(lengthof(_news_type_data) == NT_END);
270 * Return the news display option.
271 * @return display options
273 NewsDisplay NewsTypeData::GetDisplay() const
275 const SettingDesc *sd = GetSettingFromName(this->name);
276 assert(sd != nullptr && sd->IsIntSetting());
277 return (NewsDisplay)sd->AsIntSetting()->Read(nullptr);
280 /** Window class displaying a news item. */
281 struct NewsWindow : Window {
282 uint16_t chat_height; ///< Height of the chat window.
283 uint16_t status_height; ///< Height of the status bar window
284 const NewsItem *ni; ///< News item to display.
285 static int duration; ///< Remaining time for showing the current news message (may only be access while a news item is displayed).
287 NewsWindow(WindowDesc &desc, const NewsItem *ni) : Window(desc), ni(ni)
289 NewsWindow::duration = 16650;
290 const Window *w = FindWindowByClass(WC_SEND_NETWORK_MSG);
291 this->chat_height = (w != nullptr) ? w->height : 0;
292 this->status_height = FindWindowById(WC_STATUS_BAR, 0)->height;
294 this->flags |= WF_DISABLE_VP_SCROLL;
296 this->CreateNestedTree();
298 /* For company news with a face we have a separate headline in param[0] */
299 if (&desc == &_company_news_desc) this->GetWidget<NWidgetCore>(WID_N_TITLE)->widget_data = std::get<uint64_t>(this->ni->params[0]);
301 NWidgetCore *nwid = this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP);
302 if (ni->reftype1 == NR_VEHICLE && nwid != nullptr) {
303 const Vehicle *v = Vehicle::Get(ni->ref1);
304 switch (v->type) {
305 case VEH_TRAIN:
306 nwid->widget_data = STR_TRAIN;
307 break;
308 case VEH_ROAD:
309 nwid->widget_data = RoadVehicle::From(v)->IsBus() ? STR_BUS : STR_LORRY;
310 break;
311 case VEH_SHIP:
312 nwid->widget_data = STR_SHIP;
313 break;
314 case VEH_AIRCRAFT:
315 nwid->widget_data = STR_PLANE;
316 break;
317 default:
318 break; // Do nothing
322 this->FinishInitNested(0);
324 /* Initialize viewport if it exists. */
325 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
326 if (nvp != nullptr) {
327 if (ni->reftype1 == NR_VEHICLE) {
328 nvp->InitializeViewport(this, static_cast<VehicleID>(ni->ref1), ScaleZoomGUI(ZOOM_LVL_NEWS));
329 } else {
330 nvp->InitializeViewport(this, GetReferenceTile(ni->reftype1, ni->ref1), ScaleZoomGUI(ZOOM_LVL_NEWS));
332 if (this->ni->flags & NF_NO_TRANSPARENT) nvp->disp_flags |= ND_NO_TRANSPARENCY;
333 if ((this->ni->flags & NF_INCOLOUR) == 0) {
334 nvp->disp_flags |= ND_SHADE_GREY;
335 } else if (this->ni->flags & NF_SHADE) {
336 nvp->disp_flags |= ND_SHADE_DIMMED;
340 PositionNewsMessage(this);
343 void DrawNewsBorder(const Rect &r) const
345 Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
346 GfxFillRect(ir, PC_WHITE);
348 ir = ir.Expand(1);
349 GfxFillRect( r.left, r.top, ir.left, r.bottom, PC_BLACK);
350 GfxFillRect(ir.right, r.top, r.right, r.bottom, PC_BLACK);
351 GfxFillRect( r.left, r.top, r.right, ir.top, PC_BLACK);
352 GfxFillRect( r.left, ir.bottom, r.right, r.bottom, PC_BLACK);
355 Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
357 Point pt = { 0, _screen.height };
358 return pt;
361 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
363 StringID str = STR_NULL;
364 switch (widget) {
365 case WID_N_CAPTION: {
366 /* Caption is not a real caption (so that the window cannot be moved)
367 * thus it doesn't get the default sizing of a caption. */
368 Dimension d2 = GetStringBoundingBox(STR_NEWS_MESSAGE_CAPTION);
369 d2.height += WidgetDimensions::scaled.captiontext.Vertical();
370 size = maxdim(size, d2);
371 return;
374 case WID_N_MGR_FACE:
375 size = maxdim(size, GetScaledSpriteSize(SPR_GRADIENT));
376 break;
378 case WID_N_MGR_NAME:
379 SetDParamStr(0, static_cast<const CompanyNewsInformation *>(this->ni->data.get())->president_name);
380 str = STR_JUST_RAW_STRING;
381 break;
383 case WID_N_MESSAGE:
384 CopyInDParam(this->ni->params);
385 str = this->ni->string_id;
386 break;
388 case WID_N_COMPANY_MSG:
389 str = this->GetCompanyMessageString();
390 break;
392 case WID_N_VEH_NAME:
393 case WID_N_VEH_TITLE:
394 str = this->GetNewVehicleMessageString(widget);
395 break;
397 case WID_N_VEH_INFO: {
398 assert(this->ni->reftype1 == NR_ENGINE);
399 EngineID engine = this->ni->ref1;
400 str = GetEngineInfoString(engine);
401 break;
404 case WID_N_SHOW_GROUP:
405 if (this->ni->reftype1 == NR_VEHICLE) {
406 Dimension d2 = GetStringBoundingBox(this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP)->widget_data);
407 d2.height += WidgetDimensions::scaled.captiontext.Vertical();
408 d2.width += WidgetDimensions::scaled.captiontext.Horizontal();
409 size = d2;
410 } else {
411 /* Hide 'Show group window' button if this news is not about a vehicle. */
412 size.width = 0;
413 size.height = 0;
414 resize.width = 0;
415 resize.height = 0;
416 fill.width = 0;
417 fill.height = 0;
419 return;
421 default:
422 return; // Do nothing
425 /* Update minimal size with length of the multi-line string. */
426 Dimension d = size;
427 d.width = (d.width >= padding.width) ? d.width - padding.width : 0;
428 d.height = (d.height >= padding.height) ? d.height - padding.height : 0;
429 d = GetStringMultiLineBoundingBox(str, d);
430 d.width += padding.width;
431 d.height += padding.height;
432 size = maxdim(size, d);
435 void SetStringParameters(WidgetID widget) const override
437 if (widget == WID_N_DATE) SetDParam(0, this->ni->date);
440 void DrawWidget(const Rect &r, WidgetID widget) const override
442 switch (widget) {
443 case WID_N_CAPTION:
444 DrawCaption(r, COLOUR_LIGHT_BLUE, this->owner, TC_FROMSTRING, STR_NEWS_MESSAGE_CAPTION, SA_CENTER, FS_NORMAL);
445 break;
447 case WID_N_PANEL:
448 this->DrawNewsBorder(r);
449 break;
451 case WID_N_MESSAGE:
452 CopyInDParam(this->ni->params);
453 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->ni->string_id, TC_FROMSTRING, SA_CENTER);
454 break;
456 case WID_N_MGR_FACE: {
457 const CompanyNewsInformation *cni = static_cast<const CompanyNewsInformation*>(this->ni->data.get());
458 DrawCompanyManagerFace(cni->face, cni->colour, r);
459 GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
460 break;
462 case WID_N_MGR_NAME: {
463 const CompanyNewsInformation *cni = static_cast<const CompanyNewsInformation*>(this->ni->data.get());
464 SetDParamStr(0, cni->president_name);
465 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, STR_JUST_RAW_STRING, TC_FROMSTRING, SA_CENTER);
466 break;
468 case WID_N_COMPANY_MSG:
469 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->GetCompanyMessageString(), TC_FROMSTRING, SA_CENTER);
470 break;
472 case WID_N_VEH_BKGND:
473 GfxFillRect(r.left, r.top, r.right, r.bottom, PC_GREY);
474 break;
476 case WID_N_VEH_NAME:
477 case WID_N_VEH_TITLE:
478 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->GetNewVehicleMessageString(widget), TC_FROMSTRING, SA_CENTER);
479 break;
481 case WID_N_VEH_SPR: {
482 assert(this->ni->reftype1 == NR_ENGINE);
483 EngineID engine = this->ni->ref1;
484 DrawVehicleEngine(r.left, r.right, CenterBounds(r.left, r.right, 0), CenterBounds(r.top, r.bottom, 0), engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
485 GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
486 break;
488 case WID_N_VEH_INFO: {
489 assert(this->ni->reftype1 == NR_ENGINE);
490 EngineID engine = this->ni->ref1;
491 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
492 break;
497 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
499 switch (widget) {
500 case WID_N_CLOSEBOX:
501 NewsWindow::duration = 0;
502 this->Close();
503 _forced_news = std::end(_news);
504 break;
506 case WID_N_CAPTION:
507 if (this->ni->reftype1 == NR_VEHICLE) {
508 const Vehicle *v = Vehicle::Get(this->ni->ref1);
509 ShowVehicleViewWindow(v);
511 break;
513 case WID_N_VIEWPORT:
514 break; // Ignore clicks
516 case WID_N_SHOW_GROUP:
517 if (this->ni->reftype1 == NR_VEHICLE) {
518 const Vehicle *v = Vehicle::Get(this->ni->ref1);
519 ShowCompanyGroupForVehicle(v);
521 break;
522 default:
523 if (this->ni->reftype1 == NR_VEHICLE) {
524 const Vehicle *v = Vehicle::Get(this->ni->ref1);
525 ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos);
526 } else {
527 TileIndex tile1 = GetReferenceTile(this->ni->reftype1, this->ni->ref1);
528 TileIndex tile2 = GetReferenceTile(this->ni->reftype2, this->ni->ref2);
529 if (_ctrl_pressed) {
530 if (tile1 != INVALID_TILE) ShowExtraViewportWindow(tile1);
531 if (tile2 != INVALID_TILE) ShowExtraViewportWindow(tile2);
532 } else {
533 if ((tile1 == INVALID_TILE || !ScrollMainWindowToTile(tile1)) && tile2 != INVALID_TILE) {
534 ScrollMainWindowToTile(tile2);
538 break;
542 void OnResize() override
544 if (this->viewport != nullptr) {
545 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
546 nvp->UpdateViewportCoordinates(this);
548 if (ni->reftype1 != NR_VEHICLE) {
549 ScrollWindowToTile(GetReferenceTile(ni->reftype1, ni->ref1), this, true); // Re-center viewport.
555 * Some data on this window has become invalid.
556 * @param data Information about the changed data.
557 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
559 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
561 if (!gui_scope) return;
562 /* The chatbar has notified us that is was either created or closed */
563 int newtop = this->top + this->chat_height - data;
564 this->chat_height = data;
565 this->SetWindowTop(newtop);
568 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
570 /* Decrement the news timer. We don't need to action an elapsed event here,
571 * so no need to use TimerElapsed(). */
572 if (NewsWindow::duration > 0) NewsWindow::duration -= delta_ms;
576 * Scroll the news message slowly up from the bottom.
578 * The interval of 210ms is chosen to maintain 15ms at normal zoom: 210 / GetCharacterHeight(FS_NORMAL) = 15ms.
580 IntervalTimer<TimerWindow> scroll_interval = {std::chrono::milliseconds(210) / GetCharacterHeight(FS_NORMAL), [this](uint count) {
581 int newtop = std::max(this->top - 2 * static_cast<int>(count), _screen.height - this->height - this->status_height - this->chat_height);
582 this->SetWindowTop(newtop);
585 private:
587 * Moves the window to a new #top coordinate. Makes screen dirty where needed.
588 * @param newtop new top coordinate
590 void SetWindowTop(int newtop)
592 if (this->top == newtop) return;
594 int mintop = std::min(newtop, this->top);
595 int maxtop = std::max(newtop, this->top);
596 if (this->viewport != nullptr) this->viewport->top += newtop - this->top;
597 this->top = newtop;
599 AddDirtyBlock(this->left, mintop, this->left + this->width, maxtop + this->height);
602 StringID GetCompanyMessageString() const
604 /* Company news with a face have a separate headline, so the normal message is shifted by two params */
605 CopyInDParam(std::span(this->ni->params.data() + 2, this->ni->params.size() - 2));
606 return std::get<uint64_t>(this->ni->params[1]);
609 StringID GetNewVehicleMessageString(WidgetID widget) const
611 assert(this->ni->reftype1 == NR_ENGINE);
612 EngineID engine = this->ni->ref1;
614 switch (widget) {
615 case WID_N_VEH_TITLE:
616 SetDParam(0, GetEngineCategoryName(engine));
617 return STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE;
619 case WID_N_VEH_NAME:
620 SetDParam(0, PackEngineNameDParam(engine, EngineNameContext::PreviewNews));
621 return STR_NEWS_NEW_VEHICLE_TYPE;
623 default:
624 NOT_REACHED();
629 /* static */ int NewsWindow::duration = 0; // Instance creation.
631 /** Open up an own newspaper window for the news item */
632 static void ShowNewspaper(const NewsItem *ni)
634 SoundFx sound = _news_type_data[ni->type].sound;
635 if (sound != 0 && _settings_client.sound.news_full) SndPlayFx(sound);
637 new NewsWindow(GetNewsWindowLayout(ni->flags), ni);
640 /** Show news item in the ticker */
641 static void ShowTicker(NewsIterator ni)
643 if (_settings_client.sound.news_ticker) SndPlayFx(SND_16_NEWS_TICKER);
645 _statusbar_news = ni;
646 InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_TICKER);
649 /** Initialize the news-items data structures */
650 void InitNewsItemStructs()
652 _news.clear();
653 _forced_news = std::end(_news);
654 _current_news = std::end(_news);
655 _statusbar_news = std::end(_news);
656 NewsWindow::duration = 0;
660 * Are we ready to show another ticker item?
661 * Only if nothing is in the newsticker is displayed
663 static bool ReadyForNextTickerItem()
665 const NewsItem *ni = GetStatusbarNews();
666 if (ni == nullptr) return true;
668 /* Ticker message
669 * Check if the status bar message is still being displayed? */
670 return !IsNewsTickerShown();
674 * Are we ready to show another news item?
675 * Only if no newspaper is displayed
677 static bool ReadyForNextNewsItem()
679 if (_forced_news == std::end(_news) && _current_news == std::end(_news)) return true;
681 /* neither newsticker nor newspaper are running */
682 return (NewsWindow::duration <= 0 || FindWindowById(WC_NEWS_WINDOW, 0) == nullptr);
685 /** Move to the next ticker item */
686 static void MoveToNextTickerItem()
688 /* There is no status bar, so no reason to show news;
689 * especially important with the end game screen when
690 * there is no status bar but possible news. */
691 if (FindWindowById(WC_STATUS_BAR, 0) == nullptr) return;
693 /* No news to move to. */
694 if (std::empty(_news)) return;
696 /* if we're not at the latest item, then move on */
697 while (_statusbar_news != std::begin(_news)) {
698 --_statusbar_news;
699 const NewsType type = _statusbar_news->type;
701 /* check the date, don't show too old items */
702 if (TimerGameEconomy::date - _news_type_data[type].age > _statusbar_news->economy_date) continue;
704 switch (_news_type_data[type].GetDisplay()) {
705 default: NOT_REACHED();
706 case ND_OFF: // Off - show nothing only a small reminder in the status bar
707 InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_REMINDER);
708 return;
710 case ND_SUMMARY: // Summary - show ticker
711 ShowTicker(_statusbar_news);
712 return;
714 case ND_FULL: // Full - show newspaper, skipped here
715 break;;
720 /** Move to the next news item */
721 static void MoveToNextNewsItem()
723 /* There is no status bar, so no reason to show news;
724 * especially important with the end game screen when
725 * there is no status bar but possible news. */
726 if (FindWindowById(WC_STATUS_BAR, 0) == nullptr) return;
728 CloseWindowById(WC_NEWS_WINDOW, 0); // close the newspapers window if shown
729 _forced_news = std::end(_news);
731 /* No news to move to. */
732 if (std::empty(_news)) return;
734 /* if we're not at the latest item, then move on */
735 while (_current_news != std::begin(_news)) {
736 --_current_news;
737 const NewsType type = _current_news->type;
739 /* check the date, don't show too old items */
740 if (TimerGameEconomy::date - _news_type_data[type].age > _current_news->economy_date) continue;
742 switch (_news_type_data[type].GetDisplay()) {
743 default: NOT_REACHED();
744 case ND_OFF: // Off - show nothing only a small reminder in the status bar, skipped here
745 break;
747 case ND_SUMMARY: // Summary - show ticker, skipped here
748 break;;
750 case ND_FULL: // Full - show newspaper
751 ShowNewspaper(&*_current_news);
752 return;
757 /** Delete a news item from the queue */
758 static std::list<NewsItem>::iterator DeleteNewsItem(std::list<NewsItem>::iterator ni)
760 bool updateCurrentNews = (_forced_news == ni || _current_news == ni);
761 bool updateStatusbarNews = (_statusbar_news == ni);
763 if (updateCurrentNews) {
764 /* When we're the current news, go to the next older item first;
765 * we just possibly made that the last news item. */
766 if (_current_news == ni) ++_current_news;
767 if (_forced_news == ni) _forced_news = std::end(_news);
770 if (updateStatusbarNews) {
771 /* When we're the current news, go to the next older item first;
772 * we just possibly made that the last news item. */
773 ++_statusbar_news;
776 /* Delete the news from the news queue. */
777 ni = _news.erase(ni);
779 if (updateCurrentNews) {
780 /* About to remove the currently forced item (shown as newspapers) ||
781 * about to remove the currently displayed item (newspapers) */
782 MoveToNextNewsItem();
785 if (updateStatusbarNews) {
786 /* About to remove the currently displayed item (ticker, or just a reminder) */
787 InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); // invalidate the statusbar
788 MoveToNextTickerItem();
791 return ni;
795 * Create a new newsitem to be shown.
796 * @param string_id String to display.
797 * @param type The type of news.
798 * @param flags Flags related to how to display the news.
799 * @param reftype1 Type of ref1.
800 * @param ref1 Reference 1 to some object: Used for a possible viewport, scrolling after clicking on the news, and for deleting the news when the object is deleted.
801 * @param reftype2 Type of ref2.
802 * @param ref2 Reference 2 to some object: Used for scrolling after clicking on the news, and for deleting the news when the object is deleted.
803 * @param data Pointer to data that must be released once the news message is cleared.
805 * @see NewsSubtype
807 NewsItem::NewsItem(StringID string_id, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, const NewsAllocatedData *data) :
808 string_id(string_id), date(TimerGameCalendar::date), economy_date(TimerGameEconomy::date), type(type), flags(flags), reftype1(reftype1), reftype2(reftype2), ref1(ref1), ref2(ref2), data(data)
810 /* show this news message in colour? */
811 if (TimerGameCalendar::year >= _settings_client.gui.coloured_news_year) this->flags |= NF_INCOLOUR;
812 CopyOutDParam(this->params, 10);
816 * Add a new newsitem to be shown.
817 * @param string String to display
818 * @param type news category
819 * @param flags display flags for the news
820 * @param reftype1 Type of ref1
821 * @param ref1 Reference 1 to some object: Used for a possible viewport, scrolling after clicking on the news, and for deleting the news when the object is deleted.
822 * @param reftype2 Type of ref2
823 * @param ref2 Reference 2 to some object: Used for scrolling after clicking on the news, and for deleting the news when the object is deleted.
824 * @param data Pointer to data that must be released once the news message is cleared.
826 * @see NewsSubtype
828 void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, const NewsAllocatedData *data)
830 if (_game_mode == GM_MENU) return;
832 /* Create new news item node */
833 _news.emplace_front(string, type, flags, reftype1, ref1, reftype2, ref2, data);
835 /* Keep the number of stored news items to a managable number */
836 if (std::size(_news) > MAX_NEWS_AMOUNT) {
837 DeleteNewsItem(std::prev(std::end(_news)));
840 InvalidateWindowData(WC_MESSAGE_HISTORY, 0);
844 * Create a new custom news item.
845 * @param flags type of operation
846 * @aram type NewsType of the message.
847 * @param reftype1 NewsReferenceType of first reference.
848 * @param company Company this news message is for.
849 * @param reference First reference of the news message.
850 * @param text The text of the news message.
851 * @return the cost of this operation or an error
853 CommandCost CmdCustomNewsItem(DoCommandFlag flags, NewsType type, NewsReferenceType reftype1, CompanyID company, uint32_t reference, const std::string &text)
855 if (_current_company != OWNER_DEITY) return CMD_ERROR;
857 if (company != INVALID_OWNER && !Company::IsValidID(company)) return CMD_ERROR;
858 if (type >= NT_END) return CMD_ERROR;
859 if (text.empty()) return CMD_ERROR;
861 switch (reftype1) {
862 case NR_NONE: break;
863 case NR_TILE:
864 if (!IsValidTile(reference)) return CMD_ERROR;
865 break;
867 case NR_VEHICLE:
868 if (!Vehicle::IsValidID(reference)) return CMD_ERROR;
869 break;
871 case NR_STATION:
872 if (!Station::IsValidID(reference)) return CMD_ERROR;
873 break;
875 case NR_INDUSTRY:
876 if (!Industry::IsValidID(reference)) return CMD_ERROR;
877 break;
879 case NR_TOWN:
880 if (!Town::IsValidID(reference)) return CMD_ERROR;
881 break;
883 case NR_ENGINE:
884 if (!Engine::IsValidID(reference)) return CMD_ERROR;
885 break;
887 default: return CMD_ERROR;
890 if (company != INVALID_OWNER && company != _local_company) return CommandCost();
892 if (flags & DC_EXEC) {
893 NewsStringData *news = new NewsStringData(text);
894 SetDParamStr(0, news->string);
895 AddNewsItem(STR_NEWS_CUSTOM_ITEM, type, NF_NORMAL, reftype1, reference, NR_NONE, UINT32_MAX, news);
898 return CommandCost();
902 * Delete news items by predicate, and invalidate the message history if necessary.
903 * @tparam Tmin Stop if the number of news items remaining reaches \a min items.
904 * @tparam Tpredicate Condition for a news item to be deleted.
906 template <size_t Tmin = 0, class Tpredicate>
907 void DeleteNews(Tpredicate predicate)
909 bool dirty = false;
910 for (auto it = std::rbegin(_news); it != std::rend(_news); /* nothing */) {
911 if constexpr (Tmin > 0) {
912 if (std::size(_news) <= Tmin) break;
914 if (predicate(*it)) {
915 it = std::make_reverse_iterator(DeleteNewsItem(std::prev(it.base())));
916 dirty = true;
917 } else {
918 ++it;
921 if (dirty) InvalidateWindowData(WC_MESSAGE_HISTORY, 0);
925 * Delete a news item type about a vehicle.
926 * When the news item type is INVALID_STRING_ID all news about the vehicle gets deleted.
927 * @param vid The vehicle to remove the news for.
928 * @param news The news type to remove.
930 void DeleteVehicleNews(VehicleID vid, StringID news)
932 DeleteNews([&](const auto &ni) {
933 return ((ni.reftype1 == NR_VEHICLE && ni.ref1 == vid) || (ni.reftype2 == NR_VEHICLE && ni.ref2 == vid)) && (news == INVALID_STRING_ID || ni.string_id == news);
938 * Remove news regarding given station so there are no 'unknown station now accepts Mail'
939 * or 'First train arrived at unknown station' news items.
940 * @param sid station to remove news about
942 void DeleteStationNews(StationID sid)
944 DeleteNews([&](const auto &ni) {
945 return (ni.reftype1 == NR_STATION && ni.ref1 == sid) || (ni.reftype2 == NR_STATION && ni.ref2 == sid);
950 * Remove news regarding given industry
951 * @param iid industry to remove news about
953 void DeleteIndustryNews(IndustryID iid)
955 DeleteNews([&](const auto &ni) {
956 return (ni.reftype1 == NR_INDUSTRY && ni.ref1 == iid) || (ni.reftype2 == NR_INDUSTRY && ni.ref2 == iid);
961 * Remove engine announcements for invalid engines.
963 void DeleteInvalidEngineNews()
965 DeleteNews([](const auto &ni) {
966 return (ni.reftype1 == NR_ENGINE && (!Engine::IsValidID(ni.ref1) || !Engine::Get(ni.ref1)->IsEnabled())) ||
967 (ni.reftype2 == NR_ENGINE && (!Engine::IsValidID(ni.ref2) || !Engine::Get(ni.ref2)->IsEnabled()));
971 static void RemoveOldNewsItems()
973 DeleteNews<MIN_NEWS_AMOUNT>([](const auto &ni) {
974 return TimerGameEconomy::date - _news_type_data[ni.type].age * _settings_client.gui.news_message_timeout > ni.economy_date;
979 * Report a change in vehicle IDs (due to autoreplace) to affected vehicle news.
980 * @note Viewports of currently displayed news is changed via #ChangeVehicleViewports
981 * @param from_index the old vehicle ID
982 * @param to_index the new vehicle ID
984 void ChangeVehicleNews(VehicleID from_index, VehicleID to_index)
986 for (auto &ni : _news) {
987 if (ni.reftype1 == NR_VEHICLE && ni.ref1 == from_index) ni.ref1 = to_index;
988 if (ni.reftype2 == NR_VEHICLE && ni.ref2 == from_index) ni.ref2 = to_index;
989 if (ni.flags & NF_VEHICLE_PARAM0 && std::get<uint64_t>(ni.params[0]) == from_index) ni.params[0] = to_index;
993 void NewsLoop()
995 /* no news item yet */
996 if (std::empty(_news)) return;
998 static TimerGameEconomy::Month _last_clean_month = 0;
1000 if (_last_clean_month != TimerGameEconomy::month) {
1001 RemoveOldNewsItems();
1002 _last_clean_month = TimerGameEconomy::month;
1005 if (ReadyForNextTickerItem()) MoveToNextTickerItem();
1006 if (ReadyForNextNewsItem()) MoveToNextNewsItem();
1009 /** Do a forced show of a specific message */
1010 static void ShowNewsMessage(NewsIterator ni)
1012 assert(!std::empty(_news));
1014 /* Delete the news window */
1015 CloseWindowById(WC_NEWS_WINDOW, 0);
1017 /* setup forced news item */
1018 _forced_news = ni;
1020 if (_forced_news != std::end(_news)) {
1021 CloseWindowById(WC_NEWS_WINDOW, 0);
1022 ShowNewspaper(&*ni);
1027 * Close active news message window
1028 * @return true if a window was closed.
1030 bool HideActiveNewsMessage()
1032 NewsWindow *w = dynamic_cast<NewsWindow *>(FindWindowById(WC_NEWS_WINDOW, 0));
1033 if (w == nullptr) return false;
1034 w->Close();
1035 return true;
1038 /** Show previous news item */
1039 void ShowLastNewsMessage()
1041 if (std::empty(_news)) return;
1043 NewsIterator ni;
1044 if (_forced_news == std::end(_news)) {
1045 /* Not forced any news yet, show the current one, unless a news window is
1046 * open (which can only be the current one), then show the previous item */
1047 if (_current_news == std::end(_news)) {
1048 /* No news were shown yet resp. the last shown one was already deleted.
1049 * Treat this as if _forced_news reached the oldest news; so, wrap around and start anew with the latest. */
1050 ni = std::begin(_news);
1051 } else {
1052 const Window *w = FindWindowById(WC_NEWS_WINDOW, 0);
1053 ni = (w == nullptr || (std::next(_current_news) == std::end(_news))) ? _current_news : std::next(_current_news);
1055 } else if (std::next(_forced_news) == std::end(_news)) {
1056 /* We have reached the oldest news, start anew with the latest */
1057 ni = std::begin(_news);
1058 } else {
1059 /* 'Scrolling' through news history show each one in turn */
1060 ni = std::next(_forced_news);
1062 bool wrap = false;
1063 for (;;) {
1064 if (_news_type_data[ni->type].GetDisplay() != ND_OFF) {
1065 ShowNewsMessage(ni);
1066 break;
1069 ++ni;
1070 if (ni == std::end(_news)) {
1071 if (wrap) break;
1072 /* We have reached the oldest news, start anew with the latest */
1073 ni = std::begin(_news);
1074 wrap = true;
1081 * Draw an unformatted news message truncated to a maximum length. If
1082 * length exceeds maximum length it will be postfixed by '...'
1083 * @param left the left most location for the string
1084 * @param right the right most location for the string
1085 * @param y position of the string
1086 * @param colour the colour the string will be shown in
1087 * @param *ni NewsItem being printed
1089 static void DrawNewsString(uint left, uint right, int y, TextColour colour, const NewsItem *ni)
1091 CopyInDParam(ni->params);
1093 /* Get the string, replaces newlines with spaces and remove control codes from the string. */
1094 std::string message = StrMakeValid(GetString(ni->string_id), SVS_REPLACE_TAB_CR_NL_WITH_SPACE);
1096 /* Truncate and show string; postfixed by '...' if necessary */
1097 DrawString(left, right, y, message, colour);
1100 struct MessageHistoryWindow : Window {
1101 int line_height; /// < Height of a single line in the news history window including spacing.
1102 int date_width; /// < Width needed for the date part.
1104 Scrollbar *vscroll;
1106 MessageHistoryWindow(WindowDesc &desc) : Window(desc)
1108 this->CreateNestedTree();
1109 this->vscroll = this->GetScrollbar(WID_MH_SCROLLBAR);
1110 this->FinishInitNested(); // Initializes 'this->line_height' and 'this->date_width'.
1111 this->OnInvalidateData(0);
1114 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
1116 if (widget == WID_MH_BACKGROUND) {
1117 this->line_height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
1118 resize.height = this->line_height;
1120 /* Months are off-by-one, so it's actually 8. Not using
1121 * month 12 because the 1 is usually less wide. */
1122 SetDParam(0, TimerGameCalendar::ConvertYMDToDate(CalendarTime::ORIGINAL_MAX_YEAR, 7, 30));
1123 this->date_width = GetStringBoundingBox(STR_JUST_DATE_TINY).width + WidgetDimensions::scaled.hsep_wide;
1125 size.height = 4 * resize.height + WidgetDimensions::scaled.framerect.Vertical(); // At least 4 lines are visible.
1126 size.width = std::max(200u, size.width); // At least 200 pixels wide.
1130 void DrawWidget(const Rect &r, WidgetID widget) const override
1132 if (widget != WID_MH_BACKGROUND || std::empty(_news)) return;
1134 /* Fill the widget with news items. */
1135 bool rtl = _current_text_dir == TD_RTL;
1136 Rect news = r.Shrink(WidgetDimensions::scaled.framerect).Indent(this->date_width + WidgetDimensions::scaled.hsep_wide, rtl);
1137 Rect date = r.Shrink(WidgetDimensions::scaled.framerect).WithWidth(this->date_width, rtl);
1138 int y = news.top;
1140 auto [first, last] = this->vscroll->GetVisibleRangeIterators(_news);
1141 for (auto ni = first; ni != last; ++ni) {
1142 SetDParam(0, ni->date);
1143 DrawString(date.left, date.right, y, STR_JUST_DATE_TINY, TC_WHITE);
1145 DrawNewsString(news.left, news.right, y, TC_WHITE, &*ni);
1146 y += this->line_height;
1151 * Some data on this window has become invalid.
1152 * @param data Information about the changed data.
1153 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
1155 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1157 if (!gui_scope) return;
1158 this->vscroll->SetCount(std::size(_news));
1161 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1163 if (widget == WID_MH_BACKGROUND) {
1164 /* Scheduled window invalidations currently occur after the input loop, which means the scrollbar count
1165 * could be invalid, so ensure it's correct now. Potentially this means that item clicked on might be
1166 * different as well. */
1167 this->vscroll->SetCount(std::size(_news));
1168 auto ni = this->vscroll->GetScrolledItemFromWidget(_news, pt.y, this, widget, WidgetDimensions::scaled.framerect.top);
1169 if (ni == std::end(_news)) return;
1171 ShowNewsMessage(ni);
1175 void OnResize() override
1177 this->vscroll->SetCapacityFromWidget(this, WID_MH_BACKGROUND, WidgetDimensions::scaled.framerect.Vertical());
1181 static constexpr NWidgetPart _nested_message_history[] = {
1182 NWidget(NWID_HORIZONTAL),
1183 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1184 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_MESSAGE_HISTORY, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1185 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1186 NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
1187 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1188 EndContainer(),
1190 NWidget(NWID_HORIZONTAL),
1191 NWidget(WWT_PANEL, COLOUR_BROWN, WID_MH_BACKGROUND), SetMinimalSize(200, 125), SetDataTip(0x0, STR_MESSAGE_HISTORY_TOOLTIP), SetResize(1, 12), SetScrollbar(WID_MH_SCROLLBAR),
1192 EndContainer(),
1193 NWidget(NWID_VERTICAL),
1194 NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_MH_SCROLLBAR),
1195 NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
1196 EndContainer(),
1197 EndContainer(),
1200 static WindowDesc _message_history_desc(
1201 WDP_AUTO, "list_news", 400, 140,
1202 WC_MESSAGE_HISTORY, WC_NONE,
1204 _nested_message_history
1207 /** Display window with news messages history */
1208 void ShowMessageHistory()
1210 CloseWindowById(WC_MESSAGE_HISTORY, 0);
1211 new MessageHistoryWindow(_message_history_desc);