#include "boss/ui.hpp" #include "scene.hpp" #include "constants.hpp" #include "components.hpp" #include "animation.hpp" namespace boss { using namespace guecs; UI::UI(components::AnimatedScene& scene, Entity boss_id) : $boss_id(boss_id), $combat_ui(true), $arena(scene), $view_texture({BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT}), $view_sprite($view_texture.getTexture()), $zoom_anim(animation::load("test_zoom")) { $view_sprite.setPosition({BOSS_VIEW_X, BOSS_VIEW_Y}); } void UI::init() { $arena.init(); $actions.position(0,0, SCREEN_WIDTH-BOSS_VIEW_WIDTH, SCREEN_HEIGHT); $actions.layout( "[*(200,400)combat|_]" "[_|_]" "[_|_]" "[_|_]" "[*(200,300)stats]" "[_]" "[_]"); auto stats = $actions.entity("stats"); $actions.set(stats, {}); $actions.set(stats, {L"stats"}); $actions.init(); auto& cell = $actions.cell_for("combat"); $combat_ui.init(cell.x, cell.y, cell.w, cell.h); } 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); } bool UI::mouse(float x, float y, Modifiers mods) { // BUG: arena is getting the _window_ coordinates, not the rendertexture return $combat_ui.mouse(x, y, mods) || $actions.mouse(x, y, mods) || $arena.mouse(x, y, mods); } void UI::status(const std::wstring& msg) { $arena.$ui.show_text("status", msg); } void UI::move_actor(const std::string& actor, const std::string& cell_name) { $arena.move_actor(actor, cell_name); } void UI::animate_actor(const std::string& actor) { $arena.animate_actor(actor); } void UI::play_animations() { $arena.play_animations(); } void UI::zoom(const std::string &cell_name) { 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 if($zoom_anim.playing) { auto& cell = $arena.$ui.cell_for(cell_name); 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); } $view_sprite.setPosition({BOSS_VIEW_X, BOSS_VIEW_Y}); } }