2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 /** @file story_base.h %StoryPage base class. */
13 #include "company_type.h"
14 #include "story_type.h"
15 #include "timer/timer_game_calendar.h"
17 #include "vehicle_type.h"
18 #include "core/pool_type.hpp"
20 typedef Pool
<StoryPageElement
, StoryPageElementID
, 64, 64000> StoryPageElementPool
;
21 typedef Pool
<StoryPage
, StoryPageID
, 64, 64000> StoryPagePool
;
22 extern StoryPageElementPool _story_page_element_pool
;
23 extern StoryPagePool _story_page_pool
;
24 extern uint32_t _story_page_element_next_sort_value
;
25 extern uint32_t _story_page_next_sort_value
;
28 * Each story page element is one of these types.
30 enum StoryPageElementType
: byte
{
31 SPET_TEXT
= 0, ///< A text element.
32 SPET_LOCATION
, ///< An element that references a tile along with a one-line text.
33 SPET_GOAL
, ///< An element that references a goal.
34 SPET_BUTTON_PUSH
, ///< A push button that triggers an immediate event.
35 SPET_BUTTON_TILE
, ///< A button that allows the player to select a tile, and triggers an event with the tile.
36 SPET_BUTTON_VEHICLE
, ///< A button that allows the player to select a vehicle, and triggers an event wih the vehicle.
41 /** Flags available for buttons */
42 enum StoryPageButtonFlags
: byte
{
44 SPBF_FLOAT_LEFT
= 1 << 0,
45 SPBF_FLOAT_RIGHT
= 1 << 1,
47 DECLARE_ENUM_AS_BIT_SET(StoryPageButtonFlags
)
49 /** Mouse cursors usable by story page buttons. */
50 enum StoryPageButtonCursor
: byte
{
111 * Checks if a StoryPageButtonCursor value is valid.
113 * @param wc The value to check
114 * @return true if the given value is a valid StoryPageButtonCursor.
116 inline bool IsValidStoryPageButtonCursor(StoryPageButtonCursor cursor
)
118 return cursor
< SPBC_END
;
121 /** Helper to construct packed "id" values for button-type StoryPageElement */
122 struct StoryPageButtonData
{
123 uint32_t referenced_id
;
125 void SetColour(Colours button_colour
);
126 void SetFlags(StoryPageButtonFlags flags
);
127 void SetCursor(StoryPageButtonCursor cursor
);
128 void SetVehicleType(VehicleType vehtype
);
129 Colours
GetColour() const;
130 StoryPageButtonFlags
GetFlags() const;
131 StoryPageButtonCursor
GetCursor() const;
132 VehicleType
GetVehicleType() const;
133 bool ValidateColour() const;
134 bool ValidateFlags() const;
135 bool ValidateCursor() const;
136 bool ValidateVehicleType() const;
140 * Struct about story page elements.
141 * Each StoryPage is composed of one or more page elements that provide
142 * page content. Each element only contain one type of content.
144 struct StoryPageElement
: StoryPageElementPool::PoolItem
<&_story_page_element_pool
> {
145 uint32_t sort_value
; ///< A number that increases for every created story page element. Used for sorting. The id of a story page element is the pool index.
146 StoryPageID page
; ///< Id of the page which the page element belongs to
147 StoryPageElementType type
; ///< Type of page element
149 uint32_t referenced_id
; ///< Id of referenced object (location, goal etc.)
150 std::string text
; ///< Static content text of page element
153 * We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
155 inline StoryPageElement() { }
158 * (Empty) destructor has to be defined else operator delete might be called with nullptr parameter
160 inline ~StoryPageElement() { }
163 /** Struct about stories, current and completed */
164 struct StoryPage
: StoryPagePool::PoolItem
<&_story_page_pool
> {
165 uint32_t sort_value
; ///< A number that increases for every created story page. Used for sorting. The id of a story page is the pool index.
166 TimerGameCalendar::Date date
; ///< Date when the page was created.
167 CompanyID company
; ///< StoryPage is for a specific company; INVALID_COMPANY if it is global
169 std::string title
; ///< Title of story page
172 * We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
174 inline StoryPage() { }
177 * (Empty) destructor has to be defined else operator delete might be called with nullptr parameter
181 if (!this->CleaningPool()) {
182 for (StoryPageElement
*spe
: StoryPageElement::Iterate()) {
183 if (spe
->page
== this->index
) delete spe
;
189 #endif /* STORY_BASE_H */