The Battle for Wesnoth  1.19.0-dev
frame.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006 - 2024
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  */
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  std::optional<color_t> text_color_;
119  std::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  std::optional<color_t> text_color_;
181  std::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  frame_parameters merge_parameters(int current_time, const frame_parameters& animation_val,
210  const frame_parameters& engine_val = frame_parameters()) const;
211 
212  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 };
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
Easily build frame parameters with the serialized constructors.
Definition: frame.hpp:78
std::string offset_
Definition: frame.hpp:123
std::string halo_y_
Definition: frame.hpp:113
std::string image_mod_
Definition: frame.hpp:110
std::string halo_mod_
Definition: frame.hpp:114
std::string image_diagonal_
Definition: frame.hpp:109
frame_builder()
Definition: frame.cpp:45
boost::tribool auto_vflip_
Definition: frame.hpp:130
boost::tribool primary_frame_
Definition: frame.hpp:132
frame_builder & duration(const int duration)
Allow easy chained modifications.
Definition: frame.cpp:162
frame_builder & auto_hflip(const bool auto_hflip)
Definition: frame.cpp:223
std::string halo_
Definition: frame.hpp:111
frame_builder & highlight(const std::string &highlight)
Definition: frame.cpp:175
std::string sound_
Definition: frame.hpp:115
frame_builder & image_diagonal(const std::string &image_diagonal, const std::string &image_mod="")
Definition: frame.cpp:133
frame_builder & directional_x(const std::string &directional_x)
Definition: frame.cpp:205
std::optional< color_t > blend_with_
Definition: frame.hpp:119
frame_builder & submerge(const std::string &submerge)
Definition: frame.cpp:187
std::string image_
Definition: frame.hpp:108
std::string submerge_
Definition: frame.hpp:124
int duration_
Definition: frame.hpp:106
frame_builder & y(const std::string &y)
Definition: frame.cpp:199
frame_builder & primary_frame(const bool primary_frame)
Definition: frame.cpp:229
frame_builder & auto_vflip(const bool auto_vflip)
Definition: frame.cpp:217
std::optional< color_t > text_color_
Definition: frame.hpp:118
std::string y_
Definition: frame.hpp:126
std::string highlight_ratio_
Definition: frame.hpp:122
boost::tribool auto_hflip_
Definition: frame.hpp:131
std::string blend_ratio_
Definition: frame.hpp:121
std::string text_
Definition: frame.hpp:116
std::string drawing_layer_
Definition: frame.hpp:134
frame_builder & drawing_layer(const std::string &drawing_layer)
Definition: frame.cpp:235
std::string directional_x_
Definition: frame.hpp:127
std::string directional_y_
Definition: frame.hpp:128
std::string halo_x_
Definition: frame.hpp:112
frame_builder & text(const std::string &text, const color_t text_color)
Definition: frame.cpp:146
frame_builder & blend(const std::string &blend_ratio, const color_t blend_color)
Definition: frame.cpp:168
frame_builder & x(const std::string &x)
Definition: frame.cpp:193
frame_builder & offset(const std::string &offset)
Definition: frame.cpp:181
frame_builder & directional_y(const std::string &directional_y)
Definition: frame.cpp:211
frame_builder & image(const std::string &image, const std::string &image_mod="")
Definition: frame.cpp:126
frame_builder & sound(const std::string &sound)
Definition: frame.cpp:140
std::string x_
Definition: frame.hpp:125
frame_builder & halo(const std::string &halo, const std::string &halo_x, const std::string &halo_y, const std::string &halo_mod)
Definition: frame.cpp:153
Keep most parameters in a separate class to simplify the handling of the large number of parameters b...
Definition: frame.hpp:142
std::optional< color_t > blend_with_
Definition: frame.hpp:181
std::string text_
Definition: frame.hpp:178
std::optional< color_t > text_color_
Definition: frame.hpp:180
progressive_int directional_x_
Definition: frame.hpp:189
progressive_int halo_y_
Definition: frame.hpp:174
boost::tribool auto_hflip_
Definition: frame.hpp:193
progressive_image image_
Definition: frame.hpp:167
boost::tribool primary_frame_
Definition: frame.hpp:194
bool need_update() const
Definition: frame.cpp:287
progressive_double blend_ratio_
Definition: frame.hpp:183
progressive_double highlight_ratio_
Definition: frame.hpp:184
progressive_double offset_
Definition: frame.hpp:185
boost::tribool auto_vflip_
Definition: frame.hpp:192
progressive_string halo_
Definition: frame.hpp:172
progressive_int x_
Definition: frame.hpp:187
int duration() const
Definition: frame.hpp:157
std::string sound_
Definition: frame.hpp:177
const frame_parameters parameters(int current_time) const
Getters for the different parameters.
Definition: frame.cpp:292
progressive_double submerge_
Definition: frame.hpp:186
std::string halo_mod_
Definition: frame.hpp:176
std::string image_mod_
Definition: frame.hpp:170
progressive_int halo_x_
Definition: frame.hpp:173
progressive_int y_
Definition: frame.hpp:188
progressive_int drawing_layer_
Definition: frame.hpp:196
std::vector< std::string > debug_strings() const
Contents of frame in strings.
Definition: frame.cpp:374
progressive_int directional_y_
Definition: frame.hpp:190
progressive_image image_diagonal_
Definition: frame.hpp:168
bool does_not_change() const
Definition: frame.cpp:268
frame_parsed_parameters(const frame_builder &builder=frame_builder(), int override_duration=0)
Definition: frame.cpp:241
Generic locator abstracting the location of an image.
Definition: picture.hpp:63
Describes a unit's animation sequence.
Definition: frame.hpp:201
bool need_update() const
Definition: frame.hpp:232
frame_parameters merge_parameters(int current_time, const frame_parameters &animation_val, const frame_parameters &engine_val=frame_parameters()) const
This function merges the value provided by:
Definition: frame.cpp:901
int duration() const
Definition: frame.hpp:222
void redraw(const int frame_time, bool on_start_time, bool in_scope_of_frame, const map_location &src, const map_location &dst, halo::handle &halo_id, halo::manager &halo_man, const frame_parameters &animation_val, const frame_parameters &engine_val) const
Definition: frame.cpp:609
bool does_not_change() const
Definition: frame.hpp:227
std::vector< std::string > debug_strings() const
Definition: frame.hpp:237
frame_parameters parameters(int current_time) const
Definition: frame.hpp:212
std::set< map_location > get_overlaped_hex(const int frame_time, const map_location &src, const map_location &dst, const frame_parameters &animation_val, const frame_parameters &engine_val) const
Definition: frame.cpp:778
frame_parameters end_parameters() const
Definition: frame.hpp:217
unit_frame(const frame_builder &builder=frame_builder())
Definition: frame.hpp:204
frame_parsed_parameters builder_
Definition: frame.hpp:247
Definition: halo.cpp:39
std::shared_ptr< halo_record > handle
Definition: halo.hpp:31
Functions to load and save images from/to disk.
Audio output for sound and music.
Definition: sound.cpp:40
The basic class for representing 8-bit RGB or RGBA colour values.
Definition: color.hpp:59
All parameters from a frame at a given instant.
Definition: frame.hpp:36
std::string halo
Definition: frame.hpp:45
double highlight_ratio
Definition: frame.hpp:58
std::string text
Definition: frame.hpp:52
boost::tribool auto_hflip
Definition: frame.hpp:68
int directional_x
Definition: frame.hpp:64
double offset
Definition: frame.hpp:59
std::string sound
Definition: frame.hpp:51
std::string image_mod
Definition: frame.hpp:44
double submerge
Definition: frame.hpp:60
int drawing_layer
Definition: frame.hpp:71
image::locator image_diagonal
Definition: frame.hpp:42
boost::tribool primary_frame
Definition: frame.hpp:69
int directional_y
Definition: frame.hpp:65
image::locator image
Definition: frame.hpp:41
std::optional< color_t > text_color
Definition: frame.hpp:54
double blend_ratio
Definition: frame.hpp:57
std::optional< color_t > blend_with
Definition: frame.hpp:55
std::string halo_mod
Definition: frame.hpp:50
boost::tribool auto_vflip
Definition: frame.hpp:67
Encapsulates the map of the game.
Definition: location.hpp:38