Go to the documentation of this file.
26 #include "script/api/script_story_page.hpp"
27 #include "script/api/script_event_types.hpp"
34 uint32 _story_page_element_next_sort_value;
35 uint32 _story_page_next_sort_value;
70 if (!button_data.ValidateColour())
return false;
73 if (!button_data.ValidateColour())
return false;
74 if (!button_data.ValidateCursor())
return false;
77 if (!button_data.ValidateColour())
return false;
78 if (!button_data.ValidateCursor())
return false;
79 if (!button_data.ValidateVehicleType())
return false;
115 default: NOT_REACHED();
122 assert(button_colour < COLOUR_END);
123 SB(this->referenced_id, 0, 8, button_colour);
128 SB(this->referenced_id, 24, 8, flags);
134 assert(cursor < SPBC_END);
135 SB(this->referenced_id, 8, 8, cursor);
142 SB(this->referenced_id, 16, 8, vehtype);
148 return Extract<Colours, 0, 8>(this->referenced_id);
159 return Extract<StoryPageButtonCursor, 8, 8>(this->referenced_id);
171 return GB(this->referenced_id, 0, 8) < COLOUR_END;
174 bool StoryPageButtonData::ValidateFlags()
const
176 byte flags =
GB(this->referenced_id, 24, 8);
178 if ((flags & SPBF_FLOAT_LEFT) && (flags & SPBF_FLOAT_RIGHT))
return false;
180 if (flags & ~(SPBF_FLOAT_LEFT | SPBF_FLOAT_RIGHT))
return false;
187 return GB(this->referenced_id, 8, 8) < SPBC_END;
193 byte vehtype =
GB(this->referenced_id, 16, 8);
217 if (_story_page_pool.
items == 0) {
219 _story_page_next_sort_value = 0;
235 _new_story_page_id = s->
index;
236 _story_page_next_sort_value++;
261 uint16 element_count = 0;
263 if (iter->page == page_id) element_count++;
265 if (element_count >= 128)
return CMD_ERROR;
272 if (_story_page_element_pool.
items == 0) {
274 _story_page_element_next_sort_value = 0;
278 pe->
sort_value = _story_page_element_next_sort_value;
285 _new_story_page_element_id = pe->
index;
286 _story_page_element_next_sort_value++;
422 if (pe->page == p->
index) {
uint32 sort_value
A number that increases for every created story page element. Used for sorting. The id of a story pag...
@ SPET_TEXT
A text element.
uint32 TileIndex
The index/ID of a Tile.
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
CommandCost CmdUpdateStoryPageElement(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Update a new story page element.
static Titem * Get(size_t index)
Returns Titem with given index.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
StoryPageButtonCursor GetCursor() const
Get the mouse cursor used while waiting for input for the button.
void ShowStoryBook(CompanyID company, uint16 page_id=INVALID_STORY_PAGE)
Raise or create the story book window for company, at page page_id.
StoryPageButtonFlags
Flags available for buttons.
void SetCursor(StoryPageButtonCursor cursor)
Set the mouse cursor used while waiting for input for the button.
Tindex index
Index of this pool item.
@ SPET_BUTTON_PUSH
A push button that triggers an immediate event.
CommandCost CmdStoryPageButton(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Clicked/used a button on a story page.
CommandCost CmdRemoveStoryPageElement(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Remove a story page element.
CommandCost CmdRemoveStoryPage(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Remove a story page and associated story page elements.
@ SPET_GOAL
An element that references a goal.
uint32 sort_value
A number that increases for every created story page. Used for sorting. The id of a story page is the...
void SetColour(Colours button_colour)
Set the button background colour.
Owner
Enum for all companies/owners.
@ DC_EXEC
execute the given command
DoCommandFlag
List of flags for a command.
uint32 referenced_id
Id of referenced object (location, goal etc.)
bool ValidateVehicleType() const
Verity that the data stored a valid VehicleType value.
@ SPET_BUTTON_VEHICLE
A button that allows the player to select a vehicle, and triggers an event wih the vehicle.
bool ValidateCursor() const
Verify that the data stores a valid StoryPageButtonCursor value.
@ WC_STORY_BOOK
Story book; Window numbers:
@ SPET_BUTTON_TILE
A button that allows the player to select a tile, and triggers an event with the tile.
StoryPageElementType type
Type of page element.
Common return value for all commands.
Date _date
Current date in days (day counter)
@ VEH_COMPANY_END
Last company-ownable type.
size_t items
Number of used indexes (non-nullptr)
uint16 StoryPageID
ID of a story page.
VehicleType GetVehicleType() const
Get the type of vehicles that are accepted by the button.
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
int32 Date
The type to store our dates in.
Struct about stories, current and completed.
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
@ VEH_INVALID
Non-existing type of vehicle.
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
@ SPET_LOCATION
An element that references a tile along with a one-line text.
StoryPageButtonCursor
Mouse cursors usable by story page buttons.
VehicleType
Available vehicle types.
char * title
Title of story page.
void SetVehicleType(VehicleType vehtype)
Set the type of vehicles that are accepted by the button.
static bool VerifyElementContentParameters(StoryPageID page_id, StoryPageElementType type, TileIndex tile, uint32 reference, const char *text)
This helper for Create/Update PageElement Cmd procedure verifies if the page element parameters are c...
CommandCost CmdShowStoryPage(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Display a story page for all clients that are allowed to view the story page.
CompanyID _current_company
Company currently doing an action.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Base class for all pools.
CommandCost CmdCreateStoryPageElement(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Create a new story page element.
CommandCost CmdSetStoryPageDate(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Update date of a story page.
static size_t GetNumItems()
Returns number of valid items in the pool.
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
uint16 StoryPageElementID
ID of a story page element.
Colours GetColour() const
Get the button background colour.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
Struct about story page elements.
CommandCost CmdSetStoryPageTitle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Update title of a story page.
static void UpdateElement(StoryPageElement &pe, TileIndex tile, uint32 reference, const char *text)
This helper for Create/Update PageElement Cmd procedure updates a page element with new content data.
@ OWNER_DEITY
The object is owned by a superuser / goal script.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
uint32 VehicleID
The type all our vehicle IDs have.
@ INVALID_COMPANY
An invalid company.
char * text
Static content text of page element.
Helper to construct packed "id" values for button-type StoryPageElement.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
bool ValidateColour() const
Verify that the data stored a valid Colour value.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
uint16 GoalID
ID of a goal.
@ WC_MAIN_TOOLBAR
Main toolbar (the long bar at the top); Window numbers:
Date date
Date when the page was created.
CompanyID company
StoryPage is for a specific company; INVALID_COMPANY if it is global.
CommandCost CmdCreateStoryPage(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Create a new story page.
StoryPageID page
Id of the page which the page element belongs to.