31 #include "table/strings.h" 55 this->story_pages.
Clear();
58 FOR_ALL_STORY_PAGES(p) {
59 if (this->IsPageAvailable(p)) {
60 *this->story_pages.
Append() = p;
68 this->story_pages.
Sort();
74 return (*a)->sort_value - (*b)->sort_value;
81 this->story_page_elements.
Clear();
86 FOR_ALL_STORY_PAGE_ELEMENTS(pe) {
88 *this->story_page_elements.
Append() = pe;
93 this->story_page_elements.
Compact();
97 this->story_page_elements.
Sort();
103 return (*a)->sort_value - (*b)->sort_value;
111 bool IsPageAvailable(
const StoryPage *page)
const 122 if (!_story_page_pool.
IsValidID(selected_page_id))
return NULL;
123 return _story_page_pool.
Get(selected_page_id);
133 for (
const StoryPage *
const*iter = this->story_pages.
Begin(); iter != this->story_pages.
End(); iter++) {
135 if (p->
index == this->selected_page_id) {
149 if (!_story_page_pool.
IsValidID(this->selected_page_id))
return false;
151 return (*this->story_pages.
Begin())->index == this->selected_page_id;
160 if (!_story_page_pool.
IsValidID(this->selected_page_id))
return false;
162 if (this->story_pages.
Length() <= 1)
return true;
174 if (page != NULL && page->
title == NULL) {
176 GetString(selected_generic_title, STR_STORY_BOOK_GENERIC_PAGE_ITEM,
lastof(selected_generic_title));
193 if (!_story_page_pool.
IsValidID(this->selected_page_id))
return;
197 last_available = NULL;
198 for (
const StoryPage *
const*iter = this->story_pages.
Begin(); iter != this->story_pages.
End(); iter++) {
200 if (p->
index == this->selected_page_id) {
201 if (last_available == NULL)
return;
214 if (!_story_page_pool.
IsValidID(this->selected_page_id))
return;
217 for (
const StoryPage *
const*iter = this->story_pages.
Begin(); iter != this->story_pages.
End(); iter++) {
219 if (p->
index == this->selected_page_id) {
222 if (iter != this->story_pages.
End()) {
237 for (
const StoryPage *
const*iter = this->story_pages.
Begin(); iter != this->story_pages.
End(); iter++) {
241 if (p->
title != NULL) {
247 str_item->SetParam(0, page_num);
256 if (list->
Length() == 0) {
282 if (page == NULL)
return 0;
304 if (g == NULL)
return SPR_IMG_GOAL_BROKEN_REF;
305 return g->
completed ? SPR_IMG_GOAL_COMPLETED : SPR_IMG_GOAL;
308 return SPR_IMG_VIEW_LOCATION;
331 return sprite_dim.height;
348 if (page == NULL)
return 0;
356 for (
const StoryPageElement **iter = this->story_page_elements.
Begin(); iter != this->story_page_elements.
End(); iter++) {
358 height += element_vertical_dist;
379 uint element_height =
max(sprite_dim.height, (uint)line_height);
381 uint sprite_top = y_offset + (element_height - sprite_dim.height) / 2;
382 uint text_top = y_offset + (element_height - line_height) / 2;
384 DrawSprite(action_sprite, PAL_NONE, 0, sprite_top);
387 y_offset += element_height;
426 this->story_pages.
SetSortFuncs(StoryBookWindow::page_sorter_funcs);
429 this->story_page_elements.
SetSortFuncs(StoryBookWindow::page_element_sorter_funcs);
436 this->selected_generic_title[0] =
'\0';
459 if (this->selected_page_id != page_index) {
460 this->selected_page_id = page_index;
476 SetDParam(0, STR_STORY_BOOK_SPECTATOR_CAPTION);
505 if (page == NULL)
return;
526 DrawString(0, right - x, y_offset, STR_JUST_DATE_LONG, TC_BLACK);
528 y_offset += line_height;
535 for (
const StoryPageElement *
const*iter = this->story_page_elements.
Begin(); iter != this->story_page_elements.
End(); iter++) {
537 y_offset += line_height;
547 StringID string_id = g == NULL ? STR_STORY_BOOK_INVALID_GOAL_REF : STR_JUST_RAW_STRING;
558 default: NOT_REACHED();
578 for (uint16 i = 0; i < this->story_pages.
Length(); i++) {
579 const StoryPage *s = this->story_pages[i];
581 if (s->
title != NULL) {
588 if (title_d.width > d.width) {
589 d.width = title_d.width;
593 d.width += padding.width;
594 d.height += padding.height;
623 for (uint16 i = 0; i < this->story_pages.
Length(); i++) {
624 const StoryPage *p = this->story_pages[i];
625 if (p->
index == this->selected_page_id)
break;
648 if (clicked_y < head_height)
return;
651 uint y = head_height;
653 for (
const StoryPageElement *
const*iter = this->story_page_elements.
Begin(); iter != this->story_page_elements.
End(); iter++) {
656 y += element_vertical_dist;
659 if (clicked_y >= y && clicked_y < y + content_height) {
687 if (!gui_scope)
return;
697 if (this->story_pages.
Length() == 0) {
698 this->selected_generic_title[0] =
'\0';
702 if (!_story_page_pool.
IsValidID(this->selected_page_id)) {
715 }
else if (data >= 0 && this->selected_page_id == data) {
729 static const NWidgetPart _nested_story_book_widgets[] = {
758 _nested_story_book_widgets,
lengthof(_nested_story_book_widgets)
770 StoryBookWindow *w = AllocateWindowDescFront<StoryBookWindow>(&_story_book_desc, company,
true);
Functions related to OTTD's strings.
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.
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.
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
High level window description.
StoryPageID page
Id of the page which the page element belongs to.
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.
void ShowDropDownList(Window *w, const DropDownList *list, int selected, int button, uint width, bool auto_width, bool instant_close)
Show a drop down list.
virtual void OnResize()
Called after the window got resized.
bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) 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.
static int CDECL PageElementOrderSorter(const StoryPageElement *const *a, const StoryPageElement *const *b)
Sort story page elements by order value.
void RefreshSelectedPage()
Updates the content of selected page.
void Clear()
Remove all items from the list.
void Compact()
Compact the list down to the smallest block size boundary.
const T * Begin() const
Get the pointer to the first item (const)
Tindex index
Index of this pool item.
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
DropDownList * BuildDropDownList() const
Builds the page selector drop down list.
char * title
Title of story page.
#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.
const T * End() const
Get the pointer behind the last valid item (const)
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.
T * Append(uint to_add=1)
Append an item and return it.
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.
virtual void OnPaint()
The window must be repainted.
Struct about stories, current and completed.
StoryPageID selected_page_id
Pool index of selected page.
uint Length() const
Get the number of items in the list.
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.
Simple vector template class, with automatic delete.
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.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
virtual void OnDropdownSelect(int widget, int index)
A dropdown option associated to this window has been selected.
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.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
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.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
CompanyByte company
StoryPage is for a specific company; INVALID_COMPANY if it is global.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
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.
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.
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.
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?
int CDECL SortFunction(const T *, const T *)
Signature of sort function.
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.
An element that references a goal.
Functions related to commands.
static int CDECL PageOrderSorter(const StoryPage *const *a, const StoryPage *const *b)
Sort story pages by order value.
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-NULL) 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)
An element that references a tile along with a one-line text.
int32 WindowNumber
Number to differentiate different windows of the same class.
char * text
Static content text of page element.
StoryPageElementTypeByte type
Type 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.
Owner
Enum for all companies/owners.
Window functions not directly related to making/drawing windows.
String list item with parameters.
GUI functions that shouldn't be here.
uint16 StoryPageID
ID of a story page.
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)
AutoDeleteSmallVector< const DropDownListItem *, 4 > DropDownList
A drop down list is a collection of drop down list items.
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.