Now have a body damage UI to show damage to each body part.
This commit is contained in:
parent
36a49ef768
commit
ae0d205037
5 changed files with 81 additions and 10 deletions
52
src/gui/body_ui.cpp
Normal file
52
src/gui/body_ui.cpp
Normal 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
18
src/gui/body_ui.hpp
Normal 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);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -16,13 +16,8 @@ namespace gui {
|
||||||
{
|
{
|
||||||
$gui.position(x, y, width, height);
|
$gui.position(x, y, width, height);
|
||||||
$gui.layout(
|
$gui.layout(
|
||||||
"[=body_head]"
|
"[*%(100, 200)body_ui]"
|
||||||
"[=body_chest]"
|
"[_]"
|
||||||
"[=body_right_arm]"
|
|
||||||
"[=body_left_arm]"
|
|
||||||
"[=body_stomach]"
|
|
||||||
"[=body_left_leg]"
|
|
||||||
"[=body_right_leg]"
|
|
||||||
"[=inv0|=inv1|=inv2]"
|
"[=inv0|=inv1|=inv2]"
|
||||||
"[=inv3|=inv4|=inv5]"
|
"[=inv3|=inv4|=inv5]"
|
||||||
"[=inv6|=inv7|=inv8]"
|
"[=inv6|=inv7|=inv8]"
|
||||||
|
|
@ -36,11 +31,11 @@ namespace gui {
|
||||||
for(auto& [name, cell] : $gui.cells()) {
|
for(auto& [name, cell] : $gui.cells()) {
|
||||||
auto gui_id = $gui.entity(name);
|
auto gui_id = $gui.entity(name);
|
||||||
|
|
||||||
|
|
||||||
$gui.set<Text>(gui_id, {guecs::to_wstring(name)});
|
$gui.set<Text>(gui_id, {guecs::to_wstring(name)});
|
||||||
|
|
||||||
if(name.starts_with("body_")) {
|
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 {
|
} else {
|
||||||
$gui.set<Rectangle>(gui_id, {});
|
$gui.set<Rectangle>(gui_id, {});
|
||||||
$gui.set<Clickable>(gui_id, {
|
$gui.set<Clickable>(gui_id, {
|
||||||
|
|
@ -67,6 +62,8 @@ namespace gui {
|
||||||
auto player = world->get_the<components::Player>();
|
auto player = world->get_the<components::Player>();
|
||||||
auto& inventory = world->get<inventory::Model>(player.entity);
|
auto& inventory = world->get<inventory::Model>(player.entity);
|
||||||
|
|
||||||
|
$body_ui.update();
|
||||||
|
|
||||||
for(const auto& [slot, cell] : $gui.cells()) {
|
for(const auto& [slot, cell] : $gui.cells()) {
|
||||||
|
|
||||||
if(inventory.has(slot)) {
|
if(inventory.has(slot)) {
|
||||||
|
|
@ -92,6 +89,7 @@ namespace gui {
|
||||||
|
|
||||||
void StatusUI::render(sf::RenderWindow &window) {
|
void StatusUI::render(sf::RenderWindow &window) {
|
||||||
$gui.render(window);
|
$gui.render(window);
|
||||||
|
$body_ui.render(window);
|
||||||
// $gui.debug_layout(window);
|
// $gui.debug_layout(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,13 @@
|
||||||
#include "graphics/textures.hpp"
|
#include "graphics/textures.hpp"
|
||||||
#include <guecs/ui.hpp>
|
#include <guecs/ui.hpp>
|
||||||
#include "gui/guecstra.hpp"
|
#include "gui/guecstra.hpp"
|
||||||
|
#include "gui/body_ui.hpp"
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
class StatusUI {
|
class StatusUI {
|
||||||
public:
|
public:
|
||||||
guecs::UI $gui;
|
guecs::UI $gui{};
|
||||||
|
BodyUI $body_ui{};
|
||||||
|
|
||||||
explicit StatusUI(size_t x, size_t y, size_t width, size_t height);
|
explicit StatusUI(size_t x, size_t y, size_t width, size_t height);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ sources = files(
|
||||||
'gui/status_ui.cpp',
|
'gui/status_ui.cpp',
|
||||||
'gui/main_ui.cpp',
|
'gui/main_ui.cpp',
|
||||||
'gui/overlay_ui.cpp',
|
'gui/overlay_ui.cpp',
|
||||||
|
'gui/body_ui.cpp',
|
||||||
|
|
||||||
# graphics
|
# graphics
|
||||||
'graphics/animation.cpp',
|
'graphics/animation.cpp',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue