OpenTTD
story_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 "window_gui.h"
14 #include "strings_func.h"
15 #include "date_func.h"
16 #include "gui.h"
17 #include "story_base.h"
18 #include "core/geometry_func.hpp"
19 #include "company_func.h"
20 #include "command_func.h"
21 #include "widgets/dropdown_type.h"
22 #include "widgets/dropdown_func.h"
23 #include "sortlist_type.h"
24 #include "goal_base.h"
25 #include "viewport_func.h"
26 #include "window_func.h"
27 #include "company_base.h"
28 
29 #include "widgets/story_widget.h"
30 
31 #include "table/strings.h"
32 #include "table/sprites.h"
33 
34 #include "safeguards.h"
35 
38 
40 protected:
42 
47 
48  static GUIStoryPageList::SortFunction * const page_sorter_funcs[];
49  static GUIStoryPageElementList::SortFunction * const page_element_sorter_funcs[];
50 
53  {
54  if (this->story_pages.NeedRebuild()) {
55  this->story_pages.clear();
56 
57  const StoryPage *p;
58  FOR_ALL_STORY_PAGES(p) {
59  if (this->IsPageAvailable(p)) {
60  this->story_pages.push_back(p);
61  }
62  }
63 
64  this->story_pages.shrink_to_fit();
65  this->story_pages.RebuildDone();
66  }
67 
68  this->story_pages.Sort();
69  }
70 
72  static bool PageOrderSorter(const StoryPage * const &a, const StoryPage * const &b)
73  {
74  return a->sort_value < b->sort_value;
75  }
76 
79  {
80  if (this->story_page_elements.NeedRebuild()) {
81  this->story_page_elements.clear();
82 
83  const StoryPage *p = GetSelPage();
84  if (p != nullptr) {
85  const StoryPageElement *pe;
86  FOR_ALL_STORY_PAGE_ELEMENTS(pe) {
87  if (pe->page == p->index) {
88  this->story_page_elements.push_back(pe);
89  }
90  }
91  }
92 
93  this->story_page_elements.shrink_to_fit();
94  this->story_page_elements.RebuildDone();
95  }
96 
97  this->story_page_elements.Sort();
98  }
99 
101  static bool PageElementOrderSorter(const StoryPageElement * const &a, const StoryPageElement * const &b)
102  {
103  return a->sort_value < b->sort_value;
104  }
105 
106  /*
107  * Checks if a given page should be visible in the story book.
108  * @param page The page to check.
109  * @return True if the page should be visible, otherwise false.
110  */
111  bool IsPageAvailable(const StoryPage *page) const
112  {
113  return page->company == INVALID_COMPANY || page->company == this->window_number;
114  }
115 
121  {
122  if (!_story_page_pool.IsValidID(selected_page_id)) return nullptr;
123  return _story_page_pool.Get(selected_page_id);
124  }
125 
130  int GetSelPageNum() const
131  {
132  int page_number = 0;
133  for (const StoryPage *p : this->story_pages) {
134  if (p->index == this->selected_page_id) {
135  return page_number;
136  }
137  page_number++;
138  }
139  return -1;
140  }
141 
146  {
147  /* Verify that the selected page exist. */
148  if (!_story_page_pool.IsValidID(this->selected_page_id)) return false;
149 
150  return this->story_pages.front()->index == this->selected_page_id;
151  }
152 
157  {
158  /* Verify that the selected page exist. */
159  if (!_story_page_pool.IsValidID(this->selected_page_id)) return false;
160 
161  if (this->story_pages.size() <= 1) return true;
162  const StoryPage *last = this->story_pages.back();
163  return last->index == this->selected_page_id;
164  }
165 
170  {
171  /* Generate generic title if selected page have no custom title. */
172  StoryPage *page = this->GetSelPage();
173  if (page != nullptr && page->title == nullptr) {
174  SetDParam(0, GetSelPageNum() + 1);
175  GetString(selected_generic_title, STR_STORY_BOOK_GENERIC_PAGE_ITEM, lastof(selected_generic_title));
176  }
177 
178  this->story_page_elements.ForceRebuild();
180 
181  this->vscroll->SetCount(this->GetContentHeight());
185  }
186 
191  {
192  if (!_story_page_pool.IsValidID(this->selected_page_id)) return;
193 
194  /* Find the last available page which is previous to the current selected page. */
195  const StoryPage *last_available;
196  last_available = nullptr;
197  for (const StoryPage *p : this->story_pages) {
198  if (p->index == this->selected_page_id) {
199  if (last_available == nullptr) return; // No previous page available.
200  this->SetSelectedPage(last_available->index);
201  return;
202  }
203  last_available = p;
204  }
205  }
206 
211  {
212  if (!_story_page_pool.IsValidID(this->selected_page_id)) return;
213 
214  /* Find selected page. */
215  for (auto iter = this->story_pages.begin(); iter != this->story_pages.end(); iter++) {
216  const StoryPage *p = *iter;
217  if (p->index == this->selected_page_id) {
218  /* Select the page after selected page. */
219  iter++;
220  if (iter != this->story_pages.end()) {
221  this->SetSelectedPage((*iter)->index);
222  }
223  return;
224  }
225  }
226  }
227 
232  {
233  DropDownList list;
234  uint16 page_num = 1;
235  for (const StoryPage *p : this->story_pages) {
236  bool current_page = p->index == this->selected_page_id;
237  DropDownListStringItem *item = nullptr;
238  if (p->title != nullptr) {
239  item = new DropDownListCharStringItem(p->title, p->index, current_page);
240  } else {
241  /* No custom title => use a generic page title with page number. */
242  DropDownListParamStringItem *str_item =
243  new DropDownListParamStringItem(STR_STORY_BOOK_GENERIC_PAGE_ITEM, p->index, current_page);
244  str_item->SetParam(0, page_num);
245  item = str_item;
246  }
247 
248  list.emplace_back(item);
249  page_num++;
250  }
251 
252  return list;
253  }
254 
259  {
260  return this->GetWidget<NWidgetCore>(WID_SB_PAGE_PANEL)->current_x - WD_FRAMETEXT_LEFT - WD_FRAMERECT_RIGHT;
261  }
262 
270  uint GetHeadHeight(int max_width) const
271  {
272  StoryPage *page = this->GetSelPage();
273  if (page == nullptr) return 0;
274  int height = 0;
275 
276  /* Title lines */
277  height += FONT_HEIGHT_NORMAL; // Date always use exactly one line.
278  SetDParamStr(0, page->title != nullptr ? page->title : this->selected_generic_title);
279  height += GetStringHeight(STR_STORY_BOOK_TITLE, max_width);
280 
281  return height;
282  }
283 
291  {
292  switch (pe.type) {
293  case SPET_GOAL: {
294  Goal *g = Goal::Get((GoalID) pe.referenced_id);
295  if (g == nullptr) return SPR_IMG_GOAL_BROKEN_REF;
296  return g->completed ? SPR_IMG_GOAL_COMPLETED : SPR_IMG_GOAL;
297  }
298  case SPET_LOCATION:
299  return SPR_IMG_VIEW_LOCATION;
300  default:
301  NOT_REACHED();
302  }
303  }
304 
311  uint GetPageElementHeight(const StoryPageElement &pe, int max_width)
312  {
313  switch (pe.type) {
314  case SPET_TEXT:
315  SetDParamStr(0, pe.text);
316  return GetStringHeight(STR_BLACK_RAW_STRING, max_width);
317  break;
318 
319  case SPET_GOAL:
320  case SPET_LOCATION: {
321  Dimension sprite_dim = GetSpriteSize(GetPageElementSprite(pe));
322  return sprite_dim.height;
323  break;
324  }
325  default:
326  NOT_REACHED();
327  }
328  return 0;
329  }
330 
337  {
338  StoryPage *page = this->GetSelPage();
339  if (page == nullptr) return 0;
340  int max_width = GetAvailablePageContentWidth();
341  uint element_vertical_dist = FONT_HEIGHT_NORMAL;
342 
343  /* Head */
344  uint height = GetHeadHeight(max_width);
345 
346  /* Body */
347  for (const StoryPageElement *pe : this->story_page_elements) {
348  height += element_vertical_dist;
349  height += GetPageElementHeight(*pe, max_width);
350  }
351 
352  return height;
353  }
354 
366  void DrawActionElement(int &y_offset, int width, int line_height, SpriteID action_sprite, StringID string_id = STR_JUST_RAW_STRING) const
367  {
368  Dimension sprite_dim = GetSpriteSize(action_sprite);
369  uint element_height = max(sprite_dim.height, (uint)line_height);
370 
371  uint sprite_top = y_offset + (element_height - sprite_dim.height) / 2;
372  uint text_top = y_offset + (element_height - line_height) / 2;
373 
374  DrawSprite(action_sprite, PAL_NONE, 0, sprite_top);
375  DrawString(sprite_dim.width + WD_FRAMETEXT_LEFT, width, text_top, string_id, TC_BLACK);
376 
377  y_offset += element_height;
378  }
379 
385  {
386  switch (pe.type) {
387  case SPET_TEXT:
388  /* Do nothing. */
389  break;
390 
391  case SPET_LOCATION:
392  if (_ctrl_pressed) {
394  } else {
396  }
397  break;
398 
399  case SPET_GOAL:
401  break;
402 
403  default:
404  NOT_REACHED();
405  }
406  }
407 
408 public:
410  {
411  this->CreateNestedTree();
412  this->vscroll = this->GetScrollbar(WID_SB_SCROLLBAR);
413  this->vscroll->SetStepSize(FONT_HEIGHT_NORMAL);
414 
415  /* Initialize page sort. */
416  this->story_pages.SetSortFuncs(StoryBookWindow::page_sorter_funcs);
417  this->story_pages.ForceRebuild();
418  this->BuildStoryPageList();
419  this->story_page_elements.SetSortFuncs(StoryBookWindow::page_element_sorter_funcs);
420  /* story_page_elements will get built by SetSelectedPage */
421 
422  this->FinishInitNested(window_number);
423  this->owner = (Owner)this->window_number;
424 
425  /* Initialize selected vars. */
426  this->selected_generic_title[0] = '\0';
427  this->selected_page_id = INVALID_STORY_PAGE;
428 
429  this->OnInvalidateData(-1);
430  }
431 
436  {
437  this->SetWidgetDisabledState(WID_SB_PREV_PAGE, story_pages.size() == 0 || this->IsFirstPageSelected());
438  this->SetWidgetDisabledState(WID_SB_NEXT_PAGE, story_pages.size() == 0 || this->IsLastPageSelected());
441  }
442 
447  void SetSelectedPage(uint16 page_index)
448  {
449  if (this->selected_page_id != page_index) {
450  this->selected_page_id = page_index;
451  this->RefreshSelectedPage();
453  }
454  }
455 
456  void SetStringParameters(int widget) const override
457  {
458  switch (widget) {
459  case WID_SB_SEL_PAGE: {
460  StoryPage *page = this->GetSelPage();
461  SetDParamStr(0, page != nullptr && page->title != nullptr ? page->title : this->selected_generic_title);
462  break;
463  }
464  case WID_SB_CAPTION:
465  if (this->window_number == INVALID_COMPANY) {
466  SetDParam(0, STR_STORY_BOOK_SPECTATOR_CAPTION);
467  } else {
468  SetDParam(0, STR_STORY_BOOK_CAPTION);
469  SetDParam(1, this->window_number);
470  }
471  break;
472  }
473  }
474 
475  void OnPaint() override
476  {
477  /* Detect if content has changed height. This can happen if a
478  * multi-line text contains eg. {COMPANY} and that company is
479  * renamed.
480  */
481  if (this->vscroll->GetCount() != this->GetContentHeight()) {
482  this->vscroll->SetCount(this->GetContentHeight());
485  }
486 
487  this->DrawWidgets();
488  }
489 
490  void DrawWidget(const Rect &r, int widget) const override
491  {
492  if (widget != WID_SB_PAGE_PANEL) return;
493 
494  StoryPage *page = this->GetSelPage();
495  if (page == nullptr) return;
496 
497  const int x = r.left + WD_FRAMETEXT_LEFT;
498  const int y = r.top + WD_FRAMETEXT_TOP;
499  const int right = r.right - WD_FRAMETEXT_RIGHT;
500  const int bottom = r.bottom - WD_FRAMETEXT_BOTTOM;
501 
502  /* Set up a clipping region for the panel. */
503  DrawPixelInfo tmp_dpi;
504  if (!FillDrawPixelInfo(&tmp_dpi, x, y, right - x + 1, bottom - y + 1)) return;
505 
506  DrawPixelInfo *old_dpi = _cur_dpi;
507  _cur_dpi = &tmp_dpi;
508 
509  /* Draw content (now coordinates given to Draw** are local to the new clipping region). */
510  int line_height = FONT_HEIGHT_NORMAL;
511  int y_offset = - this->vscroll->GetPosition();
512 
513  /* Date */
514  if (page->date != INVALID_DATE) {
515  SetDParam(0, page->date);
516  DrawString(0, right - x, y_offset, STR_JUST_DATE_LONG, TC_BLACK);
517  }
518  y_offset += line_height;
519 
520  /* Title */
521  SetDParamStr(0, page->title != nullptr ? page->title : this->selected_generic_title);
522  y_offset = DrawStringMultiLine(0, right - x, y_offset, bottom - y, STR_STORY_BOOK_TITLE, TC_BLACK, SA_TOP | SA_HOR_CENTER);
523 
524  /* Page elements */
525  for (const StoryPageElement *const pe : this->story_page_elements) {
526  y_offset += line_height; // margin to previous element
527 
528  switch (pe->type) {
529  case SPET_TEXT:
530  SetDParamStr(0, pe->text);
531  y_offset = DrawStringMultiLine(0, right - x, y_offset, bottom - y, STR_JUST_RAW_STRING, TC_BLACK, SA_TOP | SA_LEFT);
532  break;
533 
534  case SPET_GOAL: {
535  Goal *g = Goal::Get((GoalID) pe->referenced_id);
536  StringID string_id = g == nullptr ? STR_STORY_BOOK_INVALID_GOAL_REF : STR_JUST_RAW_STRING;
537  if (g != nullptr) SetDParamStr(0, g->text);
538  DrawActionElement(y_offset, right - x, line_height, GetPageElementSprite(*pe), string_id);
539  break;
540  }
541 
542  case SPET_LOCATION:
543  SetDParamStr(0, pe->text);
544  DrawActionElement(y_offset, right - x, line_height, GetPageElementSprite(*pe));
545  break;
546 
547  default: NOT_REACHED();
548  }
549  }
550 
551  /* Restore clipping region. */
552  _cur_dpi = old_dpi;
553  }
554 
555  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
556  {
557  if (widget != WID_SB_SEL_PAGE && widget != WID_SB_PAGE_PANEL) return;
558 
559  Dimension d;
560  d.height = FONT_HEIGHT_NORMAL;
561  d.width = 0;
562 
563  switch (widget) {
564  case WID_SB_SEL_PAGE: {
565 
566  /* Get max title width. */
567  for (uint16 i = 0; i < this->story_pages.size(); i++) {
568  const StoryPage *s = this->story_pages[i];
569 
570  if (s->title != nullptr) {
571  SetDParamStr(0, s->title);
572  } else {
573  SetDParamStr(0, this->selected_generic_title);
574  }
575  Dimension title_d = GetStringBoundingBox(STR_BLACK_RAW_STRING);
576 
577  if (title_d.width > d.width) {
578  d.width = title_d.width;
579  }
580  }
581 
582  d.width += padding.width;
583  d.height += padding.height;
584  *size = maxdim(*size, d);
585  break;
586  }
587 
588  case WID_SB_PAGE_PANEL: {
589  d.height *= 5;
590  d.height += padding.height + WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM;
591  *size = maxdim(*size, d);
592  break;
593  }
594  }
595 
596  }
597 
598  void OnResize() override
599  {
601  this->vscroll->SetCount(this->GetContentHeight());
602  }
603 
604  void OnClick(Point pt, int widget, int click_count) override
605  {
606  switch (widget) {
607  case WID_SB_SEL_PAGE: {
608  DropDownList list = this->BuildDropDownList();
609  if (!list.empty()) {
610  /* Get the index of selected page. */
611  int selected = 0;
612  for (uint16 i = 0; i < this->story_pages.size(); i++) {
613  const StoryPage *p = this->story_pages[i];
614  if (p->index == this->selected_page_id) break;
615  selected++;
616  }
617 
618  ShowDropDownList(this, std::move(list), selected, widget);
619  }
620  break;
621  }
622 
623  case WID_SB_PREV_PAGE:
624  this->SelectPrevPage();
625  break;
626 
627  case WID_SB_NEXT_PAGE:
628  this->SelectNextPage();
629  break;
630 
631  case WID_SB_PAGE_PANEL: {
632  uint clicked_y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SB_PAGE_PANEL, WD_FRAMETEXT_TOP);
633  uint max_width = GetAvailablePageContentWidth();
634 
635  /* Skip head rows. */
636  uint head_height = this->GetHeadHeight(max_width);
637  if (clicked_y < head_height) return;
638 
639  /* Detect if a page element was clicked. */
640  uint y = head_height;
641  uint element_vertical_dist = FONT_HEIGHT_NORMAL;
642  for (const StoryPageElement *const pe : this->story_page_elements) {
643 
644  y += element_vertical_dist; // margin row
645 
646  uint content_height = GetPageElementHeight(*pe, max_width);
647  if (clicked_y >= y && clicked_y < y + content_height) {
648  this->OnPageElementClick(*pe);
649  return;
650  }
651 
652  y += content_height;
653  }
654  }
655  }
656  }
657 
658  void OnDropdownSelect(int widget, int index) override
659  {
660  if (widget != WID_SB_SEL_PAGE) return;
661 
662  /* index (which is set in BuildDropDownList) is the page id. */
663  this->SetSelectedPage(index);
664  }
665 
673  void OnInvalidateData(int data = 0, bool gui_scope = true) override
674  {
675  if (!gui_scope) return;
676 
677  /* If added/removed page, force rebuild. Sort order never change so just a
678  * re-sort is never needed.
679  */
680  if (data == -1) {
681  this->story_pages.ForceRebuild();
682  this->BuildStoryPageList();
683 
684  /* Was the last page removed? */
685  if (this->story_pages.size() == 0) {
686  this->selected_generic_title[0] = '\0';
687  }
688 
689  /* Verify page selection. */
690  if (!_story_page_pool.IsValidID(this->selected_page_id)) {
691  this->selected_page_id = INVALID_STORY_PAGE;
692  }
693  if (this->selected_page_id == INVALID_STORY_PAGE && this->story_pages.size() > 0) {
694  /* No page is selected, but there exist at least one available.
695  * => Select first page.
696  */
697  this->SetSelectedPage(this->story_pages[0]->index);
698  }
699 
700  this->SetWidgetDisabledState(WID_SB_SEL_PAGE, this->story_pages.size() == 0);
703  } else if (data >= 0 && this->selected_page_id == data) {
704  this->RefreshSelectedPage();
705  }
706  }
707 };
708 
709 GUIStoryPageList::SortFunction * const StoryBookWindow::page_sorter_funcs[] = {
711 };
712 
713 GUIStoryPageElementList::SortFunction * const StoryBookWindow::page_element_sorter_funcs[] = {
715 };
716 
717 static const NWidgetPart _nested_story_book_widgets[] = {
719  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
720  NWidget(WWT_CAPTION, COLOUR_BROWN, WID_SB_CAPTION), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
721  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
722  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
723  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
724  EndContainer(),
726  NWidget(NWID_VERTICAL), SetFill(1, 1),
729  NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_SB_PREV_PAGE), SetMinimalSize(100, 0), SetFill(0, 0), SetDataTip(STR_STORY_BOOK_PREV_PAGE, STR_STORY_BOOK_PREV_PAGE_TOOLTIP),
730  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_BROWN, WID_SB_SEL_PAGE), SetMinimalSize(93, 12), SetFill(1, 0),
731  SetDataTip(STR_BLACK_RAW_STRING, STR_STORY_BOOK_SEL_PAGE_TOOLTIP), SetResize(1, 0),
732  NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_SB_NEXT_PAGE), SetMinimalSize(100, 0), SetFill(0, 0), SetDataTip(STR_STORY_BOOK_NEXT_PAGE, STR_STORY_BOOK_NEXT_PAGE_TOOLTIP),
733  EndContainer(),
734  EndContainer(),
735  NWidget(NWID_VERTICAL), SetFill(0, 1),
736  NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_SB_SCROLLBAR),
737  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
738  EndContainer(),
739  EndContainer(),
740 };
741 
742 static WindowDesc _story_book_desc(
743  WDP_CENTER, "view_story", 400, 300,
745  0,
746  _nested_story_book_widgets, lengthof(_nested_story_book_widgets)
747 );
748 
754 void ShowStoryBook(CompanyID company, uint16 page_id)
755 {
756  if (!Company::IsValidID(company)) company = (CompanyID)INVALID_COMPANY;
757 
758  StoryBookWindow *w = AllocateWindowDescFront<StoryBookWindow>(&_story_book_desc, company, true);
759  if (page_id != INVALID_STORY_PAGE) w->SetSelectedPage(page_id);
760 }
Functions related to OTTD&#39;s strings.
Owner
Enum for all companies/owners.
Definition: company_type.h:20
Page body.
Definition: story_widget.h:20
Base types for having sorted lists in GUIs.
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition of stuff that is very close to a company, like the company struct itself.
Caption of the window.
Definition: story_widget.h:18
Data about how and where to blit pixels.
Definition: gfx_type.h:156
Horizontally center the text.
Definition: gfx_func.h:97
ResizeInfo resize
Resize information.
Definition: window_gui.h:324
An element that references a tile along with a one-line text.
Definition: story_base.h:32
void OnResize() override
Called after the window got resized.
Definition: story_gui.cpp:598
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:930
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1851
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:394
void SelectPrevPage()
Selects the previous available page before the currently selected page.
Definition: story_gui.cpp:190
High level window description.
Definition: window_gui.h:168
StoryPageID page
Id of the page which the page element belongs to.
Definition: story_base.h:48
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:604
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
Functions related to dates.
Scrollbar data structure.
Definition: widget_type.h:589
uint16 GoalID
ID of a goal.
Definition: goal_type.h:33
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:581
Horizontal container.
Definition: widget_type.h:75
void UpdatePrevNextDisabledState()
Updates the disabled state of the prev/next buttons.
Definition: story_gui.cpp:435
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
void OnPageElementClick(const StoryPageElement &pe)
Internal event handler for when a page element is clicked.
Definition: story_gui.cpp:384
uint32 sort_value
A number that increases for every created story page element. Used for sorting. The id of a story pag...
Definition: story_base.h:47
bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:122
Date date
Date when the page was created.
Definition: story_base.h:71
int GetSelPageNum() const
Get the page number of selected page.
Definition: story_gui.cpp:130
bool IsLastPageSelected()
Check if the selected page is also the last available page.
Definition: story_gui.cpp:156
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
Struct about goals, current and completed.
Definition: goal_base.h:23
void ShowGoalsList(CompanyID company)
Open a goal list window.
Definition: goal_gui.cpp:351
void RefreshSelectedPage()
Updates the content of selected page.
Definition: story_gui.cpp:169
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:547
Close box (at top-left of a window)
Definition: widget_type.h:69
Page selector.
Definition: story_widget.h:19
char * title
Title of story page.
Definition: story_base.h:74
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: story_gui.cpp:456
#define lastof(x)
Get the last element of an fixed size array.
Definition: depend.cpp:50
void SelectNextPage()
Selects the next available page after the currently selected page.
Definition: story_gui.cpp:210
void BuildStoryPageList()
(Re)Build story page list.
Definition: story_gui.cpp:52
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:26
char selected_generic_title[255]
If the selected page doesn&#39;t have a custom title, this buffer is used to store a generic page title...
Definition: story_gui.cpp:46
Common string list item.
Definition: dropdown_type.h:41
uint GetContentHeight()
Get the total height of the content displayed in this window.
Definition: story_gui.cpp:336
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1812
bool NeedRebuild() const
Check if a rebuild is needed.
Functions, definitions and such used only by the GUI.
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
Definition: gfx.cpp:1478
void OnPaint() override
The window must be repainted.
Definition: story_gui.cpp:475
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:670
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:910
Functions related to (drawing on) viewports.
void ForceRebuild()
Force that a rebuild is needed.
Struct about story page elements.
Definition: story_base.h:46
Data structure for an opened window.
Definition: window_gui.h:278
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:37
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1828
uint32 referenced_id
Id of referenced object (location, goal etc.)
Definition: story_base.h:51
Bottom offset of the text of the frame.
Definition: window_gui.h:75
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:281
Struct about stories, current and completed.
Definition: story_base.h:69
StoryPageID selected_page_id
Pool index of selected page.
Definition: story_gui.cpp:45
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
Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:111
void SetSelectedPage(uint16 page_index)
Sets the selected page.
Definition: story_gui.cpp:447
GUIStoryPageElementList story_page_elements
Sorted list of page elements that belong to the current page.
Definition: story_gui.cpp:44
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:178
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
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.
static const Date INVALID_DATE
Representation of an invalid date.
Definition: date_type.h:110
Top align the text.
Definition: gfx_func.h:101
A number of safeguards to prevent using unsafe methods.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: story_gui.cpp:490
Geometry functions.
Simple depressed panel.
Definition: widget_type.h:50
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:311
SpriteID GetPageElementSprite(const StoryPageElement &pe) const
Decides which sprite to display for a given page element.
Definition: story_gui.cpp:290
StoryPageElementType type
Type of page element.
Definition: story_base.h:49
Center the window.
Definition: window_gui.h:157
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
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: story_gui.cpp:673
uint GetPageElementHeight(const StoryPageElement &pe, int max_width)
Get the height in pixels used by a page element.
Definition: story_gui.cpp:311
Next button.
Definition: story_widget.h:23
Button with a drop-down.
Definition: widget_type.h:82
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:499
Right offset of the text of the frame.
Definition: window_gui.h:73
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
bool IsFirstPageSelected()
Check if the selected page is also the first available page.
Definition: story_gui.cpp:145
Top offset of the text of the frame.
Definition: window_gui.h:74
Left offset of the text of the frame.
Definition: window_gui.h:72
bool Sort(SortFunction *compare)
Sort the list.
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: story_gui.cpp:555
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
uint32 sort_value
A number that increases for every created story page. Used for sorting. The id of a story page is the...
Definition: story_base.h:70
uint GetHeadHeight(int max_width) const
Counts how many pixels of height that are used by Date and Title (excluding marginal after Title...
Definition: story_gui.cpp:270
Scrollbar * vscroll
Scrollbar of the page text.
Definition: story_gui.cpp:41
void ShowExtraViewPortWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
static const StoryPageID INVALID_STORY_PAGE
Constant representing a non-existing story page.
Definition: story_type.h:25
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:698
An element that references a goal.
Definition: story_base.h:33
uint16 GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:613
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
Types related to the story widgets.
A text element.
Definition: story_base.h:31
Functions related to companies.
An invalid company.
Definition: company_type.h:32
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
uint GetAvailablePageContentWidth()
Get the width available for displaying content on the page panel.
Definition: story_gui.cpp:258
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:19
StoryPage * GetSelPage() const
Get instance of selected page.
Definition: story_gui.cpp:120
void SetStepSize(uint16 stepsize)
Set the distance to scroll when using the buttons or the wheel.
Definition: widget_type.h:659
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
static bool PageOrderSorter(const StoryPage *const &a, const StoryPage *const &b)
Sort story pages by order value.
Definition: story_gui.cpp:72
Story book; Window numbers:
Definition: window_type.h:291
void ShowStoryBook(CompanyID company, uint16 page_id)
Raise or create the story book window for company, at page page_id.
Definition: story_gui.cpp:754
GUIStoryPageList story_pages
Sorted list of pages.
Definition: story_gui.cpp:43
bool completed
Is the goal completed or not?
Definition: goal_base.h:29
Vertical container.
Definition: widget_type.h:77
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
Scrollbar of the goal list.
Definition: story_widget.h:21
Goal base class.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2417
Functions related to commands.
Coordinates of a point in 2D.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:767
List item containing a C char string.
Definition: dropdown_type.h:71
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:235
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable...
Definition: window_gui.h:326
StoryPage base class.
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:66
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:321
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: story_gui.cpp:658
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:983
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:707
char * text
Static content text of page element.
Definition: story_base.h:52
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
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:314
char * text
Text of the goal.
Definition: goal_base.h:27
Left align the text.
Definition: gfx_func.h:96
Window functions not directly related to making/drawing windows.
DropDownList BuildDropDownList() const
Builds the page selector drop down list.
Definition: story_gui.cpp:231
String list item with parameters.
Definition: dropdown_type.h:58
GUI functions that shouldn&#39;t be here.
bool SortFunction(const T &, const T &)
Signature of sort function.
Definition: sortlist_type.h:51
uint16 StoryPageID
ID of a story page.
Definition: story_type.h:18
static bool PageElementOrderSorter(const StoryPageElement *const &a, const StoryPageElement *const &b)
Sort story page elements by order value.
Definition: story_gui.cpp:101
CompanyID company
StoryPage is for a specific company; INVALID_COMPANY if it is global.
Definition: story_base.h:72
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1095
void BuildStoryPageElementList()
(Re)Build story page element list.
Definition: story_gui.cpp:78
Dimensions (a width and height) of a rectangle in 2D.
This file contains all sprite-related enums and defines.
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:64
void DrawActionElement(int &y_offset, int width, int line_height, SpriteID action_sprite, StringID string_id=STR_JUST_RAW_STRING) const
Draws a page element that is composed of a sprite to the left and a single line of text after that...
Definition: story_gui.cpp:366
Prev button.
Definition: story_widget.h:22
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:832
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:322
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:620
(Toggle) Button with text
Definition: widget_type.h:55
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
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: story_gui.cpp:604