BAD: This gets the animation to control the camera, but it's a quick hack to prove it works.

This commit is contained in:
Zed A. Shaw 2025-11-01 01:15:18 -04:00
parent cb58bdd955
commit 102c8c36d5
5 changed files with 63 additions and 18 deletions

View file

@ -1,6 +1,8 @@
#include "boss/ui.hpp"
#include "scene.hpp"
#include "constants.hpp"
#include "components.hpp"
#include "animation.hpp"
namespace boss {
using namespace guecs;
@ -10,7 +12,8 @@ namespace boss {
$combat_ui(true),
$arena(scene),
$view_texture({BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT}),
$view_sprite($view_texture.getTexture())
$view_sprite($view_texture.getTexture()),
$zoom_anim(animation::load("test_zoom"))
{
$view_sprite.setPosition({BOSS_VIEW_X, BOSS_VIEW_Y});
}
@ -40,6 +43,11 @@ namespace boss {
void UI::render(sf::RenderWindow& window) {
$actions.render(window);
$combat_ui.render(window);
if($zoom_anim.playing) {
zoom("player2");
}
$arena.render($view_texture);
$view_texture.display();
window.draw($view_sprite);
@ -71,10 +79,25 @@ namespace boss {
if(cell_name == "") {
sf::View zoom{{BOSS_VIEW_WIDTH/2,BOSS_VIEW_HEIGHT/2}, {BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT}};
$view_texture.setView(zoom);
} else {
} else if($zoom_anim.playing) {
auto& cell = $arena.$ui.cell_for(cell_name);
sf::View zoom{{(float)cell.mid_x, (float)cell.mid_y},
{(float)cell.w*3, (float)cell.h*3}};
sf::Vector2f scale{$zoom_anim.min_x, $zoom_anim.min_y};
sf::Vector2f pos{float(cell.x), float(cell.y)};
sf::IntRect rect{{0,0}, {cell.w, cell.h}};
$zoom_anim.step(scale, pos, rect);
fmt::println("SCALE: {},{}; pos: {},{}; rect: {},{};{},{}",
scale.x, scale.y, pos.x, pos.y,
rect.position.x, rect.position.y,
rect.size.x, rect.size.y);
sf::View zoom{pos,
{float(cell.w * 2), float(cell.h * 2)}};
if($zoom_anim.scaled) {
zoom.zoom(scale.x);
}
$view_texture.setView(zoom);
}