diff --git a/combat_ui.cpp b/combat_ui.cpp index a8c808b..0a6ab5f 100644 --- a/combat_ui.cpp +++ b/combat_ui.cpp @@ -15,14 +15,13 @@ 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.push_back(button); + $shapes.insert_or_assign(name, button); sf::RectangleShape inner; auto inner_cell = lel::center(30, 40, cell); @@ -31,13 +30,20 @@ namespace gui { inner.setOutlineColor({100, 0, 0}); inner.setOutlineThickness(5); inner.setFillColor({50, 50, 50}); - $shapes.push_back(inner); + $shapes.insert_or_assign(name + "_text", inner); } } void CombatUI::draw(sf::RenderWindow& window) { - for(auto& shape : $shapes) { + for(auto& [name, shape] : $shapes) { window.draw(shape); } } + + void CombatUI::click(int x, int y) { + if(auto name = $layout.hit(x, y)) { + auto& shape = $shapes.at(*name); + shape.setFillColor({100, 0, 0}); + } + } } diff --git a/combat_ui.hpp b/combat_ui.hpp index 3bc1f6a..1522450 100644 --- a/combat_ui.hpp +++ b/combat_ui.hpp @@ -10,10 +10,11 @@ namespace gui { public: lel::Parser $layout; GameLevel $level; - std::vector $shapes; + std::unordered_map $shapes; CombatUI(GameLevel level); void draw(sf::RenderWindow& window); void update_level(GameLevel &level) { $level = level; } + void click(int x, int y); }; } diff --git a/gui.cpp b/gui.cpp index 3fba3e0..0ccd273 100644 --- a/gui.cpp +++ b/gui.cpp @@ -346,7 +346,10 @@ namespace gui { } void FSM::mouse() { - // temporarily gutted + if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) { + sf::Vector2i pos = sf::Mouse::getPosition($window); + $combat_view.click(pos.x, pos.y); + } } void FSM::generate_map() { diff --git a/tests/lel.cpp b/tests/lel.cpp index e94b2be..625cc53 100644 --- a/tests/lel.cpp +++ b/tests/lel.cpp @@ -14,7 +14,7 @@ TEST_CASE("test basic ops", "[lel]") { "[ label_1 | label3 | test1]" "[ *(300,300)text1 | %(150)people | ^test2]" "[ >label2 | _ | .test3]" - "[ =message | buttons | test4]"); + "[ =message | buttons | test4]"); REQUIRE(good);