Exploring raycasters and possibly make a little "doom like" game based on it.
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.
 
 
 
 
 
 
raycaster/ritual_ui.cpp

121 lines
3.0 KiB

#include "ritual_ui.hpp"
#include "components.hpp"
#include "guecs.hpp"
#include "rand.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(
"[ ritual_ui ]"
"[inv_slot1 | inv_slot2 | inv_slot3]"
"[inv_slot4 | inv_slot5 | inv_slot6]"
"[*%(100,300)circle_area]"
"[_]"
"[_]");
}
void RitualUI::init() {
$gui.world().set_the<Background>({$gui.$parser});
for(auto& [name, cell] : $gui.cells()) {
if(name == "circle_area") {
dbc::log("circle area not setup...");
} else {
auto button = $gui.entity(name);
$gui.set<Rectangle>(button, {});
$gui.set<Textual>(button, {""});
$gui.set<ActionData>(button, {make_any<string>(name)});
if(name == "ritual_ui") {
$gui.set<Clickable>(button, {
[this](auto, auto){ select_ritual(); }
});
}
}
}
$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.simple = false;
$ritual_anim.looped = false;
$ritual_anim.easing = ease::NONE;
$ritual_anim.stationary = true;
$ritual_anim.texture_width = 380;
$ritual_anim.frames = 3;
$ritual_anim.speed = 0.2f;
$gui.init();
}
void RitualUI::select_ritual() {
using enum RitualUIState;
switch($ritual_state) {
case OPEN:
$ritual_state = CLOSING;
break;
case CLOSED:
$ritual_state = OPENING;
$ritual_anim.play();
break;
case OPENING: // ignored
break;
case CLOSING: // ignored
break;
default:
dbc::sentinel("INVALID RitualUIState");
}
}
/* 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) {
sf::IntRect rect;
sf::Vector2f scale{1.0, 1.0};
sf::Vector2f pos{0, 0};
using enum RitualUIState;
switch($ritual_state) {
case OPEN: {
rect = $ritual_open_rect;
} break;
case CLOSED: {
rect = $ritual_closed_rect;
}
break;
case OPENING: {
if($ritual_anim.playing) {
rect = $ritual_closed_rect;
$ritual_anim.step(scale, pos, rect);
} else {
$ritual_state = OPEN;
rect = $ritual_open_rect;
}
}
break;
case CLOSING: {
rect = $ritual_closed_rect;
$ritual_state = CLOSED;
} break;
default:
dbc::sentinel("INVALID RitualUIState");
}
$ritual_ui.sprite->setTextureRect(rect);
$ritual_ui.sprite->setPosition(pos);
$ritual_ui.sprite->setScale(scale);
window.draw(*$ritual_ui.sprite);
}
}