summaryrefslogtreecommitdiff
path: root/src/story_base.h
diff options
context:
space:
mode:
authorNiels Martin Hansen <nielsm@indvikleren.dk>2020-05-22 22:22:55 +0200
committerGitHub <noreply@github.com>2020-05-22 22:22:55 +0200
commit800ade77021b34adf8daa5ca5de0efaa8df24152 (patch)
tree7a2eb5c73c926476c81cd782bcb9b42c93bafdc4 /src/story_base.h
parentc972a63c8cbee7fa8d6d5af2cbbecb8c75ee561a (diff)
downloadopenttd-800ade77021b34adf8daa5ca5de0efaa8df24152.tar.xz
Feature: Push-buttons on storybook pages (#7896)
Allow more direct player-initiated interaction for Game Scripts, by letting the GS put push-buttons on storybook pages. These buttons can either trigger an immediate event, or require the player to first select a tile on the map, or a vehicle. Additionally this reworks how the storybook pages are layouted and rendered, to allow for slightly more complex layouts, and maybe speeding drawing up a bit.
Diffstat (limited to 'src/story_base.h')
-rw-r--r--src/story_base.h109
1 files changed, 102 insertions, 7 deletions
diff --git a/src/story_base.h b/src/story_base.h
index e82b9d696..e4d677cbf 100644
--- a/src/story_base.h
+++ b/src/story_base.h
@@ -13,6 +13,8 @@
#include "company_type.h"
#include "story_type.h"
#include "date_type.h"
+#include "gfx_type.h"
+#include "vehicle_type.h"
#include "core/pool_type.hpp"
typedef Pool<StoryPageElement, StoryPageElementID, 64, 64000> StoryPageElementPool;
@@ -26,9 +28,12 @@ extern uint32 _story_page_next_sort_value;
* Each story page element is one of these types.
*/
enum StoryPageElementType : byte {
- SPET_TEXT = 0, ///< A text element.
- SPET_LOCATION, ///< An element that references a tile along with a one-line text.
- SPET_GOAL, ///< An element that references a goal.
+ SPET_TEXT = 0, ///< A text element.
+ 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_BUTTON_VEHICLE, ///< A button that allows the player to select a vehicle, and triggers an event wih the vehicle.
SPET_END,
INVALID_SPET = 0xFF,
};
@@ -36,18 +41,108 @@ enum StoryPageElementType : byte {
/** Define basic enum properties */
template <> struct EnumPropsT<StoryPageElementType> : MakeEnumPropsT<StoryPageElementType, byte, SPET_TEXT, SPET_END, INVALID_SPET, 8> {};
+/** Flags available for buttons */
+enum StoryPageButtonFlags : byte {
+ SPBF_NONE = 0,
+ SPBF_FLOAT_LEFT = 1 << 0,
+ SPBF_FLOAT_RIGHT = 1 << 1,
+};
+DECLARE_ENUM_AS_BIT_SET(StoryPageButtonFlags)
+
+/** Mouse cursors usable by story page buttons. */
+enum StoryPageButtonCursor : byte {
+ SPBC_MOUSE,
+ SPBC_ZZZ,
+ SPBC_BUOY,
+ SPBC_QUERY,
+ SPBC_HQ,
+ SPBC_SHIP_DEPOT,
+ SPBC_SIGN,
+ SPBC_TREE,
+ SPBC_BUY_LAND,
+ SPBC_LEVEL_LAND,
+ SPBC_TOWN,
+ SPBC_INDUSTRY,
+ SPBC_ROCKY_AREA,
+ SPBC_DESERT,
+ SPBC_TRANSMITTER,
+ SPBC_AIRPORT,
+ SPBC_DOCK,
+ SPBC_CANAL,
+ SPBC_LOCK,
+ SPBC_RIVER,
+ SPBC_AQUEDUCT,
+ SPBC_BRIDGE,
+ SPBC_RAIL_STATION,
+ SPBC_TUNNEL_RAIL,
+ SPBC_TUNNEL_ELRAIL,
+ SPBC_TUNNEL_MONO,
+ SPBC_TUNNEL_MAGLEV,
+ SPBC_AUTORAIL,
+ SPBC_AUTOELRAIL,
+ SPBC_AUTOMONO,
+ SPBC_AUTOMAGLEV,
+ SPBC_WAYPOINT,
+ SPBC_RAIL_DEPOT,
+ SPBC_ELRAIL_DEPOT,
+ SPBC_MONO_DEPOT,
+ SPBC_MAGLEV_DEPOT,
+ SPBC_CONVERT_RAIL,
+ SPBC_CONVERT_ELRAIL,
+ SPBC_CONVERT_MONO,
+ SPBC_CONVERT_MAGLEV,
+ SPBC_AUTOROAD,
+ SPBC_AUTOTRAM,
+ SPBC_ROAD_DEPOT,
+ SPBC_BUS_STATION,
+ SPBC_TRUCK_STATION,
+ SPBC_ROAD_TUNNEL,
+ SPBC_CLONE_TRAIN,
+ SPBC_CLONE_ROADVEH,
+ SPBC_CLONE_SHIP,
+ SPBC_CLONE_AIRPLANE,
+ SPBC_DEMOLISH,
+ SPBC_LOWERLAND,
+ SPBC_RAISELAND,
+ SPBC_PICKSTATION,
+ SPBC_BUILDSIGNALS,
+ SPBC_END,
+ INVALID_SPBC = 0xFF
+};
+
+/** Define basic enum properties */
+template <> struct EnumPropsT<StoryPageButtonCursor> : MakeEnumPropsT<StoryPageButtonCursor, byte, SPBC_MOUSE, SPBC_END, INVALID_SPBC, 8> {};
+
+/** Helper to construct packed "id" values for button-type StoryPageElement */
+struct StoryPageButtonData {
+ uint32 referenced_id;
+
+ void SetColour(Colours button_colour);
+ void SetFlags(StoryPageButtonFlags flags);
+ void SetCursor(StoryPageButtonCursor cursor);
+ void SetVehicleType(VehicleType vehtype);
+ Colours GetColour() const;
+ StoryPageButtonFlags GetFlags() const;
+ StoryPageButtonCursor GetCursor() const;
+ VehicleType GetVehicleType() const;
+ bool ValidateColour() const;
+ bool ValidateFlags() const;
+ bool ValidateCursor() const;
+ bool ValidateVehicleType() const;
+};
+
/**
* Struct about story page elements.
* Each StoryPage is composed of one or more page elements that provide
* page content. Each element only contain one type of content.
**/
struct StoryPageElement : StoryPageElementPool::PoolItem<&_story_page_element_pool> {
- uint32 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.
- StoryPageID page; ///< Id of the page which the page element belongs to
+ uint32 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.
+ StoryPageID page; ///< Id of the page which the page element belongs to
StoryPageElementType type; ///< Type of page element
- uint32 referenced_id; ///< Id of referenced object (location, goal etc.)
- char *text; ///< Static content text of page element
+ uint32 referenced_id; ///< Id of referenced object (location, goal etc.)
+ char *text; ///< Static content text of page element
/**
* We need an (empty) constructor so struct isn't zeroed (as C++ standard states)