Take display zoom into account when rendering unit animation frames

It was already considered for registering halos, just not for rendering
regular frames. This commit touches the halo code a little so we don't
need to call get_zoom_factor() multiple times per frame.

Closes #5508.
This commit is contained in:
Iris Morelle 2021-02-15 19:21:21 -03:00
parent 840b6e70be
commit 3530a4ef16
2 changed files with 12 additions and 10 deletions

View file

@ -16,6 +16,7 @@
### Miscellaneous and Bug Fixes
* Added support to wmlxgettext for double-quote characters in translatable raw strings
* Fixed an error message and the AI leader potentially not moving when it cannot reach a keep because it's occupied by an allied unit
* Fixed display zoom not being taken into account when using the `x`, `y`, `directional_x` and `directional_y` attributes in unit animations.
## Version 1.14.15
### Add-ons client

View file

@ -528,6 +528,7 @@ void unit_frame::redraw(const int frame_time, bool on_start_time, bool in_scope_
const int x = static_cast<int>(tmp_offset * xdst + (1.0 - tmp_offset) * xsrc) + d2;
const int y = static_cast<int>(tmp_offset * ydst + (1.0 - tmp_offset) * ysrc) + d2;
const double disp_zoom = display::get_singleton()->get_zoom_factor();
if(image != nullptr) {
bool facing_west = (
@ -542,19 +543,19 @@ void unit_frame::redraw(const int frame_time, bool on_start_time, bool in_scope_
if(!current_data.auto_hflip) { facing_west = false; }
if(!current_data.auto_vflip) { facing_north = true; }
int my_x = x + current_data.x - image->w / 2;
int my_y = y + current_data.y - image->h / 2;
int my_x = x + current_data.x * disp_zoom - image->w / 2;
int my_y = y + current_data.y * disp_zoom - image->h / 2;
if(facing_west) {
my_x -= current_data.directional_x;
my_x -= current_data.directional_x * disp_zoom;
} else {
my_x += current_data.directional_x;
my_x += current_data.directional_x * disp_zoom;
}
if(facing_north) {
my_y += current_data.directional_y;
my_y += current_data.directional_y * disp_zoom;
} else {
my_y -= current_data.directional_y;
my_y -= current_data.directional_y * disp_zoom;
}
display::get_singleton()->render_image(my_x, my_y,
@ -608,16 +609,16 @@ void unit_frame::redraw(const int frame_time, bool on_start_time, bool in_scope_
if(direction != map_location::SOUTH_WEST && direction != map_location::NORTH_WEST) {
halo_id = halo_man.add(
static_cast<int>(x + current_data.halo_x * display::get_singleton()->get_zoom_factor()),
static_cast<int>(y + current_data.halo_y * display::get_singleton()->get_zoom_factor()),
static_cast<int>(x + current_data.halo_x * disp_zoom),
static_cast<int>(y + current_data.halo_y * disp_zoom),
current_data.halo + current_data.halo_mod,
map_location(-1, -1),
orientation
);
} else {
halo_id = halo_man.add(
static_cast<int>(x - current_data.halo_x * display::get_singleton()->get_zoom_factor()),
static_cast<int>(y + current_data.halo_y * display::get_singleton()->get_zoom_factor()),
static_cast<int>(x - current_data.halo_x * disp_zoom),
static_cast<int>(y + current_data.halo_y * disp_zoom),
current_data.halo + current_data.halo_mod,
map_location(-1, -1),
orientation