Skip to content

Commit

Permalink
Anchor unit overlays to the topleft corner of the sprite.
Browse files Browse the repository at this point in the history
Implements PR #22464.
  • Loading branch information
lipk committed Aug 13, 2014
1 parent a33ea52 commit 8f49cba
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions players_changelog
Expand Up @@ -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:
Expand Down
13 changes: 8 additions & 5 deletions src/unit_drawer.cpp
Expand Up @@ -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>" +
Expand Down Expand Up @@ -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;
Expand All @@ -308,15 +311,15 @@ 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) {
const double filled = double(experience)/double(max_experience);

const int xp_bar_height = static_cast<int>(max_experience * u.xp_bar_scaling() / std::max<int>(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);
}

Expand All @@ -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);
}
}

Expand All @@ -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));
Expand Down

0 comments on commit 8f49cba

Please sign in to comment.