29 #include "table/strings.h" 53 this->story_pages.clear();
56 if (this->IsPageAvailable(p)) {
57 this->story_pages.push_back(p);
61 this->story_pages.shrink_to_fit();
65 this->story_pages.
Sort();
78 this->story_page_elements.clear();
83 if (pe->page == p->
index) {
84 this->story_page_elements.push_back(pe);
89 this->story_page_elements.shrink_to_fit();
93 this->story_page_elements.
Sort();
107 bool IsPageAvailable(
const StoryPage *page)
const 118 if (!_story_page_pool.
IsValidID(selected_page_id))
return nullptr;
119 return _story_page_pool.
Get(selected_page_id);
129 for (
const StoryPage *p : this->story_pages) {
130 if (p->index == this->selected_page_id) {
144 if (!_story_page_pool.
IsValidID(this->selected_page_id))
return false;
155 if (!_story_page_pool.
IsValidID(this->selected_page_id))
return false;
157 if (this->story_pages.size() <= 1)
return true;
158 const StoryPage *last = this->story_pages.back();
169 if (page !=
nullptr && page->
title ==
nullptr) {
171 GetString(selected_generic_title, STR_STORY_BOOK_GENERIC_PAGE_ITEM,
lastof(selected_generic_title));
188 if (!_story_page_pool.
IsValidID(this->selected_page_id))
return;
192 last_available =
nullptr;
193 for (
const StoryPage *p : this->story_pages) {
194 if (p->index == this->selected_page_id) {
195 if (last_available ==
nullptr)
return;
208 if (!_story_page_pool.
IsValidID(this->selected_page_id))
return;
211 for (
auto iter = this->story_pages.begin(); iter != this->story_pages.end(); iter++) {
213 if (p->
index == this->selected_page_id) {
216 if (iter != this->story_pages.end()) {
231 for (
const StoryPage *p : this->story_pages) {
234 if (p->title !=
nullptr) {
240 str_item->SetParam(0, page_num);
244 list.emplace_back(item);
269 if (page ==
nullptr)
return 0;
291 if (g ==
nullptr)
return SPR_IMG_GOAL_BROKEN_REF;
292 return g->
completed ? SPR_IMG_GOAL_COMPLETED : SPR_IMG_GOAL;
295 return SPR_IMG_VIEW_LOCATION;
318 return sprite_dim.height;
335 if (page ==
nullptr)
return 0;
344 height += element_vertical_dist;
365 uint element_height =
max(sprite_dim.height, (uint)line_height);
367 uint sprite_top = y_offset + (element_height - sprite_dim.height) / 2;
368 uint text_top = y_offset + (element_height - line_height) / 2;
370 DrawSprite(action_sprite, PAL_NONE, 0, sprite_top);
373 y_offset += element_height;
412 this->story_pages.
SetSortFuncs(StoryBookWindow::page_sorter_funcs);
415 this->story_page_elements.
SetSortFuncs(StoryBookWindow::page_element_sorter_funcs);
422 this->selected_generic_title[0] =
'\0';
445 if (this->selected_page_id != page_index) {
446 this->selected_page_id = page_index;
462 SetDParam(0, STR_STORY_BOOK_SPECTATOR_CAPTION);
491 if (page ==
nullptr)
return;
512 DrawString(0, right - x, y_offset, STR_JUST_DATE_LONG, TC_BLACK);
514 y_offset += line_height;
522 y_offset += line_height;
532 StringID string_id = g ==
nullptr ? STR_STORY_BOOK_INVALID_GOAL_REF : STR_JUST_RAW_STRING;
543 default: NOT_REACHED();
563 for (uint16 i = 0; i < this->story_pages.size(); i++) {
564 const StoryPage *s = this->story_pages[i];
566 if (s->
title !=
nullptr) {
573 if (title_d.width > d.width) {
574 d.width = title_d.width;
578 d.width += padding.width;
579 d.height += padding.height;
608 for (uint16 i = 0; i < this->story_pages.size(); i++) {
609 const StoryPage *p = this->story_pages[i];
610 if (p->
index == this->selected_page_id)
break;
633 if (clicked_y < head_height)
return;
636 uint y = head_height;
640 y += element_vertical_dist;
643 if (clicked_y >= y && clicked_y < y + content_height) {
671 if (!gui_scope)
return;
681 if (this->story_pages.size() == 0) {
682 this->selected_generic_title[0] =
'\0';
686 if (!_story_page_pool.
IsValidID(this->selected_page_id)) {
699 }
else if (data >= 0 && this->selected_page_id == data) {
713 static const NWidgetPart _nested_story_book_widgets[] = {
742 _nested_story_book_widgets,
lengthof(_nested_story_book_widgets)
754 StoryBookWindow *w = AllocateWindowDescFront<StoryBookWindow>(&_story_book_desc, company,
true);
Functions related to OTTD's strings.
Owner
Enum for all companies/owners.
Base types for having sorted lists in GUIs.
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition of stuff that is very close to a company, like the company struct itself.
Data about how and where to blit pixels.
Horizontally center the text.
ResizeInfo resize
Resize information.
An element that references a tile along with a one-line text.
void OnResize() override
Called after the window got resized.
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
void SelectPrevPage()
Selects the previous available page before the currently selected page.
High level window description.
void DrawWidgets() const
Paint all widgets of a window.
static Titem * Get(size_t index)
Returns Titem with given index.
Functions related to dates.
uint16 GoalID
ID of a goal.
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
void UpdatePrevNextDisabledState()
Updates the disabled state of the prev/next buttons.
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
void OnPageElementClick(const StoryPageElement &pe)
Internal event handler for when a page element is clicked.
uint32 sort_value
A number that increases for every created story page element. Used for sorting. The id of a story pag...
bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Date date
Date when the page was created.
int GetSelPageNum() const
Get the page number of selected page.
bool IsLastPageSelected()
Check if the selected page is also the last available page.
Struct about goals, current and completed.
void ShowGoalsList(CompanyID company)
Open a goal list window.
void RefreshSelectedPage()
Updates the content of selected page.
Tindex index
Index of this pool item.
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
char * title
Title of story page.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
#define lastof(x)
Get the last element of an fixed size array.
void SelectNextPage()
Selects the next available page after the currently selected page.
void BuildStoryPageList()
(Re)Build story page list.
static T max(const T a, const T b)
Returns the maximum of two values.
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...
uint GetContentHeight()
Get the total height of the content displayed in this window.
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
bool NeedRebuild() const
Check if a rebuild is needed.
Functions, definitions and such used only by the GUI.
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
void OnPaint() override
The window must be repainted.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width, bool auto_width, bool instant_close)
Show a drop down list.
Functions related to (drawing on) viewports.
void ForceRebuild()
Force that a rebuild is needed.
Struct about story page elements.
Data structure for an opened window.
bool _ctrl_pressed
Is Ctrl pressed?
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
uint32 referenced_id
Id of referenced object (location, goal etc.)
Bottom offset of the text of the frame.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Struct about stories, current and completed.
StoryPageID selected_page_id
Pool index of selected page.
Titem * Get(size_t index)
Returns Titem with given index.
void SetSelectedPage(uint16 page_index)
Sets the selected page.
GUIStoryPageElementList story_page_elements
Sorted list of page elements that belong to the current page.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition of base types and functions in a cross-platform compatible way.
static const Date INVALID_DATE
Representation of an invalid date.
A number of safeguards to prevent using unsafe methods.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
SpriteID GetPageElementSprite(const StoryPageElement &pe) const
Decides which sprite to display for a given page element.
StoryPageElementType type
Type of page element.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
uint GetPageElementHeight(const StoryPageElement &pe, int max_width)
Get the height in pixels used by a page element.
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.
Right offset of the text of the frame.
#define lengthof(x)
Return the length of an fixed size array.
bool IsFirstPageSelected()
Check if the selected page is also the first available page.
Top offset of the text of the frame.
Left offset of the text of the frame.
Types related to the drop down widget.
bool Sort(SortFunction *compare)
Sort the list.
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
uint32 sort_value
A number that increases for every created story page. Used for sorting. The id of a story page is the...
uint GetHeadHeight(int max_width) const
Counts how many pixels of height that are used by Date and Title (excluding marginal after Title...
Scrollbar * vscroll
Scrollbar of the page text.
void ShowExtraViewPortWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
static const StoryPageID INVALID_STORY_PAGE
Constant representing a non-existing story page.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
An element that references a goal.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
No window, redirects to WC_MAIN_WINDOW.
Types related to the story widgets.
Functions related to companies.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
uint GetAvailablePageContentWidth()
Get the width available for displaying content on the page panel.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
StoryPage * GetSelPage() const
Get instance of selected page.
uint32 TileIndex
The index/ID of a Tile.
static bool PageOrderSorter(const StoryPage *const &a, const StoryPage *const &b)
Sort story pages by order value.
Story book; Window numbers:
void ShowStoryBook(CompanyID company, uint16 page_id)
Raise or create the story book window for company, at page page_id.
GUIStoryPageList story_pages
Sorted list of pages.
bool completed
Is the goal completed or not?
Scrollbar of the goal list.
Functions related to the drop down widget.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Functions related to commands.
Coordinates of a point in 2D.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
List item containing a C char string.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable...
Offset at right to draw the frame rectangular area.
int width
width of the window (number of pixels to the right in x direction)
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
int32 WindowNumber
Number to differentiate different windows of the same class.
char * text
Static content text of page element.
Specification of a rectangle with absolute coordinates of all edges.
WindowNumber window_number
Window number within the window class.
char * text
Text of the goal.
Window functions not directly related to making/drawing windows.
DropDownList BuildDropDownList() const
Builds the page selector drop down list.
String list item with parameters.
GUI functions that shouldn't be here.
bool SortFunction(const T &, const T &)
Signature of sort function.
uint16 StoryPageID
ID of a story page.
static bool PageElementOrderSorter(const StoryPageElement *const &a, const StoryPageElement *const &b)
Sort story page elements by order value.
CompanyID company
StoryPage is for a specific company; INVALID_COMPANY if it is global.
void BuildStoryPageElementList()
(Re)Build story page element list.
Dimensions (a width and height) of a rectangle in 2D.
This file contains all sprite-related enums and defines.
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...
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
int height
Height of the window (number of pixels down in y direction)
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.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.