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.
95 lines
2.5 KiB
95 lines
2.5 KiB
#include "gui/status_ui.hpp"
|
|
#include "components.hpp"
|
|
#include <guecs/ui.hpp>
|
|
#include "rand.hpp"
|
|
#include <fmt/xchar.h>
|
|
|
|
namespace gui {
|
|
using namespace guecs;
|
|
using std::any, std::any_cast, std::string, std::make_any;
|
|
|
|
StatusUI::StatusUI(GameLevel level) :
|
|
$level(level), $ritual_ui(level)
|
|
{
|
|
$gui.position(STATUS_UI_X, STATUS_UI_Y, STATUS_UI_WIDTH, STATUS_UI_HEIGHT);
|
|
$gui.layout(
|
|
"[ritual_ui]"
|
|
"[earing|armor_head|amulet]"
|
|
"[back|*%(200,300)character_view|_|armor_bdy]"
|
|
"[hand_r|_|_ |hand_l]"
|
|
"[ring_r|_|_ |ring_l]"
|
|
"[pocket_r|armor_leg|pocket_l]");
|
|
|
|
size_t inv_id = 0;
|
|
for(auto [name, entity] : $gui.$name_ents) {
|
|
if(name.starts_with("inv_")) {
|
|
$slots[name] = inv_id++;
|
|
}
|
|
}
|
|
}
|
|
|
|
void StatusUI::init() {
|
|
$gui.set<Background>($gui.MAIN, {$gui.$parser});
|
|
|
|
for(auto& [name, cell] : $gui.cells()) {
|
|
if(name == "character_view") {
|
|
auto char_view = $gui.entity(name);
|
|
$gui.set<Rectangle>(char_view, {});
|
|
$gui.set<Sprite>(char_view, {"armored_knight"});
|
|
} else {
|
|
auto button = $gui.entity(name);
|
|
$gui.set<Rectangle>(button, {});
|
|
$gui.set<ActionData>(button, {make_any<string>(name)});
|
|
|
|
if(name == "ritual_ui") {
|
|
$gui.set<Clickable>(button, {
|
|
[this](auto, auto){ select_ritual(); }
|
|
});
|
|
$gui.set<Sound>(button, {"pickup"});
|
|
} else {
|
|
$gui.set<Textual>(button, {guecs::to_wstring(name)});
|
|
$gui.set<Clickable>(button, {
|
|
[this](auto ent, auto data){ select_slot(ent, data); }
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
$ritual_ui.event(ritual::Event::STARTED);
|
|
$gui.init();
|
|
}
|
|
|
|
bool StatusUI::mouse(float x, float y, bool hover) {
|
|
if($ritual_ui.is_open()) {
|
|
return $ritual_ui.mouse(x, y, hover);
|
|
} else {
|
|
return $gui.mouse(x, y, hover);
|
|
}
|
|
}
|
|
|
|
void StatusUI::select_ritual() {
|
|
$ritual_ui.event(ritual::Event::TOGGLE);
|
|
}
|
|
|
|
void StatusUI::select_slot(DinkyECS::Entity ent, any slot_name) {
|
|
(void)ent;
|
|
(void)slot_name;
|
|
dbc::log("REWRITE!");
|
|
}
|
|
|
|
/* WARNING: This is really not the greatest way to do this. */
|
|
void StatusUI::update() {
|
|
dbc::log("REWRITE ME!");
|
|
}
|
|
|
|
void StatusUI::render(sf::RenderWindow &window) {
|
|
$gui.render(window);
|
|
// $gui.debug_layout(window);
|
|
$ritual_ui.render(window);
|
|
}
|
|
|
|
void StatusUI::update_level(GameLevel &level) {
|
|
$level = level;
|
|
init();
|
|
}
|
|
}
|
|
|