Update: Translations from eints
[openttd-github.git] / src / news_gui.cpp
blob2758c33e5fb3b84980f907d4fae0ac41ac16fd07
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 "news_func.h"
37 #include "timer/timer.h"
38 #include "timer/timer_window.h"
39 #include "timer/timer_game_calendar.h"
41 #include "widgets/news_widget.h"
43 #include "table/strings.h"
45 #include "safeguards.h"
47 static const uint MIN_NEWS_AMOUNT = 30; ///< preferred minimum amount of news messages.
48 static const uint MAX_NEWS_AMOUNT = 1U << 10; ///< Do not exceed this number of news messages.
50 static NewsContainer _news; ///< List of news, with newest items at the start.
52 /**
53 * Forced news item.
54 * Users can force an item by accessing the history or "last message".
55 * If the message being shown was forced by the user, an iterater is stored
56 * in _forced_news. Otherwise, \a _forced_news variable is the end of \a _news.
58 static NewsIterator _forced_news = std::end(_news);
60 /** Current news item (last item shown regularly). */
61 static NewsIterator _current_news = std::end(_news);
63 /** Current status bar news item. */
64 static NewsIterator _statusbar_news = std::end(_news);
66 /**
67 * Get pointer to the current status bar news item.
68 * @return Pointer to the current status bar news item, or nullptr if there is none.
70 const NewsItem *GetStatusbarNews()
72 return (_statusbar_news == std::end(_news)) ? nullptr : &*_statusbar_news;
75 /**
76 * Get read-only reference to all news items.
77 * @return Read-only reference to all news items.
79 const NewsContainer &GetNews()
81 return _news;
84 /**
85 * Get the position a news-reference is referencing.
86 * @param reftype The type of reference.
87 * @param ref The reference.
88 * @return A tile for the referenced object, or INVALID_TILE if none.
90 static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32_t ref)
92 switch (reftype) {
93 case NR_TILE: return (TileIndex)ref;
94 case NR_STATION: return Station::Get((StationID)ref)->xy;
95 case NR_INDUSTRY: return Industry::Get((IndustryID)ref)->location.tile + TileDiffXY(1, 1);
96 case NR_TOWN: return Town::Get((TownID)ref)->xy;
97 default: return INVALID_TILE;
101 /* Normal news items. */
102 static constexpr NWidgetPart _nested_normal_news_widgets[] = {
103 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
104 NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
105 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
106 NWidget(NWID_SPACER), SetFill(1, 0),
107 NWidget(NWID_VERTICAL),
108 NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_JUST_DATE_LONG, STR_NULL), SetTextStyle(TC_BLACK, FS_SMALL),
109 NWidget(NWID_SPACER), SetFill(0, 1),
110 EndContainer(),
111 EndContainer(),
112 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(428, 154), SetPadding(0, 5, 1, 5),
113 EndContainer(),
116 static WindowDesc _normal_news_desc(
117 WDP_MANUAL, nullptr, 0, 0,
118 WC_NEWS_WINDOW, WC_NONE,
120 _nested_normal_news_widgets
123 /* New vehicles news items. */
124 static constexpr NWidgetPart _nested_vehicle_news_widgets[] = {
125 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
126 NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
127 NWidget(NWID_VERTICAL),
128 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
129 NWidget(NWID_SPACER), SetFill(0, 1),
130 EndContainer(),
131 NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_VEH_TITLE), SetFill(1, 1), SetMinimalSize(419, 55), SetDataTip(STR_EMPTY, STR_NULL),
132 EndContainer(),
133 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_VEH_BKGND), SetPadding(0, 25, 1, 25),
134 NWidget(NWID_VERTICAL),
135 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_NAME), SetMinimalSize(369, 33), SetFill(1, 0),
136 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_SPR), SetMinimalSize(369, 32), SetFill(1, 0),
137 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_INFO), SetMinimalSize(369, 46), SetFill(1, 0),
138 EndContainer(),
139 EndContainer(),
140 EndContainer(),
143 static WindowDesc _vehicle_news_desc(
144 WDP_MANUAL, nullptr, 0, 0,
145 WC_NEWS_WINDOW, WC_NONE,
147 _nested_vehicle_news_widgets
150 /* Company news items. */
151 static constexpr NWidgetPart _nested_company_news_widgets[] = {
152 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
153 NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
154 NWidget(NWID_VERTICAL),
155 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
156 NWidget(NWID_SPACER), SetFill(0, 1),
157 EndContainer(),
158 NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_TITLE), SetFill(1, 1), SetMinimalSize(410, 20), SetDataTip(STR_EMPTY, STR_NULL),
159 EndContainer(),
160 NWidget(NWID_HORIZONTAL), SetPadding(0, 1, 1, 1),
161 NWidget(NWID_VERTICAL),
162 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MGR_FACE), SetMinimalSize(93, 119), SetPadding(2, 6, 2, 1),
163 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MGR_NAME), SetMinimalSize(93, 24), SetPadding(0, 0, 0, 1),
164 NWidget(NWID_SPACER), SetFill(0, 1),
165 EndContainer(),
166 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_COMPANY_MSG), SetFill(1, 1), SetMinimalSize(328, 150),
167 EndContainer(),
168 EndContainer(),
171 static WindowDesc _company_news_desc(
172 WDP_MANUAL, nullptr, 0, 0,
173 WC_NEWS_WINDOW, WC_NONE,
175 _nested_company_news_widgets
178 /* Thin news items. */
179 static constexpr NWidgetPart _nested_thin_news_widgets[] = {
180 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
181 NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
182 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
183 NWidget(NWID_SPACER), SetFill(1, 0),
184 NWidget(NWID_VERTICAL),
185 NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_JUST_DATE_LONG, STR_NULL), SetTextStyle(TC_BLACK, FS_SMALL),
186 NWidget(NWID_SPACER), SetFill(0, 1),
187 EndContainer(),
188 EndContainer(),
189 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(428, 48), SetFill(1, 0), SetPadding(0, 5, 0, 5),
190 NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetMinimalSize(426, 70), SetPadding(1, 2, 2, 2),
191 EndContainer(),
194 static WindowDesc _thin_news_desc(
195 WDP_MANUAL, nullptr, 0, 0,
196 WC_NEWS_WINDOW, WC_NONE,
198 _nested_thin_news_widgets
201 /* Small news items. */
202 static constexpr NWidgetPart _nested_small_news_widgets[] = {
203 /* Caption + close box. The caption is no WWT_CAPTION as the window shall not be moveable and so on. */
204 NWidget(NWID_HORIZONTAL),
205 NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE, WID_N_CLOSEBOX),
206 NWidget(WWT_EMPTY, COLOUR_LIGHT_BLUE, WID_N_CAPTION), SetFill(1, 0),
207 NWidget(WWT_TEXTBTN, COLOUR_LIGHT_BLUE, WID_N_SHOW_GROUP), SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON), SetResize(1, 0),
208 SetDataTip(STR_NULL /* filled in later */, STR_NEWS_SHOW_VEHICLE_GROUP_TOOLTIP),
209 EndContainer(),
211 /* Main part */
212 NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_N_HEADLINE),
213 NWidget(WWT_INSET, COLOUR_LIGHT_BLUE, WID_N_INSET), SetPadding(2, 2, 2, 2),
214 NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetMinimalSize(274, 47), SetFill(1, 0),
215 EndContainer(),
216 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(275, 20), SetFill(1, 0), SetPadding(0, 5, 0, 5),
217 EndContainer(),
220 static WindowDesc _small_news_desc(
221 WDP_MANUAL, nullptr, 0, 0,
222 WC_NEWS_WINDOW, WC_NONE,
224 _nested_small_news_widgets
228 * Window layouts for news items.
230 static WindowDesc *_news_window_layout[] = {
231 &_thin_news_desc, ///< NF_THIN
232 &_small_news_desc, ///< NF_SMALL
233 &_normal_news_desc, ///< NF_NORMAL
234 &_vehicle_news_desc, ///< NF_VEHICLE
235 &_company_news_desc, ///< NF_COMPANY
238 WindowDesc &GetNewsWindowLayout(NewsFlag flags)
240 uint layout = GB(flags, NFB_WINDOW_LAYOUT, NFB_WINDOW_LAYOUT_COUNT);
241 assert(layout < lengthof(_news_window_layout));
242 return *_news_window_layout[layout];
246 * Per-NewsType data
248 static NewsTypeData _news_type_data[] = {
249 /* name, age, sound, */
250 NewsTypeData("news_display.arrival_player", 60, SND_1D_APPLAUSE ), ///< NT_ARRIVAL_COMPANY
251 NewsTypeData("news_display.arrival_other", 60, SND_1D_APPLAUSE ), ///< NT_ARRIVAL_OTHER
252 NewsTypeData("news_display.accident", 90, SND_BEGIN ), ///< NT_ACCIDENT
253 NewsTypeData("news_display.accident_other", 90, SND_BEGIN ), ///< NT_ACCIDENT_OTHER
254 NewsTypeData("news_display.company_info", 60, SND_BEGIN ), ///< NT_COMPANY_INFO
255 NewsTypeData("news_display.open", 90, SND_BEGIN ), ///< NT_INDUSTRY_OPEN
256 NewsTypeData("news_display.close", 90, SND_BEGIN ), ///< NT_INDUSTRY_CLOSE
257 NewsTypeData("news_display.economy", 30, SND_BEGIN ), ///< NT_ECONOMY
258 NewsTypeData("news_display.production_player", 30, SND_BEGIN ), ///< NT_INDUSTRY_COMPANY
259 NewsTypeData("news_display.production_other", 30, SND_BEGIN ), ///< NT_INDUSTRY_OTHER
260 NewsTypeData("news_display.production_nobody", 30, SND_BEGIN ), ///< NT_INDUSTRY_NOBODY
261 NewsTypeData("news_display.advice", 150, SND_BEGIN ), ///< NT_ADVICE
262 NewsTypeData("news_display.new_vehicles", 30, SND_1E_NEW_ENGINE), ///< NT_NEW_VEHICLES
263 NewsTypeData("news_display.acceptance", 90, SND_BEGIN ), ///< NT_ACCEPTANCE
264 NewsTypeData("news_display.subsidies", 180, SND_BEGIN ), ///< NT_SUBSIDIES
265 NewsTypeData("news_display.general", 60, SND_BEGIN ), ///< NT_GENERAL
268 static_assert(lengthof(_news_type_data) == NT_END);
271 * Return the news display option.
272 * @return display options
274 NewsDisplay NewsTypeData::GetDisplay() const
276 const SettingDesc *sd = GetSettingFromName(this->name);
277 assert(sd != nullptr && sd->IsIntSetting());
278 return (NewsDisplay)sd->AsIntSetting()->Read(nullptr);
281 /** Window class displaying a news item. */
282 struct NewsWindow : Window {
283 uint16_t chat_height; ///< Height of the chat window.
284 uint16_t status_height; ///< Height of the status bar window
285 const NewsItem *ni; ///< News item to display.
286 static int duration; ///< Remaining time for showing the current news message (may only be access while a news item is displayed).
288 NewsWindow(WindowDesc &desc, const NewsItem *ni) : Window(desc), ni(ni)
290 NewsWindow::duration = 16650;
291 const Window *w = FindWindowByClass(WC_SEND_NETWORK_MSG);
292 this->chat_height = (w != nullptr) ? w->height : 0;
293 this->status_height = FindWindowById(WC_STATUS_BAR, 0)->height;
295 this->flags |= WF_DISABLE_VP_SCROLL;
297 this->CreateNestedTree();
299 /* For company news with a face we have a separate headline in param[0] */
300 if (&desc == &_company_news_desc) this->GetWidget<NWidgetCore>(WID_N_TITLE)->widget_data = std::get<uint64_t>(this->ni->params[0]);
302 NWidgetCore *nwid = this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP);
303 if (ni->reftype1 == NR_VEHICLE && nwid != nullptr) {
304 const Vehicle *v = Vehicle::Get(ni->ref1);
305 switch (v->type) {
306 case VEH_TRAIN:
307 nwid->widget_data = STR_TRAIN;
308 break;
309 case VEH_ROAD:
310 nwid->widget_data = RoadVehicle::From(v)->IsBus() ? STR_BUS : STR_LORRY;
311 break;
312 case VEH_SHIP:
313 nwid->widget_data = STR_SHIP;
314 break;
315 case VEH_AIRCRAFT:
316 nwid->widget_data = STR_PLANE;
317 break;
318 default:
319 break; // Do nothing
323 this->FinishInitNested(0);
325 /* Initialize viewport if it exists. */
326 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
327 if (nvp != nullptr) {
328 if (ni->reftype1 == NR_VEHICLE) {
329 nvp->InitializeViewport(this, static_cast<VehicleID>(ni->ref1), ScaleZoomGUI(ZOOM_LVL_NEWS));
330 } else {
331 nvp->InitializeViewport(this, GetReferenceTile(ni->reftype1, ni->ref1), ScaleZoomGUI(ZOOM_LVL_NEWS));
333 if (this->ni->flags & NF_NO_TRANSPARENT) nvp->disp_flags |= ND_NO_TRANSPARENCY;
334 if ((this->ni->flags & NF_INCOLOUR) == 0) {
335 nvp->disp_flags |= ND_SHADE_GREY;
336 } else if (this->ni->flags & NF_SHADE) {
337 nvp->disp_flags |= ND_SHADE_DIMMED;
341 PositionNewsMessage(this);
344 void DrawNewsBorder(const Rect &r) const
346 Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
347 GfxFillRect(ir, PC_WHITE);
349 ir = ir.Expand(1);
350 GfxFillRect( r.left, r.top, ir.left, r.bottom, PC_BLACK);
351 GfxFillRect(ir.right, r.top, r.right, r.bottom, PC_BLACK);
352 GfxFillRect( r.left, r.top, r.right, ir.top, PC_BLACK);
353 GfxFillRect( r.left, ir.bottom, r.right, r.bottom, PC_BLACK);
356 Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
358 Point pt = { 0, _screen.height };
359 return pt;
362 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
364 StringID str = STR_NULL;
365 switch (widget) {
366 case WID_N_CAPTION: {
367 /* Caption is not a real caption (so that the window cannot be moved)
368 * thus it doesn't get the default sizing of a caption. */
369 Dimension d2 = GetStringBoundingBox(STR_NEWS_MESSAGE_CAPTION);
370 d2.height += WidgetDimensions::scaled.captiontext.Vertical();
371 size = maxdim(size, d2);
372 return;
375 case WID_N_MGR_FACE:
376 size = maxdim(size, GetScaledSpriteSize(SPR_GRADIENT));
377 break;
379 case WID_N_MGR_NAME:
380 SetDParamStr(0, static_cast<const CompanyNewsInformation *>(this->ni->data.get())->president_name);
381 str = STR_JUST_RAW_STRING;
382 break;
384 case WID_N_MESSAGE:
385 CopyInDParam(this->ni->params);
386 str = this->ni->string_id;
387 break;
389 case WID_N_COMPANY_MSG:
390 str = this->GetCompanyMessageString();
391 break;
393 case WID_N_VEH_NAME:
394 case WID_N_VEH_TITLE:
395 str = this->GetNewVehicleMessageString(widget);
396 break;
398 case WID_N_VEH_INFO: {
399 assert(this->ni->reftype1 == NR_ENGINE);
400 EngineID engine = this->ni->ref1;
401 str = GetEngineInfoString(engine);
402 break;
405 case WID_N_SHOW_GROUP:
406 if (this->ni->reftype1 == NR_VEHICLE) {
407 Dimension d2 = GetStringBoundingBox(this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP)->widget_data);
408 d2.height += WidgetDimensions::scaled.captiontext.Vertical();
409 d2.width += WidgetDimensions::scaled.captiontext.Horizontal();
410 size = d2;
411 } else {
412 /* Hide 'Show group window' button if this news is not about a vehicle. */
413 size.width = 0;
414 size.height = 0;
415 resize.width = 0;
416 resize.height = 0;
417 fill.width = 0;
418 fill.height = 0;
420 return;
422 default:
423 return; // Do nothing
426 /* Update minimal size with length of the multi-line string. */
427 Dimension d = size;
428 d.width = (d.width >= padding.width) ? d.width - padding.width : 0;
429 d.height = (d.height >= padding.height) ? d.height - padding.height : 0;
430 d = GetStringMultiLineBoundingBox(str, d);
431 d.width += padding.width;
432 d.height += padding.height;
433 size = maxdim(size, d);
436 void SetStringParameters(WidgetID widget) const override
438 if (widget == WID_N_DATE) SetDParam(0, this->ni->date);
441 void DrawWidget(const Rect &r, WidgetID widget) const override
443 switch (widget) {
444 case WID_N_CAPTION:
445 DrawCaption(r, COLOUR_LIGHT_BLUE, this->owner, TC_FROMSTRING, STR_NEWS_MESSAGE_CAPTION, SA_CENTER, FS_NORMAL);
446 break;
448 case WID_N_PANEL:
449 this->DrawNewsBorder(r);
450 break;
452 case WID_N_MESSAGE:
453 CopyInDParam(this->ni->params);
454 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->ni->string_id, TC_FROMSTRING, SA_CENTER);
455 break;
457 case WID_N_MGR_FACE: {
458 const CompanyNewsInformation *cni = static_cast<const CompanyNewsInformation*>(this->ni->data.get());
459 DrawCompanyManagerFace(cni->face, cni->colour, r);
460 GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
461 break;
463 case WID_N_MGR_NAME: {
464 const CompanyNewsInformation *cni = static_cast<const CompanyNewsInformation*>(this->ni->data.get());
465 SetDParamStr(0, cni->president_name);
466 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, STR_JUST_RAW_STRING, TC_FROMSTRING, SA_CENTER);
467 break;
469 case WID_N_COMPANY_MSG:
470 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->GetCompanyMessageString(), TC_FROMSTRING, SA_CENTER);
471 break;
473 case WID_N_VEH_BKGND:
474 GfxFillRect(r.left, r.top, r.right, r.bottom, PC_GREY);
475 break;
477 case WID_N_VEH_NAME:
478 case WID_N_VEH_TITLE:
479 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->GetNewVehicleMessageString(widget), TC_FROMSTRING, SA_CENTER);
480 break;
482 case WID_N_VEH_SPR: {
483 assert(this->ni->reftype1 == NR_ENGINE);
484 EngineID engine = this->ni->ref1;
485 DrawVehicleEngine(r.left, r.right, CenterBounds(r.left, r.right, 0), CenterBounds(r.top, r.bottom, 0), engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
486 GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
487 break;
489 case WID_N_VEH_INFO: {
490 assert(this->ni->reftype1 == NR_ENGINE);
491 EngineID engine = this->ni->ref1;
492 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
493 break;
498 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
500 switch (widget) {
501 case WID_N_CLOSEBOX:
502 NewsWindow::duration = 0;
503 this->Close();
504 _forced_news = std::end(_news);
505 break;
507 case WID_N_CAPTION:
508 if (this->ni->reftype1 == NR_VEHICLE) {
509 const Vehicle *v = Vehicle::Get(this->ni->ref1);
510 ShowVehicleViewWindow(v);
512 break;
514 case WID_N_VIEWPORT:
515 break; // Ignore clicks
517 case WID_N_SHOW_GROUP:
518 if (this->ni->reftype1 == NR_VEHICLE) {
519 const Vehicle *v = Vehicle::Get(this->ni->ref1);
520 ShowCompanyGroupForVehicle(v);
522 break;
523 default:
524 if (this->ni->reftype1 == NR_VEHICLE) {
525 const Vehicle *v = Vehicle::Get(this->ni->ref1);
526 ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos);
527 } else {
528 TileIndex tile1 = GetReferenceTile(this->ni->reftype1, this->ni->ref1);
529 TileIndex tile2 = GetReferenceTile(this->ni->reftype2, this->ni->ref2);
530 if (_ctrl_pressed) {
531 if (tile1 != INVALID_TILE) ShowExtraViewportWindow(tile1);
532 if (tile2 != INVALID_TILE) ShowExtraViewportWindow(tile2);
533 } else {
534 if ((tile1 == INVALID_TILE || !ScrollMainWindowToTile(tile1)) && tile2 != INVALID_TILE) {
535 ScrollMainWindowToTile(tile2);
539 break;
543 void OnResize() override
545 if (this->viewport != nullptr) {
546 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
547 nvp->UpdateViewportCoordinates(this);
549 if (ni->reftype1 != NR_VEHICLE) {
550 ScrollWindowToTile(GetReferenceTile(ni->reftype1, ni->ref1), this, true); // Re-center viewport.
556 * Some data on this window has become invalid.
557 * @param data Information about the changed data.
558 * @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.
560 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
562 if (!gui_scope) return;
563 /* The chatbar has notified us that is was either created or closed */
564 int newtop = this->top + this->chat_height - data;
565 this->chat_height = data;
566 this->SetWindowTop(newtop);
569 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
571 /* Decrement the news timer. We don't need to action an elapsed event here,
572 * so no need to use TimerElapsed(). */
573 if (NewsWindow::duration > 0) NewsWindow::duration -= delta_ms;
577 * Scroll the news message slowly up from the bottom.
579 * The interval of 210ms is chosen to maintain 15ms at normal zoom: 210 / GetCharacterHeight(FS_NORMAL) = 15ms.
581 IntervalTimer<TimerWindow> scroll_interval = {std::chrono::milliseconds(210) / GetCharacterHeight(FS_NORMAL), [this](uint count) {
582 int newtop = std::max(this->top - 2 * static_cast<int>(count), _screen.height - this->height - this->status_height - this->chat_height);
583 this->SetWindowTop(newtop);
586 private:
588 * Moves the window to a new #top coordinate. Makes screen dirty where needed.
589 * @param newtop new top coordinate
591 void SetWindowTop(int newtop)
593 if (this->top == newtop) return;
595 int mintop = std::min(newtop, this->top);
596 int maxtop = std::max(newtop, this->top);
597 if (this->viewport != nullptr) this->viewport->top += newtop - this->top;
598 this->top = newtop;
600 AddDirtyBlock(this->left, mintop, this->left + this->width, maxtop + this->height);
603 StringID GetCompanyMessageString() const
605 /* Company news with a face have a separate headline, so the normal message is shifted by two params */
606 CopyInDParam(std::span(this->ni->params.data() + 2, this->ni->params.size() - 2));
607 return std::get<uint64_t>(this->ni->params[1]);
610 StringID GetNewVehicleMessageString(WidgetID widget) const
612 assert(this->ni->reftype1 == NR_ENGINE);
613 EngineID engine = this->ni->ref1;
615 switch (widget) {
616 case WID_N_VEH_TITLE:
617 SetDParam(0, GetEngineCategoryName(engine));
618 return STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE;
620 case WID_N_VEH_NAME:
621 SetDParam(0, PackEngineNameDParam(engine, EngineNameContext::PreviewNews));
622 return STR_NEWS_NEW_VEHICLE_TYPE;
624 default:
625 NOT_REACHED();
630 /* static */ int NewsWindow::duration = 0; // Instance creation.
632 /** Open up an own newspaper window for the news item */
633 static void ShowNewspaper(const NewsItem *ni)
635 SoundFx sound = _news_type_data[ni->type].sound;
636 if (sound != 0 && _settings_client.sound.news_full) SndPlayFx(sound);
638 new NewsWindow(GetNewsWindowLayout(ni->flags), ni);
641 /** Show news item in the ticker */
642 static void ShowTicker(NewsIterator ni)
644 if (_settings_client.sound.news_ticker) SndPlayFx(SND_16_NEWS_TICKER);
646 _statusbar_news = ni;
647 InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_TICKER);
650 /** Initialize the news-items data structures */
651 void InitNewsItemStructs()
653 _news.clear();
654 _forced_news = std::end(_news);
655 _current_news = std::end(_news);
656 _statusbar_news = std::end(_news);
657 NewsWindow::duration = 0;
661 * Are we ready to show another ticker item?
662 * Only if nothing is in the newsticker is displayed
664 static bool ReadyForNextTickerItem()
666 const NewsItem *ni = GetStatusbarNews();
667 if (ni == nullptr) return true;
669 /* Ticker message
670 * Check if the status bar message is still being displayed? */
671 return !IsNewsTickerShown();
675 * Are we ready to show another news item?
676 * Only if no newspaper is displayed
678 static bool ReadyForNextNewsItem()
680 if (_forced_news == std::end(_news) && _current_news == std::end(_news)) return true;
682 /* neither newsticker nor newspaper are running */
683 return (NewsWindow::duration <= 0 || FindWindowById(WC_NEWS_WINDOW, 0) == nullptr);
686 /** Move to the next ticker item */
687 static void MoveToNextTickerItem()
689 /* There is no status bar, so no reason to show news;
690 * especially important with the end game screen when
691 * there is no status bar but possible news. */
692 if (FindWindowById(WC_STATUS_BAR, 0) == nullptr) return;
694 /* No news to move to. */
695 if (std::empty(_news)) return;
697 /* if we're not at the latest item, then move on */
698 while (_statusbar_news != std::begin(_news)) {
699 --_statusbar_news;
700 const NewsType type = _statusbar_news->type;
702 /* check the date, don't show too old items */
703 if (TimerGameEconomy::date - _news_type_data[type].age > _statusbar_news->economy_date) continue;
705 switch (_news_type_data[type].GetDisplay()) {
706 default: NOT_REACHED();
707 case ND_OFF: // Off - show nothing only a small reminder in the status bar
708 InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_REMINDER);
709 return;
711 case ND_SUMMARY: // Summary - show ticker
712 ShowTicker(_statusbar_news);
713 return;
715 case ND_FULL: // Full - show newspaper, skipped here
716 break;;
721 /** Move to the next news item */
722 static void MoveToNextNewsItem()
724 /* There is no status bar, so no reason to show news;
725 * especially important with the end game screen when
726 * there is no status bar but possible news. */
727 if (FindWindowById(WC_STATUS_BAR, 0) == nullptr) return;
729 CloseWindowById(WC_NEWS_WINDOW, 0); // close the newspapers window if shown
730 _forced_news = std::end(_news);
732 /* No news to move to. */
733 if (std::empty(_news)) return;
735 /* if we're not at the latest item, then move on */
736 while (_current_news != std::begin(_news)) {
737 --_current_news;
738 const NewsType type = _current_news->type;
740 /* check the date, don't show too old items */
741 if (TimerGameEconomy::date - _news_type_data[type].age > _current_news->economy_date) continue;
743 switch (_news_type_data[type].GetDisplay()) {
744 default: NOT_REACHED();
745 case ND_OFF: // Off - show nothing only a small reminder in the status bar, skipped here
746 break;
748 case ND_SUMMARY: // Summary - show ticker, skipped here
749 break;;
751 case ND_FULL: // Full - show newspaper
752 ShowNewspaper(&*_current_news);
753 return;
758 /** Delete a news item from the queue */
759 static std::list<NewsItem>::iterator DeleteNewsItem(std::list<NewsItem>::iterator ni)
761 bool updateCurrentNews = (_forced_news == ni || _current_news == ni);
762 bool updateStatusbarNews = (_statusbar_news == ni);
764 if (updateCurrentNews) {
765 /* When we're the current news, go to the next older item first;
766 * we just possibly made that the last news item. */
767 if (_current_news == ni) ++_current_news;
768 if (_forced_news == ni) _forced_news = std::end(_news);
771 if (updateStatusbarNews) {
772 /* When we're the current news, go to the next older item first;
773 * we just possibly made that the last news item. */
774 ++_statusbar_news;
777 /* Delete the news from the news queue. */
778 ni = _news.erase(ni);
780 if (updateCurrentNews) {
781 /* About to remove the currently forced item (shown as newspapers) ||
782 * about to remove the currently displayed item (newspapers) */
783 MoveToNextNewsItem();
786 if (updateStatusbarNews) {
787 /* About to remove the currently displayed item (ticker, or just a reminder) */
788 InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); // invalidate the statusbar
789 MoveToNextTickerItem();
792 return ni;
796 * Create a new newsitem to be shown.
797 * @param string_id String to display.
798 * @param type The type of news.
799 * @param flags Flags related to how to display the news.
800 * @param reftype1 Type of ref1.
801 * @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.
802 * @param reftype2 Type of ref2.
803 * @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.
804 * @param data Pointer to data that must be released once the news message is cleared.
806 * @see NewsSubtype
808 NewsItem::NewsItem(StringID string_id, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, const NewsAllocatedData *data) :
809 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)
811 /* show this news message in colour? */
812 if (TimerGameCalendar::year >= _settings_client.gui.coloured_news_year) this->flags |= NF_INCOLOUR;
813 CopyOutDParam(this->params, 10);
817 * Add a new newsitem to be shown.
818 * @param string String to display
819 * @param type news category
820 * @param flags display flags for the news
821 * @param reftype1 Type of ref1
822 * @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.
823 * @param reftype2 Type of ref2
824 * @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.
825 * @param data Pointer to data that must be released once the news message is cleared.
827 * @see NewsSubtype
829 void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, const NewsAllocatedData *data)
831 if (_game_mode == GM_MENU) return;
833 /* Create new news item node */
834 _news.emplace_front(string, type, flags, reftype1, ref1, reftype2, ref2, data);
836 /* Keep the number of stored news items to a managable number */
837 if (std::size(_news) > MAX_NEWS_AMOUNT) {
838 DeleteNewsItem(std::prev(std::end(_news)));
841 InvalidateWindowData(WC_MESSAGE_HISTORY, 0);
845 * Create a new custom news item.
846 * @param flags type of operation
847 * @aram type NewsType of the message.
848 * @param reftype1 NewsReferenceType of first reference.
849 * @param company Company this news message is for.
850 * @param reference First reference of the news message.
851 * @param text The text of the news message.
852 * @return the cost of this operation or an error
854 CommandCost CmdCustomNewsItem(DoCommandFlag flags, NewsType type, NewsReferenceType reftype1, CompanyID company, uint32_t reference, const std::string &text)
856 if (_current_company != OWNER_DEITY) return CMD_ERROR;
858 if (company != INVALID_OWNER && !Company::IsValidID(company)) return CMD_ERROR;
859 if (type >= NT_END) return CMD_ERROR;
860 if (text.empty()) return CMD_ERROR;
862 switch (reftype1) {
863 case NR_NONE: break;
864 case NR_TILE:
865 if (!IsValidTile(reference)) return CMD_ERROR;
866 break;
868 case NR_VEHICLE:
869 if (!Vehicle::IsValidID(reference)) return CMD_ERROR;
870 break;
872 case NR_STATION:
873 if (!Station::IsValidID(reference)) return CMD_ERROR;
874 break;
876 case NR_INDUSTRY:
877 if (!Industry::IsValidID(reference)) return CMD_ERROR;
878 break;
880 case NR_TOWN:
881 if (!Town::IsValidID(reference)) return CMD_ERROR;
882 break;
884 case NR_ENGINE:
885 if (!Engine::IsValidID(reference)) return CMD_ERROR;
886 break;
888 default: return CMD_ERROR;
891 if (company != INVALID_OWNER && company != _local_company) return CommandCost();
893 if (flags & DC_EXEC) {
894 SetDParamStr(0, text);
895 AddNewsItem(STR_NEWS_CUSTOM_ITEM, type, NF_NORMAL, reftype1, reference, NR_NONE, UINT32_MAX);
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);