OpenTTD Source  13.0-beta1
story_gui.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #include "stdafx.h"
11 #include "window_gui.h"
12 #include "strings_func.h"
13 #include "date_func.h"
14 #include "gui.h"
15 #include "story_base.h"
16 #include "core/geometry_func.hpp"
17 #include "company_func.h"
18 #include "command_func.h"
19 #include "widgets/dropdown_type.h"
20 #include "widgets/dropdown_func.h"
21 #include "sortlist_type.h"
22 #include "goal_base.h"
23 #include "viewport_func.h"
24 #include "window_func.h"
25 #include "company_base.h"
26 #include "tilehighlight_func.h"
27 #include "vehicle_base.h"
28 #include "story_cmd.h"
29 
30 #include "widgets/story_widget.h"
31 
32 #include "table/strings.h"
33 #include "table/sprites.h"
34 
35 #include <numeric>
36 
37 #include "safeguards.h"
38 
39 static CursorID TranslateStoryPageButtonCursor(StoryPageButtonCursor cursor);
40 
43 
45 protected:
47  const StoryPageElement *pe;
48  Rect bounds;
49  };
50  typedef std::vector<LayoutCacheElement> LayoutCache;
51 
52  enum class ElementFloat {
53  None,
54  Left,
55  Right,
56  };
57 
59  mutable LayoutCache layout_cache;
60 
65 
67 
68  static GUIStoryPageList::SortFunction * const page_sorter_funcs[];
69  static GUIStoryPageElementList::SortFunction * const page_element_sorter_funcs[];
70 
73  {
74  if (this->story_pages.NeedRebuild()) {
75  this->story_pages.clear();
76 
77  for (const StoryPage *p : StoryPage::Iterate()) {
78  if (this->IsPageAvailable(p)) {
79  this->story_pages.push_back(p);
80  }
81  }
82 
83  this->story_pages.shrink_to_fit();
84  this->story_pages.RebuildDone();
85  }
86 
87  this->story_pages.Sort();
88  }
89 
91  static bool PageOrderSorter(const StoryPage * const &a, const StoryPage * const &b)
92  {
93  return a->sort_value < b->sort_value;
94  }
95 
98  {
99  if (this->story_page_elements.NeedRebuild()) {
100  this->story_page_elements.clear();
101 
102  const StoryPage *p = GetSelPage();
103  if (p != nullptr) {
104  for (const StoryPageElement *pe : StoryPageElement::Iterate()) {
105  if (pe->page == p->index) {
106  this->story_page_elements.push_back(pe);
107  }
108  }
109  }
110 
111  this->story_page_elements.shrink_to_fit();
112  this->story_page_elements.RebuildDone();
113  }
114 
115  this->story_page_elements.Sort();
117  }
118 
120  static bool PageElementOrderSorter(const StoryPageElement * const &a, const StoryPageElement * const &b)
121  {
122  return a->sort_value < b->sort_value;
123  }
124 
125  /*
126  * Checks if a given page should be visible in the story book.
127  * @param page The page to check.
128  * @return True if the page should be visible, otherwise false.
129  */
130  bool IsPageAvailable(const StoryPage *page) const
131  {
132  return page->company == INVALID_COMPANY || page->company == this->window_number;
133  }
134 
140  {
141  if (!_story_page_pool.IsValidID(selected_page_id)) return nullptr;
142  return _story_page_pool.Get(selected_page_id);
143  }
144 
149  int GetSelPageNum() const
150  {
151  int page_number = 0;
152  for (const StoryPage *p : this->story_pages) {
153  if (p->index == this->selected_page_id) {
154  return page_number;
155  }
156  page_number++;
157  }
158  return -1;
159  }
160 
165  {
166  /* Verify that the selected page exist. */
167  if (!_story_page_pool.IsValidID(this->selected_page_id)) return false;
168 
169  return this->story_pages.front()->index == this->selected_page_id;
170  }
171 
176  {
177  /* Verify that the selected page exist. */
178  if (!_story_page_pool.IsValidID(this->selected_page_id)) return false;
179 
180  if (this->story_pages.size() <= 1) return true;
181  const StoryPage *last = this->story_pages.back();
182  return last->index == this->selected_page_id;
183  }
184 
189  {
190  /* Generate generic title if selected page have no custom title. */
191  StoryPage *page = this->GetSelPage();
192  if (page != nullptr && page->title == nullptr) {
193  SetDParam(0, GetSelPageNum() + 1);
194  GetString(selected_generic_title, STR_STORY_BOOK_GENERIC_PAGE_ITEM, lastof(selected_generic_title));
195  }
196 
197  this->story_page_elements.ForceRebuild();
199 
200  if (this->active_button_id != INVALID_STORY_PAGE_ELEMENT) ResetObjectToPlace();
201 
202  this->vscroll->SetCount(this->GetContentHeight());
206  }
207 
212  {
213  if (!_story_page_pool.IsValidID(this->selected_page_id)) return;
214 
215  /* Find the last available page which is previous to the current selected page. */
216  const StoryPage *last_available;
217  last_available = nullptr;
218  for (const StoryPage *p : this->story_pages) {
219  if (p->index == this->selected_page_id) {
220  if (last_available == nullptr) return; // No previous page available.
221  this->SetSelectedPage(last_available->index);
222  return;
223  }
224  last_available = p;
225  }
226  }
227 
232  {
233  if (!_story_page_pool.IsValidID(this->selected_page_id)) return;
234 
235  /* Find selected page. */
236  for (auto iter = this->story_pages.begin(); iter != this->story_pages.end(); iter++) {
237  const StoryPage *p = *iter;
238  if (p->index == this->selected_page_id) {
239  /* Select the page after selected page. */
240  iter++;
241  if (iter != this->story_pages.end()) {
242  this->SetSelectedPage((*iter)->index);
243  }
244  return;
245  }
246  }
247  }
248 
253  {
254  DropDownList list;
255  uint16 page_num = 1;
256  for (const StoryPage *p : this->story_pages) {
257  bool current_page = p->index == this->selected_page_id;
258  DropDownListStringItem *item = nullptr;
259  if (p->title != nullptr) {
260  item = new DropDownListCharStringItem(p->title, p->index, current_page);
261  } else {
262  /* No custom title => use a generic page title with page number. */
263  DropDownListParamStringItem *str_item =
264  new DropDownListParamStringItem(STR_STORY_BOOK_GENERIC_PAGE_ITEM, p->index, current_page);
265  str_item->SetParam(0, page_num);
266  item = str_item;
267  }
268 
269  list.emplace_back(item);
270  page_num++;
271  }
272 
273  return list;
274  }
275 
280  {
281  return this->GetWidget<NWidgetCore>(WID_SB_PAGE_PANEL)->current_x - WD_FRAMETEXT_LEFT - WD_FRAMETEXT_RIGHT - 1;
282  }
283 
291  uint GetHeadHeight(int max_width) const
292  {
293  StoryPage *page = this->GetSelPage();
294  if (page == nullptr) return 0;
295  int height = 0;
296 
297  /* Title lines */
298  height += FONT_HEIGHT_NORMAL; // Date always use exactly one line.
299  SetDParamStr(0, page->title != nullptr ? page->title : this->selected_generic_title);
300  height += GetStringHeight(STR_STORY_BOOK_TITLE, max_width);
301 
302  return height;
303  }
304 
312  {
313  switch (pe.type) {
314  case SPET_GOAL: {
315  Goal *g = Goal::Get((GoalID) pe.referenced_id);
316  if (g == nullptr) return SPR_IMG_GOAL_BROKEN_REF;
317  return g->completed ? SPR_IMG_GOAL_COMPLETED : SPR_IMG_GOAL;
318  }
319  case SPET_LOCATION:
320  return SPR_IMG_VIEW_LOCATION;
321  default:
322  NOT_REACHED();
323  }
324  }
325 
332  uint GetPageElementHeight(const StoryPageElement &pe, int max_width) const
333  {
334  switch (pe.type) {
335  case SPET_TEXT:
336  SetDParamStr(0, pe.text);
337  return GetStringHeight(STR_BLACK_RAW_STRING, max_width);
338 
339  case SPET_GOAL:
340  case SPET_LOCATION: {
341  Dimension sprite_dim = GetSpriteSize(GetPageElementSprite(pe));
342  return sprite_dim.height;
343  }
344 
345  case SPET_BUTTON_PUSH:
346  case SPET_BUTTON_TILE:
347  case SPET_BUTTON_VEHICLE: {
350  }
351 
352  default:
353  NOT_REACHED();
354  }
355  return 0;
356  }
357 
363  ElementFloat GetPageElementFloat(const StoryPageElement &pe) const
364  {
365  switch (pe.type) {
366  case SPET_BUTTON_PUSH:
367  case SPET_BUTTON_TILE:
368  case SPET_BUTTON_VEHICLE: {
370  if (flags & SPBF_FLOAT_LEFT) return ElementFloat::Left;
371  if (flags & SPBF_FLOAT_RIGHT) return ElementFloat::Right;
372  return ElementFloat::None;
373  }
374 
375  default:
376  return ElementFloat::None;
377  }
378  }
379 
386  {
387  switch (pe.type) {
388  case SPET_BUTTON_PUSH:
389  case SPET_BUTTON_TILE:
390  case SPET_BUTTON_VEHICLE: {
393  }
394 
395  default:
396  NOT_REACHED(); // only buttons can float
397  }
398  }
399 
402  {
403  this->layout_cache.clear();
404  }
405 
408  {
409  /* Assume if the layout cache has contents it is valid */
410  if (!this->layout_cache.empty()) return;
411 
412  StoryPage *page = this->GetSelPage();
413  if (page == nullptr) return;
414  int max_width = GetAvailablePageContentWidth();
415  int element_dist = FONT_HEIGHT_NORMAL;
416 
417  /* Make space for the header */
418  int main_y = GetHeadHeight(max_width) + element_dist;
419 
420  /* Current bottom of left/right column */
421  int left_y = main_y;
422  int right_y = main_y;
423  /* Current width of left/right column, 0 indicates no content in column */
424  int left_width = 0;
425  int right_width = 0;
426  /* Indexes into element cache for yet unresolved floats */
427  std::vector<size_t> left_floats;
428  std::vector<size_t> right_floats;
429 
430  /* Build layout */
431  for (const StoryPageElement *pe : this->story_page_elements) {
432  ElementFloat fl = this->GetPageElementFloat(*pe);
433 
434  if (fl == ElementFloat::None) {
435  /* Verify available width */
436  const int min_required_width = 10 * FONT_HEIGHT_NORMAL;
437  int left_offset = (left_width == 0) ? 0 : (left_width + element_dist);
438  int right_offset = (right_width == 0) ? 0 : (right_width + element_dist);
439  if (left_offset + right_offset + min_required_width >= max_width) {
440  /* Width of floats leave too little for main content, push down */
441  main_y = std::max(main_y, left_y);
442  main_y = std::max(main_y, right_y);
443  left_width = right_width = 0;
444  left_offset = right_offset = 0;
445  /* Do not add element_dist here, to keep together elements which were supposed to float besides each other. */
446  }
447  /* Determine height */
448  const int available_width = max_width - left_offset - right_offset;
449  const int height = GetPageElementHeight(*pe, available_width);
450  /* Check for button that needs extra margin */
451  if (left_offset == 0 && right_offset == 0) {
452  switch (pe->type) {
453  case SPET_BUTTON_PUSH:
454  case SPET_BUTTON_TILE:
455  case SPET_BUTTON_VEHICLE:
456  left_offset = right_offset = available_width / 5;
457  break;
458  default:
459  break;
460  }
461  }
462  /* Position element in main column */
463  LayoutCacheElement ce{ pe, {} };
464  ce.bounds.left = left_offset;
465  ce.bounds.right = max_width - right_offset;
466  ce.bounds.top = main_y;
467  main_y += height;
468  ce.bounds.bottom = main_y;
469  this->layout_cache.push_back(ce);
470  main_y += element_dist;
471  /* Clear all floats */
472  left_width = right_width = 0;
473  left_y = right_y = main_y = std::max({main_y, left_y, right_y});
474  left_floats.clear();
475  right_floats.clear();
476  } else {
477  /* Prepare references to correct column */
478  int &cur_width = (fl == ElementFloat::Left) ? left_width : right_width;
479  int &cur_y = (fl == ElementFloat::Left) ? left_y : right_y;
480  std::vector<size_t> &cur_floats = (fl == ElementFloat::Left) ? left_floats : right_floats;
481  /* Position element */
482  cur_width = std::max(cur_width, this->GetPageElementFloatWidth(*pe));
483  LayoutCacheElement ce{ pe, {} };
484  ce.bounds.left = (fl == ElementFloat::Left) ? 0 : (max_width - cur_width);
485  ce.bounds.right = (fl == ElementFloat::Left) ? cur_width : max_width;
486  ce.bounds.top = cur_y;
487  cur_y += GetPageElementHeight(*pe, cur_width);
488  ce.bounds.bottom = cur_y;
489  cur_floats.push_back(this->layout_cache.size());
490  this->layout_cache.push_back(ce);
491  cur_y += element_dist;
492  /* Update floats in column to all have the same width */
493  for (size_t index : cur_floats) {
494  LayoutCacheElement &ce = this->layout_cache[index];
495  ce.bounds.left = (fl == ElementFloat::Left) ? 0 : (max_width - cur_width);
496  ce.bounds.right = (fl == ElementFloat::Left) ? cur_width : max_width;
497  }
498  }
499  }
500  }
501 
507  {
509 
510  /* The largest bottom coordinate of any element is the height of the content */
511  uint max_y = std::accumulate(this->layout_cache.begin(), this->layout_cache.end(), 0, [](uint max_y, const LayoutCacheElement &ce) -> uint { return std::max<uint>(max_y, ce.bounds.bottom); });
512 
513  return max_y;
514  }
515 
527  void DrawActionElement(int &y_offset, int width, int line_height, SpriteID action_sprite, StringID string_id = STR_JUST_RAW_STRING) const
528  {
529  Dimension sprite_dim = GetSpriteSize(action_sprite);
530  uint element_height = std::max(sprite_dim.height, (uint)line_height);
531 
532  uint sprite_top = y_offset + (element_height - sprite_dim.height) / 2;
533  uint text_top = y_offset + (element_height - line_height) / 2;
534 
535  DrawSprite(action_sprite, PAL_NONE, 0, sprite_top);
536  DrawString(sprite_dim.width + WD_FRAMETEXT_LEFT, width, text_top, string_id, TC_BLACK);
537 
538  y_offset += element_height;
539  }
540 
546  {
547  switch (pe.type) {
548  case SPET_TEXT:
549  /* Do nothing. */
550  break;
551 
552  case SPET_LOCATION:
553  if (_ctrl_pressed) {
555  } else {
557  }
558  break;
559 
560  case SPET_GOAL:
562  break;
563 
564  case SPET_BUTTON_PUSH:
565  if (this->active_button_id != INVALID_STORY_PAGE_ELEMENT) ResetObjectToPlace();
566  this->active_button_id = pe.index;
567  this->SetTimeout();
569 
571  break;
572 
573  case SPET_BUTTON_TILE:
574  if (this->active_button_id == pe.index) {
576  this->active_button_id = INVALID_STORY_PAGE_ELEMENT;
577  } else {
578  CursorID cursor = TranslateStoryPageButtonCursor(StoryPageButtonData{ pe.referenced_id }.GetCursor());
579  SetObjectToPlaceWnd(cursor, PAL_NONE, HT_RECT, this);
580  this->active_button_id = pe.index;
581  }
583  break;
584 
585  case SPET_BUTTON_VEHICLE:
586  if (this->active_button_id == pe.index) {
588  this->active_button_id = INVALID_STORY_PAGE_ELEMENT;
589  } else {
590  CursorID cursor = TranslateStoryPageButtonCursor(StoryPageButtonData{ pe.referenced_id }.GetCursor());
591  SetObjectToPlaceWnd(cursor, PAL_NONE, HT_VEHICLE, this);
592  this->active_button_id = pe.index;
593  }
595  break;
596 
597  default:
598  NOT_REACHED();
599  }
600  }
601 
602 public:
604  {
605  this->CreateNestedTree();
606  this->vscroll = this->GetScrollbar(WID_SB_SCROLLBAR);
607  this->vscroll->SetStepSize(FONT_HEIGHT_NORMAL);
608 
609  /* Initialize page sort. */
610  this->story_pages.SetSortFuncs(StoryBookWindow::page_sorter_funcs);
611  this->story_pages.ForceRebuild();
612  this->BuildStoryPageList();
613  this->story_page_elements.SetSortFuncs(StoryBookWindow::page_element_sorter_funcs);
614  /* story_page_elements will get built by SetSelectedPage */
615 
616  this->FinishInitNested(window_number);
617  this->owner = (Owner)this->window_number;
618 
619  /* Initialize selected vars. */
620  this->selected_generic_title[0] = '\0';
621  this->selected_page_id = INVALID_STORY_PAGE;
622 
623  this->active_button_id = INVALID_STORY_PAGE_ELEMENT;
624 
625  this->OnInvalidateData(-1);
626  }
627 
632  {
633  this->SetWidgetDisabledState(WID_SB_PREV_PAGE, story_pages.size() == 0 || this->IsFirstPageSelected());
634  this->SetWidgetDisabledState(WID_SB_NEXT_PAGE, story_pages.size() == 0 || this->IsLastPageSelected());
637  }
638 
643  void SetSelectedPage(uint16 page_index)
644  {
645  if (this->selected_page_id != page_index) {
646  if (this->active_button_id) ResetObjectToPlace();
647  this->active_button_id = INVALID_STORY_PAGE_ELEMENT;
648  this->selected_page_id = page_index;
649  this->RefreshSelectedPage();
651  }
652  }
653 
654  void SetStringParameters(int widget) const override
655  {
656  switch (widget) {
657  case WID_SB_SEL_PAGE: {
658  StoryPage *page = this->GetSelPage();
659  SetDParamStr(0, page != nullptr && page->title != nullptr ? page->title : this->selected_generic_title);
660  break;
661  }
662  case WID_SB_CAPTION:
663  if (this->window_number == INVALID_COMPANY) {
664  SetDParam(0, STR_STORY_BOOK_SPECTATOR_CAPTION);
665  } else {
666  SetDParam(0, STR_STORY_BOOK_CAPTION);
667  SetDParam(1, this->window_number);
668  }
669  break;
670  }
671  }
672 
673  void OnPaint() override
674  {
675  /* Detect if content has changed height. This can happen if a
676  * multi-line text contains eg. {COMPANY} and that company is
677  * renamed.
678  */
679  if (this->vscroll->GetCount() != this->GetContentHeight()) {
680  this->vscroll->SetCount(this->GetContentHeight());
683  }
684 
685  this->DrawWidgets();
686  }
687 
688  void DrawWidget(const Rect &r, int widget) const override
689  {
690  if (widget != WID_SB_PAGE_PANEL) return;
691 
692  StoryPage *page = this->GetSelPage();
693  if (page == nullptr) return;
694 
695  const int x = r.left + WD_FRAMETEXT_LEFT;
696  const int y = r.top + WD_FRAMETEXT_TOP;
697  const int right = r.right - WD_FRAMETEXT_RIGHT;
698  const int bottom = r.bottom - WD_FRAMETEXT_BOTTOM;
699 
700  /* Set up a clipping region for the panel. */
701  DrawPixelInfo tmp_dpi;
702  if (!FillDrawPixelInfo(&tmp_dpi, x, y, right - x + 1, bottom - y + 1)) return;
703 
704  DrawPixelInfo *old_dpi = _cur_dpi;
705  _cur_dpi = &tmp_dpi;
706 
707  /* Draw content (now coordinates given to Draw** are local to the new clipping region). */
708  int line_height = FONT_HEIGHT_NORMAL;
709  const int scrollpos = this->vscroll->GetPosition();
710  int y_offset = -scrollpos;
711 
712  /* Date */
713  if (page->date != INVALID_DATE) {
714  SetDParam(0, page->date);
715  DrawString(0, right - x, y_offset, STR_JUST_DATE_LONG, TC_BLACK);
716  }
717  y_offset += line_height;
718 
719  /* Title */
720  SetDParamStr(0, page->title != nullptr ? page->title : this->selected_generic_title);
721  y_offset = DrawStringMultiLine(0, right - x, y_offset, bottom - y, STR_STORY_BOOK_TITLE, TC_BLACK, SA_TOP | SA_HOR_CENTER);
722 
723  /* Page elements */
725  for (const LayoutCacheElement &ce : this->layout_cache) {
726  y_offset = ce.bounds.top - scrollpos;
727  switch (ce.pe->type) {
728  case SPET_TEXT:
729  SetDParamStr(0, ce.pe->text);
730  y_offset = DrawStringMultiLine(ce.bounds.left, ce.bounds.right, ce.bounds.top - scrollpos, ce.bounds.bottom - scrollpos, STR_JUST_RAW_STRING, TC_BLACK, SA_TOP | SA_LEFT);
731  break;
732 
733  case SPET_GOAL: {
734  Goal *g = Goal::Get((GoalID) ce.pe->referenced_id);
735  StringID string_id = g == nullptr ? STR_STORY_BOOK_INVALID_GOAL_REF : STR_JUST_RAW_STRING;
736  if (g != nullptr) SetDParamStr(0, g->text);
737  DrawActionElement(y_offset, ce.bounds.right - ce.bounds.left, line_height, GetPageElementSprite(*ce.pe), string_id);
738  break;
739  }
740 
741  case SPET_LOCATION:
742  SetDParamStr(0, ce.pe->text);
743  DrawActionElement(y_offset, ce.bounds.right - ce.bounds.left, line_height, GetPageElementSprite(*ce.pe));
744  break;
745 
746  case SPET_BUTTON_PUSH:
747  case SPET_BUTTON_TILE:
748  case SPET_BUTTON_VEHICLE: {
749  const int tmargin = WD_BEVEL_TOP + WD_FRAMETEXT_TOP;
750  const FrameFlags frame = this->active_button_id == ce.pe->index ? FR_LOWERED : FR_NONE;
751  const Colours bgcolour = StoryPageButtonData{ ce.pe->referenced_id }.GetColour();
752 
753  DrawFrameRect(ce.bounds.left, ce.bounds.top - scrollpos, ce.bounds.right, ce.bounds.bottom - scrollpos - 1, bgcolour, frame);
754 
755  SetDParamStr(0, ce.pe->text);
756  DrawString(ce.bounds.left + WD_BEVEL_LEFT, ce.bounds.right - WD_BEVEL_RIGHT, ce.bounds.top + tmargin - scrollpos, STR_JUST_RAW_STRING, TC_WHITE, SA_CENTER);
757  break;
758  }
759 
760  default: NOT_REACHED();
761  }
762  }
763 
764  /* Restore clipping region. */
765  _cur_dpi = old_dpi;
766  }
767 
768  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
769  {
770  if (widget != WID_SB_SEL_PAGE && widget != WID_SB_PAGE_PANEL) return;
771 
772  Dimension d;
773  d.height = FONT_HEIGHT_NORMAL;
774  d.width = 0;
775 
776  switch (widget) {
777  case WID_SB_SEL_PAGE: {
778 
779  /* Get max title width. */
780  for (size_t i = 0; i < this->story_pages.size(); i++) {
781  const StoryPage *s = this->story_pages[i];
782 
783  if (s->title != nullptr) {
784  SetDParamStr(0, s->title);
785  } else {
786  SetDParamStr(0, this->selected_generic_title);
787  }
788  Dimension title_d = GetStringBoundingBox(STR_BLACK_RAW_STRING);
789 
790  if (title_d.width > d.width) {
791  d.width = title_d.width;
792  }
793  }
794 
795  d.width += padding.width;
796  d.height += padding.height;
797  *size = maxdim(*size, d);
798  break;
799  }
800 
801  case WID_SB_PAGE_PANEL: {
802  d.height *= 5;
803  d.height += padding.height + WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM;
804  *size = maxdim(*size, d);
805  break;
806  }
807  }
808 
809  }
810 
811  void OnResize() override
812  {
815  this->vscroll->SetCount(this->GetContentHeight());
816  }
817 
818  void OnClick(Point pt, int widget, int click_count) override
819  {
820  switch (widget) {
821  case WID_SB_SEL_PAGE: {
822  DropDownList list = this->BuildDropDownList();
823  if (!list.empty()) {
824  /* Get the index of selected page. */
825  int selected = 0;
826  for (size_t i = 0; i < this->story_pages.size(); i++) {
827  const StoryPage *p = this->story_pages[i];
828  if (p->index == this->selected_page_id) break;
829  selected++;
830  }
831 
832  ShowDropDownList(this, std::move(list), selected, widget);
833  }
834  break;
835  }
836 
837  case WID_SB_PREV_PAGE:
838  this->SelectPrevPage();
839  break;
840 
841  case WID_SB_NEXT_PAGE:
842  this->SelectNextPage();
843  break;
844 
845  case WID_SB_PAGE_PANEL: {
846  int clicked_y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SB_PAGE_PANEL, WD_FRAMETEXT_TOP);
848 
849  for (const LayoutCacheElement &ce : this->layout_cache) {
850  if (clicked_y >= ce.bounds.top && clicked_y < ce.bounds.bottom && pt.x >= ce.bounds.left && pt.x < ce.bounds.right) {
851  this->OnPageElementClick(*ce.pe);
852  return;
853  }
854  }
855  }
856  }
857  }
858 
859  void OnDropdownSelect(int widget, int index) override
860  {
861  if (widget != WID_SB_SEL_PAGE) return;
862 
863  /* index (which is set in BuildDropDownList) is the page id. */
864  this->SetSelectedPage(index);
865  }
866 
874  void OnInvalidateData(int data = 0, bool gui_scope = true) override
875  {
876  if (!gui_scope) return;
877 
878  /* If added/removed page, force rebuild. Sort order never change so just a
879  * re-sort is never needed.
880  */
881  if (data == -1) {
882  this->story_pages.ForceRebuild();
883  this->BuildStoryPageList();
884 
885  /* Was the last page removed? */
886  if (this->story_pages.size() == 0) {
887  this->selected_generic_title[0] = '\0';
888  }
889 
890  /* Verify page selection. */
891  if (!_story_page_pool.IsValidID(this->selected_page_id)) {
892  this->selected_page_id = INVALID_STORY_PAGE;
893  }
894  if (this->selected_page_id == INVALID_STORY_PAGE && this->story_pages.size() > 0) {
895  /* No page is selected, but there exist at least one available.
896  * => Select first page.
897  */
898  this->SetSelectedPage(this->story_pages[0]->index);
899  }
900 
901  this->SetWidgetDisabledState(WID_SB_SEL_PAGE, this->story_pages.size() == 0);
904  } else if (data >= 0 && this->selected_page_id == data) {
905  this->RefreshSelectedPage();
906  }
907  }
908 
909  void OnTimeout() override
910  {
911  this->active_button_id = INVALID_STORY_PAGE_ELEMENT;
913  }
914 
915  void OnPlaceObject(Point pt, TileIndex tile) override
916  {
917  const StoryPageElement *const pe = StoryPageElement::GetIfValid(this->active_button_id);
918  if (pe == nullptr || pe->type != SPET_BUTTON_TILE) {
920  this->active_button_id = INVALID_STORY_PAGE_ELEMENT;
922  return;
923  }
924 
927  }
928 
929  bool OnVehicleSelect(const Vehicle *v) override
930  {
931  const StoryPageElement *const pe = StoryPageElement::GetIfValid(this->active_button_id);
932  if (pe == nullptr || pe->type != SPET_BUTTON_VEHICLE) {
934  this->active_button_id = INVALID_STORY_PAGE_ELEMENT;
936  return false;
937  }
938 
939  /* Check that the vehicle matches the requested type */
941  VehicleType wanted_vehtype = data.GetVehicleType();
942  if (wanted_vehtype != VEH_INVALID && wanted_vehtype != v->type) return false;
943 
946  return true;
947  }
948 
949  void OnPlaceObjectAbort() override
950  {
951  this->active_button_id = INVALID_STORY_PAGE_ELEMENT;
953  }
954 };
955 
956 GUIStoryPageList::SortFunction * const StoryBookWindow::page_sorter_funcs[] = {
957  &PageOrderSorter,
958 };
959 
960 GUIStoryPageElementList::SortFunction * const StoryBookWindow::page_element_sorter_funcs[] = {
961  &PageElementOrderSorter,
962 };
963 
964 static const NWidgetPart _nested_story_book_widgets[] = {
966  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
967  NWidget(WWT_CAPTION, COLOUR_BROWN, WID_SB_CAPTION), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
968  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
969  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
970  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
971  EndContainer(),
974  NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_SB_SCROLLBAR),
975  EndContainer(),
977  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),
978  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_BROWN, WID_SB_SEL_PAGE), SetMinimalSize(93, 12), SetFill(1, 0),
979  SetDataTip(STR_BLACK_RAW_STRING, STR_STORY_BOOK_SEL_PAGE_TOOLTIP), SetResize(1, 0),
980  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),
981  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
982  EndContainer(),
983 };
984 
985 static WindowDesc _story_book_desc(
986  WDP_CENTER, "view_story", 400, 300,
988  0,
989  _nested_story_book_widgets, lengthof(_nested_story_book_widgets)
990 );
991 
992 static CursorID TranslateStoryPageButtonCursor(StoryPageButtonCursor cursor)
993 {
994  switch (cursor) {
995  case SPBC_MOUSE: return SPR_CURSOR_MOUSE;
996  case SPBC_ZZZ: return SPR_CURSOR_ZZZ;
997  case SPBC_BUOY: return SPR_CURSOR_BUOY;
998  case SPBC_QUERY: return SPR_CURSOR_QUERY;
999  case SPBC_HQ: return SPR_CURSOR_HQ;
1000  case SPBC_SHIP_DEPOT: return SPR_CURSOR_SHIP_DEPOT;
1001  case SPBC_SIGN: return SPR_CURSOR_SIGN;
1002  case SPBC_TREE: return SPR_CURSOR_TREE;
1003  case SPBC_BUY_LAND: return SPR_CURSOR_BUY_LAND;
1004  case SPBC_LEVEL_LAND: return SPR_CURSOR_LEVEL_LAND;
1005  case SPBC_TOWN: return SPR_CURSOR_TOWN;
1006  case SPBC_INDUSTRY: return SPR_CURSOR_INDUSTRY;
1007  case SPBC_ROCKY_AREA: return SPR_CURSOR_ROCKY_AREA;
1008  case SPBC_DESERT: return SPR_CURSOR_DESERT;
1009  case SPBC_TRANSMITTER: return SPR_CURSOR_TRANSMITTER;
1010  case SPBC_AIRPORT: return SPR_CURSOR_AIRPORT;
1011  case SPBC_DOCK: return SPR_CURSOR_DOCK;
1012  case SPBC_CANAL: return SPR_CURSOR_CANAL;
1013  case SPBC_LOCK: return SPR_CURSOR_LOCK;
1014  case SPBC_RIVER: return SPR_CURSOR_RIVER;
1015  case SPBC_AQUEDUCT: return SPR_CURSOR_AQUEDUCT;
1016  case SPBC_BRIDGE: return SPR_CURSOR_BRIDGE;
1017  case SPBC_RAIL_STATION: return SPR_CURSOR_RAIL_STATION;
1018  case SPBC_TUNNEL_RAIL: return SPR_CURSOR_TUNNEL_RAIL;
1019  case SPBC_TUNNEL_ELRAIL: return SPR_CURSOR_TUNNEL_ELRAIL;
1020  case SPBC_TUNNEL_MONO: return SPR_CURSOR_TUNNEL_MONO;
1021  case SPBC_TUNNEL_MAGLEV: return SPR_CURSOR_TUNNEL_MAGLEV;
1022  case SPBC_AUTORAIL: return SPR_CURSOR_AUTORAIL;
1023  case SPBC_AUTOELRAIL: return SPR_CURSOR_AUTOELRAIL;
1024  case SPBC_AUTOMONO: return SPR_CURSOR_AUTOMONO;
1025  case SPBC_AUTOMAGLEV: return SPR_CURSOR_AUTOMAGLEV;
1026  case SPBC_WAYPOINT: return SPR_CURSOR_WAYPOINT;
1027  case SPBC_RAIL_DEPOT: return SPR_CURSOR_RAIL_DEPOT;
1028  case SPBC_ELRAIL_DEPOT: return SPR_CURSOR_ELRAIL_DEPOT;
1029  case SPBC_MONO_DEPOT: return SPR_CURSOR_MONO_DEPOT;
1030  case SPBC_MAGLEV_DEPOT: return SPR_CURSOR_MAGLEV_DEPOT;
1031  case SPBC_CONVERT_RAIL: return SPR_CURSOR_CONVERT_RAIL;
1032  case SPBC_CONVERT_ELRAIL: return SPR_CURSOR_CONVERT_ELRAIL;
1033  case SPBC_CONVERT_MONO: return SPR_CURSOR_CONVERT_MONO;
1034  case SPBC_CONVERT_MAGLEV: return SPR_CURSOR_CONVERT_MAGLEV;
1035  case SPBC_AUTOROAD: return SPR_CURSOR_AUTOROAD;
1036  case SPBC_AUTOTRAM: return SPR_CURSOR_AUTOTRAM;
1037  case SPBC_ROAD_DEPOT: return SPR_CURSOR_ROAD_DEPOT;
1038  case SPBC_BUS_STATION: return SPR_CURSOR_BUS_STATION;
1039  case SPBC_TRUCK_STATION: return SPR_CURSOR_TRUCK_STATION;
1040  case SPBC_ROAD_TUNNEL: return SPR_CURSOR_ROAD_TUNNEL;
1041  case SPBC_CLONE_TRAIN: return SPR_CURSOR_CLONE_TRAIN;
1042  case SPBC_CLONE_ROADVEH: return SPR_CURSOR_CLONE_ROADVEH;
1043  case SPBC_CLONE_SHIP: return SPR_CURSOR_CLONE_SHIP;
1044  case SPBC_CLONE_AIRPLANE: return SPR_CURSOR_CLONE_AIRPLANE;
1045  case SPBC_DEMOLISH: return ANIMCURSOR_DEMOLISH;
1046  case SPBC_LOWERLAND: return ANIMCURSOR_LOWERLAND;
1047  case SPBC_RAISELAND: return ANIMCURSOR_RAISELAND;
1048  case SPBC_PICKSTATION: return ANIMCURSOR_PICKSTATION;
1049  case SPBC_BUILDSIGNALS: return ANIMCURSOR_BUILDSIGNALS;
1050  default: return SPR_CURSOR_QUERY;
1051  }
1052 }
1053 
1059 void ShowStoryBook(CompanyID company, uint16 page_id)
1060 {
1061  if (!Company::IsValidID(company)) company = (CompanyID)INVALID_COMPANY;
1062 
1063  StoryBookWindow *w = AllocateWindowDescFront<StoryBookWindow>(&_story_book_desc, company, true);
1064  if (page_id != INVALID_STORY_PAGE) w->SetSelectedPage(page_id);
1065 }
StoryPageElement::sort_value
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:151
Pool::IsValidID
bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:120
Window::SetTimeout
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition: window_gui.h:360
SPET_TEXT
@ SPET_TEXT
A text element.
Definition: story_base.h:31
Goal
Struct about goals, current and completed.
Definition: goal_base.h:21
StoryBookWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: story_gui.cpp:818
StoryBookWindow::GetSelPageNum
int GetSelPageNum() const
Get the page number of selected page.
Definition: story_gui.cpp:149
Pool::PoolItem<&_goal_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2446
ShowGoalsList
void ShowGoalsList(CompanyID company)
Open a goal list window.
Definition: goal_gui.cpp:321
DropDownListParamStringItem
String list item with parameters.
Definition: dropdown_type.h:56
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1190
ShowExtraViewportWindow
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Definition: viewport_gui.cpp:168
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
command_func.h
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
Pool::PoolItem<&_story_page_element_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:348
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:247
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:320
dropdown_func.h
StoryBookWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: story_gui.cpp:654
StoryBookWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: story_gui.cpp:688
company_base.h
ANIMCURSOR_RAISELAND
static const CursorID ANIMCURSOR_RAISELAND
696 - 698 - raise land tool
Definition: sprites.h:1496
StoryPageButtonFlags
StoryPageButtonFlags
Flags available for buttons.
Definition: story_base.h:45
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
StoryBookWindow::GetPageElementFloatWidth
int GetPageElementFloatWidth(const StoryPageElement &pe) const
Get the width a page element would use if it was floating left or right.
Definition: story_gui.cpp:385
WID_SB_NEXT_PAGE
@ WID_SB_NEXT_PAGE
Next button.
Definition: story_widget.h:21
GUIList< const StoryPage * >
DropDownList
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Definition: dropdown_type.h:99
StoryBookWindow::GetPageElementSprite
SpriteID GetPageElementSprite(const StoryPageElement &pe) const
Decides which sprite to display for a given page element.
Definition: story_gui.cpp:311
StoryBookWindow::GetAvailablePageContentWidth
uint GetAvailablePageContentWidth() const
Get the width available for displaying content on the page panel.
Definition: story_gui.cpp:279
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
StoryBookWindow::BuildDropDownList
DropDownList BuildDropDownList() const
Builds the page selector drop down list.
Definition: story_gui.cpp:252
FrameFlags
FrameFlags
Flags to describe the look of the frame.
Definition: window_gui.h:27
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1760
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
DropDownListCharStringItem
List item containing a C char string.
Definition: dropdown_type.h:70
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
ANIMCURSOR_BUILDSIGNALS
static const CursorID ANIMCURSOR_BUILDSIGNALS
1292 - 1293 - build signal
Definition: sprites.h:1498
SPET_BUTTON_PUSH
@ SPET_BUTTON_PUSH
A push button that triggers an immediate event.
Definition: story_base.h:34
StoryBookWindow::layout_cache
LayoutCache layout_cache
Cached element layout.
Definition: story_gui.cpp:59
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:712
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:38
vehicle_base.h
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:995
WD_FRAMETEXT_TOP
@ WD_FRAMETEXT_TOP
Top offset of the text of the frame.
Definition: window_gui.h:74
StoryBookWindow::SelectNextPage
void SelectNextPage()
Selects the next available page after the currently selected page.
Definition: story_gui.cpp:231
goal_base.h
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:645
story_widget.h
SPET_GOAL
@ SPET_GOAL
An element that references a goal.
Definition: story_base.h:33
ANIMCURSOR_DEMOLISH
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
Definition: sprites.h:1494
StoryPage::sort_value
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:171
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition: window_gui.h:319
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:711
FR_LOWERED
@ FR_LOWERED
If set the frame is lowered and the background colour brighter (ie. buttons when pressed)
Definition: window_gui.h:31
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:224
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:2138
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:631
StoryBookWindow::OnTimeout
void OnTimeout() override
Called when this window's timeout has been reached.
Definition: story_gui.cpp:909
WD_FRAMETEXT_LEFT
@ WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
Definition: window_gui.h:72
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:973
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1109
WID_SB_PAGE_PANEL
@ WID_SB_PAGE_PANEL
Page body.
Definition: story_widget.h:18
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:891
StoryPageElement::referenced_id
uint32 referenced_id
Id of referenced object (location, goal etc.)
Definition: story_base.h:155
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:790
StoryBookWindow::selected_generic_title
char selected_generic_title[255]
If the selected page doesn't have a custom title, this buffer is used to store a generic page title.
Definition: story_gui.cpp:64
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
SPET_BUTTON_VEHICLE
@ SPET_BUTTON_VEHICLE
A button that allows the player to select a vehicle, and triggers an event wih the vehicle.
Definition: story_base.h:36
WindowDesc
High level window description.
Definition: window_gui.h:168
WC_STORY_BOOK
@ WC_STORY_BOOK
Story book; Window numbers:
Definition: window_type.h:288
window_gui.h
ANIMCURSOR_PICKSTATION
static const CursorID ANIMCURSOR_PICKSTATION
716 - 718 - goto-order icon
Definition: sprites.h:1497
StoryBookWindow::vscroll
Scrollbar * vscroll
Scrollbar of the page text.
Definition: story_gui.cpp:58
SPET_BUTTON_TILE
@ SPET_BUTTON_TILE
A button that allows the player to select a tile, and triggers an event with the tile.
Definition: story_base.h:35
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:317
StoryPageElement::type
StoryPageElementType type
Type of page element.
Definition: story_base.h:153
Scrollbar::GetCount
uint16 GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:655
tilehighlight_func.h
CursorID
uint32 CursorID
The number of the cursor (sprite)
Definition: gfx_type.h:19
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:207
SA_TOP
@ SA_TOP
Top align the text.
Definition: gfx_type.h:333
StoryBookWindow::story_page_elements
GUIStoryPageElementList story_page_elements
Sorted list of page elements that belong to the current page.
Definition: story_gui.cpp:62
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:315
StoryPageID
uint16 StoryPageID
ID of a story page.
Definition: story_type.h:16
GUIList< const StoryPage * >::SortFunction
bool SortFunction(const const StoryPage * &, const const StoryPage * &)
Signature of sort function.
Definition: sortlist_type.h:48
StoryBookWindow::SelectPrevPage
void SelectPrevPage()
Selects the previous available page before the currently selected page.
Definition: story_gui.cpp:211
StoryBookWindow::GetSelPage
StoryPage * GetSelPage() const
Get instance of selected page.
Definition: story_gui.cpp:139
WD_FRAMETEXT_BOTTOM
@ WD_FRAMETEXT_BOTTOM
Bottom offset of the text of the frame.
Definition: window_gui.h:75
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width, bool auto_width, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:443
StoryBookWindow
Definition: story_gui.cpp:44
StoryBookWindow::InvalidateStoryPageElementLayout
void InvalidateStoryPageElementLayout()
Invalidate the current page layout.
Definition: story_gui.cpp:401
StoryPage
Struct about stories, current and completed.
Definition: story_base.h:170
dropdown_type.h
StoryBookWindow::RefreshSelectedPage
void RefreshSelectedPage()
Updates the content of selected page.
Definition: story_gui.cpp:188
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:386
StoryBookWindow::GetHeadHeight
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:291
WID_SB_CAPTION
@ WID_SB_CAPTION
Caption of the window.
Definition: story_widget.h:16
DropDownListStringItem
Common string list item.
Definition: dropdown_type.h:39
StoryBookWindow::OnPageElementClick
void OnPageElementClick(const StoryPageElement &pe)
Internal event handler for when a page element is clicked.
Definition: story_gui.cpp:545
safeguards.h
StoryBookWindow::OnPlaceObjectAbort
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition: story_gui.cpp:949
sortlist_type.h
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:305
VEH_INVALID
@ VEH_INVALID
Non-existing type of vehicle.
Definition: vehicle_type.h:35
StoryBookWindow::selected_page_id
StoryPageID selected_page_id
Pool index of selected page.
Definition: story_gui.cpp:63
SPET_LOCATION
@ SPET_LOCATION
An element that references a tile along with a one-line text.
Definition: story_base.h:32
DrawSprite
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:1044
StoryBookWindow::SetSelectedPage
void SetSelectedPage(uint16 page_index)
Sets the selected page.
Definition: story_gui.cpp:643
sprites.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
StoryPageButtonCursor
StoryPageButtonCursor
Mouse cursors usable by story page buttons.
Definition: story_base.h:53
StoryBookWindow::GetPageElementHeight
uint GetPageElementHeight(const StoryPageElement &pe, int max_width) const
Get the height in pixels used by a page element.
Definition: story_gui.cpp:332
date_func.h
WD_FRAMETEXT_RIGHT
@ WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
Definition: window_gui.h:73
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:307
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
StoryPage::title
char * title
Title of story page.
Definition: story_base.h:175
Pool::Get
Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:109
ShowStoryBook
void ShowStoryBook(CompanyID company, uint16 page_id)
Raise or create the story book window for company, at page page_id.
Definition: story_gui.cpp:1059
viewport_func.h
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:37
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:329
StoryBookWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: story_gui.cpp:859
HT_VEHICLE
@ HT_VEHICLE
vehicle is accepted as target as well (bitmask)
Definition: tilehighlight_type.h:27
FillDrawPixelInfo
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:1772
GetStringHeight
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:716
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:979
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:362
StoryBookWindow::IsFirstPageSelected
bool IsFirstPageSelected()
Check if the selected page is also the first available page.
Definition: story_gui.cpp:164
StoryBookWindow::DrawActionElement
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:527
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1094
Pool::PoolItem<&_story_page_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:386
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
StoryBookWindow::PageElementOrderSorter
static bool PageElementOrderSorter(const StoryPageElement *const &a, const StoryPageElement *const &b)
Sort story page elements by order value.
Definition: story_gui.cpp:120
INVALID_DATE
static const Date INVALID_DATE
Representation of an invalid date.
Definition: date_type.h:111
WD_BEVEL_RIGHT
@ WD_BEVEL_RIGHT
Width of right bevel border.
Definition: window_gui.h:57
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:168
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1209
Goal::completed
bool completed
Is the goal completed or not?
Definition: goal_base.h:27
WID_SB_PREV_PAGE
@ WID_SB_PREV_PAGE
Prev button.
Definition: story_widget.h:20
geometry_func.hpp
StoryBookWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: story_gui.cpp:811
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1012
story_cmd.h
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
StoryBookWindow::story_pages
GUIStoryPageList story_pages
Sorted list of pages.
Definition: story_gui.cpp:61
StoryBookWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: story_gui.cpp:768
StoryPageElementID
uint16 StoryPageElementID
ID of a story page element.
Definition: story_type.h:15
HT_RECT
@ HT_RECT
rectangle (stations, depots, ...)
Definition: tilehighlight_type.h:21
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:673
StoryPageElement
Struct about story page elements.
Definition: story_base.h:150
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1776
company_func.h
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:328
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:209
WD_BEVEL_TOP
@ WD_BEVEL_TOP
Height of top bevel border.
Definition: window_gui.h:58
CommandHelper
Definition: command_func.h:94
WD_BEVEL_LEFT
@ WD_BEVEL_LEFT
Width of left bevel border.
Definition: window_gui.h:56
window_func.h
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:370
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition: gfx_type.h:338
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:314
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:2212
StoryBookWindow::OnPlaceObject
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
Definition: story_gui.cpp:915
SetObjectToPlaceWnd
void SetObjectToPlaceWnd(CursorID icon, PaletteID pal, HighLightStyle mode, Window *w)
Change the cursor and mouse click/drag handling to a mode for performing special operations like tile...
Definition: viewport.cpp:3361
Scrollbar::SetStepSize
void SetStepSize(uint16 stepsize)
Set the distance to scroll when using the buttons or the wheel.
Definition: widget_type.h:701
INVALID_COMPANY
@ INVALID_COMPANY
An invalid company.
Definition: company_type.h:30
StoryPageElement::text
char * text
Static content text of page element.
Definition: story_base.h:156
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1078
gui.h
SPR_CURSOR_MOUSE
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
Definition: sprites.h:1376
StoryPageButtonData
Helper to construct packed "id" values for button-type StoryPageElement.
Definition: story_base.h:128
StoryBookWindow::PageOrderSorter
static bool PageOrderSorter(const StoryPage *const &a, const StoryPage *const &b)
Sort story pages by order value.
Definition: story_gui.cpp:91
Window
Data structure for an opened window.
Definition: window_gui.h:279
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:380
WID_SB_SEL_PAGE
@ WID_SB_SEL_PAGE
Page selector.
Definition: story_widget.h:17
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:326
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:636
StoryBookWindow::UpdatePrevNextDisabledState
void UpdatePrevNextDisabledState()
Updates the disabled state of the prev/next buttons.
Definition: story_gui.cpp:631
StoryBookWindow::LayoutCacheElement
Definition: story_gui.cpp:46
StoryBookWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: story_gui.cpp:874
StoryBookWindow::BuildStoryPageList
void BuildStoryPageList()
(Re)Build story page list.
Definition: story_gui.cpp:72
story_base.h
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:608
WID_SB_SCROLLBAR
@ WID_SB_SCROLLBAR
Scrollbar of the goal list.
Definition: story_widget.h:19
GoalID
uint16 GoalID
ID of a goal.
Definition: goal_type.h:38
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
DepotCommand::None
@ None
No special flags.
StoryBookWindow::GetContentHeight
uint GetContentHeight()
Get the total height of the content displayed in this window.
Definition: story_gui.cpp:506
StoryPage::date
Date date
Date when the page was created.
Definition: story_base.h:172
WD_BEVEL_BOTTOM
@ WD_BEVEL_BOTTOM
Height of bottom bevel border.
Definition: window_gui.h:59
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:402
StoryPage::company
CompanyID company
StoryPage is for a specific company; INVALID_COMPANY if it is global.
Definition: story_base.h:173
StoryBookWindow::IsLastPageSelected
bool IsLastPageSelected()
Check if the selected page is also the last available page.
Definition: story_gui.cpp:175
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition: viewport.cpp:3424
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:157
StoryBookWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: story_gui.cpp:673
StoryBookWindow::GetPageElementFloat
ElementFloat GetPageElementFloat(const StoryPageElement &pe) const
Get the float style of a page element.
Definition: story_gui.cpp:363
Goal::text
char * text
Text of the goal.
Definition: goal_base.h:25
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:296
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:53
StoryBookWindow::BuildStoryPageElementList
void BuildStoryPageElementList()
(Re)Build story page element list.
Definition: story_gui.cpp:97
NWID_BUTTON_DROPDOWN
@ NWID_BUTTON_DROPDOWN
Button with a drop-down.
Definition: widget_type.h:80
GUIList::SetSortFuncs
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
Definition: sortlist_type.h:270
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:155
StoryBookWindow::EnsureStoryPageElementLayout
void EnsureStoryPageElementLayout() const
Create the page layout if it is missing.
Definition: story_gui.cpp:407
StoryBookWindow::active_button_id
StoryPageElementID active_button_id
Which button element the player is currently using.
Definition: story_gui.cpp:66
ANIMCURSOR_LOWERLAND
static const CursorID ANIMCURSOR_LOWERLAND
699 - 701 - lower land tool
Definition: sprites.h:1495
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62