OpenTTD Source: src/story_gui.cpp Source File

OpenTTD Source 13.2.1

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
41 typedef GUIList<const StoryPage*> GUIStoryPageList;
42 typedef GUIList<const StoryPageElement*> GUIStoryPageElementList;
43
44 struct StoryBookWindow : Window {
45 protected:
46 struct LayoutCacheElement {
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
58 Scrollbar *vscroll;
59 mutable LayoutCache layout_cache;
60
61 GUIStoryPageList story_pages;
62 GUIStoryPageElementList story_page_elements;
63 StoryPageID selected_page_id;
64 char selected_generic_title[255];
65
66 StoryPageElementID active_button_id;
67
68 static GUIStoryPageList::SortFunction * const page_sorter_funcs[];
69 static GUIStoryPageElementList::SortFunction * const page_element_sorter_funcs[];
70
72 void BuildStoryPageList()
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
97 void BuildStoryPageElementList()
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();
116 this->InvalidateStoryPageElementLayout();
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
139 StoryPage *GetSelPage() const
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
164 bool IsFirstPageSelected()
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
175 bool IsLastPageSelected()
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
188 void RefreshSelectedPage()
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();
198 this->BuildStoryPageElementList();
199
200 if (this->active_button_id != INVALID_STORY_PAGE_ELEMENT) ResetObjectToPlace();
201
202 this->vscroll->SetCount(this->GetContentHeight());
203 this->SetWidgetDirty(WID_SB_SCROLLBAR);
204 this->SetWidgetDirty(WID_SB_SEL_PAGE);
205 this->SetWidgetDirty(WID_SB_PAGE_PANEL);
206 }
207
211 void SelectPrevPage()
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
231 void SelectNextPage()
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
252 DropDownList BuildDropDownList() const
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
279 uint GetAvailablePageContentWidth() const
280 {
281 return this->GetWidget<NWidgetCore>(WID_SB_PAGE_PANEL)->current_x - WidgetDimensions::scaled.frametext.Horizontal() - 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
311 SpriteID GetPageElementSprite(const StoryPageElement &pe) const
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: {
348 Dimension dim = GetStringBoundingBox(pe.text, FS_NORMAL);
349 return dim.height + WidgetDimensions::scaled.framerect.Vertical() + WidgetDimensions::scaled.frametext.Vertical();
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: {
369 StoryPageButtonFlags flags = StoryPageButtonData{ pe.referenced_id }.GetFlags();
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
385 int GetPageElementFloatWidth(const StoryPageElement &pe) const
386 {
387 switch (pe.type) {
388 case SPET_BUTTON_PUSH:
389 case SPET_BUTTON_TILE:
390 case SPET_BUTTON_VEHICLE: {
391 Dimension dim = GetStringBoundingBox(pe.text, FS_NORMAL);
392 return dim.width + WidgetDimensions::scaled.framerect.Vertical() + WidgetDimensions::scaled.frametext.Vertical();
393 }
394
395 default:
396 NOT_REACHED(); // only buttons can float
397 }
398 }
399
401 void InvalidateStoryPageElementLayout()
402 {
403 this->layout_cache.clear();
404 }
405
407 void EnsureStoryPageElementLayout() const
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
506 uint GetContentHeight()
507 {
508 this->EnsureStoryPageElementLayout();
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 + WidgetDimensions::scaled.frametext.left, width, text_top, string_id, TC_BLACK);
537
538 y_offset += element_height;
539 }
540
545 void OnPageElementClick(const StoryPageElement& pe)
546 {
547 switch (pe.type) {
548 case SPET_TEXT:
549 /* Do nothing. */
550 break;
551
552 case SPET_LOCATION:
553 if (_ctrl_pressed) {
554 ShowExtraViewportWindow((TileIndex)pe.referenced_id);
555 } else {
556 ScrollMainWindowToTile((TileIndex)pe.referenced_id);
557 }
558 break;
559
560 case SPET_GOAL:
561 ShowGoalsList((CompanyID)this->window_number);
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();
568 this->SetWidgetDirty(WID_SB_PAGE_PANEL);
569
570 Command<CMD_STORY_PAGE_BUTTON>::Post(0, pe.index, 0);
571 break;
572
573 case SPET_BUTTON_TILE:
574 if (this->active_button_id == pe.index) {
575 ResetObjectToPlace();
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 }
582 this->SetWidgetDirty(WID_SB_PAGE_PANEL);
583 break;
584
585 case SPET_BUTTON_VEHICLE:
586 if (this->active_button_id == pe.index) {
587 ResetObjectToPlace();
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 }
594 this->SetWidgetDirty(WID_SB_PAGE_PANEL);
595 break;
596
597 default:
598 NOT_REACHED();
599 }
600 }
601
602 public:
603 StoryBookWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
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
631 void UpdatePrevNextDisabledState()
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());
635 this->SetWidgetDirty(WID_SB_PREV_PAGE);
636 this->SetWidgetDirty(WID_SB_NEXT_PAGE);
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();
650 this->UpdatePrevNextDisabledState();
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());
681 this->SetWidgetDirty(WID_SB_SCROLLBAR);
682 this->SetWidgetDirty(WID_SB_PAGE_PANEL);
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 Rect fr = r.Shrink(WidgetDimensions::scaled.frametext);
696
697 /* Set up a clipping region for the panel. */
698 DrawPixelInfo tmp_dpi;
699 if (!FillDrawPixelInfo(&tmp_dpi, fr.left, fr.top, fr.Width(), fr.Height())) return;
700
701 DrawPixelInfo *old_dpi = _cur_dpi;
702 _cur_dpi = &tmp_dpi;
703
704 /* Draw content (now coordinates given to Draw** are local to the new clipping region). */
705 fr = fr.Translate(-fr.left, -fr.top);
706 int line_height = FONT_HEIGHT_NORMAL;
707 const int scrollpos = this->vscroll->GetPosition();
708 int y_offset = -scrollpos;
709
710 /* Date */
711 if (page->date != INVALID_DATE) {
712 SetDParam(0, page->date);
713 DrawString(0, fr.right, y_offset, STR_JUST_DATE_LONG, TC_BLACK);
714 }
715 y_offset += line_height;
716
717 /* Title */
718 SetDParamStr(0, page->title != nullptr ? page->title : this->selected_generic_title);
719 y_offset = DrawStringMultiLine(0, fr.right, y_offset, fr.bottom, STR_STORY_BOOK_TITLE, TC_BLACK, SA_TOP | SA_HOR_CENTER);
720
721 /* Page elements */
722 this->EnsureStoryPageElementLayout();
723 for (const LayoutCacheElement &ce : this->layout_cache) {
724 y_offset = ce.bounds.top - scrollpos;
725 switch (ce.pe->type) {
726 case SPET_TEXT:
727 SetDParamStr(0, ce.pe->text);
728 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);
729 break;
730
731 case SPET_GOAL: {
732 Goal *g = Goal::Get((GoalID) ce.pe->referenced_id);
733 StringID string_id = g == nullptr ? STR_STORY_BOOK_INVALID_GOAL_REF : STR_JUST_RAW_STRING;
734 if (g != nullptr) SetDParamStr(0, g->text);
735 DrawActionElement(y_offset, ce.bounds.right - ce.bounds.left, line_height, GetPageElementSprite(*ce.pe), string_id);
736 break;
737 }
738
739 case SPET_LOCATION:
740 SetDParamStr(0, ce.pe->text);
741 DrawActionElement(y_offset, ce.bounds.right - ce.bounds.left, line_height, GetPageElementSprite(*ce.pe));
742 break;
743
744 case SPET_BUTTON_PUSH:
745 case SPET_BUTTON_TILE:
746 case SPET_BUTTON_VEHICLE: {
747 const int tmargin = WidgetDimensions::scaled.bevel.top + WidgetDimensions::scaled.frametext.top;
748 const FrameFlags frame = this->active_button_id == ce.pe->index ? FR_LOWERED : FR_NONE;
749 const Colours bgcolour = StoryPageButtonData{ ce.pe->referenced_id }.GetColour();
750
751 DrawFrameRect(ce.bounds.left, ce.bounds.top - scrollpos, ce.bounds.right, ce.bounds.bottom - scrollpos - 1, bgcolour, frame);
752
753 SetDParamStr(0, ce.pe->text);
754 DrawString(ce.bounds.left + WidgetDimensions::scaled.bevel.left, ce.bounds.right - WidgetDimensions::scaled.bevel.right, ce.bounds.top + tmargin - scrollpos, STR_JUST_RAW_STRING, TC_WHITE, SA_CENTER);
755 break;
756 }
757
758 default: NOT_REACHED();
759 }
760 }
761
762 /* Restore clipping region. */
763 _cur_dpi = old_dpi;
764 }
765
766 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
767 {
768 if (widget != WID_SB_SEL_PAGE && widget != WID_SB_PAGE_PANEL) return;
769
770 Dimension d;
771 d.height = FONT_HEIGHT_NORMAL;
772 d.width = 0;
773
774 switch (widget) {
775 case WID_SB_SEL_PAGE: {
776
777 /* Get max title width. */
778 for (size_t i = 0; i < this->story_pages.size(); i++) {
779 const StoryPage *s = this->story_pages[i];
780
781 if (s->title != nullptr) {
782 SetDParamStr(0, s->title);
783 } else {
784 SetDParamStr(0, this->selected_generic_title);
785 }
786 Dimension title_d = GetStringBoundingBox(STR_BLACK_RAW_STRING);
787
788 if (title_d.width > d.width) {
789 d.width = title_d.width;
790 }
791 }
792
793 d.width += padding.width;
794 d.height += padding.height;
795 *size = maxdim(*size, d);
796 break;
797 }
798
799 case WID_SB_PAGE_PANEL: {
800 d.height *= 5;
801 d.height += padding.height + WidgetDimensions::scaled.frametext.Vertical();
802 *size = maxdim(*size, d);
803 break;
804 }
805 }
806
807 }
808
809 void OnResize() override
810 {
811 this->InvalidateStoryPageElementLayout();
812 this->vscroll->SetCapacityFromWidget(this, WID_SB_PAGE_PANEL, WidgetDimensions::scaled.frametext.Vertical());
813 this->vscroll->SetCount(this->GetContentHeight());
814 }
815
816 void OnClick(Point pt, int widget, int click_count) override
817 {
818 switch (widget) {
819 case WID_SB_SEL_PAGE: {
820 DropDownList list = this->BuildDropDownList();
821 if (!list.empty()) {
822 /* Get the index of selected page. */
823 int selected = 0;
824 for (size_t i = 0; i < this->story_pages.size(); i++) {
825 const StoryPage *p = this->story_pages[i];
826 if (p->index == this->selected_page_id) break;
827 selected++;
828 }
829
830 ShowDropDownList(this, std::move(list), selected, widget);
831 }
832 break;
833 }
834
835 case WID_SB_PREV_PAGE:
836 this->SelectPrevPage();
837 break;
838
839 case WID_SB_NEXT_PAGE:
840 this->SelectNextPage();
841 break;
842
843 case WID_SB_PAGE_PANEL: {
844 int clicked_y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SB_PAGE_PANEL, WidgetDimensions::scaled.frametext.top);
845 this->EnsureStoryPageElementLayout();
846
847 for (const LayoutCacheElement &ce : this->layout_cache) {
848 if (clicked_y >= ce.bounds.top && clicked_y < ce.bounds.bottom && pt.x >= ce.bounds.left && pt.x < ce.bounds.right) {
849 this->OnPageElementClick(*ce.pe);
850 return;
851 }
852 }
853 }
854 }
855 }
856
857 void OnDropdownSelect(int widget, int index) override
858 {
859 if (widget != WID_SB_SEL_PAGE) return;
860
861 /* index (which is set in BuildDropDownList) is the page id. */
862 this->SetSelectedPage(index);
863 }
864
872 void OnInvalidateData(int data = 0, bool gui_scope = true) override
873 {
874 if (!gui_scope) return;
875
876 /* If added/removed page, force rebuild. Sort order never change so just a
877 * re-sort is never needed.
878 */
879 if (data == -1) {
880 this->story_pages.ForceRebuild();
881 this->BuildStoryPageList();
882
883 /* Was the last page removed? */
884 if (this->story_pages.size() == 0) {
885 this->selected_generic_title[0] = '\0';
886 }
887
888 /* Verify page selection. */
889 if (!_story_page_pool.IsValidID(this->selected_page_id)) {
890 this->selected_page_id = INVALID_STORY_PAGE;
891 }
892 if (this->selected_page_id == INVALID_STORY_PAGE && this->story_pages.size() > 0) {
893 /* No page is selected, but there exist at least one available.
894 * => Select first page.
895 */
896 this->SetSelectedPage(this->story_pages[0]->index);
897 }
898
899 this->SetWidgetDisabledState(WID_SB_SEL_PAGE, this->story_pages.size() == 0);
900 this->SetWidgetDirty(WID_SB_SEL_PAGE);
901 this->UpdatePrevNextDisabledState();
902 } else if (data >= 0 && this->selected_page_id == data) {
903 this->RefreshSelectedPage();
904 }
905 }
906
907 void OnTimeout() override
908 {
909 this->active_button_id = INVALID_STORY_PAGE_ELEMENT;
910 this->SetWidgetDirty(WID_SB_PAGE_PANEL);
911 }
912
913 void OnPlaceObject(Point pt, TileIndex tile) override
914 {
915 const StoryPageElement *const pe = StoryPageElement::GetIfValid(this->active_button_id);
916 if (pe == nullptr || pe->type != SPET_BUTTON_TILE) {
917 ResetObjectToPlace();
918 this->active_button_id = INVALID_STORY_PAGE_ELEMENT;
919 this->SetWidgetDirty(WID_SB_PAGE_PANEL);
920 return;
921 }
922
923 Command<CMD_STORY_PAGE_BUTTON>::Post(tile, pe->index, 0);
924 ResetObjectToPlace();
925 }
926
927 bool OnVehicleSelect(const Vehicle *v) override
928 {
929 const StoryPageElement *const pe = StoryPageElement::GetIfValid(this->active_button_id);
930 if (pe == nullptr || pe->type != SPET_BUTTON_VEHICLE) {
931 ResetObjectToPlace();
932 this->active_button_id = INVALID_STORY_PAGE_ELEMENT;
933 this->SetWidgetDirty(WID_SB_PAGE_PANEL);
934 return false;
935 }
936
937 /* Check that the vehicle matches the requested type */
938 StoryPageButtonData data{ pe->referenced_id };
939 VehicleType wanted_vehtype = data.GetVehicleType();
940 if (wanted_vehtype != VEH_INVALID && wanted_vehtype != v->type) return false;
941
942 Command<CMD_STORY_PAGE_BUTTON>::Post(0, pe->index, v->index);
943 ResetObjectToPlace();
944 return true;
945 }
946
947 void OnPlaceObjectAbort() override
948 {
949 this->active_button_id = INVALID_STORY_PAGE_ELEMENT;
950 this->SetWidgetDirty(WID_SB_PAGE_PANEL);
951 }
952 };
953
954 GUIStoryPageList::SortFunction * const StoryBookWindow::page_sorter_funcs[] = {
955 &PageOrderSorter,
956 };
957
958 GUIStoryPageElementList::SortFunction * const StoryBookWindow::page_element_sorter_funcs[] = {
959 &PageElementOrderSorter,
960 };
961
962 static const NWidgetPart _nested_story_book_widgets[] = {
963 NWidget(NWID_HORIZONTAL),
964 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
965 NWidget(WWT_CAPTION, COLOUR_BROWN, WID_SB_CAPTION), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
966 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
967 NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
968 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
969 EndContainer(),
970 NWidget(NWID_HORIZONTAL), SetFill(1, 1),
971 NWidget(WWT_PANEL, COLOUR_BROWN, WID_SB_PAGE_PANEL), SetResize(1, 1), SetScrollbar(WID_SB_SCROLLBAR), EndContainer(),
972 NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_SB_SCROLLBAR),
973 EndContainer(),
974 NWidget(NWID_HORIZONTAL),
975 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),
976 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_BROWN, WID_SB_SEL_PAGE), SetMinimalSize(93, 12), SetFill(1, 0),
977 SetDataTip(STR_BLACK_RAW_STRING, STR_STORY_BOOK_SEL_PAGE_TOOLTIP), SetResize(1, 0),
978 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),
979 NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
980 EndContainer(),
981 };
982
983 static WindowDesc _story_book_desc(
984 WDP_CENTER, "view_story", 400, 300,
985 WC_STORY_BOOK, WC_NONE,
986 0,
987 _nested_story_book_widgets, lengthof(_nested_story_book_widgets)
988 );
989
990 static CursorID TranslateStoryPageButtonCursor(StoryPageButtonCursor cursor)
991 {
992 switch (cursor) {
993 case SPBC_MOUSE: return SPR_CURSOR_MOUSE;
994 case SPBC_ZZZ: return SPR_CURSOR_ZZZ;
995 case SPBC_BUOY: return SPR_CURSOR_BUOY;
996 case SPBC_QUERY: return SPR_CURSOR_QUERY;
997 case SPBC_HQ: return SPR_CURSOR_HQ;
998 case SPBC_SHIP_DEPOT: return SPR_CURSOR_SHIP_DEPOT;
999 case SPBC_SIGN: return SPR_CURSOR_SIGN;
1000 case SPBC_TREE: return SPR_CURSOR_TREE;
1001 case SPBC_BUY_LAND: return SPR_CURSOR_BUY_LAND;
1002 case SPBC_LEVEL_LAND: return SPR_CURSOR_LEVEL_LAND;
1003 case SPBC_TOWN: return SPR_CURSOR_TOWN;
1004 case SPBC_INDUSTRY: return SPR_CURSOR_INDUSTRY;
1005 case SPBC_ROCKY_AREA: return SPR_CURSOR_ROCKY_AREA;
1006 case SPBC_DESERT: return SPR_CURSOR_DESERT;
1007 case SPBC_TRANSMITTER: return SPR_CURSOR_TRANSMITTER;
1008 case SPBC_AIRPORT: return SPR_CURSOR_AIRPORT;
1009 case SPBC_DOCK: return SPR_CURSOR_DOCK;
1010 case SPBC_CANAL: return SPR_CURSOR_CANAL;
1011 case SPBC_LOCK: return SPR_CURSOR_LOCK;
1012 case SPBC_RIVER: return SPR_CURSOR_RIVER;
1013 case SPBC_AQUEDUCT: return SPR_CURSOR_AQUEDUCT;
1014 case SPBC_BRIDGE: return SPR_CURSOR_BRIDGE;
1015 case SPBC_RAIL_STATION: return SPR_CURSOR_RAIL_STATION;
1016 case SPBC_TUNNEL_RAIL: return SPR_CURSOR_TUNNEL_RAIL;
1017 case SPBC_TUNNEL_ELRAIL: return SPR_CURSOR_TUNNEL_ELRAIL;
1018 case SPBC_TUNNEL_MONO: return SPR_CURSOR_TUNNEL_MONO;
1019 case SPBC_TUNNEL_MAGLEV: return SPR_CURSOR_TUNNEL_MAGLEV;
1020 case SPBC_AUTORAIL: return SPR_CURSOR_AUTORAIL;
1021 case SPBC_AUTOELRAIL: return SPR_CURSOR_AUTOELRAIL;
1022 case SPBC_AUTOMONO: return SPR_CURSOR_AUTOMONO;
1023 case SPBC_AUTOMAGLEV: return SPR_CURSOR_AUTOMAGLEV;
1024 case SPBC_WAYPOINT: return SPR_CURSOR_WAYPOINT;
1025 case SPBC_RAIL_DEPOT: return SPR_CURSOR_RAIL_DEPOT;
1026 case SPBC_ELRAIL_DEPOT: return SPR_CURSOR_ELRAIL_DEPOT;
1027 case SPBC_MONO_DEPOT: return SPR_CURSOR_MONO_DEPOT;
1028 case SPBC_MAGLEV_DEPOT: return SPR_CURSOR_MAGLEV_DEPOT;
1029 case SPBC_CONVERT_RAIL: return SPR_CURSOR_CONVERT_RAIL;
1030 case SPBC_CONVERT_ELRAIL: return SPR_CURSOR_CONVERT_ELRAIL;
1031 case SPBC_CONVERT_MONO: return SPR_CURSOR_CONVERT_MONO;
1032 case SPBC_CONVERT_MAGLEV: return SPR_CURSOR_CONVERT_MAGLEV;
1033 case SPBC_AUTOROAD: return SPR_CURSOR_AUTOROAD;
1034 case SPBC_AUTOTRAM: return SPR_CURSOR_AUTOTRAM;
1035 case SPBC_ROAD_DEPOT: return SPR_CURSOR_ROAD_DEPOT;
1036 case SPBC_BUS_STATION: return SPR_CURSOR_BUS_STATION;
1037 case SPBC_TRUCK_STATION: return SPR_CURSOR_TRUCK_STATION;
1038 case SPBC_ROAD_TUNNEL: return SPR_CURSOR_ROAD_TUNNEL;
1039 case SPBC_CLONE_TRAIN: return SPR_CURSOR_CLONE_TRAIN;
1040 case SPBC_CLONE_ROADVEH: return SPR_CURSOR_CLONE_ROADVEH;
1041 case SPBC_CLONE_SHIP: return SPR_CURSOR_CLONE_SHIP;
1042 case SPBC_CLONE_AIRPLANE: return SPR_CURSOR_CLONE_AIRPLANE;
1043 case SPBC_DEMOLISH: return ANIMCURSOR_DEMOLISH;
1044 case SPBC_LOWERLAND: return ANIMCURSOR_LOWERLAND;
1045 case SPBC_RAISELAND: return ANIMCURSOR_RAISELAND;
1046 case SPBC_PICKSTATION: return ANIMCURSOR_PICKSTATION;
1047 case SPBC_BUILDSIGNALS: return ANIMCURSOR_BUILDSIGNALS;
1048 default: return SPR_CURSOR_QUERY;
1049 }
1050 }
1051
1057 void ShowStoryBook(CompanyID company, uint16 page_id)
1058 {
1059 if (!Company::IsValidID(company)) company = (CompanyID)INVALID_COMPANY;
1060
1061 StoryBookWindow *w = AllocateWindowDescFront<StoryBookWindow>(&_story_book_desc, company, true);
1062 if (page_id != INVALID_STORY_PAGE) w->SetSelectedPage(page_id);
1063 }
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:295
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:816
StoryBookWindow::GetSelPageNum
int GetSelPageNum() const
Get the page number of selected page.
Definition: story_gui.cpp:149
Rect::Height
int Height() const
Get height of Rect.
Definition: geometry_type.hpp:85
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:2456
ShowGoalsList
void ShowGoalsList(CompanyID company)
Open a goal list window.
Definition: goal_gui.cpp:317
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:1210
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:319
dropdown_func.h
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:92
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:1498
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:30
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1775
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:1500
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:717
_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:997
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:644
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:1496
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:253
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:713
FR_LOWERED
@ FR_LOWERED
If set the frame is lowered and the background colour brighter (ie. buttons when pressed)
Definition: window_gui.h:34
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:2353
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:636
StoryBookWindow::OnTimeout
void OnTimeout() override
Called when this window's timeout has been reached.
Definition: story_gui.cpp:907
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:975
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1111
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:890
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:789
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:102
WC_STORY_BOOK
@ WC_STORY_BOOK
Story book; Window numbers:
Definition: window_type.h:289
window_gui.h
ANIMCURSOR_PICKSTATION
static const CursorID ANIMCURSOR_PICKSTATION
716 - 718 - goto-order icon
Definition: sprites.h:1499
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:251
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:660
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:203
SA_TOP
@ SA_TOP
Top align the text.
Definition: gfx_type.h:339
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition: geometry_type.hpp:168
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:249
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
RectPadding::Horizontal
uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition: geometry_type.hpp:59
StoryBookWindow::GetSelPage
StoryPage * GetSelPage() const
Get instance of selected page.
Definition: story_gui.cpp:139
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:444
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
EngineDisplayFlags::None
@ None
No flag set.
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:321
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:947
sortlist_type.h
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:239
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:1058
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
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:241
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
RectPadding::Vertical
uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:65
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:1057
viewport_func.h
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:335
StoryBookWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: story_gui.cpp:857
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:1786
GetStringHeight
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:715
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:993
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:1096
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
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:206
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1229
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:809
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1014
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:766
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:678
StoryPageElement
Struct about story page elements.
Definition: story_base.h:150
WidgetDimensions::bevel
RectPadding bevel
Widths of bevel border.
Definition: window_gui.h:45
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1791
company_func.h
WidgetDimensions::framerect
RectPadding framerect
Offsets within frame area.
Definition: window_gui.h:47
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:334
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:414
CommandHelper
Definition: command_func.h:94
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:344
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:248
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:2427
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:913
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:3371
Scrollbar::SetStepSize
void SetStepSize(uint16 stepsize)
Set the distance to scroll when using the buttons or the wheel.
Definition: widget_type.h:706
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:1080
gui.h
SPR_CURSOR_MOUSE
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
Definition: sprites.h:1378
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:213
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:858
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
WidgetDimensions::frametext
RectPadding frametext
Offsets within a text frame area.
Definition: window_gui.h:48
StoryBookWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: story_gui.cpp:872
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:79
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
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:621
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:69
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
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:3434
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:91
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:297
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:151
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:1497
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62