Now you can heal yourself.
This commit is contained in:
parent
e03a63f9fb
commit
f19c1dbb20
6 changed files with 68 additions and 14 deletions
|
@ -68,10 +68,10 @@ namespace gui {
|
|||
auto& inventory = $level.world->get<inventory::Model>($level.player);
|
||||
|
||||
if(inventory.has("pocket_l")) {
|
||||
auto healing_item = inventory.get("pocket_l");
|
||||
$gui.set<Icon>(healing_button, {"healing_potion_small"});
|
||||
$gui.set<Clickable>(healing_button,
|
||||
guecs::make_action($level, Events::GUI::USE_ITEM, {healing_item}));
|
||||
$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);
|
||||
|
@ -85,6 +85,15 @@ 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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue