Junk items are now transfered to your blanket so you can use them in crafting. No UI for that though.

This commit is contained in:
Zed A. Shaw 2025-04-27 13:35:05 -04:00
parent bc557652ba
commit 1a9e068d02
10 changed files with 86 additions and 53 deletions

View file

@ -30,21 +30,7 @@ namespace gui {
}
void RitualUI::init() {
auto& blanket = $level.world->get_the<ritual::Blanket>();
int i = 0;
blanket.contents.query<ritual::JunkItem>([&](const auto, auto& item) {
std::string slot = fmt::format("inv_slot{}", i++);
std::string sprite_name = fmt::format("{}-64", item);
auto button = $gui.entity(slot);
$gui.set<Sprite>(button, {sprite_name});
$gui.set<Effect>(button, {0.4f});
$gui.set<Sound>(button, {"ui_click"});
$gui.set<Clickable>(button, {
[&](auto ent, auto){ inv_slot_clicked(ent); }
});
});
update_items();
auto circle = $gui.entity("circle_area");
$gui.set<Effect>(circle, {0.4f});
@ -85,7 +71,8 @@ namespace gui {
bs.sprite->setPosition({float(x), float(y)});
}
$engine.set_state($blanket, "has_magick", true);
// BUG: get the actual thing they clicked on
$engine.set_state($craft_state, "has_magick", true);
}
void RitualUI::reset_inv_positions() {
@ -110,13 +97,16 @@ namespace gui {
animation::rotate(*bs.sprite, 20.0);
// finalize here ritual here
$engine.plan($blanket);
$engine.plan($craft_state);
if($blanket.is_combined()) {
if($craft_state.is_combined()) {
// add it to the belt
auto ritual = $engine.finalize($blanket);
auto ritual = $engine.finalize($craft_state);
// remove the items from the blanket now
auto& the_belt = $level.world->get_the<ritual::Belt>();
the_belt.equip(0, ritual);
$level.world->send<Events::GUI>(Events::GUI::NEW_RITUAL, $level.player, {});
reset_inv_positions();
} else {
@ -129,21 +119,42 @@ namespace gui {
return $gui.mouse(x, y, hover);
}
void RitualUI::update_items() {
auto& blanket = $level.world->get_the<ritual::Blanket>();
int i = 0;
blanket.contents.query<ritual::JunkItem>([&](const auto, auto& item) {
std::string slot = fmt::format("inv_slot{}", i++);
auto button = $gui.entity(slot);
std::string sprite_name = fmt::format("{}-64", item);
if($gui.has<Clickable>(button)) {
$gui.set<Sprite>(button, {sprite_name});
} else {
$gui.set<Sprite>(button, {sprite_name});
$gui.set<Effect>(button, {0.4f});
$gui.set<Sound>(button, {"ui_click"});
$gui.set<Clickable>(button, {
[&](auto ent, auto){ inv_slot_clicked(ent); }
});
}
});
}
void RitualUI::toggle() {
using enum RitualUIState;
if($ritual_state == OPEN) {
$ritual_state = CLOSING;
} else if($ritual_state == CLOSED) {
$blanket = $engine.start();
update_items();
$gui.init();
$craft_state = $engine.start();
$ritual_state = OPENING;
$ritual_anim.play();
}
}
/* WARNING: This is really not the greatest way to do this.
* look in status_ui.update_level()
* */
void RitualUI::update() {
dbc::log("RITUAL UPDATE NOT IMPLEMENTED");
}