|
|
|
#include "overlay_ui.hpp"
|
|
|
|
#include "constants.hpp"
|
|
|
|
#include "color.hpp"
|
|
|
|
#include "events.hpp"
|
|
|
|
#include <optional>
|
|
|
|
|
|
|
|
namespace gui {
|
|
|
|
using namespace guecs;
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
OverlayUI::OverlayUI() {
|
|
|
|
$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() {
|
|
|
|
$gui.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OverlayUI::draw(sf::RenderWindow& window) {
|
|
|
|
$gui.render(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OverlayUI::show_sprite(string region, string sprite_name) {
|
|
|
|
auto ent = $gui.entity(region);
|
|
|
|
Sprite blood{sprite_name};
|
|
|
|
auto& cell = $gui.cell_for(ent);
|
|
|
|
blood.init(cell);
|
|
|
|
$gui.set<guecs::Sprite>(ent, blood);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OverlayUI::close_sprite(string region) {
|
|
|
|
auto ent = $gui.entity(region);
|
|
|
|
$gui.remove<guecs::Sprite>(ent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OverlayUI::show_text(string region, string content) {
|
|
|
|
auto ent = $gui.entity(region);
|
|
|
|
auto &cell = $gui.cell_for(ent);
|
|
|
|
Textual text{content, 20};
|
|
|
|
text.init(cell, $gui.$font);
|
|
|
|
text.text->setFillColor(ColorValue::LIGHT_MID);
|
|
|
|
$gui.set<Textual>(ent, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OverlayUI::update_text(string region, string content) {
|
|
|
|
auto ent = $gui.entity(region);
|
|
|
|
if(auto text = $gui.get_if<Textual>(ent)) {
|
|
|
|
text->text->setString(content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OverlayUI::update_label(string region, string content) {
|
|
|
|
auto ent = $gui.entity(region);
|
|
|
|
if(auto text = $gui.get_if<Label>(ent)) {
|
|
|
|
text->text->setString(content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OverlayUI::close_text(string region) {
|
|
|
|
auto ent = $gui.entity(region);
|
|
|
|
$gui.remove<Textual>(ent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OverlayUI::show_label(string region, string content) {
|
|
|
|
auto ent = $gui.entity(region);
|
|
|
|
auto &cell = $gui.cell_for(ent);
|
|
|
|
Label text{content, 20};
|
|
|
|
text.init(cell, $gui.$font);
|
|
|
|
text.text->setFillColor(ColorValue::LIGHT_MID);
|
|
|
|
$gui.set<Label>(ent, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OverlayUI::close_label(string region) {
|
|
|
|
auto ent = $gui.entity(region);
|
|
|
|
$gui.remove<Label>(ent);
|
|
|
|
}
|
|
|
|
}
|