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  */
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  frame_parameters merge_parameters(int current_time, const frame_parameters& animation_val,
211  const frame_parameters& engine_val = frame_parameters()) const;
212 
213  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 };
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
std::string offset_
Definition: frame.hpp:124
std::string halo_y_
Definition: frame.hpp:114
std::string image_mod_
Definition: frame.hpp:111
std::string halo_mod_
Definition: frame.hpp:115
std::string image_diagonal_
Definition: frame.hpp:110
frame_builder()
Definition: frame.cpp:45
boost::tribool auto_vflip_
Definition: frame.hpp:131
boost::tribool primary_frame_
Definition: frame.hpp:133
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:112
frame_builder & highlight(const std::string &highlight)
Definition: frame.cpp:175
std::string sound_
Definition: frame.hpp:116
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:120
frame_builder & submerge(const std::string &submerge)
Definition: frame.cpp:187
std::string image_
Definition: frame.hpp:109
std::string submerge_
Definition: frame.hpp:125
int duration_
Definition: frame.hpp:107
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:119
std::string y_
Definition: frame.hpp:127
std::string highlight_ratio_
Definition: frame.hpp:123
boost::tribool auto_hflip_
Definition: frame.hpp:132
std::string blend_ratio_
Definition: frame.hpp:122
std::string text_
Definition: frame.hpp:117
std::string drawing_layer_
Definition: frame.hpp:135
frame_builder & drawing_layer(const std::string &drawing_layer)
Definition: frame.cpp:235
std::string directional_x_
Definition: frame.hpp:128
std::string directional_y_
Definition: frame.hpp:129
std::string halo_x_
Definition: frame.hpp:113
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:126
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:143
std::optional< color_t > blend_with_
Definition: frame.hpp:182
std::string text_
Definition: frame.hpp:179
std::optional< color_t > text_color_
Definition: frame.hpp:181
progressive_int directional_x_
Definition: frame.hpp:190
progressive_int halo_y_
Definition: frame.hpp:175
boost::tribool auto_hflip_
Definition: frame.hpp:194
progressive_image image_
Definition: frame.hpp:168
boost::tribool primary_frame_
Definition: frame.hpp:195
bool need_update() const
Definition: frame.cpp:287
progressive_double blend_ratio_
Definition: frame.hpp:184
progressive_double highlight_ratio_
Definition: frame.hpp:185
progressive_double offset_
Definition: frame.hpp:186
boost::tribool auto_vflip_
Definition: frame.hpp:193
progressive_string halo_
Definition: frame.hpp:173
progressive_int x_
Definition: frame.hpp:188
int duration() const
Definition: frame.hpp:158
std::string sound_
Definition: frame.hpp:178
const frame_parameters parameters(int current_time) const
Getters for the different parameters.
Definition: frame.cpp:292
progressive_double submerge_
Definition: frame.hpp:187
std::string halo_mod_
Definition: frame.hpp:177
std::string image_mod_
Definition: frame.hpp:171
progressive_int halo_x_
Definition: frame.hpp:174
progressive_int y_
Definition: frame.hpp:189
progressive_int drawing_layer_
Definition: frame.hpp:197
std::vector< std::string > debug_strings() const
Contents of frame in strings.
Definition: frame.cpp:374
progressive_int directional_y_
Definition: frame.hpp:191
progressive_image image_diagonal_
Definition: frame.hpp:169
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:64
Describes a unit's animation sequence.
Definition: frame.hpp:202
bool need_update() const
Definition: frame.hpp:233
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:861
int duration() const
Definition: frame.hpp:223
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:569
bool does_not_change() const
Definition: frame.hpp:228
std::vector< std::string > debug_strings() const
Definition: frame.hpp:238
frame_parameters parameters(int current_time) const
Definition: frame.hpp:213
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:738
frame_parameters end_parameters() const
Definition: frame.hpp:218
unit_frame(const frame_builder &builder=frame_builder())
Definition: frame.hpp:205
frame_parsed_parameters builder_
Definition: frame.hpp:248
Definition: display.hpp:45
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:42
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