26 #define ERR_NG LOG_STREAM(err, log_engine)
30 , auto_vflip_(boost::logic::indeterminate)
31 , auto_hflip_(boost::logic::indeterminate)
32 , primary_frame_(boost::logic::indeterminate)
38 , image_(cfg[frame_string +
"image"])
39 , image_diagonal_(cfg[frame_string +
"image_diagonal"])
40 , image_mod_(cfg[frame_string +
"image_mod"])
41 , halo_(cfg[frame_string +
"halo"])
42 , halo_x_(cfg[frame_string +
"halo_x"])
43 , halo_y_(cfg[frame_string +
"halo_y"])
44 , halo_mod_(cfg[frame_string +
"halo_mod"])
45 , sound_(cfg[frame_string +
"sound"])
46 , text_(cfg[frame_string +
"text"])
47 , blend_ratio_(cfg[frame_string +
"blend_ratio"])
48 , highlight_ratio_(cfg[frame_string +
"alpha"])
49 , offset_(cfg[frame_string +
"offset"])
50 , submerge_(cfg[frame_string +
"submerge"])
51 , x_(cfg[frame_string +
"x"])
52 , y_(cfg[frame_string +
"y"])
53 , directional_x_(cfg[frame_string +
"directional_x"])
54 , directional_y_(cfg[frame_string +
"directional_y"])
55 , auto_vflip_(boost::logic::indeterminate)
56 , auto_hflip_(boost::logic::indeterminate)
57 , primary_frame_(boost::logic::indeterminate)
58 , drawing_layer_(cfg[frame_string +
"layer"])
61 auto_vflip_ = cfg[frame_string +
"auto_vflip"].to_bool();
65 auto_hflip_ = cfg[frame_string +
"auto_hflip"].to_bool();
72 const auto& text_color_key = cfg[frame_string +
"text_color"];
73 if(!text_color_key.empty()) {
76 }
catch(
const std::invalid_argument&
e) {
78 ERR_NG <<
"Invalid RBG text color in unit animation: " << text_color_key.str()
84 duration(chrono::parse_duration<std::chrono::milliseconds>(*v));
85 }
else if(!cfg.
get(frame_string +
"end")) {
90 duration(std::max(std::max(image_duration, image_diagonal_duration), halo_duration));
92 auto t1 = chrono::parse_duration<std::chrono::milliseconds>(cfg[frame_string +
"begin"]);
93 auto t2 = chrono::parse_duration<std::chrono::milliseconds>(cfg[frame_string +
"end"]);
99 const auto& blend_color_key = cfg[frame_string +
"blend_color"];
100 if(!blend_color_key.empty()) {
103 }
catch(
const std::invalid_argument&
e) {
105 ERR_NG <<
"Invalid RBG blend color in unit animation: " << blend_color_key.str()
227 : duration_(duration > std::
chrono::milliseconds{0} ? duration : builder.duration_)
228 , image_(builder.image_,duration_)
229 , image_diagonal_(builder.image_diagonal_,duration_)
230 , image_mod_(builder.image_mod_)
231 , halo_(builder.halo_,duration_)
232 , halo_x_(builder.halo_x_,duration_)
233 , halo_y_(builder.halo_y_,duration_)
234 , halo_mod_(builder.halo_mod_)
235 , sound_(builder.sound_)
236 , text_(builder.text_)
237 , text_color_(builder.text_color_)
238 , blend_with_(builder.blend_with_)
239 , blend_ratio_(builder.blend_ratio_,duration_)
240 , highlight_ratio_(builder.highlight_ratio_,duration_)
241 , offset_(builder.offset_,duration_)
242 , submerge_(builder.submerge_,duration_)
243 , x_(builder.x_,duration_)
244 , y_(builder.y_,duration_)
245 , directional_x_(builder.directional_x_,duration_)
246 , directional_y_(builder.directional_y_,duration_)
247 , auto_vflip_(builder.auto_vflip_)
248 , auto_hflip_(builder.auto_hflip_)
249 , primary_frame_(builder.primary_frame_)
250 , drawing_layer_(builder.drawing_layer_,duration_)
279 #ifdef __cpp_designated_initializers
337 const std::string& highlight,
338 const std::string& blend_ratio,
340 const std::string& offset,
341 const std::string& layer,
342 const std::string& modifiers)
344 if(!highlight.empty()) {
350 if(!offset.empty()) {
356 if(!blend_ratio.empty()) {
369 if(!modifiers.empty()) {
390 std::vector<std::string> v;
425 v.emplace_back(
"sound=" +
sound_);
429 v.emplace_back(
"text=" +
text_);
432 v.emplace_back(
"text_color=" +
text_color_->to_rgba_string());
440 v.emplace_back(
"blend_with=" +
blend_with_->to_rgba_string());
493 void render_unit_image(
508 if(!image_size.x || !image_size.y) {
522 blend_ratio = std::clamp(blend_ratio, 0.0, 1.0);
565 if(blend_ratio == 0.0) {
573 +
"~CHAN(255, 255, 255, alpha)"
585 blendto.a = uint8_t(
data.alpha_verts[0].color.a * blend_ratio);
586 data.alpha_verts[0].color = blendto;
587 data.alpha_verts[1].color = blendto;
589 blendto.a = uint8_t(
data.alpha_verts[2].color.a * blend_ratio);
590 data.alpha_verts[2].color = blendto;
591 data.alpha_verts[3].color = blendto;
630 void unit_frame::redraw(
const std::chrono::milliseconds& frame_time,
bool on_start_time,
bool in_scope_of_frame,
642 double tmp_offset = current_data.
offset;
651 if(!current_data.
sound.empty() ) {
669 point image_size {0, 0};
676 const int x =
static_cast<int>(tmp_offset * xdst + (1.0 - tmp_offset) * xsrc) + d2;
677 const int y =
static_cast<int>(tmp_offset * ydst + (1.0 - tmp_offset) * ysrc) + d2;
680 if(image_size.x && image_size.y) {
685 bool facing_north = (
690 if(!current_data.
auto_hflip) { facing_west =
false; }
691 if(!current_data.
auto_vflip) { facing_north =
true; }
693 int my_x = x + disp_zoom * (current_data.
x - image_size.x / 2);
694 int my_y = y + disp_zoom * (current_data.
y - image_size.y / 2);
720 render_unit_image(my_x, my_y,
737 if(!in_scope_of_frame) {
742 if(current_data.
halo.empty()) {
778 halo_id = halo_man.
add(
779 static_cast<int>(x + current_data.
halo_x * disp_zoom),
780 static_cast<int>(y + current_data.
halo_y * disp_zoom),
786 halo_id = halo_man.
add(
787 static_cast<int>(x - current_data.
halo_x * disp_zoom),
788 static_cast<int>(y + current_data.
halo_y * disp_zoom),
807 double tmp_offset = current_data.
offset;
821 std::set<map_location> result;
825 bool facing_north = (
830 if(!current_data.
auto_vflip) { facing_north =
true; }
832 int my_y = current_data.
y;
843 }
else if(my_y > 0) {
857 if(
w != 0 ||
h != 0) {
859 const int x =
static_cast<int>(tmp_offset * xdst + (1.0 - tmp_offset) * xsrc) + d2;
860 const int y =
static_cast<int>(tmp_offset * ydst + (1.0 - tmp_offset) * ysrc) + d2;
867 bool facing_north = (
872 if(!current_data.
auto_hflip) { facing_west =
false; }
873 if(!current_data.
auto_vflip) { facing_north =
true; }
875 int my_x = x + disp_zoom * (current_data.
x -
w / 2);
876 int my_y = y + disp_zoom * (current_data.
y -
h / 2);
892 const SDL_Rect r {my_x, my_y, int(
w * disp_zoom), int(
h * disp_zoom)};
896 result.insert(underlying_hex.
begin(), underlying_hex.
end());
925 if(!boost::logic::indeterminate(animation_val.
primary_frame)) {
929 if(!boost::logic::indeterminate(current_val.
primary_frame)) {
938 ? animation_val.
image
965 assert(engine_val.
halo.empty());
966 result.
halo = current_val.
halo.empty() ? animation_val.
halo : current_val.
halo;
968 assert(engine_val.
halo_x == 0);
981 assert(engine_val.
sound.empty());
984 assert(engine_val.
text.empty());
985 result.
text = current_val.
text.empty() ? animation_val.
text : current_val.
text;
1009 assert(engine_val.
offset == 0);
1011 if(result.
offset == -1000) {
1021 assert(engine_val.
x == 0);
1022 result.
x = current_val.
x ? current_val.
x : animation_val.
x;
1025 result.
y = current_val.
y?current_val.
y:animation_val.
y;
1026 result.
y += engine_val.
y;
1042 if(!boost::logic::indeterminate(animation_val.
auto_hflip)) {
1046 if(!boost::logic::indeterminate(current_val.
auto_hflip)) {
1050 if(boost::logic::indeterminate(result.
auto_hflip)) {
1056 if(!boost::logic::indeterminate(animation_val.
auto_vflip)) {
1060 if(!boost::logic::indeterminate(current_val.
auto_vflip)) {
1064 if(boost::logic::indeterminate(result.
auto_vflip)) {
Variant for storing WML attributes.
A config object defines a single node in a WML file, with access to child nodes.
bool has_attribute(config_key_type key) const
const attribute_value * get(config_key_type key) const
Returns a pointer to the attribute with the given key or nullptr if it does not exist.
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
point get_location(const map_location &loc) const
Functions to get the on-screen positions of hexes.
static int hex_size()
Function which returns the size of a hex in pixels (from top tip to bottom tip or left edge to right ...
static double get_zoom_factor()
Returns the current zoom factor.
static submerge_data get_submerge_data(const rect &dest, double submerge, const point &size, uint8_t alpha, bool hreverse, bool vreverse)
void drawing_buffer_add(const drawing_layer layer, const map_location &loc, decltype(draw_helper::do_draw) draw_func)
Add an item to the drawing buffer.
const rect_of_hexes hexes_under_rect(const rect &r) const
Return the rectangular area of hexes overlapped by r (r is in screen coordinates)
rect map_area() const
Returns the area used for the map.
static display * get_singleton()
Returns the display object if a display object exists.
static rect scaled_to_zoom(const SDL_Rect &r)
Scale the width and height of a rect by the current zoom factor.
Easily build frame parameters with the serialized constructors.
utils::optional< color_t > blend_with_
std::string image_diagonal_
boost::tribool auto_vflip_
boost::tribool primary_frame_
frame_builder & auto_hflip(const bool auto_hflip)
frame_builder & highlight(const std::string &highlight)
frame_builder & image_diagonal(const std::string &image_diagonal, const std::string &image_mod="")
frame_builder & directional_x(const std::string &directional_x)
frame_builder & submerge(const std::string &submerge)
frame_builder & y(const std::string &y)
frame_builder & primary_frame(const bool primary_frame)
frame_builder & auto_vflip(const bool auto_vflip)
std::string highlight_ratio_
boost::tribool auto_hflip_
std::string drawing_layer_
frame_builder & drawing_layer(const std::string &drawing_layer)
std::string directional_x_
std::string directional_y_
frame_builder & text(const std::string &text, const color_t text_color)
frame_builder & blend(const std::string &blend_ratio, const color_t blend_color)
frame_builder & x(const std::string &x)
utils::optional< color_t > text_color_
frame_builder & offset(const std::string &offset)
frame_builder & directional_y(const std::string &directional_y)
frame_builder & image(const std::string &image, const std::string &image_mod="")
frame_builder & sound(const std::string &sound)
frame_builder & duration(const std::chrono::milliseconds &duration)
Allow easy chained modifications.
frame_builder & halo(const std::string &halo, const std::string &halo_x, const std::string &halo_y, const std::string &halo_mod)
std::chrono::milliseconds duration_
void override(const std::chrono::milliseconds &duration, const std::string &highlight="", const std::string &blend_ratio="", color_t blend_color={0, 0, 0}, const std::string &offset="", const std::string &layer="", const std::string &modifiers="")
progressive_int directional_x_
boost::tribool auto_hflip_
boost::tribool primary_frame_
progressive_double blend_ratio_
progressive_double highlight_ratio_
progressive_double offset_
boost::tribool auto_vflip_
frame_parameters parameters(const std::chrono::milliseconds ¤t_time) const
Getters for the different parameters.
utils::optional< color_t > blend_with_
std::chrono::milliseconds duration_
progressive_double submerge_
progressive_int drawing_layer_
utils::optional< color_t > text_color_
const std::chrono::milliseconds & duration() const
std::vector< std::string > debug_strings() const
Contents of frame in strings.
progressive_int directional_y_
progressive_image image_diagonal_
frame_parsed_parameters(const frame_builder &builder=frame_builder(), const std::chrono::milliseconds &override_duration=std::chrono::milliseconds{0})
bool does_not_change() const
static game_display * get_singleton()
void float_label(const map_location &loc, const std::string &text, const color_t &color)
Function to float a label above a tile.
handle add(int x, int y, const std::string &image, const map_location &loc, halo::ORIENTATION orientation=NORMAL, bool infinite=true)
Add a haloing effect using 'image centered on (x,y).
Generic locator abstracting the location of an image.
bool is_void() const
Returns true if the locator does not correspond to an actual image.
const std::string & get_filename() const
const std::string & get_modifications() const
locator clone(const std::string &mods) const
Returns a copy of this locator with the given IPF.
std::string get_original() const
virtual bool does_not_change() const
std::chrono::milliseconds duration() const
virtual const T get_current_element(const std::chrono::milliseconds ¤t_time, T default_val=T()) const override
bool does_not_change() const override
virtual const T get_current_element(const std::chrono::milliseconds ¤t_time, T default_val=T()) const override
Wrapper class to encapsulate creation and management of an SDL_Texture.
void set_blend_mode(SDL_BlendMode)
Blend mode.
void set_src(const rect &r)
Set the source region of the texture used for drawing operations.
void set_alpha_mod(uint8_t alpha)
Alpha modifier.
void set_color_mod(uint8_t r, uint8_t g, uint8_t b)
Colour modifier.
void redraw(const std::chrono::milliseconds &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
std::set< map_location > get_overlaped_hex(const std::chrono::milliseconds &frame_time, const map_location &src, const map_location &dst, const frame_parameters &animation_val, const frame_parameters &engine_val) const
frame_parameters merge_parameters(const std::chrono::milliseconds ¤t_time, const frame_parameters &animation_val, const frame_parameters &engine_val=frame_parameters()) const
This function merges the value provided by:
frame_parsed_parameters builder_
constexpr uint8_t float_to_color(double n)
Convert a double in the range [0.0,1.0] to an 8-bit colour value.
Drawing functions, for drawing things on the screen.
@ unit_default
Default layer for drawing units.
@ unit_first
Reserve layers to be selected for wml.
static lg::log_domain log_engine("engine")
Frame for unit's animation sequence.
constexpr int get_abs_frame_layer(drawing_layer layer)
progressive_pair< double > progressive_double
progressive_single< image::locator > progressive_image
progressive_single< std::string > progressive_string
progressive_pair< int > progressive_int
Standard logging facilities (interface).
void flipped(const texture &tex, const SDL_Rect &dst, bool flip_h=true, bool flip_v=false)
Draws a texture, or part of a texture, at the given location, also mirroring/flipping the texture hor...
void smooth_shaded(const texture &tex, const SDL_Rect &dst, const SDL_Color &cTL, const SDL_Color &cTR, const SDL_Color &cBL, const SDL_Color &cBR, const SDL_FPoint &uvTL, const SDL_FPoint &uvTR, const SDL_FPoint &uvBL, const SDL_FPoint &uvBR)
Draw a texture with smoothly varying colour and alpha modification, specified at the four corners of ...
std::shared_ptr< halo_record > handle
Functions to load and save images from/to disk.
texture get_texture(const image::locator &i_locator, TYPE type, bool skip_cache)
Returns an image texture suitable for hardware-accelerated rendering.
point get_size(const locator &i_locator, bool skip_cache)
Returns the width and height of an image.
bool is_in_hex(const locator &i_locator)
Checks if an image fits into a single hex.
Audio output for sound and music.
void play_sound(const std::string &files, channel_group group, unsigned int repeats)
std::string half_signed_value(int val)
Sign with Unicode "−" if negative.
std::string bool_string(const bool value)
Converts a bool value to 'true' or 'false'.
rect dst
Location on the final composed sheet.
rect src
Non-transparent portion of the surface to compose.
The basic class for representing 8-bit RGB or RGBA colour values.
static color_t from_rgb_string(std::string_view c)
Creates a new opaque color_t object from a string variable in "R,G,B" format.
Rectangular area of hexes, allowing to decide how the top and bottom edges handles the vertical shift...
All parameters from a frame at a given instant.
utils::optional< color_t > blend_with
boost::tribool auto_hflip
image::locator image_diagonal
boost::tribool primary_frame
std::chrono::milliseconds duration
utils::optional< color_t > text_color
boost::tribool auto_vflip
Encapsulates the map of the game.
direction
Valid directions which can be moved in our hexagonal world.
An abstract description of a rectangle with integer coordinates.
bool overlaps(const SDL_Rect &r) const
Whether the given rectangle and this rectangle overlap.
static map_location::direction s