31#include "table/strings.h"
47 typedef std::vector<LayoutCacheElement> LayoutCache;
49 enum class ElementFloat {
65 static const std::initializer_list<GUIStoryPageList::SortFunction * const> page_sorter_funcs;
66 static const std::initializer_list<GUIStoryPageElementList::SortFunction * const> page_element_sorter_funcs;
72 this->story_pages.clear();
75 if (this->IsPageAvailable(p)) {
76 this->story_pages.push_back(p);
83 this->story_pages.
Sort();
96 this->story_page_elements.clear();
101 if (pe->page == p->
index) {
102 this->story_page_elements.push_back(pe);
110 this->story_page_elements.
Sort();
125 bool IsPageAvailable(
const StoryPage *page)
const
148 if (p->index ==
this->selected_page_id) {
162 if (!_story_page_pool.
IsValidID(
this->selected_page_id))
return false;
173 if (!_story_page_pool.
IsValidID(
this->selected_page_id))
return false;
175 if (this->story_pages.size() <= 1)
return true;
187 if (page !=
nullptr && page->
title.empty()) {
208 if (!_story_page_pool.
IsValidID(
this->selected_page_id))
return;
214 if (p->index ==
this->selected_page_id) {
228 if (!_story_page_pool.
IsValidID(
this->selected_page_id))
return;
231 for (
auto iter = this->story_pages.begin();
iter != this->story_pages.end();
iter++) {
233 if (p->
index ==
this->selected_page_id) {
236 if (
iter != this->story_pages.end()) {
253 if (!p->title.empty()) {
254 list.push_back(MakeDropDownListStringItem(p->title, p->index,
current_page));
284 if (page ==
nullptr)
return 0;
306 if (g ==
nullptr)
return SPR_IMG_GOAL_BROKEN_REF;
307 return g->
completed ? SPR_IMG_GOAL_COMPLETED : SPR_IMG_GOAL;
310 return SPR_IMG_VIEW_LOCATION;
360 if (
flags & SPBF_FLOAT_LEFT)
return ElementFloat::Left;
361 if (
flags & SPBF_FLOAT_RIGHT)
return ElementFloat::Right;
362 return ElementFloat::None;
366 return ElementFloat::None;
393 this->layout_cache.clear();
400 if (!this->layout_cache.empty())
return;
403 if (page ==
nullptr)
return;
424 if (
fl == ElementFloat::None) {
459 this->layout_cache.push_back(
ce);
479 cur_floats.push_back(this->layout_cache.size());
480 this->layout_cache.push_back(
ce);
556 this->active_button_id = pe.
index;
564 if (this->active_button_id == pe.
index) {
570 this->active_button_id = pe.
index;
576 if (this->active_button_id == pe.
index) {
582 this->active_button_id = pe.
index;
600 this->story_pages.
SetSortFuncs(StoryBookWindow::page_sorter_funcs);
603 this->story_page_elements.
SetSortFuncs(StoryBookWindow::page_element_sorter_funcs);
610 this->selected_generic_title.clear();
669 if (this->vscroll->
GetCount() !=
this->GetContentHeight()) {
683 if (page ==
nullptr)
return;
694 fr =
fr.Translate(-
fr.left, -
fr.top);
696 const int scrollpos = this->vscroll->
GetPosition();
697 int y_offset = -scrollpos;
704 y_offset += line_height;
713 y_offset =
ce.bounds.top - scrollpos;
714 switch (
ce.pe->type) {
747 default: NOT_REACHED();
764 for (
size_t i = 0; i < this->story_pages.size(); i++) {
765 const StoryPage *s = this->story_pages[i];
767 if (!s->
title.empty()) {
779 d.width += padding.width;
780 d.height += padding.height;
810 for (
size_t i = 0; i < this->story_pages.size(); i++) {
811 const StoryPage *p = this->story_pages[i];
812 if (p->
index ==
this->selected_page_id)
break;
870 if (this->story_pages.empty()) {
871 this->selected_generic_title.clear();
888 }
else if (data >= 0 && this->selected_page_id == data) {
913 bool OnVehicleSelect(
const Vehicle *v)
override
940const std::initializer_list<GUIStoryPageList::SortFunction * const> StoryBookWindow::page_sorter_funcs = {
944const std::initializer_list<GUIStoryPageElementList::SortFunction * const> StoryBookWindow::page_element_sorter_funcs = {
945 &PageElementOrderSorter,
948static constexpr NWidgetPart _nested_story_book_widgets[] = {
973 _nested_story_book_widgets
980 _nested_story_book_widgets
987 case SPBC_ZZZ:
return SPR_CURSOR_ZZZ;
988 case SPBC_BUOY:
return SPR_CURSOR_BUOY;
989 case SPBC_QUERY:
return SPR_CURSOR_QUERY;
990 case SPBC_HQ:
return SPR_CURSOR_HQ;
991 case SPBC_SHIP_DEPOT:
return SPR_CURSOR_SHIP_DEPOT;
992 case SPBC_SIGN:
return SPR_CURSOR_SIGN;
993 case SPBC_TREE:
return SPR_CURSOR_TREE;
994 case SPBC_BUY_LAND:
return SPR_CURSOR_BUY_LAND;
995 case SPBC_LEVEL_LAND:
return SPR_CURSOR_LEVEL_LAND;
996 case SPBC_TOWN:
return SPR_CURSOR_TOWN;
997 case SPBC_INDUSTRY:
return SPR_CURSOR_INDUSTRY;
998 case SPBC_ROCKY_AREA:
return SPR_CURSOR_ROCKY_AREA;
999 case SPBC_DESERT:
return SPR_CURSOR_DESERT;
1000 case SPBC_TRANSMITTER:
return SPR_CURSOR_TRANSMITTER;
1001 case SPBC_AIRPORT:
return SPR_CURSOR_AIRPORT;
1002 case SPBC_DOCK:
return SPR_CURSOR_DOCK;
1003 case SPBC_CANAL:
return SPR_CURSOR_CANAL;
1004 case SPBC_LOCK:
return SPR_CURSOR_LOCK;
1005 case SPBC_RIVER:
return SPR_CURSOR_RIVER;
1006 case SPBC_AQUEDUCT:
return SPR_CURSOR_AQUEDUCT;
1007 case SPBC_BRIDGE:
return SPR_CURSOR_BRIDGE;
1008 case SPBC_RAIL_STATION:
return SPR_CURSOR_RAIL_STATION;
1009 case SPBC_TUNNEL_RAIL:
return SPR_CURSOR_TUNNEL_RAIL;
1010 case SPBC_TUNNEL_ELRAIL:
return SPR_CURSOR_TUNNEL_ELRAIL;
1011 case SPBC_TUNNEL_MONO:
return SPR_CURSOR_TUNNEL_MONO;
1012 case SPBC_TUNNEL_MAGLEV:
return SPR_CURSOR_TUNNEL_MAGLEV;
1013 case SPBC_AUTORAIL:
return SPR_CURSOR_AUTORAIL;
1014 case SPBC_AUTOELRAIL:
return SPR_CURSOR_AUTOELRAIL;
1015 case SPBC_AUTOMONO:
return SPR_CURSOR_AUTOMONO;
1016 case SPBC_AUTOMAGLEV:
return SPR_CURSOR_AUTOMAGLEV;
1017 case SPBC_WAYPOINT:
return SPR_CURSOR_WAYPOINT;
1018 case SPBC_RAIL_DEPOT:
return SPR_CURSOR_RAIL_DEPOT;
1019 case SPBC_ELRAIL_DEPOT:
return SPR_CURSOR_ELRAIL_DEPOT;
1020 case SPBC_MONO_DEPOT:
return SPR_CURSOR_MONO_DEPOT;
1021 case SPBC_MAGLEV_DEPOT:
return SPR_CURSOR_MAGLEV_DEPOT;
1022 case SPBC_CONVERT_RAIL:
return SPR_CURSOR_CONVERT_RAIL;
1023 case SPBC_CONVERT_ELRAIL:
return SPR_CURSOR_CONVERT_ELRAIL;
1024 case SPBC_CONVERT_MONO:
return SPR_CURSOR_CONVERT_MONO;
1025 case SPBC_CONVERT_MAGLEV:
return SPR_CURSOR_CONVERT_MAGLEV;
1026 case SPBC_AUTOROAD:
return SPR_CURSOR_AUTOROAD;
1027 case SPBC_AUTOTRAM:
return SPR_CURSOR_AUTOTRAM;
1028 case SPBC_ROAD_DEPOT:
return SPR_CURSOR_ROAD_DEPOT;
1029 case SPBC_BUS_STATION:
return SPR_CURSOR_BUS_STATION;
1030 case SPBC_TRUCK_STATION:
return SPR_CURSOR_TRUCK_STATION;
1031 case SPBC_ROAD_TUNNEL:
return SPR_CURSOR_ROAD_TUNNEL;
1032 case SPBC_CLONE_TRAIN:
return SPR_CURSOR_CLONE_TRAIN;
1033 case SPBC_CLONE_ROADVEH:
return SPR_CURSOR_CLONE_ROADVEH;
1034 case SPBC_CLONE_SHIP:
return SPR_CURSOR_CLONE_SHIP;
1035 case SPBC_CLONE_AIRPLANE:
return SPR_CURSOR_CLONE_AIRPLANE;
1041 default:
return SPR_CURSOR_QUERY;
1055 StoryBookWindow *w = AllocateWindowDescFront<StoryBookWindow>(centered ? _story_book_gs_desc : _story_book_desc, company,
true);
@ None
Tile is not animated.
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.
static constexpr TimerGame< struct Calendar >::Date INVALID_DATE
Representation of an invalid date.
Functions related to commands.
Definition of stuff that is very close to a company, like the company struct itself.
Functions related to companies.
Owner
Enum for all companies/owners.
@ INVALID_COMPANY
An invalid company.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
Show a drop down list.
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.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
bool _ctrl_pressed
Is Ctrl pressed?
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
@ SA_TOP
Top align the text.
@ SA_LEFT
Left align the text.
@ SA_HOR_CENTER
Horizontally center the text.
@ SA_CENTER
Center both horizontally and vertically.
uint32_t CursorID
The number of the cursor (sprite)
@ FS_NORMAL
Index of the normal font in the font tables.
void ShowGoalsList(CompanyID company)
Open a goal list window.
uint16_t GoalID
ID of a goal.
GUI functions that shouldn't be here.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
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 CursorID ANIMCURSOR_PICKSTATION
716 - 718 - goto-order icon
static const CursorID ANIMCURSOR_BUILDSIGNALS
1292 - 1293 - build signal
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
static const CursorID ANIMCURSOR_LOWERLAND
699 - 701 - lower land tool
static const CursorID ANIMCURSOR_RAISELAND
696 - 698 - raise land tool
Definition of base types and functions in a cross-platform compatible way.
StoryPageButtonFlags
Flags available for buttons.
@ SPET_LOCATION
An element that references a tile along with a one-line text.
@ SPET_GOAL
An element that references a goal.
@ SPET_BUTTON_PUSH
A push button that triggers an immediate event.
@ SPET_BUTTON_TILE
A button that allows the player to select a tile, and triggers an event with the tile.
@ SPET_TEXT
A text element.
@ SPET_BUTTON_VEHICLE
A button that allows the player to select a vehicle, and triggers an event wih the vehicle.
StoryPageButtonCursor
Mouse cursors usable by story page buttons.
Command definitions related to stories.
void ShowStoryBook(CompanyID company, uint16_t page_id, bool centered)
Raise or create the story book window for company, at page page_id.
static const StoryPageElementID INVALID_STORY_PAGE_ELEMENT
Constant representing a non-existing story page element.
static const StoryPageID INVALID_STORY_PAGE
Constant representing a non-existing story page.
uint16_t StoryPageID
ID of a story page.
uint16_t StoryPageElementID
ID of a story page element.
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.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Functions related to OTTD's strings.
uint32_t 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.
Data about how and where to blit pixels.
Struct about goals, current and completed.
bool completed
Is the goal completed or not?
std::string text
Text of the goal.
Coordinates of a point in 2D.
Tindex index
Index of this pool item.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
static Titem * Get(size_t index)
Returns Titem with given index.
Titem * Get(size_t index)
Returns Titem with given index.
bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Specification of a rectangle with absolute coordinates of all edges.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
void OnTimeout() override
Called when this window's timeout has been reached.
void BuildStoryPageList()
(Re)Build story page list.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
void SetStringParameters(WidgetID widget) const override
Initialize string parameters for a widget.
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.
void OnPageElementClick(const StoryPageElement &pe)
Internal event handler for when a page element is clicked.
void OnDropdownSelect(WidgetID widget, int index) override
A dropdown option associated to this window has been selected.
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.
bool IsFirstPageSelected()
Check if the selected page is also the first available page.
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.
void UpdatePrevNextDisabledState()
Updates the disabled state of the prev/next buttons.
Scrollbar * vscroll
Scrollbar of the page text.
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.
void SelectPrevPage()
Selects the previous available page before the currently selected page.
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 RefreshSelectedPage()
Updates the content of selected page.
StoryPageID selected_page_id
Pool index of selected page.
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.
void InvalidateStoryPageElementLayout()
Invalidate the current page layout.
void BuildStoryPageElementList()
(Re)Build story page element list.
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.
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.
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.
void SetSelectedPage(uint16_t page_index)
Sets the selected page.
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.
ElementFloat GetPageElementFloat(const StoryPageElement &pe) const
Get the float style of a page element.
Helper to construct packed "id" values for button-type StoryPageElement.
Struct about story page elements.
uint32_t referenced_id
Id of referenced object (location, goal etc.)
std::string text
Static content text of page element.
uint32_t sort_value
A number that increases for every created story page element. Used for sorting. The id of a story pag...
StoryPageElementType type
Type of page element.
Struct about stories, current and completed.
uint32_t sort_value
A number that increases for every created story page. Used for sorting. The id of a story page is the...
CompanyID company
StoryPage is for a specific company; INVALID_COMPANY if it is global.
std::string title
Title of story page.
TimerGameCalendar::Date date
Date when the page was created.
High level window description.
Data structure for an opened window.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
void DrawWidgets() const
Paint all widgets of a window.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
ResizeInfo resize
Resize information.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
WindowFlags flags
Window flags.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
int height
Height of the window (number of pixels down in y direction)
int width
width of the window (number of pixels to the right in x direction)
WindowNumber window_number
Window number within the window class.
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.
@ VEH_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.
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
FrameFlags
Flags to describe the look of the frame.
@ FR_LOWERED
If set the frame is lowered and the background colour brighter (ie. buttons when pressed)
@ WDP_CENTER
Center the window.
@ WDP_AUTO
Find a place automatically.
int32_t WindowNumber
Number to differentiate different windows of the same class.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ WC_STORY_BOOK
Story book; Window numbers: