|
|
|
@ -11,27 +11,31 @@ namespace gui { |
|
|
|
|
{ |
|
|
|
|
bool good = $layout.parse($grid); |
|
|
|
|
dbc::check(good, "failed to parse combat layout"); |
|
|
|
|
|
|
|
|
|
render(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CombatUI::render() { |
|
|
|
|
$background.setPosition({float($layout.grid_x), float($layout.grid_y)}); |
|
|
|
|
$background.setSize({float($layout.grid_w), float($layout.grid_h)}); |
|
|
|
|
$background.setFillColor({0, 0, 0}); |
|
|
|
|
|
|
|
|
|
for(auto& [name, cell] : $layout.cells) { |
|
|
|
|
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}); |
|
|
|
|
shape.setOutlineColor({200, 200, 200}); |
|
|
|
|
shape.setOutlineThickness(1); |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
} else if(name == "bar_hp") { |
|
|
|
|
shape.setFillColor({50, 200, 50}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$shapes.insert_or_assign(name, shape); |
|
|
|
@ -39,6 +43,16 @@ namespace gui { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CombatUI::draw(sf::RenderWindow& window) { |
|
|
|
|
auto &player = $level.world->get_the<components::Player>(); |
|
|
|
|
auto &combat = $level.world->get<components::Combat>(player.entity); |
|
|
|
|
|
|
|
|
|
auto &hp_shape = $shapes.at("bar_hp"); |
|
|
|
|
auto &hp_cell = $layout.cells.at("bar_hp"); |
|
|
|
|
float hp_now = float(combat.hp) / float(combat.max_hp) * float(hp_cell.w); |
|
|
|
|
hp_shape.setSize({std::max(hp_now, 0.0f), float(hp_cell.h - 6)}); |
|
|
|
|
|
|
|
|
|
window.draw($background); |
|
|
|
|
|
|
|
|
|
for(auto& [name, shape] : $shapes) { |
|
|
|
|
window.draw(shape); |
|
|
|
|
} |
|
|
|
|