OpenTTD Source 20261112-master-gbcbec5e63f
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#include "stdafx.h"
11#include "window_gui.h"
12#include "strings_func.h"
13#include "gui.h"
14#include "story_base.h"
16#include "command_func.h"
17#include "dropdown_type.h"
18#include "dropdown_func.h"
19#include "sortlist_type.h"
20#include "goal_base.h"
21#include "goal_gui.h"
22#include "viewport_func.h"
23#include "company_base.h"
24#include "tilehighlight_func.h"
25#include "vehicle_base.h"
26#include "story_cmd.h"
27
29
30#include "table/strings.h"
31#include "table/sprites.h"
32
33#include "safeguards.h"
34
35static CursorID TranslateStoryPageButtonCursor(StoryPageButtonCursor cursor);
36
37typedef GUIList<const StoryPage*> GUIStoryPageList;
38typedef GUIList<const StoryPageElement*> GUIStoryPageElementList;
39
40struct StoryBookWindow : Window {
41protected:
43 const StoryPageElement *pe;
44 Rect bounds;
45 };
46 typedef std::vector<LayoutCacheElement> LayoutCache;
47
48 enum class ElementFloat : uint8_t {
49 None,
50 Left,
51 Right,
52 };
53
54 Scrollbar *vscroll = nullptr;
55 mutable LayoutCache layout_cache{};
56
57 GUIStoryPageList story_pages{};
58 GUIStoryPageElementList story_page_elements{};
60 std::string selected_generic_title{};
61
63
64 static const std::initializer_list<GUIStoryPageList::SortFunction * const> page_sorter_funcs;
65 static const std::initializer_list<GUIStoryPageElementList::SortFunction * const> page_element_sorter_funcs;
66
69 {
70 if (this->story_pages.NeedRebuild()) {
71 this->story_pages.clear();
72
73 for (const StoryPage *p : StoryPage::Iterate()) {
74 if (this->IsPageAvailable(p)) {
75 this->story_pages.push_back(p);
76 }
77 }
78
79 this->story_pages.RebuildDone();
80 }
81
82 this->story_pages.Sort();
83 }
84
86 static bool PageOrderSorter(const StoryPage * const &a, const StoryPage * const &b)
87 {
88 return a->sort_value < b->sort_value;
89 }
90
93 {
94 if (this->story_page_elements.NeedRebuild()) {
95 this->story_page_elements.clear();
96
97 const StoryPage *p = GetSelPage();
98 if (p != nullptr) {
100 if (pe->page == p->index) {
101 this->story_page_elements.push_back(pe);
102 }
103 }
104 }
105
106 this->story_page_elements.RebuildDone();
107 }
108
109 this->story_page_elements.Sort();
111 }
112
114 static bool PageElementOrderSorter(const StoryPageElement * const &a, const StoryPageElement * const &b)
115 {
116 return a->sort_value < b->sort_value;
117 }
118
124 bool IsPageAvailable(const StoryPage *page) const
125 {
126 return page->company == CompanyID::Invalid() || page->company == this->window_number;
127 }
128
134 {
135 if (!StoryPage::IsValidID(selected_page_id)) return nullptr;
137 }
138
143 int GetSelPageNum() const
144 {
145 int page_number = 0;
146 for (const StoryPage *p : this->story_pages) {
147 if (p->index == this->selected_page_id) {
148 return page_number;
149 }
150 page_number++;
151 }
152 return -1;
153 }
154
160 {
161 /* Verify that the selected page exist. */
162 if (!StoryPage::IsValidID(this->selected_page_id)) return false;
163
164 return this->story_pages.front()->index == this->selected_page_id;
165 }
166
172 {
173 /* Verify that the selected page exist. */
174 if (!StoryPage::IsValidID(this->selected_page_id)) return false;
175
176 if (this->story_pages.size() <= 1) return true;
177 const StoryPage *last = this->story_pages.back();
178 return last->index == this->selected_page_id;
179 }
180
185 {
186 /* Generate generic title if selected page have no custom title. */
187 StoryPage *page = this->GetSelPage();
188 if (page != nullptr && page->title.empty()) {
189 selected_generic_title = GetString(STR_STORY_BOOK_GENERIC_PAGE_ITEM, GetSelPageNum() + 1);
190 }
191
192 this->story_page_elements.ForceRebuild();
194
195 if (this->active_button_id != StoryPageElementID::Invalid()) ResetObjectToPlace();
196
197 this->vscroll->SetCount(this->GetContentHeight());
201 }
202
207 {
208 if (!StoryPage::IsValidID(this->selected_page_id)) return;
209
210 /* Find the last available page which is previous to the current selected page. */
211 const StoryPage *last_available;
212 last_available = nullptr;
213 for (const StoryPage *p : this->story_pages) {
214 if (p->index == this->selected_page_id) {
215 if (last_available == nullptr) return; // No previous page available.
216 this->SetSelectedPage(last_available->index);
217 return;
218 }
219 last_available = p;
220 }
221 }
222
227 {
228 if (!StoryPage::IsValidID(this->selected_page_id)) return;
229
230 /* Find selected page. */
231 for (auto iter = this->story_pages.begin(); iter != this->story_pages.end(); iter++) {
232 const StoryPage *p = *iter;
233 if (p->index == this->selected_page_id) {
234 /* Select the page after selected page. */
235 iter++;
236 if (iter != this->story_pages.end()) {
237 this->SetSelectedPage((*iter)->index);
238 }
239 return;
240 }
241 }
242 }
243
249 {
250 DropDownList list;
251 uint16_t page_num = 1;
252 for (const StoryPage *p : this->story_pages) {
253 bool current_page = p->index == this->selected_page_id;
254 if (!p->title.empty()) {
255 list.push_back(MakeDropDownListStringItem(p->title.GetDecodedString(), p->index.base(), current_page));
256 } else {
257 /* No custom title => use a generic page title with page number. */
258 list.push_back(MakeDropDownListStringItem(GetString(STR_STORY_BOOK_GENERIC_PAGE_ITEM, page_num), p->index.base(), current_page));
259 }
260 page_num++;
261 }
262
263 return list;
264 }
265
271 {
272 return this->GetWidget<NWidgetCore>(WID_SB_PAGE_PANEL)->current_x - WidgetDimensions::scaled.frametext.Horizontal() - 1;
273 }
274
282 uint GetHeadHeight(int max_width) const
283 {
284 StoryPage *page = this->GetSelPage();
285 if (page == nullptr) return 0;
286 int height = 0;
287
288 /* Title lines */
289 height += GetCharacterHeight(FontSize::Normal); // Date always use exactly one line.
290 height += GetStringHeight(GetString(STR_STORY_BOOK_TITLE, !page->title.empty() ? page->title.GetDecodedString() : this->selected_generic_title), max_width);
291
292 return height;
293 }
294
302 {
303 switch (pe.type) {
306 if (g == nullptr) return SPR_IMG_GOAL_BROKEN_REF;
308 }
311 default:
312 NOT_REACHED();
313 }
314 }
315
322 uint GetPageElementHeight(const StoryPageElement &pe, int max_width) const
323 {
324 switch (pe.type) {
326 return GetStringHeight(pe.text.GetDecodedString(), max_width);
327
331 return sprite_dim.height;
332 }
333
338 return dim.height + WidgetDimensions::scaled.framerect.Vertical() + WidgetDimensions::scaled.frametext.Vertical();
339 }
340
341 default:
342 NOT_REACHED();
343 }
344 return 0;
345 }
346
352 ElementFloat GetPageElementFloat(const StoryPageElement &pe) const
353 {
354 switch (pe.type) {
359 if (flags.Test(StoryPageButtonFlag::FloatLeft)) return ElementFloat::Left;
360 if (flags.Test(StoryPageButtonFlag::FloatRight)) return ElementFloat::Right;
361 return ElementFloat::None;
362 }
363
364 default:
365 return ElementFloat::None;
366 }
367 }
368
375 {
376 switch (pe.type) {
381 return dim.width + WidgetDimensions::scaled.framerect.Vertical() + WidgetDimensions::scaled.frametext.Vertical();
382 }
383
384 default:
385 NOT_REACHED(); // only buttons can float
386 }
387 }
388
391 {
392 this->layout_cache.clear();
393 }
394
397 {
398 /* Assume if the layout cache has contents it is valid */
399 if (!this->layout_cache.empty()) return;
400
401 StoryPage *page = this->GetSelPage();
402 if (page == nullptr) return;
403 int max_width = GetAvailablePageContentWidth();
404 int element_dist = GetCharacterHeight(FontSize::Normal);
405
406 /* Make space for the header */
407 int main_y = GetHeadHeight(max_width) + element_dist;
408
409 /* Current bottom of left/right column */
410 int left_y = main_y;
411 int right_y = main_y;
412 /* Current width of left/right column, 0 indicates no content in column */
413 int left_width = 0;
414 int right_width = 0;
415 /* Indexes into element cache for yet unresolved floats */
416 std::vector<size_t> left_floats;
417 std::vector<size_t> right_floats;
418
419 /* Build layout */
420 for (const StoryPageElement *pe : this->story_page_elements) {
421 ElementFloat fl = this->GetPageElementFloat(*pe);
422
423 if (fl == ElementFloat::None) {
424 /* Verify available width */
425 const int min_required_width = 10 * GetCharacterHeight(FontSize::Normal);
426 int left_offset = (left_width == 0) ? 0 : (left_width + element_dist);
427 int right_offset = (right_width == 0) ? 0 : (right_width + element_dist);
428 if (left_offset + right_offset + min_required_width >= max_width) {
429 /* Width of floats leave too little for main content, push down */
430 main_y = std::max(main_y, left_y);
431 main_y = std::max(main_y, right_y);
432 left_offset = right_offset = 0;
433 /* Do not add element_dist here, to keep together elements which were supposed to float besides each other. */
434 }
435 /* Determine height */
436 const int available_width = max_width - left_offset - right_offset;
437 const int height = GetPageElementHeight(*pe, available_width);
438 /* Check for button that needs extra margin */
439 if (left_offset == 0 && right_offset == 0) {
440 switch (pe->type) {
444 left_offset = right_offset = available_width / 5;
445 break;
446 default:
447 break;
448 }
449 }
450 /* Position element in main column */
451 LayoutCacheElement ce{ pe, {} };
452 ce.bounds.left = left_offset;
453 ce.bounds.right = max_width - right_offset;
454 ce.bounds.top = main_y;
455 main_y += height;
456 ce.bounds.bottom = main_y;
457 this->layout_cache.push_back(ce);
458 main_y += element_dist;
459 /* Clear all floats */
460 left_width = right_width = 0;
461 left_y = right_y = main_y = std::max({main_y, left_y, right_y});
462 left_floats.clear();
463 right_floats.clear();
464 } else {
465 /* Prepare references to correct column */
466 int &cur_width = (fl == ElementFloat::Left) ? left_width : right_width;
467 int &cur_y = (fl == ElementFloat::Left) ? left_y : right_y;
468 std::vector<size_t> &cur_floats = (fl == ElementFloat::Left) ? left_floats : right_floats;
469 /* Position element */
470 cur_width = std::max(cur_width, this->GetPageElementFloatWidth(*pe));
471 LayoutCacheElement ce{ pe, {} };
472 ce.bounds.left = (fl == ElementFloat::Left) ? 0 : (max_width - cur_width);
473 ce.bounds.right = (fl == ElementFloat::Left) ? cur_width : max_width;
474 ce.bounds.top = cur_y;
475 cur_y += GetPageElementHeight(*pe, cur_width);
476 ce.bounds.bottom = cur_y;
477 cur_floats.push_back(this->layout_cache.size());
478 this->layout_cache.push_back(ce);
479 cur_y += element_dist;
480 /* Update floats in column to all have the same width */
481 for (size_t index : cur_floats) {
482 LayoutCacheElement &ce = this->layout_cache[index];
483 ce.bounds.left = (fl == ElementFloat::Left) ? 0 : (max_width - cur_width);
484 ce.bounds.right = (fl == ElementFloat::Left) ? cur_width : max_width;
485 }
486 }
487 }
488 }
489
495 {
497
498 /* The largest bottom coordinate of any element is the height of the content */
499 int32_t max_y = std::accumulate(this->layout_cache.begin(), this->layout_cache.end(), 0, [](int32_t max_y, const LayoutCacheElement &ce) -> int32_t { return std::max<int32_t>(max_y, ce.bounds.bottom); });
500
501 return max_y;
502 }
503
514 void DrawActionElement(int &y_offset, int width, int line_height, SpriteID action_sprite, const std::string &text) const
515 {
516 Dimension sprite_dim = GetSpriteSize(action_sprite);
517 uint element_height = std::max(sprite_dim.height, (uint)line_height);
518
519 uint sprite_top = y_offset + (element_height - sprite_dim.height) / 2;
520 uint text_top = y_offset + (element_height - line_height) / 2;
521
522 DrawSprite(action_sprite, PAL_NONE, 0, sprite_top);
523 DrawString(sprite_dim.width + WidgetDimensions::scaled.frametext.left, width, text_top, text, TextColour::Black);
524
525 y_offset += element_height;
526 }
527
533 {
534 switch (pe.type) {
536 /* Do nothing. */
537 break;
538
540 if (IsCtrlPressed()) {
542 } else {
544 }
545 break;
546
549 break;
550
552 if (this->active_button_id != StoryPageElementID::Invalid()) ResetObjectToPlace();
553 this->active_button_id = pe.index;
554 this->SetTimeout();
556
557 Command<Commands::StoryPageButton>::Post(TileIndex{}, pe.index, VehicleID::Invalid());
558 break;
559
561 if (this->active_button_id == pe.index) {
563 this->active_button_id = StoryPageElementID::Invalid();
564 } else {
565 CursorID cursor = TranslateStoryPageButtonCursor(StoryPageButtonData{ pe.referenced_id }.GetCursor());
566 SetObjectToPlaceWnd(cursor, PAL_NONE, HT_RECT, this);
567 this->active_button_id = pe.index;
568 }
570 break;
571
573 if (this->active_button_id == pe.index) {
575 this->active_button_id = StoryPageElementID::Invalid();
576 } else {
577 CursorID cursor = TranslateStoryPageButtonCursor(StoryPageButtonData{ pe.referenced_id }.GetCursor());
578 SetObjectToPlaceWnd(cursor, PAL_NONE, HT_VEHICLE, this);
579 this->active_button_id = pe.index;
580 }
582 break;
583
584 default:
585 NOT_REACHED();
586 }
587 }
588
589public:
591 {
592 this->CreateNestedTree();
593 this->vscroll = this->GetScrollbar(WID_SB_SCROLLBAR);
595
596 /* Initialize page sort. */
597 this->story_pages.SetSortFuncs(StoryBookWindow::page_sorter_funcs);
598 this->story_pages.ForceRebuild();
599 this->BuildStoryPageList();
600 this->story_page_elements.SetSortFuncs(StoryBookWindow::page_element_sorter_funcs);
601 /* story_page_elements will get built by SetSelectedPage */
602
603 this->FinishInitNested(window_number);
604 this->owner = this->window_number;
605
606 /* Initialize selected vars. */
607 this->selected_generic_title.clear();
608 this->selected_page_id = StoryPageID::Invalid();
609
610 this->active_button_id = StoryPageElementID::Invalid();
611
612 this->OnInvalidateData(-1);
613 }
614
619 {
620 this->SetWidgetDisabledState(WID_SB_PREV_PAGE, story_pages.empty() || this->IsFirstPageSelected());
621 this->SetWidgetDisabledState(WID_SB_NEXT_PAGE, story_pages.empty() || this->IsLastPageSelected());
624 }
625
631 {
632 if (this->selected_page_id != page_index) {
633 if (this->active_button_id != 0) ResetObjectToPlace();
634 this->active_button_id = StoryPageElementID::Invalid();
635 this->selected_page_id = page_index;
636 this->RefreshSelectedPage();
638 }
639 }
640
641 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
642 {
643 switch (widget) {
644 case WID_SB_SEL_PAGE: {
645 const StoryPage *page = this->GetSelPage();
646 return page != nullptr && !page->title.empty() ? page->title.GetDecodedString() : this->selected_generic_title;
647 }
648
649 case WID_SB_CAPTION:
650 if (this->window_number == CompanyID::Invalid()) {
651 return GetString(STR_STORY_BOOK_SPECTATOR_CAPTION);
652 }
653 return GetString(STR_STORY_BOOK_CAPTION, this->window_number);
654
655 default:
656 return this->Window::GetWidgetString(widget, stringid);
657 }
658 }
659
660 void OnPaint() override
661 {
662 /* Detect if content has changed height. This can happen if a
663 * multi-line text contains eg. {COMPANY} and that company is
664 * renamed.
665 */
666 if (this->vscroll->GetCount() != this->GetContentHeight()) {
667 this->vscroll->SetCount(this->GetContentHeight());
670 }
671
672 this->DrawWidgets();
673 }
674
675 void DrawWidget(const Rect &r, WidgetID widget) const override
676 {
677 if (widget != WID_SB_PAGE_PANEL) return;
678
679 StoryPage *page = this->GetSelPage();
680 if (page == nullptr) return;
681
682 Rect fr = r.Shrink(WidgetDimensions::scaled.frametext);
683
684 /* Set up a clipping region for the panel. */
685 DrawPixelInfo tmp_dpi;
686 if (!FillDrawPixelInfo(&tmp_dpi, fr)) return;
687
688 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
689
690 /* Draw content (now coordinates given to Draw** are local to the new clipping region). */
691 fr = fr.Translate(-fr.left, -fr.top);
692 int line_height = GetCharacterHeight(FontSize::Normal);
693 const int scrollpos = this->vscroll->GetPosition();
694 int y_offset = -scrollpos;
695
696 /* Date */
697 if (page->date != CalendarTime::INVALID_DATE) {
698 DrawString(0, fr.right, y_offset, GetString(STR_JUST_DATE_LONG, page->date), TextColour::Black);
699 }
700 y_offset += line_height;
701
702 /* Title */
703 DrawStringMultiLine(0, fr.right, y_offset, fr.bottom,
704 GetString(STR_STORY_BOOK_TITLE, !page->title.empty() ? page->title.GetDecodedString() : this->selected_generic_title), TextColour::Black, {AlignmentH::Centre, AlignmentV::Top});
705
706 /* Page elements */
708 for (const LayoutCacheElement &ce : this->layout_cache) {
709 if (ce.bounds.bottom - scrollpos < fr.top) continue;
710
711 y_offset = ce.bounds.top - scrollpos;
712 if (y_offset > fr.bottom) return;
713
714 switch (ce.pe->type) {
716 DrawStringMultiLineWithClipping(ce.bounds.left, ce.bounds.right, ce.bounds.top - scrollpos, ce.bounds.bottom - scrollpos,
717 ce.pe->text.GetDecodedString(), TextColour::Black, {AlignmentH::Start, AlignmentV::Top});
718 break;
719
721 Goal *g = Goal::Get((GoalID) ce.pe->referenced_id);
722 DrawActionElement(y_offset, ce.bounds.right - ce.bounds.left, line_height, GetPageElementSprite(*ce.pe),
723 g == nullptr ? GetString(STR_STORY_BOOK_INVALID_GOAL_REF) : g->text.GetDecodedString());
724 break;
725 }
726
728 DrawActionElement(y_offset, ce.bounds.right - ce.bounds.left, line_height, GetPageElementSprite(*ce.pe),
729 ce.pe->text.GetDecodedString());
730 break;
731
735 const int tmargin = WidgetDimensions::scaled.bevel.top + WidgetDimensions::scaled.frametext.top;
736 const FrameFlags frame = this->active_button_id == ce.pe->index ? FrameFlag::Lowered : FrameFlags{};
737 const Colours bgcolour = StoryPageButtonData{ ce.pe->referenced_id }.GetColour();
738
739 DrawFrameRect(ce.bounds.left, ce.bounds.top - scrollpos, ce.bounds.right, ce.bounds.bottom - scrollpos - 1, bgcolour, frame);
740
741 DrawString(ce.bounds.left + WidgetDimensions::scaled.bevel.left, ce.bounds.right - WidgetDimensions::scaled.bevel.right, ce.bounds.top + tmargin - scrollpos,
742 ce.pe->text.GetDecodedString(), TextColour::White, {AlignmentH::Centre, AlignmentV::Middle});
743 break;
744 }
745
746 default: NOT_REACHED();
747 }
748 }
749 }
750
751 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
752 {
753 if (widget != WID_SB_SEL_PAGE && widget != WID_SB_PAGE_PANEL) return;
754
755 Dimension d;
757 d.width = 0;
758
759 switch (widget) {
760 case WID_SB_SEL_PAGE: {
761
762 /* Get max title width. */
763 for (size_t i = 0; i < this->story_pages.size(); i++) {
764 const StoryPage *s = this->story_pages[i];
765 Dimension title_d = GetStringBoundingBox(s->title.empty() ? this->selected_generic_title : s->title.GetDecodedString());
766
767 if (title_d.width > d.width) {
768 d.width = title_d.width;
769 }
770 }
771
772 d.width += padding.width;
773 d.height += padding.height;
774 size = maxdim(size, d);
775 break;
776 }
777
778 case WID_SB_PAGE_PANEL: {
779 d.height *= 5;
780 d.height += padding.height + WidgetDimensions::scaled.frametext.Vertical();
781 size = maxdim(size, d);
782 break;
783 }
784 }
785
786 }
787
788 void OnResize() override
789 {
791 this->vscroll->SetCapacityFromWidget(this, WID_SB_PAGE_PANEL, WidgetDimensions::scaled.frametext.Vertical());
792 this->vscroll->SetCount(this->GetContentHeight());
793 }
794
795 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
796 {
797 switch (widget) {
798 case WID_SB_SEL_PAGE: {
799 DropDownList list = this->BuildDropDownList();
800 if (!list.empty()) {
801 /* Get the index of selected page. */
802 int selected = 0;
803 for (size_t i = 0; i < this->story_pages.size(); i++) {
804 const StoryPage *p = this->story_pages[i];
805 if (p->index == this->selected_page_id) break;
806 selected++;
807 }
808
809 ShowDropDownList(this, std::move(list), selected, widget);
810 }
811 break;
812 }
813
814 case WID_SB_PREV_PAGE:
815 this->SelectPrevPage();
816 break;
817
818 case WID_SB_NEXT_PAGE:
819 this->SelectNextPage();
820 break;
821
822 case WID_SB_PAGE_PANEL: {
823 int clicked_y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SB_PAGE_PANEL, WidgetDimensions::scaled.frametext.top);
825
826 for (const LayoutCacheElement &ce : this->layout_cache) {
827 if (clicked_y >= ce.bounds.top && clicked_y < ce.bounds.bottom && pt.x >= ce.bounds.left && pt.x < ce.bounds.right) {
828 this->OnPageElementClick(*ce.pe);
829 return;
830 }
831 }
832 }
833 }
834 }
835
836 void OnDropdownSelect(WidgetID widget, int index, int) override
837 {
838 if (widget != WID_SB_SEL_PAGE) return;
839
840 /* index (which is set in BuildDropDownList) is the page id. */
841 this->SetSelectedPage(static_cast<StoryPageID>(index));
842 }
843
851 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
852 {
853 if (!gui_scope) return;
854
855 /* If added/removed page, force rebuild. Sort order never change so just a
856 * re-sort is never needed.
857 */
858 if (data == -1) {
859 this->story_pages.ForceRebuild();
860 this->BuildStoryPageList();
861
862 /* Was the last page removed? */
863 if (this->story_pages.empty()) {
864 this->selected_generic_title.clear();
865 }
866
867 /* Verify page selection. */
868 if (!StoryPage::IsValidID(this->selected_page_id)) {
869 this->selected_page_id = StoryPageID::Invalid();
870 }
871 if (this->selected_page_id == StoryPageID::Invalid() && !this->story_pages.empty()) {
872 /* No page is selected, but there exist at least one available.
873 * => Select first page.
874 */
875 this->SetSelectedPage(this->story_pages[0]->index);
876 }
877
878 this->SetWidgetDisabledState(WID_SB_SEL_PAGE, this->story_pages.empty());
881 } else if (data >= 0 && this->selected_page_id == data) {
882 this->RefreshSelectedPage();
883 }
884 }
885
886 void OnTimeout() override
887 {
888 this->active_button_id = StoryPageElementID::Invalid();
890 }
891
892 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
893 {
894 const StoryPageElement *const pe = StoryPageElement::GetIfValid(this->active_button_id);
895 if (pe == nullptr || pe->type != StoryPageElementType::ButtonTile) {
897 this->active_button_id = StoryPageElementID::Invalid();
899 return;
900 }
901
902 Command<Commands::StoryPageButton>::Post(tile, pe->index, VehicleID::Invalid());
904 }
905
906 bool OnVehicleSelect(const Vehicle *v) override
907 {
908 const StoryPageElement *const pe = StoryPageElement::GetIfValid(this->active_button_id);
909 if (pe == nullptr || pe->type != StoryPageElementType::ButtonVehicle) {
911 this->active_button_id = StoryPageElementID::Invalid();
913 return false;
914 }
915
916 /* Check that the vehicle matches the requested type */
917 StoryPageButtonData data{ pe->referenced_id };
918 VehicleType wanted_vehtype = data.GetVehicleType();
919 if (wanted_vehtype != VehicleType::Invalid && wanted_vehtype != v->type) return false;
920
921 Command<Commands::StoryPageButton>::Post(TileIndex{}, pe->index, v->index);
923 return true;
924 }
925
926 void OnPlaceObjectAbort() override
927 {
928 this->active_button_id = StoryPageElementID::Invalid();
930 }
931};
932
933const std::initializer_list<GUIStoryPageList::SortFunction * const> StoryBookWindow::page_sorter_funcs = {
934 &PageOrderSorter,
935};
936
937const std::initializer_list<GUIStoryPageElementList::SortFunction * const> StoryBookWindow::page_element_sorter_funcs = {
938 &PageElementOrderSorter,
939};
940
941static constexpr std::initializer_list<NWidgetPart> _nested_story_book_widgets = {
948 EndContainer(),
952 EndContainer(),
954 NWidget(WWT_TEXTBTN, Colours::Brown, WID_SB_PREV_PAGE), SetMinimalSize(100, 0), SetFill(0, 0), SetStringTip(STR_STORY_BOOK_PREV_PAGE, STR_STORY_BOOK_PREV_PAGE_TOOLTIP),
956 SetToolTip(STR_STORY_BOOK_SEL_PAGE_TOOLTIP), SetResize(1, 0),
957 NWidget(WWT_TEXTBTN, Colours::Brown, WID_SB_NEXT_PAGE), SetMinimalSize(100, 0), SetFill(0, 0), SetStringTip(STR_STORY_BOOK_NEXT_PAGE, STR_STORY_BOOK_NEXT_PAGE_TOOLTIP),
959 EndContainer(),
960};
961
964 WindowPosition::Automatic, "view_story", 400, 300,
965 WindowClass::StoryBook, WindowClass::None,
966 {},
967 _nested_story_book_widgets
968);
969
972 WindowPosition::Center, "view_story_gs", 400, 300,
973 WindowClass::StoryBook, WindowClass::None,
974 {},
975 _nested_story_book_widgets
976);
977
978static CursorID TranslateStoryPageButtonCursor(StoryPageButtonCursor cursor)
979{
980 switch (cursor) {
1036 default: return SPR_CURSOR_QUERY;
1037 }
1038}
1039
1046void ShowStoryBook(CompanyID company, StoryPageID page_id, bool centered)
1047{
1048 if (!Company::IsValidID(company)) company = (CompanyID)CompanyID::Invalid();
1049
1051 if (page_id != StoryPageID::Invalid()) w->SetSelectedPage(page_id);
1052}
@ None
Tile is not animated.
std::string GetDecodedString() const
Decode the encoded string.
Definition strings.cpp:206
List template of 'things' T to sort in a GUI.
void RebuildDone()
Notify the sortlist that the rebuild is done.
bool NeedRebuild() const
Check if a rebuild is needed.
void ForceRebuild()
Force that a rebuild is needed.
bool Sort(Comp compare)
Sort the list.
void SetSortFuncs(std::span< SortFunction *const > n_funcs)
Hand the sort function pointers to the GUIList.
Scrollbar data structure.
void SetCount(size_t num)
Sets the number of elements in the list.
size_type GetScrolledRowFromWidget(int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition widget.cpp:2474
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition widget.cpp:2548
size_type GetCount() const
Gets the number of elements in the list.
void SetStepSize(size_t stepsize)
Set the distance to scroll when using the buttons or the wheel.
size_type GetPosition() const
Gets the position of the first visible element in the list.
static constexpr TimerGame< struct Calendar >::Date INVALID_DATE
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
Functions related to commands.
Definition of stuff that is very close to a company, like the company struct itself.
std::unique_ptr< DropDownListItem > MakeDropDownListStringItem(StringID str, int value, bool masked, bool shaded)
Creates new DropDownListStringItem.
Definition dropdown.cpp:49
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, DropDownOptions options, std::string *const persistent_filter_text)
Show a drop down list.
Definition dropdown.cpp:591
Functions related to the drop down widget.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:88
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Geometry functions.
bool DrawStringMultiLineWithClipping(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw a multiline string, possibly over multiple lines, if the region is within the current display cl...
Definition gfx.cpp:867
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition gfx.cpp:711
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:966
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:894
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:1032
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition gfx.cpp:782
int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:663
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:1567
bool IsCtrlPressed()
Test if the ctrl key is pressed.
Definition gfx_func.h:82
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
@ Normal
Index of the normal font in the font tables.
Definition gfx_type.h:249
@ Right
Right.
Definition gfx_type.h:437
@ Left
Left.
Definition gfx_type.h:435
uint32_t CursorID
The number of the cursor (sprite).
Definition gfx_type.h:19
Colours
One of 16 base colours used for companies and windows/widgets.
Definition gfx_type.h:283
@ Brown
Brown.
Definition gfx_type.h:298
@ White
White colour.
Definition gfx_type.h:330
@ Black
Black colour.
Definition gfx_type.h:334
Goal base class.
void ShowGoalsList(CompanyID company)
Open a goal list window.
Definition goal_gui.cpp:311
Goal GUI functions.
PoolID< uint16_t, struct GoalIDTag, 64000, 0xFFFF > GoalID
ID of a goal.
Definition goal_type.h:63
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
static const CursorID ANIMCURSOR_PICKSTATION
716 - 718 - goto-order icon
Definition sprites.h:1697
static const CursorID ANIMCURSOR_BUILDSIGNALS
1292 - 1293 - build signal
Definition sprites.h:1698
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
Definition sprites.h:1694
static const CursorID ANIMCURSOR_LOWERLAND
699 - 701 - lower land tool
Definition sprites.h:1695
static const CursorID ANIMCURSOR_RAISELAND
696 - 698 - raise land tool
Definition sprites.h:1696
static const CursorID SPR_CURSOR_RIVER
Definition sprites.h:1595
static const CursorID SPR_CURSOR_TUNNEL_ELRAIL
Definition sprites.h:1627
static const CursorID SPR_CURSOR_RAIL_DEPOT
Definition sprites.h:1638
static const CursorID SPR_CURSOR_CLONE_AIRPLANE
Definition sprites.h:1667
static const CursorID SPR_CURSOR_CONVERT_ELRAIL
Definition sprites.h:1644
static const CursorID SPR_CURSOR_CANAL
Definition sprites.h:1593
static const CursorID SPR_CURSOR_CONVERT_MAGLEV
Definition sprites.h:1646
static const CursorID SPR_CURSOR_ROAD_TUNNEL
Definition sprites.h:1660
static const CursorID SPR_CURSOR_LEVEL_LAND
Definition sprites.h:1578
static const CursorID SPR_CURSOR_CLONE_TRAIN
Definition sprites.h:1664
static const CursorID SPR_CURSOR_AUTOMAGLEV
Definition sprites.h:1634
static const CursorID SPR_CURSOR_RAIL_STATION
Definition sprites.h:1624
static const CursorID SPR_CURSOR_CLONE_ROADVEH
Definition sprites.h:1665
static const CursorID SPR_CURSOR_AQUEDUCT
Definition sprites.h:1596
static const CursorID SPR_CURSOR_BRIDGE
Definition sprites.h:1600
static const CursorID SPR_CURSOR_MAGLEV_DEPOT
Definition sprites.h:1641
static const CursorID SPR_CURSOR_TOWN
Definition sprites.h:1580
static const CursorID SPR_CURSOR_TREE
Definition sprites.h:1576
static const CursorID SPR_CURSOR_TUNNEL_MONO
Definition sprites.h:1628
static const CursorID SPR_CURSOR_DOCK
Definition sprites.h:1592
static const CursorID SPR_CURSOR_AIRPORT
Definition sprites.h:1588
static const CursorID SPR_CURSOR_HQ
Definition sprites.h:1572
static const CursorID SPR_CURSOR_BUS_STATION
Definition sprites.h:1658
static const CursorID SPR_CURSOR_AUTOTRAM
Definition sprites.h:1655
static const CursorID SPR_CURSOR_SIGN
Definition sprites.h:1574
static const CursorID SPR_CURSOR_ROAD_DEPOT
Definition sprites.h:1657
static const CursorID SPR_CURSOR_SHIP_DEPOT
Definition sprites.h:1573
static const CursorID SPR_CURSOR_INDUSTRY
Definition sprites.h:1581
static const CursorID SPR_CURSOR_ROCKY_AREA
Definition sprites.h:1582
static const CursorID SPR_CURSOR_ELRAIL_DEPOT
Definition sprites.h:1639
static const CursorID SPR_CURSOR_ZZZ
Definition sprites.h:1569
static const CursorID SPR_CURSOR_WAYPOINT
Definition sprites.h:1636
static const CursorID SPR_CURSOR_MOUSE
Definition sprites.h:1568
static const CursorID SPR_CURSOR_AUTOELRAIL
Definition sprites.h:1632
static const CursorID SPR_CURSOR_DESERT
Definition sprites.h:1583
static const CursorID SPR_CURSOR_CONVERT_RAIL
Definition sprites.h:1643
static const CursorID SPR_CURSOR_CONVERT_MONO
Definition sprites.h:1645
static const CursorID SPR_CURSOR_TUNNEL_RAIL
Definition sprites.h:1626
static const CursorID SPR_CURSOR_TRUCK_STATION
Definition sprites.h:1659
static const CursorID SPR_CURSOR_BUOY
Definition sprites.h:1570
static const CursorID SPR_CURSOR_QUERY
Definition sprites.h:1571
static const CursorID SPR_CURSOR_CLONE_SHIP
Definition sprites.h:1666
static const CursorID SPR_CURSOR_AUTOMONO
Definition sprites.h:1633
static const CursorID SPR_CURSOR_AUTOROAD
Definition sprites.h:1652
static const CursorID SPR_CURSOR_MONO_DEPOT
Definition sprites.h:1640
static const CursorID SPR_CURSOR_TRANSMITTER
Definition sprites.h:1584
static const CursorID SPR_CURSOR_LOCK
Definition sprites.h:1594
static const CursorID SPR_CURSOR_BUY_LAND
Definition sprites.h:1577
static const CursorID SPR_CURSOR_TUNNEL_MAGLEV
Definition sprites.h:1629
static const CursorID SPR_CURSOR_AUTORAIL
Definition sprites.h:1631
GUI functions that shouldn't be here.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
#define Point
Macro that prevents name conflicts between included headers.
A number of safeguards to prevent using unsafe methods.
Base types for having sorted lists in GUIs.
This file contains all sprite-related enums and defines.
static const SpriteID SPR_IMG_GOAL_COMPLETED
Definition sprites.h:1547
static const SpriteID SPR_IMG_VIEW_LOCATION
Definition sprites.h:1545
static const SpriteID SPR_IMG_GOAL_BROKEN_REF
Definition sprites.h:1548
static const SpriteID SPR_IMG_GOAL
Definition sprites.h:1546
Definition of base types and functions in a cross-platform compatible way.
StoryPage base class.
@ Goal
An element that references a goal.
Definition story_base.h:32
@ ButtonTile
A button that allows the player to select a tile, and triggers an event with the tile.
Definition story_base.h:34
@ ButtonVehicle
A button that allows the player to select a vehicle, and triggers an event with the vehicle.
Definition story_base.h:35
@ ButtonPush
A push button that triggers an immediate event.
Definition story_base.h:33
@ Text
A text element.
Definition story_base.h:30
@ Location
An element that references a tile along with a one-line text.
Definition story_base.h:31
StoryPageButtonCursor
Mouse cursors usable by story page buttons.
Definition story_base.h:49
@ Desert
Use the Desert cursor.
Definition story_base.h:63
@ Dock
Use the Dock cursor.
Definition story_base.h:66
@ BuyLand
Use the Buy Land cursor.
Definition story_base.h:58
@ River
Use the River cursor.
Definition story_base.h:69
@ AutoRail
Use the Auto Rail cursor.
Definition story_base.h:77
@ LowerLand
Use the Lower Land cursor.
Definition story_base.h:101
@ Waypoint
Use the Waypoint cursor.
Definition story_base.h:81
@ TruckStation
Use the Truck Station cursor.
Definition story_base.h:94
@ ConvertMono
Use the Convert Mono cursor.
Definition story_base.h:88
@ PickStation
Use the Pick Station cursor.
Definition story_base.h:103
@ MonoDepot
Use the Mono Depot cursor.
Definition story_base.h:84
@ Sign
Use the Sign cursor.
Definition story_base.h:56
@ Transmitter
Use the Transmitter cursor.
Definition story_base.h:64
@ Tree
Use the Tree cursor.
Definition story_base.h:57
@ Demolish
Use the Demolish cursor.
Definition story_base.h:100
@ Industry
Use the Industry cursor.
Definition story_base.h:61
@ AutoMono
Use the Auto Mono cursor.
Definition story_base.h:79
@ BuildSignals
Use the Build Signals cursor.
Definition story_base.h:104
@ ConvertRail
Use the Convert Rail cursor.
Definition story_base.h:86
@ RockyArea
Use the RockyArea cursor.
Definition story_base.h:62
@ AutoTram
Use the Auto Tram cursor.
Definition story_base.h:91
@ RailDepot
Use the Rail Depot cursor.
Definition story_base.h:82
@ Query
Use the Query cursor.
Definition story_base.h:53
@ RailStation
Use the Rail Station cursor.
Definition story_base.h:72
@ RoadDepot
Use the Road Depot cursor.
Definition story_base.h:92
@ TunnelElrail
Use the Tunnel Elrail cursor.
Definition story_base.h:74
@ MaglevDepot
Use the Maglev Depot cursor.
Definition story_base.h:85
@ CloneAirplane
Use the Clone Airplane cursor.
Definition story_base.h:99
@ CloneRoadVeh
Use the Clone Road Veh cursor.
Definition story_base.h:97
@ RaiseLand
Use the Raise Land cursor.
Definition story_base.h:102
@ ConvertMaglev
Use the Convert Maglev cursor.
Definition story_base.h:89
@ CloneShip
Use the Clone Ship cursor.
Definition story_base.h:98
@ RoadTunnel
Use the Road Tunnel cursor.
Definition story_base.h:95
@ HQ
Use the HQ cursor.
Definition story_base.h:54
@ ShipDepot
Use the Ship Depot cursor.
Definition story_base.h:55
@ TunnelRail
Use the Tunnel Rail cursor.
Definition story_base.h:73
@ Canal
Use the Canal cursor.
Definition story_base.h:67
@ CloneTrain
Use the Clone Train cursor.
Definition story_base.h:96
@ TunnelMaglev
Use the Tunnel Maglev cursor.
Definition story_base.h:76
@ Buoy
Use the Buoy cursor.
Definition story_base.h:52
@ AutoRoad
Use the Auto Road cursor.
Definition story_base.h:90
@ Lock
Use the Lock cursor.
Definition story_base.h:68
@ BusStation
Use the Bus Station cursor.
Definition story_base.h:93
@ Aqueduct
Use the Aqueduct cursor.
Definition story_base.h:70
@ Town
Use the Town cursor.
Definition story_base.h:60
@ TunnelMono
Use the Tunnel Mono cursor.
Definition story_base.h:75
@ Zzz
Use the Zzz cursor.
Definition story_base.h:51
@ ConvertElrail
Use the Convert Elrail cursor.
Definition story_base.h:87
@ AutoElrail
Use the Auto Elrail cursor.
Definition story_base.h:78
@ LevelLand
Use the Level Land cursor.
Definition story_base.h:59
@ Bridge
Use the Bridge cursor.
Definition story_base.h:71
@ Airport
Use the Airport cursor.
Definition story_base.h:65
@ ElrailDepot
Use the Elrail Depot cursor.
Definition story_base.h:83
@ Mouse
Use the Mouse cursor.
Definition story_base.h:50
@ AutoMaglev
Use the Auto Maglev cursor.
Definition story_base.h:80
@ FloatLeft
Button will float on the left.
Definition story_base.h:41
@ FloatRight
Button will float on the right.
Definition story_base.h:42
EnumBitSet< StoryPageButtonFlag, uint8_t > StoryPageButtonFlags
Bitset of StoryPageButtonFlag elements.
Definition story_base.h:46
Command definitions related to stories.
void ShowStoryBook(CompanyID company, StoryPageID page_id, bool centered)
Raise or create the story book window for company, at page page_id.
static WindowDesc _story_book_desc(WindowPosition::Automatic, "view_story", 400, 300, WindowClass::StoryBook, WindowClass::None, {}, _nested_story_book_widgets)
Window definition for the story book window.
static WindowDesc _story_book_gs_desc(WindowPosition::Center, "view_story_gs", 400, 300, WindowClass::StoryBook, WindowClass::None, {}, _nested_story_book_widgets)
Window definition for the game script window.
PoolID< uint16_t, struct StoryPageIDTag, 64000, 0xFFFF > StoryPageID
ID of a story page.
Definition story_type.h:16
PoolID< uint16_t, struct StoryPageElementIDTag, 64000, 0xFFFF > StoryPageElementID
ID of a story page element.
Definition story_type.h:15
Types related to the story widgets.
@ WID_SB_PAGE_PANEL
Page body.
@ WID_SB_SEL_PAGE
Page selector.
@ WID_SB_SCROLLBAR
Scrollbar of the goal list.
@ WID_SB_CAPTION
Caption of the window.
@ WID_SB_PREV_PAGE
Prev button.
@ WID_SB_NEXT_PAGE
Next button.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:423
Functions related to OTTD's strings.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
VehicleType type
Type of vehicle.
Dimensions (a width and height) of a rectangle in 2D.
value_type height
The height of the rectangle.
value_type width
The width of the rectangle.
Data about how and where to blit pixels.
Definition gfx_type.h:157
Struct about goals, current and completed.
Definition goal_base.h:22
EncodedString text
Text of the goal.
Definition goal_base.h:26
bool completed
Is the goal completed or not?
Definition goal_base.h:28
static Pool::IterateWrapper< StoryPage > Iterate(size_t from=0)
static StoryPage * Get(auto index)
static StoryPageElement * GetIfValid(auto index)
Specification of a rectangle with absolute coordinates of all edges.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
void OnTimeout() override
Called when this window's timeout has been reached.
void BuildStoryPageList()
(Re)Build story page list.
Definition story_gui.cpp:68
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
std::string selected_generic_title
If the selected page doesn't have a custom title, this buffer is used to store a generic page title.
Definition story_gui.cpp:60
void OnPageElementClick(const StoryPageElement &pe)
Internal event handler for when a page element is clicked.
void OnResize() override
Called after the window got resized.
static bool PageElementOrderSorter(const StoryPageElement *const &a, const StoryPageElement *const &b)
Sort story page elements by order value.
uint GetAvailablePageContentWidth() const
Get the width available for displaying content on the page panel.
void OnPaint() override
The window must be repainted.
void SetSelectedPage(StoryPageID page_index)
Sets the selected page.
bool IsFirstPageSelected()
Check if the selected page is also the first available page.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
DropDownList BuildDropDownList() const
Builds the page selector drop down list.
int GetPageElementFloatWidth(const StoryPageElement &pe) const
Get the width a page element would use if it was floating left or right.
LayoutCache layout_cache
Cached element layout.
Definition story_gui.cpp:55
void UpdatePrevNextDisabledState()
Updates the disabled state of the prev/next buttons.
Scrollbar * vscroll
Scrollbar of the page text.
Definition story_gui.cpp:54
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
void SelectNextPage()
Selects the next available page after the currently selected page.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
bool IsPageAvailable(const StoryPage *page) const
Checks if a given page should be visible in the story book.
void SelectPrevPage()
Selects the previous available page before the currently selected page.
void RefreshSelectedPage()
Updates the content of selected page.
StoryPageID selected_page_id
Pool index of selected page.
Definition story_gui.cpp:59
bool IsLastPageSelected()
Check if the selected page is also the last available page.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
GUIStoryPageList story_pages
Sorted list of pages.
Definition story_gui.cpp:57
void InvalidateStoryPageElementLayout()
Invalidate the current page layout.
void DrawActionElement(int &y_offset, int width, int line_height, SpriteID action_sprite, const std::string &text) const
Draws a page element that is composed of a sprite to the left and a single line of text after that.
void BuildStoryPageElementList()
(Re)Build story page element list.
Definition story_gui.cpp:92
StoryPage * GetSelPage() const
Get instance of selected page.
static bool PageOrderSorter(const StoryPage *const &a, const StoryPage *const &b)
Sort story pages by order value.
Definition story_gui.cpp:86
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
StoryPageElementID active_button_id
Which button element the player is currently using.
Definition story_gui.cpp:62
int32_t GetContentHeight()
Get the total height of the content displayed in this window.
uint GetHeadHeight(int max_width) const
Counts how many pixels of height that are used by Date and Title (excluding marginal after Title,...
uint GetPageElementHeight(const StoryPageElement &pe, int max_width) const
Get the height in pixels used by a page element.
int GetSelPageNum() const
Get the page number of selected page.
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
SpriteID GetPageElementSprite(const StoryPageElement &pe) const
Decides which sprite to display for a given page element.
void EnsureStoryPageElementLayout() const
Create the page layout if it is missing.
GUIStoryPageElementList story_page_elements
Sorted list of page elements that belong to the current page.
Definition story_gui.cpp:58
ElementFloat GetPageElementFloat(const StoryPageElement &pe) const
Get the float style of a page element.
Helper to construct packed "id" values for button-type StoryPageElement.
Definition story_base.h:121
Colours GetColour() const
Get the button background colour.
Definition story.cpp:171
VehicleType GetVehicleType() const
Get the type of vehicles that are accepted by the button.
Definition story.cpp:202
StoryPageButtonFlags GetFlags() const
Get the button flags.
Definition story.cpp:182
StoryPageButtonCursor GetCursor() const
Get the mouse cursor used while waiting for input for the button.
Definition story.cpp:191
Struct about story page elements.
Definition story_base.h:143
uint32_t referenced_id
Id of referenced object (location, goal etc.).
Definition story_base.h:148
EncodedString text
Static content text of page element.
Definition story_base.h:149
uint32_t 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:144
StoryPageElementType type
Type of page element.
Definition story_base.h:146
Struct about stories, current and completed.
Definition story_base.h:157
EncodedString title
Title of story page.
Definition story_base.h:162
uint32_t 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:158
CompanyID company
StoryPage is for a specific company; CompanyID::Invalid() if it is global.
Definition story_base.h:160
TimerGameCalendar::Date date
Date when the page was created.
Definition story_base.h:159
Vehicle data structure.
High level window description.
Definition window_gui.h:171
Number to differentiate different windows of the same class.
Data structure for an opened window.
Definition window_gui.h:272
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1855
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:792
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:565
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:513
ResizeInfo resize
Resize information.
Definition window_gui.h:313
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1845
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition window_gui.h:315
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition window_gui.h:354
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1879
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
WindowFlags flags
Window flags.
Definition window_gui.h:299
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:322
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:380
int height
Height of the window (number of pixels down in y direction).
Definition window_gui.h:311
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:310
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:301
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
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...
@ HT_RECT
rectangle (stations, depots, ...)
@ HT_VEHICLE
vehicle is accepted as target as well (bitmask)
Base class for all vehicles.
VehicleType
Available vehicle types.
@ Invalid
Non-existing type of vehicle.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Functions related to (drawing on) viewports.
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition widget.cpp:308
@ NWID_BUTTON_DROPDOWN
Button with a drop-down.
Definition widget_type.h:74
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:44
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX).
Definition widget_type.h:57
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX).
Definition widget_type.h:55
@ WWT_CAPTION
Window caption (window title between closebox and stickybox).
Definition widget_type.h:52
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
@ WWT_CLOSEBOX
Close box (at top-left of a window).
Definition widget_type.h:60
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window).
Definition widget_type.h:59
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX).
Definition widget_type.h:56
Functions, definitions and such used only by the GUI.
EnumBitSet< FrameFlag, uint8_t > FrameFlags
Bitset of FrameFlag elements.
Definition window_gui.h:31
@ Lowered
If set the frame is lowered and the background colour brighter (ie. buttons when pressed).
Definition window_gui.h:26
Twindow * AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
Open a new window.
@ Automatic
Find a place automatically.
Definition window_gui.h:145
@ Center
Center the window.
Definition window_gui.h:146
int WidgetID
Widget ID.
Definition window_type.h:21