Exploring raycasters and possibly make a little "doom like" game based on it.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
raycaster/overlay_ui.cpp

69 lines
1.7 KiB

#include "overlay_ui.hpp"
#include "constants.hpp"
#include "color.hpp"
#include "events.hpp"
namespace gui {
using namespace guecs;
OverlayUI::OverlayUI(GameLevel level, TexturePack& textures) :
$level(level),
$textures(textures)
{
$gui.position(RAY_VIEW_X, RAY_VIEW_Y, RAY_VIEW_WIDTH, RAY_VIEW_HEIGHT);
$gui.layout(
"[top_left|top|top_right]"
"[*%(300,300)middle|_|_]"
"[_|_|_]"
"[_|_|_]"
"[bottom_left|bottom|bottom_right]"
);
}
void OverlayUI::render() {
auto &world = $gui.world();
for(auto &[name, cell] : $gui.cells()) {
auto region = $gui.entity(name);
world.set<lel::Cell>(region, cell);
}
$gui.init($textures);
}
void OverlayUI::draw(sf::RenderWindow& window) {
$gui.render(window);
}
void OverlayUI::show_damage(bool show) {
auto middle = $gui.entity("middle");
if(show) {
Sprite blood{"blood_splatter"};
auto& cell = $gui.cell_for(middle);
blood.init(cell, $textures);
$gui.set<guecs::Sprite>(middle, blood);
} else {
$gui.remove<guecs::Sprite>(middle);
}
}
void OverlayUI::init_stats() {
auto top_left = $gui.entity("top_left");
auto &cell = $gui.cell_for(top_left);
Textual text{"", 20};
text.init(cell, $gui.$font);
text.text->setFillColor(ColorValue::LIGHT_MID);
$gui.set<Textual>(top_left, text);
}
void OverlayUI::draw_stats(std::string stats) {
auto top_left = $gui.entity("top_left");
auto& text = $gui.get<Textual>(top_left);
text.text->setString(stats);
}
void OverlayUI::close_stats() {
auto top_left = $gui.entity("top_left");
$gui.remove<Textual>(top_left);
}
}