#include "boss/ui.hpp" #include "scene.hpp" #include "constants.hpp" #include "components.hpp" #include "animation.hpp" #include #include "game_level.hpp" #include "gui/guecstra.hpp" #include "events.hpp" namespace boss { using namespace guecs; using namespace DinkyECS; UI::UI(shared_ptr world, Entity boss_id, Entity player_id) : $world(world), $boss_id(boss_id), $player_id(player_id), $combat_ui(true), $arena(world->get($boss_id)), $view_texture({BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT}), $view_sprite($view_texture.getTexture()) { $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( "[*%(100,400)combat]" "[_]" "[_]" "[_]" "[commit]" "[*%(100,300)stats]" "[_]" "[_]"); auto commit = $actions.entity("commit"); $actions.set(commit, {}); $actions.set(commit, {L"COMMIT"}); $actions.set(commit, {}); $actions.set(commit, guecs::make_action(commit, game::Event::COMBAT_START, {})); auto stats = $actions.entity("stats"); $actions.set(stats, {}); update_stats(); $actions.init(); auto& cell = $actions.cell_for("combat"); $combat_ui.init(cell.x, cell.y, cell.w, cell.h); } void UI::update_stats() { auto& player_combat = $world->get($player_id); auto& boss_combat = $world->get($boss_id); std::wstring status = fmt::format( L"--PLAYER--\nHP:{}/{}\nAP:{}/{}\n\n--BOSS--\nHP:{}/{}\nAP:{}/{}\n----\n", player_combat.hp, player_combat.max_hp, player_combat.ap, player_combat.max_ap, boss_combat.hp, boss_combat.max_hp, boss_combat.ap, boss_combat.max_ap); $actions.show_text("stats", status); } void UI::set_window(sf::RenderWindow* window) { $window = window; } void UI::render() { $actions.render(*$window); $combat_ui.render(*$window); $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, const std::wstring &button_msg) { $arena.$ui.show_text("status", msg); $actions.show_text("commit", button_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::damage(const string& actor, const std::string& target, int amount) { if(amount > 0) { $arena.attach_text(target, fmt::format("{}", amount)); $arena.apply_effect(actor, "flame"); fmt::println("CAMERA zooming by 0.7 to {}", target); $arena.zoom(target, 0.8f); } else { $arena.attach_text(actor, "MISSED"); } } void UI::reset_camera() { $arena.reset($view_texture); } }