Can click on buttons and make them change color.
This commit is contained in:
parent
7f9e200abe
commit
e106ad4be7
4 changed files with 17 additions and 7 deletions
|
@ -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});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue