Split drawing_layer into its own file, make scoped enum

This commit is contained in:
Charles Dang 2024-08-08 01:11:10 -04:00
parent 8bebc86b6a
commit d762bea734
17 changed files with 166 additions and 115 deletions

View file

@ -30,7 +30,7 @@ static lg::log_domain log_arrows("arrows");
#define DBG_ARR LOG_STREAM(debug, log_arrows)
arrow::arrow(bool hidden)
: layer_(display::LAYER_ARROWS)
: layer_(drawing_layer::arrows)
, color_("red")
, style_(STYLE_STANDARD)
, path_()

View file

@ -91,7 +91,7 @@ protected:
*/
virtual void update_symbols();
display::drawing_layer layer_;
drawing_layer layer_;
std::string color_;
/** represents the subdirectory that holds images for this arrow style */

View file

@ -1220,10 +1220,10 @@ void display::get_terrain_images(const map_location& loc, const std::string& tim
namespace
{
constexpr std::array layer_groups {
display::LAYER_TERRAIN_BG,
display::LAYER_UNIT_FIRST,
display::LAYER_UNIT_MOVE_DEFAULT,
display::LAYER_REACHMAP // Make sure the movement doesn't show above fog and reachmap.
drawing_layer::terrain_bg,
drawing_layer::unit_first,
drawing_layer::unit_move_default,
drawing_layer::reachmap // Make sure the movement doesn't show above fog and reachmap.
};
enum {
@ -1257,7 +1257,7 @@ enum {
SHIFT_LAYER_GROUP = BITS_FOR_Y + SHIFT_Y
};
uint32_t generate_hex_key(const display::drawing_layer layer, const map_location& loc)
uint32_t generate_hex_key(const drawing_layer layer, const map_location& loc)
{
// Start with the index of last group entry...
uint32_t group_i = layer_groups.size() - 1;
@ -2685,7 +2685,7 @@ void display::draw_hex(const map_location& loc)
get_terrain_images(loc, tod.id, BACKGROUND); // updates terrain_image_vector_
num_images_bg = terrain_image_vector_.size();
drawing_buffer_add(LAYER_TERRAIN_BG, loc, [images = std::exchange(terrain_image_vector_, {})](const rect& dest) {
drawing_buffer_add(drawing_layer::terrain_bg, loc, [images = std::exchange(terrain_image_vector_, {})](const rect& dest) {
for(const texture& t : images) {
draw::blit(t, dest);
}
@ -2694,7 +2694,7 @@ void display::draw_hex(const map_location& loc)
get_terrain_images(loc, tod.id, FOREGROUND); // updates terrain_image_vector_
num_images_fg = terrain_image_vector_.size();
drawing_buffer_add(LAYER_TERRAIN_FG, loc, [images = std::exchange(terrain_image_vector_, {})](const rect& dest) {
drawing_buffer_add(drawing_layer::terrain_fg, loc, [images = std::exchange(terrain_image_vector_, {})](const rect& dest) {
for(const texture& t : images) {
draw::blit(t, dest);
}
@ -2705,10 +2705,10 @@ void display::draw_hex(const map_location& loc)
static const image::locator grid_top{game_config::images::grid_top};
static const image::locator grid_bottom{game_config::images::grid_bottom};
drawing_buffer_add(LAYER_GRID_TOP, loc,
drawing_buffer_add(drawing_layer::grid_top, loc,
[tex = image::get_texture(grid_top, image::TOD_COLORED)](const rect& dest) { draw::blit(tex, dest); });
drawing_buffer_add(LAYER_GRID_BOTTOM, loc,
drawing_buffer_add(drawing_layer::grid_bottom, loc,
[tex = image::get_texture(grid_bottom, image::TOD_COLORED)](const rect& dest) { draw::blit(tex, dest); });
}
}
@ -2741,7 +2741,7 @@ void display::draw_hex(const map_location& loc)
? image::get_lighted_texture(ipf, lt)
: image::get_texture(ipf, image::HEXED);
drawing_buffer_add(LAYER_TERRAIN_BG, loc, [=](const rect& dest) mutable {
drawing_buffer_add(drawing_layer::terrain_bg, loc, [=](const rect& dest) mutable {
// Adjust submerge appropriately
const t_translation::terrain_code terrain = get_map().get_terrain(loc);
const terrain_type& terrain_info = get_map().get_terrain_info(terrain);
@ -2767,14 +2767,14 @@ void display::draw_hex(const map_location& loc)
// village-control flags.
if(!is_shrouded) {
drawing_buffer_add(LAYER_TERRAIN_BG, loc, [tex = get_flag(loc)](const rect& dest) { draw::blit(tex, dest); });
drawing_buffer_add(drawing_layer::terrain_bg, loc, [tex = get_flag(loc)](const rect& dest) { draw::blit(tex, dest); });
}
// Draw the time-of-day mask on top of the terrain in the hex.
// tod may differ from tod if hex is illuminated.
const std::string& tod_hex_mask = tod.image_mask;
if(tod_hex_mask1 || tod_hex_mask2) {
drawing_buffer_add(LAYER_TERRAIN_FG, loc, [=](const rect& dest) mutable {
drawing_buffer_add(drawing_layer::terrain_fg, loc, [=](const rect& dest) mutable {
tod_hex_mask1.set_alpha_mod(tod_hex_alpha1);
draw::blit(tod_hex_mask1, dest);
@ -2782,7 +2782,7 @@ void display::draw_hex(const map_location& loc)
draw::blit(tod_hex_mask2, dest);
});
} else if(!tod_hex_mask.empty()) {
drawing_buffer_add(LAYER_TERRAIN_FG, loc,
drawing_buffer_add(drawing_layer::terrain_fg, loc,
[tex = image::get_texture(tod_hex_mask, image::HEXED)](const rect& dest) { draw::blit(tex, dest); });
}
@ -2798,19 +2798,19 @@ void display::draw_hex(const map_location& loc)
if(is_shrouded) {
// We apply void also on off-map tiles to shroud the half-hexes too
drawing_buffer_add(LAYER_FOG_SHROUD, loc,
drawing_buffer_add(drawing_layer::fog_shroud, loc,
[tex = image::get_texture(get_variant(shroud_images_, loc), image::TOD_COLORED)](const rect& dest) {
draw::blit(tex, dest);
});
} else if(fogged(loc)) {
drawing_buffer_add(LAYER_FOG_SHROUD, loc,
drawing_buffer_add(drawing_layer::fog_shroud, loc,
[tex = image::get_texture(get_variant(fog_images_, loc), image::TOD_COLORED)](const rect& dest) {
draw::blit(tex, dest);
});
}
if(!is_shrouded) {
drawing_buffer_add(LAYER_FOG_SHROUD, loc, [images = get_fog_shroud_images(loc, image::TOD_COLORED)](const rect& dest) {
drawing_buffer_add(drawing_layer::fog_shroud, loc, [images = get_fog_shroud_images(loc, image::TOD_COLORED)](const rect& dest) {
for(const texture& t : images) {
draw::blit(t, dest);
}
@ -2818,7 +2818,7 @@ void display::draw_hex(const map_location& loc)
}
if(debug_flag_set(DEBUG_FOREGROUND)) {
drawing_buffer_add(LAYER_UNIT_DEFAULT, loc,
drawing_buffer_add(drawing_layer::unit_default, loc,
[tex = image::get_texture(image::locator{"terrain/foreground.png"}, image::TOD_COLORED)](const rect& dest) {
draw::blit(tex, dest);
});
@ -2862,7 +2862,7 @@ void display::draw_hex(const map_location& loc)
renderer.set_maximum_height(-1, false);
renderer.set_maximum_width(-1);
drawing_buffer_add(LAYER_FOG_SHROUD, loc, [tex = renderer.render_and_get_texture()](const rect& dest) {
drawing_buffer_add(drawing_layer::fog_shroud, loc, [tex = renderer.render_and_get_texture()](const rect& dest) {
const rect text_dest {
(dest.x + dest.w / 2) - (tex.w() / 2),
(dest.y + dest.h / 2) - (tex.h() / 2),

View file

@ -48,6 +48,7 @@ namespace wb {
#include "animated.hpp"
#include "display_context.hpp"
#include "drawing_layer.hpp"
#include "font/standard_colors.hpp"
#include "game_config.hpp"
#include "gui/core/top_level_drawable.hpp"
@ -811,55 +812,6 @@ private:
std::vector<texture> terrain_image_vector_;
public:
/**
* The layers to render something on. This value should never be stored
* it's the internal drawing order and adding removing and reordering
* the layers should be safe.
* If needed in WML use the name and map that to the enum value.
*/
enum drawing_layer {
LAYER_TERRAIN_BG, /**<
* Layer for the terrain drawn behind the
* unit.
*/
LAYER_GRID_TOP, /**< Top half part of grid image */
LAYER_MOUSEOVER_OVERLAY, /**< Mouseover overlay used by editor*/
LAYER_FOOTSTEPS, /**< Footsteps showing path from unit to mouse */
LAYER_MOUSEOVER_TOP, /**< Top half of image following the mouse */
LAYER_UNIT_FIRST, /**< Reserve layers to be selected for WML. */
LAYER_UNIT_BG = LAYER_UNIT_FIRST+10, /**< Used for the ellipse behind the unit. */
LAYER_UNIT_DEFAULT=LAYER_UNIT_FIRST+40,/**<default layer for drawing units */
LAYER_TERRAIN_FG = LAYER_UNIT_FIRST+50, /**<
* Layer for the terrain drawn in front of
* the unit.
*/
LAYER_GRID_BOTTOM, /**<
* Used for the bottom half part of grid image.
* Should be under moving units, to avoid masking south move.
*/
LAYER_UNIT_MOVE_DEFAULT=LAYER_UNIT_FIRST+60/**<default layer for drawing moving units */,
LAYER_UNIT_FG = LAYER_UNIT_FIRST+80, /**<
* Used for the ellipse in front of the
* unit.
*/
LAYER_UNIT_MISSILE_DEFAULT = LAYER_UNIT_FIRST+90, /**< default layer for missile frames*/
LAYER_UNIT_LAST=LAYER_UNIT_FIRST+100,
LAYER_REACHMAP, /**< "black stripes" on unreachable hexes. */
LAYER_MOUSEOVER_BOTTOM, /**< Bottom half of image following the mouse */
LAYER_FOG_SHROUD, /**< Fog and shroud. */
LAYER_ARROWS, /**< Arrows from the arrows framework. Used for planned moves display. */
LAYER_ACTIONS_NUMBERING, /**< Move numbering for the whiteboard. */
LAYER_SELECTED_HEX, /**< Image on the selected unit */
LAYER_ATTACK_INDICATOR, /**< Layer which holds the attack indicator. */
LAYER_UNIT_BAR, /**<
* Unit bars and overlays are drawn on this
* layer (for testing here).
*/
LAYER_MOVE_INFO, /**< Movement info (defense%, etc...). */
LAYER_LINGER_OVERLAY, /**< The overlay used for the linger mode. */
LAYER_BORDER, /**< The border of the map. */
};
/**
* Draw text on a hex. (0.5, 0.5) is the center.
* The font size is adjusted to the zoom factor.

93
src/drawing_layer.hpp Normal file
View file

@ -0,0 +1,93 @@
/*
Copyright (C) 2003 - 2024
by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#pragma once
enum class drawing_layer {
/** Terrain drawn behind the unit */
terrain_bg,
/** Top half part of grid image */
grid_top,
/** Mouseover overlay used by editor */
mouseover_overlay,
/** Footsteps showing path from unit to mouse */
footsteps,
/** Top half of image following the mouse */
mouseover_top,
/** Reserve layers to be selected for wml. */
unit_first,
/** Ellipse behind the unit. */
unit_bg = unit_first + 10,
/** Default layer for drawing units */
unit_default = unit_first + 40,
/** Terrain drawn in front of the unit */
terrain_fg = unit_first + 50,
/** Bottom half part of grid image. Should be under moving units, to avoid masking south move */
grid_bottom,
/** Default layer for drawing moving units */
unit_move_default = unit_first + 60,
/** Ellipse in front of the unit */
unit_fg = unit_first + 80,
/** Default layer for missile frames */
unit_missile_default = unit_first + 90,
unit_last = unit_first + 100,
/** Overlay on unreachable hexes */
reachmap,
/** Bottom half of image following the mouse */
mouseover_bottom,
/** Fog and shroud. */
fog_shroud,
/** Arrows from the arrows framework. Used for planned moves display */
arrows,
/** Move numbering for the whiteboard */
actions_numbering,
/** Image on the selected unit */
selected_hex,
/** Layer which holds the attack indicator */
attack_indicator,
/** Unit bars and overlays are drawn on this layer (for testing here) */
unit_bar,
/** Movement info (defense%, etc...) */
move_info,
/** The overlay used for the linger mode */
linger_overlay,
/** The border of the map */
border,
};

View file

@ -78,7 +78,7 @@ void editor_display::draw_hex(const map_location& loc)
}
if(map().in_selection(loc)) {
drawing_buffer_add(LAYER_FOG_SHROUD, loc,
drawing_buffer_add(drawing_layer::fog_shroud, loc,
[tex = image::get_texture(image::locator{"editor/selection-overlay.png"}, image::TOD_COLORED)](const rect& d) {
draw::blit(tex, d);
});
@ -86,14 +86,14 @@ void editor_display::draw_hex(const map_location& loc)
if(brush_locations_.find(loc) != brush_locations_.end()) {
static const image::locator brush(game_config::images::editor_brush);
drawing_buffer_add(LAYER_SELECTED_HEX, loc, [tex = image::get_texture(brush, image::HEXED)](const rect& d) {
drawing_buffer_add(drawing_layer::selected_hex, loc, [tex = image::get_texture(brush, image::HEXED)](const rect& d) {
draw::blit(tex, d);
});
}
// Paint mouseover overlays
if(mouseover_hex_overlay_ && loc == mouseoverHex_) {
drawing_buffer_add(LAYER_MOUSEOVER_OVERLAY, loc, [this](const rect& dest) {
drawing_buffer_add(drawing_layer::mouseover_overlay, loc, [this](const rect& dest) {
mouseover_hex_overlay_.set_alpha_mod(196);
draw::blit(mouseover_hex_overlay_, dest);
mouseover_hex_overlay_.set_alpha_mod(SDL_ALPHA_OPAQUE);

View file

@ -239,10 +239,10 @@ void game_display::draw_hex(const map_location& loc)
}
if(on_map && loc == mouseoverHex_ && !map_screenshot_) {
drawing_layer hex_top_layer = LAYER_MOUSEOVER_BOTTOM;
drawing_layer hex_top_layer = drawing_layer::mouseover_bottom;
const unit* u = resources::gameboard->get_visible_unit(loc, dc_->teams()[viewing_team()]);
if(u != nullptr) {
hex_top_layer = LAYER_MOUSEOVER_TOP;
hex_top_layer = drawing_layer::mouseover_top;
}
const std::string* mo_top_path;
@ -265,7 +265,7 @@ void game_display::draw_hex(const map_location& loc)
drawing_buffer_add(hex_top_layer, loc,
[tex = image::get_texture(*mo_top_path, image::HEXED)](const rect& dest) { draw::blit(tex, dest); });
drawing_buffer_add(LAYER_MOUSEOVER_BOTTOM, loc,
drawing_buffer_add(drawing_layer::mouseover_bottom, loc,
[tex = image::get_texture(*mo_bot_path, image::HEXED)](const rect& dest) { draw::blit(tex, dest); });
}
@ -273,7 +273,7 @@ void game_display::draw_hex(const map_location& loc)
// We remove the reachability mask of the unit that we want to attack.
if(!is_shrouded && !reach_map_.empty() && reach_map_.find(loc) == reach_map_.end() && loc != attack_indicator_dst_) {
static const image::locator unreachable(game_config::images::unreachable);
drawing_buffer_add(LAYER_REACHMAP, loc,
drawing_buffer_add(drawing_layer::reachmap, loc,
[tex = image::get_texture(unreachable, image::HEXED)](const rect& dest) { draw::blit(tex, dest); });
}
@ -283,7 +283,7 @@ void game_display::draw_hex(const map_location& loc)
if(!(w->is_active() && w->has_temp_move())) {
std::vector<texture> footstepImages = footsteps_images(loc, route_, dc_);
if(!footstepImages.empty()) {
drawing_buffer_add(LAYER_FOOTSTEPS, loc, [images = std::move(footstepImages)](const rect& dest) {
drawing_buffer_add(drawing_layer::footsteps, loc, [images = std::move(footstepImages)](const rect& dest) {
for(const texture& t : images) {
draw::blit(t, dest);
}
@ -294,12 +294,12 @@ void game_display::draw_hex(const map_location& loc)
// Draw the attack direction indicator
if(on_map && loc == attack_indicator_src_) {
drawing_buffer_add(LAYER_ATTACK_INDICATOR, loc,
drawing_buffer_add(drawing_layer::attack_indicator, loc,
[tex = image::get_texture("misc/attack-indicator-src-" + attack_indicator_direction() + ".png", image::HEXED)](const rect& dest)
{ draw::blit(tex, dest); }
);
} else if(on_map && loc == attack_indicator_dst_) {
drawing_buffer_add(LAYER_ATTACK_INDICATOR, loc,
drawing_buffer_add(drawing_layer::attack_indicator, loc,
[tex = image::get_texture("misc/attack-indicator-dst-" + attack_indicator_direction() + ".png", image::HEXED)](const rect& dest)
{ draw::blit(tex, dest); }
);
@ -309,13 +309,13 @@ void game_display::draw_hex(const map_location& loc)
// so it's drawn over the shroud and fog.
if(mode_ != RUNNING) {
static const image::locator linger(game_config::images::linger);
drawing_buffer_add(LAYER_LINGER_OVERLAY, loc,
drawing_buffer_add(drawing_layer::linger_overlay, loc,
[tex = image::get_texture(linger, image::TOD_COLORED)](const rect& dest) { draw::blit(tex, dest); });
}
if(on_map && loc == selectedHex_ && !game_config::images::selected.empty()) {
static const image::locator selected(game_config::images::selected);
drawing_buffer_add(LAYER_SELECTED_HEX, loc,
drawing_buffer_add(drawing_layer::selected_hex, loc,
[tex = image::get_texture(selected, image::HEXED)](const rect& dest) { draw::blit(tex, dest); });
}
@ -328,7 +328,7 @@ void game_display::draw_hex(const map_location& loc)
int debugH = debugHighlights_[loc];
if (debugH) {
std::string txt = std::to_string(debugH);
draw_text_in_hex(loc, LAYER_MOVE_INFO, txt, 18, font::BAD_COLOR);
draw_text_in_hex(loc, drawing_layer::move_info, txt, 18, font::BAD_COLOR);
}
}
}
@ -401,9 +401,9 @@ void game_display::draw_movement_info(const map_location& loc)
// simple mark (no turn point) use smaller font
int def_font = w->second.turns > 0 ? 18 : 16;
draw_text_in_hex(loc, LAYER_MOVE_INFO, def_text.str(), def_font, color);
draw_text_in_hex(loc, drawing_layer::move_info, def_text.str(), def_font, color);
drawing_buffer_add(LAYER_MOVE_INFO, loc,
drawing_buffer_add(drawing_layer::move_info, loc,
[inv = w->second.invisible, zoc = w->second.zoc, cap = w->second.capture](const rect& dest) {
if(inv) {
draw::blit(image::get_texture(image::locator{"misc/hidden.png"}, image::HEXED), dest);
@ -422,7 +422,7 @@ void game_display::draw_movement_info(const map_location& loc)
if (w->second.turns > 1 || (w->second.turns == 1 && loc != route_.steps.back())) {
std::stringstream turns_text;
turns_text << w->second.turns;
draw_text_in_hex(loc, LAYER_MOVE_INFO, turns_text.str(), 17, font::NORMAL_COLOR, 0.5,0.8);
draw_text_in_hex(loc, drawing_layer::move_info, turns_text.str(), 17, font::NORMAL_COLOR, 0.5,0.8);
}
// The hex is full now, so skip the "show enemy moves"
@ -446,7 +446,7 @@ void game_display::draw_movement_info(const map_location& loc)
// use small font
int def_font = 16;
draw_text_in_hex(loc, LAYER_MOVE_INFO, def_text.str(), def_font, color);
draw_text_in_hex(loc, drawing_layer::move_info, def_text.str(), def_font, color);
}
}
@ -454,7 +454,7 @@ void game_display::draw_movement_info(const map_location& loc)
reach_map::iterator reach = reach_map_.find(loc);
if (reach != reach_map_.end() && reach->second > 1) {
const std::string num = std::to_string(reach->second);
draw_text_in_hex(loc, LAYER_MOVE_INFO, num, 16, font::YELLOW_COLOR);
draw_text_in_hex(loc, drawing_layer::move_info, num, 16, font::YELLOW_COLOR);
}
}
}

View file

@ -545,7 +545,7 @@ void unit_animation::fill_initial_animations(std::vector<unit_animation>& animat
animations.push_back(base);
animations.back().event_ = { "movement" };
animations.back().unit_anim_.override(0, 200,
particle::NO_CYCLE, "", "", {0,0,0}, "0~1:200", std::to_string(display::LAYER_UNIT_MOVE_DEFAULT - display::LAYER_UNIT_FIRST));
particle::NO_CYCLE, "", "", {0,0,0}, "0~1:200", std::to_string(get_abs_frame_layer(drawing_layer::unit_move_default)));
animations.push_back(base);
animations.back().event_ = { "defend" };
@ -559,7 +559,7 @@ void unit_animation::fill_initial_animations(std::vector<unit_animation>& animat
animations.push_back(base);
animations.back().event_ = { "attack" };
animations.back().unit_anim_.override(-150, 300, particle::NO_CYCLE, "", "", {0,0,0}, "0~0.6:150,0.6~0:150", std::to_string(display::LAYER_UNIT_MOVE_DEFAULT-display::LAYER_UNIT_FIRST));
animations.back().unit_anim_.override(-150, 300, particle::NO_CYCLE, "", "", {0,0,0}, "0~0.6:150,0.6~0:150", std::to_string(get_abs_frame_layer(drawing_layer::unit_move_default)));
animations.back().primary_attack_filter_.emplace_back("range", "melee");
animations.push_back(base);
@ -606,7 +606,7 @@ void unit_animation::fill_initial_animations(std::vector<unit_animation>& animat
static void add_simple_anim(std::vector<unit_animation>& animations,
const config& cfg, char const* tag_name, char const* apply_to,
display::drawing_layer layer = display::LAYER_UNIT_DEFAULT,
drawing_layer layer = drawing_layer::unit_default,
bool offscreen = true)
{
for(const animation_branch& ab : prepare_animation(cfg, tag_name)) {
@ -619,7 +619,7 @@ static void add_simple_anim(std::vector<unit_animation>& animations,
}
config::attribute_value& v = anim["layer"];
if(v.empty()) v = layer - display::LAYER_UNIT_FIRST;
if(v.empty()) v = get_abs_frame_layer(layer);
animations.emplace_back(anim);
}
@ -631,16 +631,16 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
animations.emplace_back(ab.merge());
}
const int default_layer = display::LAYER_UNIT_DEFAULT - display::LAYER_UNIT_FIRST;
const int move_layer = display::LAYER_UNIT_MOVE_DEFAULT - display::LAYER_UNIT_FIRST;
const int missile_layer = display::LAYER_UNIT_MISSILE_DEFAULT - display::LAYER_UNIT_FIRST;
constexpr int default_layer = get_abs_frame_layer(drawing_layer::unit_default);
constexpr int move_layer = get_abs_frame_layer(drawing_layer::unit_move_default);
constexpr int missile_layer = get_abs_frame_layer(drawing_layer::unit_missile_default);
add_simple_anim(animations, cfg, "resistance_anim", "resistance");
add_simple_anim(animations, cfg, "leading_anim", "leading");
add_simple_anim(animations, cfg, "teaching_anim", "teaching");
add_simple_anim(animations, cfg, "recruit_anim", "recruited");
add_simple_anim(animations, cfg, "recruiting_anim", "recruiting");
add_simple_anim(animations, cfg, "idle_anim", "idling", display::LAYER_UNIT_DEFAULT, false);
add_simple_anim(animations, cfg, "idle_anim", "idling", drawing_layer::unit_default, false);
add_simple_anim(animations, cfg, "levelin_anim", "levelin");
add_simple_anim(animations, cfg, "levelout_anim", "levelout");
@ -736,7 +736,7 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
animations.back().sub_anims_["_poison_sound"].add_frame(1,frame_builder().sound(game_config::sounds::status::poisoned),true);
}
add_simple_anim(animations, cfg, "pre_movement_anim", "pre_movement", display::LAYER_UNIT_MOVE_DEFAULT);
add_simple_anim(animations, cfg, "pre_movement_anim", "pre_movement", drawing_layer::unit_move_default);
for(const animation_branch& ab : prepare_animation(cfg, "movement_anim")) {
config anim = ab.merge();
@ -753,7 +753,7 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
animations.emplace_back(anim);
}
add_simple_anim(animations, cfg, "post_movement_anim", "post_movement", display::LAYER_UNIT_MOVE_DEFAULT);
add_simple_anim(animations, cfg, "post_movement_anim", "post_movement", drawing_layer::unit_move_default);
for(const animation_branch& ab : prepare_animation(cfg, "defend")) {
config anim = ab.merge();
@ -799,8 +799,8 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
}
}
add_simple_anim(animations, cfg, "draw_weapon_anim", "draw_weapon", display::LAYER_UNIT_MOVE_DEFAULT);
add_simple_anim(animations, cfg, "sheath_weapon_anim", "sheath_weapon", display::LAYER_UNIT_MOVE_DEFAULT);
add_simple_anim(animations, cfg, "draw_weapon_anim", "draw_weapon", drawing_layer::unit_move_default);
add_simple_anim(animations, cfg, "sheath_weapon_anim", "sheath_weapon", drawing_layer::unit_move_default);
for(const animation_branch& ab : prepare_animation(cfg, "attack_anim")) {
config anim = ab.merge();

View file

@ -314,7 +314,7 @@ void unit_drawer::redraw_unit(const unit& u) const
}
}
disp.drawing_buffer_add(display::LAYER_UNIT_FIRST, loc, [=, adj_y = adjusted_params.y](const rect& d) {
disp.drawing_buffer_add(drawing_layer::unit_first, loc, [=, adj_y = adjusted_params.y](const rect& d) {
// Both front and back have the same origin
const point origin { d.x, d.y + adj_y - ellipse_floating };
@ -395,7 +395,7 @@ void unit_drawer::redraw_unit(const unit& u) const
}
};
disp.drawing_buffer_add(display::LAYER_UNIT_BAR, loc, [=,
disp.drawing_buffer_add(drawing_layer::unit_bar, loc, [=,
textures = std::move(textures),
adj_y = adjusted_params.y,
//origin = point{xsrc + xoff, ysrc + yoff + adjusted_params.y},

View file

@ -39,7 +39,7 @@ frame_parameters::frame_parameters()
, auto_vflip(boost::logic::indeterminate)
, auto_hflip(boost::logic::indeterminate)
, primary_frame(boost::logic::indeterminate)
, drawing_layer(display::LAYER_UNIT_DEFAULT - display::LAYER_UNIT_FIRST)
, drawing_layer(get_abs_frame_layer(drawing_layer::unit_default))
{}
frame_builder::frame_builder()
@ -47,7 +47,7 @@ frame_builder::frame_builder()
, auto_vflip_(boost::logic::indeterminate)
, auto_hflip_(boost::logic::indeterminate)
, primary_frame_(boost::logic::indeterminate)
, drawing_layer_(std::to_string(display::LAYER_UNIT_DEFAULT - display::LAYER_UNIT_FIRST))
, drawing_layer_(std::to_string(get_abs_frame_layer(drawing_layer::unit_default)))
{}
frame_builder::frame_builder(const config& cfg,const std::string& frame_string)
@ -315,7 +315,7 @@ const frame_parameters frame_parsed_parameters::parameters(int current_time) con
result.auto_vflip = auto_vflip_;
result.auto_hflip = auto_hflip_;
result.primary_frame = primary_frame_;
result.drawing_layer = drawing_layer_.get_current_element(current_time,display::LAYER_UNIT_DEFAULT-display::LAYER_UNIT_FIRST);
result.drawing_layer = drawing_layer_.get_current_element(current_time, get_abs_frame_layer(drawing_layer::unit_default));
return result;
}
@ -479,7 +479,7 @@ namespace
void render_unit_image(
int x,
int y,
const display::drawing_layer drawing_layer,
const drawing_layer drawing_layer,
const map_location& loc,
const image::locator& i_locator,
bool hreverse,
@ -699,7 +699,7 @@ void unit_frame::redraw(const int frame_time, bool on_start_time, bool in_scope_
if(alpha != 0) {
render_unit_image(my_x, my_y,
static_cast<display::drawing_layer>(display::LAYER_UNIT_FIRST + current_data.drawing_layer),
drawing_layer { int(drawing_layer::unit_first) + current_data.drawing_layer },
src,
image_loc,
facing_west,
@ -1014,8 +1014,8 @@ frame_parameters unit_frame::merge_parameters(int current_time, const frame_para
assert(engine_val.directional_y == 0);
result.directional_y = current_val.directional_y ? current_val.directional_y : animation_val.directional_y;
assert(engine_val.drawing_layer == display::LAYER_UNIT_DEFAULT - display::LAYER_UNIT_FIRST);
result.drawing_layer = current_val.drawing_layer != display::LAYER_UNIT_DEFAULT-display::LAYER_UNIT_FIRST
assert(engine_val.drawing_layer == get_abs_frame_layer(drawing_layer::unit_default));
result.drawing_layer = current_val.drawing_layer != get_abs_frame_layer(drawing_layer::unit_default)
? current_val.drawing_layer
: animation_val.drawing_layer;

View file

@ -23,6 +23,7 @@
#include "units/frame_private.hpp"
#include "color.hpp"
#include "drawing_layer.hpp"
#include "halo.hpp"
#include "picture.hpp"
#include "utils/optional_fwd.hpp"
@ -31,6 +32,11 @@
class config;
constexpr int get_abs_frame_layer(drawing_layer layer)
{
return int(layer) - int(drawing_layer::unit_first);
}
/** All parameters from a frame at a given instant */
struct frame_parameters
{

View file

@ -201,9 +201,9 @@ void attack::draw_hex(const map_location& hex)
return;
}
//@todo: replace this by either the use of transparency + LAYER_ATTACK_INDICATOR,
//@todo: replace this by either the use of transparency + drawing_layer::attack_indicator,
//or a dedicated layer
const display::drawing_layer layer = display::LAYER_FOOTSTEPS;
const drawing_layer layer = drawing_layer::footsteps;
//calculate direction (valid for both hexes)
const std::string direction_text = map_location::write_direction(get_dest_hex().get_relative_dir(target_hex_));

View file

@ -483,7 +483,7 @@ static void draw_numbers(const map_location& hex, side_actions::numbers_t number
color_t color = team::get_side_color(static_cast<int>(team_numbers[i]+1));
const double x_in_hex = x_origin + x_offset;
const double y_in_hex = y_origin + y_offset;
display::get_singleton()->draw_text_in_hex(hex, display::LAYER_ACTIONS_NUMBERING,
display::get_singleton()->draw_text_in_hex(hex, drawing_layer::actions_numbering,
number_text, font_size, color, x_in_hex, y_in_hex);
x_offset += x_offset_base;
y_offset += y_offset_base;

View file

@ -398,7 +398,7 @@ void move::draw_hex(const map_location& hex)
{
std::stringstream turn_text;
turn_text << turn_number_;
display::get_singleton()->draw_text_in_hex(hex, display::LAYER_MOVE_INFO, turn_text.str(), 17, font::NORMAL_COLOR, 0.5,0.8);
display::get_singleton()->draw_text_in_hex(hex, drawing_layer::move_info, turn_text.str(), 17, font::NORMAL_COLOR, 0.5,0.8);
}
}

View file

@ -206,7 +206,7 @@ void recall::draw_hex(const map_location& hex)
}
std::size_t font_size = 16;
color_t color {255, 0, 0}; //red
display::get_singleton()->draw_text_in_hex(hex, display::LAYER_ACTIONS_NUMBERING,
display::get_singleton()->draw_text_in_hex(hex, drawing_layer::actions_numbering,
number_text.str(), font_size, color, x_offset, y_offset);
}
}

View file

@ -175,7 +175,7 @@ void recruit::draw_hex(const map_location& hex)
number_text << font::unicode_minus << cost_;
std::size_t font_size = 16;
color_t color {255, 0, 0}; //red
display::get_singleton()->draw_text_in_hex(hex, display::LAYER_ACTIONS_NUMBERING,
display::get_singleton()->draw_text_in_hex(hex, drawing_layer::actions_numbering,
number_text.str(), font_size, color, x_offset, y_offset);
}
}

View file

@ -134,7 +134,7 @@ void suppose_dead::draw_hex(const map_location& hex)
}
//@todo: Possibly use a different layer
const display::drawing_layer layer = display::LAYER_ARROWS;
const drawing_layer layer = drawing_layer::arrows;
display::get_singleton()->drawing_buffer_add(
layer, loc_, [tex = image::get_texture(image::locator{"whiteboard/suppose_dead.png"}, image::HEXED)](const rect& d) {