|
OpenTTD Source
14.0-beta1
|
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_t _story_page_element_next_sort_value;
33 uint32_t _story_page_next_sort_value;
56 if (text.empty())
return false;
59 if (text.empty())
return false;
68 if (!button_data.ValidateColour())
return false;
69 if (!button_data.ValidateFlags())
return false;
72 if (!button_data.ValidateColour())
return false;
73 if (!button_data.ValidateFlags())
return false;
74 if (!button_data.ValidateCursor())
return false;
77 if (!button_data.ValidateColour())
return false;
78 if (!button_data.ValidateFlags())
return false;
79 if (!button_data.ValidateCursor())
return false;
80 if (!button_data.ValidateVehicleType())
return false;
116 default: NOT_REACHED();
123 assert(button_colour < COLOUR_END);
124 SB(this->referenced_id, 0, 8, button_colour);
129 SB(this->referenced_id, 24, 8, flags);
135 assert(cursor < SPBC_END);
136 SB(this->referenced_id, 8, 8, cursor);
143 SB(this->referenced_id, 16, 8, vehtype);
149 Colours colour =
static_cast<Colours
>(
GB(this->referenced_id, 0, 8));
176 return GB(this->referenced_id, 0, 8) < COLOUR_END;
179 bool StoryPageButtonData::ValidateFlags()
const
181 byte flags =
GB(this->referenced_id, 24, 8);
183 if ((flags & SPBF_FLOAT_LEFT) && (flags & SPBF_FLOAT_RIGHT))
return false;
185 if (flags & ~(SPBF_FLOAT_LEFT | SPBF_FLOAT_RIGHT))
return false;
192 return GB(this->referenced_id, 8, 8) < SPBC_END;
198 byte vehtype =
GB(this->referenced_id, 16, 8);
217 if (_story_page_pool.
items == 0) {
219 _story_page_next_sort_value = 0;
231 _story_page_next_sort_value++;
253 uint16_t element_count = 0;
255 if (iter->page == page_id) element_count++;
257 if (element_count >= 128)
return {
CMD_ERROR, INVALID_STORY_PAGE_ELEMENT };
265 if (_story_page_element_pool.
items == 0) {
267 _story_page_element_next_sort_value = 0;
271 pe->
sort_value = _story_page_element_next_sort_value;
278 _story_page_element_next_sort_value++;
282 return {
CommandCost(), INVALID_STORY_PAGE_ELEMENT };
391 if (pe->page == p->
index) {
@ 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-...
CommandCost CmdSetStoryPageDate(DoCommandFlag flags, StoryPageID page_id, TimerGameCalendar::Date date)
Update date of a story page.
static Titem * Get(size_t index)
Returns Titem with given index.
std::string title
Title of story page.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
TimerGameCalendar::Date date
Date when the page was created.
StoryPageButtonCursor GetCursor() const
Get the mouse cursor used while waiting for input for the button.
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.
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Tindex index
Index of this pool item.
@ SPET_BUTTON_PUSH
A push button that triggers an immediate event.
uint16_t StoryPageElementID
ID of a story page element.
bool IsValidColours(Colours colours)
Checks if a Colours value is valid.
@ SPET_GOAL
An element that references a goal.
std::tuple< CommandCost, StoryPageElementID > CmdCreateStoryPageElement(DoCommandFlag flags, TileIndex tile, StoryPageID page_id, StoryPageElementType type, uint32_t reference, const std::string &text)
Create a new story page element.
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.
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.
@ VEH_COMPANY_END
Last company-ownable type.
size_t items
Number of used indexes (non-nullptr)
VehicleType GetVehicleType() const
Get the type of vehicles that are accepted by the button.
bool IsValidStoryPageButtonCursor(StoryPageButtonCursor cursor)
Checks if a StoryPageButtonCursor value is valid.
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.
@ SPET_LOCATION
An element that references a tile along with a one-line text.
uint32_t VehicleID
The type all our vehicle IDs have.
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.
uint16_t GoalID
ID of a goal.
VehicleType
Available vehicle types.
CommandCost CmdUpdateStoryPageElement(DoCommandFlag flags, TileIndex tile, StoryPageElementID page_element_id, uint32_t reference, const std::string &text)
Update a new story page element.
void SetVehicleType(VehicleType vehtype)
Set the type of vehicles that are accepted by the button.
bool IsValidTile(Tile tile)
Checks if a tile is valid.
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.
uint32_t referenced_id
Id of referenced object (location, goal etc.)
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...
uint32_t sort_value
A number that increases for every created story page. Used for sorting. The id of a story page is the...
Colours GetColour() const
Get the button background colour.
static void UpdateElement(StoryPageElement &pe, TileIndex tile, uint32_t reference, const std::string &text)
This helper for Create/Update PageElement Cmd procedure updates a page element with new content data.
std::string text
Static content text of page element.
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.
@ OWNER_DEITY
The object is owned by a superuser / goal script.
void ShowStoryBook(CompanyID company, uint16_t page_id=INVALID_STORY_PAGE, bool centered=false)
Raise or create the story book window for company, at page page_id.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
@ INVALID_COMPANY
An invalid company.
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
static Date date
Current date in days (day counter).
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 bool VerifyElementContentParameters(StoryPageID page_id, StoryPageElementType type, TileIndex tile, uint32_t reference, const std::string &text)
This helper for Create/Update PageElement Cmd procedure verifies if the page element parameters are c...
uint16_t StoryPageID
ID of a story page.
uint32_t sort_value
A number that increases for every created story page element. Used for sorting. The id of a story pag...
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:
CompanyID company
StoryPage is for a specific company; INVALID_COMPANY if it is global.
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.