Now have a body damage UI to show damage to each body part.

This commit is contained in:
Zed A. Shaw 2026-03-29 14:43:05 -04:00
parent 36a49ef768
commit ae0d205037
5 changed files with 81 additions and 10 deletions

52
src/gui/body_ui.cpp Normal file
View file

@ -0,0 +1,52 @@
#include "gui/body_ui.hpp"
#include "game/components.hpp"
#include <guecs/ui.hpp>
#include "algos/rand.hpp"
#include <fmt/xchar.h>
#include "gui/guecstra.hpp"
#include "game/systems.hpp"
#include "game/inventory.hpp"
#include "game/level.hpp"
namespace gui {
using namespace guecs;
using std::any, std::any_cast, std::string, std::make_any;
void BodyUI::init(size_t x, size_t y, size_t width, size_t height) {
$gui.position(x, y, width, height);
$gui.layout(
"[body_head]"
"[body_chest]"
"[body_right_arm]"
"[body_left_arm]"
"[body_stomach]"
"[body_left_leg]"
"[body_right_leg]");
$gui.set<Background>($gui.MAIN, {$gui.$parser, });
for(auto& [name, cell] : $gui.cells()) {
auto gui_id = $gui.entity(name);
$gui.set<Text>(gui_id, {guecs::to_wstring(name)});
$gui.set<Meter>(gui_id, {1.0f, THEME.DARK_MID, {}});
}
$gui.init();
update();
}
bool BodyUI::mouse(float x, float y, guecs::Modifiers mods) {
return $gui.mouse(x, y, mods);
}
void BodyUI::update() {
auto world = GameDB::current_world();
auto player = world->get_the<components::Player>();
}
void BodyUI::render(sf::RenderWindow &window) {
$gui.render(window);
// $gui.debug_layout(window);
}
}

18
src/gui/body_ui.hpp Normal file
View file

@ -0,0 +1,18 @@
#pragma once
#include "constants.hpp"
#include <deque>
#include "graphics/textures.hpp"
#include <guecs/ui.hpp>
#include "gui/guecstra.hpp"
namespace gui {
class BodyUI {
public:
guecs::UI $gui{};
void init(size_t x, size_t y, size_t width, size_t height);
void render(sf::RenderWindow &window);
void update();
bool mouse(float x, float y, guecs::Modifiers mods);
};
}

View file

@ -16,13 +16,8 @@ namespace gui {
{
$gui.position(x, y, width, height);
$gui.layout(
"[=body_head]"
"[=body_chest]"
"[=body_right_arm]"
"[=body_left_arm]"
"[=body_stomach]"
"[=body_left_leg]"
"[=body_right_leg]"
"[*%(100, 200)body_ui]"
"[_]"
"[=inv0|=inv1|=inv2]"
"[=inv3|=inv4|=inv5]"
"[=inv6|=inv7|=inv8]"
@ -36,11 +31,11 @@ namespace gui {
for(auto& [name, cell] : $gui.cells()) {
auto gui_id = $gui.entity(name);
$gui.set<Text>(gui_id, {guecs::to_wstring(name)});
if(name.starts_with("body_")) {
$gui.set<Meter>(gui_id, {});
auto& cell = $gui.cell_for(name);
$body_ui.init(cell.x, cell.y, cell.w, cell.h);
} else {
$gui.set<Rectangle>(gui_id, {});
$gui.set<Clickable>(gui_id, {
@ -67,6 +62,8 @@ namespace gui {
auto player = world->get_the<components::Player>();
auto& inventory = world->get<inventory::Model>(player.entity);
$body_ui.update();
for(const auto& [slot, cell] : $gui.cells()) {
if(inventory.has(slot)) {
@ -92,6 +89,7 @@ namespace gui {
void StatusUI::render(sf::RenderWindow &window) {
$gui.render(window);
$body_ui.render(window);
// $gui.debug_layout(window);
}

View file

@ -4,11 +4,13 @@
#include "graphics/textures.hpp"
#include <guecs/ui.hpp>
#include "gui/guecstra.hpp"
#include "gui/body_ui.hpp"
namespace gui {
class StatusUI {
public:
guecs::UI $gui;
guecs::UI $gui{};
BodyUI $body_ui{};
explicit StatusUI(size_t x, size_t y, size_t width, size_t height);