OpenTTD
news_gui.cpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #include "stdafx.h"
13 #include "gui.h"
14 #include "viewport_func.h"
15 #include "strings_func.h"
16 #include "window_func.h"
17 #include "date_func.h"
18 #include "vehicle_base.h"
19 #include "vehicle_func.h"
20 #include "vehicle_gui.h"
21 #include "station_base.h"
22 #include "industry.h"
23 #include "town.h"
24 #include "sound_func.h"
25 #include "string_func.h"
26 #include "widgets/dropdown_func.h"
27 #include "statusbar_gui.h"
28 #include "company_manager_face.h"
29 #include "company_func.h"
30 #include "engine_base.h"
31 #include "engine_gui.h"
32 #include "core/geometry_func.hpp"
33 #include "command_func.h"
34 #include "company_base.h"
35 #include "settings_internal.h"
36 #include "guitimer_func.h"
37 
38 #include "widgets/news_widget.h"
39 
40 #include "table/strings.h"
41 
42 #include "safeguards.h"
43 
44 const NewsItem *_statusbar_news_item = NULL;
45 
46 static uint MIN_NEWS_AMOUNT = 30;
47 static uint _total_news = 0;
48 static NewsItem *_oldest_news = NULL;
50 
57 static const NewsItem *_forced_news = NULL;
58 
60 static const NewsItem *_current_news = NULL;
61 
62 
69 static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32 ref)
70 {
71  switch (reftype) {
72  case NR_TILE: return (TileIndex)ref;
73  case NR_STATION: return Station::Get((StationID)ref)->xy;
74  case NR_INDUSTRY: return Industry::Get((IndustryID)ref)->location.tile + TileDiffXY(1, 1);
75  case NR_TOWN: return Town::Get((TownID)ref)->xy;
76  default: return INVALID_TILE;
77  }
78 }
79 
80 /* Normal news items. */
81 static const NWidgetPart _nested_normal_news_widgets[] = {
82  NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
83  NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
84  NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
85  NWidget(NWID_SPACER), SetFill(1, 0),
87  NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_DATE_LONG_SMALL, STR_NULL),
88  NWidget(NWID_SPACER), SetFill(0, 1),
89  EndContainer(),
90  EndContainer(),
91  NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(428, 154), SetPadding(0, 5, 1, 5),
92  EndContainer(),
93 };
94 
95 static WindowDesc _normal_news_desc(
96  WDP_MANUAL, NULL, 0, 0,
98  0,
99  _nested_normal_news_widgets, lengthof(_nested_normal_news_widgets)
100 );
101 
102 /* New vehicles news items. */
103 static const NWidgetPart _nested_vehicle_news_widgets[] = {
104  NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
105  NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
107  NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
108  NWidget(NWID_SPACER), SetFill(0, 1),
109  EndContainer(),
110  NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_VEH_TITLE), SetFill(1, 1), SetMinimalSize(419, 55), SetDataTip(STR_EMPTY, STR_NULL),
111  EndContainer(),
112  NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_VEH_BKGND), SetPadding(0, 25, 1, 25),
114  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_NAME), SetMinimalSize(369, 33), SetFill(1, 0),
115  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_SPR), SetMinimalSize(369, 32), SetFill(1, 0),
116  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_INFO), SetMinimalSize(369, 46), SetFill(1, 0),
117  EndContainer(),
118  EndContainer(),
119  EndContainer(),
120 };
121 
122 static WindowDesc _vehicle_news_desc(
123  WDP_MANUAL, NULL, 0, 0,
125  0,
126  _nested_vehicle_news_widgets, lengthof(_nested_vehicle_news_widgets)
127 );
128 
129 /* Company news items. */
130 static const NWidgetPart _nested_company_news_widgets[] = {
131  NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
132  NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
134  NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
135  NWidget(NWID_SPACER), SetFill(0, 1),
136  EndContainer(),
137  NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_TITLE), SetFill(1, 1), SetMinimalSize(410, 20), SetDataTip(STR_EMPTY, STR_NULL),
138  EndContainer(),
139  NWidget(NWID_HORIZONTAL), SetPadding(0, 1, 1, 1),
141  NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MGR_FACE), SetMinimalSize(93, 119), SetPadding(2, 6, 2, 1),
142  NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MGR_NAME), SetMinimalSize(93, 24), SetPadding(0, 0, 0, 1),
143  NWidget(NWID_SPACER), SetFill(0, 1),
144  EndContainer(),
145  NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_COMPANY_MSG), SetFill(1, 1), SetMinimalSize(328, 150),
146  EndContainer(),
147  EndContainer(),
148 };
149 
150 static WindowDesc _company_news_desc(
151  WDP_MANUAL, NULL, 0, 0,
153  0,
154  _nested_company_news_widgets, lengthof(_nested_company_news_widgets)
155 );
156 
157 /* Thin news items. */
158 static const NWidgetPart _nested_thin_news_widgets[] = {
159  NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
160  NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
161  NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
162  NWidget(NWID_SPACER), SetFill(1, 0),
164  NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_DATE_LONG_SMALL, STR_NULL),
165  NWidget(NWID_SPACER), SetFill(0, 1),
166  EndContainer(),
167  EndContainer(),
168  NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(428, 48), SetFill(1, 0), SetPadding(0, 5, 0, 5),
169  NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetMinimalSize(426, 70), SetPadding(1, 2, 2, 2),
170  EndContainer(),
171 };
172 
173 static WindowDesc _thin_news_desc(
174  WDP_MANUAL, NULL, 0, 0,
176  0,
177  _nested_thin_news_widgets, lengthof(_nested_thin_news_widgets)
178 );
179 
180 /* Small news items. */
181 static const NWidgetPart _nested_small_news_widgets[] = {
182  /* Caption + close box. The caption is no WWT_CAPTION as the window shall not be moveable and so on. */
184  NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE, WID_N_CLOSEBOX),
185  NWidget(WWT_EMPTY, COLOUR_LIGHT_BLUE, WID_N_CAPTION), SetFill(1, 0),
186  EndContainer(),
187 
188  /* Main part */
189  NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_N_HEADLINE),
190  NWidget(WWT_INSET, COLOUR_LIGHT_BLUE, WID_N_INSET), SetPadding(2, 2, 2, 2),
191  NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetPadding(1, 1, 1, 1), SetMinimalSize(274, 47), SetFill(1, 0),
192  EndContainer(),
193  NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(275, 20), SetFill(1, 0), SetPadding(0, 5, 0, 5),
194  EndContainer(),
195 };
196 
197 static WindowDesc _small_news_desc(
198  WDP_MANUAL, NULL, 0, 0,
200  0,
201  _nested_small_news_widgets, lengthof(_nested_small_news_widgets)
202 );
203 
208  &_thin_news_desc,
209  &_small_news_desc,
210  &_normal_news_desc,
211  &_vehicle_news_desc,
212  &_company_news_desc,
213 };
214 
215 WindowDesc* GetNewsWindowLayout(NewsFlag flags)
216 {
217  uint layout = GB(flags, NFB_WINDOW_LAYOUT, NFB_WINDOW_LAYOUT_COUNT);
218  assert(layout < lengthof(_news_window_layout));
219  return _news_window_layout[layout];
220 }
221 
226  /* name, age, sound, */
227  NewsTypeData("news_display.arrival_player", 60, SND_1D_APPLAUSE ),
228  NewsTypeData("news_display.arrival_other", 60, SND_1D_APPLAUSE ),
229  NewsTypeData("news_display.accident", 90, SND_BEGIN ),
230  NewsTypeData("news_display.company_info", 60, SND_BEGIN ),
231  NewsTypeData("news_display.open", 90, SND_BEGIN ),
232  NewsTypeData("news_display.close", 90, SND_BEGIN ),
233  NewsTypeData("news_display.economy", 30, SND_BEGIN ),
234  NewsTypeData("news_display.production_player", 30, SND_BEGIN ),
235  NewsTypeData("news_display.production_other", 30, SND_BEGIN ),
236  NewsTypeData("news_display.production_nobody", 30, SND_BEGIN ),
237  NewsTypeData("news_display.advice", 150, SND_BEGIN ),
238  NewsTypeData("news_display.new_vehicles", 30, SND_1E_OOOOH ),
239  NewsTypeData("news_display.acceptance", 90, SND_BEGIN ),
240  NewsTypeData("news_display.subsidies", 180, SND_BEGIN ),
241  NewsTypeData("news_display.general", 60, SND_BEGIN ),
242 };
243 
244 assert_compile(lengthof(_news_type_data) == NT_END);
245 
251 {
252  uint index;
253  const SettingDesc *sd = GetSettingFromName(this->name, &index);
254  assert(sd != NULL);
255  void *ptr = GetVariableAddress(NULL, &sd->save);
256  return (NewsDisplay)ReadValue(ptr, sd->save.conv);
257 }
258 
260 struct NewsWindow : Window {
261  uint16 chat_height;
262  uint16 status_height;
263  const NewsItem *ni;
264  static int duration;
265 
266  GUITimer timer;
267 
268  NewsWindow(WindowDesc *desc, const NewsItem *ni) : Window(desc), ni(ni)
269  {
270  NewsWindow::duration = 16650;
272  this->chat_height = (w != NULL) ? w->height : 0;
273  this->status_height = FindWindowById(WC_STATUS_BAR, 0)->height;
274 
275  this->flags |= WF_DISABLE_VP_SCROLL;
276 
277  this->timer.SetInterval(15);
278 
279  this->CreateNestedTree();
280 
281  /* For company news with a face we have a separate headline in param[0] */
282  if (desc == &_company_news_desc) this->GetWidget<NWidgetCore>(WID_N_TITLE)->widget_data = this->ni->params[0];
283 
284  this->FinishInitNested(0);
285 
286  /* Initialize viewport if it exists. */
287  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
288  if (nvp != NULL) {
289  nvp->InitializeViewport(this, ni->reftype1 == NR_VEHICLE ? 0x80000000 | ni->ref1 : GetReferenceTile(ni->reftype1, ni->ref1), ZOOM_LVL_NEWS);
290  if (this->ni->flags & NF_NO_TRANSPARENT) nvp->disp_flags |= ND_NO_TRANSPARENCY;
291  if ((this->ni->flags & NF_INCOLOUR) == 0) {
292  nvp->disp_flags |= ND_SHADE_GREY;
293  } else if (this->ni->flags & NF_SHADE) {
294  nvp->disp_flags |= ND_SHADE_DIMMED;
295  }
296  }
297 
298  PositionNewsMessage(this);
299  }
300 
301  void DrawNewsBorder(const Rect &r) const
302  {
303  GfxFillRect(r.left, r.top, r.right, r.bottom, PC_WHITE);
304 
305  GfxFillRect(r.left, r.top, r.left, r.bottom, PC_BLACK);
306  GfxFillRect(r.right, r.top, r.right, r.bottom, PC_BLACK);
307  GfxFillRect(r.left, r.top, r.right, r.top, PC_BLACK);
308  GfxFillRect(r.left, r.bottom, r.right, r.bottom, PC_BLACK);
309  }
310 
311  virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
312  {
313  Point pt = { 0, _screen.height };
314  return pt;
315  }
316 
317  virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
318  {
319  StringID str = STR_NULL;
320  switch (widget) {
321  case WID_N_CAPTION: {
322  /* Caption is not a real caption (so that the window cannot be moved)
323  * thus it doesn't get the default sizing of a caption. */
324  Dimension d2 = GetStringBoundingBox(STR_NEWS_MESSAGE_CAPTION);
326  *size = maxdim(*size, d2);
327  return;
328  }
329 
330  case WID_N_MGR_FACE:
331  *size = maxdim(*size, GetSpriteSize(SPR_GRADIENT));
332  break;
333 
334  case WID_N_MGR_NAME:
335  SetDParamStr(0, static_cast<const CompanyNewsInformation *>(this->ni->free_data)->president_name);
336  str = STR_JUST_RAW_STRING;
337  break;
338 
339  case WID_N_MESSAGE:
340  CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
341  str = this->ni->string_id;
342  break;
343 
344  case WID_N_COMPANY_MSG:
345  str = this->GetCompanyMessageString();
346  break;
347 
348  case WID_N_VEH_NAME:
349  case WID_N_VEH_TITLE:
350  str = this->GetNewVehicleMessageString(widget);
351  break;
352 
353  case WID_N_VEH_INFO: {
354  assert(this->ni->reftype1 == NR_ENGINE);
355  EngineID engine = this->ni->ref1;
356  str = GetEngineInfoString(engine);
357  break;
358  }
359  default:
360  return; // Do nothing
361  }
362 
363  /* Update minimal size with length of the multi-line string. */
364  Dimension d = *size;
365  d.width = (d.width >= padding.width) ? d.width - padding.width : 0;
366  d.height = (d.height >= padding.height) ? d.height - padding.height : 0;
367  d = GetStringMultiLineBoundingBox(str, d);
368  d.width += padding.width;
369  d.height += padding.height;
370  *size = maxdim(*size, d);
371  }
372 
373  virtual void SetStringParameters(int widget) const
374  {
375  if (widget == WID_N_DATE) SetDParam(0, this->ni->date);
376  }
377 
378  virtual void DrawWidget(const Rect &r, int widget) const
379  {
380  switch (widget) {
381  case WID_N_CAPTION:
382  DrawCaption(r, COLOUR_LIGHT_BLUE, this->owner, STR_NEWS_MESSAGE_CAPTION);
383  break;
384 
385  case WID_N_PANEL:
386  this->DrawNewsBorder(r);
387  break;
388 
389  case WID_N_MESSAGE:
390  CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
391  DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->ni->string_id, TC_FROMSTRING, SA_CENTER);
392  break;
393 
394  case WID_N_MGR_FACE: {
395  const CompanyNewsInformation *cni = (const CompanyNewsInformation*)this->ni->free_data;
396  DrawCompanyManagerFace(cni->face, cni->colour, r.left, r.top);
397  GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
398  break;
399  }
400  case WID_N_MGR_NAME: {
401  const CompanyNewsInformation *cni = (const CompanyNewsInformation*)this->ni->free_data;
402  SetDParamStr(0, cni->president_name);
403  DrawStringMultiLine(r.left, r.right, r.top, r.bottom, STR_JUST_RAW_STRING, TC_FROMSTRING, SA_CENTER);
404  break;
405  }
406  case WID_N_COMPANY_MSG:
407  DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->GetCompanyMessageString(), TC_FROMSTRING, SA_CENTER);
408  break;
409 
410  case WID_N_VEH_BKGND:
411  GfxFillRect(r.left, r.top, r.right, r.bottom, PC_GREY);
412  break;
413 
414  case WID_N_VEH_NAME:
415  case WID_N_VEH_TITLE:
416  DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->GetNewVehicleMessageString(widget), TC_FROMSTRING, SA_CENTER);
417  break;
418 
419  case WID_N_VEH_SPR: {
420  assert(this->ni->reftype1 == NR_ENGINE);
421  EngineID engine = this->ni->ref1;
422  DrawVehicleEngine(r.left, r.right, (r.left + r.right) / 2, (r.top + r.bottom) / 2, engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
423  GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
424  break;
425  }
426  case WID_N_VEH_INFO: {
427  assert(this->ni->reftype1 == NR_ENGINE);
428  EngineID engine = this->ni->ref1;
429  DrawStringMultiLine(r.left, r.right, r.top, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
430  break;
431  }
432  }
433  }
434 
435  virtual void OnClick(Point pt, int widget, int click_count)
436  {
437  switch (widget) {
438  case WID_N_CLOSEBOX:
440  delete this;
441  _forced_news = NULL;
442  break;
443 
444  case WID_N_CAPTION:
445  if (this->ni->reftype1 == NR_VEHICLE) {
446  const Vehicle *v = Vehicle::Get(this->ni->ref1);
448  }
449  break;
450 
451  case WID_N_VIEWPORT:
452  break; // Ignore clicks
453 
454  default:
455  if (this->ni->reftype1 == NR_VEHICLE) {
456  const Vehicle *v = Vehicle::Get(this->ni->ref1);
457  ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos);
458  } else {
459  TileIndex tile1 = GetReferenceTile(this->ni->reftype1, this->ni->ref1);
460  TileIndex tile2 = GetReferenceTile(this->ni->reftype2, this->ni->ref2);
461  if (_ctrl_pressed) {
462  if (tile1 != INVALID_TILE) ShowExtraViewPortWindow(tile1);
463  if (tile2 != INVALID_TILE) ShowExtraViewPortWindow(tile2);
464  } else {
465  if ((tile1 == INVALID_TILE || !ScrollMainWindowToTile(tile1)) && tile2 != INVALID_TILE) {
466  ScrollMainWindowToTile(tile2);
467  }
468  }
469  }
470  break;
471  }
472  }
473 
474  virtual EventState OnKeyPress(WChar key, uint16 keycode)
475  {
476  if (keycode == WKC_SPACE) {
477  /* Don't continue. */
478  delete this;
479  return ES_HANDLED;
480  }
481  return ES_NOT_HANDLED;
482  }
483 
489  virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
490  {
491  if (!gui_scope) return;
492  /* The chatbar has notified us that is was either created or closed */
493  int newtop = this->top + this->chat_height - data;
494  this->chat_height = data;
495  this->SetWindowTop(newtop);
496  }
497 
498  virtual void OnRealtimeTick(uint delta_ms)
499  {
500  int count = this->timer.CountElapsed(delta_ms);
501  if (count > 0) {
502  /* Scroll up newsmessages from the bottom */
503  int newtop = max(this->top - 2 * count, _screen.height - this->height - this->status_height - this->chat_height);
504  this->SetWindowTop(newtop);
505  }
506 
507  /* Decrement the news timer. We don't need to action an elapsed event here,
508  * so no need to use TimerElapsed(). */
509  if (NewsWindow::duration > 0) NewsWindow::duration -= delta_ms;
510  }
511 
512 private:
517  void SetWindowTop(int newtop)
518  {
519  if (this->top == newtop) return;
520 
521  int mintop = min(newtop, this->top);
522  int maxtop = max(newtop, this->top);
523  if (this->viewport != NULL) this->viewport->top += newtop - this->top;
524  this->top = newtop;
525 
526  SetDirtyBlocks(this->left, mintop, this->left + this->width, maxtop + this->height);
527  }
528 
529  StringID GetCompanyMessageString() const
530  {
531  /* Company news with a face have a separate headline, so the normal message is shifted by two params */
532  CopyInDParam(0, this->ni->params + 2, lengthof(this->ni->params) - 2);
533  return this->ni->params[1];
534  }
535 
536  StringID GetNewVehicleMessageString(int widget) const
537  {
538  assert(this->ni->reftype1 == NR_ENGINE);
539  EngineID engine = this->ni->ref1;
540 
541  switch (widget) {
542  case WID_N_VEH_TITLE:
543  SetDParam(0, GetEngineCategoryName(engine));
544  return STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE;
545 
546  case WID_N_VEH_NAME:
547  SetDParam(0, engine);
548  return STR_NEWS_NEW_VEHICLE_TYPE;
549 
550  default:
551  NOT_REACHED();
552  }
553  }
554 };
555 
556 /* static */ int NewsWindow::duration = 0; // Instance creation.
557 
558 
560 static void ShowNewspaper(const NewsItem *ni)
561 {
562  SoundFx sound = _news_type_data[ni->type].sound;
563  if (sound != 0 && _settings_client.sound.news_full) SndPlayFx(sound);
564 
565  new NewsWindow(GetNewsWindowLayout(ni->flags), ni);
566 }
567 
569 static void ShowTicker(const NewsItem *ni)
570 {
571  if (_settings_client.sound.news_ticker) SndPlayFx(SND_16_MORSE);
572 
573  _statusbar_news_item = ni;
575 }
576 
579 {
580  for (NewsItem *ni = _oldest_news; ni != NULL; ) {
581  NewsItem *next = ni->next;
582  delete ni;
583  ni = next;
584  }
585 
586  _total_news = 0;
587  _oldest_news = NULL;
588  _latest_news = NULL;
589  _forced_news = NULL;
590  _current_news = NULL;
591  _statusbar_news_item = NULL;
593 }
594 
599 static bool ReadyForNextItem()
600 {
601  const NewsItem *ni = _forced_news == NULL ? _current_news : _forced_news;
602  if (ni == NULL) return true;
603 
604  /* Ticker message
605  * Check if the status bar message is still being displayed? */
606  if (IsNewsTickerShown()) return false;
607 
608  /* neither newsticker nor newspaper are running */
609  return (NewsWindow::duration <= 0 || FindWindowById(WC_NEWS_WINDOW, 0) == NULL);
610 }
611 
613 static void MoveToNextItem()
614 {
615  InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); // invalidate the statusbar
616  DeleteWindowById(WC_NEWS_WINDOW, 0); // close the newspapers window if shown
617  _forced_news = NULL;
618  _statusbar_news_item = NULL;
619 
620  /* if we're not at the last item, then move on */
621  if (_current_news != _latest_news) {
622  _current_news = (_current_news == NULL) ? _oldest_news : _current_news->next;
623  const NewsItem *ni = _current_news;
624  const NewsType type = ni->type;
625 
626  /* check the date, don't show too old items */
627  if (_date - _news_type_data[type].age > ni->date) return;
628 
629  switch (_news_type_data[type].GetDisplay()) {
630  default: NOT_REACHED();
631  case ND_OFF: // Off - show nothing only a small reminder in the status bar
633  break;
634 
635  case ND_SUMMARY: // Summary - show ticker
636  ShowTicker(ni);
637  break;
638 
639  case ND_FULL: // Full - show newspaper
640  ShowNewspaper(ni);
641  break;
642  }
643  }
644 }
645 
659 void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32 ref1, NewsReferenceType reftype2, uint32 ref2, void *free_data)
660 {
661  if (_game_mode == GM_MENU) return;
662 
663  /* Create new news item node */
664  NewsItem *ni = new NewsItem;
665 
666  ni->string_id = string;
667  ni->type = type;
668  ni->flags = flags;
669 
670  /* show this news message in colour? */
672 
673  ni->reftype1 = reftype1;
674  ni->reftype2 = reftype2;
675  ni->ref1 = ref1;
676  ni->ref2 = ref2;
677  ni->free_data = free_data;
678  ni->date = _date;
679  CopyOutDParam(ni->params, 0, lengthof(ni->params));
680 
681  if (_total_news++ == 0) {
682  assert(_oldest_news == NULL);
683  _oldest_news = ni;
684  ni->prev = NULL;
685  } else {
686  assert(_latest_news->next == NULL);
687  _latest_news->next = ni;
688  ni->prev = _latest_news;
689  }
690 
691  ni->next = NULL;
692  _latest_news = ni;
693 
695 }
696 
709 CommandCost CmdCustomNewsItem(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
710 {
711  if (_current_company != OWNER_DEITY) return CMD_ERROR;
712 
713  NewsType type = (NewsType)GB(p1, 0, 8);
714  NewsReferenceType reftype1 = (NewsReferenceType)GB(p1, 8, 8);
715  CompanyID company = (CompanyID)GB(p1, 16, 8);
716 
717  if (company != INVALID_OWNER && !Company::IsValidID(company)) return CMD_ERROR;
718  if (type >= NT_END) return CMD_ERROR;
719  if (StrEmpty(text)) return CMD_ERROR;
720 
721  switch (reftype1) {
722  case NR_NONE: break;
723  case NR_TILE:
724  if (!IsValidTile(p2)) return CMD_ERROR;
725  break;
726 
727  case NR_VEHICLE:
728  if (!Vehicle::IsValidID(p2)) return CMD_ERROR;
729  break;
730 
731  case NR_STATION:
732  if (!Station::IsValidID(p2)) return CMD_ERROR;
733  break;
734 
735  case NR_INDUSTRY:
736  if (!Industry::IsValidID(p2)) return CMD_ERROR;
737  break;
738 
739  case NR_TOWN:
740  if (!Town::IsValidID(p2)) return CMD_ERROR;
741  break;
742 
743  case NR_ENGINE:
744  if (!Engine::IsValidID(p2)) return CMD_ERROR;
745  break;
746 
747  default: return CMD_ERROR;
748  }
749 
750  if (company != INVALID_OWNER && company != _local_company) return CommandCost();
751 
752  if (flags & DC_EXEC) {
753  char *news = stredup(text);
754  SetDParamStr(0, news);
755  AddNewsItem(STR_NEWS_CUSTOM_ITEM, type, NF_NORMAL, reftype1, p2, NR_NONE, UINT32_MAX, news);
756  }
757 
758  return CommandCost();
759 }
760 
762 static void DeleteNewsItem(NewsItem *ni)
763 {
764  /* Delete the news from the news queue. */
765  if (ni->prev != NULL) {
766  ni->prev->next = ni->next;
767  } else {
768  assert(_oldest_news == ni);
769  _oldest_news = ni->next;
770  }
771 
772  if (ni->next != NULL) {
773  ni->next->prev = ni->prev;
774  } else {
775  assert(_latest_news == ni);
776  _latest_news = ni->prev;
777  }
778 
779  _total_news--;
780 
781  if (_forced_news == ni || _current_news == ni || _statusbar_news_item == ni) {
782  /* When we're the current news, go to the previous item first;
783  * we just possibly made that the last news item. */
784  if (_current_news == ni) _current_news = ni->prev;
785 
786  /* About to remove the currently forced item (shown as newspapers) ||
787  * about to remove the currently displayed item (newspapers, ticker, or just a reminder) */
788  MoveToNextItem();
789  }
790 
791  delete ni;
792 
794 }
795 
803 {
804  NewsItem *ni = _oldest_news;
805 
806  while (ni != NULL) {
807  NewsItem *next = ni->next;
808  if (((ni->reftype1 == NR_VEHICLE && ni->ref1 == vid) || (ni->reftype2 == NR_VEHICLE && ni->ref2 == vid)) &&
809  (news == INVALID_STRING_ID || ni->string_id == news)) {
810  DeleteNewsItem(ni);
811  }
812  ni = next;
813  }
814 }
815 
821 void DeleteStationNews(StationID sid)
822 {
823  NewsItem *ni = _oldest_news;
824 
825  while (ni != NULL) {
826  NewsItem *next = ni->next;
827  if ((ni->reftype1 == NR_STATION && ni->ref1 == sid) || (ni->reftype2 == NR_STATION && ni->ref2 == sid)) {
828  DeleteNewsItem(ni);
829  }
830  ni = next;
831  }
832 }
833 
838 void DeleteIndustryNews(IndustryID iid)
839 {
840  NewsItem *ni = _oldest_news;
841 
842  while (ni != NULL) {
843  NewsItem *next = ni->next;
844  if ((ni->reftype1 == NR_INDUSTRY && ni->ref1 == iid) || (ni->reftype2 == NR_INDUSTRY && ni->ref2 == iid)) {
845  DeleteNewsItem(ni);
846  }
847  ni = next;
848  }
849 }
850 
855 {
856  NewsItem *ni = _oldest_news;
857 
858  while (ni != NULL) {
859  NewsItem *next = ni->next;
860  if ((ni->reftype1 == NR_ENGINE && (!Engine::IsValidID(ni->ref1) || !Engine::Get(ni->ref1)->IsEnabled())) ||
861  (ni->reftype2 == NR_ENGINE && (!Engine::IsValidID(ni->ref2) || !Engine::Get(ni->ref2)->IsEnabled()))) {
862  DeleteNewsItem(ni);
863  }
864  ni = next;
865  }
866 }
867 
868 static void RemoveOldNewsItems()
869 {
870  NewsItem *next;
871  for (NewsItem *cur = _oldest_news; _total_news > MIN_NEWS_AMOUNT && cur != NULL; cur = next) {
872  next = cur->next;
873  if (_date - _news_type_data[cur->type].age * _settings_client.gui.news_message_timeout > cur->date) DeleteNewsItem(cur);
874  }
875 }
876 
883 void ChangeVehicleNews(VehicleID from_index, VehicleID to_index)
884 {
885  for (NewsItem *ni = _oldest_news; ni != NULL; ni = ni->next) {
886  if (ni->reftype1 == NR_VEHICLE && ni->ref1 == from_index) ni->ref1 = to_index;
887  if (ni->reftype2 == NR_VEHICLE && ni->ref2 == from_index) ni->ref2 = to_index;
888  if (ni->flags & NF_VEHICLE_PARAM0 && ni->params[0] == from_index) ni->params[0] = to_index;
889  }
890 }
891 
892 void NewsLoop()
893 {
894  /* no news item yet */
895  if (_total_news == 0) return;
896 
897  /* There is no status bar, so no reason to show news;
898  * especially important with the end game screen when
899  * there is no status bar but possible news. */
900  if (FindWindowById(WC_STATUS_BAR, 0) == NULL) return;
901 
902  static byte _last_clean_month = 0;
903 
904  if (_last_clean_month != _cur_month) {
905  RemoveOldNewsItems();
906  _last_clean_month = _cur_month;
907  }
908 
910 }
911 
913 static void ShowNewsMessage(const NewsItem *ni)
914 {
915  assert(_total_news != 0);
916 
917  /* Delete the news window */
919 
920  /* setup forced news item */
921  _forced_news = ni;
922 
923  if (_forced_news != NULL) {
925  ShowNewspaper(ni);
926  }
927 }
928 
931 {
932  const NewsItem *ni = NULL;
933  if (_total_news == 0) {
934  return;
935  } else if (_forced_news == NULL) {
936  /* Not forced any news yet, show the current one, unless a news window is
937  * open (which can only be the current one), then show the previous item */
938  if (_current_news == NULL) {
939  /* No news were shown yet resp. the last shown one was already deleted.
940  * Threat this as if _forced_news reached _oldest_news; so, wrap around and start anew with the latest. */
941  ni = _latest_news;
942  } else {
943  const Window *w = FindWindowById(WC_NEWS_WINDOW, 0);
944  ni = (w == NULL || (_current_news == _oldest_news)) ? _current_news : _current_news->prev;
945  }
946  } else if (_forced_news == _oldest_news) {
947  /* We have reached the oldest news, start anew with the latest */
948  ni = _latest_news;
949  } else {
950  /* 'Scrolling' through news history show each one in turn */
951  ni = _forced_news->prev;
952  }
953  bool wrap = false;
954  for (;;) {
955  if (_news_type_data[ni->type].GetDisplay() != ND_OFF) {
956  ShowNewsMessage(ni);
957  break;
958  }
959 
960  ni = ni->prev;
961  if (ni == NULL) {
962  if (wrap) break;
963  /* We have reached the oldest news, start anew with the latest */
964  ni = _latest_news;
965  wrap = true;
966  }
967  }
968 }
969 
970 
980 static void DrawNewsString(uint left, uint right, int y, TextColour colour, const NewsItem *ni)
981 {
982  char buffer[512], buffer2[512];
983  StringID str;
984 
985  CopyInDParam(0, ni->params, lengthof(ni->params));
986  str = ni->string_id;
987 
988  GetString(buffer, str, lastof(buffer));
989  /* Copy the just gotten string to another buffer to remove any formatting
990  * from it such as big fonts, etc. */
991  const char *ptr = buffer;
992  char *dest = buffer2;
993  WChar c_last = '\0';
994  for (;;) {
995  WChar c = Utf8Consume(&ptr);
996  if (c == 0) break;
997  /* Make a space from a newline, but ignore multiple newlines */
998  if (c == '\n' && c_last != '\n') {
999  dest[0] = ' ';
1000  dest++;
1001  } else if (c == '\r') {
1002  dest[0] = dest[1] = dest[2] = dest[3] = ' ';
1003  dest += 4;
1004  } else if (IsPrintable(c)) {
1005  dest += Utf8Encode(dest, c);
1006  }
1007  c_last = c;
1008  }
1009 
1010  *dest = '\0';
1011  /* Truncate and show string; postfixed by '...' if necessary */
1012  DrawString(left, right, y, buffer2, colour);
1013 }
1014 
1016  static const int top_spacing;
1017  static const int bottom_spacing;
1018 
1019  int line_height;
1021 
1023 
1024  MessageHistoryWindow(WindowDesc *desc) : Window(desc)
1025  {
1026  this->CreateNestedTree();
1027  this->vscroll = this->GetScrollbar(WID_MH_SCROLLBAR);
1028  this->FinishInitNested(); // Initializes 'this->line_height' and 'this->date_width'.
1029  this->OnInvalidateData(0);
1030  }
1031 
1032  virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
1033  {
1034  if (widget == WID_MH_BACKGROUND) {
1035  this->line_height = FONT_HEIGHT_NORMAL + 2;
1036  resize->height = this->line_height;
1037 
1038  /* Months are off-by-one, so it's actually 8. Not using
1039  * month 12 because the 1 is usually less wide. */
1041  this->date_width = GetStringBoundingBox(STR_SHORT_DATE).width;
1042 
1043  size->height = 4 * resize->height + this->top_spacing + this->bottom_spacing; // At least 4 lines are visible.
1044  size->width = max(200u, size->width); // At least 200 pixels wide.
1045  }
1046  }
1047 
1048  virtual void OnPaint()
1049  {
1050  this->OnInvalidateData(0);
1051  this->DrawWidgets();
1052  }
1053 
1054  virtual void DrawWidget(const Rect &r, int widget) const
1055  {
1056  if (widget != WID_MH_BACKGROUND || _total_news == 0) return;
1057 
1058  /* Find the first news item to display. */
1059  NewsItem *ni = _latest_news;
1060  for (int n = this->vscroll->GetPosition(); n > 0; n--) {
1061  ni = ni->prev;
1062  if (ni == NULL) return;
1063  }
1064 
1065  /* Fill the widget with news items. */
1066  int y = r.top + this->top_spacing;
1067  bool rtl = _current_text_dir == TD_RTL;
1068  uint date_left = rtl ? r.right - WD_FRAMERECT_RIGHT - this->date_width : r.left + WD_FRAMERECT_LEFT;
1069  uint date_right = rtl ? r.right - WD_FRAMERECT_RIGHT : r.left + WD_FRAMERECT_LEFT + this->date_width;
1070  uint news_left = rtl ? r.left + WD_FRAMERECT_LEFT : r.left + WD_FRAMERECT_LEFT + this->date_width + WD_FRAMERECT_RIGHT;
1071  uint news_right = rtl ? r.right - WD_FRAMERECT_RIGHT - this->date_width - WD_FRAMERECT_RIGHT : r.right - WD_FRAMERECT_RIGHT;
1072  for (int n = this->vscroll->GetCapacity(); n > 0; n--) {
1073  SetDParam(0, ni->date);
1074  DrawString(date_left, date_right, y, STR_SHORT_DATE);
1075 
1076  DrawNewsString(news_left, news_right, y, TC_WHITE, ni);
1077  y += this->line_height;
1078 
1079  ni = ni->prev;
1080  if (ni == NULL) return;
1081  }
1082  }
1083 
1089  virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
1090  {
1091  if (!gui_scope) return;
1092  this->vscroll->SetCount(_total_news);
1093  }
1094 
1095  virtual void OnClick(Point pt, int widget, int click_count)
1096  {
1097  if (widget == WID_MH_BACKGROUND) {
1098  NewsItem *ni = _latest_news;
1099  if (ni == NULL) return;
1100 
1101  for (int n = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_MH_BACKGROUND, WD_FRAMERECT_TOP, this->line_height); n > 0; n--) {
1102  ni = ni->prev;
1103  if (ni == NULL) return;
1104  }
1105 
1106  ShowNewsMessage(ni);
1107  }
1108  }
1109 
1110  virtual void OnResize()
1111  {
1112  this->vscroll->SetCapacityFromWidget(this, WID_MH_BACKGROUND);
1113  }
1114 };
1115 
1118 
1119 static const NWidgetPart _nested_message_history[] = {
1121  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1122  NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_MESSAGE_HISTORY, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1123  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1124  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
1125  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1126  EndContainer(),
1127 
1129  NWidget(WWT_PANEL, COLOUR_BROWN, WID_MH_BACKGROUND), SetMinimalSize(200, 125), SetDataTip(0x0, STR_MESSAGE_HISTORY_TOOLTIP), SetResize(1, 12), SetScrollbar(WID_MH_SCROLLBAR),
1130  EndContainer(),
1132  NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_MH_SCROLLBAR),
1133  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
1134  EndContainer(),
1135  EndContainer(),
1136 };
1137 
1138 static WindowDesc _message_history_desc(
1139  WDP_AUTO, "list_news", 400, 140,
1141  0,
1142  _nested_message_history, lengthof(_nested_message_history)
1143 );
1144 
1147 {
1149  new MessageHistoryWindow(&_message_history_desc);
1150 }
EventState
State of handling an event.
Definition: window_type.h:713
Nested widget containing a viewport.
Definition: widget_type.h:81
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
NewsItem * _latest_news
tail of news items queue
Definition: news_gui.cpp:49
Functions related to OTTD&#39;s strings.
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:883
Background of the window.
Definition: news_widget.h:41
Face of the manager.
Definition: news_widget.h:29
void DeleteStationNews(StationID sid)
Remove news regarding given station so there are no &#39;unknown station now accepts Mail&#39; or &#39;First trai...
Definition: news_gui.cpp:821
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:48
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: news_gui.cpp:378
start scrolling news
Definition: statusbar_gui.h:19
Definition of stuff that is very close to a company, like the company struct itself.
static const int top_spacing
Additional spacing at the top of the WID_MH_BACKGROUND widget.
Definition: news_gui.cpp:1016
static const uint8 PC_WHITE
White palette colour.
Definition: gfx_func.h:210
StringID GetEngineInfoString(EngineID engine)
Get a multi-line string with some technical data, describing the engine.
Definition: engine_gui.cpp:266
StringID GetEngineCategoryName(EngineID engine)
Return the category of an engine.
Definition: engine_gui.cpp:39
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:930
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen...
Definition: gfx.cpp:113
Show newspaper.
Definition: news_type.h:93
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3201
Reference station. Scroll to station when clicking on the news. Delete news when station is deleted...
Definition: news_type.h:55
Year coloured_news_year
when does newspaper become coloured?
virtual void OnRealtimeTick(uint delta_ms)
Called periodically.
Definition: news_gui.cpp:498
High level window description.
Definition: window_gui.h:168
end-of-array marker
Definition: news_type.h:39
uint CountElapsed(uint delta)
Count how many times the interval has elapsed.
Definition: guitimer_func.h:42
void SetWindowTop(int newtop)
Moves the window to a new top coordinate.
Definition: news_gui.cpp:517
Scrollbar for the list.
Definition: news_widget.h:42
static uint MIN_NEWS_AMOUNT
preferred minimum amount of news messages
Definition: news_gui.cpp:46
Types related to the news widgets.
void DeleteInvalidEngineNews()
Remove engine announcements for invalid engines.
Definition: news_gui.cpp:854
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
NewsReferenceType reftype2
Type of ref2.
Definition: news_type.h:130
Functions related to dates.
const char *const name
Name.
Definition: news_type.h:100
Centered label.
Definition: widget_type.h:57
static const Year ORIGINAL_MAX_YEAR
The maximum year of the original TTD.
Definition: date_type.h:55
Scrollbar data structure.
Definition: widget_type.h:589
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:64
Inset around the viewport in the window. Only used in small news items.
Definition: news_widget.h:25
Horizontal container.
Definition: widget_type.h:75
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1114
The passed event is not handled.
Definition: window_type.h:715
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:264
Bit value of the &#39;no transparency&#39; flag.
Definition: widget_type.h:270
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:25
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
Definition: news_gui.cpp:489
Default zoom level for the news messages.
Definition: zoom_type.h:36
First bit for window layout.
Definition: news_type.h:69
Functions related to vehicles.
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
Pressed (inset) panel, most commonly used as combo box text area.
Definition: widget_type.h:51
Vehicle data structure.
Definition: vehicle_base.h:212
static NewsTypeData _news_type_data[]
Per-NewsType data.
Definition: news_gui.cpp:225
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:141
void DrawCompanyManagerFace(CompanyManagerFace cmf, int colour, int x, int y)
Draws the face of a company manager&#39;s face.
int64 ReadValue(const void *ptr, VarType conv)
Return a signed-long version of the value of a setting.
Definition: saveload.cpp:752
Close box (at top-left of a window)
Definition: widget_type.h:69
uint64 params[10]
Parameters for string resolving.
Definition: news_type.h:141
Bit value of the &#39;shade to grey&#39; flag.
Definition: widget_type.h:271
virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
Compute the initial position of the window.
Definition: news_gui.cpp:311
#define lastof(x)
Get the last element of an fixed size array.
Definition: depend.cpp:50
Data that needs to be stored for company news messages.
Definition: news_type.h:150
void InitializeViewport(Window *w, uint32 follow_flags, ZoomLevel zoom)
Initialize the viewport of the window.
Definition: widget.cpp:1927
static void ShowNewsMessage(const NewsItem *ni)
Do a forced show of a specific message.
Definition: news_gui.cpp:913
Common return value for all commands.
Definition: command_type.h:25
virtual void OnPaint()
The window must be repainted.
Definition: news_gui.cpp:1048
NewsReferenceType reftype1
Type of ref1.
Definition: news_type.h:129
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:26
Year _cur_year
Current year, starting at 0.
Definition: date.cpp:26
byte news_message_timeout
how much longer than the news message "age" should we keep the message in the history ...
Nested widget to display a viewport in a window.
Definition: widget_type.h:575
Per-NewsType data.
Definition: news_type.h:99
Functions related to the vehicle&#39;s GUIs.
Viewport in the window.
Definition: news_widget.h:26
Bit value for specifying that string param 0 contains a vehicle ID. (special autoreplace behaviour) ...
Definition: news_type.h:76
static NewsItem * _oldest_news
head of news items queue
Definition: news_gui.cpp:48
void * free_data
Data to be freed when the news item has reached its end.
Definition: news_type.h:134
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:670
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:910
Functions related to (drawing on) viewports.
bool news_full
Play sound effects associated to certain news types.
The object is owned by a superuser / goal script.
Definition: company_type.h:29
Data structure for an opened window.
Definition: window_gui.h:278
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:36
Panel of the window.
Definition: news_widget.h:19
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Definition: tile_map.h:163
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:1046
SaveLoad save
Internal structure (going to savegame, parts to config)
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:282
Date of the news item.
Definition: news_widget.h:23
Date date
Date of the news.
Definition: news_type.h:125
Functions related to low-level strings.
Only show a reminder in the status bar.
Definition: news_type.h:91
Invisible widget that takes some space.
Definition: widget_type.h:79
StringID string_id
Message text.
Definition: news_type.h:124
VarType conv
type of the variable to be saved, int
Definition: saveload.h:489
GUI Timers.
uint32 ref1
Reference 1 to some object: Used for a possible viewport, scrolling after clicking on the news...
Definition: news_type.h:131
Window class displaying a news item.
Definition: news_gui.cpp:260
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:65
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:1959
int date_width
< Height of a single line in the news history window including spacing.
Definition: news_gui.cpp:1020
int PositionNewsMessage(Window *w)
(Re)position news message window at the screen.
Definition: window.cpp:3510
SoundSettings sound
sound effect settings
Chatbox; Window numbers:
Definition: window_type.h:493
uint32 VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:18
void ShowMessageHistory()
Display window with news messages history.
Definition: news_gui.cpp:1146
DoCommandFlag
List of flags for a command.
Definition: command_type.h:343
static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32 ref)
Get the position a news-reference is referencing.
Definition: news_gui.cpp:69
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:180
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
abort current news display (active news were deleted)
Definition: statusbar_gui.h:21
NewsDisplay
News display options.
Definition: news_type.h:90
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:76
Apply a recolour sprite to the screen content.
Definition: gfx_type.h:285
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Definition: news_gui.cpp:1095
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:947
Definition of base types and functions in a cross-platform compatible way.
Center both horizontally and vertically.
Definition: gfx_func.h:108
PaletteID GetEnginePalette(EngineID engine_type, CompanyID company)
Get the colour map for an engine.
Definition: vehicle.cpp:1971
Bit value for disabling transparency.
Definition: news_type.h:74
char president_name[64]
The name of the president.
Definition: news_type.h:152
NewsFlag
Various OR-able news-item flags.
Definition: news_type.h:65
Reference tile. Scroll to tile when clicking on the news.
Definition: news_type.h:53
A number of safeguards to prevent using unsafe methods.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:247
Name of the new vehicle.
Definition: news_widget.h:33
Title of the company news.
Definition: news_widget.h:20
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:152
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
Definition: news_gui.cpp:1032
Vehicle drawn in preview window, news, ...
Definition: vehicle_type.h:95
Geometry functions.
Simple depressed panel.
Definition: widget_type.h:50
show a reminder (dot on the right side of the statusbar)
Definition: statusbar_gui.h:20
static void ShowNewspaper(const NewsItem *ni)
Open up an own newspaper window for the news item.
Definition: news_gui.cpp:560
Engine GUI functions, used by build_vehicle_gui and autoreplace_gui
const SettingDesc * GetSettingFromName(const char *name, uint *i)
Given a name of setting, return a setting description of it.
Definition: settings.cpp:2058
Empty reference.
Definition: news_type.h:52
virtual EventState OnKeyPress(WChar key, uint16 keycode)
A key has been pressed.
Definition: news_gui.cpp:474
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:138
static const PaletteID PALETTE_NEWSPAPER
Recolour sprite for newspaper-greying.
Definition: sprites.h:1579
Normal news item. (Newspaper with text only)
Definition: news_type.h:80
NewsItem * prev
Previous news item.
Definition: news_type.h:122
void ShowLastNewsMessage()
Show previous news item.
Definition: news_gui.cpp:930
Title bar of the window. Only used in small news items.
Definition: news_widget.h:24
void DeleteIndustryNews(IndustryID iid)
Remove news regarding given industry.
Definition: news_gui.cpp:838
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: news_gui.cpp:1054
uint32 ref2
Reference 2 to some object: Used for scrolling after clicking on the news, and for deleteing the news...
Definition: news_type.h:132
uint16 status_height
Height of the status bar window.
Definition: news_gui.cpp:262
Bit value of the &#39;dimmed colours&#39; flag.
Definition: widget_type.h:272
const NewsItem * ni
News item to display.
Definition: news_gui.cpp:263
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1114
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:65
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:500
void ShowVehicleViewWindow(const Vehicle *v)
Shows the vehicle view window of the given vehicle.
Bit value for coloured news.
Definition: news_type.h:73
static const int bottom_spacing
Additional spacing at the bottom of the WID_MH_BACKGROUND widget.
Definition: news_gui.cpp:1017
void SetDirtyBlocks(int left, int top, int right, int bottom)
This function extends the internal _invalid_rect rectangle as it now contains the rectangle defined b...
Definition: gfx.cpp:1420
Close the window.
Definition: news_widget.h:22
void InitNewsItemStructs()
Initialize the news-items data structures.
Definition: news_gui.cpp:578
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
virtual void OnResize()
Called after the window got resized.
Definition: news_gui.cpp:1110
Graphical display of the new vehicle.
Definition: news_widget.h:34
Message in company news items.
Definition: news_widget.h:27
Functions related to sound.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:207
void DeleteVehicleNews(VehicleID vid, StringID news)
Delete a news item type about a vehicle.
Definition: news_gui.cpp:802
NewsDisplay GetDisplay() const
Return the news display option.
Definition: news_gui.cpp:250
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:659
Name of the manager.
Definition: news_widget.h:30
void ShowExtraViewPortWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Offset of the caption text at the top.
Definition: window_gui.h:129
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:700
News history list; Window numbers:
Definition: window_type.h:267
Month _cur_month
Current month (0..11)
Definition: date.cpp:27
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
Definition: gfx.cpp:588
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:40
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1146
Number of bits for window layout.
Definition: news_type.h:70
static const uint8 PC_GREY
Grey palette colour.
Definition: gfx_func.h:209
execute the given command
Definition: command_type.h:345
The news headline.
Definition: news_widget.h:21
static void * GetVariableAddress(const void *object, const SaveLoad *sld)
Get the address of the variable.
Definition: saveload.h:813
uint32 face
The face of the president.
Definition: news_type.h:155
Functions related to companies.
static void DeleteNewsItem(NewsItem *ni)
Delete a news item from the queue.
Definition: news_gui.cpp:762
Show ticker.
Definition: news_type.h:92
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
Space for displaying the message. Only used in small news items.
Definition: news_widget.h:28
Base class for engines.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Definition: news_gui.cpp:435
Functionality related to the company manager&#39;s face.
GUISettings gui
settings related to the GUI
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
NewsItem * next
Next news item.
Definition: news_type.h:123
Reference town. Scroll to town when clicking on the news.
Definition: news_type.h:57
Base class for all vehicles.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:59
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:22
Offset of the caption text at the bottom.
Definition: window_gui.h:130
CompanyByte _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:52
static void MoveToNextItem()
Move to the next news item.
Definition: news_gui.cpp:613
CommandCost CmdCustomNewsItem(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Create a new custom news item.
Definition: news_gui.cpp:709
Vertical container.
Definition: widget_type.h:77
static WindowDesc * _news_window_layout[]
Window layouts for news items.
Definition: news_gui.cpp:207
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
Definition: news_gui.cpp:317
TileIndex xy
Base tile of the station.
const SoundFx sound
Sound.
Definition: news_type.h:102
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:999
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
static const NewsItem * _forced_news
Forced news item.
Definition: news_gui.cpp:57
Functions and types used internally for the settings configurations.
Dark background of new vehicle news.
Definition: news_widget.h:32
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition: window.cpp:1130
NewsFlag flags
NewsFlags bits.
Definition: news_type.h:127
int32 z_pos
z coordinate.
Definition: vehicle_base.h:270
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2133
Statusbar (at the bottom of your screen); Window numbers:
Definition: window_type.h:59
Functions related to commands.
static bool IsValidID(size_t index)
Tests whether given index is a valid index for station of this type.
Coordinates of a point in 2D.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:769
Vehicle new title.
Definition: news_widget.h:31
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
Definition: pool_type.hpp:235
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:622
bool IsNewsTickerShown()
Checks whether the news ticker is currently being used.
Window does not do autoscroll,.
Definition: window_gui.h:241
Reference engine.
Definition: news_type.h:58
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:19
NewsReferenceType
References to objects in news.
Definition: news_type.h:51
size_t Utf8Encode(char *buf, WChar c)
Encode a unicode character and place it in the buffer.
Definition: string.cpp:488
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition: map_func.h:181
void DrawCaption(const Rect &r, Colours colour, Owner owner, StringID str)
Draw a caption bar.
Definition: widget.cpp:540
Base of all industries.
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
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:980
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:66
uint16 chat_height
Height of the chat window.
Definition: news_gui.cpp:261
int32 x_pos
x coordinate.
Definition: vehicle_base.h:268
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:983
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:85
Base of the town class.
static bool ReadyForNextItem()
Are we ready to show another news item? Only if nothing is in the newsticker and no newspaper is disp...
Definition: news_gui.cpp:599
Reference industry. Scroll to industry when clicking on the news. Delete news when industry is delete...
Definition: news_type.h:56
static uint _total_news
current number of news items
Definition: news_gui.cpp:47
NewsType type
Type of the news.
Definition: news_type.h:126
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:1973
Specification of a rectangle with absolute coordinates of all edges.
Vertical scrollbar.
Definition: widget_type.h:84
The passed event is handled.
Definition: window_type.h:714
int32 y_pos
y coordinate.
Definition: vehicle_base.h:269
Text is written right-to-left by default.
Definition: strings_type.h:26
Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Definition: date.cpp:149
Owner
Enum for all companies/owners.
Definition: company_type.h:20
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
Definition: news_gui.cpp:1089
Window functions not directly related to making/drawing windows.
Find a place automatically.
Definition: window_gui.h:156
Manually align the window (so no automatic location finding)
Definition: window_gui.h:155
NWidgetDisplay disp_flags
Flags that affect display and interaction with the widget.
Definition: widget_type.h:302
GUI functions that shouldn&#39;t be here.
Some technical data of the new vehicle.
Definition: news_widget.h:35
NewsType
Type of news.
Definition: news_type.h:23
Base classes/functions for stations.
Functions, definitions and such used only by the GUI.
static Station * Get(size_t index)
Gets station with given index.
Date _date
Current date in days (day counter)
Definition: date.cpp:28
uint32 WChar
Type for wide characters, i.e.
Definition: string_type.h:35
bool news_ticker
Play a ticker sound when a news item is published.
const byte age
Maximum age of news items (in days)
Definition: news_type.h:101
static void ShowTicker(const NewsItem *ni)
Show news item in the ticker.
Definition: news_gui.cpp:569
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1095
Reference vehicle. Scroll to vehicle when clicking on the news. Delete news when vehicle is deleted...
Definition: news_type.h:54
Dimensions (a width and height) of a rectangle in 2D.
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:62
Bit value for enabling shading.
Definition: news_type.h:75
SoundFx
Sound effects from baseset.
Definition: sound_type.h:39
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:64
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
Definition: news_gui.cpp:373
Scrollbar * vscroll
< Width needed for the date part.
Definition: news_gui.cpp:1022
An invalid owner.
Definition: company_type.h:31
Information about a single item of news.
Definition: news_type.h:121
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:3301
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:322
static const NewsItem * _current_news
Current news item (last item shown regularly).
Definition: news_gui.cpp:60
News window; Window numbers:
Definition: window_type.h:243
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:621
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:631
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:201
byte colour
The colour related to the company.
Definition: news_type.h:156