diff --git a/combat_ui.cpp b/combat_ui.cpp index b65c928..044a60b 100644 --- a/combat_ui.cpp +++ b/combat_ui.cpp @@ -15,18 +15,27 @@ namespace gui { dbc::check(good, "failed to parse combat layout"); for(auto& [name, cell] : $layout.cells) { + (void)name; 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[name] = button; + $shapes.push_back(button); + + sf::RectangleShape inner; + auto inner_cell = lel::center(30, 40, cell); + inner.setPosition({float(inner_cell.x), float(inner_cell.y)}); + inner.setSize({float(inner_cell.w), float(inner_cell.h)}); + inner.setOutlineColor({100, 100, 100}); + inner.setOutlineThickness(5); + $shapes.push_back(inner); } } void CombatUI::draw(sf::RenderWindow& window) { - for(auto& [name, shape] : $shapes) { + for(auto& shape : $shapes) { window.draw(shape); } } diff --git a/combat_ui.hpp b/combat_ui.hpp index b705b17..3bc1f6a 100644 --- a/combat_ui.hpp +++ b/combat_ui.hpp @@ -10,7 +10,7 @@ namespace gui { public: lel::Parser $layout; GameLevel $level; - std::unordered_map $shapes; + std::vector $shapes; CombatUI(GameLevel level); void draw(sf::RenderWindow& window); diff --git a/lel.cpp b/lel.cpp index c47faa1..d2297b7 100644 --- a/lel.cpp +++ b/lel.cpp @@ -26,6 +26,7 @@ namespace lel { cur = {cur.col + 1, cur.row}; } + void Parser::finalize() { dbc::check(columns > 0, "columns are 0"); dbc::check(rows > 0, "rows are 0"); @@ -47,12 +48,14 @@ namespace lel { cell.w = cell.expand ? std::min(cell.max_w, grid_w) : std::min(cell_width, cell.max_w); cell.h = cell.expand ? std::min(cell.max_h, grid_h) : std::min(cell_height, cell.max_h); + cell.mid_x = std::midpoint(cell.x, cell.x + cell_width); + cell.mid_y = std::midpoint(cell.y, cell.y + cell_height); if(cell.right) cell.x += cell_width - cell.w; if(cell.bottom) cell.y += cell_height - cell.h; if(cell.center) { - cell.x = std::midpoint(cell.x, cell.x + cell_width) - cell.w / 2; - cell.y = std::midpoint(cell.y, cell.y + cell_height) - cell.h / 2; + cell.x = cell.mid_x - cell.w / 2; + cell.y = cell.mid_y - cell.h / 2; } dbc::check(cell.h > 0, fmt::format("invalid height cell {}", name)); @@ -65,4 +68,15 @@ namespace lel { columns = 0; cur = {0, 0}; } + + Cell center(int width, int height, Cell &parent) { + Cell copy = parent; + + copy.x = parent.mid_x - width / 2; + copy.y = parent.mid_y - height / 2; + copy.w = width; + copy.h = height; + + return copy; + } } diff --git a/lel.hpp b/lel.hpp index 4f3f732..eba8e90 100644 --- a/lel.hpp +++ b/lel.hpp @@ -9,6 +9,8 @@ namespace lel { int y = 0; int w = 0; int h = 0; + int mid_x = 0; + int mid_y = 0; int max_w = 0; int max_h = 0; int col = 0; @@ -38,4 +40,6 @@ namespace lel { bool parse(std::string input); void finalize(); }; + + Cell center(int width, int height, Cell &parent); }