23 #define ERR_NG LOG_STREAM(err, log_engine) 30 , highlight_ratio(1.0)
37 , auto_vflip(
boost::logic::indeterminate)
38 , auto_hflip(
boost::logic::indeterminate)
39 , primary_frame(
boost::logic::indeterminate)
40 , drawing_layer(
display::LAYER_UNIT_DEFAULT -
display::LAYER_UNIT_FIRST)
45 , auto_vflip_(
boost::logic::indeterminate)
46 , auto_hflip_(
boost::logic::indeterminate)
47 , primary_frame_(
boost::logic::indeterminate)
48 , drawing_layer_(
std::to_string(
display::LAYER_UNIT_DEFAULT -
display::LAYER_UNIT_FIRST))
53 ,
image_(cfg[frame_string +
"image"])
56 ,
halo_(cfg[frame_string +
"halo"])
57 ,
halo_x_(cfg[frame_string +
"halo_x"])
58 ,
halo_y_(cfg[frame_string +
"halo_y"])
59 ,
halo_mod_(cfg[frame_string +
"halo_mod"])
60 ,
sound_(cfg[frame_string +
"sound"])
61 ,
text_(cfg[frame_string +
"text"])
64 ,
offset_(cfg[frame_string +
"offset"])
65 ,
submerge_(cfg[frame_string +
"submerge"])
66 ,
x_(cfg[frame_string +
"x"])
67 ,
y_(cfg[frame_string +
"y"])
76 auto_vflip_ = cfg[frame_string +
"auto_vflip"].to_bool();
80 auto_hflip_ = cfg[frame_string +
"auto_hflip"].to_bool();
87 const auto& text_color_key = cfg[frame_string +
"text_color"];
88 if(!text_color_key.empty()) {
91 }
catch(
const std::invalid_argument&
e) {
93 ERR_NG <<
"Invalid RBG text color in unit animation: " << text_color_key.str()
94 <<
"\n" << e.what() <<
"\n;";
100 }
else if(!cfg.
get(frame_string +
"end")) {
105 duration(std::max(std::max(image_duration, image_diagonal_duration), halo_duration));
107 duration(cfg[frame_string +
"end"].to_int() - cfg[frame_string +
"begin"].to_int());
112 const auto& blend_color_key = cfg[frame_string +
"blend_color"];
113 if(!blend_color_key.empty()) {
116 }
catch(
const std::invalid_argument&
e) {
118 ERR_NG <<
"Invalid RBG blend color in unit animation: " << blend_color_key.str()
119 <<
"\n" << e.what() <<
"\n;";
321 const std::string& highlight,
322 const std::string& blend_ratio,
324 const std::string& offset,
325 const std::string& layer,
326 const std::string& modifiers)
328 if(!highlight.empty()) {
334 if(!offset.empty()) {
340 if(!blend_ratio.empty()) {
353 if(!modifiers.empty()) {
374 std::vector<std::string> v;
409 v.emplace_back(
"sound=" +
sound_);
413 v.emplace_back(
"text=" +
text_);
416 v.emplace_back(
"text_color=" +
text_color_->to_rgba_string());
424 v.emplace_back(
"blend_with=" +
blend_with_->to_rgba_string());
488 const frame_parameters current_data = merge_parameters(frame_time,animation_val,engine_val);
489 double tmp_offset = current_data.
offset;
498 if(!current_data.
sound.empty() ) {
523 const int x =
static_cast<int>(tmp_offset * xdst + (1.0 - tmp_offset) * xsrc) + d2;
524 const int y =
static_cast<int>(tmp_offset * ydst + (1.0 - tmp_offset) * ysrc) + d2;
527 if(image !=
nullptr) {
532 bool facing_north = (
537 if(!current_data.
auto_hflip) { facing_west =
false; }
538 if(!current_data.
auto_vflip) { facing_north =
true; }
540 int my_x = x + current_data.
x * disp_zoom - image->w / 2;
541 int my_y = y + current_data.
y * disp_zoom - image->h / 2;
557 src, image, facing_west,
false,
564 if(!in_scope_of_frame) {
569 if(current_data.
halo.empty()) {
605 halo_id = halo_man.
add(
606 static_cast<int>(x + current_data.
halo_x * disp_zoom),
607 static_cast<int>(y + current_data.
halo_y * disp_zoom),
613 halo_id = halo_man.
add(
614 static_cast<int>(x - current_data.
halo_x * disp_zoom),
615 static_cast<int>(y + current_data.
halo_y * disp_zoom),
634 const frame_parameters current_data = merge_parameters(frame_time, animation_val, engine_val);
636 double tmp_offset = current_data.
offset;
650 std::set<map_location> result;
654 bool facing_north = (
659 if(!current_data.
auto_vflip) { facing_north =
true; }
661 int my_y = current_data.
y;
672 }
else if(my_y > 0) {
686 if(image !=
nullptr) {
692 if(w != 0 ||
h != 0) {
693 const int x =
static_cast<int>(tmp_offset * xdst + (1.0 - tmp_offset) * xsrc);
694 const int y =
static_cast<int>(tmp_offset * ydst + (1.0 - tmp_offset) * ysrc);
700 bool facing_north = (
705 if(!current_data.
auto_vflip) { facing_north =
true; }
706 if(!current_data.
auto_hflip) { facing_west =
false; }
708 int my_x = x + current_data.
x + d2 - w / 2;
709 int my_y = y + current_data.
y + d2 -
h / 2;
725 const SDL_Rect r {my_x, my_y,
w,
h};
729 result.insert(underlying_hex.
begin(), underlying_hex.
end());
757 if(!boost::logic::indeterminate(animation_val.
primary_frame)) {
761 if(!boost::logic::indeterminate(current_val.
primary_frame)) {
770 ? animation_val.
image 797 assert(engine_val.
halo.empty());
798 result.
halo = current_val.
halo.empty() ? animation_val.
halo : current_val.
halo;
800 assert(engine_val.
halo_x == 0);
813 assert(engine_val.
sound.empty());
816 assert(engine_val.
text.empty());
817 result.
text = current_val.
text.empty() ? animation_val.
text : current_val.
text;
841 assert(engine_val.
offset == 0);
843 if(result.
offset == -1000) {
853 assert(engine_val.
x == 0);
854 result.
x = current_val.
x ? current_val.
x : animation_val.
x;
857 result.
y = current_val.
y?current_val.
y:animation_val.
y;
858 result.
y += engine_val.
y;
874 if(!boost::logic::indeterminate(animation_val.
auto_hflip)) {
878 if(!boost::logic::indeterminate(current_val.
auto_hflip)) {
882 if(boost::logic::indeterminate(result.
auto_hflip)) {
888 if(!boost::logic::indeterminate(animation_val.
auto_vflip)) {
892 if(!boost::logic::indeterminate(current_val.
auto_vflip)) {
896 if(boost::logic::indeterminate(result.
auto_vflip)) {
const frame_parameters parameters(int current_time) const
Getters for the different parameters.
virtual bool does_not_change() const
surface get_image(const image::locator &i_locator, TYPE type)
Caches and returns an image.
virtual const T get_current_element(int current_time, T default_val=T()) const override
Reserve layers to be selected for WML.
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_builder & y(const std::string &y)
boost::tribool auto_hflip_
All parameters from a frame at a given instant.
boost::tribool auto_hflip
static display * get_singleton()
Returns the display object if a display object exists.
progressive_single< image::locator > progressive_image
progressive_double blend_ratio_
frame_parsed_parameters(const frame_builder &builder=frame_builder(), int override_duration=0)
frame_builder & blend(const std::string &blend_ratio, const color_t blend_color)
DIRECTION get_relative_dir(const map_location &loc, map_location::RELATIVE_DIR_MODE mode) const
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 ...
std::optional< color_t > blend_with
Variant for storing WML attributes.
std::string directional_y_
static double get_zoom_factor()
Returns the current zoom factor.
bool has_attribute(config_key_type key) const
Frame for unit's animation sequence.
void render_image(int x, int y, const display::drawing_layer drawing_layer, const map_location &loc, surface image, bool hreverse=false, bool greyscale=false, fixed_t alpha=ftofxp(1.0), color_t blendto={0, 0, 0}, double blend_ratio=0, double submerged=0.0, bool vreverse=false)
Draw an image at a certain location.
frame_builder & drawing_layer(const std::string &drawing_layer)
frame_builder & image_diagonal(const std::string &image_diagonal, const std::string &image_mod="")
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.
std::string drawing_layer_
std::string get_original() const
Audio output for sound and music.
Rectangular area of hexes, allowing to decide how the top and bottom edges handles the vertical shift...
frame_builder & directional_x(const std::string &directional_x)
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="")
frame_builder & image(const std::string &image, const std::string &image_mod="")
image::locator image_diagonal
boost::tribool primary_frame_
void play_sound(const std::string &files, channel_group group, unsigned int repeats)
map_location get_direction(DIRECTION dir, unsigned int n=1u) const
frame_builder & submerge(const std::string &submerge)
bool does_not_change() const override
virtual const T get_current_element(int current_time, T default_val=T()) const override
frame_builder & auto_hflip(const bool auto_hflip)
std::string half_signed_value(int val)
Sign with Unicode "−" if negative.
std::optional< color_t > blend_with_
frame_builder & sound(const std::string &sound)
progressive_image image_diagonal_
std::string highlight_ratio_
boost::tribool primary_frame_
frame_builder & auto_vflip(const bool auto_vflip)
progressive_double highlight_ratio_
progressive_pair< int > progressive_int
std::optional< color_t > text_color
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) ...
std::string directional_x_
Generic locator abstracting the location of an image.
progressive_int drawing_layer_
std::vector< std::string > debug_strings() const
Contents of frame in strings.
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).
#define ftofxp(x)
IN: float or int - OUT: fixed_t.
Image rescaled according to the zoom settings.
progressive_int directional_x_
Encapsulates the map of the game.
void float_label(const map_location &loc, const std::string &text, const color_t &color)
Function to float a label above a tile.
std::optional< color_t > text_color_
progressive_single< std::string > progressive_string
std::optional< color_t > text_color_
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
static lg::log_domain log_engine("engine")
default layer for drawing units
int get_location_y(const map_location &loc) const
std::string bool_string(const bool value)
Converts a bool value to 'true' or 'false'.
frame_builder & offset(const std::string &offset)
frame_builder & x(const std::string &x)
DIRECTION
Valid directions which can be moved in our hexagonal world.
boost::tribool auto_vflip
const std::string & get_filename() const
frame_builder & primary_frame(const bool primary_frame)
bool is_in_hex(const locator &i_locator)
Checks if an image fits into a single hex.
frame_builder & directional_y(const std::string &directional_y)
progressive_double submerge_
int get_location_x(const map_location &loc) const
Functions to get the on-screen positions of hexes.
progressive_int directional_y_
std::optional< color_t > blend_with_
boost::tribool auto_vflip_
Functions to load and save images from/to disk.
Standard logging facilities (interface).
frame_builder & duration(const int duration)
Allow easy chained modifications.
std::string image_diagonal_
boost::tribool auto_hflip_
progressive_double offset_
frame_builder & highlight(const std::string &highlight)
bool is_void() const
Returns true if the locator does not correspond to an actual image.
A config object defines a single node in a WML file, with access to child nodes.
std::shared_ptr< halo_record > handle
boost::tribool primary_frame
frame_builder & text(const std::string &text, const color_t text_color)
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.
bool does_not_change() const
frame_builder & halo(const std::string &halo, const std::string &halo_x, const std::string &halo_y, const std::string &halo_mod)
const 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:
progressive_pair< double > progressive_double
static game_display * get_singleton()
boost::tribool auto_vflip_