OpenTTD Source  1.11.0-beta2
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 "date_func.h"
16 #include "vehicle_base.h"
17 #include "vehicle_func.h"
18 #include "vehicle_gui.h"
19 #include "roadveh.h"
20 #include "station_base.h"
21 #include "industry.h"
22 #include "town.h"
23 #include "sound_func.h"
24 #include "string_func.h"
25 #include "widgets/dropdown_func.h"
26 #include "statusbar_gui.h"
27 #include "company_manager_face.h"
28 #include "company_func.h"
29 #include "engine_base.h"
30 #include "engine_gui.h"
31 #include "core/geometry_func.hpp"
32 #include "command_func.h"
33 #include "company_base.h"
34 #include "settings_internal.h"
35 #include "guitimer_func.h"
36 #include "group_gui.h"
37 #include "zoom_func.h"
38 
39 #include "widgets/news_widget.h"
40 
41 #include "table/strings.h"
42 
43 #include "safeguards.h"
44 
45 const NewsItem *_statusbar_news_item = nullptr;
46 
47 static uint MIN_NEWS_AMOUNT = 30;
48 static uint MAX_NEWS_AMOUNT = 1 << 10;
49 static uint _total_news = 0;
50 static NewsItem *_oldest_news = nullptr;
51 NewsItem *_latest_news = nullptr;
52 
59 static const NewsItem *_forced_news = nullptr;
60 
62 static const NewsItem *_current_news = nullptr;
63 
64 
71 static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32 ref)
72 {
73  switch (reftype) {
74  case NR_TILE: return (TileIndex)ref;
75  case NR_STATION: return Station::Get((StationID)ref)->xy;
76  case NR_INDUSTRY: return Industry::Get((IndustryID)ref)->location.tile + TileDiffXY(1, 1);
77  case NR_TOWN: return Town::Get((TownID)ref)->xy;
78  default: return INVALID_TILE;
79  }
80 }
81 
82 /* Normal news items. */
83 static const NWidgetPart _nested_normal_news_widgets[] = {
84  NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
85  NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
86  NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
87  NWidget(NWID_SPACER), SetFill(1, 0),
89  NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_DATE_LONG_SMALL, STR_NULL),
90  NWidget(NWID_SPACER), SetFill(0, 1),
91  EndContainer(),
92  EndContainer(),
93  NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(428, 154), SetPadding(0, 5, 1, 5),
94  EndContainer(),
95 };
96 
97 static WindowDesc _normal_news_desc(
98  WDP_MANUAL, nullptr, 0, 0,
100  0,
101  _nested_normal_news_widgets, lengthof(_nested_normal_news_widgets)
102 );
103 
104 /* New vehicles news items. */
105 static const NWidgetPart _nested_vehicle_news_widgets[] = {
106  NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
107  NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
109  NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
110  NWidget(NWID_SPACER), SetFill(0, 1),
111  EndContainer(),
112  NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_VEH_TITLE), SetFill(1, 1), SetMinimalSize(419, 55), SetDataTip(STR_EMPTY, STR_NULL),
113  EndContainer(),
114  NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_VEH_BKGND), SetPadding(0, 25, 1, 25),
116  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_NAME), SetMinimalSize(369, 33), SetFill(1, 0),
117  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_SPR), SetMinimalSize(369, 32), SetFill(1, 0),
118  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_INFO), SetMinimalSize(369, 46), SetFill(1, 0),
119  EndContainer(),
120  EndContainer(),
121  EndContainer(),
122 };
123 
124 static WindowDesc _vehicle_news_desc(
125  WDP_MANUAL, nullptr, 0, 0,
127  0,
128  _nested_vehicle_news_widgets, lengthof(_nested_vehicle_news_widgets)
129 );
130 
131 /* Company news items. */
132 static const NWidgetPart _nested_company_news_widgets[] = {
133  NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
134  NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
136  NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
137  NWidget(NWID_SPACER), SetFill(0, 1),
138  EndContainer(),
139  NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_TITLE), SetFill(1, 1), SetMinimalSize(410, 20), SetDataTip(STR_EMPTY, STR_NULL),
140  EndContainer(),
141  NWidget(NWID_HORIZONTAL), SetPadding(0, 1, 1, 1),
143  NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MGR_FACE), SetMinimalSize(93, 119), SetPadding(2, 6, 2, 1),
144  NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MGR_NAME), SetMinimalSize(93, 24), SetPadding(0, 0, 0, 1),
145  NWidget(NWID_SPACER), SetFill(0, 1),
146  EndContainer(),
147  NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_COMPANY_MSG), SetFill(1, 1), SetMinimalSize(328, 150),
148  EndContainer(),
149  EndContainer(),
150 };
151 
152 static WindowDesc _company_news_desc(
153  WDP_MANUAL, nullptr, 0, 0,
155  0,
156  _nested_company_news_widgets, lengthof(_nested_company_news_widgets)
157 );
158 
159 /* Thin news items. */
160 static const NWidgetPart _nested_thin_news_widgets[] = {
161  NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
162  NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
163  NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
164  NWidget(NWID_SPACER), SetFill(1, 0),
166  NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_DATE_LONG_SMALL, STR_NULL),
167  NWidget(NWID_SPACER), SetFill(0, 1),
168  EndContainer(),
169  EndContainer(),
170  NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(428, 48), SetFill(1, 0), SetPadding(0, 5, 0, 5),
171  NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetMinimalSize(426, 70), SetPadding(1, 2, 2, 2),
172  EndContainer(),
173 };
174 
175 static WindowDesc _thin_news_desc(
176  WDP_MANUAL, nullptr, 0, 0,
178  0,
179  _nested_thin_news_widgets, lengthof(_nested_thin_news_widgets)
180 );
181 
182 /* Small news items. */
183 static const NWidgetPart _nested_small_news_widgets[] = {
184  /* Caption + close box. The caption is no WWT_CAPTION as the window shall not be moveable and so on. */
186  NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE, WID_N_CLOSEBOX),
187  NWidget(WWT_EMPTY, COLOUR_LIGHT_BLUE, WID_N_CAPTION), SetFill(1, 0),
188  NWidget(WWT_TEXTBTN, COLOUR_LIGHT_BLUE, WID_N_SHOW_GROUP), SetMinimalSize(14, 11), SetResize(1, 0),
189  SetDataTip(STR_NULL /* filled in later */, STR_NEWS_SHOW_VEHICLE_GROUP_TOOLTIP),
190  EndContainer(),
191 
192  /* Main part */
193  NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_N_HEADLINE),
194  NWidget(WWT_INSET, COLOUR_LIGHT_BLUE, WID_N_INSET), SetPadding(2, 2, 2, 2),
195  NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetPadding(1, 1, 1, 1), SetMinimalSize(274, 47), SetFill(1, 0),
196  EndContainer(),
197  NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(275, 20), SetFill(1, 0), SetPadding(0, 5, 0, 5),
198  EndContainer(),
199 };
200 
201 static WindowDesc _small_news_desc(
202  WDP_MANUAL, nullptr, 0, 0,
204  0,
205  _nested_small_news_widgets, lengthof(_nested_small_news_widgets)
206 );
207 
212  &_thin_news_desc,
213  &_small_news_desc,
214  &_normal_news_desc,
215  &_vehicle_news_desc,
216  &_company_news_desc,
217 };
218 
219 WindowDesc* GetNewsWindowLayout(NewsFlag flags)
220 {
221  uint layout = GB(flags, NFB_WINDOW_LAYOUT, NFB_WINDOW_LAYOUT_COUNT);
222  assert(layout < lengthof(_news_window_layout));
223  return _news_window_layout[layout];
224 }
225 
230  /* name, age, sound, */
231  NewsTypeData("news_display.arrival_player", 60, SND_1D_APPLAUSE ),
232  NewsTypeData("news_display.arrival_other", 60, SND_1D_APPLAUSE ),
233  NewsTypeData("news_display.accident", 90, SND_BEGIN ),
234  NewsTypeData("news_display.company_info", 60, SND_BEGIN ),
235  NewsTypeData("news_display.open", 90, SND_BEGIN ),
236  NewsTypeData("news_display.close", 90, SND_BEGIN ),
237  NewsTypeData("news_display.economy", 30, SND_BEGIN ),
238  NewsTypeData("news_display.production_player", 30, SND_BEGIN ),
239  NewsTypeData("news_display.production_other", 30, SND_BEGIN ),
240  NewsTypeData("news_display.production_nobody", 30, SND_BEGIN ),
241  NewsTypeData("news_display.advice", 150, SND_BEGIN ),
242  NewsTypeData("news_display.new_vehicles", 30, SND_1E_NEW_ENGINE),
243  NewsTypeData("news_display.acceptance", 90, SND_BEGIN ),
244  NewsTypeData("news_display.subsidies", 180, SND_BEGIN ),
245  NewsTypeData("news_display.general", 60, SND_BEGIN ),
246 };
247 
248 static_assert(lengthof(_news_type_data) == NT_END);
249 
255 {
256  uint index;
257  const SettingDesc *sd = GetSettingFromName(this->name, &index);
258  assert(sd != nullptr);
259  void *ptr = GetVariableAddress(nullptr, &sd->save);
260  return (NewsDisplay)ReadValue(ptr, sd->save.conv);
261 }
262 
264 struct NewsWindow : Window {
265  uint16 chat_height;
266  uint16 status_height;
267  const NewsItem *ni;
268  static int duration;
269 
270  GUITimer timer;
271 
272  NewsWindow(WindowDesc *desc, const NewsItem *ni) : Window(desc), ni(ni)
273  {
274  NewsWindow::duration = 16650;
276  this->chat_height = (w != nullptr) ? w->height : 0;
277  this->status_height = FindWindowById(WC_STATUS_BAR, 0)->height;
278 
279  this->flags |= WF_DISABLE_VP_SCROLL;
280 
281  this->timer.SetInterval(15);
282 
283  this->CreateNestedTree();
284 
285  /* For company news with a face we have a separate headline in param[0] */
286  if (desc == &_company_news_desc) this->GetWidget<NWidgetCore>(WID_N_TITLE)->widget_data = this->ni->params[0];
287 
288  NWidgetCore *nwid = this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP);
289  if (ni->reftype1 == NR_VEHICLE && nwid != nullptr) {
290  const Vehicle *v = Vehicle::Get(ni->ref1);
291  switch (v->type) {
292  case VEH_TRAIN:
293  nwid->widget_data = STR_TRAIN;
294  break;
295  case VEH_ROAD:
296  nwid->widget_data = RoadVehicle::From(v)->IsBus() ? STR_BUS : STR_LORRY;
297  break;
298  case VEH_SHIP:
299  nwid->widget_data = STR_SHIP;
300  break;
301  case VEH_AIRCRAFT:
302  nwid->widget_data = STR_PLANE;
303  break;
304  default:
305  break; // Do nothing
306  }
307  }
308 
309  this->FinishInitNested(0);
310 
311  /* Initialize viewport if it exists. */
312  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
313  if (nvp != nullptr) {
315  if (this->ni->flags & NF_NO_TRANSPARENT) nvp->disp_flags |= ND_NO_TRANSPARENCY;
316  if ((this->ni->flags & NF_INCOLOUR) == 0) {
317  nvp->disp_flags |= ND_SHADE_GREY;
318  } else if (this->ni->flags & NF_SHADE) {
319  nvp->disp_flags |= ND_SHADE_DIMMED;
320  }
321  }
322 
323  PositionNewsMessage(this);
324  }
325 
326  void DrawNewsBorder(const Rect &r) const
327  {
328  GfxFillRect(r.left, r.top, r.right, r.bottom, PC_WHITE);
329 
330  GfxFillRect(r.left, r.top, r.left, r.bottom, PC_BLACK);
331  GfxFillRect(r.right, r.top, r.right, r.bottom, PC_BLACK);
332  GfxFillRect(r.left, r.top, r.right, r.top, PC_BLACK);
333  GfxFillRect(r.left, r.bottom, r.right, r.bottom, PC_BLACK);
334  }
335 
336  Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
337  {
338  Point pt = { 0, _screen.height };
339  return pt;
340  }
341 
342  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
343  {
344  StringID str = STR_NULL;
345  switch (widget) {
346  case WID_N_CAPTION: {
347  /* Caption is not a real caption (so that the window cannot be moved)
348  * thus it doesn't get the default sizing of a caption. */
349  Dimension d2 = GetStringBoundingBox(STR_NEWS_MESSAGE_CAPTION);
351  *size = maxdim(*size, d2);
352  return;
353  }
354 
355  case WID_N_MGR_FACE:
356  *size = maxdim(*size, GetSpriteSize(SPR_GRADIENT));
357  break;
358 
359  case WID_N_MGR_NAME:
360  SetDParamStr(0, static_cast<const CompanyNewsInformation *>(this->ni->free_data)->president_name);
361  str = STR_JUST_RAW_STRING;
362  break;
363 
364  case WID_N_MESSAGE:
365  CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
366  str = this->ni->string_id;
367  break;
368 
369  case WID_N_COMPANY_MSG:
370  str = this->GetCompanyMessageString();
371  break;
372 
373  case WID_N_VEH_NAME:
374  case WID_N_VEH_TITLE:
375  str = this->GetNewVehicleMessageString(widget);
376  break;
377 
378  case WID_N_VEH_INFO: {
379  assert(this->ni->reftype1 == NR_ENGINE);
380  EngineID engine = this->ni->ref1;
381  str = GetEngineInfoString(engine);
382  break;
383  }
384 
385  case WID_N_SHOW_GROUP:
386  if (this->ni->reftype1 == NR_VEHICLE) {
387  Dimension d2 = GetStringBoundingBox(this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP)->widget_data);
390  *size = d2;
391  } else {
392  /* Hide 'Show group window' button if this news is not about a vehicle. */
393  size->width = 0;
394  size->height = 0;
395  resize->width = 0;
396  resize->height = 0;
397  fill->width = 0;
398  fill->height = 0;
399  }
400  return;
401 
402  default:
403  return; // Do nothing
404  }
405 
406  /* Update minimal size with length of the multi-line string. */
407  Dimension d = *size;
408  d.width = (d.width >= padding.width) ? d.width - padding.width : 0;
409  d.height = (d.height >= padding.height) ? d.height - padding.height : 0;
410  d = GetStringMultiLineBoundingBox(str, d);
411  d.width += padding.width;
412  d.height += padding.height;
413  *size = maxdim(*size, d);
414  }
415 
416  void SetStringParameters(int widget) const override
417  {
418  if (widget == WID_N_DATE) SetDParam(0, this->ni->date);
419  }
420 
421  void DrawWidget(const Rect &r, int widget) const override
422  {
423  switch (widget) {
424  case WID_N_CAPTION:
425  DrawCaption(r, COLOUR_LIGHT_BLUE, this->owner, STR_NEWS_MESSAGE_CAPTION);
426  break;
427 
428  case WID_N_PANEL:
429  this->DrawNewsBorder(r);
430  break;
431 
432  case WID_N_MESSAGE:
433  CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
434  DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->ni->string_id, TC_FROMSTRING, SA_CENTER);
435  break;
436 
437  case WID_N_MGR_FACE: {
438  const CompanyNewsInformation *cni = (const CompanyNewsInformation*)this->ni->free_data;
439  DrawCompanyManagerFace(cni->face, cni->colour, r.left, r.top);
440  GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
441  break;
442  }
443  case WID_N_MGR_NAME: {
444  const CompanyNewsInformation *cni = (const CompanyNewsInformation*)this->ni->free_data;
445  SetDParamStr(0, cni->president_name);
446  DrawStringMultiLine(r.left, r.right, r.top, r.bottom, STR_JUST_RAW_STRING, TC_FROMSTRING, SA_CENTER);
447  break;
448  }
449  case WID_N_COMPANY_MSG:
450  DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->GetCompanyMessageString(), TC_FROMSTRING, SA_CENTER);
451  break;
452 
453  case WID_N_VEH_BKGND:
454  GfxFillRect(r.left, r.top, r.right, r.bottom, PC_GREY);
455  break;
456 
457  case WID_N_VEH_NAME:
458  case WID_N_VEH_TITLE:
459  DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->GetNewVehicleMessageString(widget), TC_FROMSTRING, SA_CENTER);
460  break;
461 
462  case WID_N_VEH_SPR: {
463  assert(this->ni->reftype1 == NR_ENGINE);
464  EngineID engine = this->ni->ref1;
465  DrawVehicleEngine(r.left, r.right, (r.left + r.right) / 2, (r.top + r.bottom) / 2, engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
466  GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
467  break;
468  }
469  case WID_N_VEH_INFO: {
470  assert(this->ni->reftype1 == NR_ENGINE);
471  EngineID engine = this->ni->ref1;
472  DrawStringMultiLine(r.left, r.right, r.top, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
473  break;
474  }
475  }
476  }
477 
478  void OnClick(Point pt, int widget, int click_count) override
479  {
480  switch (widget) {
481  case WID_N_CLOSEBOX:
483  delete this;
484  _forced_news = nullptr;
485  break;
486 
487  case WID_N_CAPTION:
488  if (this->ni->reftype1 == NR_VEHICLE) {
489  const Vehicle *v = Vehicle::Get(this->ni->ref1);
491  }
492  break;
493 
494  case WID_N_VIEWPORT:
495  break; // Ignore clicks
496 
497  case WID_N_SHOW_GROUP:
498  if (this->ni->reftype1 == NR_VEHICLE) {
499  const Vehicle *v = Vehicle::Get(this->ni->ref1);
501  }
502  break;
503  default:
504  if (this->ni->reftype1 == NR_VEHICLE) {
505  const Vehicle *v = Vehicle::Get(this->ni->ref1);
506  ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos);
507  } else {
508  TileIndex tile1 = GetReferenceTile(this->ni->reftype1, this->ni->ref1);
509  TileIndex tile2 = GetReferenceTile(this->ni->reftype2, this->ni->ref2);
510  if (_ctrl_pressed) {
511  if (tile1 != INVALID_TILE) ShowExtraViewportWindow(tile1);
512  if (tile2 != INVALID_TILE) ShowExtraViewportWindow(tile2);
513  } else {
514  if ((tile1 == INVALID_TILE || !ScrollMainWindowToTile(tile1)) && tile2 != INVALID_TILE) {
515  ScrollMainWindowToTile(tile2);
516  }
517  }
518  }
519  break;
520  }
521  }
522 
528  void OnInvalidateData(int data = 0, bool gui_scope = true) override
529  {
530  if (!gui_scope) return;
531  /* The chatbar has notified us that is was either created or closed */
532  int newtop = this->top + this->chat_height - data;
533  this->chat_height = data;
534  this->SetWindowTop(newtop);
535  }
536 
537  void OnRealtimeTick(uint delta_ms) override
538  {
539  int count = this->timer.CountElapsed(delta_ms);
540  if (count > 0) {
541  /* Scroll up newsmessages from the bottom */
542  int newtop = std::max(this->top - 2 * count, _screen.height - this->height - this->status_height - this->chat_height);
543  this->SetWindowTop(newtop);
544  }
545 
546  /* Decrement the news timer. We don't need to action an elapsed event here,
547  * so no need to use TimerElapsed(). */
548  if (NewsWindow::duration > 0) NewsWindow::duration -= delta_ms;
549  }
550 
551 private:
556  void SetWindowTop(int newtop)
557  {
558  if (this->top == newtop) return;
559 
560  int mintop = std::min(newtop, this->top);
561  int maxtop = std::max(newtop, this->top);
562  if (this->viewport != nullptr) this->viewport->top += newtop - this->top;
563  this->top = newtop;
564 
565  AddDirtyBlock(this->left, mintop, this->left + this->width, maxtop + this->height);
566  }
567 
568  StringID GetCompanyMessageString() const
569  {
570  /* Company news with a face have a separate headline, so the normal message is shifted by two params */
571  CopyInDParam(0, this->ni->params + 2, lengthof(this->ni->params) - 2);
572  return this->ni->params[1];
573  }
574 
575  StringID GetNewVehicleMessageString(int widget) const
576  {
577  assert(this->ni->reftype1 == NR_ENGINE);
578  EngineID engine = this->ni->ref1;
579 
580  switch (widget) {
581  case WID_N_VEH_TITLE:
582  SetDParam(0, GetEngineCategoryName(engine));
583  return STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE;
584 
585  case WID_N_VEH_NAME:
586  SetDParam(0, engine);
587  return STR_NEWS_NEW_VEHICLE_TYPE;
588 
589  default:
590  NOT_REACHED();
591  }
592  }
593 };
594 
595 /* static */ int NewsWindow::duration = 0; // Instance creation.
596 
598 static void ShowNewspaper(const NewsItem *ni)
599 {
600  SoundFx sound = _news_type_data[ni->type].sound;
601  if (sound != 0 && _settings_client.sound.news_full) SndPlayFx(sound);
602 
603  new NewsWindow(GetNewsWindowLayout(ni->flags), ni);
604 }
605 
607 static void ShowTicker(const NewsItem *ni)
608 {
610 
611  _statusbar_news_item = ni;
613 }
614 
617 {
618  for (NewsItem *ni = _oldest_news; ni != nullptr; ) {
619  NewsItem *next = ni->next;
620  delete ni;
621  ni = next;
622  }
623 
624  _total_news = 0;
625  _oldest_news = nullptr;
626  _latest_news = nullptr;
627  _forced_news = nullptr;
628  _current_news = nullptr;
629  _statusbar_news_item = nullptr;
631 }
632 
638 {
639  const NewsItem *ni = _statusbar_news_item;
640  if (ni == nullptr) return true;
641 
642  /* Ticker message
643  * Check if the status bar message is still being displayed? */
644  if (IsNewsTickerShown()) return false;
645  return true;
646 }
647 
652 static bool ReadyForNextNewsItem()
653 {
654  const NewsItem *ni = _forced_news == nullptr ? _current_news : _forced_news;
655  if (ni == nullptr) return true;
656 
657  /* neither newsticker nor newspaper are running */
658  return (NewsWindow::duration <= 0 || FindWindowById(WC_NEWS_WINDOW, 0) == nullptr);
659 }
660 
662 static void MoveToNextTickerItem()
663 {
664  /* There is no status bar, so no reason to show news;
665  * especially important with the end game screen when
666  * there is no status bar but possible news. */
667  if (FindWindowById(WC_STATUS_BAR, 0) == nullptr) return;
668 
669  /* if we're not at the last item, then move on */
670  while (_statusbar_news_item != _latest_news) {
671  _statusbar_news_item = (_statusbar_news_item == nullptr) ? _oldest_news : _statusbar_news_item->next;
672  const NewsItem *ni = _statusbar_news_item;
673  const NewsType type = ni->type;
674 
675  /* check the date, don't show too old items */
676  if (_date - _news_type_data[type].age > ni->date) continue;
677 
678  switch (_news_type_data[type].GetDisplay()) {
679  default: NOT_REACHED();
680  case ND_OFF: // Off - show nothing only a small reminder in the status bar
682  break;
683 
684  case ND_SUMMARY: // Summary - show ticker
685  ShowTicker(ni);
686  break;
687 
688  case ND_FULL: // Full - show newspaper, skipped here
689  continue;
690  }
691  return;
692  }
693 }
694 
696 static void MoveToNextNewsItem()
697 {
698  /* There is no status bar, so no reason to show news;
699  * especially important with the end game screen when
700  * there is no status bar but possible news. */
701  if (FindWindowById(WC_STATUS_BAR, 0) == nullptr) return;
702 
703  DeleteWindowById(WC_NEWS_WINDOW, 0); // close the newspapers window if shown
704  _forced_news = nullptr;
705 
706  /* if we're not at the last item, then move on */
707  while (_current_news != _latest_news) {
709  const NewsItem *ni = _current_news;
710  const NewsType type = ni->type;
711 
712  /* check the date, don't show too old items */
713  if (_date - _news_type_data[type].age > ni->date) continue;
714 
715  switch (_news_type_data[type].GetDisplay()) {
716  default: NOT_REACHED();
717  case ND_OFF: // Off - show nothing only a small reminder in the status bar, skipped here
718  continue;
719 
720  case ND_SUMMARY: // Summary - show ticker, skipped here
721  continue;
722 
723  case ND_FULL: // Full - show newspaper
724  ShowNewspaper(ni);
725  break;
726  }
727  return;
728  }
729 }
730 
732 static void DeleteNewsItem(NewsItem *ni)
733 {
734  /* Delete the news from the news queue. */
735  if (ni->prev != nullptr) {
736  ni->prev->next = ni->next;
737  } else {
738  assert(_oldest_news == ni);
739  _oldest_news = ni->next;
740  }
741 
742  if (ni->next != nullptr) {
743  ni->next->prev = ni->prev;
744  } else {
745  assert(_latest_news == ni);
746  _latest_news = ni->prev;
747  }
748 
749  _total_news--;
750 
751  if (_forced_news == ni || _current_news == ni) {
752  /* When we're the current news, go to the previous item first;
753  * we just possibly made that the last news item. */
754  if (_current_news == ni) _current_news = ni->prev;
755 
756  /* About to remove the currently forced item (shown as newspapers) ||
757  * about to remove the currently displayed item (newspapers) */
759  }
760 
761  if (_statusbar_news_item == ni) {
762  /* When we're the current news, go to the previous item first;
763  * we just possibly made that the last news item. */
764  _statusbar_news_item = ni->prev;
765 
766  /* About to remove the currently displayed item (ticker, or just a reminder) */
767  InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); // invalidate the statusbar
769  }
770 
771  delete ni;
772 
774 }
775 
789 void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32 ref1, NewsReferenceType reftype2, uint32 ref2, void *free_data)
790 {
791  if (_game_mode == GM_MENU) return;
792 
793  /* Create new news item node */
794  NewsItem *ni = new NewsItem;
795 
796  ni->string_id = string;
797  ni->type = type;
798  ni->flags = flags;
799 
800  /* show this news message in colour? */
802 
803  ni->reftype1 = reftype1;
804  ni->reftype2 = reftype2;
805  ni->ref1 = ref1;
806  ni->ref2 = ref2;
807  ni->free_data = free_data;
808  ni->date = _date;
809  CopyOutDParam(ni->params, 0, lengthof(ni->params));
810 
811  if (_total_news++ == 0) {
812  assert(_oldest_news == nullptr);
813  _oldest_news = ni;
814  ni->prev = nullptr;
815  } else {
816  assert(_latest_news->next == nullptr);
817  _latest_news->next = ni;
818  ni->prev = _latest_news;
819  }
820 
821  ni->next = nullptr;
822  _latest_news = ni;
823 
824  /* Keep the number of stored news items to a managable number */
827  }
828 
830 }
831 
844 CommandCost CmdCustomNewsItem(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
845 {
846  if (_current_company != OWNER_DEITY) return CMD_ERROR;
847 
848  NewsType type = (NewsType)GB(p1, 0, 8);
849  NewsReferenceType reftype1 = (NewsReferenceType)GB(p1, 8, 8);
850  CompanyID company = (CompanyID)GB(p1, 16, 8);
851 
852  if (company != INVALID_OWNER && !Company::IsValidID(company)) return CMD_ERROR;
853  if (type >= NT_END) return CMD_ERROR;
854  if (StrEmpty(text)) return CMD_ERROR;
855 
856  switch (reftype1) {
857  case NR_NONE: break;
858  case NR_TILE:
859  if (!IsValidTile(p2)) return CMD_ERROR;
860  break;
861 
862  case NR_VEHICLE:
863  if (!Vehicle::IsValidID(p2)) return CMD_ERROR;
864  break;
865 
866  case NR_STATION:
867  if (!Station::IsValidID(p2)) return CMD_ERROR;
868  break;
869 
870  case NR_INDUSTRY:
871  if (!Industry::IsValidID(p2)) return CMD_ERROR;
872  break;
873 
874  case NR_TOWN:
875  if (!Town::IsValidID(p2)) return CMD_ERROR;
876  break;
877 
878  case NR_ENGINE:
879  if (!Engine::IsValidID(p2)) return CMD_ERROR;
880  break;
881 
882  default: return CMD_ERROR;
883  }
884 
885  if (company != INVALID_OWNER && company != _local_company) return CommandCost();
886 
887  if (flags & DC_EXEC) {
888  char *news = stredup(text);
889  SetDParamStr(0, news);
890  AddNewsItem(STR_NEWS_CUSTOM_ITEM, type, NF_NORMAL, reftype1, p2, NR_NONE, UINT32_MAX, news);
891  }
892 
893  return CommandCost();
894 }
895 
903 {
904  NewsItem *ni = _oldest_news;
905 
906  while (ni != nullptr) {
907  NewsItem *next = ni->next;
908  if (((ni->reftype1 == NR_VEHICLE && ni->ref1 == vid) || (ni->reftype2 == NR_VEHICLE && ni->ref2 == vid)) &&
909  (news == INVALID_STRING_ID || ni->string_id == news)) {
910  DeleteNewsItem(ni);
911  }
912  ni = next;
913  }
914 }
915 
921 void DeleteStationNews(StationID sid)
922 {
923  NewsItem *ni = _oldest_news;
924 
925  while (ni != nullptr) {
926  NewsItem *next = ni->next;
927  if ((ni->reftype1 == NR_STATION && ni->ref1 == sid) || (ni->reftype2 == NR_STATION && ni->ref2 == sid)) {
928  DeleteNewsItem(ni);
929  }
930  ni = next;
931  }
932 }
933 
938 void DeleteIndustryNews(IndustryID iid)
939 {
940  NewsItem *ni = _oldest_news;
941 
942  while (ni != nullptr) {
943  NewsItem *next = ni->next;
944  if ((ni->reftype1 == NR_INDUSTRY && ni->ref1 == iid) || (ni->reftype2 == NR_INDUSTRY && ni->ref2 == iid)) {
945  DeleteNewsItem(ni);
946  }
947  ni = next;
948  }
949 }
950 
955 {
956  NewsItem *ni = _oldest_news;
957 
958  while (ni != nullptr) {
959  NewsItem *next = ni->next;
960  if ((ni->reftype1 == NR_ENGINE && (!Engine::IsValidID(ni->ref1) || !Engine::Get(ni->ref1)->IsEnabled())) ||
961  (ni->reftype2 == NR_ENGINE && (!Engine::IsValidID(ni->ref2) || !Engine::Get(ni->ref2)->IsEnabled()))) {
962  DeleteNewsItem(ni);
963  }
964  ni = next;
965  }
966 }
967 
968 static void RemoveOldNewsItems()
969 {
970  NewsItem *next;
971  for (NewsItem *cur = _oldest_news; _total_news > MIN_NEWS_AMOUNT && cur != nullptr; cur = next) {
972  next = cur->next;
973  if (_date - _news_type_data[cur->type].age * _settings_client.gui.news_message_timeout > cur->date) DeleteNewsItem(cur);
974  }
975 }
976 
983 void ChangeVehicleNews(VehicleID from_index, VehicleID to_index)
984 {
985  for (NewsItem *ni = _oldest_news; ni != nullptr; ni = ni->next) {
986  if (ni->reftype1 == NR_VEHICLE && ni->ref1 == from_index) ni->ref1 = to_index;
987  if (ni->reftype2 == NR_VEHICLE && ni->ref2 == from_index) ni->ref2 = to_index;
988  if (ni->flags & NF_VEHICLE_PARAM0 && ni->params[0] == from_index) ni->params[0] = to_index;
989  }
990 }
991 
992 void NewsLoop()
993 {
994  /* no news item yet */
995  if (_total_news == 0) return;
996 
997  static byte _last_clean_month = 0;
998 
999  if (_last_clean_month != _cur_month) {
1000  RemoveOldNewsItems();
1001  _last_clean_month = _cur_month;
1002  }
1003 
1006 }
1007 
1009 static void ShowNewsMessage(const NewsItem *ni)
1010 {
1011  assert(_total_news != 0);
1012 
1013  /* Delete the news window */
1015 
1016  /* setup forced news item */
1017  _forced_news = ni;
1018 
1019  if (_forced_news != nullptr) {
1021  ShowNewspaper(ni);
1022  }
1023 }
1024 
1031  if (w == nullptr) return false;
1032  delete w;
1033  return true;
1034 }
1035 
1038 {
1039  const NewsItem *ni = nullptr;
1040  if (_total_news == 0) {
1041  return;
1042  } else if (_forced_news == nullptr) {
1043  /* Not forced any news yet, show the current one, unless a news window is
1044  * open (which can only be the current one), then show the previous item */
1045  if (_current_news == nullptr) {
1046  /* No news were shown yet resp. the last shown one was already deleted.
1047  * Threat this as if _forced_news reached _oldest_news; so, wrap around and start anew with the latest. */
1048  ni = _latest_news;
1049  } else {
1050  const Window *w = FindWindowById(WC_NEWS_WINDOW, 0);
1051  ni = (w == nullptr || (_current_news == _oldest_news)) ? _current_news : _current_news->prev;
1052  }
1053  } else if (_forced_news == _oldest_news) {
1054  /* We have reached the oldest news, start anew with the latest */
1055  ni = _latest_news;
1056  } else {
1057  /* 'Scrolling' through news history show each one in turn */
1058  ni = _forced_news->prev;
1059  }
1060  bool wrap = false;
1061  for (;;) {
1062  if (_news_type_data[ni->type].GetDisplay() != ND_OFF) {
1063  ShowNewsMessage(ni);
1064  break;
1065  }
1066 
1067  ni = ni->prev;
1068  if (ni == nullptr) {
1069  if (wrap) break;
1070  /* We have reached the oldest news, start anew with the latest */
1071  ni = _latest_news;
1072  wrap = true;
1073  }
1074  }
1075 }
1076 
1077 
1087 static void DrawNewsString(uint left, uint right, int y, TextColour colour, const NewsItem *ni)
1088 {
1089  char buffer[512], buffer2[512];
1090  StringID str;
1091 
1092  CopyInDParam(0, ni->params, lengthof(ni->params));
1093  str = ni->string_id;
1094 
1095  GetString(buffer, str, lastof(buffer));
1096  /* Copy the just gotten string to another buffer to remove any formatting
1097  * from it such as big fonts, etc. */
1098  const char *ptr = buffer;
1099  char *dest = buffer2;
1100  WChar c_last = '\0';
1101  for (;;) {
1102  WChar c = Utf8Consume(&ptr);
1103  if (c == 0) break;
1104  /* Make a space from a newline, but ignore multiple newlines */
1105  if (c == '\n' && c_last != '\n') {
1106  dest[0] = ' ';
1107  dest++;
1108  } else if (c == '\r') {
1109  dest[0] = dest[1] = dest[2] = dest[3] = ' ';
1110  dest += 4;
1111  } else if (IsPrintable(c)) {
1112  dest += Utf8Encode(dest, c);
1113  }
1114  c_last = c;
1115  }
1116 
1117  *dest = '\0';
1118  /* Truncate and show string; postfixed by '...' if necessary */
1119  DrawString(left, right, y, buffer2, colour);
1120 }
1121 
1123  static const int top_spacing;
1124  static const int bottom_spacing;
1125 
1126  int line_height;
1128 
1130 
1131  MessageHistoryWindow(WindowDesc *desc) : Window(desc)
1132  {
1133  this->CreateNestedTree();
1134  this->vscroll = this->GetScrollbar(WID_MH_SCROLLBAR);
1135  this->FinishInitNested(); // Initializes 'this->line_height' and 'this->date_width'.
1136  this->OnInvalidateData(0);
1137  }
1138 
1139  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1140  {
1141  if (widget == WID_MH_BACKGROUND) {
1142  this->line_height = FONT_HEIGHT_NORMAL + 2;
1143  resize->height = this->line_height;
1144 
1145  /* Months are off-by-one, so it's actually 8. Not using
1146  * month 12 because the 1 is usually less wide. */
1148  this->date_width = GetStringBoundingBox(STR_SHORT_DATE).width;
1149 
1150  size->height = 4 * resize->height + this->top_spacing + this->bottom_spacing; // At least 4 lines are visible.
1151  size->width = std::max(200u, size->width); // At least 200 pixels wide.
1152  }
1153  }
1154 
1155  void OnPaint() override
1156  {
1157  this->OnInvalidateData(0);
1158  this->DrawWidgets();
1159  }
1160 
1161  void DrawWidget(const Rect &r, int widget) const override
1162  {
1163  if (widget != WID_MH_BACKGROUND || _total_news == 0) return;
1164 
1165  /* Find the first news item to display. */
1166  NewsItem *ni = _latest_news;
1167  for (int n = this->vscroll->GetPosition(); n > 0; n--) {
1168  ni = ni->prev;
1169  if (ni == nullptr) return;
1170  }
1171 
1172  /* Fill the widget with news items. */
1173  int y = r.top + this->top_spacing;
1174  bool rtl = _current_text_dir == TD_RTL;
1175  uint date_left = rtl ? r.right - WD_FRAMERECT_RIGHT - this->date_width : r.left + WD_FRAMERECT_LEFT;
1176  uint date_right = rtl ? r.right - WD_FRAMERECT_RIGHT : r.left + WD_FRAMERECT_LEFT + this->date_width;
1177  uint news_left = rtl ? r.left + WD_FRAMERECT_LEFT : r.left + WD_FRAMERECT_LEFT + this->date_width + WD_FRAMERECT_RIGHT + ScaleFontTrad(5);
1178  uint news_right = rtl ? r.right - WD_FRAMERECT_RIGHT - this->date_width - WD_FRAMERECT_RIGHT - ScaleFontTrad(5) : r.right - WD_FRAMERECT_RIGHT;
1179  for (int n = this->vscroll->GetCapacity(); n > 0; n--) {
1180  SetDParam(0, ni->date);
1181  DrawString(date_left, date_right, y, STR_SHORT_DATE);
1182 
1183  DrawNewsString(news_left, news_right, y, TC_WHITE, ni);
1184  y += this->line_height;
1185 
1186  ni = ni->prev;
1187  if (ni == nullptr) return;
1188  }
1189  }
1190 
1196  void OnInvalidateData(int data = 0, bool gui_scope = true) override
1197  {
1198  if (!gui_scope) return;
1199  this->vscroll->SetCount(_total_news);
1200  }
1201 
1202  void OnClick(Point pt, int widget, int click_count) override
1203  {
1204  if (widget == WID_MH_BACKGROUND) {
1205  NewsItem *ni = _latest_news;
1206  if (ni == nullptr) return;
1207 
1208  for (int n = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_MH_BACKGROUND, WD_FRAMERECT_TOP, this->line_height); n > 0; n--) {
1209  ni = ni->prev;
1210  if (ni == nullptr) return;
1211  }
1212 
1213  ShowNewsMessage(ni);
1214  }
1215  }
1216 
1217  void OnResize() override
1218  {
1219  this->vscroll->SetCapacityFromWidget(this, WID_MH_BACKGROUND);
1220  }
1221 };
1222 
1225 
1226 static const NWidgetPart _nested_message_history[] = {
1228  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1229  NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_MESSAGE_HISTORY, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1230  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1231  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
1232  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1233  EndContainer(),
1234 
1236  NWidget(WWT_PANEL, COLOUR_BROWN, WID_MH_BACKGROUND), SetMinimalSize(200, 125), SetDataTip(0x0, STR_MESSAGE_HISTORY_TOOLTIP), SetResize(1, 12), SetScrollbar(WID_MH_SCROLLBAR),
1237  EndContainer(),
1239  NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_MH_SCROLLBAR),
1240  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
1241  EndContainer(),
1242  EndContainer(),
1243 };
1244 
1245 static WindowDesc _message_history_desc(
1246  WDP_AUTO, "list_news", 400, 140,
1248  0,
1249  _nested_message_history, lengthof(_nested_message_history)
1250 );
1251 
1254 {
1256  new MessageHistoryWindow(&_message_history_desc);
1257 }
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:266
NewsWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: news_gui.cpp:416
PC_WHITE
static const uint8 PC_WHITE
White palette colour.
Definition: gfx_func.h:209
WID_N_PANEL
@ WID_N_PANEL
Panel of the window.
Definition: news_widget.h:17
MessageHistoryWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: news_gui.cpp:1196
WID_MH_SCROLLBAR
@ WID_MH_SCROLLBAR
Scrollbar for the list.
Definition: news_widget.h:41
WD_FRAMERECT_TOP
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:62
NewsWindow::chat_height
uint16 chat_height
Height of the chat window.
Definition: news_gui.cpp:265
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
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:3321
EIT_PREVIEW
@ EIT_PREVIEW
Vehicle drawn in preview window, news, ...
Definition: vehicle_type.h:91
sound_func.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:921
Pool::PoolItem<&_industry_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:329
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2443
vehicle_gui.h
WChar
char32_t WChar
Type for wide characters, i.e.
Definition: string_type.h:35
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:1576
Vehicle::y_pos
int32 y_pos
y coordinate.
Definition: vehicle_base.h:279
CompanyNewsInformation::colour
byte colour
The colour related to the company.
Definition: news_type.h:154
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3220
NewsWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: news_gui.cpp:342
CopyOutDParam
void CopyOutDParam(uint64 *dst, int offs, int num)
Copy num string parameters from the global string parameter array to the dst array.
Definition: strings.cpp:149
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1094
ShowExtraViewportWindow
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Definition: viewport_gui.cpp:168
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
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:268
Vehicle::x_pos
int32 x_pos
x coordinate.
Definition: vehicle_base.h:278
NewsWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: news_gui.cpp:421
ScaleFontTrad
static int ScaleFontTrad(int value)
Scale traditional pixel dimensions to Font zoom level.
Definition: zoom_func.h:96
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
Scrollbar::GetCapacity
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:621
command_func.h
MessageHistoryWindow::bottom_spacing
static const int bottom_spacing
Additional spacing at the bottom of the WID_MH_BACKGROUND widget.
Definition: news_gui.cpp:1124
WID_N_MGR_FACE
@ WID_N_MGR_FACE
Face of the manager.
Definition: news_widget.h:27
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:1087
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1045
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:23
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:309
dropdown_func.h
_news_window_layout
static WindowDesc * _news_window_layout[]
Window layouts for news items.
Definition: news_gui.cpp:211
guitimer_func.h
statusbar_gui.h
NewsItem
Information about a single item of news.
Definition: news_type.h:119
company_base.h
_cur_year
Year _cur_year
Current year, starting at 0.
Definition: date.cpp:26
WID_N_SHOW_GROUP
@ WID_N_SHOW_GROUP
Show vehicle's group.
Definition: news_widget.h:34
NWidgetViewport
Nested widget to display a viewport in a window.
Definition: widget_type.h:574
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
Vehicle::z_pos
int32 z_pos
z coordinate.
Definition: vehicle_base.h:280
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:1966
NewsItem::ref2
uint32 ref2
Reference 2 to some object: Used for scrolling after clicking on the news, and for deleting the news ...
Definition: news_type.h:130
NewsTypeData
Per-NewsType data.
Definition: news_type.h:97
NR_STATION
@ NR_STATION
Reference station. Scroll to station when clicking on the news. Delete news when station is deleted.
Definition: news_type.h:53
WF_DISABLE_VP_SCROLL
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
Definition: window_gui.h:239
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:326
ND_SHADE_DIMMED
@ ND_SHADE_DIMMED
Bit value of the 'dimmed colours' flag.
Definition: widget_type.h:270
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition: widget_type.h:55
SettingDesc::save
SaveLoad save
Internal structure (going to savegame, parts to config)
Definition: settings_internal.h:111
FILLRECT_RECOLOUR
@ FILLRECT_RECOLOUR
Apply a recolour sprite to the screen content.
Definition: gfx_type.h:289
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
group_gui.h
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1832
company_manager_face.h
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
Viewport::top
int top
Screen coordinate top edge of the viewport.
Definition: viewport_type.h:24
WID_N_MESSAGE
@ WID_N_MESSAGE
Space for displaying the message. Only used in small news items.
Definition: news_widget.h:26
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1133
ND_FULL
@ ND_FULL
Show newspaper.
Definition: news_type.h:91
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:669
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:35
Utf8Encode
size_t Utf8Encode(T buf, WChar c)
Encode a unicode character and place it in the buffer.
Definition: string.cpp:523
WID_N_VEH_BKGND
@ WID_N_VEH_BKGND
Dark background of new vehicle news.
Definition: news_widget.h:30
GetEngineCategoryName
StringID GetEngineCategoryName(EngineID engine)
Return the category of an engine.
Definition: engine_gui.cpp:38
ShowMessageHistory
void ShowMessageHistory()
Display window with news messages history.
Definition: news_gui.cpp:1253
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:250
vehicle_base.h
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:983
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:929
zoom_func.h
WID_N_CLOSEBOX
@ WID_N_CLOSEBOX
Close the window.
Definition: news_widget.h:20
WC_MESSAGE_HISTORY
@ WC_MESSAGE_HISTORY
News history list; Window numbers:
Definition: window_type.h:265
SpecializedStation< Station, false >::Get
static Station * Get(size_t index)
Gets station with given index.
Definition: base_station_base.h:219
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:79
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:640
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:210
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
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:324
NFB_WINDOW_LAYOUT
@ NFB_WINDOW_LAYOUT
First bit for window layout.
Definition: news_type.h:67
NewsItem::reftype2
NewsReferenceType reftype2
Type of ref2.
Definition: news_type.h:128
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:74
MessageHistoryWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: news_gui.cpp:1217
NewsWindow::SetWindowTop
void SetWindowTop(int newtop)
Moves the window to a new top coordinate.
Definition: news_gui.cpp:556
settings_internal.h
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition: gfx_func.h:106
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:222
SaveLoad::conv
VarType conv
type of the variable to be saved, int
Definition: saveload.h:518
IsNewsTickerShown
bool IsNewsTickerShown()
Checks whether the news ticker is currently being used.
Definition: statusbar_gui.cpp:261
WID_N_INSET
@ WID_N_INSET
Inset around the viewport in the window. Only used in small news items.
Definition: news_widget.h:23
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:588
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:348
GetEnginePalette
PaletteID GetEnginePalette(EngineID engine_type, CompanyID company)
Get the colour map for an engine.
Definition: vehicle.cpp:2031
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:199
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:909
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:346
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1013
NWidgetCore::widget_data
uint32 widget_data
Data of the widget.
Definition: widget_type.h:304
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:842
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:763
NewsWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: news_gui.cpp:528
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:1129
NewsItem::flags
NewsFlag flags
NewsFlags bits.
Definition: news_type.h:125
NF_NO_TRANSPARENT
@ NF_NO_TRANSPARENT
Bit value for disabling transparency.
Definition: news_type.h:72
NewsTypeData::age
const byte age
Maximum age of news items (in days)
Definition: news_type.h:99
NewsTypeData::sound
const SoundFx sound
Sound.
Definition: news_type.h:100
WindowDesc
High level window description.
Definition: window_gui.h:166
WID_N_VEH_SPR
@ WID_N_VEH_SPR
Graphical display of the new vehicle.
Definition: news_widget.h:32
_total_news
static uint _total_news
current number of news items
Definition: news_gui.cpp:49
NewsWindow
Window class displaying a news item.
Definition: news_gui.cpp:264
NewsItem::type
NewsType type
Type of the news.
Definition: news_type.h:124
PositionNewsMessage
int PositionNewsMessage(Window *w)
(Re)position news message window at the screen.
Definition: window.cpp:3529
EngineID
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
GUITimer
Definition: guitimer_func.h:13
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:154
DeleteVehicleNews
void DeleteVehicleNews(VehicleID vid, StringID news)
Delete a news item type about a vehicle.
Definition: news_gui.cpp:902
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:322
CommandCost
Common return value for all commands.
Definition: command_type.h:23
_date
Date _date
Current date in days (day counter)
Definition: date.cpp:28
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:570
CompanyNewsInformation::president_name
char president_name[64]
The name of the president.
Definition: news_type.h:150
NF_INCOLOUR
@ NF_INCOLOUR
Bit value for coloured news.
Definition: news_type.h:71
NWID_VIEWPORT
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition: widget_type.h:79
ShowCompanyGroupForVehicle
void ShowCompanyGroupForVehicle(const Vehicle *v)
Show the group window for the given vehicle.
Definition: group_gui.cpp:1117
WID_N_MGR_NAME
@ WID_N_MGR_NAME
Name of the manager.
Definition: news_widget.h:28
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:320
DrawCaption
void DrawCaption(const Rect &r, Colours colour, Owner owner, StringID str)
Draw a caption bar.
Definition: widget.cpp:538
WD_FRAMERECT_LEFT
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:60
SBI_NEWS_DELETED
@ SBI_NEWS_DELETED
abort current news display (active news were deleted)
Definition: statusbar_gui.h:19
ConvertYMDToDate
Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Definition: date.cpp:149
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:47
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:61
WID_N_TITLE
@ WID_N_TITLE
Title of the company news.
Definition: news_widget.h:18
WD_FRAMERECT_BOTTOM
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:63
NewsTypeData::name
const char *const name
Name.
Definition: news_type.h:98
SoundSettings::news_full
bool news_full
Play sound effects associated to certain news types.
Definition: settings_type.h:185
DeleteNewsItem
static void DeleteNewsItem(NewsItem *ni)
Delete a news item from the queue.
Definition: news_gui.cpp:732
MessageHistoryWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: news_gui.cpp:1155
NewsType
NewsType
Type of news.
Definition: news_type.h:21
PALETTE_NEWSPAPER
static const PaletteID PALETTE_NEWSPAPER
Recolour sprite for newspaper-greying.
Definition: sprites.h:1593
MoveToNextTickerItem
static void MoveToNextTickerItem()
Move to the next ticker item.
Definition: news_gui.cpp:662
MAX_NEWS_AMOUNT
static uint MAX_NEWS_AMOUNT
Do not exceed this number of news messages.
Definition: news_gui.cpp:48
NewsWindow::OnInitialPosition
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
Compute the initial position of the window.
Definition: news_gui.cpp:336
NewsWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: news_gui.cpp:478
WID_N_VEH_TITLE
@ WID_N_VEH_TITLE
Vehicle new title.
Definition: news_widget.h:29
NewsTypeData::GetDisplay
NewsDisplay GetDisplay() const
Return the news display option.
Definition: news_gui.cpp:254
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
ShowTicker
static void ShowTicker(const NewsItem *ni)
Show news item in the ticker.
Definition: news_gui.cpp:607
industry.h
WID_N_DATE
@ WID_N_DATE
Date of the news item.
Definition: news_widget.h:21
safeguards.h
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:317
NewsWindow::status_height
uint16 status_height
Height of the status bar window.
Definition: news_gui.cpp:266
IsValidTile
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Definition: tile_map.h:161
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:60
NewsItem::string_id
StringID string_id
Message text.
Definition: news_type.h:122
GetSettingFromName
const SettingDesc * GetSettingFromName(const char *name, uint *i)
Given a name of setting, return a setting description of it.
Definition: settings.cpp:2099
NewsItem::prev
NewsItem * prev
Previous news item.
Definition: news_type.h:120
MessageHistoryWindow
Definition: news_gui.cpp:1122
ND_OFF
@ ND_OFF
Only show a reminder in the status bar.
Definition: news_type.h:89
GetStringMultiLineBoundingBox
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
Definition: gfx.cpp:729
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:1869
_forced_news
static const NewsItem * _forced_news
Forced news item.
Definition: news_gui.cpp:59
WID_N_HEADLINE
@ WID_N_HEADLINE
The news headline.
Definition: news_widget.h:19
date_func.h
MessageHistoryWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: news_gui.cpp:1139
DeleteIndustryNews
void DeleteIndustryNews(IndustryID iid)
Remove news regarding given industry.
Definition: news_gui.cpp:938
stdafx.h
NewsItem::next
NewsItem * next
Next news item.
Definition: news_type.h:121
NR_NONE
@ NR_NONE
Empty reference.
Definition: news_type.h:50
MessageHistoryWindow::top_spacing
static const int top_spacing
Additional spacing at the top of the WID_MH_BACKGROUND widget.
Definition: news_gui.cpp:1123
PC_BLACK
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:206
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:312
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:114
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:78
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
NewsDisplay
NewsDisplay
News display options.
Definition: news_type.h:88
PC_GREY
static const uint8 PC_GREY
Grey palette colour.
Definition: gfx_func.h:208
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
NewsItem::free_data
void * free_data
Data to be freed when the news item has reached its end.
Definition: news_type.h:132
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:913
NewsWindow::OnRealtimeTick
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition: news_gui.cpp:537
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
news_widget.h
ND_SUMMARY
@ ND_SUMMARY
Show ticker.
Definition: news_type.h:90
NewsReferenceType
NewsReferenceType
References to objects in news.
Definition: news_type.h:49
string_func.h
NR_TOWN
@ NR_TOWN
Reference town. Scroll to town when clicking on the news.
Definition: news_type.h:55
NR_TILE
@ NR_TILE
Reference tile. Scroll to tile when clicking on the news.
Definition: news_type.h:51
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
ORIGINAL_MAX_YEAR
static const Year ORIGINAL_MAX_YEAR
The maximum year of the original TTD.
Definition: date_type.h:53
vehicle_func.h
GetReferenceTile
static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32 ref)
Get the position a news-reference is referencing.
Definition: news_gui.cpp:71
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:998
station_base.h
CompanyNewsInformation
Data that needs to be stored for company news messages.
Definition: news_type.h:148
engine_gui.h
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
DeleteWindowById
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1165
NWidgetCore::disp_flags
NWidgetDisplay disp_flags
Flags that affect display and interaction with the widget.
Definition: widget_type.h:301
NewsWindow::ni
const NewsItem * ni
News item to display.
Definition: news_gui.cpp:267
WID_N_VEH_INFO
@ WID_N_VEH_INFO
Some technical data of the new vehicle.
Definition: news_widget.h:33
ShowNewsMessage
static void ShowNewsMessage(const NewsItem *ni)
Do a forced show of a specific message.
Definition: news_gui.cpp:1009
SettingDesc
Definition: settings_internal.h:109
WID_N_CAPTION
@ WID_N_CAPTION
Title bar of the window. Only used in small news items.
Definition: news_widget.h:22
SpecializedVehicle< RoadVehicle, Type >::From
static RoadVehicle * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1162
WID_MH_BACKGROUND
@ WID_MH_BACKGROUND
Background of the window.
Definition: news_widget.h:40
WD_CAPTIONTEXT_TOP
@ WD_CAPTIONTEXT_TOP
Offset of the caption text at the top.
Definition: window_gui.h:127
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:179
ShowNewspaper
static void ShowNewspaper(const NewsItem *ni)
Open up an own newspaper window for the news item.
Definition: news_gui.cpp:598
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1113
MessageHistoryWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: news_gui.cpp:1161
geometry_func.hpp
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:946
NWidgetViewport::InitializeViewport
void InitializeViewport(Window *w, uint32 follow_flags, ZoomLevel zoom)
Initialize the viewport of the window.
Definition: widget.cpp:1934
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
ShowLastNewsMessage
void ShowLastNewsMessage()
Show previous news item.
Definition: news_gui.cpp:1037
CompanyNewsInformation::face
uint32 face
The face of the president.
Definition: news_type.h:153
DrawCompanyManagerFace
void DrawCompanyManagerFace(CompanyManagerFace cmf, int colour, int x, int y)
Draws the face of a company manager's face.
Definition: company_gui.cpp:1113
TileDiffXY
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition: map_func.h:179
MessageHistoryWindow::date_width
int date_width
< Height of a single line in the news history window including spacing.
Definition: news_gui.cpp:1127
NFB_WINDOW_LAYOUT_COUNT
@ NFB_WINDOW_LAYOUT_COUNT
Number of bits for window layout.
Definition: news_type.h:68
WID_N_COMPANY_MSG
@ WID_N_COMPANY_MSG
Message in company news items.
Definition: news_widget.h:25
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:630
FindWindowByClass
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition: window.cpp:1149
GUITimer::CountElapsed
uint CountElapsed(uint delta)
Count how many times the interval has elapsed.
Definition: guitimer_func.h:40
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:62
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1848
BaseStation::xy
TileIndex xy
Base tile of the station.
Definition: base_station_base.h:53
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:77
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:133
company_func.h
WWT_INSET
@ WWT_INSET
Pressed (inset) panel, most commonly used as combo box text area.
Definition: widget_type.h:49
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:318
stredup
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:137
NR_VEHICLE
@ NR_VEHICLE
Reference vehicle. Scroll to vehicle when clicking on the news. Delete news when vehicle is deleted.
Definition: news_type.h:52
VehicleID
uint32 VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
WID_N_VEH_NAME
@ WID_N_VEH_NAME
Name of the new vehicle.
Definition: news_widget.h:31
NewsItem::date
Date date
Date of the news.
Definition: news_type.h:123
SoundSettings::news_ticker
bool news_ticker
Play a ticker sound when a news item is published.
Definition: settings_type.h:184
WC_SEND_NETWORK_MSG
@ WC_SEND_NETWORK_MSG
Chatbox; Window numbers:
Definition: window_type.h:491
ShowVehicleViewWindow
void ShowVehicleViewWindow(const Vehicle *v)
Shows the vehicle view window of the given vehicle.
Definition: vehicle_gui.cpp:3043
window_func.h
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:367
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:319
_latest_news
NewsItem * _latest_news
tail of news items queue
Definition: news_gui.cpp:51
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:1980
WD_CAPTIONTEXT_BOTTOM
@ WD_CAPTIONTEXT_BOTTOM
Offset of the caption text at the bottom.
Definition: window_gui.h:128
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:153
ReadyForNextNewsItem
static bool ReadyForNextNewsItem()
Are we ready to show another news item? Only if no newspaper is displayed.
Definition: news_gui.cpp:652
AddNewsItem
void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32 ref1, NewsReferenceType reftype2, uint32 ref2, void *free_data)
Add a new newsitem to be shown.
Definition: news_gui.cpp:789
ZOOM_LVL_NEWS
@ ZOOM_LVL_NEWS
Default zoom level for the news messages.
Definition: zoom_type.h:36
NF_SHADE
@ NF_SHADE
Bit value for enabling shading.
Definition: news_type.h:73
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:83
RoadVehicle::IsBus
bool IsBus() const
Check whether a roadvehicle is a bus.
Definition: roadveh_cmd.cpp:79
engine_base.h
NewsItem::params
uint64 params[10]
Parameters for string resolving.
Definition: news_type.h:139
HideActiveNewsMessage
bool HideActiveNewsMessage()
Close active news message window.
Definition: news_gui.cpp:1029
MoveToNextNewsItem
static void MoveToNextNewsItem()
Move to the next news item.
Definition: news_gui.cpp:696
ND_SHADE_GREY
@ ND_SHADE_GREY
Bit value of the 'shade to grey' flag.
Definition: widget_type.h:269
NewsFlag
NewsFlag
Various OR-able news-item flags.
Definition: news_type.h:63
_oldest_news
static NewsItem * _oldest_news
head of news items queue
Definition: news_gui.cpp:50
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:982
_news_type_data
static NewsTypeData _news_type_data[]
Per-NewsType data.
Definition: news_gui.cpp:229
gui.h
ReadValue
int64 ReadValue(const void *ptr, VarType conv)
Return a signed-long version of the value of a setting.
Definition: saveload.cpp:749
WID_N_VIEWPORT
@ WID_N_VIEWPORT
Viewport in the window.
Definition: news_widget.h:24
Window
Data structure for an opened window.
Definition: window_gui.h:276
WD_CAPTIONTEXT_LEFT
@ WD_CAPTIONTEXT_LEFT
Offset of the caption text at the left.
Definition: window_gui.h:125
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
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:318
WC_STATUS_BAR
@ WC_STATUS_BAR
Statusbar (at the bottom of your screen); Window numbers:
Definition: window_type.h:57
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
DeleteInvalidEngineNews
void DeleteInvalidEngineNews()
Remove engine announcements for invalid engines.
Definition: news_gui.cpp:954
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:602
WC_NEWS_WINDOW
@ WC_NEWS_WINDOW
News window; Window numbers:
Definition: window_type.h:241
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:282
InitNewsItemStructs
void InitNewsItemStructs()
Initialize the news-items data structures.
Definition: news_gui.cpp:616
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
NewsItem::ref1
uint32 ref1
Reference 1 to some object: Used for a possible viewport, scrolling after clicking on the news,...
Definition: news_type.h:129
NR_INDUSTRY
@ NR_INDUSTRY
Reference industry. Scroll to industry when clicking on the news. Delete news when industry is delete...
Definition: news_type.h:54
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
_cur_month
Month _cur_month
Current month (0..11)
Definition: date.cpp:27
NT_END
@ NT_END
end-of-array marker
Definition: news_type.h:37
SND_1D_APPLAUSE
@ SND_1D_APPLAUSE
27 == 0x1B News: first vehicle at station
Definition: sound_type.h:66
GetVariableAddress
static void * GetVariableAddress(const void *object, const SaveLoad *sld)
Get the address of the variable.
Definition: saveload.h:887
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:383
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:48
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:296
SBI_SHOW_TICKER
@ SBI_SHOW_TICKER
start scrolling news
Definition: statusbar_gui.h:17
CopyInDParam
void CopyInDParam(int offs, const uint64 *src, int num)
Copy num string parameters from array src into the global string parameter array.
Definition: strings.cpp:138
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:286
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:53
NR_ENGINE
@ NR_ENGINE
Reference engine.
Definition: news_type.h:56
GUISettings::coloured_news_year
Year coloured_news_year
when does newspaper become coloured?
Definition: settings_type.h:126
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
CmdCustomNewsItem
CommandCost CmdCustomNewsItem(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Create a new custom news item.
Definition: news_gui.cpp:844
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:567
MessageHistoryWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: news_gui.cpp:1202
NewsItem::reftype1
NewsReferenceType reftype1
Type of ref1.
Definition: news_type.h:127
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:268
WD_CAPTIONTEXT_RIGHT
@ WD_CAPTIONTEXT_RIGHT
Offset of the caption text at the right.
Definition: window_gui.h:126
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:637
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62