#include "combat_ui.hpp" #include "constants.hpp" #include "color.hpp" namespace gui { CombatUI::CombatUI(GameLevel level) : $layout(RAY_VIEW_X, RAY_VIEW_HEIGHT, RAY_VIEW_WIDTH, SCREEN_HEIGHT - RAY_VIEW_HEIGHT), $level(level), $font{FONT_FILE_NAME} { bool good = $layout.parse($grid); dbc::check(good, "failed to parse combat layout"); render(); } void CombatUI::render() { for(auto& [name, cell] : $layout.cells) { sf::RectangleShape button; button.setPosition({float(cell.x + 10), float(cell.y + 10)}); button.setSize({float(cell.w - 20), float(cell.h - 20)}); button.setFillColor({100, 100, 100}); button.setOutlineColor({200, 200, 200}); button.setOutlineThickness(5); $shapes.insert_or_assign(name, button); sf::Text label($font, name); auto bounds = label.getLocalBounds(); fmt::println("CENTER w/h={},{} vs bounds={},{}", cell.w, cell.h, bounds.size.x, bounds.size.y); auto label_cell = lel::center(bounds.size.x, bounds.size.y, cell); label.setPosition({float(label_cell.x), float(label_cell.y)}); $labels.push_back(label); sf::RectangleShape label_box; label_box.setPosition({float(label_cell.x), float(label_cell.y)}); label_box.setSize({float(label_cell.w), float(label_cell.h)}); label_box.setFillColor({10, 10, 10}); label_box.setOutlineColor({100,100,100}); label_box.setOutlineThickness(1.0); $label_boxes.insert_or_assign("Z" + name, label_box); } } void CombatUI::draw(sf::RenderWindow& window) { for(auto& [name, shape] : $shapes) { window.draw(shape); } for(auto& [name, shape] : $label_boxes) { window.draw(shape); } for(auto& label : $labels) { window.draw(label); } } void CombatUI::click(int x, int y) { if(auto name = $layout.hit(x, y)) { auto& shape = $shapes.at(*name); shape.setFillColor({100, 0, 0}); } } }