#include "gui/status_ui.hpp" #include "components.hpp" #include #include "rand.hpp" #include #include "gui/guecstra.hpp" 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]"); } void StatusUI::init() { $gui.set($gui.MAIN, {$gui.$parser}); for(auto& [name, cell] : $gui.cells()) { if(name == "character_view") { auto char_view = $gui.entity(name); $gui.set(char_view, {}); $gui.set(char_view, {"armored_knight"}); } else { auto button = $gui.entity(name); $gui.set(button, {}); $gui.set(button, {make_any(name)}); if(name == "ritual_ui") { $gui.set(button, { [this](auto, auto){ select_ritual(); } }); $gui.set(button, {"pickup"}); } else { $gui.set(button, {guecs::to_wstring(name)}); $gui.set(button, { guecs::make_action(*$level.world, Events::GUI::LOOT_PLACE, {name}) }); } } } $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::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(); } void StatusUI::select_slot(int slot_id, DinkyECS::Entity entity) { $selected_slot = slot_id; $selected_entity = entity; } int StatusUI::place_slot(const std::string &name) { fmt::println("LOOT slot={}, entity={} PLACE into slot={}", $selected_slot, $selected_entity, name); auto& sprite = $level.world->get($selected_entity); auto gui_id = $gui.entity(name); $gui.set_init(gui_id, {sprite.name}); $slots.insert_or_assign(name, $selected_entity); return $selected_slot; } }