25#include "script/api/script_story_page.hpp"
26#include "script/api/script_event_types.hpp"
32uint32_t _story_page_element_next_sort_value;
33uint32_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;
179bool StoryPageButtonData::ValidateFlags()
const
181 uint8_t 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 uint8_t 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++;
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++;
391 if (pe->page == p->
index) {
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.
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Common return value for all commands.
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
static Date date
Current date in days (day counter).
Functions related to commands.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
DoCommandFlag
List of flags for a command.
@ DC_EXEC
execute the given command
Definition of stuff that is very close to a company, like the company struct itself.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
Owner
Enum for all companies/owners.
@ INVALID_COMPANY
An invalid company.
@ OWNER_DEITY
The object is owned by a superuser / goal script.
Base functions for all Games.
basic types related to goals
uint16_t GoalID
ID of a goal.
GUI functions that shouldn't be here.
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.
bool IsValidColours(Colours colours)
Checks if a Colours value is valid.
Some methods of Pool are placed here in order to reduce compilation time and binary size.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
CommandCost CmdStoryPageButton(DoCommandFlag flags, TileIndex tile, StoryPageElementID page_element_id, VehicleID reference)
Clicked/used a button on a story page.
CommandCost CmdRemoveStoryPage(DoCommandFlag flags, StoryPageID page_id)
Remove a story page and associated story page elements.
CommandCost CmdUpdateStoryPageElement(DoCommandFlag flags, TileIndex tile, StoryPageElementID page_element_id, uint32_t reference, const std::string &text)
Update a new story page element.
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.
CommandCost CmdSetStoryPageTitle(DoCommandFlag flags, StoryPageID page_id, const std::string &text)
Update title of a story page.
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...
CommandCost CmdShowStoryPage(DoCommandFlag flags, StoryPageID page_id)
Display a story page for all clients that are allowed to view the story page.
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 CmdRemoveStoryPageElement(DoCommandFlag flags, StoryPageElementID page_element_id)
Remove a story page element.
std::tuple< CommandCost, StoryPageID > CmdCreateStoryPage(DoCommandFlag flags, CompanyID company, const std::string &text)
Create a new story page.
CommandCost CmdSetStoryPageDate(DoCommandFlag flags, StoryPageID page_id, TimerGameCalendar::Date date)
Update date of a story page.
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.
bool IsValidStoryPageButtonCursor(StoryPageButtonCursor cursor)
Checks if a StoryPageButtonCursor value is valid.
Command definitions related to stories.
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.
Functions related to low-level strings.
Tindex index
Index of this pool item.
static size_t GetNumItems()
Returns number of valid items in the pool.
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 bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
static Titem * Get(size_t index)
Returns Titem with given index.
Base class for all pools.
size_t items
Number of used indexes (non-nullptr)
Helper to construct packed "id" values for button-type StoryPageElement.
Colours GetColour() const
Get the button background colour.
VehicleType GetVehicleType() const
Get the type of vehicles that are accepted by the button.
void SetColour(Colours button_colour)
Set the button background colour.
bool ValidateVehicleType() const
Verity that the data stored a valid VehicleType value.
bool ValidateColour() const
Verify that the data stored a valid Colour value.
void SetVehicleType(VehicleType vehtype)
Set the type of vehicles that are accepted by the button.
StoryPageButtonCursor GetCursor() const
Get the mouse cursor used while waiting for input for the button.
bool ValidateCursor() const
Verify that the data stores a valid StoryPageButtonCursor value.
void SetCursor(StoryPageButtonCursor cursor)
Set the mouse cursor used while waiting for input for the button.
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.
StoryPageID page
Id of the page which the page element belongs to.
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.
Map writing/reading functions for tiles.
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition of the game-calendar-timer.
Base class for all vehicles.
VehicleType
Available vehicle types.
@ VEH_INVALID
Non-existing type of vehicle.
@ VEH_COMPANY_END
Last company-ownable type.
uint32_t VehicleID
The type all our vehicle IDs have.
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-...
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...
Window functions not directly related to making/drawing windows.
@ WC_STORY_BOOK
Story book; Window numbers:
@ WC_MAIN_TOOLBAR
Main toolbar (the long bar at the top); Window numbers: