OpenTTD Source: src/news_gui.cpp Source File

OpenTTD Source 14.0-beta3

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 "widgets/dropdown_func.h"
25 #include "statusbar_gui.h"
26 #include "company_manager_face.h"
27 #include "company_func.h"
28 #include "engine_base.h"
29 #include "engine_gui.h"
30 #include "core/geometry_func.hpp"
31 #include "command_func.h"
32 #include "company_base.h"
33 #include "settings_internal.h"
34 #include "group_gui.h"
35 #include "zoom_func.h"
36 #include "news_cmd.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 const NewsItem *_statusbar_news_item = nullptr;
48
49 static uint MIN_NEWS_AMOUNT = 30;
50 static uint MAX_NEWS_AMOUNT = 1 << 10;
51 static uint _total_news = 0;
52 static NewsItem *_oldest_news = nullptr;
53 NewsItem *_latest_news = nullptr;
54
61 static const NewsItem *_forced_news = nullptr;
62
64 static const NewsItem *_current_news = nullptr;
65
66
73 static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32_t ref)
74 {
75 switch (reftype) {
76 case NR_TILE: return (TileIndex)ref;
77 case NR_STATION: return Station::Get((StationID)ref)->xy;
78 case NR_INDUSTRY: return Industry::Get((IndustryID)ref)->location.tile + TileDiffXY(1, 1);
79 case NR_TOWN: return Town::Get((TownID)ref)->xy;
80 default: return INVALID_TILE;
81 }
82 }
83
84 /* Normal news items. */
85 static constexpr NWidgetPart _nested_normal_news_widgets[] = {
86 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
87 NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
88 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
89 NWidget(NWID_SPACER), SetFill(1, 0),
90 NWidget(NWID_VERTICAL),
91 NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_JUST_DATE_LONG, STR_NULL), SetTextStyle(TC_BLACK, FS_SMALL),
92 NWidget(NWID_SPACER), SetFill(0, 1),
93 EndContainer(),
94 EndContainer(),
95 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(428, 154), SetPadding(0, 5, 1, 5),
96 EndContainer(),
97 };
98
99 static WindowDesc _normal_news_desc(__FILE__, __LINE__,
100 WDP_MANUAL, nullptr, 0, 0,
101 WC_NEWS_WINDOW, WC_NONE,
102 0,
103 std::begin(_nested_normal_news_widgets), std::end(_nested_normal_news_widgets)
104 );
105
106 /* New vehicles news items. */
107 static constexpr NWidgetPart _nested_vehicle_news_widgets[] = {
108 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
109 NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
110 NWidget(NWID_VERTICAL),
111 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
112 NWidget(NWID_SPACER), SetFill(0, 1),
113 EndContainer(),
114 NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_VEH_TITLE), SetFill(1, 1), SetMinimalSize(419, 55), SetDataTip(STR_EMPTY, STR_NULL),
115 EndContainer(),
116 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_VEH_BKGND), SetPadding(0, 25, 1, 25),
117 NWidget(NWID_VERTICAL),
118 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_NAME), SetMinimalSize(369, 33), SetFill(1, 0),
119 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_SPR), SetMinimalSize(369, 32), SetFill(1, 0),
120 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_INFO), SetMinimalSize(369, 46), SetFill(1, 0),
121 EndContainer(),
122 EndContainer(),
123 EndContainer(),
124 };
125
126 static WindowDesc _vehicle_news_desc(__FILE__, __LINE__,
127 WDP_MANUAL, nullptr, 0, 0,
128 WC_NEWS_WINDOW, WC_NONE,
129 0,
130 std::begin(_nested_vehicle_news_widgets), std::end(_nested_vehicle_news_widgets)
131 );
132
133 /* Company news items. */
134 static constexpr NWidgetPart _nested_company_news_widgets[] = {
135 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
136 NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
137 NWidget(NWID_VERTICAL),
138 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
139 NWidget(NWID_SPACER), SetFill(0, 1),
140 EndContainer(),
141 NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_TITLE), SetFill(1, 1), SetMinimalSize(410, 20), SetDataTip(STR_EMPTY, STR_NULL),
142 EndContainer(),
143 NWidget(NWID_HORIZONTAL), SetPadding(0, 1, 1, 1),
144 NWidget(NWID_VERTICAL),
145 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MGR_FACE), SetMinimalSize(93, 119), SetPadding(2, 6, 2, 1),
146 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MGR_NAME), SetMinimalSize(93, 24), SetPadding(0, 0, 0, 1),
147 NWidget(NWID_SPACER), SetFill(0, 1),
148 EndContainer(),
149 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_COMPANY_MSG), SetFill(1, 1), SetMinimalSize(328, 150),
150 EndContainer(),
151 EndContainer(),
152 };
153
154 static WindowDesc _company_news_desc(__FILE__, __LINE__,
155 WDP_MANUAL, nullptr, 0, 0,
156 WC_NEWS_WINDOW, WC_NONE,
157 0,
158 std::begin(_nested_company_news_widgets), std::end(_nested_company_news_widgets)
159 );
160
161 /* Thin news items. */
162 static constexpr NWidgetPart _nested_thin_news_widgets[] = {
163 NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
164 NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
165 NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
166 NWidget(NWID_SPACER), SetFill(1, 0),
167 NWidget(NWID_VERTICAL),
168 NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_JUST_DATE_LONG, STR_NULL), SetTextStyle(TC_BLACK, FS_SMALL),
169 NWidget(NWID_SPACER), SetFill(0, 1),
170 EndContainer(),
171 EndContainer(),
172 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(428, 48), SetFill(1, 0), SetPadding(0, 5, 0, 5),
173 NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetMinimalSize(426, 70), SetPadding(1, 2, 2, 2),
174 EndContainer(),
175 };
176
177 static WindowDesc _thin_news_desc(__FILE__, __LINE__,
178 WDP_MANUAL, nullptr, 0, 0,
179 WC_NEWS_WINDOW, WC_NONE,
180 0,
181 std::begin(_nested_thin_news_widgets), std::end(_nested_thin_news_widgets)
182 );
183
184 /* Small news items. */
185 static constexpr NWidgetPart _nested_small_news_widgets[] = {
186 /* Caption + close box. The caption is no WWT_CAPTION as the window shall not be moveable and so on. */
187 NWidget(NWID_HORIZONTAL),
188 NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE, WID_N_CLOSEBOX),
189 NWidget(WWT_EMPTY, COLOUR_LIGHT_BLUE, WID_N_CAPTION), SetFill(1, 0),
190 NWidget(WWT_TEXTBTN, COLOUR_LIGHT_BLUE, WID_N_SHOW_GROUP), SetMinimalSize(14, 11), SetResize(1, 0),
191 SetDataTip(STR_NULL /* filled in later */, STR_NEWS_SHOW_VEHICLE_GROUP_TOOLTIP),
192 EndContainer(),
193
194 /* Main part */
195 NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_N_HEADLINE),
196 NWidget(WWT_INSET, COLOUR_LIGHT_BLUE, WID_N_INSET), SetPadding(2, 2, 2, 2),
197 NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetMinimalSize(274, 47), SetFill(1, 0),
198 EndContainer(),
199 NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(275, 20), SetFill(1, 0), SetPadding(0, 5, 0, 5),
200 EndContainer(),
201 };
202
203 static WindowDesc _small_news_desc(__FILE__, __LINE__,
204 WDP_MANUAL, nullptr, 0, 0,
205 WC_NEWS_WINDOW, WC_NONE,
206 0,
207 std::begin(_nested_small_news_widgets), std::end(_nested_small_news_widgets)
208 );
209
213 static WindowDesc *_news_window_layout[] = {
214 &_thin_news_desc,
215 &_small_news_desc,
216 &_normal_news_desc,
217 &_vehicle_news_desc,
218 &_company_news_desc,
219 };
220
221 WindowDesc *GetNewsWindowLayout(NewsFlag flags)
222 {
223 uint layout = GB(flags, NFB_WINDOW_LAYOUT, NFB_WINDOW_LAYOUT_COUNT);
224 assert(layout < lengthof(_news_window_layout));
225 return _news_window_layout[layout];
226 }
227
231 static NewsTypeData _news_type_data[] = {
232 /* name, age, sound, */
233 NewsTypeData("news_display.arrival_player", 60, SND_1D_APPLAUSE ),
234 NewsTypeData("news_display.arrival_other", 60, SND_1D_APPLAUSE ),
235 NewsTypeData("news_display.accident", 90, SND_BEGIN ),
236 NewsTypeData("news_display.accident_other", 90, SND_BEGIN ),
237 NewsTypeData("news_display.company_info", 60, SND_BEGIN ),
238 NewsTypeData("news_display.open", 90, SND_BEGIN ),
239 NewsTypeData("news_display.close", 90, SND_BEGIN ),
240 NewsTypeData("news_display.economy", 30, SND_BEGIN ),
241 NewsTypeData("news_display.production_player", 30, SND_BEGIN ),
242 NewsTypeData("news_display.production_other", 30, SND_BEGIN ),
243 NewsTypeData("news_display.production_nobody", 30, SND_BEGIN ),
244 NewsTypeData("news_display.advice", 150, SND_BEGIN ),
245 NewsTypeData("news_display.new_vehicles", 30, SND_1E_NEW_ENGINE),
246 NewsTypeData("news_display.acceptance", 90, SND_BEGIN ),
247 NewsTypeData("news_display.subsidies", 180, SND_BEGIN ),
248 NewsTypeData("news_display.general", 60, SND_BEGIN ),
249 };
250
251 static_assert(lengthof(_news_type_data) == NT_END);
252
257 NewsDisplay NewsTypeData::GetDisplay() const
258 {
259 const SettingDesc *sd = GetSettingFromName(this->name);
260 assert(sd != nullptr && sd->IsIntSetting());
261 return (NewsDisplay)sd->AsIntSetting()->Read(nullptr);
262 }
263
265 struct NewsWindow : Window {
266 uint16_t chat_height;
267 uint16_t status_height;
268 const NewsItem *ni;
269 static int duration;
270
271 NewsWindow(WindowDesc *desc, const NewsItem *ni) : Window(desc), ni(ni)
272 {
273 NewsWindow::duration = 16650;
274 const Window *w = FindWindowByClass(WC_SEND_NETWORK_MSG);
275 this->chat_height = (w != nullptr) ? w->height : 0;
276 this->status_height = FindWindowById(WC_STATUS_BAR, 0)->height;
277
278 this->flags |= WF_DISABLE_VP_SCROLL;
279
280 this->CreateNestedTree();
281
282 /* For company news with a face we have a separate headline in param[0] */
283 if (desc == &_company_news_desc) this->GetWidget<NWidgetCore>(WID_N_TITLE)->widget_data = this->ni->params[0].data;
284
285 NWidgetCore *nwid = this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP);
286 if (ni->reftype1 == NR_VEHICLE && nwid != nullptr) {
287 const Vehicle *v = Vehicle::Get(ni->ref1);
288 switch (v->type) {
289 case VEH_TRAIN:
290 nwid->widget_data = STR_TRAIN;
291 break;
292 case VEH_ROAD:
293 nwid->widget_data = RoadVehicle::From(v)->IsBus() ? STR_BUS : STR_LORRY;
294 break;
295 case VEH_SHIP:
296 nwid->widget_data = STR_SHIP;
297 break;
298 case VEH_AIRCRAFT:
299 nwid->widget_data = STR_PLANE;
300 break;
301 default:
302 break; // Do nothing
303 }
304 }
305
306 this->FinishInitNested(0);
307
308 /* Initialize viewport if it exists. */
309 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
310 if (nvp != nullptr) {
311 if (ni->reftype1 == NR_VEHICLE) {
312 nvp->InitializeViewport(this, static_cast<VehicleID>(ni->ref1), ScaleZoomGUI(ZOOM_LVL_NEWS));
313 } else {
314 nvp->InitializeViewport(this, GetReferenceTile(ni->reftype1, ni->ref1), ScaleZoomGUI(ZOOM_LVL_NEWS));
315 }
316 if (this->ni->flags & NF_NO_TRANSPARENT) nvp->disp_flags |= ND_NO_TRANSPARENCY;
317 if ((this->ni->flags & NF_INCOLOUR) == 0) {
318 nvp->disp_flags |= ND_SHADE_GREY;
319 } else if (this->ni->flags & NF_SHADE) {
320 nvp->disp_flags |= ND_SHADE_DIMMED;
321 }
322 }
323
324 PositionNewsMessage(this);
325 }
326
327 void DrawNewsBorder(const Rect &r) const
328 {
329 Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
330 GfxFillRect(ir, PC_WHITE);
331
332 ir = ir.Expand(1);
333 GfxFillRect( r.left, r.top, ir.left, r.bottom, PC_BLACK);
334 GfxFillRect(ir.right, r.top, r.right, r.bottom, PC_BLACK);
335 GfxFillRect( r.left, r.top, r.right, ir.top, PC_BLACK);
336 GfxFillRect( r.left, ir.bottom, r.right, r.bottom, PC_BLACK);
337 }
338
339 Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
340 {
341 Point pt = { 0, _screen.height };
342 return pt;
343 }
344
345 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
346 {
347 StringID str = STR_NULL;
348 switch (widget) {
349 case WID_N_CAPTION: {
350 /* Caption is not a real caption (so that the window cannot be moved)
351 * thus it doesn't get the default sizing of a caption. */
352 Dimension d2 = GetStringBoundingBox(STR_NEWS_MESSAGE_CAPTION);
353 d2.height += WidgetDimensions::scaled.captiontext.Vertical();
354 *size = maxdim(*size, d2);
355 return;
356 }
357
358 case WID_N_MGR_FACE:
359 *size = maxdim(*size, GetScaledSpriteSize(SPR_GRADIENT));
360 break;
361
362 case WID_N_MGR_NAME:
363 SetDParamStr(0, static_cast<const CompanyNewsInformation *>(this->ni->data.get())->president_name);
364 str = STR_JUST_RAW_STRING;
365 break;
366
367 case WID_N_MESSAGE:
368 CopyInDParam(this->ni->params);
369 str = this->ni->string_id;
370 break;
371
372 case WID_N_COMPANY_MSG:
373 str = this->GetCompanyMessageString();
374 break;
375
376 case WID_N_VEH_NAME:
377 case WID_N_VEH_TITLE:
378 str = this->GetNewVehicleMessageString(widget);
379 break;
380
381 case WID_N_VEH_INFO: {
382 assert(this->ni->reftype1 == NR_ENGINE);
383 EngineID engine = this->ni->ref1;
384 str = GetEngineInfoString(engine);
385 break;
386 }
387
388 case WID_N_SHOW_GROUP:
389 if (this->ni->reftype1 == NR_VEHICLE) {
390 Dimension d2 = GetStringBoundingBox(this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP)->widget_data);
391 d2.height += WidgetDimensions::scaled.captiontext.Vertical();
392 d2.width += WidgetDimensions::scaled.captiontext.Horizontal();
393 *size = d2;
394 } else {
395 /* Hide 'Show group window' button if this news is not about a vehicle. */
396 size->width = 0;
397 size->height = 0;
398 resize->width = 0;
399 resize->height = 0;
400 fill->width = 0;
401 fill->height = 0;
402 }
403 return;
404
405 default:
406 return; // Do nothing
407 }
408
409 /* Update minimal size with length of the multi-line string. */
410 Dimension d = *size;
411 d.width = (d.width >= padding.width) ? d.width - padding.width : 0;
412 d.height = (d.height >= padding.height) ? d.height - padding.height : 0;
413 d = GetStringMultiLineBoundingBox(str, d);
414 d.width += padding.width;
415 d.height += padding.height;
416 *size = maxdim(*size, d);
417 }
418
419 void SetStringParameters(WidgetID widget) const override
420 {
421 if (widget == WID_N_DATE) SetDParam(0, this->ni->date);
422 }
423
424 void DrawWidget(const Rect &r, WidgetID widget) const override
425 {
426 switch (widget) {
427 case WID_N_CAPTION:
428 DrawCaption(r, COLOUR_LIGHT_BLUE, this->owner, TC_FROMSTRING, STR_NEWS_MESSAGE_CAPTION, SA_CENTER, FS_NORMAL);
429 break;
430
431 case WID_N_PANEL:
432 this->DrawNewsBorder(r);
433 break;
434
435 case WID_N_MESSAGE:
436 CopyInDParam(this->ni->params);
437 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->ni->string_id, TC_FROMSTRING, SA_CENTER);
438 break;
439
440 case WID_N_MGR_FACE: {
441 const CompanyNewsInformation *cni = static_cast<const CompanyNewsInformation*>(this->ni->data.get());
442 DrawCompanyManagerFace(cni->face, cni->colour, r);
443 GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
444 break;
445 }
446 case WID_N_MGR_NAME: {
447 const CompanyNewsInformation *cni = static_cast<const CompanyNewsInformation*>(this->ni->data.get());
448 SetDParamStr(0, cni->president_name);
449 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, STR_JUST_RAW_STRING, TC_FROMSTRING, SA_CENTER);
450 break;
451 }
452 case WID_N_COMPANY_MSG:
453 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->GetCompanyMessageString(), TC_FROMSTRING, SA_CENTER);
454 break;
455
456 case WID_N_VEH_BKGND:
457 GfxFillRect(r.left, r.top, r.right, r.bottom, PC_GREY);
458 break;
459
460 case WID_N_VEH_NAME:
461 case WID_N_VEH_TITLE:
462 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->GetNewVehicleMessageString(widget), TC_FROMSTRING, SA_CENTER);
463 break;
464
465 case WID_N_VEH_SPR: {
466 assert(this->ni->reftype1 == NR_ENGINE);
467 EngineID engine = this->ni->ref1;
468 DrawVehicleEngine(r.left, r.right, CenterBounds(r.left, r.right, 0), CenterBounds(r.top, r.bottom, 0), engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
469 GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
470 break;
471 }
472 case WID_N_VEH_INFO: {
473 assert(this->ni->reftype1 == NR_ENGINE);
474 EngineID engine = this->ni->ref1;
475 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
476 break;
477 }
478 }
479 }
480
481 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
482 {
483 switch (widget) {
484 case WID_N_CLOSEBOX:
485 NewsWindow::duration = 0;
486 this->Close();
487 _forced_news = nullptr;
488 break;
489
490 case WID_N_CAPTION:
491 if (this->ni->reftype1 == NR_VEHICLE) {
492 const Vehicle *v = Vehicle::Get(this->ni->ref1);
493 ShowVehicleViewWindow(v);
494 }
495 break;
496
497 case WID_N_VIEWPORT:
498 break; // Ignore clicks
499
500 case WID_N_SHOW_GROUP:
501 if (this->ni->reftype1 == NR_VEHICLE) {
502 const Vehicle *v = Vehicle::Get(this->ni->ref1);
503 ShowCompanyGroupForVehicle(v);
504 }
505 break;
506 default:
507 if (this->ni->reftype1 == NR_VEHICLE) {
508 const Vehicle *v = Vehicle::Get(this->ni->ref1);
509 ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos);
510 } else {
511 TileIndex tile1 = GetReferenceTile(this->ni->reftype1, this->ni->ref1);
512 TileIndex tile2 = GetReferenceTile(this->ni->reftype2, this->ni->ref2);
513 if (_ctrl_pressed) {
514 if (tile1 != INVALID_TILE) ShowExtraViewportWindow(tile1);
515 if (tile2 != INVALID_TILE) ShowExtraViewportWindow(tile2);
516 } else {
517 if ((tile1 == INVALID_TILE || !ScrollMainWindowToTile(tile1)) && tile2 != INVALID_TILE) {
518 ScrollMainWindowToTile(tile2);
519 }
520 }
521 }
522 break;
523 }
524 }
525
526 void OnResize() override
527 {
528 if (this->viewport != nullptr) {
529 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
530 nvp->UpdateViewportCoordinates(this);
531
532 if (ni->reftype1 != NR_VEHICLE) {
533 ScrollWindowToTile(GetReferenceTile(ni->reftype1, ni->ref1), this, true); // Re-center viewport.
534 }
535 }
536 }
537
543 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
544 {
545 if (!gui_scope) return;
546 /* The chatbar has notified us that is was either created or closed */
547 int newtop = this->top + this->chat_height - data;
548 this->chat_height = data;
549 this->SetWindowTop(newtop);
550 }
551
552 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
553 {
554 /* Decrement the news timer. We don't need to action an elapsed event here,
555 * so no need to use TimerElapsed(). */
556 if (NewsWindow::duration > 0) NewsWindow::duration -= delta_ms;
557 }
558
564 IntervalTimer<TimerWindow> scroll_interval = {std::chrono::milliseconds(210) / GetCharacterHeight(FS_NORMAL), [this](uint count) {
565 int newtop = std::max(this->top - 2 * static_cast<int>(count), _screen.height - this->height - this->status_height - this->chat_height);
566 this->SetWindowTop(newtop);
567 }};
568
569 private:
574 void SetWindowTop(int newtop)
575 {
576 if (this->top == newtop) return;
577
578 int mintop = std::min(newtop, this->top);
579 int maxtop = std::max(newtop, this->top);
580 if (this->viewport != nullptr) this->viewport->top += newtop - this->top;
581 this->top = newtop;
582
583 AddDirtyBlock(this->left, mintop, this->left + this->width, maxtop + this->height);
584 }
585
586 StringID GetCompanyMessageString() const
587 {
588 /* Company news with a face have a separate headline, so the normal message is shifted by two params */
589 CopyInDParam(std::span(this->ni->params.data() + 2, this->ni->params.size() - 2));
590 return this->ni->params[1].data;
591 }
592
593 StringID GetNewVehicleMessageString(WidgetID widget) const
594 {
595 assert(this->ni->reftype1 == NR_ENGINE);
596 EngineID engine = this->ni->ref1;
597
598 switch (widget) {
599 case WID_N_VEH_TITLE:
600 SetDParam(0, GetEngineCategoryName(engine));
601 return STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE;
602
603 case WID_N_VEH_NAME:
604 SetDParam(0, PackEngineNameDParam(engine, EngineNameContext::PreviewNews));
605 return STR_NEWS_NEW_VEHICLE_TYPE;
606
607 default:
608 NOT_REACHED();
609 }
610 }
611 };
612
613 /* static */ int NewsWindow::duration = 0; // Instance creation.
614
616 static void ShowNewspaper(const NewsItem *ni)
617 {
618 SoundFx sound = _news_type_data[ni->type].sound;
619 if (sound != 0 && _settings_client.sound.news_full) SndPlayFx(sound);
620
621 new NewsWindow(GetNewsWindowLayout(ni->flags), ni);
622 }
623
625 static void ShowTicker(const NewsItem *ni)
626 {
627 if (_settings_client.sound.news_ticker) SndPlayFx(SND_16_NEWS_TICKER);
628
629 _statusbar_news_item = ni;
630 InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_TICKER);
631 }
632
634 void InitNewsItemStructs()
635 {
636 for (NewsItem *ni = _oldest_news; ni != nullptr; ) {
637 NewsItem *next = ni->next;
638 delete ni;
639 ni = next;
640 }
641
642 _total_news = 0;
643 _oldest_news = nullptr;
644 _latest_news = nullptr;
645 _forced_news = nullptr;
646 _current_news = nullptr;
647 _statusbar_news_item = nullptr;
648 NewsWindow::duration = 0;
649 }
650
655 static bool ReadyForNextTickerItem()
656 {
657 const NewsItem *ni = _statusbar_news_item;
658 if (ni == nullptr) return true;
659
660 /* Ticker message
661 * Check if the status bar message is still being displayed? */
662 return !IsNewsTickerShown();
663 }
664
669 static bool ReadyForNextNewsItem()
670 {
671 const NewsItem *ni = _forced_news == nullptr ? _current_news : _forced_news;
672 if (ni == nullptr) return true;
673
674 /* neither newsticker nor newspaper are running */
675 return (NewsWindow::duration <= 0 || FindWindowById(WC_NEWS_WINDOW, 0) == nullptr);
676 }
677
679 static void MoveToNextTickerItem()
680 {
681 /* There is no status bar, so no reason to show news;
682 * especially important with the end game screen when
683 * there is no status bar but possible news. */
684 if (FindWindowById(WC_STATUS_BAR, 0) == nullptr) return;
685
686 /* if we're not at the last item, then move on */
687 while (_statusbar_news_item != _latest_news) {
688 _statusbar_news_item = (_statusbar_news_item == nullptr) ? _oldest_news : _statusbar_news_item->next;
689 const NewsItem *ni = _statusbar_news_item;
690 const NewsType type = ni->type;
691
692 /* check the date, don't show too old items */
693 if (TimerGameEconomy::date - _news_type_data[type].age > ni->economy_date) continue;
694
695 switch (_news_type_data[type].GetDisplay()) {
696 default: NOT_REACHED();
697 case ND_OFF: // Off - show nothing only a small reminder in the status bar
698 InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_REMINDER);
699 break;
700
701 case ND_SUMMARY: // Summary - show ticker
702 ShowTicker(ni);
703 break;
704
705 case ND_FULL: // Full - show newspaper, skipped here
706 continue;
707 }
708 return;
709 }
710 }
711
713 static void MoveToNextNewsItem()
714 {
715 /* There is no status bar, so no reason to show news;
716 * especially important with the end game screen when
717 * there is no status bar but possible news. */
718 if (FindWindowById(WC_STATUS_BAR, 0) == nullptr) return;
719
720 CloseWindowById(WC_NEWS_WINDOW, 0); // close the newspapers window if shown
721 _forced_news = nullptr;
722
723 /* if we're not at the last item, then move on */
724 while (_current_news != _latest_news) {
725 _current_news = (_current_news == nullptr) ? _oldest_news : _current_news->next;
726 const NewsItem *ni = _current_news;
727 const NewsType type = ni->type;
728
729 /* check the date, don't show too old items */
730 if (TimerGameEconomy::date - _news_type_data[type].age > ni->economy_date) continue;
731
732 switch (_news_type_data[type].GetDisplay()) {
733 default: NOT_REACHED();
734 case ND_OFF: // Off - show nothing only a small reminder in the status bar, skipped here
735 continue;
736
737 case ND_SUMMARY: // Summary - show ticker, skipped here
738 continue;
739
740 case ND_FULL: // Full - show newspaper
741 ShowNewspaper(ni);
742 break;
743 }
744 return;
745 }
746 }
747
749 static void DeleteNewsItem(NewsItem *ni)
750 {
751 /* Delete the news from the news queue. */
752 if (ni->prev != nullptr) {
753 ni->prev->next = ni->next;
754 } else {
755 assert(_oldest_news == ni);
756 _oldest_news = ni->next;
757 }
758
759 if (ni->next != nullptr) {
760 ni->next->prev = ni->prev;
761 } else {
762 assert(_latest_news == ni);
763 _latest_news = ni->prev;
764 }
765
766 _total_news--;
767
768 if (_forced_news == ni || _current_news == ni) {
769 /* When we're the current news, go to the previous item first;
770 * we just possibly made that the last news item. */
771 if (_current_news == ni) _current_news = ni->prev;
772
773 /* About to remove the currently forced item (shown as newspapers) ||
774 * about to remove the currently displayed item (newspapers) */
775 MoveToNextNewsItem();
776 }
777
778 if (_statusbar_news_item == ni) {
779 /* When we're the current news, go to the previous item first;
780 * we just possibly made that the last news item. */
781 _statusbar_news_item = ni->prev;
782
783 /* About to remove the currently displayed item (ticker, or just a reminder) */
784 InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); // invalidate the statusbar
785 MoveToNextTickerItem();
786 }
787
788 delete ni;
789
790 SetWindowDirty(WC_MESSAGE_HISTORY, 0);
791 }
792
806 NewsItem::NewsItem(StringID string_id, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, const NewsAllocatedData *data) :
807 string_id(string_id), date(TimerGameCalendar::date), economy_date(TimerGameEconomy::date), type(type), flags(flags), reftype1(reftype1), reftype2(reftype2), ref1(ref1), ref2(ref2), data(data)
808 {
809 /* show this news message in colour? */
810 if (TimerGameCalendar::year >= _settings_client.gui.coloured_news_year) this->flags |= NF_INCOLOUR;
811 CopyOutDParam(this->params, 10);
812 }
813
827 void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, const NewsAllocatedData *data)
828 {
829 if (_game_mode == GM_MENU) return;
830
831 /* Create new news item node */
832 NewsItem *ni = new NewsItem(string, type, flags, reftype1, ref1, reftype2, ref2, data);
833
834 if (_total_news++ == 0) {
835 assert(_oldest_news == nullptr);
836 _oldest_news = ni;
837 ni->prev = nullptr;
838 } else {
839 assert(_latest_news->next == nullptr);
840 _latest_news->next = ni;
841 ni->prev = _latest_news;
842 }
843
844 ni->next = nullptr;
845 _latest_news = ni;
846
847 /* Keep the number of stored news items to a managable number */
848 if (_total_news > MAX_NEWS_AMOUNT) {
849 DeleteNewsItem(_oldest_news);
850 }
851
852 SetWindowDirty(WC_MESSAGE_HISTORY, 0);
853 }
854
865 CommandCost CmdCustomNewsItem(DoCommandFlag flags, NewsType type, NewsReferenceType reftype1, CompanyID company, uint32_t reference, const std::string &text)
866 {
867 if (_current_company != OWNER_DEITY) return CMD_ERROR;
868
869 if (company != INVALID_OWNER && !Company::IsValidID(company)) return CMD_ERROR;
870 if (type >= NT_END) return CMD_ERROR;
871 if (text.empty()) return CMD_ERROR;
872
873 switch (reftype1) {
874 case NR_NONE: break;
875 case NR_TILE:
876 if (!IsValidTile(reference)) return CMD_ERROR;
877 break;
878
879 case NR_VEHICLE:
880 if (!Vehicle::IsValidID(reference)) return CMD_ERROR;
881 break;
882
883 case NR_STATION:
884 if (!Station::IsValidID(reference)) return CMD_ERROR;
885 break;
886
887 case NR_INDUSTRY:
888 if (!Industry::IsValidID(reference)) return CMD_ERROR;
889 break;
890
891 case NR_TOWN:
892 if (!Town::IsValidID(reference)) return CMD_ERROR;
893 break;
894
895 case NR_ENGINE:
896 if (!Engine::IsValidID(reference)) return CMD_ERROR;
897 break;
898
899 default: return CMD_ERROR;
900 }
901
902 if (company != INVALID_OWNER && company != _local_company) return CommandCost();
903
904 if (flags & DC_EXEC) {
905 NewsStringData *news = new NewsStringData(text);
906 SetDParamStr(0, news->string);
907 AddNewsItem(STR_NEWS_CUSTOM_ITEM, type, NF_NORMAL, reftype1, reference, NR_NONE, UINT32_MAX, news);
908 }
909
910 return CommandCost();
911 }
912
919 void DeleteVehicleNews(VehicleID vid, StringID news)
920 {
921 NewsItem *ni = _oldest_news;
922
923 while (ni != nullptr) {
924 NewsItem *next = ni->next;
925 if (((ni->reftype1 == NR_VEHICLE && ni->ref1 == vid) || (ni->reftype2 == NR_VEHICLE && ni->ref2 == vid)) &&
926 (news == INVALID_STRING_ID || ni->string_id == news)) {
927 DeleteNewsItem(ni);
928 }
929 ni = next;
930 }
931 }
932
938 void DeleteStationNews(StationID sid)
939 {
940 NewsItem *ni = _oldest_news;
941
942 while (ni != nullptr) {
943 NewsItem *next = ni->next;
944 if ((ni->reftype1 == NR_STATION && ni->ref1 == sid) || (ni->reftype2 == NR_STATION && ni->ref2 == sid)) {
945 DeleteNewsItem(ni);
946 }
947 ni = next;
948 }
949 }
950
955 void DeleteIndustryNews(IndustryID iid)
956 {
957 NewsItem *ni = _oldest_news;
958
959 while (ni != nullptr) {
960 NewsItem *next = ni->next;
961 if ((ni->reftype1 == NR_INDUSTRY && ni->ref1 == iid) || (ni->reftype2 == NR_INDUSTRY && ni->ref2 == iid)) {
962 DeleteNewsItem(ni);
963 }
964 ni = next;
965 }
966 }
967
971 void DeleteInvalidEngineNews()
972 {
973 NewsItem *ni = _oldest_news;
974
975 while (ni != nullptr) {
976 NewsItem *next = ni->next;
977 if ((ni->reftype1 == NR_ENGINE && (!Engine::IsValidID(ni->ref1) || !Engine::Get(ni->ref1)->IsEnabled())) ||
978 (ni->reftype2 == NR_ENGINE && (!Engine::IsValidID(ni->ref2) || !Engine::Get(ni->ref2)->IsEnabled()))) {
979 DeleteNewsItem(ni);
980 }
981 ni = next;
982 }
983 }
984
985 static void RemoveOldNewsItems()
986 {
987 NewsItem *next;
988 for (NewsItem *cur = _oldest_news; _total_news > MIN_NEWS_AMOUNT && cur != nullptr; cur = next) {
989 next = cur->next;
990 if (TimerGameEconomy::date - _news_type_data[cur->type].age * _settings_client.gui.news_message_timeout > cur->economy_date) DeleteNewsItem(cur);
991 }
992 }
993
1000 void ChangeVehicleNews(VehicleID from_index, VehicleID to_index)
1001 {
1002 for (NewsItem *ni = _oldest_news; ni != nullptr; ni = ni->next) {
1003 if (ni->reftype1 == NR_VEHICLE && ni->ref1 == from_index) ni->ref1 = to_index;
1004 if (ni->reftype2 == NR_VEHICLE && ni->ref2 == from_index) ni->ref2 = to_index;
1005 if (ni->flags & NF_VEHICLE_PARAM0 && ni->params[0].data == from_index) ni->params[0] = to_index;
1006 }
1007 }
1008
1009 void NewsLoop()
1010 {
1011 /* no news item yet */
1012 if (_total_news == 0) return;
1013
1014 static TimerGameEconomy::Month _last_clean_month = 0;
1015
1016 if (_last_clean_month != TimerGameEconomy::month) {
1017 RemoveOldNewsItems();
1018 _last_clean_month = TimerGameEconomy::month;
1019 }
1020
1021 if (ReadyForNextTickerItem()) MoveToNextTickerItem();
1022 if (ReadyForNextNewsItem()) MoveToNextNewsItem();
1023 }
1024
1026 static void ShowNewsMessage(const NewsItem *ni)
1027 {
1028 assert(_total_news != 0);
1029
1030 /* Delete the news window */
1031 CloseWindowById(WC_NEWS_WINDOW, 0);
1032
1033 /* setup forced news item */
1034 _forced_news = ni;
1035
1036 if (_forced_news != nullptr) {
1037 CloseWindowById(WC_NEWS_WINDOW, 0);
1038 ShowNewspaper(ni);
1039 }
1040 }
1041
1046 bool HideActiveNewsMessage()
1047 {
1048 NewsWindow *w = (NewsWindow*)FindWindowById(WC_NEWS_WINDOW, 0);
1049 if (w == nullptr) return false;
1050 w->Close();
1051 return true;
1052 }
1053
1055 void ShowLastNewsMessage()
1056 {
1057 const NewsItem *ni = nullptr;
1058 if (_total_news == 0) {
1059 return;
1060 } else if (_forced_news == nullptr) {
1061 /* Not forced any news yet, show the current one, unless a news window is
1062 * open (which can only be the current one), then show the previous item */
1063 if (_current_news == nullptr) {
1064 /* No news were shown yet resp. the last shown one was already deleted.
1065 * Threat this as if _forced_news reached _oldest_news; so, wrap around and start anew with the latest. */
1066 ni = _latest_news;
1067 } else {
1068 const Window *w = FindWindowById(WC_NEWS_WINDOW, 0);
1069 ni = (w == nullptr || (_current_news == _oldest_news)) ? _current_news : _current_news->prev;
1070 }
1071 } else if (_forced_news == _oldest_news) {
1072 /* We have reached the oldest news, start anew with the latest */
1073 ni = _latest_news;
1074 } else {
1075 /* 'Scrolling' through news history show each one in turn */
1076 ni = _forced_news->prev;
1077 }
1078 bool wrap = false;
1079 for (;;) {
1080 if (_news_type_data[ni->type].GetDisplay() != ND_OFF) {
1081 ShowNewsMessage(ni);
1082 break;
1083 }
1084
1085 ni = ni->prev;
1086 if (ni == nullptr) {
1087 if (wrap) break;
1088 /* We have reached the oldest news, start anew with the latest */
1089 ni = _latest_news;
1090 wrap = true;
1091 }
1092 }
1093 }
1094
1095
1105 static void DrawNewsString(uint left, uint right, int y, TextColour colour, const NewsItem *ni)
1106 {
1107 CopyInDParam(ni->params);
1108
1109 /* Get the string, replaces newlines with spaces and remove control codes from the string. */
1110 std::string message = StrMakeValid(GetString(ni->string_id), SVS_REPLACE_TAB_CR_NL_WITH_SPACE);
1111
1112 /* Truncate and show string; postfixed by '...' if necessary */
1113 DrawString(left, right, y, message, colour);
1114 }
1115
1116 struct MessageHistoryWindow : Window {
1117 int line_height;
1118 int date_width;
1119
1120 Scrollbar *vscroll;
1121
1122 MessageHistoryWindow(WindowDesc *desc) : Window(desc)
1123 {
1124 this->CreateNestedTree();
1125 this->vscroll = this->GetScrollbar(WID_MH_SCROLLBAR);
1126 this->FinishInitNested(); // Initializes 'this->line_height' and 'this->date_width'.
1127 this->OnInvalidateData(0);
1128 }
1129
1130 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
1131 {
1132 if (widget == WID_MH_BACKGROUND) {
1133 this->line_height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
1134 resize->height = this->line_height;
1135
1136 /* Months are off-by-one, so it's actually 8. Not using
1137 * month 12 because the 1 is usually less wide. */
1138 SetDParam(0, TimerGameCalendar::ConvertYMDToDate(CalendarTime::ORIGINAL_MAX_YEAR, 7, 30));
1139 this->date_width = GetStringBoundingBox(STR_JUST_DATE_TINY).width + WidgetDimensions::scaled.hsep_wide;
1140
1141 size->height = 4 * resize->height + WidgetDimensions::scaled.framerect.Vertical(); // At least 4 lines are visible.
1142 size->width = std::max(200u, size->width); // At least 200 pixels wide.
1143 }
1144 }
1145
1146 void OnPaint() override
1147 {
1148 this->OnInvalidateData(0);
1149 this->DrawWidgets();
1150 }
1151
1152 void DrawWidget(const Rect &r, WidgetID widget) const override
1153 {
1154 if (widget != WID_MH_BACKGROUND || _total_news == 0) return;
1155
1156 /* Find the first news item to display. */
1157 NewsItem *ni = _latest_news;
1158 for (int n = this->vscroll->GetPosition(); n > 0; n--) {
1159 ni = ni->prev;
1160 if (ni == nullptr) return;
1161 }
1162
1163 /* Fill the widget with news items. */
1164 bool rtl = _current_text_dir == TD_RTL;
1165 Rect news = r.Shrink(WidgetDimensions::scaled.framerect).Indent(this->date_width + WidgetDimensions::scaled.hsep_wide, rtl);
1166 Rect date = r.Shrink(WidgetDimensions::scaled.framerect).WithWidth(this->date_width, rtl);
1167 int y = news.top;
1168 for (int n = this->vscroll->GetCapacity(); n > 0; n--) {
1169 SetDParam(0, ni->date);
1170 DrawString(date.left, date.right, y, STR_JUST_DATE_TINY, TC_WHITE);
1171
1172 DrawNewsString(news.left, news.right, y, TC_WHITE, ni);
1173 y += this->line_height;
1174
1175 ni = ni->prev;
1176 if (ni == nullptr) return;
1177 }
1178 }
1179
1185 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1186 {
1187 if (!gui_scope) return;
1188 this->vscroll->SetCount(_total_news);
1189 }
1190
1191 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1192 {
1193 if (widget == WID_MH_BACKGROUND) {
1194 NewsItem *ni = _latest_news;
1195 if (ni == nullptr) return;
1196
1197 for (int n = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_MH_BACKGROUND, WidgetDimensions::scaled.framerect.top); n > 0; n--) {
1198 ni = ni->prev;
1199 if (ni == nullptr) return;
1200 }
1201
1202 ShowNewsMessage(ni);
1203 }
1204 }
1205
1206 void OnResize() override
1207 {
1208 this->vscroll->SetCapacityFromWidget(this, WID_MH_BACKGROUND);
1209 }
1210 };
1211
1212 static constexpr NWidgetPart _nested_message_history[] = {
1213 NWidget(NWID_HORIZONTAL),
1214 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1215 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_MESSAGE_HISTORY, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1216 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1217 NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
1218 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1219 EndContainer(),
1220
1221 NWidget(NWID_HORIZONTAL),
1222 NWidget(WWT_PANEL, COLOUR_BROWN, WID_MH_BACKGROUND), SetMinimalSize(200, 125), SetDataTip(0x0, STR_MESSAGE_HISTORY_TOOLTIP), SetResize(1, 12), SetScrollbar(WID_MH_SCROLLBAR),
1223 EndContainer(),
1224 NWidget(NWID_VERTICAL),
1225 NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_MH_SCROLLBAR),
1226 NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
1227 EndContainer(),
1228 EndContainer(),
1229 };
1230
1231 static WindowDesc _message_history_desc(__FILE__, __LINE__,
1232 WDP_AUTO, "list_news", 400, 140,
1233 WC_MESSAGE_HISTORY, WC_NONE,
1234 0,
1235 std::begin(_nested_message_history), std::end(_nested_message_history)
1236 );
1237
1239 void ShowMessageHistory()
1240 {
1241 CloseWindowById(WC_MESSAGE_HISTORY, 0);
1242 new MessageHistoryWindow(&_message_history_desc);
1243 }
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
GetEngineInfoString
StringID GetEngineInfoString(EngineID engine)
Get a multi-line string with some technical data, describing the engine.
Definition: engine_gui.cpp:273
AddNewsItem
void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, const NewsAllocatedData *data)
Add a new newsitem to be shown.
Definition: news_gui.cpp:827
NewsItem::NewsItem
NewsItem(StringID string_id, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, const NewsAllocatedData *data)
Create a new newsitem to be shown.
Definition: news_gui.cpp:806
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1141
WID_N_VEH_TITLE
@ WID_N_VEH_TITLE
Vehicle new title.
Definition: news_widget.h:29
NewsWindow::status_height
uint16_t status_height
Height of the status bar window.
Definition: news_gui.cpp:267
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:3200
EIT_PREVIEW
@ EIT_PREVIEW
Vehicle drawn in preview window, news, ...
Definition: vehicle_type.h:91
sound_func.h
CopyInDParam
void CopyInDParam(const std::span< const StringParameterBackup > backup)
Copy the parameters from the backup into the global string parameter array.
Definition: strings.cpp:159
news_cmd.h
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:938
Pool::PoolItem<&_industry_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:335
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2509
vehicle_gui.h
NewsItem::data
std::unique_ptr< const 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:142
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:1509
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3082
NR_TILE
@ NR_TILE
Reference tile. Scroll to tile when clicking on the news.
Definition: news_type.h:54
ShowExtraViewportWindow
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Definition: viewport_gui.cpp:156
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:269
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
command_func.h
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:1105
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:68
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:28
dropdown_func.h
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
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:1619
_news_window_layout
static WindowDesc * _news_window_layout[]
Window layouts for news items.
Definition: news_gui.cpp:213
statusbar_gui.h
NewsItem
Information about a single item of news.
Definition: news_type.h:128
company_base.h
WID_N_VEH_NAME
@ WID_N_VEH_NAME
Name of the new vehicle.
Definition: news_widget.h:31
WID_N_SHOW_GROUP
@ WID_N_SHOW_GROUP
Show vehicle's group.
Definition: news_widget.h:34
CompanyNewsInformation::president_name
std::string president_name
The name of the president.
Definition: news_type.h:163
timer_game_calendar.h
NWidgetViewport
Nested widget to display a viewport in a window.
Definition: widget_type.h:664
WID_N_MGR_NAME
@ WID_N_MGR_NAME
Name of the manager.
Definition: news_widget.h:28
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
NewsAllocatedData
Container for any custom data that must be deleted after the news item has reached end-of-life.
Definition: news_type.h:122
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
NewsTypeData
Per-NewsType data.
Definition: news_type.h:100
NWidgetViewport::InitializeViewport
void InitializeViewport(Window *w, std::variant< TileIndex, VehicleID > focus, ZoomLevel zoom)
Initialize the viewport of the window.
Definition: widget.cpp:2228
WF_DISABLE_VP_SCROLL
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
Definition: window_gui.h:229
PC_WHITE
static const uint8_t PC_WHITE
White palette colour.
Definition: palette_func.h:58
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:312
GetReferenceTile
static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32_t ref)
Get the position a news-reference is referencing.
Definition: news_gui.cpp:73
ND_SHADE_DIMMED
@ ND_SHADE_DIMMED
Bit value of the 'dimmed colours' flag.
Definition: widget_type.h:343
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition: widget_type.h:59
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:1141
NWidgetCore::widget_data
uint32_t widget_data
Data of the widget.
Definition: widget_type.h:379
FILLRECT_RECOLOUR
@ FILLRECT_RECOLOUR
Apply a recolour sprite to the screen content.
Definition: gfx_type.h:295
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:67
IntervalTimer< TimerWindow >
group_gui.h
GB
constexpr static debug_inline 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
company_manager_face.h
NewsItem::params
std::vector< StringParameterBackup > params
Parameters for string resolving.
Definition: news_type.h:144
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
NewsWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: news_gui.cpp:543
TimerGameEconomy::month
static Month month
Current month (0..11).
Definition: timer_game_economy.h:36
Viewport::top
int top
Screen coordinate top edge of the viewport.
Definition: viewport_type.h:24
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:865
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
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:1048
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1099
CompanyNewsInformation::colour
Colours colour
The colour related to the company.
Definition: news_type.h:167
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
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:114
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1151
ND_FULL
@ ND_FULL
Show newspaper.
Definition: news_type.h:94
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:37
GetEngineCategoryName
StringID GetEngineCategoryName(EngineID engine)
Return the category of an engine.
Definition: engine_gui.cpp:40
ShowMessageHistory
void ShowMessageHistory()
Display window with news messages history.
Definition: news_gui.cpp:1239
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
vehicle_base.h
WID_N_PANEL
@ WID_N_PANEL
Panel of the window.
Definition: news_widget.h:17
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:1000
zoom_func.h
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:2334
WC_MESSAGE_HISTORY
@ WC_MESSAGE_HISTORY
News history list; Window numbers:
Definition: window_type.h:272
WID_N_TITLE
@ WID_N_TITLE
Title of the company news.
Definition: news_widget.h:18
SpecializedStation< Station, false >::Get
static Station * Get(size_t index)
Gets station with given index.
Definition: base_station_base.h:259
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
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:250
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition: widget_type.h:50
WidgetDimensions::hsep_wide
int hsep_wide
Wide horizontal spacing.
Definition: window_gui.h:64
town.h
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition: window_gui.h:310
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:69
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
NFB_WINDOW_LAYOUT
@ NFB_WINDOW_LAYOUT
First bit for window layout.
Definition: news_type.h:70
NewsItem::reftype2
NewsReferenceType reftype2
Type of ref2.
Definition: news_type.h:138
NewsWindow::scroll_interval
IntervalTimer< TimerWindow > scroll_interval
Scroll the news message slowly up from the bottom.
Definition: news_gui.cpp:564
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
MessageHistoryWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: news_gui.cpp:1206
NewsItem::date
TimerGameCalendar::Date date
Calendar date to show for the news.
Definition: news_type.h:132
NewsWindow::SetWindowTop
void SetWindowTop(int newtop)
Moves the window to a new top coordinate.
Definition: news_gui.cpp:574
settings_internal.h
Rect::Expand
Rect Expand(int s) const
Copy and expand Rect by s pixels.
Definition: geometry_type.hpp:153
ScaleZoomGUI
ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
Definition: zoom_func.h:87
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:240
IsNewsTickerShown
bool IsNewsTickerShown()
Checks whether the news ticker is currently being used.
Definition: statusbar_gui.cpp:241
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
WID_N_INSET
@ WID_N_INSET
Inset around the viewport in the window. Only used in small news items.
Definition: news_widget.h:23
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:678
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:315
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:371
GetEnginePalette
PaletteID GetEnginePalette(EngineID engine_type, CompanyID company)
Get the colour map for an engine.
Definition: vehicle.cpp:2113
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1038
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:369
Scrollbar::GetPosition
uint16_t GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:720
Vehicle::x_pos
int32_t x_pos
x coordinate.
Definition: vehicle_base.h:299
SND_1E_NEW_ENGINE
@ SND_1E_NEW_ENGINE
28 == 0x1C News: new engine available
Definition: sound_type.h:67
MessageHistoryWindow::vscroll
Scrollbar * vscroll
< Width needed for the date part.
Definition: news_gui.cpp:1120
NR_ENGINE
@ NR_ENGINE
Reference engine.
Definition: news_type.h:59
NR_NONE
@ NR_NONE
Empty reference.
Definition: news_type.h:53
WID_N_MESSAGE
@ WID_N_MESSAGE
Space for displaying the message. Only used in small news items.
Definition: news_widget.h:26
NewsItem::flags
NewsFlag flags
NewsFlags bits.
Definition: news_type.h:135
NF_NO_TRANSPARENT
@ NF_NO_TRANSPARENT
Bit value for disabling transparency.
Definition: news_type.h:75
NewsTypeData::age
const byte age
Maximum age of news items (in days)
Definition: news_type.h:102
NewsTypeData::sound
const SoundFx sound
Sound.
Definition: news_type.h:103
WindowDesc
High level window description.
Definition: window_gui.h:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
NR_TOWN
@ NR_TOWN
Reference town. Scroll to town when clicking on the news.
Definition: news_type.h:58
RectPadding::Horizontal
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition: geometry_type.hpp:63
_total_news
static uint _total_news
current number of news items
Definition: news_gui.cpp:51
WID_N_VEH_SPR
@ WID_N_VEH_SPR
Graphical display of the new vehicle.
Definition: news_widget.h:32
NewsWindow
Window class displaying a news item.
Definition: news_gui.cpp:265
NT_END
@ NT_END
end-of-array marker
Definition: news_type.h:40
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:1188
NewsItem::type
NewsType type
Type of the news.
Definition: news_type.h:134
WID_N_COMPANY_MSG
@ WID_N_COMPANY_MSG
Message in company news items.
Definition: news_widget.h:25
PositionNewsMessage
int PositionNewsMessage(Window *w)
(Re)position news message window at the screen.
Definition: window.cpp:3392
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1086
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:141
DeleteVehicleNews
void DeleteVehicleNews(VehicleID vid, StringID news)
Delete a news item type about a vehicle.
Definition: news_gui.cpp:919
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:308
CommandCost
Common return value for all commands.
Definition: command_type.h:23
PreviewNews
@ PreviewNews
Name is shown in exclusive preview or newspaper.
Definition: engine_type.h:194
NWidgetViewport::UpdateViewportCoordinates
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition: widget.cpp:2237
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:639
WID_N_CAPTION
@ WID_N_CAPTION
Title bar of the window. Only used in small news items.
Definition: news_widget.h:22
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
TimerGameCalendar
Timer that is increased every 27ms, and counts towards ticks / days / months / years.
Definition: timer_game_calendar.h:30
NF_INCOLOUR
@ NF_INCOLOUR
Bit value for coloured news.
Definition: news_type.h:74
NWID_VIEWPORT
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition: widget_type.h:83
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1244
ShowCompanyGroupForVehicle
void ShowCompanyGroupForVehicle(const Vehicle *v)
Show the group window for the given vehicle.
Definition: group_gui.cpp:1143
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:306
NewsType
NewsType
Type of news.
Definition: news_type.h:23
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:199
WID_MH_SCROLLBAR
@ WID_MH_SCROLLBAR
Scrollbar for the list.
Definition: news_widget.h:41
WID_N_VIEWPORT
@ WID_N_VIEWPORT
Viewport in the window.
Definition: news_widget.h:24
SBI_NEWS_DELETED
@ SBI_NEWS_DELETED
abort current news display (active news were deleted)
Definition: statusbar_gui.h:19
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition: gfx_type.h:204
ScrollWindowToTile
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
Definition: viewport.cpp:2498
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
INVALID_OWNER
@ INVALID_OWNER
An invalid owner.
Definition: company_type.h:29
MIN_NEWS_AMOUNT
static uint MIN_NEWS_AMOUNT
preferred minimum amount of news messages
Definition: news_gui.cpp:49
NewsReferenceType
NewsReferenceType
References to objects in news.
Definition: news_type.h:52
NewsTypeData::name
const char *const name
Name.
Definition: news_type.h:101
SoundSettings::news_full
bool news_full
Play sound effects associated to certain news types.
Definition: settings_type.h:238
NewsWindow::OnRealtimeTick
void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
Called periodically.
Definition: news_gui.cpp:552
DeleteNewsItem
static void DeleteNewsItem(NewsItem *ni)
Delete a news item from the queue.
Definition: news_gui.cpp:749
MessageHistoryWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: news_gui.cpp:1146
PALETTE_NEWSPAPER
static const PaletteID PALETTE_NEWSPAPER
Recolour sprite for newspaper-greying.
Definition: sprites.h:1601
MoveToNextTickerItem
static void MoveToNextTickerItem()
Move to the next ticker item.
Definition: news_gui.cpp:679
MAX_NEWS_AMOUNT
static uint MAX_NEWS_AMOUNT
Do not exceed this number of news messages.
Definition: news_gui.cpp:50
Scrollbar::GetCapacity
uint16_t GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:711
TileDiffXY
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition: map_func.h:401
NewsStringData
Container for a single string to be passed as NewsAllocatedData.
Definition: news_type.h:150
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
NewsTypeData::GetDisplay
NewsDisplay GetDisplay() const
Return the news display option.
Definition: news_gui.cpp:257
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1258
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:49
WID_N_CLOSEBOX
@ WID_N_CLOSEBOX
Close the window.
Definition: news_widget.h:20
ShowTicker
static void ShowTicker(const NewsItem *ni)
Show news item in the ticker.
Definition: news_gui.cpp:625
industry.h
safeguards.h
timer.h
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:303
CopyOutDParam
void CopyOutDParam(std::vector< StringParameterBackup > &backup, size_t num)
Copy num string parameters from the global string parameter array to the backup.
Definition: strings.cpp:176
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:198
GUISettings::coloured_news_year
TimerGameCalendar::Year coloured_news_year
when does newspaper become coloured?
Definition: settings_type.h:177
NewsItem::string_id
StringID string_id
Message text.
Definition: news_type.h:131
NewsWindow::chat_height
uint16_t chat_height
Height of the chat window.
Definition: news_gui.cpp:266
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:185
NewsItem::prev
NewsItem * prev
Previous news item.
Definition: news_type.h:129
VehicleID
uint32_t VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
MessageHistoryWindow
Definition: news_gui.cpp:1116
ND_OFF
@ ND_OFF
Only show a reminder in the status bar.
Definition: news_type.h:92
GetStringMultiLineBoundingBox
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
Definition: gfx.cpp:741
NewsWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: news_gui.cpp:526
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
ScrollMainWindowTo
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
Definition: smallmap_gui.cpp:2007
_forced_news
static const NewsItem * _forced_news
Forced news item.
Definition: news_gui.cpp:61
CenterBounds
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition: gfx_func.h:166
DeleteIndustryNews
void DeleteIndustryNews(IndustryID iid)
Remove news regarding given industry.
Definition: news_gui.cpp:955
stdafx.h
NewsItem::next
NewsItem * next
Next news item.
Definition: news_type.h:130
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:296
SBI_SHOW_REMINDER
@ SBI_SHOW_REMINDER
show a reminder (dot on the right side of the statusbar)
Definition: statusbar_gui.h:18
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:113
SoundFx
SoundFx
Sound effects from baseset.
Definition: sound_type.h:37
viewport_func.h
NF_NORMAL
@ NF_NORMAL
Normal news item. (Newspaper with text only)
Definition: news_type.h:81
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
NewsDisplay
NewsDisplay
News display options.
Definition: news_type.h:91
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:140
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
WID_N_DATE
@ WID_N_DATE
Date of the news item.
Definition: news_widget.h:21
Vehicle::z_pos
int32_t z_pos
z coordinate.
Definition: vehicle_base.h:301
IsValidTile
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition: tile_map.h:161
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:2260
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:70
news_widget.h
ND_SUMMARY
@ ND_SUMMARY
Show ticker.
Definition: news_type.h:93
string_func.h
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:139
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:775
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:50
vehicle_func.h
station_base.h
CompanyNewsInformation
Data that needs to be stored for company news messages.
Definition: news_type.h:161
engine_gui.h
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1724
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
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
NWidgetCore::disp_flags
NWidgetDisplay disp_flags
Flags that affect display and interaction with the widget.
Definition: widget_type.h:376
WID_N_VEH_INFO
@ WID_N_VEH_INFO
Some technical data of the new vehicle.
Definition: news_widget.h:33
NewsWindow::ni
const NewsItem * ni
News item to display.
Definition: news_gui.cpp:268
ShowNewsMessage
static void ShowNewsMessage(const NewsItem *ni)
Do a forced show of a specific message.
Definition: news_gui.cpp:1026
SettingDesc
Properties of config file settings.
Definition: settings_internal.h:71
SpecializedVehicle< RoadVehicle, Type >::From
static RoadVehicle * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1201
ShowNewspaper
static void ShowNewspaper(const NewsItem *ni)
Open up an own newspaper window for the news item.
Definition: news_gui.cpp:616
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
geometry_func.hpp
CompanyNewsInformation::face
uint32_t face
The face of the president.
Definition: news_type.h:166
IntSettingDesc::Read
int32_t Read(const void *object) const
Read the integer from the the actual setting.
Definition: settings.cpp:577
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
WID_N_MGR_FACE
@ WID_N_MGR_FACE
Face of the manager.
Definition: news_widget.h:27
ShowLastNewsMessage
void ShowLastNewsMessage()
Show previous news item.
Definition: news_gui.cpp:1055
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition: window_gui.h:60
NewsItem::economy_date
TimerGameEconomy::Date economy_date
Economy date of the news item, never shown but used to calculate age.
Definition: news_type.h:133
MessageHistoryWindow::date_width
int date_width
< Height of a single line in the news history window including spacing.
Definition: news_gui.cpp:1118
NFB_WINDOW_LAYOUT_COUNT
@ NFB_WINDOW_LAYOUT_COUNT
Number of bits for window layout.
Definition: news_type.h:71
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:760
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:327
FindWindowByClass
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition: window.cpp:1114
PC_GREY
static const uint8_t PC_GREY
Grey palette colour.
Definition: palette_func.h:57
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:352
OWNER_DEITY
@ OWNER_DEITY
The object is owned by a superuser / goal script.
Definition: company_type.h:27
_current_news
static const NewsItem * _current_news
Current news item (last item shown regularly).
Definition: news_gui.cpp:64
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1734
BaseStation::xy
TileIndex xy
Base tile of the station.
Definition: base_station_base.h:65
MessageHistoryWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: news_gui.cpp:1185
PC_BLACK
static const uint8_t PC_BLACK
Black palette colour.
Definition: palette_func.h:55
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:81
GUISettings::news_message_timeout
byte news_message_timeout
how much longer than the news message "age" should we keep the message in the history
Definition: settings_type.h:184
company_func.h
WWT_INSET
@ WWT_INSET
Pressed (inset) panel, most commonly used as combo box text area.
Definition: widget_type.h:53
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:304
Vehicle::y_pos
int32_t y_pos
y coordinate.
Definition: vehicle_base.h:300
SoundSettings::news_ticker
bool news_ticker
Play a ticker sound when a news item is published.
Definition: settings_type.h:237
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
DrawCompanyManagerFace
void DrawCompanyManagerFace(CompanyManagerFace cmf, Colours colour, const Rect &r)
Draws the face of a company manager's face.
Definition: company_gui.cpp:1162
WC_SEND_NETWORK_MSG
@ WC_SEND_NETWORK_MSG
Chatbox; Window numbers:
Definition: window_type.h:503
ShowVehicleViewWindow
void ShowVehicleViewWindow(const Vehicle *v)
Shows the vehicle view window of the given vehicle.
Definition: vehicle_gui.cpp:3398
window_func.h
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition: gfx_type.h:348
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:300
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:305
_latest_news
NewsItem * _latest_news
tail of news items queue
Definition: news_gui.cpp:53
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1097
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:140
ReadyForNextNewsItem
static bool ReadyForNextNewsItem()
Are we ready to show another news item? Only if no newspaper is displayed.
Definition: news_gui.cpp:669
ZOOM_LVL_NEWS
@ ZOOM_LVL_NEWS
Default zoom level for the news messages.
Definition: zoom_type.h:32
NF_SHADE
@ NF_SHADE
Bit value for enabling shading.
Definition: news_type.h:76
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:658
timer_window.h
RoadVehicle::IsBus
bool IsBus() const
Check whether a roadvehicle is a bus.
Definition: roadveh_cmd.cpp:83
engine_base.h
HideActiveNewsMessage
bool HideActiveNewsMessage()
Close active news message window.
Definition: news_gui.cpp:1046
MoveToNextNewsItem
static void MoveToNextNewsItem()
Move to the next news item.
Definition: news_gui.cpp:713
ND_SHADE_GREY
@ ND_SHADE_GREY
Bit value of the 'shade to grey' flag.
Definition: widget_type.h:342
NewsStringData::string
std::string string
The string to retain.
Definition: news_type.h:151
NewsFlag
NewsFlag
Various OR-able news-item flags.
Definition: news_type.h:66
_oldest_news
static NewsItem * _oldest_news
head of news items queue
Definition: news_gui.cpp:52
_news_type_data
static NewsTypeData _news_type_data[]
Per-NewsType data.
Definition: news_gui.cpp:231
gui.h
EngineID
uint16_t EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
Window
Data structure for an opened window.
Definition: window_gui.h:267
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
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
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:324
WC_STATUS_BAR
@ WC_STATUS_BAR
Statusbar (at the bottom of your screen); Window numbers:
Definition: window_type.h:64
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:51
DeleteInvalidEngineNews
void DeleteInvalidEngineNews()
Remove engine announcements for invalid engines.
Definition: news_gui.cpp:971
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:731
WC_NEWS_WINDOW
@ WC_NEWS_WINDOW
News window; Window numbers:
Definition: window_type.h:248
SettingDesc::IsIntSetting
virtual bool IsIntSetting() const
Check whether this setting is an integer type setting.
Definition: settings_internal.h:96
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1162
GetScaledSpriteSize
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
Definition: widget.cpp:54
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:356
InitNewsItemStructs
void InitNewsItemStructs()
Initialize the news-items data structures.
Definition: news_gui.cpp:634
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
SND_1D_APPLAUSE
@ SND_1D_APPLAUSE
27 == 0x1B News: first vehicle at station
Definition: sound_type.h:66
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
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition: window_gui.h:42
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:679
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
SetTextStyle
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
Definition: widget_type.h:1120
TimerGameEconomy
Timer that is increased every 27ms, and counts towards economy time units, expressed in days / months...
Definition: timer_game_economy.h:33
TimerGame< struct Economy >::Month
uint8_t Month
Type for the month, note: 0 based, i.e.
Definition: timer_game_common.h:44
WID_MH_BACKGROUND
@ WID_MH_BACKGROUND
Background of the window.
Definition: news_widget.h:40
WID_N_VEH_BKGND
@ WID_N_VEH_BKGND
Dark background of new vehicle news.
Definition: news_widget.h:30
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:852
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
SBI_SHOW_TICKER
@ SBI_SHOW_TICKER
start scrolling news
Definition: statusbar_gui.h:17
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:57
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
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:636
NewsItem::reftype1
NewsReferenceType reftype1
Type of ref1.
Definition: news_type.h:137
SettingDesc::AsIntSetting
const struct IntSettingDesc * AsIntSetting() const
Get the setting description of this setting as an integer setting.
Definition: settings.cpp:910
SND_16_NEWS_TICKER
@ SND_16_NEWS_TICKER
20 == 0x14 News ticker
Definition: sound_type.h:59
ND_NO_TRANSPARENCY
@ ND_NO_TRANSPARENCY
Bit value of the 'no transparency' flag.
Definition: widget_type.h:341
roadveh.h
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:655
WidgetDimensions::captiontext
RectPadding captiontext
Padding for text within caption widget.
Definition: window_gui.h:51
TimerGameCalendar::year
static Year year
Current year, starting at 0.
Definition: timer_game_calendar.h:32
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:66
WID_N_HEADLINE
@ WID_N_HEADLINE
The news headline.
Definition: news_widget.h:19
TimerGameEconomy::date
static Date date
Current date in days (day counter).
Definition: timer_game_economy.h:37