Fixing more bugs related to percentages and then prototype a more complex UI.

This commit is contained in:
Zed A. Shaw 2025-02-15 22:14:19 -05:00
parent e106ad4be7
commit a7991a8f06
5 changed files with 45 additions and 20 deletions

View file

@ -6,14 +6,17 @@ namespace gui {
CombatUI::CombatUI(GameLevel level) :
$layout(RAY_VIEW_X, RAY_VIEW_HEIGHT,
RAY_VIEW_WIDTH, SCREEN_HEIGHT - RAY_VIEW_HEIGHT),
$level(level)
$level(level),
$font{FONT_FILE_NAME}
{
bool good = $layout.parse(
"[attack1 | attack2 | attack3 | heal]"
);
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)});
@ -23,14 +26,11 @@ namespace gui {
button.setOutlineThickness(5);
$shapes.insert_or_assign(name, 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, 0, 0});
inner.setOutlineThickness(5);
inner.setFillColor({50, 50, 50});
$shapes.insert_or_assign(name + "_text", inner);
sf::Text label($font, name);
auto bounds = label.getLocalBounds();
auto inner_cell = lel::center(bounds.size.x, bounds.size.y, cell);
label.setPosition({float(inner_cell.x), float(inner_cell.y)});
$labels.push_back(label);
}
}
@ -38,6 +38,10 @@ namespace gui {
for(auto& [name, shape] : $shapes) {
window.draw(shape);
}
for(auto& label : $labels) {
window.draw(label);
}
}
void CombatUI::click(int x, int y) {