Go to the documentation of this file.
25 #include "script/api/script_story_page.hpp"
26 #include "script/api/script_event_types.hpp"
32 uint32 _story_page_element_next_sort_value;
33 uint32 _story_page_next_sort_value;
68 if (!button_data.ValidateColour())
return false;
71 if (!button_data.ValidateColour())
return false;
72 if (!button_data.ValidateCursor())
return false;
75 if (!button_data.ValidateColour())
return false;
76 if (!button_data.ValidateCursor())
return false;
77 if (!button_data.ValidateVehicleType())
return false;
113 default: NOT_REACHED();
120 assert(button_colour < COLOUR_END);
121 SB(this->referenced_id, 0, 8, button_colour);
126 SB(this->referenced_id, 24, 8, flags);
132 assert(cursor < SPBC_END);
133 SB(this->referenced_id, 8, 8, cursor);
140 SB(this->referenced_id, 16, 8, vehtype);
146 Colours colour = (Colours)
GB(this->referenced_id, 0, 8);
173 return GB(this->referenced_id, 0, 8) < COLOUR_END;
176 bool StoryPageButtonData::ValidateFlags()
const
178 byte flags =
GB(this->referenced_id, 24, 8);
180 if ((flags & SPBF_FLOAT_LEFT) && (flags & SPBF_FLOAT_RIGHT))
return false;
182 if (flags & ~(SPBF_FLOAT_LEFT | SPBF_FLOAT_RIGHT))
return false;
189 return GB(this->referenced_id, 8, 8) < SPBC_END;
195 byte vehtype =
GB(this->referenced_id, 16, 8);
214 if (_story_page_pool.
items == 0) {
216 _story_page_next_sort_value = 0;
232 _story_page_next_sort_value++;
254 uint16 element_count = 0;
256 if (iter->page == page_id) element_count++;
258 if (element_count >= 128)
return {
CMD_ERROR, INVALID_STORY_PAGE_ELEMENT };
266 if (_story_page_element_pool.
items == 0) {
268 _story_page_element_next_sort_value = 0;
272 pe->
sort_value = _story_page_element_next_sort_value;
279 _story_page_element_next_sort_value++;
283 return {
CommandCost(), INVALID_STORY_PAGE_ELEMENT };
397 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.
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-...
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.
std::tuple< CommandCost, StoryPageID > CmdCreateStoryPage(DoCommandFlag flags, CompanyID company, const std::string &text)
Create a new story page.
Tindex index
Index of this pool item.
@ SPET_BUTTON_PUSH
A push button that triggers an immediate event.
@ 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...
CommandCost CmdShowStoryPage(DoCommandFlag flags, StoryPageID page_id)
Display a story page for all clients that are allowed to view the story page.
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.
CommandCost CmdSetStoryPageDate(DoCommandFlag flags, StoryPageID page_id, Date date)
Update date of a story page.
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.
CommandCost CmdUpdateStoryPageElement(DoCommandFlag flags, TileIndex tile, StoryPageElementID page_element_id, uint32 reference, const std::string &text)
Update a new story page element.
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.
CommandCost CmdStoryPageButton(DoCommandFlag flags, TileIndex tile, StoryPageElementID page_element_id, VehicleID reference)
Clicked/used a button on a story page.
static bool IsValidStoryPageButtonCursor(StoryPageButtonCursor cursor)
Checks if a StoryPageButtonCursor value is valid.
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...
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 CmdSetStoryPageTitle(DoCommandFlag flags, StoryPageID page_id, const std::string &text)
Update title 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.
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.
std::tuple< CommandCost, StoryPageElementID > CmdCreateStoryPageElement(DoCommandFlag flags, TileIndex tile, StoryPageID page_id, StoryPageElementType type, uint32 reference, const std::string &text)
Create a new story page element.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
uint16 GoalID
ID of a goal.
CommandCost CmdRemoveStoryPageElement(DoCommandFlag flags, StoryPageElementID page_element_id)
Remove a story page element.
@ 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.
static bool IsValidColours(Colours colours)
Checks if a Colours value is valid.
StoryPageID page
Id of the page which the page element belongs to.
CommandCost CmdRemoveStoryPage(DoCommandFlag flags, StoryPageID page_id)
Remove a story page and associated story page elements.