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.
101 lines
2.8 KiB
101 lines
2.8 KiB
#include "ritual_ui.hpp"
|
|
#include "components.hpp"
|
|
#include "guecs.hpp"
|
|
#include "rand.hpp"
|
|
#include "animation.hpp"
|
|
|
|
namespace gui {
|
|
using namespace guecs;
|
|
using std::any, std::any_cast, std::string, std::make_any;
|
|
|
|
RitualUI::RitualUI(GameLevel level) :
|
|
$level(level)
|
|
{
|
|
$gui.position(STATUS_UI_X, STATUS_UI_Y, STATUS_UI_WIDTH, STATUS_UI_HEIGHT);
|
|
$gui.layout(
|
|
"[_]"
|
|
"[inv_slot9 | inv_slot10 | inv_slot11| inv_slot12]"
|
|
"[inv_slot13 | inv_slot14 | inv_slot15| inv_slot16]"
|
|
"[inv_slot17 | inv_slot18 | inv_slot19| inv_slot20]"
|
|
"[inv_slot21 | inv_slot22 | inv_slot23| inv_slot24]"
|
|
"[*%(100,600)circle_area]"
|
|
"[_]"
|
|
"[_]"
|
|
"[_]"
|
|
"[_]"
|
|
"[_]"
|
|
"[ ritual_ui ]");
|
|
}
|
|
|
|
void RitualUI::init() {
|
|
for(auto& [name, cell] : $gui.cells()) {
|
|
auto button = $gui.entity(name);
|
|
|
|
if(name == "circle_area") {
|
|
// $gui.set<Rectangle>(button, {});
|
|
$gui.set<Sprite>(button, {"the_ritual_circle"});
|
|
$gui.set<Clickable>(button, {
|
|
[this](auto, auto){ dbc::log("circle clicked"); }
|
|
});
|
|
} else if(name.starts_with("inv_slot")) {
|
|
$gui.set<Sprite>(button, {"the_ritual_circle"});
|
|
// $gui.set<Rectangle>(button, {});
|
|
$gui.set<Clickable>(button, {
|
|
[this, name](auto, auto){ dbc::log(fmt::format("inv_slot {}", name)); }
|
|
});
|
|
} else if(name == "ritual_ui") {
|
|
$gui.set<Clickable>(button, {
|
|
[this](auto, auto){ toggle(); }
|
|
});
|
|
}
|
|
}
|
|
|
|
$ritual_ui = textures::get("ritual_crafting_area");
|
|
$ritual_ui.sprite->setPosition({0,0});
|
|
$ritual_ui.sprite->setTextureRect($ritual_closed_rect);
|
|
$ritual_state = RitualUIState::CLOSED;
|
|
$ritual_anim = animation::load("ritual_blanket");
|
|
|
|
$gui.init();
|
|
}
|
|
|
|
bool RitualUI::is_open() {
|
|
return $ritual_state != RitualUIState::CLOSED;
|
|
}
|
|
|
|
bool RitualUI::mouse(float x, float y) {
|
|
return $gui.mouse(x, y);
|
|
}
|
|
|
|
void RitualUI::toggle() {
|
|
using enum RitualUIState;
|
|
|
|
if($ritual_state == OPEN) {
|
|
$ritual_state = CLOSING;
|
|
} else if($ritual_state == CLOSED) {
|
|
$ritual_state = OPENING;
|
|
$ritual_anim.play();
|
|
}
|
|
}
|
|
|
|
/* WARNING: This is really not the greatest way to do this. */
|
|
void RitualUI::update() {
|
|
dbc::log("RITUAL UPDATE NOT IMPLEMENTED");
|
|
}
|
|
|
|
void RitualUI::render(sf::RenderWindow &window) {
|
|
using enum RitualUIState;
|
|
|
|
if($ritual_state == OPENING) {
|
|
if(!animation::apply($ritual_anim, $ritual_ui)) {
|
|
$ritual_state = OPEN;
|
|
}
|
|
} else if($ritual_state == CLOSING) {
|
|
$ritual_ui.sprite->setTextureRect($ritual_closed_rect);
|
|
$ritual_state = CLOSED;
|
|
}
|
|
|
|
window.draw(*$ritual_ui.sprite);
|
|
if($ritual_state == OPEN) $gui.render(window);
|
|
}
|
|
}
|
|
|