OpenTTD Source  20240917-master-g9ab0a47812
news_gui.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #include "stdafx.h"
11 #include "gui.h"
12 #include "viewport_func.h"
13 #include "strings_func.h"
14 #include "window_func.h"
15 #include "vehicle_base.h"
16 #include "vehicle_func.h"
17 #include "vehicle_gui.h"
18 #include "roadveh.h"
19 #include "station_base.h"
20 #include "industry.h"
21 #include "town.h"
22 #include "sound_func.h"
23 #include "string_func.h"
24 #include "statusbar_gui.h"
25 #include "company_manager_face.h"
26 #include "company_func.h"
27 #include "engine_base.h"
28 #include "engine_gui.h"
29 #include "core/geometry_func.hpp"
30 #include "command_func.h"
31 #include "company_base.h"
32 #include "settings_internal.h"
33 #include "group_gui.h"
34 #include "zoom_func.h"
35 #include "news_cmd.h"
36 #include "timer/timer.h"
37 #include "timer/timer_window.h"
39 
40 #include "widgets/news_widget.h"
41 
42 #include "table/strings.h"
43 
44 #include "safeguards.h"
45 
46 static const uint MIN_NEWS_AMOUNT = 30;
47 static const uint MAX_NEWS_AMOUNT = 1U << 10;
48 
50 
57 static NewsIterator _forced_news = std::end(_news);
58 
60 static NewsIterator _current_news = std::end(_news);
61 
63 static NewsIterator _statusbar_news = std::end(_news);
64 
70 {
71  return (_statusbar_news == std::end(_news)) ? nullptr : &*_statusbar_news;
72 }
73 
79 {
80  return _news;
81 }
82 
89 static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32_t ref)
90 {
91  switch (reftype) {
92  case NR_TILE: return (TileIndex)ref;
93  case NR_STATION: return Station::Get((StationID)ref)->xy;
94  case NR_INDUSTRY: return Industry::Get((IndustryID)ref)->location.tile + TileDiffXY(1, 1);
95  case NR_TOWN: return Town::Get((TownID)ref)->xy;
96  default: return INVALID_TILE;
97  }
98 }
99 
100 /* Normal news items. */
101 static constexpr NWidgetPart _nested_normal_news_widgets[] = {
102  NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
103  NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
104  NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
105  NWidget(NWID_SPACER), SetFill(1, 0),
107  NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_JUST_DATE_LONG, STR_NULL), SetTextStyle(TC_BLACK, FS_SMALL),
108  NWidget(NWID_SPACER), SetFill(0, 1),
109  EndContainer(),
110  EndContainer(),
111  NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(428, 154), SetPadding(0, 5, 1, 5),
112  EndContainer(),
113 };
114 
115 static WindowDesc _normal_news_desc(
116  WDP_MANUAL, nullptr, 0, 0,
118  0,
119  _nested_normal_news_widgets
120 );
121 
122 /* New vehicles news items. */
123 static constexpr NWidgetPart _nested_vehicle_news_widgets[] = {
124  NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
125  NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
127  NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
128  NWidget(NWID_SPACER), SetFill(0, 1),
129  EndContainer(),
130  NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_VEH_TITLE), SetFill(1, 1), SetMinimalSize(419, 55), SetDataTip(STR_EMPTY, STR_NULL),
131  EndContainer(),
132  NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_VEH_BKGND), SetPadding(0, 25, 1, 25),
134  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_NAME), SetMinimalSize(369, 33), SetFill(1, 0),
135  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_SPR), SetMinimalSize(369, 32), SetFill(1, 0),
136  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_INFO), SetMinimalSize(369, 46), SetFill(1, 0),
137  EndContainer(),
138  EndContainer(),
139  EndContainer(),
140 };
141 
142 static WindowDesc _vehicle_news_desc(
143  WDP_MANUAL, nullptr, 0, 0,
145  0,
146  _nested_vehicle_news_widgets
147 );
148 
149 /* Company news items. */
150 static constexpr NWidgetPart _nested_company_news_widgets[] = {
151  NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
152  NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
154  NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
155  NWidget(NWID_SPACER), SetFill(0, 1),
156  EndContainer(),
157  NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_TITLE), SetFill(1, 1), SetMinimalSize(410, 20), SetDataTip(STR_EMPTY, STR_NULL),
158  EndContainer(),
159  NWidget(NWID_HORIZONTAL), SetPadding(0, 1, 1, 1),
161  NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MGR_FACE), SetMinimalSize(93, 119), SetPadding(2, 6, 2, 1),
162  NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MGR_NAME), SetMinimalSize(93, 24), SetPadding(0, 0, 0, 1),
163  NWidget(NWID_SPACER), SetFill(0, 1),
164  EndContainer(),
165  NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_COMPANY_MSG), SetFill(1, 1), SetMinimalSize(328, 150),
166  EndContainer(),
167  EndContainer(),
168 };
169 
170 static WindowDesc _company_news_desc(
171  WDP_MANUAL, nullptr, 0, 0,
173  0,
174  _nested_company_news_widgets
175 );
176 
177 /* Thin news items. */
178 static constexpr NWidgetPart _nested_thin_news_widgets[] = {
179  NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
180  NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
181  NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
182  NWidget(NWID_SPACER), SetFill(1, 0),
184  NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_JUST_DATE_LONG, STR_NULL), SetTextStyle(TC_BLACK, FS_SMALL),
185  NWidget(NWID_SPACER), SetFill(0, 1),
186  EndContainer(),
187  EndContainer(),
188  NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(428, 48), SetFill(1, 0), SetPadding(0, 5, 0, 5),
189  NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetMinimalSize(426, 70), SetPadding(1, 2, 2, 2),
190  EndContainer(),
191 };
192 
193 static WindowDesc _thin_news_desc(
194  WDP_MANUAL, nullptr, 0, 0,
196  0,
197  _nested_thin_news_widgets
198 );
199 
200 /* Small news items. */
201 static constexpr NWidgetPart _nested_small_news_widgets[] = {
202  /* Caption + close box. The caption is no WWT_CAPTION as the window shall not be moveable and so on. */
204  NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE, WID_N_CLOSEBOX),
205  NWidget(WWT_EMPTY, COLOUR_LIGHT_BLUE, WID_N_CAPTION), SetFill(1, 0),
206  NWidget(WWT_TEXTBTN, COLOUR_LIGHT_BLUE, WID_N_SHOW_GROUP), SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON), SetResize(1, 0),
207  SetDataTip(STR_NULL /* filled in later */, STR_NEWS_SHOW_VEHICLE_GROUP_TOOLTIP),
208  EndContainer(),
209 
210  /* Main part */
211  NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_N_HEADLINE),
212  NWidget(WWT_INSET, COLOUR_LIGHT_BLUE, WID_N_INSET), SetPadding(2, 2, 2, 2),
213  NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetMinimalSize(274, 47), SetFill(1, 0),
214  EndContainer(),
215  NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(275, 20), SetFill(1, 0), SetPadding(0, 5, 0, 5),
216  EndContainer(),
217 };
218 
219 static WindowDesc _small_news_desc(
220  WDP_MANUAL, nullptr, 0, 0,
222  0,
223  _nested_small_news_widgets
224 );
225 
230  &_thin_news_desc,
231  &_small_news_desc,
232  &_normal_news_desc,
233  &_vehicle_news_desc,
234  &_company_news_desc,
235 };
236 
237 WindowDesc &GetNewsWindowLayout(NewsFlag flags)
238 {
239  uint layout = GB(flags, NFB_WINDOW_LAYOUT, NFB_WINDOW_LAYOUT_COUNT);
240  assert(layout < lengthof(_news_window_layout));
241  return *_news_window_layout[layout];
242 }
243 
248  /* name, age, sound, */
249  NewsTypeData("news_display.arrival_player", 60, SND_1D_APPLAUSE ),
250  NewsTypeData("news_display.arrival_other", 60, SND_1D_APPLAUSE ),
251  NewsTypeData("news_display.accident", 90, SND_BEGIN ),
252  NewsTypeData("news_display.accident_other", 90, SND_BEGIN ),
253  NewsTypeData("news_display.company_info", 60, SND_BEGIN ),
254  NewsTypeData("news_display.open", 90, SND_BEGIN ),
255  NewsTypeData("news_display.close", 90, SND_BEGIN ),
256  NewsTypeData("news_display.economy", 30, SND_BEGIN ),
257  NewsTypeData("news_display.production_player", 30, SND_BEGIN ),
258  NewsTypeData("news_display.production_other", 30, SND_BEGIN ),
259  NewsTypeData("news_display.production_nobody", 30, SND_BEGIN ),
260  NewsTypeData("news_display.advice", 150, SND_BEGIN ),
261  NewsTypeData("news_display.new_vehicles", 30, SND_1E_NEW_ENGINE),
262  NewsTypeData("news_display.acceptance", 90, SND_BEGIN ),
263  NewsTypeData("news_display.subsidies", 180, SND_BEGIN ),
264  NewsTypeData("news_display.general", 60, SND_BEGIN ),
265 };
266 
267 static_assert(lengthof(_news_type_data) == NT_END);
268 
274 {
275  const SettingDesc *sd = GetSettingFromName(this->name);
276  assert(sd != nullptr && sd->IsIntSetting());
277  return (NewsDisplay)sd->AsIntSetting()->Read(nullptr);
278 }
279 
281 struct NewsWindow : Window {
282  uint16_t chat_height;
283  uint16_t status_height;
284  const NewsItem *ni;
285  static int duration;
286 
287  NewsWindow(WindowDesc &desc, const NewsItem *ni) : Window(desc), ni(ni)
288  {
289  NewsWindow::duration = 16650;
291  this->chat_height = (w != nullptr) ? w->height : 0;
292  this->status_height = FindWindowById(WC_STATUS_BAR, 0)->height;
293 
294  this->flags |= WF_DISABLE_VP_SCROLL;
295 
296  this->CreateNestedTree();
297 
298  /* For company news with a face we have a separate headline in param[0] */
299  if (&desc == &_company_news_desc) this->GetWidget<NWidgetCore>(WID_N_TITLE)->widget_data = std::get<uint64_t>(this->ni->params[0]);
300 
301  NWidgetCore *nwid = this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP);
302  if (ni->reftype1 == NR_VEHICLE && nwid != nullptr) {
303  const Vehicle *v = Vehicle::Get(ni->ref1);
304  switch (v->type) {
305  case VEH_TRAIN:
306  nwid->widget_data = STR_TRAIN;
307  break;
308  case VEH_ROAD:
309  nwid->widget_data = RoadVehicle::From(v)->IsBus() ? STR_BUS : STR_LORRY;
310  break;
311  case VEH_SHIP:
312  nwid->widget_data = STR_SHIP;
313  break;
314  case VEH_AIRCRAFT:
315  nwid->widget_data = STR_PLANE;
316  break;
317  default:
318  break; // Do nothing
319  }
320  }
321 
322  this->FinishInitNested(0);
323 
324  /* Initialize viewport if it exists. */
325  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
326  if (nvp != nullptr) {
327  if (ni->reftype1 == NR_VEHICLE) {
328  nvp->InitializeViewport(this, static_cast<VehicleID>(ni->ref1), ScaleZoomGUI(ZOOM_LVL_NEWS));
329  } else {
331  }
332  if (this->ni->flags & NF_NO_TRANSPARENT) nvp->disp_flags |= ND_NO_TRANSPARENCY;
333  if ((this->ni->flags & NF_INCOLOUR) == 0) {
334  nvp->disp_flags |= ND_SHADE_GREY;
335  } else if (this->ni->flags & NF_SHADE) {
336  nvp->disp_flags |= ND_SHADE_DIMMED;
337  }
338  }
339 
340  PositionNewsMessage(this);
341  }
342 
343  void DrawNewsBorder(const Rect &r) const
344  {
345  Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
346  GfxFillRect(ir, PC_WHITE);
347 
348  ir = ir.Expand(1);
349  GfxFillRect( r.left, r.top, ir.left, r.bottom, PC_BLACK);
350  GfxFillRect(ir.right, r.top, r.right, r.bottom, PC_BLACK);
351  GfxFillRect( r.left, r.top, r.right, ir.top, PC_BLACK);
352  GfxFillRect( r.left, ir.bottom, r.right, r.bottom, PC_BLACK);
353  }
354 
355  Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
356  {
357  Point pt = { 0, _screen.height };
358  return pt;
359  }
360 
361  void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
362  {
363  StringID str = STR_NULL;
364  switch (widget) {
365  case WID_N_CAPTION: {
366  /* Caption is not a real caption (so that the window cannot be moved)
367  * thus it doesn't get the default sizing of a caption. */
368  Dimension d2 = GetStringBoundingBox(STR_NEWS_MESSAGE_CAPTION);
370  size = maxdim(size, d2);
371  return;
372  }
373 
374  case WID_N_MGR_FACE:
375  size = maxdim(size, GetScaledSpriteSize(SPR_GRADIENT));
376  break;
377 
378  case WID_N_MGR_NAME:
379  SetDParamStr(0, static_cast<const CompanyNewsInformation *>(this->ni->data.get())->president_name);
380  str = STR_JUST_RAW_STRING;
381  break;
382 
383  case WID_N_MESSAGE:
384  CopyInDParam(this->ni->params);
385  str = this->ni->string_id;
386  break;
387 
388  case WID_N_COMPANY_MSG:
389  str = this->GetCompanyMessageString();
390  break;
391 
392  case WID_N_VEH_NAME:
393  case WID_N_VEH_TITLE:
394  str = this->GetNewVehicleMessageString(widget);
395  break;
396 
397  case WID_N_VEH_INFO: {
398  assert(this->ni->reftype1 == NR_ENGINE);
399  EngineID engine = this->ni->ref1;
400  str = GetEngineInfoString(engine);
401  break;
402  }
403 
404  case WID_N_SHOW_GROUP:
405  if (this->ni->reftype1 == NR_VEHICLE) {
406  Dimension d2 = GetStringBoundingBox(this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP)->widget_data);
409  size = d2;
410  } else {
411  /* Hide 'Show group window' button if this news is not about a vehicle. */
412  size.width = 0;
413  size.height = 0;
414  resize.width = 0;
415  resize.height = 0;
416  fill.width = 0;
417  fill.height = 0;
418  }
419  return;
420 
421  default:
422  return; // Do nothing
423  }
424 
425  /* Update minimal size with length of the multi-line string. */
426  Dimension d = size;
427  d.width = (d.width >= padding.width) ? d.width - padding.width : 0;
428  d.height = (d.height >= padding.height) ? d.height - padding.height : 0;
429  d = GetStringMultiLineBoundingBox(str, d);
430  d.width += padding.width;
431  d.height += padding.height;
432  size = maxdim(size, d);
433  }
434 
435  void SetStringParameters(WidgetID widget) const override
436  {
437  if (widget == WID_N_DATE) SetDParam(0, this->ni->date);
438  }
439 
440  void DrawWidget(const Rect &r, WidgetID widget) const override
441  {
442  switch (widget) {
443  case WID_N_CAPTION:
444  DrawCaption(r, COLOUR_LIGHT_BLUE, this->owner, TC_FROMSTRING, STR_NEWS_MESSAGE_CAPTION, SA_CENTER, FS_NORMAL);
445  break;
446 
447  case WID_N_PANEL:
448  this->DrawNewsBorder(r);
449  break;
450 
451  case WID_N_MESSAGE:
452  CopyInDParam(this->ni->params);
453  DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->ni->string_id, TC_FROMSTRING, SA_CENTER);
454  break;
455 
456  case WID_N_MGR_FACE: {
457  const CompanyNewsInformation *cni = static_cast<const CompanyNewsInformation*>(this->ni->data.get());
458  DrawCompanyManagerFace(cni->face, cni->colour, r);
459  GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
460  break;
461  }
462  case WID_N_MGR_NAME: {
463  const CompanyNewsInformation *cni = static_cast<const CompanyNewsInformation*>(this->ni->data.get());
464  SetDParamStr(0, cni->president_name);
465  DrawStringMultiLine(r.left, r.right, r.top, r.bottom, STR_JUST_RAW_STRING, TC_FROMSTRING, SA_CENTER);
466  break;
467  }
468  case WID_N_COMPANY_MSG:
469  DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->GetCompanyMessageString(), TC_FROMSTRING, SA_CENTER);
470  break;
471 
472  case WID_N_VEH_BKGND:
473  GfxFillRect(r.left, r.top, r.right, r.bottom, PC_GREY);
474  break;
475 
476  case WID_N_VEH_NAME:
477  case WID_N_VEH_TITLE:
478  DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->GetNewVehicleMessageString(widget), TC_FROMSTRING, SA_CENTER);
479  break;
480 
481  case WID_N_VEH_SPR: {
482  assert(this->ni->reftype1 == NR_ENGINE);
483  EngineID engine = this->ni->ref1;
484  DrawVehicleEngine(r.left, r.right, CenterBounds(r.left, r.right, 0), CenterBounds(r.top, r.bottom, 0), engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
485  GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
486  break;
487  }
488  case WID_N_VEH_INFO: {
489  assert(this->ni->reftype1 == NR_ENGINE);
490  EngineID engine = this->ni->ref1;
491  DrawStringMultiLine(r.left, r.right, r.top, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
492  break;
493  }
494  }
495  }
496 
497  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
498  {
499  switch (widget) {
500  case WID_N_CLOSEBOX:
502  this->Close();
503  _forced_news = std::end(_news);
504  break;
505 
506  case WID_N_CAPTION:
507  if (this->ni->reftype1 == NR_VEHICLE) {
508  const Vehicle *v = Vehicle::Get(this->ni->ref1);
510  }
511  break;
512 
513  case WID_N_VIEWPORT:
514  break; // Ignore clicks
515 
516  case WID_N_SHOW_GROUP:
517  if (this->ni->reftype1 == NR_VEHICLE) {
518  const Vehicle *v = Vehicle::Get(this->ni->ref1);
520  }
521  break;
522  default:
523  if (this->ni->reftype1 == NR_VEHICLE) {
524  const Vehicle *v = Vehicle::Get(this->ni->ref1);
525  ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos);
526  } else {
527  TileIndex tile1 = GetReferenceTile(this->ni->reftype1, this->ni->ref1);
528  TileIndex tile2 = GetReferenceTile(this->ni->reftype2, this->ni->ref2);
529  if (_ctrl_pressed) {
530  if (tile1 != INVALID_TILE) ShowExtraViewportWindow(tile1);
531  if (tile2 != INVALID_TILE) ShowExtraViewportWindow(tile2);
532  } else {
533  if ((tile1 == INVALID_TILE || !ScrollMainWindowToTile(tile1)) && tile2 != INVALID_TILE) {
534  ScrollMainWindowToTile(tile2);
535  }
536  }
537  }
538  break;
539  }
540  }
541 
542  void OnResize() override
543  {
544  if (this->viewport != nullptr) {
545  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
546  nvp->UpdateViewportCoordinates(this);
547 
548  if (ni->reftype1 != NR_VEHICLE) {
549  ScrollWindowToTile(GetReferenceTile(ni->reftype1, ni->ref1), this, true); // Re-center viewport.
550  }
551  }
552  }
553 
559  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
560  {
561  if (!gui_scope) return;
562  /* The chatbar has notified us that is was either created or closed */
563  int newtop = this->top + this->chat_height - data;
564  this->chat_height = data;
565  this->SetWindowTop(newtop);
566  }
567 
568  void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
569  {
570  /* Decrement the news timer. We don't need to action an elapsed event here,
571  * so no need to use TimerElapsed(). */
572  if (NewsWindow::duration > 0) NewsWindow::duration -= delta_ms;
573  }
574 
580  IntervalTimer<TimerWindow> scroll_interval = {std::chrono::milliseconds(210) / GetCharacterHeight(FS_NORMAL), [this](uint count) {
581  int newtop = std::max(this->top - 2 * static_cast<int>(count), _screen.height - this->height - this->status_height - this->chat_height);
582  this->SetWindowTop(newtop);
583  }};
584 
585 private:
590  void SetWindowTop(int newtop)
591  {
592  if (this->top == newtop) return;
593 
594  int mintop = std::min(newtop, this->top);
595  int maxtop = std::max(newtop, this->top);
596  if (this->viewport != nullptr) this->viewport->top += newtop - this->top;
597  this->top = newtop;
598 
599  AddDirtyBlock(this->left, mintop, this->left + this->width, maxtop + this->height);
600  }
601 
602  StringID GetCompanyMessageString() const
603  {
604  /* Company news with a face have a separate headline, so the normal message is shifted by two params */
605  CopyInDParam(std::span(this->ni->params.data() + 2, this->ni->params.size() - 2));
606  return std::get<uint64_t>(this->ni->params[1]);
607  }
608 
609  StringID GetNewVehicleMessageString(WidgetID widget) const
610  {
611  assert(this->ni->reftype1 == NR_ENGINE);
612  EngineID engine = this->ni->ref1;
613 
614  switch (widget) {
615  case WID_N_VEH_TITLE:
616  SetDParam(0, GetEngineCategoryName(engine));
617  return STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE;
618 
619  case WID_N_VEH_NAME:
621  return STR_NEWS_NEW_VEHICLE_TYPE;
622 
623  default:
624  NOT_REACHED();
625  }
626  }
627 };
628 
629 /* static */ int NewsWindow::duration = 0; // Instance creation.
630 
632 static void ShowNewspaper(const NewsItem *ni)
633 {
634  SoundFx sound = _news_type_data[ni->type].sound;
635  if (sound != 0 && _settings_client.sound.news_full) SndPlayFx(sound);
636 
637  new NewsWindow(GetNewsWindowLayout(ni->flags), ni);
638 }
639 
641 static void ShowTicker(NewsIterator ni)
642 {
644 
645  _statusbar_news = ni;
647 }
648 
651 {
652  _news.clear();
653  _forced_news = std::end(_news);
654  _current_news = std::end(_news);
655  _statusbar_news = std::end(_news);
657 }
658 
664 {
665  const NewsItem *ni = GetStatusbarNews();
666  if (ni == nullptr) return true;
667 
668  /* Ticker message
669  * Check if the status bar message is still being displayed? */
670  return !IsNewsTickerShown();
671 }
672 
677 static bool ReadyForNextNewsItem()
678 {
679  if (_forced_news == std::end(_news) && _current_news == std::end(_news)) return true;
680 
681  /* neither newsticker nor newspaper are running */
682  return (NewsWindow::duration <= 0 || FindWindowById(WC_NEWS_WINDOW, 0) == nullptr);
683 }
684 
686 static void MoveToNextTickerItem()
687 {
688  /* There is no status bar, so no reason to show news;
689  * especially important with the end game screen when
690  * there is no status bar but possible news. */
691  if (FindWindowById(WC_STATUS_BAR, 0) == nullptr) return;
692 
693  /* No news to move to. */
694  if (std::empty(_news)) return;
695 
696  /* if we're not at the latest item, then move on */
697  while (_statusbar_news != std::begin(_news)) {
698  --_statusbar_news;
699  const NewsType type = _statusbar_news->type;
700 
701  /* check the date, don't show too old items */
702  if (TimerGameEconomy::date - _news_type_data[type].age > _statusbar_news->economy_date) continue;
703 
704  switch (_news_type_data[type].GetDisplay()) {
705  default: NOT_REACHED();
706  case ND_OFF: // Off - show nothing only a small reminder in the status bar
708  return;
709 
710  case ND_SUMMARY: // Summary - show ticker
712  return;
713 
714  case ND_FULL: // Full - show newspaper, skipped here
715  break;;
716  }
717  }
718 }
719 
721 static void MoveToNextNewsItem()
722 {
723  /* There is no status bar, so no reason to show news;
724  * especially important with the end game screen when
725  * there is no status bar but possible news. */
726  if (FindWindowById(WC_STATUS_BAR, 0) == nullptr) return;
727 
728  CloseWindowById(WC_NEWS_WINDOW, 0); // close the newspapers window if shown
729  _forced_news = std::end(_news);
730 
731  /* No news to move to. */
732  if (std::empty(_news)) return;
733 
734  /* if we're not at the latest item, then move on */
735  while (_current_news != std::begin(_news)) {
736  --_current_news;
737  const NewsType type = _current_news->type;
738 
739  /* check the date, don't show too old items */
740  if (TimerGameEconomy::date - _news_type_data[type].age > _current_news->economy_date) continue;
741 
742  switch (_news_type_data[type].GetDisplay()) {
743  default: NOT_REACHED();
744  case ND_OFF: // Off - show nothing only a small reminder in the status bar, skipped here
745  break;
746 
747  case ND_SUMMARY: // Summary - show ticker, skipped here
748  break;;
749 
750  case ND_FULL: // Full - show newspaper
752  return;
753  }
754  }
755 }
756 
758 static std::list<NewsItem>::iterator DeleteNewsItem(std::list<NewsItem>::iterator ni)
759 {
760  bool updateCurrentNews = (_forced_news == ni || _current_news == ni);
761  bool updateStatusbarNews = (_statusbar_news == ni);
762 
763  if (updateCurrentNews) {
764  /* When we're the current news, go to the next older item first;
765  * we just possibly made that the last news item. */
766  if (_current_news == ni) ++_current_news;
767  if (_forced_news == ni) _forced_news = std::end(_news);
768  }
769 
770  if (updateStatusbarNews) {
771  /* When we're the current news, go to the next older item first;
772  * we just possibly made that the last news item. */
773  ++_statusbar_news;
774  }
775 
776  /* Delete the news from the news queue. */
777  ni = _news.erase(ni);
778 
779  if (updateCurrentNews) {
780  /* About to remove the currently forced item (shown as newspapers) ||
781  * about to remove the currently displayed item (newspapers) */
783  }
784 
785  if (updateStatusbarNews) {
786  /* About to remove the currently displayed item (ticker, or just a reminder) */
787  InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); // invalidate the statusbar
789  }
790 
791  return ni;
792 }
793 
807 NewsItem::NewsItem(StringID string_id, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, const NewsAllocatedData *data) :
808  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)
809 {
810  /* show this news message in colour? */
812  CopyOutDParam(this->params, 10);
813 }
814 
828 void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, const NewsAllocatedData *data)
829 {
830  if (_game_mode == GM_MENU) return;
831 
832  /* Create new news item node */
833  _news.emplace_front(string, type, flags, reftype1, ref1, reftype2, ref2, data);
834 
835  /* Keep the number of stored news items to a managable number */
836  if (std::size(_news) > MAX_NEWS_AMOUNT) {
837  DeleteNewsItem(std::prev(std::end(_news)));
838  }
839 
841 }
842 
853 CommandCost CmdCustomNewsItem(DoCommandFlag flags, NewsType type, NewsReferenceType reftype1, CompanyID company, uint32_t reference, const std::string &text)
854 {
855  if (_current_company != OWNER_DEITY) return CMD_ERROR;
856 
857  if (company != INVALID_OWNER && !Company::IsValidID(company)) return CMD_ERROR;
858  if (type >= NT_END) return CMD_ERROR;
859  if (text.empty()) return CMD_ERROR;
860 
861  switch (reftype1) {
862  case NR_NONE: break;
863  case NR_TILE:
864  if (!IsValidTile(reference)) return CMD_ERROR;
865  break;
866 
867  case NR_VEHICLE:
868  if (!Vehicle::IsValidID(reference)) return CMD_ERROR;
869  break;
870 
871  case NR_STATION:
872  if (!Station::IsValidID(reference)) return CMD_ERROR;
873  break;
874 
875  case NR_INDUSTRY:
876  if (!Industry::IsValidID(reference)) return CMD_ERROR;
877  break;
878 
879  case NR_TOWN:
880  if (!Town::IsValidID(reference)) return CMD_ERROR;
881  break;
882 
883  case NR_ENGINE:
884  if (!Engine::IsValidID(reference)) return CMD_ERROR;
885  break;
886 
887  default: return CMD_ERROR;
888  }
889 
890  if (company != INVALID_OWNER && company != _local_company) return CommandCost();
891 
892  if (flags & DC_EXEC) {
893  NewsStringData *news = new NewsStringData(text);
894  SetDParamStr(0, news->string);
895  AddNewsItem(STR_NEWS_CUSTOM_ITEM, type, NF_NORMAL, reftype1, reference, NR_NONE, UINT32_MAX, news);
896  }
897 
898  return CommandCost();
899 }
900 
906 template <size_t Tmin = 0, class Tpredicate>
907 void DeleteNews(Tpredicate predicate)
908 {
909  bool dirty = false;
910  for (auto it = std::rbegin(_news); it != std::rend(_news); /* nothing */) {
911  if constexpr (Tmin > 0) {
912  if (std::size(_news) <= Tmin) break;
913  }
914  if (predicate(*it)) {
915  it = std::make_reverse_iterator(DeleteNewsItem(std::prev(it.base())));
916  dirty = true;
917  } else {
918  ++it;
919  }
920  }
922 }
923 
931 {
932  DeleteNews([&](const auto &ni) {
933  return ((ni.reftype1 == NR_VEHICLE && ni.ref1 == vid) || (ni.reftype2 == NR_VEHICLE && ni.ref2 == vid)) && (news == INVALID_STRING_ID || ni.string_id == news);
934  });
935 }
936 
942 void DeleteStationNews(StationID sid)
943 {
944  DeleteNews([&](const auto &ni) {
945  return (ni.reftype1 == NR_STATION && ni.ref1 == sid) || (ni.reftype2 == NR_STATION && ni.ref2 == sid);
946  });
947 }
948 
953 void DeleteIndustryNews(IndustryID iid)
954 {
955  DeleteNews([&](const auto &ni) {
956  return (ni.reftype1 == NR_INDUSTRY && ni.ref1 == iid) || (ni.reftype2 == NR_INDUSTRY && ni.ref2 == iid);
957  });
958 }
959 
964 {
965  DeleteNews([](const auto &ni) {
966  return (ni.reftype1 == NR_ENGINE && (!Engine::IsValidID(ni.ref1) || !Engine::Get(ni.ref1)->IsEnabled())) ||
967  (ni.reftype2 == NR_ENGINE && (!Engine::IsValidID(ni.ref2) || !Engine::Get(ni.ref2)->IsEnabled()));
968  });
969 }
970 
971 static void RemoveOldNewsItems()
972 {
973  DeleteNews<MIN_NEWS_AMOUNT>([](const auto &ni) {
975  });
976 }
977 
984 void ChangeVehicleNews(VehicleID from_index, VehicleID to_index)
985 {
986  for (auto &ni : _news) {
987  if (ni.reftype1 == NR_VEHICLE && ni.ref1 == from_index) ni.ref1 = to_index;
988  if (ni.reftype2 == NR_VEHICLE && ni.ref2 == from_index) ni.ref2 = to_index;
989  if (ni.flags & NF_VEHICLE_PARAM0 && std::get<uint64_t>(ni.params[0]) == from_index) ni.params[0] = to_index;
990  }
991 }
992 
993 void NewsLoop()
994 {
995  /* no news item yet */
996  if (std::empty(_news)) return;
997 
998  static TimerGameEconomy::Month _last_clean_month = 0;
999 
1000  if (_last_clean_month != TimerGameEconomy::month) {
1001  RemoveOldNewsItems();
1002  _last_clean_month = TimerGameEconomy::month;
1003  }
1004 
1007 }
1008 
1011 {
1012  assert(!std::empty(_news));
1013 
1014  /* Delete the news window */
1016 
1017  /* setup forced news item */
1018  _forced_news = ni;
1019 
1020  if (_forced_news != std::end(_news)) {
1022  ShowNewspaper(&*ni);
1023  }
1024 }
1025 
1031 {
1032  NewsWindow *w = dynamic_cast<NewsWindow *>(FindWindowById(WC_NEWS_WINDOW, 0));
1033  if (w == nullptr) return false;
1034  w->Close();
1035  return true;
1036 }
1037 
1040 {
1041  if (std::empty(_news)) return;
1042 
1043  NewsIterator ni;
1044  if (_forced_news == std::end(_news)) {
1045  /* Not forced any news yet, show the current one, unless a news window is
1046  * open (which can only be the current one), then show the previous item */
1047  if (_current_news == std::end(_news)) {
1048  /* No news were shown yet resp. the last shown one was already deleted.
1049  * Treat this as if _forced_news reached the oldest news; so, wrap around and start anew with the latest. */
1050  ni = std::begin(_news);
1051  } else {
1052  const Window *w = FindWindowById(WC_NEWS_WINDOW, 0);
1053  ni = (w == nullptr || (std::next(_current_news) == std::end(_news))) ? _current_news : std::next(_current_news);
1054  }
1055  } else if (std::next(_forced_news) == std::end(_news)) {
1056  /* We have reached the oldest news, start anew with the latest */
1057  ni = std::begin(_news);
1058  } else {
1059  /* 'Scrolling' through news history show each one in turn */
1060  ni = std::next(_forced_news);
1061  }
1062  bool wrap = false;
1063  for (;;) {
1064  if (_news_type_data[ni->type].GetDisplay() != ND_OFF) {
1065  ShowNewsMessage(ni);
1066  break;
1067  }
1068 
1069  ++ni;
1070  if (ni == std::end(_news)) {
1071  if (wrap) break;
1072  /* We have reached the oldest news, start anew with the latest */
1073  ni = std::begin(_news);
1074  wrap = true;
1075  }
1076  }
1077 }
1078 
1079 
1089 static void DrawNewsString(uint left, uint right, int y, TextColour colour, const NewsItem *ni)
1090 {
1091  CopyInDParam(ni->params);
1092 
1093  /* Get the string, replaces newlines with spaces and remove control codes from the string. */
1095 
1096  /* Truncate and show string; postfixed by '...' if necessary */
1097  DrawString(left, right, y, message, colour);
1098 }
1099 
1101  int line_height;
1103 
1105 
1106  MessageHistoryWindow(WindowDesc &desc) : Window(desc)
1107  {
1108  this->CreateNestedTree();
1109  this->vscroll = this->GetScrollbar(WID_MH_SCROLLBAR);
1110  this->FinishInitNested(); // Initializes 'this->line_height' and 'this->date_width'.
1111  this->OnInvalidateData(0);
1112  }
1113 
1114  void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
1115  {
1116  if (widget == WID_MH_BACKGROUND) {
1118  resize.height = this->line_height;
1119 
1120  /* Months are off-by-one, so it's actually 8. Not using
1121  * month 12 because the 1 is usually less wide. */
1123  this->date_width = GetStringBoundingBox(STR_JUST_DATE_TINY).width + WidgetDimensions::scaled.hsep_wide;
1124 
1125  size.height = 4 * resize.height + WidgetDimensions::scaled.framerect.Vertical(); // At least 4 lines are visible.
1126  size.width = std::max(200u, size.width); // At least 200 pixels wide.
1127  }
1128  }
1129 
1130  void DrawWidget(const Rect &r, WidgetID widget) const override
1131  {
1132  if (widget != WID_MH_BACKGROUND || std::empty(_news)) return;
1133 
1134  /* Fill the widget with news items. */
1135  bool rtl = _current_text_dir == TD_RTL;
1136  Rect news = r.Shrink(WidgetDimensions::scaled.framerect).Indent(this->date_width + WidgetDimensions::scaled.hsep_wide, rtl);
1137  Rect date = r.Shrink(WidgetDimensions::scaled.framerect).WithWidth(this->date_width, rtl);
1138  int y = news.top;
1139 
1140  auto [first, last] = this->vscroll->GetVisibleRangeIterators(_news);
1141  for (auto ni = first; ni != last; ++ni) {
1142  SetDParam(0, ni->date);
1143  DrawString(date.left, date.right, y, STR_JUST_DATE_TINY, TC_WHITE);
1144 
1145  DrawNewsString(news.left, news.right, y, TC_WHITE, &*ni);
1146  y += this->line_height;
1147  }
1148  }
1149 
1155  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1156  {
1157  if (!gui_scope) return;
1158  this->vscroll->SetCount(std::size(_news));
1159  }
1160 
1161  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1162  {
1163  if (widget == WID_MH_BACKGROUND) {
1164  /* Scheduled window invalidations currently occur after the input loop, which means the scrollbar count
1165  * could be invalid, so ensure it's correct now. Potentially this means that item clicked on might be
1166  * different as well. */
1167  this->vscroll->SetCount(std::size(_news));
1168  auto ni = this->vscroll->GetScrolledItemFromWidget(_news, pt.y, this, widget, WidgetDimensions::scaled.framerect.top);
1169  if (ni == std::end(_news)) return;
1170 
1171  ShowNewsMessage(ni);
1172  }
1173  }
1174 
1175  void OnResize() override
1176  {
1177  this->vscroll->SetCapacityFromWidget(this, WID_MH_BACKGROUND, WidgetDimensions::scaled.framerect.Vertical());
1178  }
1179 };
1180 
1181 static constexpr NWidgetPart _nested_message_history[] = {
1183  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1184  NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_MESSAGE_HISTORY, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1185  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1186  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
1187  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1188  EndContainer(),
1189 
1191  NWidget(WWT_PANEL, COLOUR_BROWN, WID_MH_BACKGROUND), SetMinimalSize(200, 125), SetDataTip(0x0, STR_MESSAGE_HISTORY_TOOLTIP), SetResize(1, 12), SetScrollbar(WID_MH_SCROLLBAR),
1192  EndContainer(),
1194  NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_MH_SCROLLBAR),
1195  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
1196  EndContainer(),
1197  EndContainer(),
1198 };
1199 
1200 static WindowDesc _message_history_desc(
1201  WDP_AUTO, "list_news", 400, 140,
1203  0,
1204  _nested_message_history
1205 );
1206 
1209 {
1211  new MessageHistoryWindow(_message_history_desc);
1212 }
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:828
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:807
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1183
WID_N_VEH_TITLE
@ WID_N_VEH_TITLE
Vehicle new title.
Definition: news_widget.h:29
OWNER_DEITY
@ OWNER_DEITY
The object is owned by a superuser / goal script.
Definition: company_type.h:27
NewsWindow::status_height
uint16_t status_height
Height of the status bar window.
Definition: news_gui.cpp:283
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:3208
EIT_PREVIEW
@ EIT_PREVIEW
Vehicle drawn in preview window, news, ...
Definition: vehicle_type.h:84
sound_func.h
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:942
Pool::PoolItem<&_industry_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:339
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2512
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:140
AddDirtyBlock
void AddDirtyBlock(int left, int top, int right, int bottom)
Extend the internal _invalid_rect rectangle to contain the rectangle defined by the given parameters.
Definition: gfx.cpp:1486
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:285
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:1089
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
_forced_news
static NewsIterator _forced_news
Forced news item.
Definition: news_gui.cpp:57
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:1616
_news_window_layout
static WindowDesc * _news_window_layout[]
Window layouts for news items.
Definition: news_gui.cpp:229
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
statusbar_gui.h
NR_TILE
@ NR_TILE
Reference tile. Scroll to tile when clicking on the news.
Definition: news_type.h:54
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:161
timer_game_calendar.h
_news
static NewsContainer _news
List of news, with newest items at the start.
Definition: news_gui.cpp:49
NWidgetViewport
Nested widget to display a viewport in a window.
Definition: widget_type.h:682
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
INVALID_OWNER
@ INVALID_OWNER
An invalid owner.
Definition: company_type.h:29
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:2288
WF_DISABLE_VP_SCROLL
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
Definition: window_gui.h:238
NT_END
@ NT_END
end-of-array marker
Definition: news_type.h:40
PC_WHITE
static const uint8_t PC_WHITE
White palette colour.
Definition: palette_func.h:70
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:321
GetReferenceTile
static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32_t ref)
Get the position a news-reference is referencing.
Definition: news_gui.cpp:89
ND_SHADE_DIMMED
@ ND_SHADE_DIMMED
Bit value of the 'dimmed colours' flag.
Definition: widget_type.h:359
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:1140
NWidgetCore::widget_data
uint32_t widget_data
Data of the widget.
Definition: widget_type.h:395
FILLRECT_RECOLOUR
@ FILLRECT_RECOLOUR
Apply a recolour sprite to the screen content.
Definition: gfx_type.h:302
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
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
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:559
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
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:853
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:1047
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1098
CompanyNewsInformation::colour
Colours colour
The colour related to the company.
Definition: news_type.h:165
NewsItem::params
std::vector< StringParameterData > params
Parameters for string resolving.
Definition: news_type.h:142
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:107
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1193
_statusbar_news
static NewsIterator _statusbar_news
Current status bar news item.
Definition: news_gui.cpp:63
NewsContainer
std::list< NewsItem > NewsContainer
Container type for storing news items.
Definition: news_type.h:170
ND_FULL
@ ND_FULL
Show newspaper.
Definition: news_type.h:94
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:38
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:1208
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:260
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:984
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
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:2394
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:254
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:56
DeleteNewsItem
static std::list< NewsItem >::iterator DeleteNewsItem(std::list< NewsItem >::iterator ni)
Delete a news item from the queue.
Definition: news_gui.cpp:758
SpecializedStation< Station, false >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index is a valid index for station of this type.
Definition: base_station_base.h:245
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:319
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 > >
ShowNewsMessage
static void ShowNewsMessage(NewsIterator ni)
Do a forced show of a specific message.
Definition: news_gui.cpp:1010
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:136
NewsWindow::scroll_interval
IntervalTimer< TimerWindow > scroll_interval
Scroll the news message slowly up from the bottom.
Definition: news_gui.cpp:580
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:1175
NewsItem::date
TimerGameCalendar::Date date
Calendar date to show for the news.
Definition: news_type.h:130
NewsWindow::SetWindowTop
void SetWindowTop(int newtop)
Moves the window to a new top coordinate.
Definition: news_gui.cpp:590
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
GetStatusbarNews
const NewsItem * GetStatusbarNews()
Get pointer to the current status bar news item.
Definition: news_gui.cpp:69
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:244
NewsReferenceType
NewsReferenceType
References to objects in news.
Definition: news_type.h:52
IsNewsTickerShown
bool IsNewsTickerShown()
Checks whether the news ticker is currently being used.
Definition: statusbar_gui.cpp:241
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:696
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:314
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:376
GetEnginePalette
PaletteID GetEnginePalette(EngineID engine_type, CompanyID company)
Get the colour map for an engine.
Definition: vehicle.cpp:2142
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1077
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:374
ZOOM_LVL_NEWS
@ ZOOM_LVL_NEWS
Default zoom level for the news messages.
Definition: zoom_type.h:29
GetNews
const NewsContainer & GetNews()
Get read-only reference to all news items.
Definition: news_gui.cpp:78
Vehicle::x_pos
int32_t x_pos
x coordinate.
Definition: vehicle_base.h:304
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:1104
ShowTicker
static void ShowTicker(NewsIterator ni)
Show news item in the ticker.
Definition: news_gui.cpp:641
NR_TOWN
@ NR_TOWN
Reference town. Scroll to town when clicking on the news.
Definition: news_type.h:58
_current_news
static NewsIterator _current_news
Current news item (last item shown regularly).
Definition: news_gui.cpp:60
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:133
NF_NO_TRANSPARENT
@ NF_NO_TRANSPARENT
Bit value for disabling transparency.
Definition: news_type.h:75
NewsTypeData::sound
const SoundFx sound
Sound.
Definition: news_type.h:103
WindowDesc
High level window description.
Definition: window_gui.h:162
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
RectPadding::Horizontal
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition: geometry_type.hpp:63
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
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:281
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:1230
NewsItem::type
NewsType type
Type of the news.
Definition: news_type.h:132
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:3401
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1128
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:150
DeleteVehicleNews
void DeleteVehicleNews(VehicleID vid, StringID news)
Delete a news item type about a vehicle.
Definition: news_gui.cpp:930
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:317
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:2297
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:614
WID_N_CAPTION
@ WID_N_CAPTION
Title bar of the window. Only used in small news items.
Definition: news_widget.h:22
NewsIterator
NewsContainer::const_iterator NewsIterator
Iterator type for news items.
Definition: news_type.h:171
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:209
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:1286
ShowCompanyGroupForVehicle
void ShowCompanyGroupForVehicle(const Vehicle *v)
Show the group window for the given vehicle.
Definition: group_gui.cpp:1185
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:315
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:210
ScrollWindowToTile
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
Definition: viewport.cpp:2501
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
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:246
NewsWindow::OnRealtimeTick
void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
Called periodically.
Definition: news_gui.cpp:568
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
PALETTE_NEWSPAPER
static const PaletteID PALETTE_NEWSPAPER
Recolour sprite for newspaper-greying.
Definition: sprites.h:1609
MoveToNextTickerItem
static void MoveToNextTickerItem()
Move to the next ticker item.
Definition: news_gui.cpp:686
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:148
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:273
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1311
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:52
WID_N_CLOSEBOX
@ WID_N_CLOSEBOX
Close the window.
Definition: news_widget.h:20
industry.h
safeguards.h
timer.h
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:312
lengthof
#define lengthof(array)
Return the length of an fixed size array.
Definition: stdafx.h:280
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:185
NewsItem::string_id
StringID string_id
Message text.
Definition: news_type.h:129
NewsWindow::chat_height
uint16_t chat_height
Height of the chat window.
Definition: news_gui.cpp:282
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:185
NewsType
NewsType
Type of news.
Definition: news_type.h:23
VehicleID
uint32_t VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
MessageHistoryWindow
Definition: news_gui.cpp:1100
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:740
NewsWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: news_gui.cpp:542
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:2080
MIN_NEWS_AMOUNT
static const uint MIN_NEWS_AMOUNT
preferred minimum amount of news messages.
Definition: news_gui.cpp:46
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:953
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:305
SBI_SHOW_REMINDER
@ SBI_SHOW_REMINDER
show a reminder (dot on the right side of the statusbar)
Definition: statusbar_gui.h:18
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
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition: gfx.cpp:114
SoundFx
SoundFx
Sound effects from baseset.
Definition: sound_type.h:37
MAX_NEWS_AMOUNT
static const uint MAX_NEWS_AMOUNT
Do not exceed this number of news messages.
Definition: news_gui.cpp:47
viewport_func.h
NF_NORMAL
@ NF_NORMAL
Normal news item. (Newspaper with text only)
Definition: news_type.h:81
GUISettings::news_message_timeout
uint8_t news_message_timeout
how much longer than the news message "age" should we keep the message in the history
Definition: settings_type.h:192
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:138
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:306
NR_ENGINE
@ NR_ENGINE
Reference engine.
Definition: news_type.h:59
IsValidTile
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition: tile_map.h:161
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:137
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:774
CopyOutDParam
void CopyOutDParam(std::vector< StringParameterData > &backup, size_t num)
Copy num string parameters from the global string parameter array to the backup.
Definition: strings.cpp:171
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:53
vehicle_func.h
station_base.h
CompanyNewsInformation
Data that needs to be stored for company news messages.
Definition: news_type.h:159
engine_gui.h
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1723
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
NWidgetCore::disp_flags
NWidgetDisplay disp_flags
Flags that affect display and interaction with the widget.
Definition: widget_type.h:392
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:284
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:1215
ShowNewspaper
static void ShowNewspaper(const NewsItem *ni)
Open up an own newspaper window for the news item.
Definition: news_gui.cpp:632
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
CopyInDParam
void CopyInDParam(const std::span< const StringParameterData > backup)
Copy the parameters from the backup into the global string parameter array.
Definition: strings.cpp:159
CompanyNewsInformation::face
uint32_t face
The face of the president.
Definition: news_type.h:164
IntSettingDesc::Read
int32_t Read(const void *object) const
Read the integer from the the actual setting.
Definition: settings.cpp:561
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:1039
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:131
MessageHistoryWindow::date_width
int date_width
< Height of a single line in the news history window including spacing.
Definition: news_gui.cpp:1102
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:782
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:319
FindWindowByClass
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition: window.cpp:1113
PC_GREY
static const uint8_t PC_GREY
Grey palette colour.
Definition: palette_func.h:69
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:344
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1733
BaseStation::xy
TileIndex xy
Base tile of the station.
Definition: base_station_base.h:60
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:1155
PC_BLACK
static const uint8_t PC_BLACK
Black palette colour.
Definition: palette_func.h:67
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:81
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:313
Vehicle::y_pos
int32_t y_pos
y coordinate.
Definition: vehicle_base.h:305
SoundSettings::news_ticker
bool news_ticker
Play a ticker sound when a news item is published.
Definition: settings_type.h:245
DrawCompanyManagerFace
void DrawCompanyManagerFace(CompanyManagerFace cmf, Colours colour, const Rect &r)
Draws the face of a company manager's face.
Definition: company_gui.cpp:1104
WC_SEND_NETWORK_MSG
@ WC_SEND_NETWORK_MSG
Chatbox; Window numbers:
Definition: window_type.h:509
ShowVehicleViewWindow
void ShowVehicleViewWindow(const Vehicle *v)
Shows the vehicle view window of the given vehicle.
Definition: vehicle_gui.cpp:3413
window_func.h
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition: gfx_type.h:355
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:77
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:314
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1139
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:149
ReadyForNextNewsItem
static bool ReadyForNextNewsItem()
Are we ready to show another news item? Only if no newspaper is displayed.
Definition: news_gui.cpp:677
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:657
timer_window.h
RoadVehicle::IsBus
bool IsBus() const
Check whether a roadvehicle is a bus.
Definition: roadveh_cmd.cpp:82
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
engine_base.h
HideActiveNewsMessage
bool HideActiveNewsMessage()
Close active news message window.
Definition: news_gui.cpp:1030
MoveToNextNewsItem
static void MoveToNextNewsItem()
Move to the next news item.
Definition: news_gui.cpp:721
ND_SHADE_GREY
@ ND_SHADE_GREY
Bit value of the 'shade to grey' flag.
Definition: widget_type.h:358
NewsStringData::string
std::string string
The string to retain.
Definition: news_type.h:149
NewsFlag
NewsFlag
Various OR-able news-item flags.
Definition: news_type.h:66
_news_type_data
static NewsTypeData _news_type_data[]
Per-NewsType data.
Definition: news_gui.cpp:247
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:276
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:328
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:963
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:1204
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:372
InitNewsItemStructs
void InitNewsItemStructs()
Initialize the news-items data structures.
Definition: news_gui.cpp:650
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
SetAspect
constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags=AspectFlags::ResizeX)
Widget part function for setting the aspect ratio.
Definition: widget_type.h:1297
NewsTypeData::age
const uint8_t age
Maximum age of news items (in days)
Definition: news_type.h:102
SND_1D_APPLAUSE
@ SND_1D_APPLAUSE
27 == 0x1B News: first vehicle at station
Definition: sound_type.h:66
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition: window_gui.h:42
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:881
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:862
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:1162
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
NR_NONE
@ NR_NONE
Empty reference.
Definition: news_type.h:53
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:851
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:611
NewsItem::reftype1
NewsReferenceType reftype1
Type of ref1.
Definition: news_type.h:135
DeleteNews
void DeleteNews(Tpredicate predicate)
Delete news items by predicate, and invalidate the message history if necessary.
Definition: news_gui.cpp:907
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:357
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:663
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