OpenTTD Source: src/news_gui.cpp Source File

OpenTTD Source 15.0-beta1

news_gui.cpp
Go to the documentation of this file.
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 */
7
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"
40
41#include "widgets/news_widget.h"
42
43#include "table/strings.h"
44
45#include "safeguards.h"
46
47 static const uint MIN_NEWS_AMOUNT = 30;
48 static const uint MAX_NEWS_AMOUNT = 1U << 10;
49
50 static NewsContainer _news;
51
58 static NewsIterator _forced_news = std::end(_news);
59
61 static NewsIterator _current_news = std::end(_news);
62
64 static NewsIterator _statusbar_news = std::end(_news);
65
70 const NewsItem *GetStatusbarNews()
71{
72 return (_statusbar_news == std::end(_news)) ? nullptr : &*_statusbar_news;
73}
74
79 const NewsContainer &GetNews()
80{
81 return _news;
82}
83
90 static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32_t ref)
91{
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;
98 }
99}
100
101/* Normal news items. */
102static constexpr NWidgetPart _nested_normal_news_widgets[] = {
103 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
104 NWidget(NWID_VERTICAL), SetPadding(WidgetDimensions::unscaled.fullbevel),
105 NWidget(NWID_LAYER),
106 /* Layer 1 */
107 NWidget(NWID_VERTICAL), SetPIPRatio(0, 0, 1),
108 NWidget(NWID_HORIZONTAL), SetPIPRatio(0, 1, 0),
109 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX),
110 NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE),
111 SetDataTip(STR_JUST_DATE_LONG, STR_NULL),
112 SetTextStyle(TC_BLACK, FS_SMALL),
113 SetAlignment(SA_RIGHT | SA_TOP),
114 EndContainer(),
115 EndContainer(),
116 /* Layer 2 */
117 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE),
118 SetMinimalTextLines(8, 0, FS_LARGE),
119 SetMinimalSize(400, 0),
120 SetPadding(WidgetDimensions::unscaled.hsep_indent, WidgetDimensions::unscaled.vsep_wide),
121 EndContainer(),
122 EndContainer(),
123 EndContainer(),
124};
125
126static WindowDesc _normal_news_desc(
127 WDP_MANUAL, nullptr, 0, 0,
128 WC_NEWS_WINDOW, WC_NONE,
129 0,
130 _nested_normal_news_widgets
131);
132
133/* New vehicles news items. */
134static constexpr NWidgetPart _nested_vehicle_news_widgets[] = {
135 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
136 NWidget(NWID_VERTICAL), SetPadding(WidgetDimensions::unscaled.fullbevel),
137 NWidget(NWID_LAYER),
138 /* Layer 1 */
139 NWidget(NWID_VERTICAL), SetPIPRatio(0, 0, 1),
140 NWidget(NWID_HORIZONTAL), SetPIPRatio(0, 1, 0),
141 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX),
142 EndContainer(),
143 EndContainer(),
144 /* Layer 2 */
145 NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_VEH_TITLE),
146 SetFill(1, 1),
147 SetMinimalTextLines(2, 0, FS_LARGE),
148 SetMinimalSize(400, 0),
149 SetPadding(WidgetDimensions::unscaled.hsep_indent, WidgetDimensions::unscaled.vsep_wide),
150 SetDataTip(STR_EMPTY, STR_NULL),
151 EndContainer(),
152 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_VEH_BKGND), SetPadding(WidgetDimensions::unscaled.fullbevel),
153 NWidget(NWID_VERTICAL),
154 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_NAME),
155 SetMinimalTextLines(1, 0, FS_LARGE),
156 SetMinimalSize(350, 0),
157 SetPadding(WidgetDimensions::unscaled.hsep_indent, WidgetDimensions::unscaled.vsep_wide),
158 SetFill(1, 0),
159 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_SPR),
160 SetMinimalSize(350, 32),
161 SetFill(1, 0),
162 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_INFO),
163 SetMinimalTextLines(3, 0, FS_NORMAL),
164 SetMinimalSize(350, 0),
165 SetPadding(WidgetDimensions::unscaled.hsep_indent, WidgetDimensions::unscaled.vsep_wide),
166 SetFill(1, 0),
167 EndContainer(),
168 EndContainer(),
169 EndContainer(),
170 EndContainer(),
171};
172
173static WindowDesc _vehicle_news_desc(
174 WDP_MANUAL, nullptr, 0, 0,
175 WC_NEWS_WINDOW, WC_NONE,
176 0,
177 _nested_vehicle_news_widgets
178);
179
180/* Company news items. */
181static constexpr NWidgetPart _nested_company_news_widgets[] = {
182 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
183 NWidget(NWID_VERTICAL), SetPadding(WidgetDimensions::unscaled.fullbevel),
184 NWidget(NWID_LAYER),
185 /* Layer 1 */
186 NWidget(NWID_VERTICAL), SetPIPRatio(0, 0, 1),
187 NWidget(NWID_HORIZONTAL), SetPIPRatio(0, 1, 0),
188 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX),
189 EndContainer(),
190 EndContainer(),
191 /* Layer 2 */
192 NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_TITLE),
193 SetFill(1, 1),
194 SetMinimalTextLines(1, 0, FS_LARGE),
195 SetMinimalSize(400, 0),
196 SetPadding(WidgetDimensions::unscaled.hsep_indent, WidgetDimensions::unscaled.vsep_normal),
197 SetDataTip(STR_EMPTY, STR_NULL),
198 EndContainer(),
199 NWidget(NWID_HORIZONTAL),
200 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0), SetPadding(2),
201 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MGR_FACE),
202 SetFill(0, 0),
203 SetMinimalSize(93, 119),
204 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MGR_NAME),
205 SetFill(0, 1),
206 SetMinimalTextLines(2, 0),
207 EndContainer(),
208 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_COMPANY_MSG),
209 SetFill(1, 1),
210 SetPadding(WidgetDimensions::unscaled.hsep_indent, WidgetDimensions::unscaled.vsep_wide),
211 SetMinimalSize(300, 0),
212 EndContainer(),
213 EndContainer(),
214 EndContainer(),
215};
216
217static WindowDesc _company_news_desc(
218 WDP_MANUAL, nullptr, 0, 0,
219 WC_NEWS_WINDOW, WC_NONE,
220 0,
221 _nested_company_news_widgets
222);
223
224/* Thin news items. */
225static constexpr NWidgetPart _nested_thin_news_widgets[] = {
226 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
227 NWidget(NWID_VERTICAL), SetPadding(WidgetDimensions::unscaled.fullbevel),
228 NWidget(NWID_LAYER),
229 /* Layer 1 */
230 NWidget(NWID_VERTICAL), SetPIPRatio(0, 0, 1),
231 NWidget(NWID_HORIZONTAL), SetPIPRatio(0, 1, 0),
232 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX),
233 NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE),
234 SetDataTip(STR_JUST_DATE_LONG, STR_NULL),
235 SetTextStyle(TC_BLACK, FS_SMALL),
236 SetAlignment(SA_RIGHT | SA_TOP),
237 EndContainer(),
238 EndContainer(),
239 /* Layer 2 */
240 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_MESSAGE),
241 SetMinimalTextLines(3, 0, FS_LARGE),
242 SetMinimalSize(400, 0),
243 SetPadding(WidgetDimensions::unscaled.hsep_indent, WidgetDimensions::unscaled.vsep_normal),
244 EndContainer(),
245 NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetMinimalSize(426, 70),
246 SetPadding(WidgetDimensions::unscaled.fullbevel),
247 EndContainer(),
248 EndContainer(),
249};
250
251static WindowDesc _thin_news_desc(
252 WDP_MANUAL, nullptr, 0, 0,
253 WC_NEWS_WINDOW, WC_NONE,
254 0,
255 _nested_thin_news_widgets
256);
257
258/* Small news items. */
259static constexpr NWidgetPart _nested_small_news_widgets[] = {
260 /* Caption + close box. The caption is not WWT_CAPTION as the window shall not be moveable and so on. */
261 NWidget(NWID_HORIZONTAL),
262 NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE, WID_N_CLOSEBOX),
263 NWidget(WWT_EMPTY, COLOUR_LIGHT_BLUE, WID_N_CAPTION),
264 NWidget(WWT_TEXTBTN, COLOUR_LIGHT_BLUE, WID_N_SHOW_GROUP),
265 SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON),
266 SetResize(1, 0),
267 SetDataTip(STR_NULL /* filled in later */, STR_NEWS_SHOW_VEHICLE_GROUP_TOOLTIP),
268 EndContainer(),
269
270 /* Main part */
271 NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_N_HEADLINE),
272 NWidget(NWID_VERTICAL),
273 SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
274 SetPadding(2),
275 NWidget(WWT_INSET, COLOUR_LIGHT_BLUE, WID_N_INSET),
276 NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT),
277 SetMinimalSize(274, 47),
278 EndContainer(),
279 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE),
280 SetMinimalTextLines(2, 0),
281 SetMinimalSize(275, 0),
282 EndContainer(),
283 EndContainer(),
284};
285
286static WindowDesc _small_news_desc(
287 WDP_MANUAL, nullptr, 0, 0,
288 WC_NEWS_WINDOW, WC_NONE,
289 0,
290 _nested_small_news_widgets
291);
292
296 static WindowDesc *_news_window_layout[] = {
297 &_thin_news_desc,
298 &_small_news_desc,
299 &_normal_news_desc,
300 &_vehicle_news_desc,
301 &_company_news_desc,
302};
303
304 WindowDesc &GetNewsWindowLayout(NewsFlag flags)
305{
306 uint layout = GB(flags, NFB_WINDOW_LAYOUT, NFB_WINDOW_LAYOUT_COUNT);
307 assert(layout < lengthof(_news_window_layout));
308 return *_news_window_layout[layout];
309}
310
314 static NewsTypeData _news_type_data[] = {
315 /* name, age, sound, */
316 NewsTypeData("news_display.arrival_player", 60, SND_1D_APPLAUSE ),
317 NewsTypeData("news_display.arrival_other", 60, SND_1D_APPLAUSE ),
318 NewsTypeData("news_display.accident", 90, SND_BEGIN ),
319 NewsTypeData("news_display.accident_other", 90, SND_BEGIN ),
320 NewsTypeData("news_display.company_info", 60, SND_BEGIN ),
321 NewsTypeData("news_display.open", 90, SND_BEGIN ),
322 NewsTypeData("news_display.close", 90, SND_BEGIN ),
323 NewsTypeData("news_display.economy", 30, SND_BEGIN ),
324 NewsTypeData("news_display.production_player", 30, SND_BEGIN ),
325 NewsTypeData("news_display.production_other", 30, SND_BEGIN ),
326 NewsTypeData("news_display.production_nobody", 30, SND_BEGIN ),
327 NewsTypeData("news_display.advice", 150, SND_BEGIN ),
328 NewsTypeData("news_display.new_vehicles", 30, SND_1E_NEW_ENGINE),
329 NewsTypeData("news_display.acceptance", 90, SND_BEGIN ),
330 NewsTypeData("news_display.subsidies", 180, SND_BEGIN ),
331 NewsTypeData("news_display.general", 60, SND_BEGIN ),
332};
333
334static_assert(lengthof(_news_type_data) == NT_END);
335
340 NewsDisplay NewsTypeData::GetDisplay() const
341{
342 const SettingDesc *sd = GetSettingFromName(this->name);
343 assert(sd != nullptr && sd->IsIntSetting());
344 return (NewsDisplay)sd->AsIntSetting()->Read(nullptr);
345}
346
348 struct NewsWindow : Window {
349 uint16_t chat_height;
350 uint16_t status_height;
351 const NewsItem *ni;
352 static int duration;
353
354 NewsWindow(WindowDesc &desc, const NewsItem *ni) : Window(desc), ni(ni)
355 {
356 NewsWindow::duration = 16650;
357 const Window *w = FindWindowByClass(WC_SEND_NETWORK_MSG);
358 this->chat_height = (w != nullptr) ? w->height : 0;
359 this->status_height = FindWindowById(WC_STATUS_BAR, 0)->height;
360
361 this->flags |= WF_DISABLE_VP_SCROLL;
362
363 this->CreateNestedTree();
364
365 /* For company news with a face we have a separate headline in param[0] */
366 if (&desc == &_company_news_desc) this->GetWidget<NWidgetCore>(WID_N_TITLE)->widget_data = std::get<uint64_t>(this->ni->params[0]);
367
368 NWidgetCore *nwid = this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP);
369 if (ni->reftype1 == NR_VEHICLE && nwid != nullptr) {
370 const Vehicle *v = Vehicle::Get(ni->ref1);
371 switch (v->type) {
372 case VEH_TRAIN:
373 nwid->widget_data = STR_TRAIN;
374 break;
375 case VEH_ROAD:
376 nwid->widget_data = RoadVehicle::From(v)->IsBus() ? STR_BUS : STR_LORRY;
377 break;
378 case VEH_SHIP:
379 nwid->widget_data = STR_SHIP;
380 break;
381 case VEH_AIRCRAFT:
382 nwid->widget_data = STR_PLANE;
383 break;
384 default:
385 break; // Do nothing
386 }
387 }
388
389 this->FinishInitNested(0);
390
391 /* Initialize viewport if it exists. */
392 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
393 if (nvp != nullptr) {
394 if (ni->reftype1 == NR_VEHICLE) {
395 nvp->InitializeViewport(this, static_cast<VehicleID>(ni->ref1), ScaleZoomGUI(ZOOM_LVL_NEWS));
396 } else {
397 nvp->InitializeViewport(this, GetReferenceTile(ni->reftype1, ni->ref1), ScaleZoomGUI(ZOOM_LVL_NEWS));
398 }
399 if (this->ni->flags & NF_NO_TRANSPARENT) nvp->disp_flags |= ND_NO_TRANSPARENCY;
400 if ((this->ni->flags & NF_INCOLOUR) == 0) {
401 nvp->disp_flags |= ND_SHADE_GREY;
402 } else if (this->ni->flags & NF_SHADE) {
403 nvp->disp_flags |= ND_SHADE_DIMMED;
404 }
405 }
406
407 PositionNewsMessage(this);
408 }
409
410 void DrawNewsBorder(const Rect &r) const
411 {
412 Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
413 GfxFillRect(ir, PC_WHITE);
414
415 ir = ir.Expand(1);
416 GfxFillRect( r.left, r.top, ir.left, r.bottom, PC_BLACK);
417 GfxFillRect(ir.right, r.top, r.right, r.bottom, PC_BLACK);
418 GfxFillRect( r.left, r.top, r.right, ir.top, PC_BLACK);
419 GfxFillRect( r.left, ir.bottom, r.right, r.bottom, PC_BLACK);
420 }
421
422 Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
423 {
424 Point pt = { 0, _screen.height };
425 return pt;
426 }
427
428 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
429 {
430 StringID str = STR_NULL;
431 switch (widget) {
432 case WID_N_CAPTION: {
433 /* Caption is not a real caption (so that the window cannot be moved)
434 * thus it doesn't get the default sizing of a caption. */
435 Dimension d2 = GetStringBoundingBox(STR_NEWS_MESSAGE_CAPTION);
436 d2.height += WidgetDimensions::scaled.captiontext.Vertical();
437 size = maxdim(size, d2);
438 return;
439 }
440
441 case WID_N_MGR_FACE:
442 size = maxdim(size, GetScaledSpriteSize(SPR_GRADIENT));
443 break;
444
445 case WID_N_MESSAGE:
446 CopyInDParam(this->ni->params);
447 str = this->ni->string_id;
448 break;
449
450 case WID_N_COMPANY_MSG:
451 str = this->GetCompanyMessageString();
452 break;
453
454 case WID_N_VEH_NAME:
455 case WID_N_VEH_TITLE:
456 str = this->GetNewVehicleMessageString(widget);
457 break;
458
459 case WID_N_VEH_INFO: {
460 assert(this->ni->reftype1 == NR_ENGINE);
461 EngineID engine = this->ni->ref1;
462 str = GetEngineInfoString(engine);
463 break;
464 }
465
466 case WID_N_SHOW_GROUP:
467 if (this->ni->reftype1 == NR_VEHICLE) {
468 Dimension d2 = GetStringBoundingBox(this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP)->widget_data);
469 d2.height += WidgetDimensions::scaled.captiontext.Vertical();
470 d2.width += WidgetDimensions::scaled.captiontext.Horizontal();
471 size = d2;
472 } else {
473 /* Hide 'Show group window' button if this news is not about a vehicle. */
474 size.width = 0;
475 size.height = 0;
476 resize.width = 0;
477 resize.height = 0;
478 fill.width = 0;
479 fill.height = 0;
480 }
481 return;
482
483 default:
484 return; // Do nothing
485 }
486
487 /* Update minimal size with length of the multi-line string. */
488 Dimension d = size;
489 d.width = (d.width >= padding.width) ? d.width - padding.width : 0;
490 d.height = (d.height >= padding.height) ? d.height - padding.height : 0;
491 d = GetStringMultiLineBoundingBox(str, d);
492 d.width += padding.width;
493 d.height += padding.height;
494 size = maxdim(size, d);
495 }
496
497 void SetStringParameters(WidgetID widget) const override
498 {
499 if (widget == WID_N_DATE) SetDParam(0, this->ni->date);
500 }
501
502 void DrawWidget(const Rect &r, WidgetID widget) const override
503 {
504 switch (widget) {
505 case WID_N_CAPTION:
506 DrawCaption(r, COLOUR_LIGHT_BLUE, this->owner, TC_FROMSTRING, STR_NEWS_MESSAGE_CAPTION, SA_CENTER, FS_NORMAL);
507 break;
508
509 case WID_N_PANEL:
510 this->DrawNewsBorder(r);
511 break;
512
513 case WID_N_MESSAGE:
514 CopyInDParam(this->ni->params);
515 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->ni->string_id, TC_FROMSTRING, SA_CENTER);
516 break;
517
518 case WID_N_MGR_FACE: {
519 const CompanyNewsInformation *cni = static_cast<const CompanyNewsInformation*>(this->ni->data.get());
520 DrawCompanyManagerFace(cni->face, cni->colour, r);
521 GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
522 break;
523 }
524 case WID_N_MGR_NAME: {
525 const CompanyNewsInformation *cni = static_cast<const CompanyNewsInformation*>(this->ni->data.get());
526 SetDParamStr(0, cni->president_name);
527 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, STR_JUST_RAW_STRING, TC_FROMSTRING, SA_CENTER);
528 break;
529 }
530 case WID_N_COMPANY_MSG:
531 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->GetCompanyMessageString(), TC_FROMSTRING, SA_CENTER);
532 break;
533
534 case WID_N_VEH_BKGND:
535 GfxFillRect(r.left, r.top, r.right, r.bottom, PC_GREY);
536 break;
537
538 case WID_N_VEH_NAME:
539 case WID_N_VEH_TITLE:
540 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->GetNewVehicleMessageString(widget), TC_FROMSTRING, SA_CENTER);
541 break;
542
543 case WID_N_VEH_SPR: {
544 assert(this->ni->reftype1 == NR_ENGINE);
545 EngineID engine = this->ni->ref1;
546 DrawVehicleEngine(r.left, r.right, CenterBounds(r.left, r.right, 0), CenterBounds(r.top, r.bottom, 0), engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
547 GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
548 break;
549 }
550 case WID_N_VEH_INFO: {
551 assert(this->ni->reftype1 == NR_ENGINE);
552 EngineID engine = this->ni->ref1;
553 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
554 break;
555 }
556 }
557 }
558
559 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
560 {
561 switch (widget) {
562 case WID_N_CLOSEBOX:
563 NewsWindow::duration = 0;
564 this->Close();
565 _forced_news = std::end(_news);
566 break;
567
568 case WID_N_CAPTION:
569 if (this->ni->reftype1 == NR_VEHICLE) {
570 const Vehicle *v = Vehicle::Get(this->ni->ref1);
571 ShowVehicleViewWindow(v);
572 }
573 break;
574
575 case WID_N_VIEWPORT:
576 break; // Ignore clicks
577
578 case WID_N_SHOW_GROUP:
579 if (this->ni->reftype1 == NR_VEHICLE) {
580 const Vehicle *v = Vehicle::Get(this->ni->ref1);
581 ShowCompanyGroupForVehicle(v);
582 }
583 break;
584 default:
585 if (this->ni->reftype1 == NR_VEHICLE) {
586 const Vehicle *v = Vehicle::Get(this->ni->ref1);
587 ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos);
588 } else {
589 TileIndex tile1 = GetReferenceTile(this->ni->reftype1, this->ni->ref1);
590 TileIndex tile2 = GetReferenceTile(this->ni->reftype2, this->ni->ref2);
591 if (_ctrl_pressed) {
592 if (tile1 != INVALID_TILE) ShowExtraViewportWindow(tile1);
593 if (tile2 != INVALID_TILE) ShowExtraViewportWindow(tile2);
594 } else {
595 if ((tile1 == INVALID_TILE || !ScrollMainWindowToTile(tile1)) && tile2 != INVALID_TILE) {
596 ScrollMainWindowToTile(tile2);
597 }
598 }
599 }
600 break;
601 }
602 }
603
604 void OnResize() override
605 {
606 if (this->viewport != nullptr) {
607 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
608 nvp->UpdateViewportCoordinates(this);
609
610 if (ni->reftype1 != NR_VEHICLE) {
611 ScrollWindowToTile(GetReferenceTile(ni->reftype1, ni->ref1), this, true); // Re-center viewport.
612 }
613 }
614
615 NWidgetResizeBase *wid = this->GetWidget<NWidgetResizeBase>(WID_N_MGR_NAME);
616 if (wid != nullptr) {
617 SetDParamStr(0, static_cast<const CompanyNewsInformation *>(this->ni->data.get())->president_name);
618 int y = GetStringHeight(STR_JUST_RAW_STRING, wid->current_x);
619 if (wid->UpdateVerticalSize(y)) this->ReInit(0, 0);
620 }
621 }
622
628 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
629 {
630 if (!gui_scope) return;
631 /* The chatbar has notified us that is was either created or closed */
632 int newtop = this->top + this->chat_height - data;
633 this->chat_height = data;
634 this->SetWindowTop(newtop);
635 }
636
637 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
638 {
639 /* Decrement the news timer. We don't need to action an elapsed event here,
640 * so no need to use TimerElapsed(). */
641 if (NewsWindow::duration > 0) NewsWindow::duration -= delta_ms;
642 }
643
649 IntervalTimer<TimerWindow> scroll_interval = {std::chrono::milliseconds(210) / GetCharacterHeight(FS_NORMAL), [this](uint count) {
650 int newtop = std::max(this->top - 2 * static_cast<int>(count), _screen.height - this->height - this->status_height - this->chat_height);
651 this->SetWindowTop(newtop);
652 }};
653
654private:
659 void SetWindowTop(int newtop)
660 {
661 if (this->top == newtop) return;
662
663 int mintop = std::min(newtop, this->top);
664 int maxtop = std::max(newtop, this->top);
665 if (this->viewport != nullptr) this->viewport->top += newtop - this->top;
666 this->top = newtop;
667
668 AddDirtyBlock(this->left, mintop, this->left + this->width, maxtop + this->height);
669 }
670
671 StringID GetCompanyMessageString() const
672 {
673 /* Company news with a face have a separate headline, so the normal message is shifted by two params */
674 CopyInDParam(std::span(this->ni->params.data() + 2, this->ni->params.size() - 2));
675 return std::get<uint64_t>(this->ni->params[1]);
676 }
677
678 StringID GetNewVehicleMessageString(WidgetID widget) const
679 {
680 assert(this->ni->reftype1 == NR_ENGINE);
681 EngineID engine = this->ni->ref1;
682
683 switch (widget) {
684 case WID_N_VEH_TITLE:
685 SetDParam(0, GetEngineCategoryName(engine));
686 return STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE;
687
688 case WID_N_VEH_NAME:
689 SetDParam(0, PackEngineNameDParam(engine, EngineNameContext::PreviewNews));
690 return STR_NEWS_NEW_VEHICLE_TYPE;
691
692 default:
693 NOT_REACHED();
694 }
695 }
696};
697
698/* static */ int NewsWindow::duration = 0; // Instance creation.
699
701 static void ShowNewspaper(const NewsItem *ni)
702{
703 SoundFx sound = _news_type_data[ni->type].sound;
704 if (sound != 0 && _settings_client.sound.news_full) SndPlayFx(sound);
705
706 new NewsWindow(GetNewsWindowLayout(ni->flags), ni);
707}
708
710 static void ShowTicker(NewsIterator ni)
711{
712 if (_settings_client.sound.news_ticker) SndPlayFx(SND_16_NEWS_TICKER);
713
714 _statusbar_news = ni;
715 InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_TICKER);
716}
717
719 void InitNewsItemStructs()
720{
721 _news.clear();
722 _forced_news = std::end(_news);
723 _current_news = std::end(_news);
724 _statusbar_news = std::end(_news);
725 NewsWindow::duration = 0;
726}
727
732 static bool ReadyForNextTickerItem()
733{
734 const NewsItem *ni = GetStatusbarNews();
735 if (ni == nullptr) return true;
736
737 /* Ticker message
738 * Check if the status bar message is still being displayed? */
739 return !IsNewsTickerShown();
740}
741
746 static bool ReadyForNextNewsItem()
747{
748 if (_forced_news == std::end(_news) && _current_news == std::end(_news)) return true;
749
750 /* neither newsticker nor newspaper are running */
751 return (NewsWindow::duration <= 0 || FindWindowById(WC_NEWS_WINDOW, 0) == nullptr);
752}
753
755 static void MoveToNextTickerItem()
756{
757 /* There is no status bar, so no reason to show news;
758 * especially important with the end game screen when
759 * there is no status bar but possible news. */
760 if (FindWindowById(WC_STATUS_BAR, 0) == nullptr) return;
761
762 /* No news to move to. */
763 if (std::empty(_news)) return;
764
765 /* if we're not at the latest item, then move on */
766 while (_statusbar_news != std::begin(_news)) {
767 --_statusbar_news;
768 const NewsType type = _statusbar_news->type;
769
770 /* check the date, don't show too old items */
771 if (TimerGameEconomy::date - _news_type_data[type].age > _statusbar_news->economy_date) continue;
772
773 switch (_news_type_data[type].GetDisplay()) {
774 default: NOT_REACHED();
775 case ND_OFF: // Off - show nothing only a small reminder in the status bar
776 InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_REMINDER);
777 return;
778
779 case ND_SUMMARY: // Summary - show ticker
780 ShowTicker(_statusbar_news);
781 return;
782
783 case ND_FULL: // Full - show newspaper, skipped here
784 break;;
785 }
786 }
787}
788
790 static void MoveToNextNewsItem()
791{
792 /* There is no status bar, so no reason to show news;
793 * especially important with the end game screen when
794 * there is no status bar but possible news. */
795 if (FindWindowById(WC_STATUS_BAR, 0) == nullptr) return;
796
797 CloseWindowById(WC_NEWS_WINDOW, 0); // close the newspapers window if shown
798 _forced_news = std::end(_news);
799
800 /* No news to move to. */
801 if (std::empty(_news)) return;
802
803 /* if we're not at the latest item, then move on */
804 while (_current_news != std::begin(_news)) {
805 --_current_news;
806 const NewsType type = _current_news->type;
807
808 /* check the date, don't show too old items */
809 if (TimerGameEconomy::date - _news_type_data[type].age > _current_news->economy_date) continue;
810
811 switch (_news_type_data[type].GetDisplay()) {
812 default: NOT_REACHED();
813 case ND_OFF: // Off - show nothing only a small reminder in the status bar, skipped here
814 break;
815
816 case ND_SUMMARY: // Summary - show ticker, skipped here
817 break;;
818
819 case ND_FULL: // Full - show newspaper
820 ShowNewspaper(&*_current_news);
821 return;
822 }
823 }
824}
825
827 static std::list<NewsItem>::iterator DeleteNewsItem(std::list<NewsItem>::iterator ni)
828{
829 bool updateCurrentNews = (_forced_news == ni || _current_news == ni);
830 bool updateStatusbarNews = (_statusbar_news == ni);
831
832 if (updateCurrentNews) {
833 /* When we're the current news, go to the next older item first;
834 * we just possibly made that the last news item. */
835 if (_current_news == ni) ++_current_news;
836 if (_forced_news == ni) _forced_news = std::end(_news);
837 }
838
839 if (updateStatusbarNews) {
840 /* When we're the current news, go to the next older item first;
841 * we just possibly made that the last news item. */
842 ++_statusbar_news;
843 }
844
845 /* Delete the news from the news queue. */
846 ni = _news.erase(ni);
847
848 if (updateCurrentNews) {
849 /* About to remove the currently forced item (shown as newspapers) ||
850 * about to remove the currently displayed item (newspapers) */
851 MoveToNextNewsItem();
852 }
853
854 if (updateStatusbarNews) {
855 /* About to remove the currently displayed item (ticker, or just a reminder) */
856 InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); // invalidate the statusbar
857 MoveToNextTickerItem();
858 }
859
860 return ni;
861}
862
876NewsItem::NewsItem(StringID string_id, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, std::unique_ptr<NewsAllocatedData> &&data) :
877 string_id(string_id), date(TimerGameCalendar::date), economy_date(TimerGameEconomy::date), type(type), flags(flags), reftype1(reftype1), reftype2(reftype2), ref1(ref1), ref2(ref2), data(std::move(data))
878{
879 /* show this news message in colour? */
880 if (TimerGameCalendar::year >= _settings_client.gui.coloured_news_year) this->flags |= NF_INCOLOUR;
881 CopyOutDParam(this->params, 10);
882}
883
897 void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, std::unique_ptr<NewsAllocatedData> &&data)
898{
899 if (_game_mode == GM_MENU) return;
900
901 /* Create new news item node */
902 _news.emplace_front(string, type, flags, reftype1, ref1, reftype2, ref2, std::move(data));
903
904 /* Keep the number of stored news items to a managable number */
905 if (std::size(_news) > MAX_NEWS_AMOUNT) {
906 DeleteNewsItem(std::prev(std::end(_news)));
907 }
908
909 InvalidateWindowData(WC_MESSAGE_HISTORY, 0);
910}
911
922 CommandCost CmdCustomNewsItem(DoCommandFlag flags, NewsType type, NewsReferenceType reftype1, CompanyID company, uint32_t reference, const std::string &text)
923{
924 if (_current_company != OWNER_DEITY) return CMD_ERROR;
925
926 if (company != INVALID_OWNER && !Company::IsValidID(company)) return CMD_ERROR;
927 if (type >= NT_END) return CMD_ERROR;
928 if (text.empty()) return CMD_ERROR;
929
930 switch (reftype1) {
931 case NR_NONE: break;
932 case NR_TILE:
933 if (!IsValidTile(reference)) return CMD_ERROR;
934 break;
935
936 case NR_VEHICLE:
937 if (!Vehicle::IsValidID(reference)) return CMD_ERROR;
938 break;
939
940 case NR_STATION:
941 if (!Station::IsValidID(reference)) return CMD_ERROR;
942 break;
943
944 case NR_INDUSTRY:
945 if (!Industry::IsValidID(reference)) return CMD_ERROR;
946 break;
947
948 case NR_TOWN:
949 if (!Town::IsValidID(reference)) return CMD_ERROR;
950 break;
951
952 case NR_ENGINE:
953 if (!Engine::IsValidID(reference)) return CMD_ERROR;
954 break;
955
956 default: return CMD_ERROR;
957 }
958
959 if (company != INVALID_OWNER && company != _local_company) return CommandCost();
960
961 if (flags & DC_EXEC) {
962 SetDParamStr(0, text);
963 AddNewsItem(STR_NEWS_CUSTOM_ITEM, type, NF_NORMAL, reftype1, reference, NR_NONE, UINT32_MAX);
964 }
965
966 return CommandCost();
967}
968
974template <size_t Tmin = 0, class Tpredicate>
975 void DeleteNews(Tpredicate predicate)
976{
977 bool dirty = false;
978 for (auto it = std::rbegin(_news); it != std::rend(_news); /* nothing */) {
979 if constexpr (Tmin > 0) {
980 if (std::size(_news) <= Tmin) break;
981 }
982 if (predicate(*it)) {
983 it = std::make_reverse_iterator(DeleteNewsItem(std::prev(it.base())));
984 dirty = true;
985 } else {
986 ++it;
987 }
988 }
989 if (dirty) InvalidateWindowData(WC_MESSAGE_HISTORY, 0);
990}
991
998 void DeleteVehicleNews(VehicleID vid, StringID news)
999{
1000 DeleteNews([&](const auto &ni) {
1001 return ((ni.reftype1 == NR_VEHICLE && ni.ref1 == vid) || (ni.reftype2 == NR_VEHICLE && ni.ref2 == vid)) && (news == INVALID_STRING_ID || ni.string_id == news);
1002 });
1003}
1004
1010 void DeleteStationNews(StationID sid)
1011{
1012 DeleteNews([&](const auto &ni) {
1013 return (ni.reftype1 == NR_STATION && ni.ref1 == sid) || (ni.reftype2 == NR_STATION && ni.ref2 == sid);
1014 });
1015}
1016
1021 void DeleteIndustryNews(IndustryID iid)
1022{
1023 DeleteNews([&](const auto &ni) {
1024 return (ni.reftype1 == NR_INDUSTRY && ni.ref1 == iid) || (ni.reftype2 == NR_INDUSTRY && ni.ref2 == iid);
1025 });
1026}
1027
1031 void DeleteInvalidEngineNews()
1032{
1033 DeleteNews([](const auto &ni) {
1034 return (ni.reftype1 == NR_ENGINE && (!Engine::IsValidID(ni.ref1) || !Engine::Get(ni.ref1)->IsEnabled())) ||
1035 (ni.reftype2 == NR_ENGINE && (!Engine::IsValidID(ni.ref2) || !Engine::Get(ni.ref2)->IsEnabled()));
1036 });
1037}
1038
1039static void RemoveOldNewsItems()
1040{
1041 DeleteNews<MIN_NEWS_AMOUNT>([](const auto &ni) {
1042 return TimerGameEconomy::date - _news_type_data[ni.type].age * _settings_client.gui.news_message_timeout > ni.economy_date;
1043 });
1044}
1045
1052 void ChangeVehicleNews(VehicleID from_index, VehicleID to_index)
1053{
1054 for (auto &ni : _news) {
1055 if (ni.reftype1 == NR_VEHICLE && ni.ref1 == from_index) ni.ref1 = to_index;
1056 if (ni.reftype2 == NR_VEHICLE && ni.ref2 == from_index) ni.ref2 = to_index;
1057 if (ni.flags & NF_VEHICLE_PARAM0 && std::get<uint64_t>(ni.params[0]) == from_index) ni.params[0] = to_index;
1058 }
1059}
1060
1061void NewsLoop()
1062{
1063 /* no news item yet */
1064 if (std::empty(_news)) return;
1065
1066 static TimerGameEconomy::Month _last_clean_month = 0;
1067
1068 if (_last_clean_month != TimerGameEconomy::month) {
1069 RemoveOldNewsItems();
1070 _last_clean_month = TimerGameEconomy::month;
1071 }
1072
1073 if (ReadyForNextTickerItem()) MoveToNextTickerItem();
1074 if (ReadyForNextNewsItem()) MoveToNextNewsItem();
1075}
1076
1078 static void ShowNewsMessage(NewsIterator ni)
1079{
1080 assert(!std::empty(_news));
1081
1082 /* Delete the news window */
1083 CloseWindowById(WC_NEWS_WINDOW, 0);
1084
1085 /* setup forced news item */
1086 _forced_news = ni;
1087
1088 if (_forced_news != std::end(_news)) {
1089 CloseWindowById(WC_NEWS_WINDOW, 0);
1090 ShowNewspaper(&*ni);
1091 }
1092}
1093
1098 bool HideActiveNewsMessage()
1099{
1100 NewsWindow *w = dynamic_cast<NewsWindow *>(FindWindowById(WC_NEWS_WINDOW, 0));
1101 if (w == nullptr) return false;
1102 w->Close();
1103 return true;
1104}
1105
1107 void ShowLastNewsMessage()
1108{
1109 if (std::empty(_news)) return;
1110
1111 NewsIterator ni;
1112 if (_forced_news == std::end(_news)) {
1113 /* Not forced any news yet, show the current one, unless a news window is
1114 * open (which can only be the current one), then show the previous item */
1115 if (_current_news == std::end(_news)) {
1116 /* No news were shown yet resp. the last shown one was already deleted.
1117 * Treat this as if _forced_news reached the oldest news; so, wrap around and start anew with the latest. */
1118 ni = std::begin(_news);
1119 } else {
1120 const Window *w = FindWindowById(WC_NEWS_WINDOW, 0);
1121 ni = (w == nullptr || (std::next(_current_news) == std::end(_news))) ? _current_news : std::next(_current_news);
1122 }
1123 } else if (std::next(_forced_news) == std::end(_news)) {
1124 /* We have reached the oldest news, start anew with the latest */
1125 ni = std::begin(_news);
1126 } else {
1127 /* 'Scrolling' through news history show each one in turn */
1128 ni = std::next(_forced_news);
1129 }
1130 bool wrap = false;
1131 for (;;) {
1132 if (_news_type_data[ni->type].GetDisplay() != ND_OFF) {
1133 ShowNewsMessage(ni);
1134 break;
1135 }
1136
1137 ++ni;
1138 if (ni == std::end(_news)) {
1139 if (wrap) break;
1140 /* We have reached the oldest news, start anew with the latest */
1141 ni = std::begin(_news);
1142 wrap = true;
1143 }
1144 }
1145}
1146
1147
1157 static void DrawNewsString(uint left, uint right, int y, TextColour colour, const NewsItem *ni)
1158{
1159 CopyInDParam(ni->params);
1160
1161 /* Get the string, replaces newlines with spaces and remove control codes from the string. */
1162 std::string message = StrMakeValid(GetString(ni->string_id), SVS_REPLACE_TAB_CR_NL_WITH_SPACE);
1163
1164 /* Truncate and show string; postfixed by '...' if necessary */
1165 DrawString(left, right, y, message, colour);
1166}
1167
1168 struct MessageHistoryWindow : Window {
1169 int line_height;
1170 int date_width;
1171
1172 Scrollbar *vscroll;
1173
1174 MessageHistoryWindow(WindowDesc &desc) : Window(desc)
1175 {
1176 this->CreateNestedTree();
1177 this->vscroll = this->GetScrollbar(WID_MH_SCROLLBAR);
1178 this->FinishInitNested(); // Initializes 'this->line_height' and 'this->date_width'.
1179 this->OnInvalidateData(0);
1180 }
1181
1182 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
1183 {
1184 if (widget == WID_MH_BACKGROUND) {
1185 this->line_height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
1186 resize.height = this->line_height;
1187
1188 /* Months are off-by-one, so it's actually 8. Not using
1189 * month 12 because the 1 is usually less wide. */
1190 SetDParam(0, TimerGameCalendar::ConvertYMDToDate(CalendarTime::ORIGINAL_MAX_YEAR, 7, 30));
1191 this->date_width = GetStringBoundingBox(STR_JUST_DATE_TINY).width + WidgetDimensions::scaled.hsep_wide;
1192
1193 size.height = 4 * resize.height + WidgetDimensions::scaled.framerect.Vertical(); // At least 4 lines are visible.
1194 size.width = std::max(200u, size.width); // At least 200 pixels wide.
1195 }
1196 }
1197
1198 void DrawWidget(const Rect &r, WidgetID widget) const override
1199 {
1200 if (widget != WID_MH_BACKGROUND || std::empty(_news)) return;
1201
1202 /* Fill the widget with news items. */
1203 bool rtl = _current_text_dir == TD_RTL;
1204 Rect news = r.Shrink(WidgetDimensions::scaled.framerect).Indent(this->date_width + WidgetDimensions::scaled.hsep_wide, rtl);
1205 Rect date = r.Shrink(WidgetDimensions::scaled.framerect).WithWidth(this->date_width, rtl);
1206 int y = news.top;
1207
1208 auto [first, last] = this->vscroll->GetVisibleRangeIterators(_news);
1209 for (auto ni = first; ni != last; ++ni) {
1210 SetDParam(0, ni->date);
1211 DrawString(date.left, date.right, y, STR_JUST_DATE_TINY, TC_WHITE);
1212
1213 DrawNewsString(news.left, news.right, y, TC_WHITE, &*ni);
1214 y += this->line_height;
1215 }
1216 }
1217
1223 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1224 {
1225 if (!gui_scope) return;
1226 this->vscroll->SetCount(std::size(_news));
1227 }
1228
1229 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1230 {
1231 if (widget == WID_MH_BACKGROUND) {
1232 /* Scheduled window invalidations currently occur after the input loop, which means the scrollbar count
1233 * could be invalid, so ensure it's correct now. Potentially this means that item clicked on might be
1234 * different as well. */
1235 this->vscroll->SetCount(std::size(_news));
1236 auto ni = this->vscroll->GetScrolledItemFromWidget(_news, pt.y, this, widget, WidgetDimensions::scaled.framerect.top);
1237 if (ni == std::end(_news)) return;
1238
1239 ShowNewsMessage(ni);
1240 }
1241 }
1242
1243 void OnResize() override
1244 {
1245 this->vscroll->SetCapacityFromWidget(this, WID_MH_BACKGROUND, WidgetDimensions::scaled.framerect.Vertical());
1246 }
1247};
1248
1249static constexpr NWidgetPart _nested_message_history[] = {
1250 NWidget(NWID_HORIZONTAL),
1251 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1252 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_MESSAGE_HISTORY, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1253 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1254 NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
1255 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1256 EndContainer(),
1257
1258 NWidget(NWID_HORIZONTAL),
1259 NWidget(WWT_PANEL, COLOUR_BROWN, WID_MH_BACKGROUND), SetMinimalSize(200, 125), SetDataTip(0x0, STR_MESSAGE_HISTORY_TOOLTIP), SetResize(1, 12), SetScrollbar(WID_MH_SCROLLBAR),
1260 EndContainer(),
1261 NWidget(NWID_VERTICAL),
1262 NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_MH_SCROLLBAR),
1263 NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
1264 EndContainer(),
1265 EndContainer(),
1266};
1267
1268static WindowDesc _message_history_desc(
1269 WDP_AUTO, "list_news", 400, 140,
1270 WC_MESSAGE_HISTORY, WC_NONE,
1271 0,
1272 _nested_message_history
1273);
1274
1276 void ShowMessageHistory()
1277{
1278 CloseWindowById(WC_MESSAGE_HISTORY, 0);
1279 new MessageHistoryWindow(_message_history_desc);
1280}
GB
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition bitmath_func.hpp:32
CommandCost
Common return value for all commands.
Definition command_type.h:23
IntervalTimer
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition timer.h:76
NWidgetCore
Base class for a 'real' widget.
Definition widget_type.h:371
NWidgetResizeBase
Base class for a resizable nested widget.
Definition widget_type.h:304
NWidgetViewport
Nested widget to display a viewport in a window.
Definition widget_type.h:680
NWidgetViewport::UpdateViewportCoordinates
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition widget.cpp:2354
Scrollbar
Scrollbar data structure.
Definition widget_type.h:694
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition widget_type.h:780
Scrollbar::GetScrolledItemFromWidget
auto GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Return an iterator pointing to the element of a scrolled widget that a user clicked in.
Definition widget_type.h:879
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition widget.cpp:2451
Scrollbar::GetVisibleRangeIterators
auto GetVisibleRangeIterators(Tcontainer &container) const
Get a pair of iterators for the range of visible elements in a container.
Definition widget_type.h:860
TimerGameCalendar
Timer that is increased every 27ms, and counts towards ticks / days / months / years.
Definition timer_game_calendar.h:30
TimerGameCalendar::ConvertYMDToDate
static Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Definition timer_game_calendar.cpp:55
TimerGameCalendar::year
static Year year
Current year, starting at 0.
Definition timer_game_calendar.h:31
TimerGameConst< struct Calendar >::ORIGINAL_MAX_YEAR
static constexpr TimerGame< struct Calendar >::Year ORIGINAL_MAX_YEAR
The maximum year of the original TTD.
Definition timer_game_common.h:167
TimerGameEconomy
Timer that is increased every 27ms, and counts towards economy time units, expressed in days / months...
Definition timer_game_economy.h:33
TimerGameEconomy::date
static Date date
Current date in days (day counter).
Definition timer_game_economy.h:38
TimerGameEconomy::month
static Month month
Current month (0..11).
Definition timer_game_economy.h:37
TimerGame< struct Economy >::Month
uint8_t Month
Type for the month, note: 0 based, i.e.
Definition timer_game_common.h:44
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition window_gui.h:42
WidgetDimensions::captiontext
RectPadding captiontext
Padding for text within caption widget.
Definition window_gui.h:51
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:28
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition window_gui.h:60
WidgetDimensions::hsep_wide
int hsep_wide
Wide horizontal spacing.
Definition window_gui.h:64
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:96
command_func.h
Functions related to commands.
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition command_func.h:28
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition command_type.h:374
DC_EXEC
@ DC_EXEC
execute the given command
Definition command_type.h:376
company_base.h
Definition of stuff that is very close to a company, like the company struct itself.
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition company_cmd.cpp:52
_current_company
CompanyID _current_company
Company currently doing an action.
Definition company_cmd.cpp:53
company_func.h
Functions related to companies.
DrawCompanyManagerFace
void DrawCompanyManagerFace(CompanyManagerFace cmf, Colours colour, const Rect &r)
Draws the face of a company manager's face.
Definition company_gui.cpp:1126
company_manager_face.h
Functionality related to the company manager's face.
Owner
Owner
Enum for all companies/owners.
Definition company_type.h:18
INVALID_OWNER
@ INVALID_OWNER
An invalid owner.
Definition company_type.h:29
OWNER_DEITY
@ OWNER_DEITY
The object is owned by a superuser / goal script.
Definition company_type.h:27
engine_base.h
Base class for engines.
GetEngineCategoryName
StringID GetEngineCategoryName(EngineID engine)
Return the category of an engine.
Definition engine_gui.cpp:40
GetEngineInfoString
StringID GetEngineInfoString(EngineID engine)
Get a multi-line string with some technical data, describing the engine.
Definition engine_gui.cpp:273
DrawVehicleEngine
void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
Draw an engine.
Definition engine_gui.cpp:303
engine_gui.h
Engine GUI functions, used by build_vehicle_gui and autoreplace_gui
EngineID
uint16_t EngineID
Unique identification number of an engine.
Definition engine_type.h:21
PackEngineNameDParam
uint64_t PackEngineNameDParam(EngineID engine_id, EngineNameContext context, uint32_t extra_data=0)
Combine an engine ID and a name context to an engine name dparam.
Definition engine_type.h:203
PreviewNews
@ PreviewNews
Name is shown in exclusive preview or newspaper.
Definition engine_type.h:198
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:77
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition geometry_func.cpp:22
geometry_func.hpp
Geometry functions.
GetStringHeight
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition gfx.cpp:704
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:851
DrawString
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:657
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:38
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition gfx.cpp:114
GetStringMultiLineBoundingBox
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
Definition gfx.cpp:740
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition gfx.cpp:774
GetScaledSpriteSize
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
Definition widget.cpp:54
CenterBounds
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition gfx_func.h:166
SA_TOP
@ SA_TOP
Top align the text.
Definition gfx_type.h:348
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition gfx_type.h:345
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition gfx_type.h:353
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition gfx_type.h:210
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:209
FS_LARGE
@ FS_LARGE
Index of the large font in the font tables.
Definition gfx_type.h:211
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:260
FILLRECT_RECOLOUR
@ FILLRECT_RECOLOUR
Apply a recolour sprite to the screen content.
Definition gfx_type.h:300
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1181
SetPIP
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
Definition widget_type.h:1271
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition widget_type.h:1295
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition widget_type.h:1228
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition widget_type.h:1202
SetTextStyle
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
Definition widget_type.h:1160
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition widget_type.h:1137
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1320
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1191
SetMinimalTextLines
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition widget_type.h:1149
SetAlignment
constexpr NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
Definition widget_type.h:1170
SetAspect
constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags=AspectFlags::ResizeX)
Widget part function for setting the aspect ratio.
Definition widget_type.h:1306
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1126
SetPIPRatio
constexpr NWidgetPart SetPIPRatio(uint8_t ratio_pre, uint8_t ratio_inter, uint8_t ratio_post)
Widget part function for setting a pre/inter/post ratio.
Definition widget_type.h:1283
AddDirtyBlock
void AddDirtyBlock(int left, int top, int right, int bottom)
Extend the internal _invalid_rect rectangle to contain the rectangle defined by the given parameters.
Definition gfx.cpp:1486
ShowCompanyGroupForVehicle
void ShowCompanyGroupForVehicle(const Vehicle *v)
Show the group window for the given vehicle.
Definition group_gui.cpp:1194
group_gui.h
Functions/definitions that have something to do with groups.
gui.h
GUI functions that shouldn't be here.
ShowExtraViewportWindow
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Definition viewport_gui.cpp:156
industry.h
Base of all industries.
TileDiffXY
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition map_func.h:389
news_cmd.h
Command definitions related to news messages.
news_func.h
Functions related to news.
_news
static NewsContainer _news
List of news, with newest items at the start.
Definition news_gui.cpp:50
DrawNewsString
static void DrawNewsString(uint left, uint right, int y, TextColour colour, const NewsItem *ni)
Draw an unformatted news message truncated to a maximum length.
Definition news_gui.cpp:1157
MoveToNextNewsItem
static void MoveToNextNewsItem()
Move to the next news item.
Definition news_gui.cpp:790
ShowTicker
static void ShowTicker(NewsIterator ni)
Show news item in the ticker.
Definition news_gui.cpp:710
DeleteNews
void DeleteNews(Tpredicate predicate)
Delete news items by predicate, and invalidate the message history if necessary.
Definition news_gui.cpp:975
DeleteVehicleNews
void DeleteVehicleNews(VehicleID vid, StringID news)
Delete a news item type about a vehicle.
Definition news_gui.cpp:998
ShowNewspaper
static void ShowNewspaper(const NewsItem *ni)
Open up an own newspaper window for the news item.
Definition news_gui.cpp:701
MIN_NEWS_AMOUNT
static const uint MIN_NEWS_AMOUNT
preferred minimum amount of news messages.
Definition news_gui.cpp:47
_news_type_data
static NewsTypeData _news_type_data[]
Per-NewsType data.
Definition news_gui.cpp:314
_forced_news
static NewsIterator _forced_news
Forced news item.
Definition news_gui.cpp:58
DeleteIndustryNews
void DeleteIndustryNews(IndustryID iid)
Remove news regarding given industry.
Definition news_gui.cpp:1021
DeleteStationNews
void DeleteStationNews(StationID sid)
Remove news regarding given station so there are no 'unknown station now accepts Mail' or 'First trai...
Definition news_gui.cpp:1010
ShowLastNewsMessage
void ShowLastNewsMessage()
Show previous news item.
Definition news_gui.cpp:1107
MAX_NEWS_AMOUNT
static const uint MAX_NEWS_AMOUNT
Do not exceed this number of news messages.
Definition news_gui.cpp:48
DeleteInvalidEngineNews
void DeleteInvalidEngineNews()
Remove engine announcements for invalid engines.
Definition news_gui.cpp:1031
ReadyForNextNewsItem
static bool ReadyForNextNewsItem()
Are we ready to show another news item? Only if no newspaper is displayed.
Definition news_gui.cpp:746
GetReferenceTile
static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32_t ref)
Get the position a news-reference is referencing.
Definition news_gui.cpp:90
DeleteNewsItem
static std::list< NewsItem >::iterator DeleteNewsItem(std::list< NewsItem >::iterator ni)
Delete a news item from the queue.
Definition news_gui.cpp:827
HideActiveNewsMessage
bool HideActiveNewsMessage()
Close active news message window.
Definition news_gui.cpp:1098
ShowMessageHistory
void ShowMessageHistory()
Display window with news messages history.
Definition news_gui.cpp:1276
ChangeVehicleNews
void ChangeVehicleNews(VehicleID from_index, VehicleID to_index)
Report a change in vehicle IDs (due to autoreplace) to affected vehicle news.
Definition news_gui.cpp:1052
CmdCustomNewsItem
CommandCost CmdCustomNewsItem(DoCommandFlag flags, NewsType type, NewsReferenceType reftype1, CompanyID company, uint32_t reference, const std::string &text)
Create a new custom news item.
Definition news_gui.cpp:922
InitNewsItemStructs
void InitNewsItemStructs()
Initialize the news-items data structures.
Definition news_gui.cpp:719
MoveToNextTickerItem
static void MoveToNextTickerItem()
Move to the next ticker item.
Definition news_gui.cpp:755
GetNews
const NewsContainer & GetNews()
Get read-only reference to all news items.
Definition news_gui.cpp:79
ShowNewsMessage
static void ShowNewsMessage(NewsIterator ni)
Do a forced show of a specific message.
Definition news_gui.cpp:1078
_current_news
static NewsIterator _current_news
Current news item (last item shown regularly).
Definition news_gui.cpp:61
GetStatusbarNews
const NewsItem * GetStatusbarNews()
Get pointer to the current status bar news item.
Definition news_gui.cpp:70
AddNewsItem
void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, std::unique_ptr< NewsAllocatedData > &&data)
Add a new newsitem to be shown.
Definition news_gui.cpp:897
ReadyForNextTickerItem
static bool ReadyForNextTickerItem()
Are we ready to show another ticker item? Only if nothing is in the newsticker is displayed.
Definition news_gui.cpp:732
_news_window_layout
static WindowDesc * _news_window_layout[]
Window layouts for news items.
Definition news_gui.cpp:296
_statusbar_news
static NewsIterator _statusbar_news
Current status bar news item.
Definition news_gui.cpp:64
NewsType
NewsType
Type of news.
Definition news_type.h:23
NT_END
@ NT_END
end-of-array marker
Definition news_type.h:40
NewsReferenceType
NewsReferenceType
References to objects in news.
Definition news_type.h:52
NR_TILE
@ NR_TILE
Reference tile. Scroll to tile when clicking on the news.
Definition news_type.h:54
NR_STATION
@ NR_STATION
Reference station. Scroll to station when clicking on the news. Delete news when station is deleted.
Definition news_type.h:56
NR_ENGINE
@ NR_ENGINE
Reference engine.
Definition news_type.h:59
NR_TOWN
@ NR_TOWN
Reference town. Scroll to town when clicking on the news.
Definition news_type.h:58
NR_INDUSTRY
@ NR_INDUSTRY
Reference industry. Scroll to industry when clicking on the news. Delete news when industry is delete...
Definition news_type.h:57
NR_NONE
@ NR_NONE
Empty reference.
Definition news_type.h:53
NR_VEHICLE
@ NR_VEHICLE
Reference vehicle. Scroll to vehicle when clicking on the news. Delete news when vehicle is deleted.
Definition news_type.h:55
NewsIterator
NewsContainer::const_iterator NewsIterator
Iterator type for news items.
Definition news_type.h:165
NewsDisplay
NewsDisplay
News display options.
Definition news_type.h:91
ND_SUMMARY
@ ND_SUMMARY
Show ticker.
Definition news_type.h:93
ND_OFF
@ ND_OFF
Only show a reminder in the status bar.
Definition news_type.h:92
ND_FULL
@ ND_FULL
Show newspaper.
Definition news_type.h:94
NewsContainer
std::list< NewsItem > NewsContainer
Container type for storing news items.
Definition news_type.h:164
NewsFlag
NewsFlag
Various OR-able news-item flags.
Definition news_type.h:66
NF_NO_TRANSPARENT
@ NF_NO_TRANSPARENT
Bit value for disabling transparency.
Definition news_type.h:75
NF_SHADE
@ NF_SHADE
Bit value for enabling shading.
Definition news_type.h:76
NF_VEHICLE_PARAM0
@ NF_VEHICLE_PARAM0
Bit value for specifying that string param 0 contains a vehicle ID. (special autoreplace behaviour)
Definition news_type.h:77
NFB_WINDOW_LAYOUT
@ NFB_WINDOW_LAYOUT
First bit for window layout.
Definition news_type.h:70
NF_NORMAL
@ NF_NORMAL
Normal news item. (Newspaper with text only)
Definition news_type.h:81
NF_INCOLOUR
@ NF_INCOLOUR
Bit value for coloured news.
Definition news_type.h:74
NFB_WINDOW_LAYOUT_COUNT
@ NFB_WINDOW_LAYOUT_COUNT
Number of bits for window layout.
Definition news_type.h:71
news_widget.h
Types related to the news widgets.
WID_N_DATE
@ WID_N_DATE
Date of the news item.
Definition news_widget.h:21
WID_N_PANEL
@ WID_N_PANEL
Panel of the window.
Definition news_widget.h:17
WID_N_CLOSEBOX
@ WID_N_CLOSEBOX
Close the window.
Definition news_widget.h:20
WID_N_SHOW_GROUP
@ WID_N_SHOW_GROUP
Show vehicle's group.
Definition news_widget.h:34
WID_N_CAPTION
@ WID_N_CAPTION
Title bar of the window. Only used in small news items.
Definition news_widget.h:22
WID_N_HEADLINE
@ WID_N_HEADLINE
The news headline.
Definition news_widget.h:19
WID_N_INSET
@ WID_N_INSET
Inset around the viewport in the window. Only used in small news items.
Definition news_widget.h:23
WID_N_VEH_TITLE
@ WID_N_VEH_TITLE
Vehicle new title.
Definition news_widget.h:29
WID_N_VEH_INFO
@ WID_N_VEH_INFO
Some technical data of the new vehicle.
Definition news_widget.h:33
WID_N_TITLE
@ WID_N_TITLE
Title of the company news.
Definition news_widget.h:18
WID_N_VIEWPORT
@ WID_N_VIEWPORT
Viewport in the window.
Definition news_widget.h:24
WID_N_MGR_FACE
@ WID_N_MGR_FACE
Face of the manager.
Definition news_widget.h:27
WID_N_MESSAGE
@ WID_N_MESSAGE
Space for displaying the message. Only used in small news items.
Definition news_widget.h:26
WID_N_VEH_BKGND
@ WID_N_VEH_BKGND
Dark background of new vehicle news.
Definition news_widget.h:30
WID_N_VEH_SPR
@ WID_N_VEH_SPR
Graphical display of the new vehicle.
Definition news_widget.h:32
WID_N_VEH_NAME
@ WID_N_VEH_NAME
Name of the new vehicle.
Definition news_widget.h:31
WID_N_COMPANY_MSG
@ WID_N_COMPANY_MSG
Message in company news items.
Definition news_widget.h:25
WID_N_MGR_NAME
@ WID_N_MGR_NAME
Name of the manager.
Definition news_widget.h:28
WID_MH_SCROLLBAR
@ WID_MH_SCROLLBAR
Scrollbar for the list.
Definition news_widget.h:41
WID_MH_BACKGROUND
@ WID_MH_BACKGROUND
Background of the window.
Definition news_widget.h:40
PC_GREY
static const uint8_t PC_GREY
Grey palette colour.
Definition palette_func.h:69
PC_WHITE
static const uint8_t PC_WHITE
White palette colour.
Definition palette_func.h:70
PC_BLACK
static const uint8_t PC_BLACK
Black palette colour.
Definition palette_func.h:67
roadveh.h
Road vehicle states.
safeguards.h
A number of safeguards to prevent using unsafe methods.
GetSettingFromName
static const SettingDesc * GetSettingFromName(const std::string_view name, const SettingTable &settings)
Given a name of setting, return a setting description from the table.
Definition settings.cpp:1616
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:56
settings_internal.h
Functions and types used internally for the settings configurations.
ScrollMainWindowTo
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
Definition smallmap_gui.cpp:2077
sound_func.h
Functions related to sound.
SoundFx
SoundFx
Sound effects from baseset.
Definition sound_type.h:45
SND_1D_APPLAUSE
@ SND_1D_APPLAUSE
27 == 0x1B News: first vehicle at station
Definition sound_type.h:74
SND_16_NEWS_TICKER
@ SND_16_NEWS_TICKER
20 == 0x14 News ticker
Definition sound_type.h:67
SND_1E_NEW_ENGINE
@ SND_1E_NEW_ENGINE
28 == 0x1C News: new engine available
Definition sound_type.h:75
PALETTE_NEWSPAPER
static const PaletteID PALETTE_NEWSPAPER
Recolour sprite for newspaper-greying.
Definition sprites.h:1604
station_base.h
Base classes/functions for stations.
IsNewsTickerShown
bool IsNewsTickerShown()
Checks whether the news ticker is currently being used.
Definition statusbar_gui.cpp:241
statusbar_gui.h
Functions, definitions and such used only by the GUI.
SBI_SHOW_REMINDER
@ SBI_SHOW_REMINDER
show a reminder (dot on the right side of the statusbar)
Definition statusbar_gui.h:18
SBI_SHOW_TICKER
@ SBI_SHOW_TICKER
start scrolling news
Definition statusbar_gui.h:17
SBI_NEWS_DELETED
@ SBI_NEWS_DELETED
abort current news display (active news were deleted)
Definition statusbar_gui.h:19
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
lengthof
#define lengthof(array)
Return the length of an fixed size array.
Definition stdafx.h:280
StrMakeValid
static void StrMakeValid(T &dst, const char *str, const char *last, StringValidationSettings settings)
Copies the valid (UTF-8) characters from str up to last to the dst.
Definition string.cpp:107
string_func.h
Functions related to low-level strings.
SVS_REPLACE_TAB_CR_NL_WITH_SPACE
@ SVS_REPLACE_TAB_CR_NL_WITH_SPACE
Replace tabs ('\t'), carriage returns ('\r') and newlines (' ') with spaces.
Definition string_type.h:54
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition strings.cpp:104
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
Definition strings.cpp:333
CopyOutDParam
void CopyOutDParam(std::vector< StringParameterData > &backup, size_t num)
Copy num string parameters from the global string parameter array to the backup.
Definition strings.cpp:171
CopyInDParam
void CopyInDParam(const std::span< const StringParameterData > backup)
Copy the parameters from the backup into the global string parameter array.
Definition strings.cpp:159
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
SetDParamStr
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition strings.cpp:371
strings_func.h
Functions related to OTTD's strings.
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition strings_type.h:24
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:16
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition strings_type.h:17
BaseStation::xy
TileIndex xy
Base tile of the station.
Definition base_station_base.h:60
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition vehicle_type.h:51
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition settings_type.h:613
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition settings_type.h:610
CompanyNewsInformation
Data that needs to be stored for company news messages.
Definition news_type.h:153
CompanyNewsInformation::president_name
std::string president_name
The name of the president.
Definition news_type.h:155
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:30
GUISettings::news_message_timeout
uint8_t news_message_timeout
how much longer than the news message "age" should we keep the message in the history
Definition settings_type.h:192
GUISettings::coloured_news_year
TimerGameCalendar::Year coloured_news_year
when does newspaper become coloured?
Definition settings_type.h:185
IntSettingDesc::Read
int32_t Read(const void *object) const
Read the integer from the the actual setting.
Definition settings.cpp:561
MessageHistoryWindow
Definition news_gui.cpp:1168
MessageHistoryWindow::date_width
int date_width
< Height of a single line in the news history window including spacing.
Definition news_gui.cpp:1170
MessageHistoryWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition news_gui.cpp:1229
MessageHistoryWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition news_gui.cpp:1198
MessageHistoryWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition news_gui.cpp:1223
MessageHistoryWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition news_gui.cpp:1243
MessageHistoryWindow::vscroll
Scrollbar * vscroll
< Width needed for the date part.
Definition news_gui.cpp:1172
MessageHistoryWindow::UpdateWidgetSize
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Definition news_gui.cpp:1182
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition widget_type.h:1075
NewsItem
Information about a single item of news.
Definition news_type.h:128
NewsItem::date
TimerGameCalendar::Date date
Calendar date to show for the news.
Definition news_type.h:130
NewsItem::data
std::unique_ptr< NewsAllocatedData > data
Custom data for the news item that will be deallocated (deleted) when the news item has reached its e...
Definition news_type.h:140
NewsItem::params
std::vector< StringParameterData > params
Parameters for string resolving.
Definition news_type.h:142
NewsItem::type
NewsType type
Type of the news.
Definition news_type.h:132
NewsItem::ref1
uint32_t ref1
Reference 1 to some object: Used for a possible viewport, scrolling after clicking on the news,...
Definition news_type.h:137
NewsItem::reftype1
NewsReferenceType reftype1
Type of ref1.
Definition news_type.h:135
NewsItem::economy_date
TimerGameEconomy::Date economy_date
Economy date of the news item, never shown but used to calculate age.
Definition news_type.h:131
NewsItem::ref2
uint32_t ref2
Reference 2 to some object: Used for scrolling after clicking on the news, and for deleting the news ...
Definition news_type.h:138
NewsItem::string_id
StringID string_id
Message text.
Definition news_type.h:129
NewsItem::NewsItem
NewsItem(StringID string_id, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, std::unique_ptr< NewsAllocatedData > &&data)
Create a new newsitem to be shown.
Definition news_gui.cpp:876
NewsItem::flags
NewsFlag flags
NewsFlags bits.
Definition news_type.h:133
NewsItem::reftype2
NewsReferenceType reftype2
Type of ref2.
Definition news_type.h:136
NewsTypeData
Per-NewsType data.
Definition news_type.h:100
NewsTypeData::GetDisplay
NewsDisplay GetDisplay() const
Return the news display option.
Definition news_gui.cpp:340
NewsTypeData::name
const char *const name
Name.
Definition news_type.h:101
NewsTypeData::sound
const SoundFx sound
Sound.
Definition news_type.h:103
NewsTypeData::age
const uint8_t age
Maximum age of news items (in days)
Definition news_type.h:102
NewsWindow
Window class displaying a news item.
Definition news_gui.cpp:348
NewsWindow::chat_height
uint16_t chat_height
Height of the chat window.
Definition news_gui.cpp:349
NewsWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition news_gui.cpp:604
NewsWindow::duration
static int duration
Remaining time for showing the current news message (may only be access while a news item is displaye...
Definition news_gui.cpp:352
NewsWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition news_gui.cpp:502
NewsWindow::UpdateWidgetSize
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Definition news_gui.cpp:428
NewsWindow::OnInitialPosition
Point OnInitialPosition(int16_t sm_width, int16_t sm_height, int window_number) override
Compute the initial position of the window.
Definition news_gui.cpp:422
NewsWindow::OnRealtimeTick
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition news_gui.cpp:637
NewsWindow::status_height
uint16_t status_height
Height of the status bar window.
Definition news_gui.cpp:350
NewsWindow::SetStringParameters
void SetStringParameters(WidgetID widget) const override
Initialize string parameters for a widget.
Definition news_gui.cpp:497
NewsWindow::ni
const NewsItem * ni
News item to display.
Definition news_gui.cpp:351
NewsWindow::SetWindowTop
void SetWindowTop(int newtop)
Moves the window to a new top coordinate.
Definition news_gui.cpp:659
NewsWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition news_gui.cpp:628
NewsWindow::scroll_interval
IntervalTimer< TimerWindow > scroll_interval
Scroll the news message slowly up from the bottom.
Definition news_gui.cpp:649
NewsWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition news_gui.cpp:559
Point
Coordinates of a point in 2D.
Definition geometry_type.hpp:21
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition pool_type.hpp:328
Pool::PoolItem<&_industry_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition pool_type.hpp:339
RectPadding::Horizontal
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition geometry_type.hpp:63
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition geometry_type.hpp:69
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:75
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition geometry_type.hpp:185
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition geometry_type.hpp:98
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition geometry_type.hpp:198
SettingDesc
Properties of config file settings.
Definition settings_internal.h:71
SettingDesc::IsIntSetting
virtual bool IsIntSetting() const
Check whether this setting is an integer type setting.
Definition settings_internal.h:96
SettingDesc::AsIntSetting
const struct IntSettingDesc * AsIntSetting() const
Get the setting description of this setting as an integer setting.
Definition settings.cpp:910
SoundSettings::news_ticker
bool news_ticker
Play a ticker sound when a news item is published.
Definition settings_type.h:245
SoundSettings::news_full
bool news_full
Play sound effects associated to certain news types.
Definition settings_type.h:246
SpecializedStation< Station, false >::Get
static Station * Get(size_t index)
Gets station with given index.
Definition base_station_base.h:254
SpecializedStation< Station, false >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index is a valid index for station of this type.
Definition base_station_base.h:245
SpecializedVehicle::From
static T * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition vehicle_base.h:1215
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
Vehicle
Vehicle data structure.
Definition vehicle_base.h:244
Vehicle::z_pos
int32_t z_pos
z coordinate.
Definition vehicle_base.h:306
Vehicle::y_pos
int32_t y_pos
y coordinate.
Definition vehicle_base.h:305
Vehicle::x_pos
int32_t x_pos
x coordinate.
Definition vehicle_base.h:304
Viewport::top
int top
Screen coordinate top edge of the viewport.
Definition viewport_type.h:24
WindowDesc
High level window description.
Definition window_gui.h:159
Window
Data structure for an opened window.
Definition window_gui.h:273
Window::ReInit
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:952
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1047
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1733
Window::resize
ResizeInfo resize
Resize information.
Definition window_gui.h:314
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1723
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition window_gui.h:318
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition window_gui.h:316
Window::left
int left
x position of left edge of the window
Definition window_gui.h:309
Window::top
int top
y position of top edge of the window
Definition window_gui.h:310
Window::GetWidget
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:977
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:314
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition window_gui.h:312
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:311
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:302
IsValidTile
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition tile_map.h:161
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
timer.h
Definition of Interval and OneShot timers.
timer_game_calendar.h
Definition of the game-calendar-timer.
timer_window.h
Definition of the Window system.
town.h
Base of the town class.
GetEnginePalette
PaletteID GetEnginePalette(EngineID engine_type, CompanyID company)
Get the colour map for an engine.
Definition vehicle.cpp:2142
vehicle_base.h
Base class for all vehicles.
vehicle_func.h
Functions related to vehicles.
ShowVehicleViewWindow
void ShowVehicleViewWindow(const Vehicle *v)
Shows the vehicle view window of the given vehicle.
Definition vehicle_gui.cpp:3504
vehicle_gui.h
Functions related to the vehicle's GUIs.
EIT_PREVIEW
@ EIT_PREVIEW
Vehicle drawn in preview window, news, ...
Definition vehicle_type.h:84
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition vehicle_type.h:25
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition vehicle_type.h:27
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition vehicle_type.h:26
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition vehicle_type.h:24
VehicleID
uint32_t VehicleID
The type all our vehicle IDs have.
Definition vehicle_type.h:16
ScrollWindowToTile
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
Definition viewport.cpp:2504
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition viewport.cpp:2515
viewport_func.h
Functions related to (drawing on) viewports.
DrawCaption
void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, StringID str, StringAlignment align, FontSize fs)
Draw a caption bar.
Definition widget.cpp:680
ND_SHADE_GREY
@ ND_SHADE_GREY
Bit value of the 'shade to grey' flag.
Definition widget_type.h:357
ND_SHADE_DIMMED
@ ND_SHADE_DIMMED
Bit value of the 'dimmed colours' flag.
Definition widget_type.h:358
ND_NO_TRANSPARENCY
@ ND_NO_TRANSPARENCY
Bit value of the 'no transparency' flag.
Definition widget_type.h:356
WWT_INSET
@ WWT_INSET
Pressed (inset) panel, most commonly used as combo box text area.
Definition widget_type.h:51
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition widget_type.h:57
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:75
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:55
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:50
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:66
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:64
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:61
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:85
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:77
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:69
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:48
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition widget_type.h:68
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition widget_type.h:65
NWID_VIEWPORT
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition widget_type.h:82
NWID_LAYER
@ NWID_LAYER
Layered widgets, all visible together.
Definition widget_type.h:81
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition window.cpp:1140
FindWindowByClass
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition window.cpp:1113
PositionNewsMessage
int PositionNewsMessage(Window *w)
(Re)position news message window at the screen.
Definition window.cpp:3412
InvalidateWindowData
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition window.cpp:3219
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition window.cpp:1098
window_func.h
Window functions not directly related to making/drawing windows.
WF_DISABLE_VP_SCROLL
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
Definition window_gui.h:235
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:147
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition window_gui.h:146
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:18
WC_NEWS_WINDOW
@ WC_NEWS_WINDOW
News window; Window numbers:
Definition window_type.h:248
WC_STATUS_BAR
@ WC_STATUS_BAR
Statusbar (at the bottom of your screen); Window numbers:
Definition window_type.h:64
WC_SEND_NETWORK_MSG
@ WC_SEND_NETWORK_MSG
Chatbox; Window numbers:
Definition window_type.h:509
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:45
WC_MESSAGE_HISTORY
@ WC_MESSAGE_HISTORY
News history list; Window numbers:
Definition window_type.h:272
zoom_func.h
Functions related to zooming.
ScaleZoomGUI
ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
Definition zoom_func.h:87
ZOOM_LVL_NEWS
@ ZOOM_LVL_NEWS
Default zoom level for the news messages.
Definition zoom_type.h:29