Fix: Stopped ships shouldn't block depots (#8578)
[openttd-github.git] / src / news_gui.cpp
blob3412c351cece9ed7378773fb04d8bc770955ae12
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 "date_func.h"
16 #include "vehicle_base.h"
17 #include "vehicle_func.h"
18 #include "vehicle_gui.h"
19 #include "roadveh.h"
20 #include "station_base.h"
21 #include "industry.h"
22 #include "town.h"
23 #include "sound_func.h"
24 #include "string_func.h"
25 #include "widgets/dropdown_func.h"
26 #include "statusbar_gui.h"
27 #include "company_manager_face.h"
28 #include "company_func.h"
29 #include "engine_base.h"
30 #include "engine_gui.h"
31 #include "core/geometry_func.hpp"
32 #include "command_func.h"
33 #include "company_base.h"
34 #include "settings_internal.h"
35 #include "guitimer_func.h"
36 #include "group_gui.h"
37 #include "zoom_func.h"
39 #include "widgets/news_widget.h"
41 #include "table/strings.h"
43 #include "safeguards.h"
45 const NewsItem *_statusbar_news_item = nullptr;
47 static uint MIN_NEWS_AMOUNT = 30; ///< preferred minimum amount of news messages
48 static uint MAX_NEWS_AMOUNT = 1 << 10; ///< Do not exceed this number of news messages
49 static uint _total_news = 0; ///< current number of news items
50 static NewsItem *_oldest_news = nullptr; ///< head of news items queue
51 NewsItem *_latest_news = nullptr; ///< tail of news items queue
53 /**
54 * Forced news item.
55 * Users can force an item by accessing the history or "last message".
56 * If the message being shown was forced by the user, a pointer is stored
57 * in _forced_news. Otherwise, \a _forced_news variable is nullptr.
59 static const NewsItem *_forced_news = nullptr;
61 /** Current news item (last item shown regularly). */
62 static const NewsItem *_current_news = nullptr;
65 /**
66 * Get the position a news-reference is referencing.
67 * @param reftype The type of reference.
68 * @param ref The reference.
69 * @return A tile for the referenced object, or INVALID_TILE if none.
71 static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32 ref)
73 switch (reftype) {
74 case NR_TILE: return (TileIndex)ref;
75 case NR_STATION: return Station::Get((StationID)ref)->xy;
76 case NR_INDUSTRY: return Industry::Get((IndustryID)ref)->location.tile + TileDiffXY(1, 1);
77 case NR_TOWN: return Town::Get((TownID)ref)->xy;
78 default: return INVALID_TILE;
82 /* Normal news items. */
83 static const NWidgetPart _nested_normal_news_widgets[] = {
84 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
85 NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
86 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
87 NWidget(NWID_SPACER), SetFill(1, 0),
88 NWidget(NWID_VERTICAL),
89 NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_DATE_LONG_SMALL, STR_NULL),
90 NWidget(NWID_SPACER), SetFill(0, 1),
91 EndContainer(),
92 EndContainer(),
93 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(428, 154), SetPadding(0, 5, 1, 5),
94 EndContainer(),
97 static WindowDesc _normal_news_desc(
98 WDP_MANUAL, nullptr, 0, 0,
99 WC_NEWS_WINDOW, WC_NONE,
101 _nested_normal_news_widgets, lengthof(_nested_normal_news_widgets)
104 /* New vehicles news items. */
105 static const NWidgetPart _nested_vehicle_news_widgets[] = {
106 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
107 NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
108 NWidget(NWID_VERTICAL),
109 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
110 NWidget(NWID_SPACER), SetFill(0, 1),
111 EndContainer(),
112 NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_VEH_TITLE), SetFill(1, 1), SetMinimalSize(419, 55), SetDataTip(STR_EMPTY, STR_NULL),
113 EndContainer(),
114 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_VEH_BKGND), SetPadding(0, 25, 1, 25),
115 NWidget(NWID_VERTICAL),
116 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_NAME), SetMinimalSize(369, 33), SetFill(1, 0),
117 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_SPR), SetMinimalSize(369, 32), SetFill(1, 0),
118 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_INFO), SetMinimalSize(369, 46), SetFill(1, 0),
119 EndContainer(),
120 EndContainer(),
121 EndContainer(),
124 static WindowDesc _vehicle_news_desc(
125 WDP_MANUAL, nullptr, 0, 0,
126 WC_NEWS_WINDOW, WC_NONE,
128 _nested_vehicle_news_widgets, lengthof(_nested_vehicle_news_widgets)
131 /* Company news items. */
132 static const NWidgetPart _nested_company_news_widgets[] = {
133 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
134 NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
135 NWidget(NWID_VERTICAL),
136 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
137 NWidget(NWID_SPACER), SetFill(0, 1),
138 EndContainer(),
139 NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_TITLE), SetFill(1, 1), SetMinimalSize(410, 20), SetDataTip(STR_EMPTY, STR_NULL),
140 EndContainer(),
141 NWidget(NWID_HORIZONTAL), SetPadding(0, 1, 1, 1),
142 NWidget(NWID_VERTICAL),
143 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MGR_FACE), SetMinimalSize(93, 119), SetPadding(2, 6, 2, 1),
144 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MGR_NAME), SetMinimalSize(93, 24), SetPadding(0, 0, 0, 1),
145 NWidget(NWID_SPACER), SetFill(0, 1),
146 EndContainer(),
147 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_COMPANY_MSG), SetFill(1, 1), SetMinimalSize(328, 150),
148 EndContainer(),
149 EndContainer(),
152 static WindowDesc _company_news_desc(
153 WDP_MANUAL, nullptr, 0, 0,
154 WC_NEWS_WINDOW, WC_NONE,
156 _nested_company_news_widgets, lengthof(_nested_company_news_widgets)
159 /* Thin news items. */
160 static const NWidgetPart _nested_thin_news_widgets[] = {
161 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
162 NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
163 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
164 NWidget(NWID_SPACER), SetFill(1, 0),
165 NWidget(NWID_VERTICAL),
166 NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_DATE_LONG_SMALL, STR_NULL),
167 NWidget(NWID_SPACER), SetFill(0, 1),
168 EndContainer(),
169 EndContainer(),
170 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(428, 48), SetFill(1, 0), SetPadding(0, 5, 0, 5),
171 NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetMinimalSize(426, 70), SetPadding(1, 2, 2, 2),
172 EndContainer(),
175 static WindowDesc _thin_news_desc(
176 WDP_MANUAL, nullptr, 0, 0,
177 WC_NEWS_WINDOW, WC_NONE,
179 _nested_thin_news_widgets, lengthof(_nested_thin_news_widgets)
182 /* Small news items. */
183 static const NWidgetPart _nested_small_news_widgets[] = {
184 /* Caption + close box. The caption is no WWT_CAPTION as the window shall not be moveable and so on. */
185 NWidget(NWID_HORIZONTAL),
186 NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE, WID_N_CLOSEBOX),
187 NWidget(WWT_EMPTY, COLOUR_LIGHT_BLUE, WID_N_CAPTION), SetFill(1, 0),
188 NWidget(WWT_TEXTBTN, COLOUR_LIGHT_BLUE, WID_N_SHOW_GROUP), SetMinimalSize(14, 11), SetResize(1, 0),
189 SetDataTip(STR_NULL /* filled in later */, STR_NEWS_SHOW_VEHICLE_GROUP_TOOLTIP),
190 EndContainer(),
192 /* Main part */
193 NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_N_HEADLINE),
194 NWidget(WWT_INSET, COLOUR_LIGHT_BLUE, WID_N_INSET), SetPadding(2, 2, 2, 2),
195 NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetPadding(1, 1, 1, 1), SetMinimalSize(274, 47), SetFill(1, 0),
196 EndContainer(),
197 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(275, 20), SetFill(1, 0), SetPadding(0, 5, 0, 5),
198 EndContainer(),
201 static WindowDesc _small_news_desc(
202 WDP_MANUAL, nullptr, 0, 0,
203 WC_NEWS_WINDOW, WC_NONE,
205 _nested_small_news_widgets, lengthof(_nested_small_news_widgets)
209 * Window layouts for news items.
211 static WindowDesc* _news_window_layout[] = {
212 &_thin_news_desc, ///< NF_THIN
213 &_small_news_desc, ///< NF_SMALL
214 &_normal_news_desc, ///< NF_NORMAL
215 &_vehicle_news_desc, ///< NF_VEHICLE
216 &_company_news_desc, ///< NF_COMPANY
219 WindowDesc* GetNewsWindowLayout(NewsFlag flags)
221 uint layout = GB(flags, NFB_WINDOW_LAYOUT, NFB_WINDOW_LAYOUT_COUNT);
222 assert(layout < lengthof(_news_window_layout));
223 return _news_window_layout[layout];
227 * Per-NewsType data
229 static NewsTypeData _news_type_data[] = {
230 /* name, age, sound, */
231 NewsTypeData("news_display.arrival_player", 60, SND_1D_APPLAUSE ), ///< NT_ARRIVAL_COMPANY
232 NewsTypeData("news_display.arrival_other", 60, SND_1D_APPLAUSE ), ///< NT_ARRIVAL_OTHER
233 NewsTypeData("news_display.accident", 90, SND_BEGIN ), ///< NT_ACCIDENT
234 NewsTypeData("news_display.company_info", 60, SND_BEGIN ), ///< NT_COMPANY_INFO
235 NewsTypeData("news_display.open", 90, SND_BEGIN ), ///< NT_INDUSTRY_OPEN
236 NewsTypeData("news_display.close", 90, SND_BEGIN ), ///< NT_INDUSTRY_CLOSE
237 NewsTypeData("news_display.economy", 30, SND_BEGIN ), ///< NT_ECONOMY
238 NewsTypeData("news_display.production_player", 30, SND_BEGIN ), ///< NT_INDUSTRY_COMPANY
239 NewsTypeData("news_display.production_other", 30, SND_BEGIN ), ///< NT_INDUSTRY_OTHER
240 NewsTypeData("news_display.production_nobody", 30, SND_BEGIN ), ///< NT_INDUSTRY_NOBODY
241 NewsTypeData("news_display.advice", 150, SND_BEGIN ), ///< NT_ADVICE
242 NewsTypeData("news_display.new_vehicles", 30, SND_1E_OOOOH ), ///< NT_NEW_VEHICLES
243 NewsTypeData("news_display.acceptance", 90, SND_BEGIN ), ///< NT_ACCEPTANCE
244 NewsTypeData("news_display.subsidies", 180, SND_BEGIN ), ///< NT_SUBSIDIES
245 NewsTypeData("news_display.general", 60, SND_BEGIN ), ///< NT_GENERAL
248 static_assert(lengthof(_news_type_data) == NT_END);
251 * Return the news display option.
252 * @return display options
254 NewsDisplay NewsTypeData::GetDisplay() const
256 uint index;
257 const SettingDesc *sd = GetSettingFromName(this->name, &index);
258 assert(sd != nullptr);
259 void *ptr = GetVariableAddress(nullptr, &sd->save);
260 return (NewsDisplay)ReadValue(ptr, sd->save.conv);
263 /** Window class displaying a news item. */
264 struct NewsWindow : Window {
265 uint16 chat_height; ///< Height of the chat window.
266 uint16 status_height; ///< Height of the status bar window
267 const NewsItem *ni; ///< News item to display.
268 static int duration; ///< Remaining time for showing the current news message (may only be access while a news item is displayed).
270 GUITimer timer;
272 NewsWindow(WindowDesc *desc, const NewsItem *ni) : Window(desc), ni(ni)
274 NewsWindow::duration = 16650;
275 const Window *w = FindWindowByClass(WC_SEND_NETWORK_MSG);
276 this->chat_height = (w != nullptr) ? w->height : 0;
277 this->status_height = FindWindowById(WC_STATUS_BAR, 0)->height;
279 this->flags |= WF_DISABLE_VP_SCROLL;
281 this->timer.SetInterval(15);
283 this->CreateNestedTree();
285 /* For company news with a face we have a separate headline in param[0] */
286 if (desc == &_company_news_desc) this->GetWidget<NWidgetCore>(WID_N_TITLE)->widget_data = this->ni->params[0];
288 NWidgetCore *nwid = this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP);
289 if (ni->reftype1 == NR_VEHICLE && nwid != nullptr) {
290 const Vehicle *v = Vehicle::Get(ni->ref1);
291 switch (v->type) {
292 case VEH_TRAIN:
293 nwid->widget_data = STR_TRAIN;
294 break;
295 case VEH_ROAD:
296 nwid->widget_data = RoadVehicle::From(v)->IsBus() ? STR_BUS : STR_LORRY;
297 break;
298 case VEH_SHIP:
299 nwid->widget_data = STR_SHIP;
300 break;
301 case VEH_AIRCRAFT:
302 nwid->widget_data = STR_PLANE;
303 break;
304 default:
305 break; // Do nothing
309 this->FinishInitNested(0);
311 /* Initialize viewport if it exists. */
312 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
313 if (nvp != nullptr) {
314 nvp->InitializeViewport(this, ni->reftype1 == NR_VEHICLE ? 0x80000000 | ni->ref1 : GetReferenceTile(ni->reftype1, ni->ref1), ZOOM_LVL_NEWS);
315 if (this->ni->flags & NF_NO_TRANSPARENT) nvp->disp_flags |= ND_NO_TRANSPARENCY;
316 if ((this->ni->flags & NF_INCOLOUR) == 0) {
317 nvp->disp_flags |= ND_SHADE_GREY;
318 } else if (this->ni->flags & NF_SHADE) {
319 nvp->disp_flags |= ND_SHADE_DIMMED;
323 PositionNewsMessage(this);
326 void DrawNewsBorder(const Rect &r) const
328 GfxFillRect(r.left, r.top, r.right, r.bottom, PC_WHITE);
330 GfxFillRect(r.left, r.top, r.left, r.bottom, PC_BLACK);
331 GfxFillRect(r.right, r.top, r.right, r.bottom, PC_BLACK);
332 GfxFillRect(r.left, r.top, r.right, r.top, PC_BLACK);
333 GfxFillRect(r.left, r.bottom, r.right, r.bottom, PC_BLACK);
336 Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
338 Point pt = { 0, _screen.height };
339 return pt;
342 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
344 StringID str = STR_NULL;
345 switch (widget) {
346 case WID_N_CAPTION: {
347 /* Caption is not a real caption (so that the window cannot be moved)
348 * thus it doesn't get the default sizing of a caption. */
349 Dimension d2 = GetStringBoundingBox(STR_NEWS_MESSAGE_CAPTION);
350 d2.height += WD_CAPTIONTEXT_TOP + WD_CAPTIONTEXT_BOTTOM;
351 *size = maxdim(*size, d2);
352 return;
355 case WID_N_MGR_FACE:
356 *size = maxdim(*size, GetSpriteSize(SPR_GRADIENT));
357 break;
359 case WID_N_MGR_NAME:
360 SetDParamStr(0, static_cast<const CompanyNewsInformation *>(this->ni->free_data)->president_name);
361 str = STR_JUST_RAW_STRING;
362 break;
364 case WID_N_MESSAGE:
365 CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
366 str = this->ni->string_id;
367 break;
369 case WID_N_COMPANY_MSG:
370 str = this->GetCompanyMessageString();
371 break;
373 case WID_N_VEH_NAME:
374 case WID_N_VEH_TITLE:
375 str = this->GetNewVehicleMessageString(widget);
376 break;
378 case WID_N_VEH_INFO: {
379 assert(this->ni->reftype1 == NR_ENGINE);
380 EngineID engine = this->ni->ref1;
381 str = GetEngineInfoString(engine);
382 break;
385 case WID_N_SHOW_GROUP:
386 if (this->ni->reftype1 == NR_VEHICLE) {
387 Dimension d2 = GetStringBoundingBox(this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP)->widget_data);
388 d2.height += WD_CAPTIONTEXT_TOP + WD_CAPTIONTEXT_BOTTOM;
389 d2.width += WD_CAPTIONTEXT_LEFT + WD_CAPTIONTEXT_RIGHT;
390 *size = d2;
391 } else {
392 /* Hide 'Show group window' button if this news is not about a vehicle. */
393 size->width = 0;
394 size->height = 0;
395 resize->width = 0;
396 resize->height = 0;
397 fill->width = 0;
398 fill->height = 0;
400 return;
402 default:
403 return; // Do nothing
406 /* Update minimal size with length of the multi-line string. */
407 Dimension d = *size;
408 d.width = (d.width >= padding.width) ? d.width - padding.width : 0;
409 d.height = (d.height >= padding.height) ? d.height - padding.height : 0;
410 d = GetStringMultiLineBoundingBox(str, d);
411 d.width += padding.width;
412 d.height += padding.height;
413 *size = maxdim(*size, d);
416 void SetStringParameters(int widget) const override
418 if (widget == WID_N_DATE) SetDParam(0, this->ni->date);
421 void DrawWidget(const Rect &r, int widget) const override
423 switch (widget) {
424 case WID_N_CAPTION:
425 DrawCaption(r, COLOUR_LIGHT_BLUE, this->owner, STR_NEWS_MESSAGE_CAPTION);
426 break;
428 case WID_N_PANEL:
429 this->DrawNewsBorder(r);
430 break;
432 case WID_N_MESSAGE:
433 CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
434 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->ni->string_id, TC_FROMSTRING, SA_CENTER);
435 break;
437 case WID_N_MGR_FACE: {
438 const CompanyNewsInformation *cni = (const CompanyNewsInformation*)this->ni->free_data;
439 DrawCompanyManagerFace(cni->face, cni->colour, r.left, r.top);
440 GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
441 break;
443 case WID_N_MGR_NAME: {
444 const CompanyNewsInformation *cni = (const CompanyNewsInformation*)this->ni->free_data;
445 SetDParamStr(0, cni->president_name);
446 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, STR_JUST_RAW_STRING, TC_FROMSTRING, SA_CENTER);
447 break;
449 case WID_N_COMPANY_MSG:
450 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->GetCompanyMessageString(), TC_FROMSTRING, SA_CENTER);
451 break;
453 case WID_N_VEH_BKGND:
454 GfxFillRect(r.left, r.top, r.right, r.bottom, PC_GREY);
455 break;
457 case WID_N_VEH_NAME:
458 case WID_N_VEH_TITLE:
459 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->GetNewVehicleMessageString(widget), TC_FROMSTRING, SA_CENTER);
460 break;
462 case WID_N_VEH_SPR: {
463 assert(this->ni->reftype1 == NR_ENGINE);
464 EngineID engine = this->ni->ref1;
465 DrawVehicleEngine(r.left, r.right, (r.left + r.right) / 2, (r.top + r.bottom) / 2, engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
466 GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
467 break;
469 case WID_N_VEH_INFO: {
470 assert(this->ni->reftype1 == NR_ENGINE);
471 EngineID engine = this->ni->ref1;
472 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
473 break;
478 void OnClick(Point pt, int widget, int click_count) override
480 switch (widget) {
481 case WID_N_CLOSEBOX:
482 NewsWindow::duration = 0;
483 delete this;
484 _forced_news = nullptr;
485 break;
487 case WID_N_CAPTION:
488 if (this->ni->reftype1 == NR_VEHICLE) {
489 const Vehicle *v = Vehicle::Get(this->ni->ref1);
490 ShowVehicleViewWindow(v);
492 break;
494 case WID_N_VIEWPORT:
495 break; // Ignore clicks
497 case WID_N_SHOW_GROUP:
498 if (this->ni->reftype1 == NR_VEHICLE) {
499 const Vehicle *v = Vehicle::Get(this->ni->ref1);
500 ShowCompanyGroupForVehicle(v);
502 break;
503 default:
504 if (this->ni->reftype1 == NR_VEHICLE) {
505 const Vehicle *v = Vehicle::Get(this->ni->ref1);
506 ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos);
507 } else {
508 TileIndex tile1 = GetReferenceTile(this->ni->reftype1, this->ni->ref1);
509 TileIndex tile2 = GetReferenceTile(this->ni->reftype2, this->ni->ref2);
510 if (_ctrl_pressed) {
511 if (tile1 != INVALID_TILE) ShowExtraViewportWindow(tile1);
512 if (tile2 != INVALID_TILE) ShowExtraViewportWindow(tile2);
513 } else {
514 if ((tile1 == INVALID_TILE || !ScrollMainWindowToTile(tile1)) && tile2 != INVALID_TILE) {
515 ScrollMainWindowToTile(tile2);
519 break;
524 * Some data on this window has become invalid.
525 * @param data Information about the changed data.
526 * @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.
528 void OnInvalidateData(int data = 0, bool gui_scope = true) override
530 if (!gui_scope) return;
531 /* The chatbar has notified us that is was either created or closed */
532 int newtop = this->top + this->chat_height - data;
533 this->chat_height = data;
534 this->SetWindowTop(newtop);
537 void OnRealtimeTick(uint delta_ms) override
539 int count = this->timer.CountElapsed(delta_ms);
540 if (count > 0) {
541 /* Scroll up newsmessages from the bottom */
542 int newtop = std::max(this->top - 2 * count, _screen.height - this->height - this->status_height - this->chat_height);
543 this->SetWindowTop(newtop);
546 /* Decrement the news timer. We don't need to action an elapsed event here,
547 * so no need to use TimerElapsed(). */
548 if (NewsWindow::duration > 0) NewsWindow::duration -= delta_ms;
551 private:
553 * Moves the window to a new #top coordinate. Makes screen dirty where needed.
554 * @param newtop new top coordinate
556 void SetWindowTop(int newtop)
558 if (this->top == newtop) return;
560 int mintop = std::min(newtop, this->top);
561 int maxtop = std::max(newtop, this->top);
562 if (this->viewport != nullptr) this->viewport->top += newtop - this->top;
563 this->top = newtop;
565 AddDirtyBlock(this->left, mintop, this->left + this->width, maxtop + this->height);
568 StringID GetCompanyMessageString() const
570 /* Company news with a face have a separate headline, so the normal message is shifted by two params */
571 CopyInDParam(0, this->ni->params + 2, lengthof(this->ni->params) - 2);
572 return this->ni->params[1];
575 StringID GetNewVehicleMessageString(int widget) const
577 assert(this->ni->reftype1 == NR_ENGINE);
578 EngineID engine = this->ni->ref1;
580 switch (widget) {
581 case WID_N_VEH_TITLE:
582 SetDParam(0, GetEngineCategoryName(engine));
583 return STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE;
585 case WID_N_VEH_NAME:
586 SetDParam(0, engine);
587 return STR_NEWS_NEW_VEHICLE_TYPE;
589 default:
590 NOT_REACHED();
595 /* static */ int NewsWindow::duration = 0; // Instance creation.
597 /** Open up an own newspaper window for the news item */
598 static void ShowNewspaper(const NewsItem *ni)
600 SoundFx sound = _news_type_data[ni->type].sound;
601 if (sound != 0 && _settings_client.sound.news_full) SndPlayFx(sound);
603 new NewsWindow(GetNewsWindowLayout(ni->flags), ni);
606 /** Show news item in the ticker */
607 static void ShowTicker(const NewsItem *ni)
609 if (_settings_client.sound.news_ticker) SndPlayFx(SND_16_MORSE);
611 _statusbar_news_item = ni;
612 InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_TICKER);
615 /** Initialize the news-items data structures */
616 void InitNewsItemStructs()
618 for (NewsItem *ni = _oldest_news; ni != nullptr; ) {
619 NewsItem *next = ni->next;
620 delete ni;
621 ni = next;
624 _total_news = 0;
625 _oldest_news = nullptr;
626 _latest_news = nullptr;
627 _forced_news = nullptr;
628 _current_news = nullptr;
629 _statusbar_news_item = nullptr;
630 NewsWindow::duration = 0;
634 * Are we ready to show another ticker item?
635 * Only if nothing is in the newsticker is displayed
637 static bool ReadyForNextTickerItem()
639 const NewsItem *ni = _statusbar_news_item;
640 if (ni == nullptr) return true;
642 /* Ticker message
643 * Check if the status bar message is still being displayed? */
644 if (IsNewsTickerShown()) return false;
645 return true;
649 * Are we ready to show another news item?
650 * Only if no newspaper is displayed
652 static bool ReadyForNextNewsItem()
654 const NewsItem *ni = _forced_news == nullptr ? _current_news : _forced_news;
655 if (ni == nullptr) return true;
657 /* neither newsticker nor newspaper are running */
658 return (NewsWindow::duration <= 0 || FindWindowById(WC_NEWS_WINDOW, 0) == nullptr);
661 /** Move to the next ticker item */
662 static void MoveToNextTickerItem()
664 /* There is no status bar, so no reason to show news;
665 * especially important with the end game screen when
666 * there is no status bar but possible news. */
667 if (FindWindowById(WC_STATUS_BAR, 0) == nullptr) return;
669 InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); // invalidate the statusbar
671 /* if we're not at the last item, then move on */
672 while (_statusbar_news_item != _latest_news) {
673 _statusbar_news_item = (_statusbar_news_item == nullptr) ? _oldest_news : _statusbar_news_item->next;
674 const NewsItem *ni = _statusbar_news_item;
675 const NewsType type = ni->type;
677 /* check the date, don't show too old items */
678 if (_date - _news_type_data[type].age > ni->date) continue;
680 switch (_news_type_data[type].GetDisplay()) {
681 default: NOT_REACHED();
682 case ND_OFF: // Off - show nothing only a small reminder in the status bar
683 InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_REMINDER);
684 break;
686 case ND_SUMMARY: // Summary - show ticker
687 ShowTicker(ni);
688 break;
690 case ND_FULL: // Full - show newspaper, skipped here
691 continue;
693 return;
697 /** Move to the next news item */
698 static void MoveToNextNewsItem()
700 /* There is no status bar, so no reason to show news;
701 * especially important with the end game screen when
702 * there is no status bar but possible news. */
703 if (FindWindowById(WC_STATUS_BAR, 0) == nullptr) return;
705 DeleteWindowById(WC_NEWS_WINDOW, 0); // close the newspapers window if shown
706 _forced_news = nullptr;
708 /* if we're not at the last item, then move on */
709 while (_current_news != _latest_news) {
710 _current_news = (_current_news == nullptr) ? _oldest_news : _current_news->next;
711 const NewsItem *ni = _current_news;
712 const NewsType type = ni->type;
714 /* check the date, don't show too old items */
715 if (_date - _news_type_data[type].age > ni->date) continue;
717 switch (_news_type_data[type].GetDisplay()) {
718 default: NOT_REACHED();
719 case ND_OFF: // Off - show nothing only a small reminder in the status bar, skipped here
720 continue;
722 case ND_SUMMARY: // Summary - show ticker, skipped here
723 continue;
725 case ND_FULL: // Full - show newspaper
726 ShowNewspaper(ni);
727 break;
729 return;
733 /** Delete a news item from the queue */
734 static void DeleteNewsItem(NewsItem *ni)
736 /* Delete the news from the news queue. */
737 if (ni->prev != nullptr) {
738 ni->prev->next = ni->next;
739 } else {
740 assert(_oldest_news == ni);
741 _oldest_news = ni->next;
744 if (ni->next != nullptr) {
745 ni->next->prev = ni->prev;
746 } else {
747 assert(_latest_news == ni);
748 _latest_news = ni->prev;
751 _total_news--;
753 if (_forced_news == ni || _current_news == ni) {
754 /* When we're the current news, go to the previous item first;
755 * we just possibly made that the last news item. */
756 if (_current_news == ni) _current_news = ni->prev;
758 /* About to remove the currently forced item (shown as newspapers) ||
759 * about to remove the currently displayed item (newspapers) */
760 MoveToNextNewsItem();
763 if (_statusbar_news_item == ni) {
764 /* When we're the current news, go to the previous item first;
765 * we just possibly made that the last news item. */
766 _statusbar_news_item = ni->prev;
768 /* About to remove the currently displayed item (ticker, or just a reminder) */
769 MoveToNextTickerItem();
772 delete ni;
774 SetWindowDirty(WC_MESSAGE_HISTORY, 0);
778 * Add a new newsitem to be shown.
779 * @param string String to display
780 * @param type news category
781 * @param flags display flags for the news
782 * @param reftype1 Type of ref1
783 * @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.
784 * @param reftype2 Type of ref2
785 * @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.
786 * @param free_data Pointer to data that must be freed once the news message is cleared
788 * @see NewsSubtype
790 void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32 ref1, NewsReferenceType reftype2, uint32 ref2, void *free_data)
792 if (_game_mode == GM_MENU) return;
794 /* Create new news item node */
795 NewsItem *ni = new NewsItem;
797 ni->string_id = string;
798 ni->type = type;
799 ni->flags = flags;
801 /* show this news message in colour? */
802 if (_cur_year >= _settings_client.gui.coloured_news_year) ni->flags |= NF_INCOLOUR;
804 ni->reftype1 = reftype1;
805 ni->reftype2 = reftype2;
806 ni->ref1 = ref1;
807 ni->ref2 = ref2;
808 ni->free_data = free_data;
809 ni->date = _date;
810 CopyOutDParam(ni->params, 0, lengthof(ni->params));
812 if (_total_news++ == 0) {
813 assert(_oldest_news == nullptr);
814 _oldest_news = ni;
815 ni->prev = nullptr;
816 } else {
817 assert(_latest_news->next == nullptr);
818 _latest_news->next = ni;
819 ni->prev = _latest_news;
822 ni->next = nullptr;
823 _latest_news = ni;
825 /* Keep the number of stored news items to a managable number */
826 if (_total_news > MAX_NEWS_AMOUNT) {
827 DeleteNewsItem(_oldest_news);
830 SetWindowDirty(WC_MESSAGE_HISTORY, 0);
834 * Create a new custom news item.
835 * @param tile unused
836 * @param flags type of operation
837 * @param p1 various bitstuffed elements
838 * - p1 = (bit 0 - 7) - NewsType of the message.
839 * - p1 = (bit 8 - 15) - NewsReferenceType of first reference.
840 * - p1 = (bit 16 - 23) - Company this news message is for.
841 * @param p2 First reference of the news message.
842 * @param text The text of the news message.
843 * @return the cost of this operation or an error
845 CommandCost CmdCustomNewsItem(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
847 if (_current_company != OWNER_DEITY) return CMD_ERROR;
849 NewsType type = (NewsType)GB(p1, 0, 8);
850 NewsReferenceType reftype1 = (NewsReferenceType)GB(p1, 8, 8);
851 CompanyID company = (CompanyID)GB(p1, 16, 8);
853 if (company != INVALID_OWNER && !Company::IsValidID(company)) return CMD_ERROR;
854 if (type >= NT_END) return CMD_ERROR;
855 if (StrEmpty(text)) return CMD_ERROR;
857 switch (reftype1) {
858 case NR_NONE: break;
859 case NR_TILE:
860 if (!IsValidTile(p2)) return CMD_ERROR;
861 break;
863 case NR_VEHICLE:
864 if (!Vehicle::IsValidID(p2)) return CMD_ERROR;
865 break;
867 case NR_STATION:
868 if (!Station::IsValidID(p2)) return CMD_ERROR;
869 break;
871 case NR_INDUSTRY:
872 if (!Industry::IsValidID(p2)) return CMD_ERROR;
873 break;
875 case NR_TOWN:
876 if (!Town::IsValidID(p2)) return CMD_ERROR;
877 break;
879 case NR_ENGINE:
880 if (!Engine::IsValidID(p2)) return CMD_ERROR;
881 break;
883 default: return CMD_ERROR;
886 if (company != INVALID_OWNER && company != _local_company) return CommandCost();
888 if (flags & DC_EXEC) {
889 char *news = stredup(text);
890 SetDParamStr(0, news);
891 AddNewsItem(STR_NEWS_CUSTOM_ITEM, type, NF_NORMAL, reftype1, p2, NR_NONE, UINT32_MAX, news);
894 return CommandCost();
898 * Delete a news item type about a vehicle.
899 * When the news item type is INVALID_STRING_ID all news about the vehicle gets deleted.
900 * @param vid The vehicle to remove the news for.
901 * @param news The news type to remove.
903 void DeleteVehicleNews(VehicleID vid, StringID news)
905 NewsItem *ni = _oldest_news;
907 while (ni != nullptr) {
908 NewsItem *next = ni->next;
909 if (((ni->reftype1 == NR_VEHICLE && ni->ref1 == vid) || (ni->reftype2 == NR_VEHICLE && ni->ref2 == vid)) &&
910 (news == INVALID_STRING_ID || ni->string_id == news)) {
911 DeleteNewsItem(ni);
913 ni = next;
918 * Remove news regarding given station so there are no 'unknown station now accepts Mail'
919 * or 'First train arrived at unknown station' news items.
920 * @param sid station to remove news about
922 void DeleteStationNews(StationID sid)
924 NewsItem *ni = _oldest_news;
926 while (ni != nullptr) {
927 NewsItem *next = ni->next;
928 if ((ni->reftype1 == NR_STATION && ni->ref1 == sid) || (ni->reftype2 == NR_STATION && ni->ref2 == sid)) {
929 DeleteNewsItem(ni);
931 ni = next;
936 * Remove news regarding given industry
937 * @param iid industry to remove news about
939 void DeleteIndustryNews(IndustryID iid)
941 NewsItem *ni = _oldest_news;
943 while (ni != nullptr) {
944 NewsItem *next = ni->next;
945 if ((ni->reftype1 == NR_INDUSTRY && ni->ref1 == iid) || (ni->reftype2 == NR_INDUSTRY && ni->ref2 == iid)) {
946 DeleteNewsItem(ni);
948 ni = next;
953 * Remove engine announcements for invalid engines.
955 void DeleteInvalidEngineNews()
957 NewsItem *ni = _oldest_news;
959 while (ni != nullptr) {
960 NewsItem *next = ni->next;
961 if ((ni->reftype1 == NR_ENGINE && (!Engine::IsValidID(ni->ref1) || !Engine::Get(ni->ref1)->IsEnabled())) ||
962 (ni->reftype2 == NR_ENGINE && (!Engine::IsValidID(ni->ref2) || !Engine::Get(ni->ref2)->IsEnabled()))) {
963 DeleteNewsItem(ni);
965 ni = next;
969 static void RemoveOldNewsItems()
971 NewsItem *next;
972 for (NewsItem *cur = _oldest_news; _total_news > MIN_NEWS_AMOUNT && cur != nullptr; cur = next) {
973 next = cur->next;
974 if (_date - _news_type_data[cur->type].age * _settings_client.gui.news_message_timeout > cur->date) DeleteNewsItem(cur);
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 (NewsItem *ni = _oldest_news; ni != nullptr; ni = ni->next) {
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 && ni->params[0] == from_index) ni->params[0] = to_index;
993 void NewsLoop()
995 /* no news item yet */
996 if (_total_news == 0) return;
998 static byte _last_clean_month = 0;
1000 if (_last_clean_month != _cur_month) {
1001 RemoveOldNewsItems();
1002 _last_clean_month = _cur_month;
1005 if (ReadyForNextTickerItem()) MoveToNextTickerItem();
1006 if (ReadyForNextNewsItem()) MoveToNextNewsItem();
1009 /** Do a forced show of a specific message */
1010 static void ShowNewsMessage(const NewsItem *ni)
1012 assert(_total_news != 0);
1014 /* Delete the news window */
1015 DeleteWindowById(WC_NEWS_WINDOW, 0);
1017 /* setup forced news item */
1018 _forced_news = ni;
1020 if (_forced_news != nullptr) {
1021 DeleteWindowById(WC_NEWS_WINDOW, 0);
1022 ShowNewspaper(ni);
1027 * Close active news message window
1028 * @return true if a window was closed.
1030 bool HideActiveNewsMessage() {
1031 NewsWindow *w = (NewsWindow*)FindWindowById(WC_NEWS_WINDOW, 0);
1032 if (w == nullptr) return false;
1033 delete w;
1034 return true;
1037 /** Show previous news item */
1038 void ShowLastNewsMessage()
1040 const NewsItem *ni = nullptr;
1041 if (_total_news == 0) {
1042 return;
1043 } else if (_forced_news == nullptr) {
1044 /* Not forced any news yet, show the current one, unless a news window is
1045 * open (which can only be the current one), then show the previous item */
1046 if (_current_news == nullptr) {
1047 /* No news were shown yet resp. the last shown one was already deleted.
1048 * Threat this as if _forced_news reached _oldest_news; so, wrap around and start anew with the latest. */
1049 ni = _latest_news;
1050 } else {
1051 const Window *w = FindWindowById(WC_NEWS_WINDOW, 0);
1052 ni = (w == nullptr || (_current_news == _oldest_news)) ? _current_news : _current_news->prev;
1054 } else if (_forced_news == _oldest_news) {
1055 /* We have reached the oldest news, start anew with the latest */
1056 ni = _latest_news;
1057 } else {
1058 /* 'Scrolling' through news history show each one in turn */
1059 ni = _forced_news->prev;
1061 bool wrap = false;
1062 for (;;) {
1063 if (_news_type_data[ni->type].GetDisplay() != ND_OFF) {
1064 ShowNewsMessage(ni);
1065 break;
1068 ni = ni->prev;
1069 if (ni == nullptr) {
1070 if (wrap) break;
1071 /* We have reached the oldest news, start anew with the latest */
1072 ni = _latest_news;
1073 wrap = true;
1080 * Draw an unformatted news message truncated to a maximum length. If
1081 * length exceeds maximum length it will be postfixed by '...'
1082 * @param left the left most location for the string
1083 * @param right the right most location for the string
1084 * @param y position of the string
1085 * @param colour the colour the string will be shown in
1086 * @param *ni NewsItem being printed
1088 static void DrawNewsString(uint left, uint right, int y, TextColour colour, const NewsItem *ni)
1090 char buffer[512], buffer2[512];
1091 StringID str;
1093 CopyInDParam(0, ni->params, lengthof(ni->params));
1094 str = ni->string_id;
1096 GetString(buffer, str, lastof(buffer));
1097 /* Copy the just gotten string to another buffer to remove any formatting
1098 * from it such as big fonts, etc. */
1099 const char *ptr = buffer;
1100 char *dest = buffer2;
1101 WChar c_last = '\0';
1102 for (;;) {
1103 WChar c = Utf8Consume(&ptr);
1104 if (c == 0) break;
1105 /* Make a space from a newline, but ignore multiple newlines */
1106 if (c == '\n' && c_last != '\n') {
1107 dest[0] = ' ';
1108 dest++;
1109 } else if (c == '\r') {
1110 dest[0] = dest[1] = dest[2] = dest[3] = ' ';
1111 dest += 4;
1112 } else if (IsPrintable(c)) {
1113 dest += Utf8Encode(dest, c);
1115 c_last = c;
1118 *dest = '\0';
1119 /* Truncate and show string; postfixed by '...' if necessary */
1120 DrawString(left, right, y, buffer2, colour);
1123 struct MessageHistoryWindow : Window {
1124 static const int top_spacing; ///< Additional spacing at the top of the #WID_MH_BACKGROUND widget.
1125 static const int bottom_spacing; ///< Additional spacing at the bottom of the #WID_MH_BACKGROUND widget.
1127 int line_height; /// < Height of a single line in the news history window including spacing.
1128 int date_width; /// < Width needed for the date part.
1130 Scrollbar *vscroll;
1132 MessageHistoryWindow(WindowDesc *desc) : Window(desc)
1134 this->CreateNestedTree();
1135 this->vscroll = this->GetScrollbar(WID_MH_SCROLLBAR);
1136 this->FinishInitNested(); // Initializes 'this->line_height' and 'this->date_width'.
1137 this->OnInvalidateData(0);
1140 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1142 if (widget == WID_MH_BACKGROUND) {
1143 this->line_height = FONT_HEIGHT_NORMAL + 2;
1144 resize->height = this->line_height;
1146 /* Months are off-by-one, so it's actually 8. Not using
1147 * month 12 because the 1 is usually less wide. */
1148 SetDParam(0, ConvertYMDToDate(ORIGINAL_MAX_YEAR, 7, 30));
1149 this->date_width = GetStringBoundingBox(STR_SHORT_DATE).width;
1151 size->height = 4 * resize->height + this->top_spacing + this->bottom_spacing; // At least 4 lines are visible.
1152 size->width = std::max(200u, size->width); // At least 200 pixels wide.
1156 void OnPaint() override
1158 this->OnInvalidateData(0);
1159 this->DrawWidgets();
1162 void DrawWidget(const Rect &r, int widget) const override
1164 if (widget != WID_MH_BACKGROUND || _total_news == 0) return;
1166 /* Find the first news item to display. */
1167 NewsItem *ni = _latest_news;
1168 for (int n = this->vscroll->GetPosition(); n > 0; n--) {
1169 ni = ni->prev;
1170 if (ni == nullptr) return;
1173 /* Fill the widget with news items. */
1174 int y = r.top + this->top_spacing;
1175 bool rtl = _current_text_dir == TD_RTL;
1176 uint date_left = rtl ? r.right - WD_FRAMERECT_RIGHT - this->date_width : r.left + WD_FRAMERECT_LEFT;
1177 uint date_right = rtl ? r.right - WD_FRAMERECT_RIGHT : r.left + WD_FRAMERECT_LEFT + this->date_width;
1178 uint news_left = rtl ? r.left + WD_FRAMERECT_LEFT : r.left + WD_FRAMERECT_LEFT + this->date_width + WD_FRAMERECT_RIGHT + ScaleFontTrad(5);
1179 uint news_right = rtl ? r.right - WD_FRAMERECT_RIGHT - this->date_width - WD_FRAMERECT_RIGHT - ScaleFontTrad(5) : r.right - WD_FRAMERECT_RIGHT;
1180 for (int n = this->vscroll->GetCapacity(); n > 0; n--) {
1181 SetDParam(0, ni->date);
1182 DrawString(date_left, date_right, y, STR_SHORT_DATE);
1184 DrawNewsString(news_left, news_right, y, TC_WHITE, ni);
1185 y += this->line_height;
1187 ni = ni->prev;
1188 if (ni == nullptr) return;
1193 * Some data on this window has become invalid.
1194 * @param data Information about the changed data.
1195 * @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.
1197 void OnInvalidateData(int data = 0, bool gui_scope = true) override
1199 if (!gui_scope) return;
1200 this->vscroll->SetCount(_total_news);
1203 void OnClick(Point pt, int widget, int click_count) override
1205 if (widget == WID_MH_BACKGROUND) {
1206 NewsItem *ni = _latest_news;
1207 if (ni == nullptr) return;
1209 for (int n = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_MH_BACKGROUND, WD_FRAMERECT_TOP, this->line_height); n > 0; n--) {
1210 ni = ni->prev;
1211 if (ni == nullptr) return;
1214 ShowNewsMessage(ni);
1218 void OnResize() override
1220 this->vscroll->SetCapacityFromWidget(this, WID_MH_BACKGROUND);
1224 const int MessageHistoryWindow::top_spacing = WD_FRAMERECT_TOP + 4;
1225 const int MessageHistoryWindow::bottom_spacing = WD_FRAMERECT_BOTTOM;
1227 static const NWidgetPart _nested_message_history[] = {
1228 NWidget(NWID_HORIZONTAL),
1229 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1230 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_MESSAGE_HISTORY, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1231 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1232 NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
1233 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1234 EndContainer(),
1236 NWidget(NWID_HORIZONTAL),
1237 NWidget(WWT_PANEL, COLOUR_BROWN, WID_MH_BACKGROUND), SetMinimalSize(200, 125), SetDataTip(0x0, STR_MESSAGE_HISTORY_TOOLTIP), SetResize(1, 12), SetScrollbar(WID_MH_SCROLLBAR),
1238 EndContainer(),
1239 NWidget(NWID_VERTICAL),
1240 NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_MH_SCROLLBAR),
1241 NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
1242 EndContainer(),
1243 EndContainer(),
1246 static WindowDesc _message_history_desc(
1247 WDP_AUTO, "list_news", 400, 140,
1248 WC_MESSAGE_HISTORY, WC_NONE,
1250 _nested_message_history, lengthof(_nested_message_history)
1253 /** Display window with news messages history */
1254 void ShowMessageHistory()
1256 DeleteWindowById(WC_MESSAGE_HISTORY, 0);
1257 new MessageHistoryWindow(&_message_history_desc);