|
|
|
@ -17,20 +17,24 @@ namespace gui { |
|
|
|
|
|
|
|
|
|
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(); |
|
|
|
|
auto label_cell = lel::center(bounds.size.x, bounds.size.y, cell); |
|
|
|
|
// this stupid / 2 is because SFML renders from baseline rather than from the claimed bounding box
|
|
|
|
|
label.setPosition({float(label_cell.x), float(label_cell.y) - label_cell.h / 2}); |
|
|
|
|
$labels.push_back(label); |
|
|
|
|
sf::RectangleShape shape; |
|
|
|
|
shape.setPosition({float(cell.x + 3), float(cell.y + 3)}); |
|
|
|
|
shape.setSize({float(cell.w - 6), float(cell.h - 6)}); |
|
|
|
|
shape.setFillColor({100, 100, 100}); |
|
|
|
|
|
|
|
|
|
if(name.starts_with("button_")) { |
|
|
|
|
shape.setOutlineColor({200, 200, 200}); |
|
|
|
|
shape.setOutlineThickness(1); |
|
|
|
|
|
|
|
|
|
sf::Text label($font, name); |
|
|
|
|
auto bounds = label.getLocalBounds(); |
|
|
|
|
auto label_cell = lel::center(bounds.size.x, bounds.size.y, cell); |
|
|
|
|
// this stupid / 2 is because SFML renders from baseline rather than from the claimed bounding box
|
|
|
|
|
label.setPosition({float(label_cell.x), float(label_cell.y) - label_cell.h / 2}); |
|
|
|
|
$labels.push_back(label); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$shapes.insert_or_assign(name, shape); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -50,8 +54,10 @@ namespace gui { |
|
|
|
|
|
|
|
|
|
void CombatUI::click(int x, int y) { |
|
|
|
|
if(auto name = $layout.hit(x, y)) { |
|
|
|
|
auto& shape = $shapes.at(*name); |
|
|
|
|
shape.setFillColor({100, 0, 0}); |
|
|
|
|
if((*name).starts_with("button_")) { |
|
|
|
|
auto& shape = $shapes.at(*name); |
|
|
|
|
shape.setFillColor({100, 0, 0}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|