The Battle for Wesnoth  1.15.2+dev
part.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2018 by Iris Morelle <shadowm2006@gmail.com>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * @file
17  * Storyscreen parts and floating images representation.
18  */
19 
20 #include "storyscreen/part.hpp"
21 
22 #include "config.hpp"
23 #include "variable.hpp"
24 
25 namespace storyscreen
26 {
28  : file_()
29  , x_(0)
30  , y_(0)
31  , delay_(0)
32  , autoscaled_(false)
33  , centered_(false)
34 {
35  this->assign(fi);
36 }
37 
39  : file_(cfg["file"])
40  , x_(cfg["x"])
41  , y_(cfg["y"])
42  , delay_(cfg["delay"])
43  , autoscaled_(cfg["scaled"].to_bool())
44  , centered_(cfg["centered"].to_bool())
45 {
46 }
47 
49 {
50  if(&fi == this) {
51  return;
52  }
53 
54  file_ = fi.file_;
55  x_ = fi.x_;
56  y_ = fi.y_;
57  delay_ = fi.delay_;
59  centered_ = fi.centered_;
60 }
61 
63  : scale_horizontally_(true)
64  , scale_vertically_(true)
65  , tile_horizontally_(false)
66  , tile_vertically_(false)
67  , keep_aspect_ratio_(true)
68  , is_base_layer_(false)
69  , image_file_()
70 {
71 }
72 
74  : scale_horizontally_(true)
75  , scale_vertically_(true)
76  , tile_horizontally_(false)
77  , tile_vertically_(false)
78  , keep_aspect_ratio_(true)
79  , is_base_layer_(false)
80  , image_file_()
81 {
82  if(cfg.has_attribute("image")) {
83  image_file_ = cfg["image"].str();
84  }
85 
86  if(cfg.has_attribute("scale")) {
87  scale_vertically_ = cfg["scale"].to_bool(true);
88  scale_horizontally_ = cfg["scale"].to_bool(true);
89  } else {
90  if(cfg.has_attribute("scale_vertically")) {
91  scale_vertically_ = cfg["scale_vertically"].to_bool(true);
92  }
93 
94  if(cfg.has_attribute("scale_horizontally")) {
95  scale_horizontally_ = cfg["scale_horizontally"].to_bool(true);
96  }
97  }
98 
99  if(cfg.has_attribute("tile")) {
100  tile_vertically_ = cfg["tile"].to_bool(false);
101  tile_horizontally_ = cfg["tile"].to_bool(false);
102  } else {
103  if(cfg.has_attribute("tile_vertically")) {
104  tile_vertically_ = cfg["tile_vertically"].to_bool(false);
105  }
106 
107  if(cfg.has_attribute("tile_horizontally")) {
108  tile_horizontally_ = cfg["tile_horizontally"].to_bool(false);
109  }
110  }
111 
112  if(cfg.has_attribute("keep_aspect_ratio")) {
113  keep_aspect_ratio_ = cfg["keep_aspect_ratio"].to_bool(true);
114  }
115 
116  if(cfg.has_attribute("base_layer")) {
117  is_base_layer_ = cfg["base_layer"].to_bool(false);
118  }
119 }
120 
121 part::part(const vconfig& part_cfg)
122  : show_title_()
123  , text_()
124  , text_title_()
125  , text_block_loc_(part::BLOCK_BOTTOM)
126  , text_alignment_("left")
127  , title_alignment_("left")
128  , music_()
129  , sound_()
130  , background_layers_()
131  , floating_images_()
132 {
133  resolve_wml(part_cfg);
134 }
135 
137 {
138  if(s.empty() != true) {
139  if(s == "top") {
140  return part::BLOCK_TOP;
141  } else if(s == "middle") {
142  return part::BLOCK_MIDDLE;
143  }
144  }
145 
146  return part::BLOCK_BOTTOM;
147 }
148 
149 void part::resolve_wml(const vconfig& cfg)
150 {
151  if(cfg.null()) {
152  return;
153  }
154 
155  // Converts shortcut syntax to members of [background_layer]
156  background_layer bl;
157 
158  if(cfg.has_attribute("background")) {
159  bl.set_file(cfg["background"].str());
160  }
161 
162  if(cfg.has_attribute("scale_background")) {
163  bl.set_scale_horizontally(cfg["scale_background"].to_bool(true));
164  bl.set_scale_vertically(cfg["scale_background"].to_bool(true));
165  } else {
166  if(cfg.has_attribute("scale_background_vertically")) {
167  bl.set_scale_vertically(cfg["scale_background_vertically"].to_bool(true));
168  }
169 
170  if(cfg.has_attribute("scale_background_horizontally")) {
171  bl.set_scale_horizontally(cfg["scale_background_horizontally"].to_bool(true));
172  }
173  }
174 
175  if(cfg.has_attribute("tile_background")) {
176  bl.set_tile_horizontally(cfg["tile_background"].to_bool(false));
177  bl.set_tile_vertically(cfg["tile_background"].to_bool(false));
178  } else {
179  if(cfg.has_attribute("tile_background_vertically")) {
180  bl.set_tile_vertically(cfg["tile_background_vertically"].to_bool(false));
181  }
182 
183  if(cfg.has_attribute("tile_background_horizontally")) {
184  bl.set_tile_vertically(cfg["tile_background_horizontally"].to_bool(false));
185  }
186  }
187 
188  if(cfg.has_attribute("keep_aspect_ratio")) {
189  bl.set_keep_aspect_ratio(cfg["keep_aspect_ratio"].to_bool(true));
190  }
191 
192  background_layers_.push_back(bl);
193 
194  if(cfg.has_attribute("show_title")) {
195  show_title_ = cfg["show_title"].to_bool();
196  }
197 
198  if(cfg.has_attribute("story")) {
199  text_ = cfg["story"].str();
200  }
201 
202  if(cfg.has_attribute("title")) {
203  text_title_ = cfg["title"].str();
204  if(!cfg.has_attribute("show_title")) {
205  show_title_ = true;
206  }
207  }
208 
209  if(cfg.has_attribute("text_layout")) {
210  text_block_loc_ = string_tblock_loc(cfg["text_layout"]);
211  }
212 
213  if(cfg.has_attribute("text_alignment")) {
214  text_alignment_ = cfg["text_alignment"].str();
215  }
216 
217  if(cfg.has_attribute("title_alignment")) {
218  title_alignment_ = cfg["title_alignment"].str();
219  }
220 
221  if(cfg.has_attribute("music")) {
222  music_ = cfg["music"].str();
223  }
224 
225  if(cfg.has_attribute("sound")) {
226  sound_ = cfg["sound"].str();
227  }
228 
229  if(cfg.has_attribute("voice")) {
230  voice_ = cfg["voice"].str();
231  }
232 
233  // Inherited
235 }
236 
237 bool part::resolve_wml_helper(const std::string& key, const vconfig& node)
238 {
239  bool found = false;
240 
241  // [background_layer]
242  if(key == "background_layer") {
243  background_layers_.push_back(node.get_parsed_config());
244  found = true;
245  }
246  // [image]
247  else if(key == "image") {
248  floating_images_.push_back(node.get_parsed_config());
249  found = true;
250  }
251 
252  return found;
253 }
254 
255 } // end namespace storyscreen
std::string music_
Definition: part.hpp:347
void set_keep_aspect_ratio(bool b)
Sets whether the aspect ratio should be preserved.
Definition: part.hpp:182
Center of the screen.
Definition: part.hpp:234
Storyscreen parts and floating images representation.
bool has_attribute(config_key_type key) const
Definition: config.cpp:213
bool has_attribute(const std::string &key) const
< Synonym for operator[]
Definition: variable.hpp:99
std::string title_alignment_
Definition: part.hpp:345
std::string text_
Definition: part.hpp:341
std::string voice_
Definition: part.hpp:349
Bottom of the screen.
Definition: part.hpp:235
Definitions for the interface to Wesnoth Markup Language (WML).
void set_tile_vertically(bool b)
Sets whether the layer should be tiled vertically.
Definition: part.hpp:170
virtual void resolve_wml(const vconfig &cfg)
Takes care of initializing and branching properties.
Definition: parser.cpp:29
BLOCK_LOCATION text_block_loc_
Definition: part.hpp:343
void set_file(const std::string &str)
Sets the path to the image file.
Definition: part.hpp:206
Represents and contains information about image labels used in story screen parts.
Definition: part.hpp:37
void set_tile_horizontally(bool b)
Sets whether the layer should be tiled horizontally.
Definition: part.hpp:158
virtual bool resolve_wml_helper(const std::string &key, const vconfig &node) override
Inherited from story_parser.
Definition: part.cpp:237
config get_parsed_config() const
Definition: variable.cpp:140
std::vector< background_layer > background_layers_
Definition: part.hpp:351
Represents and contains information about a single storyscreen part.
Definition: part.hpp:224
std::vector< floating_image > floating_images_
Definition: part.hpp:352
std::string sound_
Definition: part.hpp:348
static BLOCK_LOCATION string_tblock_loc(const std::string &s)
Definition: part.cpp:136
std::string text_title_
Definition: part.hpp:342
Top of the screen.
Definition: part.hpp:233
void assign(const floating_image &fi)
Copy constructor and operator=() implementation details.
Definition: part.cpp:48
static map_location::DIRECTION s
bool show_title_
Definition: part.hpp:340
virtual void resolve_wml(const vconfig &cfg) override
Inherited from story_parser.
Definition: part.cpp:149
std::string text_alignment_
Definition: part.hpp:344
floating_image(const config &cfg)
WML-based constructor.
Definition: part.cpp:38
part(const vconfig &part_cfg)
Constructs a storyscreen part from a managed WML node.
Definition: part.cpp:121
A variable-expanding proxy for the config class.
Definition: variable.hpp:42
void set_scale_horizontally(bool b)
Sets whether the layer should be scaled horizontally.
Definition: part.hpp:134
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
bool null() const
Definition: variable.hpp:73
void set_scale_vertically(bool b)
Sets whether the layer should be scaled vertically.
Definition: part.hpp:146
BLOCK_LOCATION
Currently used to indicate where the text block should be placed.
Definition: part.hpp:232