The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
part.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2009 - 2025
3 by Iris Morelle <shadowm2006@gmail.com>
4 Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY.
12
13 See the COPYING file for more details.
14*/
15
16/**
17 * @file
18 * Storyscreen parts and floating images representation.
19 */
20
21#pragma once
22
23#include "sdl/point.hpp"
25
26#include <chrono>
27#include <string>
28#include <vector>
29
30class config;
31class vconfig;
32
33namespace storyscreen
34{
35/**
36 * Represents and contains information about image labels used
37 * in story screen parts.
38 */
40{
41public:
42 /**
43 * WML-based constructor.
44 * @param cfg Object corresponding to a [image] block's contents from
45 * a [part] node.
46 */
48
49 floating_image(const floating_image& fi) = default;
51
53 {
54 assign(fi);
55 return *this;
56 }
57
58 std::string file() const
59 {
60 return file_;
61 }
62
63 /**
64 * Returns the referential X coordinate of the image.
65 * The actual (corrected) value is determined at render time.
66 */
67 int ref_x() const
68 {
69 return x_;
70 }
71
72 /**
73 * Returns the referential Y coordinate of the image.
74 * The actual (corrected) value is determined at render time.
75 */
76 int ref_y() const
77 {
78 return y_;
79 }
80
81 /**
82 * If true, the size of the image is changed in the same way that the ref_x
83 * and ref_y are mapped to use the base layer's pixels as the coordinate
84 * system.
85 */
87 {
89 }
90
91 /**
92 * Whether the image coordinates specify the location of its
93 * center (true) or top-left corner (false).
94 */
95 bool centered() const
96 {
97 return centered_;
98 }
99
100 /**
101 * Delay after displaying this image and before displaying the next image,
102 * in milliseconds.
103 */
104 const std::chrono::milliseconds& display_delay() const
105 {
106 return delay_;
107 }
108
109private:
110 std::string file_;
111 int x_, y_; // referential (non corrected) x,y
112 std::chrono::milliseconds delay_;
115
116 /** Copy constructor and operator=() implementation details. */
117 void assign(const floating_image& fi);
118};
119
121{
122public:
124
125 /**
126 * Constructor. Initializes a background_layer object from a
127 * [background_layer] WML node.
128 */
130
131 /** Whether the layer should be scaled horizontally. */
133 {
134 return scale_horizontally_;
135 }
136
137 /** Sets whether the layer should be scaled horizontally. */
139 {
141 }
142
143 /** Whether the layer should be scaled vertically. */
144 bool scale_vertically() const
145 {
146 return scale_vertically_;
147 }
148
149 /** Sets whether the layer should be scaled vertically. */
151 {
153 }
154
155 /** Whether the layer should be tiled horizontally. */
156 bool tile_horizontally() const
157 {
158 return tile_horizontally_;
159 }
160
161 /** Sets whether the layer should be tiled horizontally. */
163 {
165 }
166
167 /** Whether the layer should be tiled vertically. */
168 bool tile_vertically() const
169 {
170 return tile_vertically_;
171 }
172
173 /** Sets whether the layer should be tiled vertically. */
175 {
177 }
178
179 /** Whether the aspect ratio should be preserved while scaling. */
180 bool keep_aspect_ratio() const
181 {
182 return keep_aspect_ratio_;
183 }
184
185 /** Sets whether the aspect ratio should be preserved. */
187 {
189 }
190
191 /** Whether is this layer the base layer. */
192 bool is_base_layer() const
193 {
194 return is_base_layer_;
195 }
196
197 /** Sets whether is this layer a base layer. */
198 void set_base_layer(bool b)
199 {
201 }
202
203 /** The path to the file to load the image from. */
204 const std::string& file() const
205 {
206 return image_file_;
207 }
208
209 /** Sets the path to the image file. */
210 void set_file(const std::string& str)
211 {
212 image_file_ = str;
213 }
214
215private:
222 std::string image_file_;
223};
224
225/**
226 * Represents and contains information about a single storyscreen part.
227 */
228class part : private story_parser
229{
230public:
231 /**
232 * Currently used to indicate where the text block should be placed.
233 * Note that it will always take as much space as it is
234 * possible horizontally.
235 */
237 BLOCK_TOP, /**< Top of the screen. */
238 BLOCK_MIDDLE, /**< Center of the screen. */
239 BLOCK_BOTTOM /**< Bottom of the screen. This is the default. */
240 };
241
242 /**
243 * Used to signal user actions.
244 */
245 enum RESULT {
246 NEXT, /**< Jump to next story part. */
247 SKIP, /**< Skip all story parts for this set. */
248 QUIT /**< Quit game and go back to main menu. */
249 };
250
251 /**
252 * Constructs a storyscreen part from a managed WML node.
253 * @param part_cfg Node object which should correspond to a [part] block's contents.
254 */
255 part(const vconfig& part_cfg);
256
257 /** Whether the story screen title should be displayed or not. */
258 bool show_title() const
259 {
260 return show_title_;
261 }
262
263 /** Retrieves the story text itself. */
264 const std::string& text() const
265 {
266 return text_;
267 }
268
269 /** Changes the story text. */
270 void set_text(const std::string& text)
271 {
272 text_ = text;
273 }
274
275 /** Retrieves the story screen title. */
276 const std::string& title() const
277 {
278 return text_title_;
279 }
280
281 /** Changes the story screen title. */
282 void set_title(const std::string& title)
283 {
285 }
286
287 /** Retrieves the background music. */
288 const std::string& music() const
289 {
290 return music_;
291 }
292
293 /** Retrieves a one-time-only sound effect. */
294 const std::string& sound() const
295 {
296 return sound_;
297 }
298
299 /** Retrieves a voice track. */
300 const std::string& voice() const
301 {
302 return voice_;
303 }
304
305 /** Retrieves the area of the screen on which the story text is displayed. */
307 {
308 return text_block_loc_;
309 }
310
311 /** Retrieves the alignment of the story text within the text area. */
312 const std::string& story_text_alignment() const
313 {
314 return text_alignment_;
315 }
316
317 /** Retrieves the alignment of the title text against the screen. */
318 const std::string& title_text_alignment() const
319 {
320 return title_alignment_;
321 }
322
323 /** Retrieves the percentage based position of the title text */
324 const point& title_position() const
325 {
326 return title_perc_pos_;
327 }
328
329 /** Retrieve any associated floating images for this story screen. */
330 const std::vector<floating_image>& get_floating_images() const
331 {
332 return floating_images_;
333 }
334
335 /** Retrieve background layers for this story screen. */
336 const std::vector<background_layer>& get_background_layers() const
337 {
338 return background_layers_;
339 }
340
341private:
342 /** Inherited from story_parser. */
343 virtual void resolve_wml(const vconfig& cfg) override;
344
345 /** Inherited from story_parser. */
346 virtual bool resolve_wml_helper(const std::string& key, const vconfig& node) override;
347
348 static BLOCK_LOCATION string_tblock_loc(const std::string& s);
349
351 std::string text_;
352 std::string text_title_;
354 std::string text_alignment_;
355 std::string title_alignment_;
356
357 std::string music_;
358 std::string sound_;
359 std::string voice_;
360
361 // Position of the title text in percentage. (0,0) at top left.
363
364 std::vector<background_layer> background_layers_;
365 std::vector<floating_image> floating_images_;
366};
367
368} // end namespace storyscreen
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
const std::string & file() const
The path to the file to load the image from.
Definition part.hpp:204
void set_scale_horizontally(bool b)
Sets whether the layer should be scaled horizontally.
Definition part.hpp:138
bool tile_horizontally() const
Whether the layer should be tiled horizontally.
Definition part.hpp:156
void set_keep_aspect_ratio(bool b)
Sets whether the aspect ratio should be preserved.
Definition part.hpp:186
void set_tile_vertically(bool b)
Sets whether the layer should be tiled vertically.
Definition part.hpp:174
void set_file(const std::string &str)
Sets the path to the image file.
Definition part.hpp:210
bool scale_vertically() const
Whether the layer should be scaled vertically.
Definition part.hpp:144
bool keep_aspect_ratio() const
Whether the aspect ratio should be preserved while scaling.
Definition part.hpp:180
bool tile_vertically() const
Whether the layer should be tiled vertically.
Definition part.hpp:168
bool is_base_layer() const
Whether is this layer the base layer.
Definition part.hpp:192
bool scale_horizontally() const
Whether the layer should be scaled horizontally.
Definition part.hpp:132
void set_base_layer(bool b)
Sets whether is this layer a base layer.
Definition part.hpp:198
void set_tile_horizontally(bool b)
Sets whether the layer should be tiled horizontally.
Definition part.hpp:162
void set_scale_vertically(bool b)
Sets whether the layer should be scaled vertically.
Definition part.hpp:150
Represents and contains information about image labels used in story screen parts.
Definition part.hpp:40
const std::chrono::milliseconds & display_delay() const
Delay after displaying this image and before displaying the next image, in milliseconds.
Definition part.hpp:104
bool centered() const
Whether the image coordinates specify the location of its center (true) or top-left corner (false).
Definition part.hpp:95
void assign(const floating_image &fi)
Copy constructor and operator=() implementation details.
int ref_x() const
Returns the referential X coordinate of the image.
Definition part.hpp:67
int ref_y() const
Returns the referential Y coordinate of the image.
Definition part.hpp:76
floating_image & operator=(const floating_image &fi)
Definition part.hpp:52
bool resize_with_background() const
If true, the size of the image is changed in the same way that the ref_x and ref_y are mapped to use ...
Definition part.hpp:86
floating_image(const floating_image &fi)=default
std::chrono::milliseconds delay_
Definition part.hpp:112
std::string file() const
Definition part.hpp:58
floating_image(floating_image &&fi)=default
Represents and contains information about a single storyscreen part.
Definition part.hpp:229
std::string voice_
Definition part.hpp:359
const std::string & story_text_alignment() const
Retrieves the alignment of the story text within the text area.
Definition part.hpp:312
point title_perc_pos_
Definition part.hpp:362
const std::string & voice() const
Retrieves a voice track.
Definition part.hpp:300
static BLOCK_LOCATION string_tblock_loc(const std::string &s)
Definition part.cpp:112
BLOCK_LOCATION text_block_loc_
Definition part.hpp:353
const std::string & title() const
Retrieves the story screen title.
Definition part.hpp:276
std::string text_title_
Definition part.hpp:352
const std::string & music() const
Retrieves the background music.
Definition part.hpp:288
std::string text_
Definition part.hpp:351
std::vector< floating_image > floating_images_
Definition part.hpp:365
std::string title_alignment_
Definition part.hpp:355
std::vector< background_layer > background_layers_
Definition part.hpp:364
const std::vector< background_layer > & get_background_layers() const
Retrieve background layers for this story screen.
Definition part.hpp:336
std::string music_
Definition part.hpp:357
std::string text_alignment_
Definition part.hpp:354
const std::vector< floating_image > & get_floating_images() const
Retrieve any associated floating images for this story screen.
Definition part.hpp:330
const point & title_position() const
Retrieves the percentage based position of the title text.
Definition part.hpp:324
const std::string & sound() const
Retrieves a one-time-only sound effect.
Definition part.hpp:294
std::string sound_
Definition part.hpp:358
virtual void resolve_wml(const vconfig &cfg) override
Inherited from story_parser.
Definition part.cpp:125
void set_title(const std::string &title)
Changes the story screen title.
Definition part.hpp:282
const std::string & title_text_alignment() const
Retrieves the alignment of the title text against the screen.
Definition part.hpp:318
RESULT
Used to signal user actions.
Definition part.hpp:245
@ NEXT
Jump to next story part.
Definition part.hpp:246
@ QUIT
Quit game and go back to main menu.
Definition part.hpp:248
@ SKIP
Skip all story parts for this set.
Definition part.hpp:247
bool show_title() const
Whether the story screen title should be displayed or not.
Definition part.hpp:258
BLOCK_LOCATION story_text_location() const
Retrieves the area of the screen on which the story text is displayed.
Definition part.hpp:306
const std::string & text() const
Retrieves the story text itself.
Definition part.hpp:264
void set_text(const std::string &text)
Changes the story text.
Definition part.hpp:270
virtual bool resolve_wml_helper(const std::string &key, const vconfig &node) override
Inherited from story_parser.
Definition part.cpp:262
BLOCK_LOCATION
Currently used to indicate where the text block should be placed.
Definition part.hpp:236
@ BLOCK_BOTTOM
Bottom of the screen.
Definition part.hpp:239
@ BLOCK_MIDDLE
Center of the screen.
Definition part.hpp:238
@ BLOCK_TOP
Top of the screen.
Definition part.hpp:237
Small helper class to encapsulate the common logic for parsing storyscreen WML.
Definition parser.hpp:29
A variable-expanding proxy for the config class.
Definition variable.hpp:45
const config * cfg
Holds a 2D point.
Definition point.hpp:25
static map_location::direction s
#define b