From 8f49cbad5508d761c1139c65e064c31ea3c79a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Boldizs=C3=A1r=20Lipka?= Date: Wed, 13 Aug 2014 15:00:42 +0200 Subject: [PATCH] Anchor unit overlays to the topleft corner of the sprite. Implements PR #22464. --- changelog | 1 + players_changelog | 2 ++ src/unit_drawer.cpp | 13 ++++++++----- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/changelog b/changelog index 4805520a8e4d..dfe0b3c30c13 100644 --- a/changelog +++ b/changelog @@ -296,6 +296,7 @@ Version 1.13.0-dev: * Added automatic help entries for all eras, fulfilling Feature Request #22107 * Fixed in-game help descriptions of default factions, using content from wiki * Added automatically generated lists of races and alignments to the descriptions of factions + * Align unit overlays to the sprite rather than the occupied hex. Version 1.11.11: * Add-ons server: diff --git a/players_changelog b/players_changelog index 209b461c268c..3428e3143ca2 100644 --- a/players_changelog +++ b/players_changelog @@ -93,6 +93,8 @@ Version 1.13.0-dev: * Autogenerate help pages for all eras and factions. * Help pages for a faction autogenerates a list of races and alignments that appear in that faction. * Make nice help descriptions for the default factions (using content from the wiki). + * Align unit overlays to the sprite rather than the occupied hex. + Version 1.11.11: * Campaigns: diff --git a/src/unit_drawer.cpp b/src/unit_drawer.cpp index 91cf224dfcaf..317fc7edaaf0 100644 --- a/src/unit_drawer.cpp +++ b/src/unit_drawer.cpp @@ -250,6 +250,9 @@ void unit_drawer::redraw_unit (const unit & u) const #endif if(draw_bars) { const image::locator* orb_img = NULL; + const surface unit_img = image::get_image(u.absolute_image()); + const int xoff = (hex_size - unit_img->w)/2; + const int yoff = (hex_size - unit_img->h)/2; /*static*/ const image::locator partmoved_orb(game_config::images::orb + "~RC(magenta>" + preferences::partial_color() + ")" ); /*static*/ const image::locator moved_orb(game_config::images::orb + "~RC(magenta>" + @@ -296,7 +299,7 @@ void unit_drawer::redraw_unit (const unit & u) const if (orb_img != NULL) { surface orb(image::get_image(*orb_img,image::SCALED_TO_ZOOM)); disp.drawing_buffer_add(display::LAYER_UNIT_BAR, - loc, xsrc, ysrc +adjusted_params.y, orb); + loc, xsrc + xoff, ysrc + adjusted_params.y + yoff, orb); } double unit_energy = 0.0; @@ -308,7 +311,7 @@ void unit_drawer::redraw_unit (const unit & u) const const fixed_t bar_alpha = (loc == mouse_hex || loc == sel_hex) ? ftofxp(1.0): ftofxp(0.8); - draw_bar(*energy_file, xsrc+bar_shift, ysrc +adjusted_params.y, + draw_bar(*energy_file, xsrc+bar_shift+xoff, ysrc + adjusted_params.y + yoff, loc, hp_bar_height, unit_energy,hp_color, bar_alpha); if(experience > 0 && can_advance) { @@ -316,7 +319,7 @@ void unit_drawer::redraw_unit (const unit & u) const const int xp_bar_height = static_cast(max_experience * u.xp_bar_scaling() / std::max(u.level(),1)); - draw_bar(*energy_file, xsrc, ysrc +adjusted_params.y, + draw_bar(*energy_file, xsrc + xoff, ysrc + adjusted_params.y + yoff, loc, xp_bar_height, filled, xp_color, bar_alpha); } @@ -327,7 +330,7 @@ void unit_drawer::redraw_unit (const unit & u) const // crown = adjust_surface_alpha(crown, bar_alpha); //} disp.drawing_buffer_add(display::LAYER_UNIT_BAR, - loc, xsrc, ysrc +adjusted_params.y, crown); + loc, xsrc + xoff, ysrc +adjusted_params.y + yoff, crown); } } @@ -336,7 +339,7 @@ void unit_drawer::redraw_unit (const unit & u) const const sdl::timage ov_img(image::get_texture(*ov, image::SCALED_TO_ZOOM)); if(!ov_img.null()) { disp.drawing_buffer_add(display::LAYER_UNIT_BAR, - loc, xsrc, ysrc +adjusted_params.y, ov_img); + loc, xsrc + xoff, ysrc + adjusted_params.y + yoff, ov_img); } #else const surface ov_img(image::get_image(*ov, image::SCALED_TO_ZOOM));