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