OpenTTD Source: src/news_gui.cpp Source File

OpenTTD Source 15.0-RC2

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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
89 static TileIndex GetReferenceTile(const NewsReference &reference)
90{
91 struct visitor {
92 TileIndex operator()(const std::monostate &) { return INVALID_TILE; }
93 TileIndex operator()(const TileIndex &t) { return t; }
94 TileIndex operator()(const VehicleID) { return INVALID_TILE; }
95 TileIndex operator()(const StationID s) { return Station::Get(s)->xy; }
96 TileIndex operator()(const IndustryID i) { return Industry::Get(i)->location.tile + TileDiffXY(1, 1); }
97 TileIndex operator()(const TownID t) { return Town::Get(t)->xy; }
98 TileIndex operator()(const EngineID) { return INVALID_TILE; }
99 };
100
101 return std::visit(visitor{}, reference);
102}
103
104/* Normal news items. */
105static constexpr std::initializer_list<NWidgetPart> _nested_normal_news_widgets = {
106 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
107 NWidget(NWID_VERTICAL), SetPadding(WidgetDimensions::unscaled.fullbevel),
108 NWidget(NWID_LAYER, INVALID_COLOUR),
109 /* Layer 1 */
110 NWidget(NWID_VERTICAL), SetPIPRatio(0, 0, 1),
111 NWidget(NWID_HORIZONTAL), SetPIPRatio(0, 1, 0),
112 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX),
113 NWidget(WWT_LABEL, INVALID_COLOUR, WID_N_DATE),
114 SetTextStyle(TC_BLACK, FS_SMALL),
115 SetAlignment(SA_RIGHT | SA_TOP),
116 EndContainer(),
117 EndContainer(),
118 /* Layer 2 */
119 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_MESSAGE),
120 SetMinimalTextLines(8, 0, FS_LARGE),
121 SetMinimalSize(400, 0),
122 SetPadding(WidgetDimensions::unscaled.hsep_indent, WidgetDimensions::unscaled.vsep_wide),
123 SetTextStyle(TC_BLACK, FS_LARGE),
124 EndContainer(),
125 EndContainer(),
126 EndContainer(),
127};
128
129static WindowDesc _normal_news_desc(
130 WDP_MANUAL, {}, 0, 0,
131 WC_NEWS_WINDOW, WC_NONE,
132 {},
133 _nested_normal_news_widgets
134);
135
136/* New vehicles news items. */
137static constexpr std::initializer_list<NWidgetPart> _nested_vehicle_news_widgets = {
138 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
139 NWidget(NWID_VERTICAL), SetPadding(WidgetDimensions::unscaled.fullbevel),
140 NWidget(NWID_LAYER, INVALID_COLOUR),
141 /* Layer 1 */
142 NWidget(NWID_VERTICAL), SetPIPRatio(0, 0, 1),
143 NWidget(NWID_HORIZONTAL), SetPIPRatio(0, 1, 0),
144 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX),
145 EndContainer(),
146 EndContainer(),
147 /* Layer 2 */
148 NWidget(WWT_LABEL, INVALID_COLOUR, WID_N_VEH_TITLE),
149 SetFill(1, 1),
150 SetMinimalTextLines(2, 0, FS_LARGE),
151 SetMinimalSize(400, 0),
152 SetPadding(WidgetDimensions::unscaled.hsep_indent, WidgetDimensions::unscaled.vsep_wide),
153 SetStringTip(STR_EMPTY),
154 SetTextStyle(TC_BLACK, FS_LARGE),
155 EndContainer(),
156 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_VEH_BKGND), SetPadding(WidgetDimensions::unscaled.fullbevel),
157 NWidget(NWID_VERTICAL),
158 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_NAME),
159 SetMinimalTextLines(1, 0, FS_LARGE),
160 SetMinimalSize(350, 0),
161 SetPadding(WidgetDimensions::unscaled.hsep_indent, WidgetDimensions::unscaled.vsep_wide),
162 SetFill(1, 0),
163 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_SPR),
164 SetMinimalSize(350, 32),
165 SetFill(1, 0),
166 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_INFO),
167 SetMinimalTextLines(3, 0, FS_NORMAL),
168 SetMinimalSize(350, 0),
169 SetPadding(WidgetDimensions::unscaled.hsep_indent, WidgetDimensions::unscaled.vsep_wide),
170 SetFill(1, 0),
171 EndContainer(),
172 EndContainer(),
173 EndContainer(),
174 EndContainer(),
175};
176
177static WindowDesc _vehicle_news_desc(
178 WDP_MANUAL, {}, 0, 0,
179 WC_NEWS_WINDOW, WC_NONE,
180 {},
181 _nested_vehicle_news_widgets
182);
183
184/* Company news items. */
185static constexpr std::initializer_list<NWidgetPart> _nested_company_news_widgets = {
186 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
187 NWidget(NWID_VERTICAL), SetPadding(WidgetDimensions::unscaled.fullbevel),
188 NWidget(NWID_LAYER, INVALID_COLOUR),
189 /* Layer 1 */
190 NWidget(NWID_VERTICAL), SetPIPRatio(0, 0, 1),
191 NWidget(NWID_HORIZONTAL), SetPIPRatio(0, 1, 0),
192 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX),
193 EndContainer(),
194 EndContainer(),
195 /* Layer 2 */
196 NWidget(WWT_LABEL, INVALID_COLOUR, WID_N_TITLE),
197 SetFill(1, 1),
198 SetMinimalTextLines(1, 0, FS_LARGE),
199 SetMinimalSize(400, 0),
200 SetPadding(WidgetDimensions::unscaled.hsep_indent, WidgetDimensions::unscaled.vsep_normal),
201 SetTextStyle(TC_BLACK, FS_LARGE),
202 EndContainer(),
203 NWidget(NWID_HORIZONTAL),
204 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0), SetPadding(2),
205 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_MGR_FACE),
206 SetFill(0, 0),
207 SetMinimalSize(93, 119),
208 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_MGR_NAME),
209 SetFill(0, 1),
210 SetMinimalTextLines(2, 0),
211 EndContainer(),
212 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_COMPANY_MSG),
213 SetFill(1, 1),
214 SetPadding(WidgetDimensions::unscaled.hsep_indent, WidgetDimensions::unscaled.vsep_wide),
215 SetMinimalSize(300, 0),
216 SetTextStyle(TC_BLACK, FS_LARGE),
217 EndContainer(),
218 EndContainer(),
219 EndContainer(),
220};
221
222static WindowDesc _company_news_desc(
223 WDP_MANUAL, {}, 0, 0,
224 WC_NEWS_WINDOW, WC_NONE,
225 {},
226 _nested_company_news_widgets
227);
228
229/* Thin news items. */
230static constexpr std::initializer_list<NWidgetPart> _nested_thin_news_widgets = {
231 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
232 NWidget(NWID_VERTICAL), SetPadding(WidgetDimensions::unscaled.fullbevel),
233 NWidget(NWID_LAYER, INVALID_COLOUR),
234 /* Layer 1 */
235 NWidget(NWID_VERTICAL), SetPIPRatio(0, 0, 1),
236 NWidget(NWID_HORIZONTAL), SetPIPRatio(0, 1, 0),
237 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX),
238 NWidget(WWT_LABEL, INVALID_COLOUR, WID_N_DATE),
239 SetTextStyle(TC_BLACK, FS_SMALL),
240 SetAlignment(SA_RIGHT | SA_TOP),
241 EndContainer(),
242 EndContainer(),
243 /* Layer 2 */
244 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_MESSAGE),
245 SetMinimalTextLines(3, 0, FS_LARGE),
246 SetMinimalSize(400, 0),
247 SetPadding(WidgetDimensions::unscaled.hsep_indent, WidgetDimensions::unscaled.vsep_normal),
248 SetTextStyle(TC_BLACK, FS_LARGE),
249 EndContainer(),
250 NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetMinimalSize(426, 70),
251 SetPadding(WidgetDimensions::unscaled.fullbevel),
252 EndContainer(),
253 EndContainer(),
254};
255
256static WindowDesc _thin_news_desc(
257 WDP_MANUAL, {}, 0, 0,
258 WC_NEWS_WINDOW, WC_NONE,
259 {},
260 _nested_thin_news_widgets
261);
262
263/* Small news items. */
264static constexpr std::initializer_list<NWidgetPart> _nested_small_news_widgets = {
265 /* Caption + close box. The caption is not WWT_CAPTION as the window shall not be moveable and so on. */
266 NWidget(NWID_HORIZONTAL),
267 NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE, WID_N_CLOSEBOX),
268 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_CAPTION),
269 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_N_SHOW_GROUP_SEL),
270 NWidget(WWT_TEXTBTN, COLOUR_LIGHT_BLUE, WID_N_SHOW_GROUP),
271 SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON),
272 SetResize(1, 0),
273 SetToolTip(STR_NEWS_SHOW_VEHICLE_GROUP_TOOLTIP),
274 EndContainer(),
275 EndContainer(),
276
277 /* Main part */
278 NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_N_HEADLINE),
279 NWidget(NWID_VERTICAL),
280 SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
281 SetPadding(2),
282 NWidget(WWT_INSET, COLOUR_LIGHT_BLUE, WID_N_INSET),
283 NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT),
284 SetMinimalSize(274, 47),
285 EndContainer(),
286 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_MESSAGE),
287 SetMinimalTextLines(2, 0),
288 SetMinimalSize(275, 0),
289 SetTextStyle(TC_WHITE, FS_NORMAL),
290 EndContainer(),
291 EndContainer(),
292};
293
294static WindowDesc _small_news_desc(
295 WDP_MANUAL, {}, 0, 0,
296 WC_NEWS_WINDOW, WC_NONE,
297 {},
298 _nested_small_news_widgets
299);
300
304 static WindowDesc *_news_window_layout[] = {
305 &_thin_news_desc, // NewsStyle::Thin
306 &_small_news_desc, // NewsStyle::Small
307 &_normal_news_desc, // NewsStyle::Normal
308 &_vehicle_news_desc, // NewsStyle::Vehicle
309 &_company_news_desc, // NewsStyle::Company
310};
311
312static WindowDesc &GetNewsWindowLayout(NewsStyle style)
313{
314 uint layout = to_underlying(style);
315 assert(layout < lengthof(_news_window_layout));
316 return *_news_window_layout[layout];
317}
318
322 static const NewsTypeData _news_type_data[] = {
323 /* name, age, sound, */
324 NewsTypeData("news_display.arrival_player", 60, SND_1D_APPLAUSE ),
325 NewsTypeData("news_display.arrival_other", 60, SND_1D_APPLAUSE ),
326 NewsTypeData("news_display.accident", 90, SND_BEGIN ),
327 NewsTypeData("news_display.accident_other", 90, SND_BEGIN ),
328 NewsTypeData("news_display.company_info", 60, SND_BEGIN ),
329 NewsTypeData("news_display.open", 90, SND_BEGIN ),
330 NewsTypeData("news_display.close", 90, SND_BEGIN ),
331 NewsTypeData("news_display.economy", 30, SND_BEGIN ),
332 NewsTypeData("news_display.production_player", 30, SND_BEGIN ),
333 NewsTypeData("news_display.production_other", 30, SND_BEGIN ),
334 NewsTypeData("news_display.production_nobody", 30, SND_BEGIN ),
335 NewsTypeData("news_display.advice", 150, SND_BEGIN ),
336 NewsTypeData("news_display.new_vehicles", 30, SND_1E_NEW_ENGINE),
337 NewsTypeData("news_display.acceptance", 90, SND_BEGIN ),
338 NewsTypeData("news_display.subsidies", 180, SND_BEGIN ),
339 NewsTypeData("news_display.general", 60, SND_BEGIN ),
340};
341
342static_assert(std::size(_news_type_data) == to_underlying(NewsType::End));
343
348 NewsDisplay NewsTypeData::GetDisplay() const
349{
350 const SettingDesc *sd = GetSettingFromName(this->name);
351 assert(sd != nullptr && sd->IsIntSetting());
352 return static_cast<NewsDisplay>(sd->AsIntSetting()->Read(nullptr));
353}
354
356 struct NewsWindow : Window {
357 uint16_t chat_height = 0;
358 uint16_t status_height = 0;
359 const NewsItem *ni = nullptr;
360 static int duration;
361
362 NewsWindow(WindowDesc &desc, const NewsItem *ni) : Window(desc), ni(ni)
363 {
364 NewsWindow::duration = 16650;
365 const Window *w = FindWindowByClass(WC_SEND_NETWORK_MSG);
366 this->chat_height = (w != nullptr) ? w->height : 0;
367 this->status_height = FindWindowById(WC_STATUS_BAR, 0)->height;
368
369 this->flags.Set(WindowFlag::DisableVpScroll);
370
371 this->CreateNestedTree();
372
373 bool has_vehicle_id = std::holds_alternative<VehicleID>(ni->ref1);
374 NWidgetStacked *nwid_sel = this->GetWidget<NWidgetStacked>(WID_N_SHOW_GROUP_SEL);
375 if (nwid_sel != nullptr) nwid_sel->SetDisplayedPlane(has_vehicle_id ? 0 : SZSP_NONE);
376
377 NWidgetCore *nwid = this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP);
378 if (has_vehicle_id && nwid != nullptr) {
379 const Vehicle *v = Vehicle::Get(std::get<VehicleID>(ni->ref1));
380 switch (v->type) {
381 case VEH_TRAIN:
382 nwid->SetString(STR_TRAIN);
383 break;
384 case VEH_ROAD:
385 nwid->SetString(RoadVehicle::From(v)->IsBus() ? STR_BUS : STR_LORRY);
386 break;
387 case VEH_SHIP:
388 nwid->SetString(STR_SHIP);
389 break;
390 case VEH_AIRCRAFT:
391 nwid->SetString(STR_PLANE);
392 break;
393 default:
394 break; // Do nothing
395 }
396 }
397
398 this->FinishInitNested(0);
399
400 /* Initialize viewport if it exists. */
401 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
402 if (nvp != nullptr) {
403 if (std::holds_alternative<VehicleID>(ni->ref1)) {
404 nvp->InitializeViewport(this, std::get<VehicleID>(ni->ref1), ScaleZoomGUI(ZoomLevel::News));
405 } else {
406 nvp->InitializeViewport(this, GetReferenceTile(ni->ref1), ScaleZoomGUI(ZoomLevel::News));
407 }
408 if (this->ni->flags.Test(NewsFlag::NoTransparency)) nvp->disp_flags.Set(NWidgetDisplayFlag::NoTransparency);
409 if (!this->ni->flags.Test(NewsFlag::InColour)) {
410 nvp->disp_flags.Set(NWidgetDisplayFlag::ShadeGrey);
411 } else if (this->ni->flags.Test(NewsFlag::Shaded)) {
412 nvp->disp_flags.Set(NWidgetDisplayFlag::ShadeDimmed);
413 }
414 }
415
416 PositionNewsMessage(this);
417 }
418
419 void DrawNewsBorder(const Rect &r) const
420 {
421 Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
422 GfxFillRect(ir, PC_WHITE);
423
424 ir = ir.Expand(1);
425 GfxFillRect( r.left, r.top, ir.left, r.bottom, PC_BLACK);
426 GfxFillRect(ir.right, r.top, r.right, r.bottom, PC_BLACK);
427 GfxFillRect( r.left, r.top, r.right, ir.top, PC_BLACK);
428 GfxFillRect( r.left, ir.bottom, r.right, r.bottom, PC_BLACK);
429 }
430
431 Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
432 {
433 Point pt = { 0, _screen.height };
434 return pt;
435 }
436
437 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
438 {
439 FontSize fontsize = FS_NORMAL;
440 std::string str;
441 switch (widget) {
442 case WID_N_CAPTION: {
443 /* Caption is not a real caption (so that the window cannot be moved)
444 * thus it doesn't get the default sizing of a caption. */
445 Dimension d2 = GetStringBoundingBox(STR_NEWS_MESSAGE_CAPTION);
446 d2.height += WidgetDimensions::scaled.captiontext.Vertical();
447 size = maxdim(size, d2);
448 return;
449 }
450
451 case WID_N_MGR_FACE:
452 size = maxdim(size, GetScaledSpriteSize(SPR_GRADIENT));
453 break;
454
455 case WID_N_MESSAGE:
456 case WID_N_COMPANY_MSG:
457 fontsize = this->GetWidget<NWidgetLeaf>(widget)->GetFontSize();
458 str = this->ni->headline.GetDecodedString();
459 break;
460
461 case WID_N_VEH_NAME:
462 case WID_N_VEH_TITLE:
463 str = this->GetNewVehicleMessageString(widget);
464 break;
465
466 case WID_N_VEH_INFO: {
467 assert(std::holds_alternative<EngineID>(ni->ref1));
468 EngineID engine = std::get<EngineID>(this->ni->ref1);
469 str = GetEngineInfoString(engine);
470 break;
471 }
472
473 case WID_N_SHOW_GROUP:
474 if (std::holds_alternative<VehicleID>(ni->ref1)) {
475 Dimension d2 = GetStringBoundingBox(this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP)->GetString());
476 d2.height += WidgetDimensions::scaled.captiontext.Vertical();
477 d2.width += WidgetDimensions::scaled.captiontext.Horizontal();
478 size = d2;
479 }
480 return;
481
482 default:
483 return; // Do nothing
484 }
485
486 /* Update minimal size with length of the multi-line string. */
487 Dimension d = size;
488 d.width = (d.width >= padding.width) ? d.width - padding.width : 0;
489 d.height = (d.height >= padding.height) ? d.height - padding.height : 0;
490 d = GetStringMultiLineBoundingBox(str, d, fontsize);
491 d.width += padding.width;
492 d.height += padding.height;
493 size = maxdim(size, d);
494 }
495
496 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
497 {
498 if (widget == WID_N_DATE) {
499 return GetString(STR_JUST_DATE_LONG, this->ni->date);
500 } else if (widget == WID_N_TITLE) {
501 const CompanyNewsInformation *cni = static_cast<const CompanyNewsInformation*>(this->ni->data.get());
502 return GetString(cni->title);
503 }
504
505 return this->Window::GetWidgetString(widget, stringid);
506
507 }
508
509 void DrawWidget(const Rect &r, WidgetID widget) const override
510 {
511 switch (widget) {
512 case WID_N_CAPTION:
513 DrawCaption(r, COLOUR_LIGHT_BLUE, this->owner, TC_FROMSTRING, GetString(STR_NEWS_MESSAGE_CAPTION), SA_CENTER, FS_NORMAL);
514 break;
515
516 case WID_N_PANEL:
517 this->DrawNewsBorder(r);
518 break;
519
520 case WID_N_MESSAGE:
521 case WID_N_COMPANY_MSG: {
522 const NWidgetLeaf &nwid = *this->GetWidget<NWidgetLeaf>(widget);
523 DrawStringMultiLine(r, this->ni->headline.GetDecodedString(), nwid.GetTextColour(), SA_CENTER, false, nwid.GetFontSize());
524 break;
525 }
526
527 case WID_N_MGR_FACE: {
528 const CompanyNewsInformation *cni = static_cast<const CompanyNewsInformation*>(this->ni->data.get());
529 DrawCompanyManagerFace(cni->face, cni->colour, r);
530 GfxFillRect(r, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
531 break;
532 }
533 case WID_N_MGR_NAME: {
534 const CompanyNewsInformation *cni = static_cast<const CompanyNewsInformation*>(this->ni->data.get());
535 DrawStringMultiLine(r, GetString(STR_JUST_RAW_STRING, cni->president_name), TC_FROMSTRING, SA_CENTER);
536 break;
537 }
538
539 case WID_N_VEH_BKGND:
540 GfxFillRect(r, PC_GREY);
541 break;
542
543 case WID_N_VEH_NAME:
544 case WID_N_VEH_TITLE:
545 DrawStringMultiLine(r, this->GetNewVehicleMessageString(widget), TC_FROMSTRING, SA_CENTER);
546 break;
547
548 case WID_N_VEH_SPR: {
549 assert(std::holds_alternative<EngineID>(ni->ref1));
550 EngineID engine = std::get<EngineID>(this->ni->ref1);
551 DrawVehicleEngine(r.left, r.right, CentreBounds(r.left, r.right, 0), CentreBounds(r.top, r.bottom, 0), engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
552 GfxFillRect(r, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
553 break;
554 }
555 case WID_N_VEH_INFO: {
556 assert(std::holds_alternative<EngineID>(ni->ref1));
557 EngineID engine = std::get<EngineID>(this->ni->ref1);
558 DrawStringMultiLine(r, GetEngineInfoString(engine), TC_BLACK, SA_CENTER);
559 break;
560 }
561 }
562 }
563
564 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
565 {
566 switch (widget) {
567 case WID_N_CLOSEBOX:
568 NewsWindow::duration = 0;
569 this->Close();
570 _forced_news = std::end(_news);
571 break;
572
573 case WID_N_CAPTION:
574 if (std::holds_alternative<VehicleID>(ni->ref1)) {
575 const Vehicle *v = Vehicle::Get(std::get<VehicleID>(this->ni->ref1));
576 ShowVehicleViewWindow(v);
577 }
578 break;
579
580 case WID_N_VIEWPORT:
581 break; // Ignore clicks
582
583 case WID_N_SHOW_GROUP:
584 if (std::holds_alternative<VehicleID>(ni->ref1)) {
585 const Vehicle *v = Vehicle::Get(std::get<VehicleID>(this->ni->ref1));
586 ShowCompanyGroupForVehicle(v);
587 }
588 break;
589 default:
590 if (std::holds_alternative<VehicleID>(ni->ref1)) {
591 const Vehicle *v = Vehicle::Get(std::get<VehicleID>(this->ni->ref1));
592 ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos);
593 } else {
594 TileIndex tile1 = GetReferenceTile(this->ni->ref1);
595 TileIndex tile2 = GetReferenceTile(this->ni->ref2);
596 if (_ctrl_pressed) {
597 if (tile1 != INVALID_TILE) ShowExtraViewportWindow(tile1);
598 if (tile2 != INVALID_TILE) ShowExtraViewportWindow(tile2);
599 } else {
600 if ((tile1 == INVALID_TILE || !ScrollMainWindowToTile(tile1)) && tile2 != INVALID_TILE) {
601 ScrollMainWindowToTile(tile2);
602 }
603 }
604 }
605 break;
606 }
607 }
608
609 void OnResize() override
610 {
611 if (this->viewport != nullptr) {
612 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
613 nvp->UpdateViewportCoordinates(this);
614
615 if (!std::holds_alternative<VehicleID>(ni->ref1)) {
616 ScrollWindowToTile(GetReferenceTile(ni->ref1), this, true); // Re-center viewport.
617 }
618 }
619
620 NWidgetResizeBase *wid = this->GetWidget<NWidgetResizeBase>(WID_N_MGR_NAME);
621 if (wid != nullptr) {
622 int y = GetStringHeight(GetString(STR_JUST_RAW_STRING, static_cast<const CompanyNewsInformation *>(this->ni->data.get())->president_name), wid->current_x);
623 if (wid->UpdateVerticalSize(y)) this->ReInit(0, 0);
624 }
625 }
626
632 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
633 {
634 if (!gui_scope) return;
635 /* The chatbar has notified us that is was either created or closed */
636 int newtop = this->top + this->chat_height - data;
637 this->chat_height = data;
638 this->SetWindowTop(newtop);
639 }
640
641 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
642 {
643 /* Decrement the news timer. We don't need to action an elapsed event here,
644 * so no need to use TimerElapsed(). */
645 if (NewsWindow::duration > 0) NewsWindow::duration -= delta_ms;
646 }
647
653 const IntervalTimer<TimerWindow> scroll_interval = {std::chrono::milliseconds(210) / GetCharacterHeight(FS_NORMAL), [this](uint count) {
654 int newtop = std::max(this->top - 2 * static_cast<int>(count), _screen.height - this->height - this->status_height - this->chat_height);
655 this->SetWindowTop(newtop);
656 }};
657
658private:
663 void SetWindowTop(int newtop)
664 {
665 if (this->top == newtop) return;
666
667 int mintop = std::min(newtop, this->top);
668 int maxtop = std::max(newtop, this->top);
669 if (this->viewport != nullptr) this->viewport->top += newtop - this->top;
670 this->top = newtop;
671
672 AddDirtyBlock(this->left, mintop, this->left + this->width, maxtop + this->height);
673 }
674
675 std::string GetNewVehicleMessageString(WidgetID widget) const
676 {
677 assert(std::holds_alternative<EngineID>(ni->ref1));
678 EngineID engine = std::get<EngineID>(this->ni->ref1);
679
680 switch (widget) {
681 case WID_N_VEH_TITLE:
682 return GetString(STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE, GetEngineCategoryName(engine));
683
684 case WID_N_VEH_NAME:
685 return GetString(STR_NEWS_NEW_VEHICLE_TYPE, PackEngineNameDParam(engine, EngineNameContext::PreviewNews));
686
687 default:
688 NOT_REACHED();
689 }
690 }
691};
692
693/* static */ int NewsWindow::duration = 0; // Instance creation.
694
696 static void ShowNewspaper(const NewsItem *ni)
697{
698 SoundFx sound = _news_type_data[to_underlying(ni->type)].sound;
699 if (sound != 0 && _settings_client.sound.news_full) SndPlayFx(sound);
700
701 new NewsWindow(GetNewsWindowLayout(ni->style), ni);
702}
703
705 static void ShowTicker(NewsIterator ni)
706{
707 if (_settings_client.sound.news_ticker) SndPlayFx(SND_16_NEWS_TICKER);
708
709 _statusbar_news = ni;
710 InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_TICKER);
711}
712
714 void InitNewsItemStructs()
715{
716 _news.clear();
717 _forced_news = std::end(_news);
718 _current_news = std::end(_news);
719 _statusbar_news = std::end(_news);
720 NewsWindow::duration = 0;
721}
722
727 static bool ReadyForNextTickerItem()
728{
729 const NewsItem *ni = GetStatusbarNews();
730 if (ni == nullptr) return true;
731
732 /* Ticker message
733 * Check if the status bar message is still being displayed? */
734 return !IsNewsTickerShown();
735}
736
741 static bool ReadyForNextNewsItem()
742{
743 if (_forced_news == std::end(_news) && _current_news == std::end(_news)) return true;
744
745 /* neither newsticker nor newspaper are running */
746 return (NewsWindow::duration <= 0 || FindWindowById(WC_NEWS_WINDOW, 0) == nullptr);
747}
748
750 static void MoveToNextTickerItem()
751{
752 /* There is no status bar, so no reason to show news;
753 * especially important with the end game screen when
754 * there is no status bar but possible news. */
755 if (FindWindowById(WC_STATUS_BAR, 0) == nullptr) return;
756
757 /* No news to move to. */
758 if (std::empty(_news)) return;
759
760 /* if we're not at the latest item, then move on */
761 while (_statusbar_news != std::begin(_news)) {
762 --_statusbar_news;
763 const NewsType type = _statusbar_news->type;
764
765 /* check the date, don't show too old items */
766 if (TimerGameEconomy::date - _news_type_data[to_underlying(type)].age > _statusbar_news->economy_date) continue;
767
768 switch (_news_type_data[to_underlying(type)].GetDisplay()) {
769 default: NOT_REACHED();
770 case NewsDisplay::Off: // Show nothing only a small reminder in the status bar.
771 InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_REMINDER);
772 return;
773
774 case NewsDisplay::Summary: // Show ticker.
775 ShowTicker(_statusbar_news);
776 return;
777
778 case NewsDisplay::Full: // Show newspaper, skipped here.
779 break;;
780 }
781 }
782}
783
785 static void MoveToNextNewsItem()
786{
787 /* There is no status bar, so no reason to show news;
788 * especially important with the end game screen when
789 * there is no status bar but possible news. */
790 if (FindWindowById(WC_STATUS_BAR, 0) == nullptr) return;
791
792 CloseWindowById(WC_NEWS_WINDOW, 0); // close the newspapers window if shown
793 _forced_news = std::end(_news);
794
795 /* No news to move to. */
796 if (std::empty(_news)) return;
797
798 /* if we're not at the latest item, then move on */
799 while (_current_news != std::begin(_news)) {
800 --_current_news;
801 const NewsType type = _current_news->type;
802
803 /* check the date, don't show too old items */
804 if (TimerGameEconomy::date - _news_type_data[to_underlying(type)].age > _current_news->economy_date) continue;
805
806 switch (_news_type_data[to_underlying(type)].GetDisplay()) {
807 default: NOT_REACHED();
808 case NewsDisplay::Off: // Show nothing only a small reminder in the status bar, skipped here.
809 break;
810
811 case NewsDisplay::Summary: // Show ticker, skipped here.
812 break;
813
814 case NewsDisplay::Full: // Sshow newspaper.
815 ShowNewspaper(&*_current_news);
816 return;
817 }
818 }
819}
820
822 static std::list<NewsItem>::iterator DeleteNewsItem(std::list<NewsItem>::iterator ni)
823{
824 bool update_current_news = (_forced_news == ni || _current_news == ni);
825 bool update_statusbar_news = (_statusbar_news == ni);
826
827 if (update_current_news) {
828 /* When we're the current news, go to the next older item first;
829 * we just possibly made that the last news item. */
830 if (_current_news == ni) ++_current_news;
831 if (_forced_news == ni) _forced_news = std::end(_news);
832 }
833
834 if (update_statusbar_news) {
835 /* When we're the current news, go to the next older item first;
836 * we just possibly made that the last news item. */
837 ++_statusbar_news;
838 }
839
840 /* Delete the news from the news queue. */
841 ni = _news.erase(ni);
842
843 if (update_current_news) {
844 /* About to remove the currently forced item (shown as newspapers) ||
845 * about to remove the currently displayed item (newspapers) */
846 MoveToNextNewsItem();
847 }
848
849 if (update_statusbar_news) {
850 /* About to remove the currently displayed item (ticker, or just a reminder) */
851 InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); // invalidate the statusbar
852 MoveToNextTickerItem();
853 }
854
855 return ni;
856}
857
870NewsItem::NewsItem(EncodedString &&headline, NewsType type, NewsStyle style, NewsFlags flags, NewsReference ref1, NewsReference ref2, std::unique_ptr<NewsAllocatedData> &&data, AdviceType advice_type) :
871 headline(std::move(headline)), date(TimerGameCalendar::date), economy_date(TimerGameEconomy::date), type(type), advice_type(advice_type), style(style), flags(flags), ref1(ref1), ref2(ref2), data(std::move(data))
872{
873 /* show this news message in colour? */
874 if (TimerGameCalendar::year >= _settings_client.gui.coloured_news_year) this->flags.Set(NewsFlag::InColour);
875}
876
877std::string NewsItem::GetStatusText() const
878{
879 if (this->data != nullptr) {
880 /* CompanyNewsInformation is the only type of additional data used. */
881 const CompanyNewsInformation &cni = *static_cast<const CompanyNewsInformation*>(this->data.get());
882 return GetString(STR_MESSAGE_NEWS_FORMAT, cni.title, this->headline.GetDecodedString());
883 }
884
885 return this->headline.GetDecodedString();
886}
887
900 void AddNewsItem(EncodedString &&headline, NewsType type, NewsStyle style, NewsFlags flags, NewsReference ref1, NewsReference ref2, std::unique_ptr<NewsAllocatedData> &&data, AdviceType advice_type)
901{
902 if (_game_mode == GM_MENU) return;
903
904 /* Create new news item node */
905 _news.emplace_front(std::move(headline), type, style, flags, ref1, ref2, std::move(data), advice_type);
906
907 /* Keep the number of stored news items to a manageable number */
908 if (std::size(_news) > MAX_NEWS_AMOUNT) {
909 DeleteNewsItem(std::prev(std::end(_news)));
910 }
911
912 InvalidateWindowData(WC_MESSAGE_HISTORY, 0);
913}
914
920uint32_t SerialiseNewsReference(const NewsReference &reference)
921{
922 struct visitor {
923 uint32_t operator()(const std::monostate &) { return 0; }
924 uint32_t operator()(const TileIndex &t) { return t.base(); }
925 uint32_t operator()(const VehicleID v) { return v.base(); }
926 uint32_t operator()(const StationID s) { return s.base(); }
927 uint32_t operator()(const IndustryID i) { return i.base(); }
928 uint32_t operator()(const TownID t) { return t.base(); }
929 uint32_t operator()(const EngineID e) { return e.base(); }
930 };
931
932 return std::visit(visitor{}, reference);
933}
934
945 CommandCost CmdCustomNewsItem(DoCommandFlags flags, NewsType type, CompanyID company, NewsReference reference, const EncodedString &text)
946{
947 if (_current_company != OWNER_DEITY) return CMD_ERROR;
948
949 if (company != INVALID_OWNER && !Company::IsValidID(company)) return CMD_ERROR;
950 if (type >= NewsType::End) return CMD_ERROR;
951 if (text.empty()) return CMD_ERROR;
952
953 struct visitor {
954 bool operator()(const std::monostate &) { return true; }
955 bool operator()(const TileIndex t) { return IsValidTile(t); }
956 bool operator()(const VehicleID v) { return Vehicle::IsValidID(v); }
957 bool operator()(const StationID s) { return Station::IsValidID(s); }
958 bool operator()(const IndustryID i) { return Industry::IsValidID(i); }
959 bool operator()(const TownID t) { return Town::IsValidID(t); }
960 bool operator()(const EngineID e) { return Engine::IsValidID(e); }
961 };
962
963 if (!std::visit(visitor{}, reference)) return CMD_ERROR;
964
965 if (company != INVALID_OWNER && company != _local_company) return CommandCost();
966
967 if (flags.Test(DoCommandFlag::Execute)) {
968 AddNewsItem(EncodedString{text}, type, NewsStyle::Normal, {}, reference, {});
969 }
970
971 return CommandCost();
972}
973
979template <size_t Tmin = 0, class Tpredicate>
980 void DeleteNews(Tpredicate predicate)
981{
982 bool dirty = false;
983 for (auto it = std::rbegin(_news); it != std::rend(_news); /* nothing */) {
984 if constexpr (Tmin > 0) {
985 if (std::size(_news) <= Tmin) break;
986 }
987 if (predicate(*it)) {
988 it = std::make_reverse_iterator(DeleteNewsItem(std::prev(it.base())));
989 dirty = true;
990 } else {
991 ++it;
992 }
993 }
994 if (dirty) InvalidateWindowData(WC_MESSAGE_HISTORY, 0);
995}
996
997template <typename T>
998static bool IsReferenceObject(const NewsReference &reference, T id)
999{
1000 return std::holds_alternative<T>(reference) && std::get<T>(reference) == id;
1001}
1002
1003template <typename T>
1004static bool HasReferenceObject(const NewsItem &ni, T id)
1005{
1006 return IsReferenceObject(ni.ref1, id) || IsReferenceObject(ni.ref2, id);
1007}
1008
1015 void DeleteVehicleNews(VehicleID vid, AdviceType advice_type)
1016{
1017 DeleteNews([&](const auto &ni) {
1018 return HasReferenceObject(ni, vid) && (advice_type == AdviceType::Invalid || ni.advice_type == advice_type);
1019 });
1020}
1021
1027 void DeleteStationNews(StationID sid)
1028{
1029 DeleteNews([&](const auto &ni) {
1030 return HasReferenceObject(ni, sid);
1031 });
1032}
1033
1038 void DeleteIndustryNews(IndustryID iid)
1039{
1040 DeleteNews([&](const auto &ni) {
1041 return HasReferenceObject(ni, iid);
1042 });
1043}
1044
1045bool IsInvalidEngineNews(const NewsReference &reference)
1046{
1047 if (!std::holds_alternative<EngineID>(reference)) return false;
1048
1049 EngineID eid = std::get<EngineID>(reference);
1050 return !Engine::IsValidID(eid) || !Engine::Get(eid)->IsEnabled();
1051}
1052
1056 void DeleteInvalidEngineNews()
1057{
1058 DeleteNews([](const auto &ni) {
1059 return IsInvalidEngineNews(ni.ref1) || IsInvalidEngineNews(ni.ref2);
1060 });
1061}
1062
1063static void RemoveOldNewsItems()
1064{
1065 DeleteNews<MIN_NEWS_AMOUNT>([](const auto &ni) {
1066 return TimerGameEconomy::date - _news_type_data[to_underlying(ni.type)].age * _settings_client.gui.news_message_timeout > ni.economy_date;
1067 });
1068}
1069
1070template <typename T>
1071static void ChangeObject(NewsReference reference, T from, T to)
1072{
1073 if (!std::holds_alternative<T>(reference)) return;
1074 if (std::get<T>(reference) == from) reference = to;
1075}
1076
1083 void ChangeVehicleNews(VehicleID from_index, VehicleID to_index)
1084{
1085 for (auto &ni : _news) {
1086 ChangeObject(ni.ref1, from_index, to_index);
1087 ChangeObject(ni.ref2, from_index, to_index);
1088 if (ni.flags.Test(NewsFlag::VehicleParam0) && IsReferenceObject(ni.ref1, to_index)) ni.headline = ni.headline.ReplaceParam(0, to_index.base());
1089 }
1090}
1091
1092void NewsLoop()
1093{
1094 /* no news item yet */
1095 if (std::empty(_news)) return;
1096
1097 static TimerGameEconomy::Month _last_clean_month = 0;
1098
1099 if (_last_clean_month != TimerGameEconomy::month) {
1100 RemoveOldNewsItems();
1101 _last_clean_month = TimerGameEconomy::month;
1102 }
1103
1104 if (ReadyForNextTickerItem()) MoveToNextTickerItem();
1105 if (ReadyForNextNewsItem()) MoveToNextNewsItem();
1106}
1107
1109 static void ShowNewsMessage(NewsIterator ni)
1110{
1111 assert(!std::empty(_news));
1112
1113 /* Delete the news window */
1114 CloseWindowById(WC_NEWS_WINDOW, 0);
1115
1116 /* setup forced news item */
1117 _forced_news = ni;
1118
1119 if (_forced_news != std::end(_news)) {
1120 CloseWindowById(WC_NEWS_WINDOW, 0);
1121 ShowNewspaper(&*ni);
1122 }
1123}
1124
1129 bool HideActiveNewsMessage()
1130{
1131 NewsWindow *w = dynamic_cast<NewsWindow *>(FindWindowById(WC_NEWS_WINDOW, 0));
1132 if (w == nullptr) return false;
1133 w->Close();
1134 return true;
1135}
1136
1138 void ShowLastNewsMessage()
1139{
1140 if (std::empty(_news)) return;
1141
1142 NewsIterator ni;
1143 if (_forced_news == std::end(_news)) {
1144 /* Not forced any news yet, show the current one, unless a news window is
1145 * open (which can only be the current one), then show the previous item */
1146 if (_current_news == std::end(_news)) {
1147 /* No news were shown yet resp. the last shown one was already deleted.
1148 * Treat this as if _forced_news reached the oldest news; so, wrap around and start anew with the latest. */
1149 ni = std::begin(_news);
1150 } else {
1151 const Window *w = FindWindowById(WC_NEWS_WINDOW, 0);
1152 ni = (w == nullptr || (std::next(_current_news) == std::end(_news))) ? _current_news : std::next(_current_news);
1153 }
1154 } else if (std::next(_forced_news) == std::end(_news)) {
1155 /* We have reached the oldest news, start anew with the latest */
1156 ni = std::begin(_news);
1157 } else {
1158 /* 'Scrolling' through news history show each one in turn */
1159 ni = std::next(_forced_news);
1160 }
1161 bool wrap = false;
1162 for (;;) {
1163 if (_news_type_data[to_underlying(ni->type)].GetDisplay() != NewsDisplay::Off) {
1164 ShowNewsMessage(ni);
1165 break;
1166 }
1167
1168 ++ni;
1169 if (ni == std::end(_news)) {
1170 if (wrap) break;
1171 /* We have reached the oldest news, start anew with the latest */
1172 ni = std::begin(_news);
1173 wrap = true;
1174 }
1175 }
1176}
1177
1178
1188 static void DrawNewsString(uint left, uint right, int y, TextColour colour, const NewsItem &ni)
1189{
1190 /* Get the string, replaces newlines with spaces and remove control codes from the string. */
1191 std::string message = StrMakeValid(ni.GetStatusText(), StringValidationSetting::ReplaceTabCrNlWithSpace);
1192
1193 /* Truncate and show string; postfixed by '...' if necessary */
1194 DrawString(left, right, y, message, colour);
1195}
1196
1197 struct MessageHistoryWindow : Window {
1198 int line_height = 0;
1199 int date_width = 0;
1200
1201 Scrollbar *vscroll = nullptr;
1202
1203 MessageHistoryWindow(WindowDesc &desc) : Window(desc)
1204 {
1205 this->CreateNestedTree();
1206 this->vscroll = this->GetScrollbar(WID_MH_SCROLLBAR);
1207 this->FinishInitNested(); // Initializes 'this->line_height' and 'this->date_width'.
1208 this->OnInvalidateData(0);
1209 }
1210
1211 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
1212 {
1213 if (widget == WID_MH_BACKGROUND) {
1214 this->line_height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
1215 fill.height = resize.height = this->line_height;
1216
1217 /* Months are off-by-one, so it's actually 8. Not using
1218 * month 12 because the 1 is usually less wide. */
1219 this->date_width = GetStringBoundingBox(GetString(STR_JUST_DATE_TINY, TimerGameCalendar::ConvertYMDToDate(CalendarTime::ORIGINAL_MAX_YEAR, 7, 30))).width + WidgetDimensions::scaled.hsep_wide;
1220
1221 size.height = 4 * resize.height + WidgetDimensions::scaled.framerect.Vertical(); // At least 4 lines are visible.
1222 size.width = std::max(200u, size.width); // At least 200 pixels wide.
1223 }
1224 }
1225
1226 void DrawWidget(const Rect &r, WidgetID widget) const override
1227 {
1228 if (widget != WID_MH_BACKGROUND || std::empty(_news)) return;
1229
1230 /* Fill the widget with news items. */
1231 bool rtl = _current_text_dir == TD_RTL;
1232 Rect news = r.Shrink(WidgetDimensions::scaled.framerect).Indent(this->date_width + WidgetDimensions::scaled.hsep_wide, rtl);
1233 Rect date = r.Shrink(WidgetDimensions::scaled.framerect).WithWidth(this->date_width, rtl);
1234 int y = news.top;
1235
1236 auto [first, last] = this->vscroll->GetVisibleRangeIterators(_news);
1237 for (auto ni = first; ni != last; ++ni) {
1238 DrawString(date.left, date.right, y, GetString(STR_JUST_DATE_TINY, ni->date), TC_WHITE);
1239
1240 DrawNewsString(news.left, news.right, y, TC_WHITE, *ni);
1241 y += this->line_height;
1242 }
1243 }
1244
1250 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1251 {
1252 if (!gui_scope) return;
1253 this->vscroll->SetCount(std::size(_news));
1254 }
1255
1256 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1257 {
1258 if (widget == WID_MH_BACKGROUND) {
1259 /* Scheduled window invalidations currently occur after the input loop, which means the scrollbar count
1260 * could be invalid, so ensure it's correct now. Potentially this means that item clicked on might be
1261 * different as well. */
1262 this->vscroll->SetCount(std::size(_news));
1263 auto ni = this->vscroll->GetScrolledItemFromWidget(_news, pt.y, this, widget, WidgetDimensions::scaled.framerect.top);
1264 if (ni == std::end(_news)) return;
1265
1266 ShowNewsMessage(ni);
1267 }
1268 }
1269
1270 void OnResize() override
1271 {
1272 this->vscroll->SetCapacityFromWidget(this, WID_MH_BACKGROUND, WidgetDimensions::scaled.framerect.Vertical());
1273 }
1274};
1275
1276static constexpr std::initializer_list<NWidgetPart> _nested_message_history = {
1277 NWidget(NWID_HORIZONTAL),
1278 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1279 NWidget(WWT_CAPTION, COLOUR_BROWN), SetStringTip(STR_MESSAGE_HISTORY, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1280 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1281 NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
1282 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1283 EndContainer(),
1284
1285 NWidget(NWID_HORIZONTAL),
1286 NWidget(WWT_PANEL, COLOUR_BROWN, WID_MH_BACKGROUND), SetMinimalSize(200, 125), SetToolTip(STR_MESSAGE_HISTORY_TOOLTIP), SetResize(1, 12), SetScrollbar(WID_MH_SCROLLBAR),
1287 EndContainer(),
1288 NWidget(NWID_VERTICAL),
1289 NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_MH_SCROLLBAR),
1290 NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
1291 EndContainer(),
1292 EndContainer(),
1293};
1294
1295static WindowDesc _message_history_desc(
1296 WDP_AUTO, "list_news", 400, 140,
1297 WC_MESSAGE_HISTORY, WC_NONE,
1298 {},
1299 _nested_message_history
1300);
1301
1303 void ShowMessageHistory()
1304{
1305 CloseWindowById(WC_MESSAGE_HISTORY, 0);
1306 new MessageHistoryWindow(_message_history_desc);
1307}
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
BaseBitSet::Set
constexpr Timpl & Set()
Set all bits.
Definition base_bitset_type.hpp:40
CommandCost
Common return value for all commands.
Definition command_type.h:24
EncodedString
Container for an encoded string, created by GetEncodedString.
Definition strings_type.h:98
EncodedString::GetDecodedString
std::string GetDecodedString() const
Decode the encoded string.
Definition strings.cpp:207
EncodedString::ReplaceParam
EncodedString ReplaceParam(size_t param, StringParameter &&value) const
Replace a parameter of this EncodedString.
Definition strings.cpp:150
EnumBitSet< NewsFlag, uint8_t >
IntervalTimer
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition timer.h:76
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition widget_type.h:237
NWidgetCore
Base class for a 'real' widget.
Definition widget_type.h:368
NWidgetCore::disp_flags
NWidgetDisplayFlags disp_flags
Flags that affect display and interaction with the widget.
Definition widget_type.h:399
NWidgetCore::SetString
void SetString(StringID string)
Set string of the nested widget.
Definition widget.cpp:1154
NWidgetLeaf
Leaf widget.
Definition widget_type.h:928
NWidgetResizeBase
Base class for a resizable nested widget.
Definition widget_type.h:299
NWidgetResizeBase::UpdateVerticalSize
bool UpdateVerticalSize(uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition widget.cpp:1120
NWidgetStacked
Stacked widgets, widgets all occupying the same space in the window.
Definition widget_type.h:521
NWidgetStacked::SetDisplayedPlane
bool SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition widget.cpp:1422
NWidgetViewport
Nested widget to display a viewport in a window.
Definition widget_type.h:694
NWidgetViewport::UpdateViewportCoordinates
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition widget.cpp:2402
NWidgetViewport::InitializeViewport
void InitializeViewport(Window *w, std::variant< TileIndex, VehicleID > focus, ZoomLevel zoom)
Initialize the viewport of the window.
Definition widget.cpp:2393
Scrollbar
Scrollbar data structure.
Definition widget_type.h:708
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition widget_type.h:792
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:891
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:2499
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:872
TimerGameCalendar
Timer that is increased every 27ms, and counts towards ticks / days / months / years.
Definition timer_game_calendar.h:28
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:32
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:40
WidgetDimensions::captiontext
RectPadding captiontext
Padding for text within caption widget.
Definition window_gui.h:49
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition window_gui.h:58
WidgetDimensions::hsep_wide
int hsep_wide
Wide horizontal spacing.
Definition window_gui.h:62
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:93
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::Execute
@ Execute
execute the given command
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:55
_current_company
CompanyID _current_company
Company currently doing an action.
Definition company_cmd.cpp:56
company_func.h
Functions related to companies.
DrawCompanyManagerFace
void DrawCompanyManagerFace(const CompanyManagerFace &cmf, Colours colour, const Rect &r)
Draws the face of a company manager's face.
Definition company_gui.cpp:1120
company_manager_face.h
Functionality related to the company manager's face.
OWNER_DEITY
static constexpr Owner OWNER_DEITY
The object is owned by a superuser / goal script.
Definition company_type.h:28
INVALID_OWNER
static constexpr Owner INVALID_OWNER
An invalid owner.
Definition company_type.h:30
engine_base.h
Base class for engines.
GetEngineInfoString
std::string GetEngineInfoString(EngineID engine)
Get a multi-line string with some technical data, describing the engine.
Definition engine_gui.cpp:296
GetEngineCategoryName
StringID GetEngineCategoryName(EngineID engine)
Return the category of an engine.
Definition engine_gui.cpp:40
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:326
engine_gui.h
Engine GUI functions, used by build_vehicle_gui and autoreplace_gui
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:239
EngineNameContext::PreviewNews
@ PreviewNews
Name is shown in exclusive preview or newspaper.
to_underlying
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23)
Definition enum_type.hpp:17
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:87
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.
CentreBounds
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
Definition geometry_type.hpp:26
GetStringHeight
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition gfx.cpp:712
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:894
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:665
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:38
GetStringMultiLineBoundingBox
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
Definition gfx.cpp:748
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:782
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition gfx.cpp:115
GetScaledSpriteSize
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
Definition widget.cpp:68
FontSize
FontSize
Available font sizes.
Definition gfx_type.h:248
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition gfx_type.h:250
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:249
FS_LARGE
@ FS_LARGE
Index of the large font in the font tables.
Definition gfx_type.h:251
SA_TOP
@ SA_TOP
Top align the text.
Definition gfx_type.h:393
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition gfx_type.h:390
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition gfx_type.h:398
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:307
FILLRECT_RECOLOUR
@ FILLRECT_RECOLOUR
Apply a recolour sprite to the screen content.
Definition gfx_type.h:347
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1219
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:1375
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition widget_type.h:1399
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:1332
SetStringTip
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
Definition widget_type.h:1240
SetAspect
constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags=AspectFlag::ResizeX)
Widget part function for setting the aspect ratio.
Definition widget_type.h:1410
SetTextStyle
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
Definition widget_type.h:1198
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition widget_type.h:1156
SetToolTip
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
Definition widget_type.h:1318
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1229
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1424
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:1187
SetAlignment
constexpr NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
Definition widget_type.h:1208
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1145
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:1387
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:1513
ShowCompanyGroupForVehicle
void ShowCompanyGroupForVehicle(const Vehicle *v)
Show the group window for the given vehicle.
Definition group_gui.cpp:1249
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:159
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:401
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
AddNewsItem
void AddNewsItem(EncodedString &&headline, NewsType type, NewsStyle style, NewsFlags flags, NewsReference ref1, NewsReference ref2, std::unique_ptr< NewsAllocatedData > &&data, AdviceType advice_type)
Add a new newsitem to be shown.
Definition news_gui.cpp:900
MoveToNextNewsItem
static void MoveToNextNewsItem()
Move to the next news item.
Definition news_gui.cpp:785
ShowTicker
static void ShowTicker(NewsIterator ni)
Show news item in the ticker.
Definition news_gui.cpp:705
DeleteNews
void DeleteNews(Tpredicate predicate)
Delete news items by predicate, and invalidate the message history if necessary.
Definition news_gui.cpp:980
ShowNewspaper
static void ShowNewspaper(const NewsItem *ni)
Open up an own newspaper window for the news item.
Definition news_gui.cpp:696
_news_type_data
static const NewsTypeData _news_type_data[]
Per-NewsType data.
Definition news_gui.cpp:322
MIN_NEWS_AMOUNT
static const uint MIN_NEWS_AMOUNT
preferred minimum amount of news messages.
Definition news_gui.cpp:47
CmdCustomNewsItem
CommandCost CmdCustomNewsItem(DoCommandFlags flags, NewsType type, CompanyID company, NewsReference reference, const EncodedString &text)
Create a new custom news item.
Definition news_gui.cpp:945
_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:1038
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:1027
GetReferenceTile
static TileIndex GetReferenceTile(const NewsReference &reference)
Get the position a news-reference is referencing.
Definition news_gui.cpp:89
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:1188
ShowLastNewsMessage
void ShowLastNewsMessage()
Show previous news item.
Definition news_gui.cpp:1138
MAX_NEWS_AMOUNT
static const uint MAX_NEWS_AMOUNT
Do not exceed this number of news messages.
Definition news_gui.cpp:48
SerialiseNewsReference
uint32_t SerialiseNewsReference(const NewsReference &reference)
Encode a NewsReference for serialisation, e.g.
Definition news_gui.cpp:920
DeleteInvalidEngineNews
void DeleteInvalidEngineNews()
Remove engine announcements for invalid engines.
Definition news_gui.cpp:1056
ReadyForNextNewsItem
static bool ReadyForNextNewsItem()
Are we ready to show another news item? Only if no newspaper is displayed.
Definition news_gui.cpp:741
DeleteNewsItem
static std::list< NewsItem >::iterator DeleteNewsItem(std::list< NewsItem >::iterator ni)
Delete a news item from the queue.
Definition news_gui.cpp:822
HideActiveNewsMessage
bool HideActiveNewsMessage()
Close active news message window.
Definition news_gui.cpp:1129
ShowMessageHistory
void ShowMessageHistory()
Display window with news messages history.
Definition news_gui.cpp:1303
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:1083
InitNewsItemStructs
void InitNewsItemStructs()
Initialize the news-items data structures.
Definition news_gui.cpp:714
MoveToNextTickerItem
static void MoveToNextTickerItem()
Move to the next ticker item.
Definition news_gui.cpp:750
DeleteVehicleNews
void DeleteVehicleNews(VehicleID vid, AdviceType advice_type)
Delete news with a given advice type about a vehicle.
Definition news_gui.cpp:1015
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:1109
_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
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:727
_news_window_layout
static WindowDesc * _news_window_layout[]
Window layouts for news items.
Definition news_gui.cpp:304
_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:29
NewsType::End
@ End
end-of-array marker
NewsIterator
NewsContainer::const_iterator NewsIterator
Iterator type for news items.
Definition news_type.h:175
NewsContainer
std::list< NewsItem > NewsContainer
Container type for storing news items.
Definition news_type.h:174
NewsStyle
NewsStyle
News Window Styles.
Definition news_type.h:77
NewsStyle::Normal
@ Normal
Normal news item. (Newspaper with text only)
AdviceType
AdviceType
Sub type of the NewsType::Advice to be able to remove specific news items.
Definition news_type.h:51
NewsReference
std::variant< std::monostate, TileIndex, VehicleID, StationID, IndustryID, TownID, EngineID > NewsReference
References to objects in news.
Definition news_type.h:74
NewsFlag::NoTransparency
@ NoTransparency
News item disables transparency in the viewport.
NewsFlag::VehicleParam0
@ VehicleParam0
String param 0 contains a vehicle ID. (special autoreplace behaviour)
NewsFlag::Shaded
@ Shaded
News item uses shaded colours.
NewsFlag::InColour
@ InColour
News item is shown in colour (otherwise it is shown in black & white).
NewsDisplay
NewsDisplay
News display options.
Definition news_type.h:100
NewsDisplay::Summary
@ Summary
Show ticker.
NewsDisplay::Full
@ Full
Show newspaper.
NewsDisplay::Off
@ Off
Only show a reminder in the status bar.
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_SHOW_GROUP_SEL
@ WID_N_SHOW_GROUP_SEL
Selector for showing vehicle group, which can be hidden.
Definition news_widget.h:35
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:42
WID_MH_BACKGROUND
@ WID_MH_BACKGROUND
Background of the window.
Definition news_widget.h:41
PC_GREY
static constexpr PixelColour PC_GREY
Grey palette colour.
Definition palette_func.h:98
PC_BLACK
static constexpr PixelColour PC_BLACK
Black palette colour.
Definition palette_func.h:96
PC_WHITE
static constexpr PixelColour PC_WHITE
White palette colour.
Definition palette_func.h:99
roadveh.h
Road vehicle states.
safeguards.h
A number of safeguards to prevent using unsafe methods.
GetSettingFromName
static const SettingDesc * GetSettingFromName(std::string_view name, const SettingTable &settings)
Given a name of setting, return a setting description from the table.
Definition settings.cpp:1640
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
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:2078
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:1618
station_base.h
Base classes/functions for stations.
IsNewsTickerShown
bool IsNewsTickerShown()
Checks whether the news ticker is currently being used.
Definition statusbar_gui.cpp:231
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:271
StrMakeValid
static void StrMakeValid(Builder &builder, StringConsumer &consumer, StringValidationSettings settings)
Copies the valid (UTF-8) characters from consumer to the builder.
Definition string.cpp:119
string_func.h
Functions related to low-level strings.
StringValidationSetting::ReplaceTabCrNlWithSpace
@ ReplaceTabCrNlWithSpace
Replace tabs ('\t'), carriage returns ('\r') and newlines (' ') with spaces.
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
strings_func.h
Functions related to OTTD's strings.
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition strings_type.h:27
BaseStation::xy
TileIndex xy
Base tile of the station.
Definition base_station_base.h:59
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition vehicle_type.h:51
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition settings_type.h:653
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition settings_type.h:650
CompanyNewsInformation
Data that needs to be stored for company news messages.
Definition news_type.h:162
CompanyNewsInformation::face
CompanyManagerFace face
The face of the president.
Definition news_type.h:168
CompanyNewsInformation::colour
Colours colour
The colour related to the company.
Definition news_type.h:169
CompanyNewsInformation::president_name
std::string president_name
The name of the president.
Definition news_type.h:164
Coord2D< int >
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:56
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:219
GUISettings::coloured_news_year
TimerGameCalendar::Year coloured_news_year
when does newspaper become coloured?
Definition settings_type.h:212
IntSettingDesc::Read
int32_t Read(const void *object) const
Read the integer from the the actual setting.
Definition settings.cpp:567
MessageHistoryWindow
Definition news_gui.cpp:1197
MessageHistoryWindow::date_width
int date_width
< Height of a single line in the news history window including spacing.
Definition news_gui.cpp:1199
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:1256
MessageHistoryWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition news_gui.cpp:1226
MessageHistoryWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition news_gui.cpp:1250
MessageHistoryWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition news_gui.cpp:1270
MessageHistoryWindow::vscroll
Scrollbar * vscroll
< Width needed for the date part.
Definition news_gui.cpp:1201
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:1211
NewsItem
Information about a single item of news.
Definition news_type.h:137
NewsItem::date
TimerGameCalendar::Date date
Calendar date to show for the news.
Definition news_type.h:139
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:149
NewsItem::type
NewsType type
Type of the news.
Definition news_type.h:141
NewsItem::headline
EncodedString headline
Headline of news.
Definition news_type.h:138
NewsItem::advice_type
AdviceType advice_type
The type of advice, to be able to remove specific advices later on.
Definition news_type.h:142
NewsItem::economy_date
TimerGameEconomy::Date economy_date
Economy date of the news item, never shown but used to calculate age.
Definition news_type.h:140
NewsItem::NewsItem
NewsItem(EncodedString &&headline, NewsType type, NewsStyle style, NewsFlags flags, NewsReference ref1, NewsReference ref2, std::unique_ptr< NewsAllocatedData > &&data, AdviceType advice_type)
Create a new newsitem to be shown.
Definition news_gui.cpp:870
NewsItem::flags
NewsFlags flags
Window style for the news.
Definition news_type.h:144
NewsItem::ref2
NewsReference ref2
Reference 2 to some object: Used for scrolling after clicking on the news, and for deleting the news ...
Definition news_type.h:147
NewsItem::ref1
NewsReference ref1
Reference 1 to some object: Used for a possible viewport, scrolling after clicking on the news,...
Definition news_type.h:146
NewsTypeData
Per-NewsType data.
Definition news_type.h:109
NewsTypeData::GetDisplay
NewsDisplay GetDisplay() const
Return the news display option.
Definition news_gui.cpp:348
NewsTypeData::name
const std::string_view name
Name.
Definition news_type.h:110
NewsTypeData::sound
const SoundFx sound
Sound.
Definition news_type.h:112
NewsTypeData::age
const uint8_t age
Maximum age of news items (in days)
Definition news_type.h:111
NewsWindow
Window class displaying a news item.
Definition news_gui.cpp:356
NewsWindow::chat_height
uint16_t chat_height
Height of the chat window.
Definition news_gui.cpp:357
NewsWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition news_gui.cpp:609
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:360
NewsWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition news_gui.cpp:509
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:437
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:431
NewsWindow::OnRealtimeTick
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition news_gui.cpp:641
NewsWindow::status_height
uint16_t status_height
Height of the status bar window.
Definition news_gui.cpp:358
NewsWindow::ni
const NewsItem * ni
News item to display.
Definition news_gui.cpp:359
NewsWindow::SetWindowTop
void SetWindowTop(int newtop)
Moves the window to a new top coordinate.
Definition news_gui.cpp:663
NewsWindow::GetWidgetString
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition news_gui.cpp:496
NewsWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition news_gui.cpp:632
NewsWindow::scroll_interval
const IntervalTimer< TimerWindow > scroll_interval
Scroll the news message slowly up from the bottom.
Definition news_gui.cpp:653
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:564
PoolID< uint32_t, struct VehicleIDTag, 0xFF000, 0xFFFFF >
Pool::PoolItem<&_industry_pool >::Get
static Titem * Get(auto index)
Returns Titem with given index.
Definition pool_type.hpp:387
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition pool_type.hpp:376
RectPadding::Horizontal
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition geometry_type.hpp:89
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition geometry_type.hpp:95
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:101
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition geometry_type.hpp:211
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition geometry_type.hpp:124
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition geometry_type.hpp:224
Rect::Expand
Rect Expand(int s) const
Copy and expand Rect by s pixels.
Definition geometry_type.hpp:179
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:921
SoundSettings::news_ticker
bool news_ticker
Play a ticker sound when a news item is published.
Definition settings_type.h:272
SoundSettings::news_full
bool news_full
Play sound effects associated to certain news types.
Definition settings_type.h:273
SpecializedStation< Station, false >::IsValidID
static bool IsValidID(auto index)
Tests whether given index is a valid index for station of this type.
Definition base_station_base.h:239
SpecializedStation< Station, false >::Get
static Station * Get(auto index)
Gets station with given index.
Definition base_station_base.h:248
SpecializedVehicle::From
static T * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition vehicle_base.h:1134
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:205
Vehicle::z_pos
int32_t z_pos
z coordinate.
Definition vehicle_base.h:267
Vehicle::y_pos
int32_t y_pos
y coordinate.
Definition vehicle_base.h:266
Vehicle::x_pos
int32_t x_pos
x coordinate.
Definition vehicle_base.h:265
WindowDesc
High level window description.
Definition window_gui.h:168
Window
Data structure for an opened window.
Definition window_gui.h:274
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:978
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:1102
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1807
Window::viewport
std::unique_ptr< ViewportData > viewport
Pointer to viewport data, if present.
Definition window_gui.h:319
Window::GetWidgetString
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:504
Window::resize
ResizeInfo resize
Resize information.
Definition window_gui.h:315
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1797
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition window_gui.h:317
Window::left
int left
x position of left edge of the window
Definition window_gui.h:310
Window::top
int top
y position of top edge of the window
Definition window_gui.h:311
Window::flags
WindowFlags flags
Window flags.
Definition window_gui.h:301
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:313
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition window_gui.h:313
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:312
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:303
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:2123
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:3432
vehicle_gui.h
Functions related to the vehicle's GUIs.
EIT_PREVIEW
@ EIT_PREVIEW
Vehicle drawn in preview window, news, ...
Definition vehicle_type.h:80
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition vehicle_type.h:26
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition vehicle_type.h:28
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition vehicle_type.h:27
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition vehicle_type.h:25
ScrollWindowToTile
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
Definition viewport.cpp:2581
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition viewport.cpp:2592
viewport_func.h
Functions related to (drawing on) viewports.
DrawCaption
void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, std::string_view str, StringAlignment align, FontSize fs)
Draw a caption bar.
Definition widget.cpp:718
WWT_INSET
@ WWT_INSET
Pressed (inset) panel, most commonly used as combo box text area.
Definition widget_type.h:40
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition widget_type.h:48
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:44
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:57
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:55
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:52
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:60
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:37
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition widget_type.h:59
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition widget_type.h:56
NWID_VIEWPORT
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition widget_type.h:73
NWID_LAYER
@ NWID_LAYER
Layered widgets, all visible together.
Definition widget_type.h:72
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:71
ShadeDimmed
@ ShadeDimmed
Display dimmed colours in the viewport.
Definition widget_type.h:339
ShadeGrey
@ ShadeGrey
Shade viewport to grey-scale.
Definition widget_type.h:338
NoTransparency
@ NoTransparency
Viewport is never transparent.
Definition widget_type.h:337
SZSP_NONE
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
Definition widget_type.h:506
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:1193
FindWindowByClass
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition window.cpp:1166
PositionNewsMessage
int PositionNewsMessage(Window *w)
(Re)position news message window at the screen.
Definition window.cpp:3487
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:3294
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition window.cpp:1151
window_func.h
Window functions not directly related to making/drawing windows.
WindowFlag::DisableVpScroll
@ DisableVpScroll
Window does not do autoscroll,.
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:144
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition window_gui.h:143
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:20
WC_NEWS_WINDOW
@ WC_NEWS_WINDOW
News window; Window numbers:
Definition window_type.h:253
WC_STATUS_BAR
@ WC_STATUS_BAR
Statusbar (at the bottom of your screen); Window numbers:
Definition window_type.h:69
WC_SEND_NETWORK_MSG
@ WC_SEND_NETWORK_MSG
Chatbox; Window numbers:
Definition window_type.h:514
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:50
WC_MESSAGE_HISTORY
@ WC_MESSAGE_HISTORY
News history list; Window numbers:
Definition window_type.h:277
zoom_func.h
Functions related to zooming.
ScaleZoomGUI
ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
Definition zoom_func.h:87
ZoomLevel::News
@ News
Default zoom level for the news messages.