Made it so you can right-click on an item to use it, but yeah it's bad. Gotta refactor.

This commit is contained in:
Zed A. Shaw 2025-08-13 11:43:23 -04:00
parent 42575ef1f5
commit ad0069e899
9 changed files with 48 additions and 61 deletions

View file

@ -64,19 +64,6 @@ namespace gui {
}
}
auto healing_button = $gui.entity("healing_button");
auto& inventory = $level.world->get<inventory::Model>($level.player);
if(inventory.has("pocket_l")) {
$gui.set<Icon>(healing_button, {"healing_potion_small"});
$gui.set<Clickable>(healing_button, {[&](auto gui_id, auto) {
use_item(gui_id, "pocket_l");
}});
} else {
$gui.remove<Icon>(healing_button);
$gui.remove<Clickable>(healing_button);
}
auto hp_gauge = $gui.entity("hp_gauge");
$gui.set<Sprite>(hp_gauge, {"stone_doll_cursed"});
$gui.set<Clickable>(hp_gauge,
@ -85,15 +72,6 @@ namespace gui {
$gui.init();
}
void CombatUI::use_item(guecs::Entity gui_id, const string& slot) {
auto& inventory = $level.world->get<inventory::Model>($level.player);
dbc::check(inventory.has(slot), fmt::format(
"attempted to use an item but {} isn't in your inventory", slot));
auto healing_item = inventory.get(slot);
$level.world->send<Events::GUI>(Events::GUI::USE_ITEM, gui_id, {healing_item});
}
void CombatUI::render(sf::RenderWindow& window) {
$gui.render(window);
}