Public Member Functions | |
StoryBookWindow (WindowDesc *desc, WindowNumber window_number) | |
void | UpdatePrevNextDisabledState () |
Updates the disabled state of the prev/next buttons. | |
void | SetSelectedPage (uint16 page_index) |
Sets the selected page. | |
virtual void | SetStringParameters (int widget) const |
Initialize string parameters for a widget. | |
virtual void | OnPaint () |
The window must be repainted. | |
virtual void | DrawWidget (const Rect &r, int widget) const |
Draw the contents of a nested widget. | |
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. | |
virtual void | OnResize () |
Called after the window got resized. | |
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. | |
virtual void | OnInvalidateData (int data=0, bool gui_scope=true) |
Some data on this window has become invalid. | |
Protected Member Functions | |
void | BuildStoryPageList () |
(Re)Build story page list. | |
void | BuildStoryPageElementList () |
(Re)Build story page element list. | |
bool | IsPageAvailable (const StoryPage *page) const |
StoryPage * | GetSelPage () const |
Get instance of selected page. | |
int | GetSelPageNum () const |
Get the page number of selected page. | |
bool | IsFirstPageSelected () |
Check if the selected page is also the first available page. | |
bool | IsLastPageSelected () |
Check if the selected page is also the last available page. | |
void | RefreshSelectedPage () |
Updates the content of selected page. | |
void | SelectPrevPage () |
Selects the previous available page before the currently selected page. | |
void | SelectNextPage () |
Selects the next available page after the currently selected page. | |
DropDownList * | BuildDropDownList () const |
Builds the page selector drop down list. | |
uint | GetAvailablePageContentWidth () |
Get the width available for displaying content on the page panel. | |
uint | GetHeadHeight (int max_width) const |
Counts how many pixels of height that are used by Date and Title (excluding marginal after Title, as each body element has an empty row before the elment). | |
SpriteID | GetPageElementSprite (const StoryPageElement &pe) const |
Decides which sprite to display for a given page element. | |
uint | GetPageElementHeight (const StoryPageElement &pe, int max_width) |
Get the height in pixels used by a page element. | |
uint | GetContentHeight () |
Get the total height of the content displayed in this window. | |
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 | OnPageElementClick (const StoryPageElement &pe) |
Internal event handler for when a page element is clicked. | |
Static Protected Member Functions | |
static int CDECL | PageOrderSorter (const StoryPage *const *a, const StoryPage *const *b) |
Sort story pages by order value. | |
static int CDECL | PageElementOrderSorter (const StoryPageElement *const *a, const StoryPageElement *const *b) |
Sort story page elements by order value. | |
Protected Attributes | |
Scrollbar * | vscroll |
Scrollbar of the page text. | |
GUIStoryPageList | story_pages |
Sorted list of pages. | |
GUIStoryPageElementList | story_page_elements |
Sorted list of page elements that belong to the current page. | |
StoryPageID | selected_page_id |
Pool index of selected page. | |
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. | |
Static Protected Attributes | |
static GUIStoryPageList::SortFunction *const | page_sorter_funcs [] |
static GUIStoryPageElementList::SortFunction *const | page_element_sorter_funcs [] |
Definition at line 37 of file story_gui.cpp.
void StoryBookWindow::BuildStoryPageElementList | ( | ) | [inline, protected] |
(Re)Build story page element list.
Definition at line 76 of file story_gui.cpp.
References SmallVector< T, S >::Append(), SmallVector< T, S >::Clear(), SmallVector< T, S >::Compact(), GetSelPage(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, GUIList< T, F >::NeedRebuild(), StoryPageElement::page, GUIList< T, F >::RebuildDone(), GUIList< T, F >::Sort(), and story_page_elements.
Referenced by RefreshSelectedPage().
void StoryBookWindow::BuildStoryPageList | ( | ) | [inline, protected] |
(Re)Build story page list.
Definition at line 50 of file story_gui.cpp.
References SmallVector< T, S >::Append(), SmallVector< T, S >::Clear(), SmallVector< T, S >::Compact(), GUIList< T, F >::NeedRebuild(), GUIList< T, F >::RebuildDone(), GUIList< T, F >::Sort(), and story_pages.
Referenced by OnInvalidateData().
void StoryBookWindow::DrawActionElement | ( | int & | y_offset, | |
int | width, | |||
int | line_height, | |||
SpriteID | action_sprite, | |||
StringID | string_id = STR_JUST_RAW_STRING | |||
) | const [inline, protected] |
Draws a page element that is composed of a sprite to the left and a single line of text after that.
These page elements are generally clickable and are thus called action elements.
y_offset | Current y_offset which will get updated when this method has completed its drawing. | |
width | Width of the region available for drawing. | |
line_height | Height of one line of text. | |
action_sprite | The sprite to draw. | |
string_id | The string id to draw. |
Definition at line 374 of file story_gui.cpp.
References DrawSprite(), DrawString(), GetSpriteSize(), max(), and WD_FRAMETEXT_LEFT.
Referenced by DrawWidget().
virtual void StoryBookWindow::DrawWidget | ( | const Rect & | r, | |
int | widget | |||
) | const [inline, virtual] |
Draw the contents of a nested widget.
r | Rectangle occupied by the widget. | |
widget | Number of the widget to draw. |
Reimplemented from Window.
Definition at line 498 of file story_gui.cpp.
References SmallVector< T, S >::Begin(), StoryPage::date, DrawActionElement(), DrawString(), DrawStringMultiLine(), SmallVector< T, S >::End(), FillDrawPixelInfo(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_goal_pool >::Get(), GetPageElementSprite(), Scrollbar::GetPosition(), GetSelPage(), INVALID_DATE, StoryPageElement::referenced_id, SA_HOR_CENTER, SA_LEFT, SA_TOP, SetDParam(), SetDParamStr(), SPET_GOAL, SPET_LOCATION, SPET_TEXT, story_page_elements, Goal::text, StoryPageElement::text, StoryPage::title, StoryPageElement::type, vscroll, and WID_SB_PAGE_PANEL.
uint StoryBookWindow::GetContentHeight | ( | ) | [inline, protected] |
Get the total height of the content displayed in this window.
Definition at line 343 of file story_gui.cpp.
References SmallVector< T, S >::Begin(), SmallVector< T, S >::End(), GetAvailablePageContentWidth(), GetHeadHeight(), GetPageElementHeight(), GetSelPage(), Window::height, and story_page_elements.
Referenced by OnPaint(), OnResize(), and RefreshSelectedPage().
uint StoryBookWindow::GetHeadHeight | ( | int | max_width | ) | const [inline, protected] |
Counts how many pixels of height that are used by Date and Title (excluding marginal after Title, as each body element has an empty row before the elment).
max_width | Available width to display content. |
Definition at line 277 of file story_gui.cpp.
References GetSelPage(), GetStringHeight(), Window::height, SetDParamStr(), and StoryPage::title.
Referenced by GetContentHeight(), and OnClick().
uint StoryBookWindow::GetPageElementHeight | ( | const StoryPageElement & | pe, | |
int | max_width | |||
) | [inline, protected] |
Get the height in pixels used by a page element.
pe | The story page element. | |
max_width | Available width to display content. |
Definition at line 318 of file story_gui.cpp.
References GetPageElementSprite(), GetSpriteSize(), GetStringHeight(), SetDParamStr(), SPET_GOAL, SPET_LOCATION, SPET_TEXT, StoryPageElement::text, and StoryPageElement::type.
Referenced by GetContentHeight(), and OnClick().
SpriteID StoryBookWindow::GetPageElementSprite | ( | const StoryPageElement & | pe | ) | const [inline, protected] |
Decides which sprite to display for a given page element.
pe | The page element. |
Definition at line 297 of file story_gui.cpp.
References Goal::completed, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_goal_pool >::Get(), StoryPageElement::referenced_id, SPET_GOAL, SPET_LOCATION, and StoryPageElement::type.
Referenced by DrawWidget(), and GetPageElementHeight().
StoryPage* StoryBookWindow::GetSelPage | ( | ) | const [inline, protected] |
Get instance of selected page.
Definition at line 118 of file story_gui.cpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::IsValidID(), and selected_page_id.
Referenced by BuildStoryPageElementList(), DrawWidget(), GetContentHeight(), GetHeadHeight(), RefreshSelectedPage(), and SetStringParameters().
int StoryBookWindow::GetSelPageNum | ( | ) | const [inline, protected] |
Get the page number of selected page.
Definition at line 128 of file story_gui.cpp.
References SmallVector< T, S >::Begin(), SmallVector< T, S >::End(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, and story_pages.
Referenced by RefreshSelectedPage().
virtual void StoryBookWindow::OnClick | ( | Point | pt, | |
int | widget, | |||
int | click_count | |||
) | [inline, virtual] |
A click with the left mouse button has been made on the window.
pt | the point inside the window that has been clicked. | |
widget | the clicked widget. | |
click_count | Number of fast consecutive clicks at same position |
Reimplemented from Window.
Definition at line 613 of file story_gui.cpp.
References SmallVector< T, S >::Begin(), BuildDropDownList(), SmallVector< T, S >::End(), GetAvailablePageContentWidth(), GetHeadHeight(), GetPageElementHeight(), Scrollbar::GetScrolledRowFromWidget(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, SmallVector< T, S >::Length(), OnPageElementClick(), SelectNextPage(), SelectPrevPage(), ShowDropDownList(), story_page_elements, story_pages, vscroll, WD_FRAMETEXT_TOP, WID_SB_NEXT_PAGE, WID_SB_PAGE_PANEL, WID_SB_PREV_PAGE, and WID_SB_SEL_PAGE.
virtual void StoryBookWindow::OnDropdownSelect | ( | int | widget, | |
int | index | |||
) | [inline, virtual] |
A dropdown option associated to this window has been selected.
widget | the widget (button) that the dropdown is associated with. | |
index | the element in the dropdown that is selected. |
Reimplemented from Window.
Definition at line 668 of file story_gui.cpp.
References SetSelectedPage(), and WID_SB_SEL_PAGE.
virtual void StoryBookWindow::OnInvalidateData | ( | int | data = 0 , |
|
bool | gui_scope = true | |||
) | [inline, virtual] |
Some data on this window has become invalid.
data | Information about the changed data. -1 Rebuild page list and refresh current page; >= 0 Id of the page that needs to be refreshed. If it is not the current page, nothing happens. | |
gui_scope | Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See InvalidateWindowData() for details. |
Reimplemented from Window.
Definition at line 683 of file story_gui.cpp.
References BuildStoryPageList(), GUIList< T, F >::ForceRebuild(), INVALID_STORY_PAGE, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::IsValidID(), SmallVector< T, S >::Length(), RefreshSelectedPage(), selected_generic_title, selected_page_id, SetSelectedPage(), Window::SetWidgetDirty(), Window::SetWidgetDisabledState(), story_pages, UpdatePrevNextDisabledState(), and WID_SB_SEL_PAGE.
void StoryBookWindow::OnPageElementClick | ( | const StoryPageElement & | pe | ) | [inline, protected] |
Internal event handler for when a page element is clicked.
pe | The clicked page element. |
Definition at line 392 of file story_gui.cpp.
References _ctrl_pressed, StoryPageElement::referenced_id, ScrollMainWindowToTile(), ShowExtraViewPortWindow(), ShowGoalsList(), SPET_GOAL, SPET_LOCATION, SPET_TEXT, StoryPageElement::type, and Window::window_number.
Referenced by OnClick().
virtual void StoryBookWindow::OnPaint | ( | ) | [inline, virtual] |
The window must be repainted.
Reimplemented from Window.
Definition at line 483 of file story_gui.cpp.
References Window::DrawWidgets(), GetContentHeight(), Scrollbar::GetCount(), Scrollbar::SetCount(), Window::SetWidgetDirty(), vscroll, WID_SB_PAGE_PANEL, and WID_SB_SCROLLBAR.
virtual void StoryBookWindow::OnResize | ( | ) | [inline, virtual] |
Called after the window got resized.
For nested windows with a viewport, call NWidgetViewport::UpdateViewportCoordinates.
Reimplemented from Window.
Definition at line 607 of file story_gui.cpp.
References GetContentHeight(), Scrollbar::SetCapacityFromWidget(), Scrollbar::SetCount(), vscroll, WD_FRAMETEXT_BOTTOM, WD_FRAMETEXT_TOP, and WID_SB_PAGE_PANEL.
static int CDECL StoryBookWindow::PageElementOrderSorter | ( | const StoryPageElement *const * | a, | |
const StoryPageElement *const * | b | |||
) | [inline, static, protected] |
Sort story page elements by order value.
Definition at line 99 of file story_gui.cpp.
static int CDECL StoryBookWindow::PageOrderSorter | ( | const StoryPage *const * | a, | |
const StoryPage *const * | b | |||
) | [inline, static, protected] |
Sort story pages by order value.
Definition at line 70 of file story_gui.cpp.
void StoryBookWindow::SetSelectedPage | ( | uint16 | page_index | ) | [inline] |
Sets the selected page.
page_index | pool index of the page to select. |
Definition at line 455 of file story_gui.cpp.
References RefreshSelectedPage(), selected_page_id, and UpdatePrevNextDisabledState().
Referenced by OnDropdownSelect(), OnInvalidateData(), SelectNextPage(), and SelectPrevPage().
virtual void StoryBookWindow::SetStringParameters | ( | int | widget | ) | const [inline, virtual] |
Initialize string parameters for a widget.
Calls to this function are made during initialization to measure the size (that is as part of InitNested()), during drawing, and while re-initializing the window. Only for widgets that render text initializing is requested.
widget | Widget number. |
Reimplemented from Window.
Definition at line 464 of file story_gui.cpp.
References GetSelPage(), INVALID_COMPANY, SetDParam(), SetDParamStr(), StoryPage::title, WID_SB_CAPTION, and WID_SB_SEL_PAGE.
virtual void StoryBookWindow::UpdateWidgetSize | ( | int | widget, | |
Dimension * | size, | |||
const Dimension & | padding, | |||
Dimension * | fill, | |||
Dimension * | resize | |||
) | [inline, virtual] |
Update size and resize step of a widget in the window.
After retrieval of the minimal size and the resize-steps of a widget, this function is called to allow further refinement, typically by computing the real maximal size of the content. Afterwards, size is taken to be the minimal size of the widget and resize is taken to contain the resize steps. For the convenience of the callee, padding contains the amount of padding between the content and the edge of the widget. This should be added to the returned size.
widget | Widget number. | |
size | Size of the widget. | |
padding | Recommended amount of space between the widget content and the widget edge. | |
fill | Fill step of the widget. | |
resize | Resize step of the widget. |
Reimplemented from Window.
Definition at line 564 of file story_gui.cpp.
References GetStringBoundingBox(), SmallVector< T, S >::Length(), maxdim(), selected_generic_title, SetDParamStr(), story_pages, StoryPage::title, WD_FRAMETEXT_TOP, WID_SB_PAGE_PANEL, and WID_SB_SEL_PAGE.
GUIStoryPageElementList::SortFunction *const StoryBookWindow::page_element_sorter_funcs [static, protected] |
{ &PageElementOrderSorter, }
Definition at line 47 of file story_gui.cpp.
GUIStoryPageList::SortFunction *const StoryBookWindow::page_sorter_funcs [static, protected] |
{ &PageOrderSorter, }
Definition at line 46 of file story_gui.cpp.