The Battle for Wesnoth  1.15.2+dev
frame.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006 - 2018 by Jeremy Rosen <jeremy.rosen@enst-bretagne.fr>
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  * Frame for unit's animation sequence.
18  */
19 
20 #pragma once
21 
22 #include "units/frame_private.hpp"
23 
24 #include "color.hpp"
25 #include "halo.hpp"
26 #include "picture.hpp"
27 
28 #include <boost/logic/tribool.hpp>
29 #include <boost/optional.hpp>
30 
31 class config;
32 
33 /** All parameters from a frame at a given instant */
35 {
37 
38  int duration;
39 
42 
43  std::string image_mod;
44  std::string halo;
45 
46  int halo_x;
47  int halo_y;
48 
49  std::string halo_mod;
50  std::string sound;
51  std::string text;
52 
53  boost::optional<color_t> text_color;
54  boost::optional<color_t> blend_with;
55 
56  double blend_ratio;
58  double offset;
59  double submerge;
60 
61  int x;
62  int y;
65 
66  boost::tribool auto_vflip;
67  boost::tribool auto_hflip;
68  boost::tribool primary_frame;
69 
71 };
72 
73 /**
74  * Easily build frame parameters with the serialized constructors
75  */
78 {
79 public:
80  frame_builder();
81  frame_builder(const config& cfg, const std::string& frame_string = "");
82 
83  /** Allow easy chained modifications. Will raised assert if used after initialization */
84  frame_builder& duration(const int duration);
85  frame_builder& image(const std::string& image, const std::string& image_mod = "");
86  frame_builder& image_diagonal(const std::string& image_diagonal, const std::string& image_mod = "");
87  frame_builder& sound(const std::string& sound);
88  frame_builder& text(const std::string& text, const color_t text_color);
89  frame_builder& halo(const std::string& halo, const std::string& halo_x, const std::string& halo_y, const std::string& halo_mod);
90  frame_builder& blend(const std::string& blend_ratio, const color_t blend_color);
91  frame_builder& highlight(const std::string& highlight);
92  frame_builder& offset(const std::string& offset);
93  frame_builder& submerge(const std::string& submerge);
94  frame_builder& x(const std::string& x);
95  frame_builder& y(const std::string& y);
96  frame_builder& directional_x(const std::string& directional_x);
97  frame_builder& directional_y(const std::string& directional_y);
98  frame_builder& auto_vflip(const bool auto_vflip);
99  frame_builder& auto_hflip(const bool auto_hflip);
101  frame_builder& drawing_layer(const std::string& drawing_layer);
102 
103 private:
105 
107 
108  std::string image_;
109  std::string image_diagonal_;
110  std::string image_mod_;
111  std::string halo_;
112  std::string halo_x_;
113  std::string halo_y_;
114  std::string halo_mod_;
115  std::string sound_;
116  std::string text_;
117 
118  boost::optional<color_t> text_color_;
119  boost::optional<color_t> blend_with_;
120 
121  std::string blend_ratio_;
122  std::string highlight_ratio_;
123  std::string offset_;
124  std::string submerge_;
125  std::string x_;
126  std::string y_;
127  std::string directional_x_;
128  std::string directional_y_;
129 
130  boost::tribool auto_vflip_;
131  boost::tribool auto_hflip_;
132  boost::tribool primary_frame_;
133 
134  std::string drawing_layer_;
135 };
136 
137 /**
138  * Keep most parameters in a separate class to simplify the handling of the large
139  * number of parameters between the frame level and animation level.
140  */
142 {
143 public:
144  frame_parsed_parameters(const frame_builder& builder = frame_builder(), int override_duration = 0);
145 
146  void override(int duration,
147  const std::string& highlight = "",
148  const std::string& blend_ratio = "",
149  color_t blend_color = {0,0,0},
150  const std::string& offset = "",
151  const std::string& layer = "",
152  const std::string& modifiers = "");
153 
154  /** Getters for the different parameters */
155  const frame_parameters parameters(int current_time) const;
156 
157  int duration() const{ return duration_;}
158  bool does_not_change() const;
159  bool need_update() const;
160 
161  /** Contents of frame in strings */
162  std::vector<std::string> debug_strings() const;
163 
164 private:
166 
169 
170  std::string image_mod_;
171 
175 
176  std::string halo_mod_;
177  std::string sound_;
178  std::string text_;
179 
180  boost::optional<color_t> text_color_;
181  boost::optional<color_t> blend_with_;
182 
191 
192  boost::tribool auto_vflip_;
193  boost::tribool auto_hflip_;
194  boost::tribool primary_frame_;
195 
197 };
198 
199 /** Describes a unit's animation sequence. */
201 {
202 public:
203  // Constructors
204  unit_frame(const frame_builder& builder = frame_builder()) : builder_(builder) {}
205 
206  void redraw(const int frame_time, bool on_start_time, bool in_scope_of_frame, const map_location& src, const map_location& dst,
207  halo::handle& halo_id, halo::manager& halo_man, const frame_parameters& animation_val, const frame_parameters& engine_val) const;
208 
209  const frame_parameters merge_parameters(int current_time, const frame_parameters& animation_val,
210  const frame_parameters& engine_val = frame_parameters()) const;
211 
212  const frame_parameters parameters(int current_time) const
213  {
214  return builder_.parameters(current_time);
215  }
216 
218  {
219  return builder_.parameters(duration());
220  }
221 
222  int duration() const
223  {
224  return builder_.duration();
225  }
226 
227  bool does_not_change() const
228  {
229  return builder_.does_not_change();
230  }
231 
232  bool need_update() const
233  {
234  return builder_.need_update();
235  }
236 
237  std::vector<std::string> debug_strings() const
238  {
239  // Contents of frame in strings
240  return builder_.debug_strings();
241  }
242 
243  std::set<map_location> get_overlaped_hex(const int frame_time, const map_location& src, const map_location& dst,
244  const frame_parameters& animation_val, const frame_parameters& engine_val) const;
245 
246 private:
248 };
Describes a unit&#39;s animation sequence.
Definition: frame.hpp:200
std::string image_
Definition: frame.hpp:108
std::string sound
Definition: frame.hpp:50
boost::tribool auto_hflip_
Definition: frame.hpp:193
All parameters from a frame at a given instant.
Definition: frame.hpp:34
boost::tribool auto_hflip
Definition: frame.hpp:67
image::locator image
Definition: frame.hpp:40
progressive_int halo_x_
Definition: frame.hpp:173
progressive_double blend_ratio_
Definition: frame.hpp:183
std::string image_mod_
Definition: frame.hpp:170
Keep most parameters in a separate class to simplify the handling of the large number of parameters b...
Definition: frame.hpp:141
std::string blend_ratio_
Definition: frame.hpp:121
std::string sound_
Definition: frame.hpp:177
std::string directional_y_
Definition: frame.hpp:128
std::string text_
Definition: frame.hpp:116
boost::optional< color_t > text_color
Definition: frame.hpp:53
int directional_x
Definition: frame.hpp:63
int drawing_layer
Definition: frame.hpp:70
std::string drawing_layer_
Definition: frame.hpp:134
std::string text
Definition: frame.hpp:51
Audio output for sound and music.
Definition: sound.cpp:40
std::string halo_mod_
Definition: frame.hpp:114
int directional_y
Definition: frame.hpp:64
unit_frame(const frame_builder &builder=frame_builder())
Definition: frame.hpp:204
std::string halo_y_
Definition: frame.hpp:113
image::locator image_diagonal
Definition: frame.hpp:41
boost::tribool primary_frame_
Definition: frame.hpp:132
std::string halo
Definition: frame.hpp:44
std::vector< std::string > debug_strings() const
Definition: frame.hpp:237
std::string halo_
Definition: frame.hpp:111
frame_parsed_parameters builder_
Definition: frame.hpp:247
boost::optional< color_t > text_color_
Definition: frame.hpp:118
std::string halo_mod
Definition: frame.hpp:49
progressive_image image_diagonal_
Definition: frame.hpp:168
std::string highlight_ratio_
Definition: frame.hpp:122
progressive_int x_
Definition: frame.hpp:187
const frame_parameters parameters(int current_time) const
Definition: frame.hpp:212
boost::tribool primary_frame_
Definition: frame.hpp:194
bool does_not_change() const
Definition: frame.hpp:227
std::string text_
Definition: frame.hpp:178
bool need_update() const
Definition: frame.hpp:232
progressive_image image_
Definition: frame.hpp:167
progressive_double highlight_ratio_
Definition: frame.hpp:184
std::string y_
Definition: frame.hpp:126
progressive_int halo_y_
Definition: frame.hpp:174
std::string directional_x_
Definition: frame.hpp:127
progressive_int drawing_layer_
Definition: frame.hpp:196
progressive_int directional_x_
Definition: frame.hpp:189
Encapsulates the map of the game.
Definition: location.hpp:42
boost::optional< color_t > blend_with
Definition: frame.hpp:54
boost::optional< color_t > text_color_
Definition: frame.hpp:180
double highlight_ratio
Definition: frame.hpp:57
boost::optional< color_t > blend_with_
Definition: frame.hpp:181
int duration() const
Definition: frame.hpp:157
std::string image_mod
Definition: frame.hpp:43
int duration_
Definition: frame.hpp:106
const frame_parameters end_parameters() const
Definition: frame.hpp:217
std::string offset_
Definition: frame.hpp:123
boost::tribool auto_vflip
Definition: frame.hpp:66
double blend_ratio
Definition: frame.hpp:56
progressive_double submerge_
Definition: frame.hpp:186
double submerge
Definition: frame.hpp:59
int duration() const
Definition: frame.hpp:222
double offset
Definition: frame.hpp:58
Definition: display.hpp:44
progressive_int directional_y_
Definition: frame.hpp:190
boost::tribool auto_vflip_
Definition: frame.hpp:130
this module manages the cache of images.
std::string halo_mod_
Definition: frame.hpp:176
std::string image_diagonal_
Definition: frame.hpp:109
boost::tribool auto_hflip_
Definition: frame.hpp:131
progressive_double offset_
Definition: frame.hpp:185
std::string halo_x_
Definition: frame.hpp:112
std::string x_
Definition: frame.hpp:125
boost::optional< color_t > blend_with_
Definition: frame.hpp:119
progressive_string halo_
Definition: frame.hpp:172
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
progressive_int y_
Definition: frame.hpp:188
std::string image_mod_
Definition: frame.hpp:110
std::shared_ptr< halo_record > handle
Definition: halo.hpp:31
boost::tribool primary_frame
Definition: frame.hpp:68
std::string submerge_
Definition: frame.hpp:124
std::string sound_
Definition: frame.hpp:115
boost::tribool auto_vflip_
Definition: frame.hpp:192