#include "ritual_ui.hpp" #include "components.hpp" #include "guecs.hpp" #include "rand.hpp" #include "animation.hpp" #include "rand.hpp" #include "sound.hpp" namespace gui { namespace ritual { using namespace guecs; using std::any, std::any_cast, std::string, std::make_any; void UI::event(Event ev) { switch($state) { FSM_STATE(State, START, ev); FSM_STATE(State, OPENED, ev); FSM_STATE(State, CLOSED, ev); FSM_STATE(State, OPENING, ev); FSM_STATE(State, CLOSING, ev); } } void UI::START(Event) { $ritual_ui = textures::get("ritual_crafting_area"); $ritual_ui.sprite->setPosition($gui.get_position()); $ritual_ui.sprite->setTextureRect($ritual_closed_rect); state(State::CLOSED); $ritual_anim = animation::load("ritual_blanket"); for(auto& [name, cell] : $gui.cells()) { auto button = $gui.entity(name); $gui.set(button, {GUECS_PADDING, {50, 50, 50, 150}}); $gui.set(button, { [](auto ent, auto) { fmt::println("clicked {}", ent); } }); } auto open_close_toggle = $gui.entity("ritual_ui"); $gui.set(open_close_toggle, { [&](auto, auto){ event(Event::TOGGLE); } }); $gui.init(); state(State::CLOSED); } void UI::OPENED(Event ev) { if(ev == Event::TOGGLE) { state(State::CLOSING); } } void UI::CLOSED(Event ev) { if(ev == Event::TOGGLE) { $ritual_anim.play(); state(State::OPENING); } } void UI::OPENING(Event ev) { if(ev == Event::TICK) { if(!animation::apply($ritual_anim, $ritual_ui)) { state(State::OPENED); } } } void UI::CLOSING(Event ev) { if(ev == Event::TICK) { $ritual_ui.sprite->setTextureRect($ritual_closed_rect); state(State::CLOSED); } } UI::UI(GameLevel level) : $level(level) { $gui.position(STATUS_UI_X, STATUS_UI_Y, STATUS_UI_WIDTH, STATUS_UI_HEIGHT); $gui.layout( "[_]" "[inv_slot0 | inv_slot1 | inv_slot2| inv_slot3]" "[inv_slot4 | inv_slot5 | inv_slot6| inv_slot7]" "[inv_slot8 | inv_slot9 | inv_slot10| inv_slot11]" "[inv_slot12 | inv_slot13 | inv_slot14| inv_slot15]" "[reset |*%(200,400)result_text|_]" "[*%(100,200)result_image|_ |_]" "[_|_|_]" "[combine|_|_]" "[_|craft0|craft1|craft2|craft3|_]" "[_|craft4|craft5|craft6|craft7|_]" "[ ritual_ui ]"); } bool UI::mouse(float x, float y, bool hover) { return $gui.mouse(x, y, hover); } bool UI::is_open() { return !in_state(State::CLOSED); } void UI::render(sf::RenderWindow &window) { event(Event::TICK); window.draw(*$ritual_ui.sprite); if(in_state(State::OPENED)) { $gui.render(window); $gui.debug_layout(window); } } } }