25 #define ERR_NG LOG_STREAM(err, log_engine)
32 , highlight_ratio(1.0)
39 , auto_vflip(
boost::logic::indeterminate)
40 , auto_hflip(
boost::logic::indeterminate)
41 , primary_frame(
boost::logic::indeterminate)
42 , drawing_layer(
display::LAYER_UNIT_DEFAULT -
display::LAYER_UNIT_FIRST)
47 , auto_vflip_(
boost::logic::indeterminate)
48 , auto_hflip_(
boost::logic::indeterminate)
49 , primary_frame_(
boost::logic::indeterminate)
50 , drawing_layer_(std::to_string(
display::LAYER_UNIT_DEFAULT -
display::LAYER_UNIT_FIRST))
55 , image_(cfg[frame_string +
"image"])
56 , image_diagonal_(cfg[frame_string +
"image_diagonal"])
57 , image_mod_(cfg[frame_string +
"image_mod"])
58 , halo_(cfg[frame_string +
"halo"])
59 , halo_x_(cfg[frame_string +
"halo_x"])
60 , halo_y_(cfg[frame_string +
"halo_y"])
61 , halo_mod_(cfg[frame_string +
"halo_mod"])
62 , sound_(cfg[frame_string +
"sound"])
63 , text_(cfg[frame_string +
"text"])
64 , blend_ratio_(cfg[frame_string +
"blend_ratio"])
65 , highlight_ratio_(cfg[frame_string +
"alpha"])
66 , offset_(cfg[frame_string +
"offset"])
67 , submerge_(cfg[frame_string +
"submerge"])
68 , x_(cfg[frame_string +
"x"])
69 , y_(cfg[frame_string +
"y"])
70 , directional_x_(cfg[frame_string +
"directional_x"])
71 , directional_y_(cfg[frame_string +
"directional_y"])
72 , auto_vflip_(
boost::logic::indeterminate)
73 , auto_hflip_(
boost::logic::indeterminate)
74 , primary_frame_(
boost::logic::indeterminate)
75 , drawing_layer_(cfg[frame_string +
"layer"])
78 auto_vflip_ = cfg[frame_string +
"auto_vflip"].to_bool();
82 auto_hflip_ = cfg[frame_string +
"auto_hflip"].to_bool();
89 const auto& text_color_key = cfg[frame_string +
"text_color"];
90 if(!text_color_key.empty()) {
93 }
catch(
const std::invalid_argument&
e) {
95 ERR_NG <<
"Invalid RBG text color in unit animation: " << text_color_key.str()
102 }
else if(!cfg.
get(frame_string +
"end")) {
107 duration(std::max(std::max(image_duration, image_diagonal_duration), halo_duration));
109 duration(cfg[frame_string +
"end"].to_int() - cfg[frame_string +
"begin"].to_int());
114 const auto& blend_color_key = cfg[frame_string +
"blend_color"];
115 if(!blend_color_key.empty()) {
118 }
catch(
const std::invalid_argument&
e) {
120 ERR_NG <<
"Invalid RBG blend color in unit animation: " << blend_color_key.str()
242 : duration_(duration ? duration : builder.duration_)
243 , image_(builder.image_,duration_)
244 , image_diagonal_(builder.image_diagonal_,duration_)
245 , image_mod_(builder.image_mod_)
246 , halo_(builder.halo_,duration_)
247 , halo_x_(builder.halo_x_,duration_)
248 , halo_y_(builder.halo_y_,duration_)
249 , halo_mod_(builder.halo_mod_)
250 , sound_(builder.sound_)
251 , text_(builder.text_)
252 , text_color_(builder.text_color_)
253 , blend_with_(builder.blend_with_)
254 , blend_ratio_(builder.blend_ratio_,duration_)
255 , highlight_ratio_(builder.highlight_ratio_,duration_)
256 , offset_(builder.offset_,duration_)
257 , submerge_(builder.submerge_,duration_)
258 , x_(builder.x_,duration_)
259 , y_(builder.y_,duration_)
260 , directional_x_(builder.directional_x_,duration_)
261 , directional_y_(builder.directional_y_,duration_)
262 , auto_vflip_(builder.auto_vflip_)
263 , auto_hflip_(builder.auto_hflip_)
264 , primary_frame_(builder.primary_frame_)
265 , drawing_layer_(builder.drawing_layer_,duration_)
323 const std::string& highlight,
324 const std::string& blend_ratio,
326 const std::string& offset,
327 const std::string& layer,
328 const std::string& modifiers)
330 if(!highlight.empty()) {
336 if(!offset.empty()) {
342 if(!blend_ratio.empty()) {
355 if(!modifiers.empty()) {
376 std::vector<std::string> v;
411 v.emplace_back(
"sound=" +
sound_);
415 v.emplace_back(
"text=" +
text_);
418 v.emplace_back(
"text_color=" +
text_color_->to_rgba_string());
426 v.emplace_back(
"blend_with=" +
blend_with_->to_rgba_string());
479 void render_unit_image(
495 if(!image_size.x || !image_size.y) {
507 std::string new_modifications;
510 new_modifications +=
"~GS()";
516 if(!new_modifications.empty()) {
523 blend_ratio = std::clamp(blend_ratio, 0.0, 1.0);
540 if(blend_ratio > 0.0) {
546 +
"~CHAN(255, 255, 255, alpha)"
583 double tmp_offset = current_data.
offset;
592 if(!current_data.
sound.empty() ) {
610 point image_size {0, 0};
617 const int x =
static_cast<int>(tmp_offset * xdst + (1.0 - tmp_offset) * xsrc) + d2;
618 const int y =
static_cast<int>(tmp_offset * ydst + (1.0 - tmp_offset) * ysrc) + d2;
621 if(image_size.x && image_size.y) {
626 bool facing_north = (
631 if(!current_data.
auto_hflip) { facing_west =
false; }
632 if(!current_data.
auto_vflip) { facing_north =
true; }
634 int my_x = x + disp_zoom * (current_data.
x - image_size.x / 2);
635 int my_y = y + disp_zoom * (current_data.
y - image_size.y / 2);
661 render_unit_image(my_x, my_y,
679 if(!in_scope_of_frame) {
684 if(current_data.
halo.empty()) {
720 halo_id = halo_man.
add(
721 static_cast<int>(x + current_data.
halo_x * disp_zoom),
722 static_cast<int>(y + current_data.
halo_y * disp_zoom),
728 halo_id = halo_man.
add(
729 static_cast<int>(x - current_data.
halo_x * disp_zoom),
730 static_cast<int>(y + current_data.
halo_y * disp_zoom),
751 double tmp_offset = current_data.
offset;
765 std::set<map_location> result;
769 bool facing_north = (
774 if(!current_data.
auto_vflip) { facing_north =
true; }
776 int my_y = current_data.
y;
787 }
else if(my_y > 0) {
801 if(
w != 0 ||
h != 0) {
803 const int x =
static_cast<int>(tmp_offset * xdst + (1.0 - tmp_offset) * xsrc) + d2;
804 const int y =
static_cast<int>(tmp_offset * ydst + (1.0 - tmp_offset) * ysrc) + d2;
811 bool facing_north = (
816 if(!current_data.
auto_hflip) { facing_west =
false; }
817 if(!current_data.
auto_vflip) { facing_north =
true; }
819 int my_x = x + disp_zoom * (current_data.
x -
w / 2);
820 int my_y = y + disp_zoom * (current_data.
y -
h / 2);
836 const SDL_Rect r {my_x, my_y, int(
w * disp_zoom), int(
h * disp_zoom)};
840 result.insert(underlying_hex.
begin(), underlying_hex.
end());
868 if(!boost::logic::indeterminate(animation_val.
primary_frame)) {
872 if(!boost::logic::indeterminate(current_val.
primary_frame)) {
881 ? animation_val.
image
908 assert(engine_val.
halo.empty());
909 result.
halo = current_val.
halo.empty() ? animation_val.
halo : current_val.
halo;
911 assert(engine_val.
halo_x == 0);
924 assert(engine_val.
sound.empty());
927 assert(engine_val.
text.empty());
928 result.
text = current_val.
text.empty() ? animation_val.
text : current_val.
text;
952 assert(engine_val.
offset == 0);
954 if(result.
offset == -1000) {
964 assert(engine_val.
x == 0);
965 result.
x = current_val.
x ? current_val.
x : animation_val.
x;
968 result.
y = current_val.
y?current_val.
y:animation_val.
y;
969 result.
y += engine_val.
y;
985 if(!boost::logic::indeterminate(animation_val.
auto_hflip)) {
989 if(!boost::logic::indeterminate(current_val.
auto_hflip)) {
993 if(boost::logic::indeterminate(result.
auto_hflip)) {
999 if(!boost::logic::indeterminate(animation_val.
auto_vflip)) {
1003 if(!boost::logic::indeterminate(current_val.
auto_vflip)) {
1007 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.
static void add_submerge_ipf_mod(std::string &image_path, int image_height, double submersion_amount, int shift=0)
drawing_layer
The layers to render something on.
@ LAYER_UNIT_FIRST
Reserve layers to be selected for WML.
@ LAYER_UNIT_DEFAULT
default layer for drawing units
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 ...
int get_location_x(const map_location &loc) const
Functions to get the on-screen positions of hexes.
static double get_zoom_factor()
Returns the current zoom factor.
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 SDL_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.
int get_location_y(const map_location &loc) const
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.
std::string image_diagonal_
boost::tribool auto_vflip_
boost::tribool primary_frame_
frame_builder & duration(const int duration)
Allow easy chained modifications.
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)
std::optional< color_t > blend_with_
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::optional< color_t > text_color_
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)
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 & halo(const std::string &halo, const std::string &halo_x, const std::string &halo_y, const std::string &halo_mod)
std::optional< color_t > blend_with_
std::optional< color_t > text_color_
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_
const frame_parameters parameters(int current_time) const
Getters for the different parameters.
void override(int 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_double submerge_
progressive_int drawing_layer_
std::vector< std::string > debug_strings() const
Contents of frame in strings.
progressive_int directional_y_
progressive_image image_diagonal_
bool does_not_change() const
frame_parsed_parameters(const frame_builder &builder=frame_builder(), int override_duration=0)
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
virtual const T get_current_element(int current_time, T default_val=T()) const override
bool does_not_change() const override
virtual const T get_current_element(int current_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_alpha_mod(uint8_t alpha)
Alpha modifier.
void set_color_mod(uint8_t r, uint8_t g, uint8_t b)
Colour modifier.
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:
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
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
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.
static lg::log_domain log_engine("engine")
Frame for unit's animation sequence.
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...
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'.
The basic class for representing 8-bit RGB or RGBA colour values.
static color_t from_rgb_string(const std::string &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.
boost::tribool auto_hflip
image::locator image_diagonal
boost::tribool primary_frame
std::optional< color_t > text_color
std::optional< color_t > blend_with
boost::tribool auto_vflip
Encapsulates the map of the game.
DIRECTION
Valid directions which can be moved in our hexagonal world.
map_location get_direction(DIRECTION dir, unsigned int n=1u) const
DIRECTION get_relative_dir(const map_location &loc, map_location::RELATIVE_DIR_MODE mode) const
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