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.
62 lines
1.6 KiB
62 lines
1.6 KiB
#include "status_ui.hpp"
|
|
#include "components.hpp"
|
|
#include "color.hpp"
|
|
#include "guecs.hpp"
|
|
|
|
namespace gui {
|
|
using namespace guecs;
|
|
|
|
StatusUI::StatusUI(GameLevel level) :
|
|
$level(level)
|
|
{
|
|
$gui.position(STATUS_UI_X, STATUS_UI_Y, STATUS_UI_WIDTH, STATUS_UI_HEIGHT);
|
|
$gui.layout(
|
|
"[button1 | button2 | button3]"
|
|
"[button4 | button5 | button6]"
|
|
"[button7 | button8 | button9]"
|
|
"[*%(100,300)log_view]"
|
|
"[_]"
|
|
"[_]"
|
|
);
|
|
}
|
|
|
|
void StatusUI::render(TexturePack &textures) {
|
|
auto& world = $gui.world();
|
|
|
|
for(auto& [name, cell] : $gui.cells()) {
|
|
if(name == "log_view") {
|
|
$log_to = $gui.entity("log_view");
|
|
world.set<lel::Cell>($log_to, cell);
|
|
world.set<Rectangle>($log_to, {});
|
|
world.set<Textual>($log_to, {"Welcome to the Game!", 20});
|
|
} else {
|
|
auto button = $gui.entity(name);
|
|
world.set<lel::Cell>(button, cell);
|
|
world.set<Rectangle>(button, {});
|
|
world.set<Label>(button, {name});
|
|
world.set<Clickable>(button,
|
|
guecs::make_action(*$level.world, Events::GUI::NOOP));
|
|
}
|
|
}
|
|
|
|
$gui.init(textures);
|
|
}
|
|
|
|
void StatusUI::draw(sf::RenderWindow &window) {
|
|
auto &world = $gui.world();
|
|
auto &text = world.get<Textual>($log_to);
|
|
std::string log;
|
|
for(auto msg : $messages) {
|
|
log += msg + "\n";
|
|
}
|
|
text.update(log);
|
|
$gui.render(window);
|
|
}
|
|
|
|
void StatusUI::log(std::string msg) {
|
|
$messages.push_front(msg);
|
|
if($messages.size() > MAX_LOG_MESSAGES) {
|
|
$messages.pop_back();
|
|
}
|
|
}
|
|
}
|
|
|