diff --git a/events.hpp b/events.hpp index 38cc923..82b4bee 100644 --- a/events.hpp +++ b/events.hpp @@ -7,7 +7,7 @@ namespace Events { ATTACK, NEW_RITUAL, UPDATE_SPRITE, ENTITY_SPAWN, NOOP, LOOT_ITEM, LOOT_CONTAINER, - LOOT_CLOSE, LOOT_SELECT, INV_SELECT, AIM_CLICK + LOOT_CLOSE, LOOT_SELECT, INV_SELECT, AIM_CLICK, USE_ITEM }; struct Combat { diff --git a/gui/combat_ui.cpp b/gui/combat_ui.cpp index b4a60e5..305715a 100644 --- a/gui/combat_ui.cpp +++ b/gui/combat_ui.cpp @@ -3,6 +3,7 @@ #include "rituals.hpp" #include #include "gui/guecstra.hpp" +#include "inventory.hpp" namespace gui { using namespace guecs; @@ -13,7 +14,7 @@ namespace gui { $gui.position(COMBAT_UI_X, COMBAT_UI_Y, COMBAT_UI_WIDTH, COMBAT_UI_HEIGHT); $gui.layout( "[button_0 | button_1 | button_2 | button_3" - "|button_4 | button_5 | button_6 | hp_gauge ]" + "|button_4 | button_5 | button_6 | healing_button | hp_gauge ]" ); } @@ -63,6 +64,19 @@ namespace gui { } } + auto healing_button = $gui.entity("healing_button"); + auto& inventory = $level.world->get($level.player); + + if(inventory.has("pocket_l")) { + auto healing_item = inventory.get("pocket_l"); + $gui.set(healing_button, {"healing_potion_small"}); + $gui.set(healing_button, + guecs::make_action($level, Events::GUI::USE_ITEM, {healing_item})); + } else { + $gui.remove(healing_button); + $gui.remove(healing_button); + } + auto hp_gauge = $gui.entity("hp_gauge"); $gui.set(hp_gauge, {"stone_doll_cursed"}); $gui.set(hp_gauge, diff --git a/gui/fsm.cpp b/gui/fsm.cpp index cecf4f9..1d8e22d 100644 --- a/gui/fsm.cpp +++ b/gui/fsm.cpp @@ -503,6 +503,11 @@ namespace gui { case eGUI::STAIRS_DOWN: event(Event::STAIRS_DOWN); break; + case eGUI::USE_ITEM: { + auto what = std::any_cast(data); + dbc::log(fmt::format("USE ITEM: {}", what)); + break; + } case eGUI::DEATH: { $status_ui.update(); if(entity != player.entity) { diff --git a/worldbuilder.cpp b/worldbuilder.cpp index 696b40a..3b37380 100644 --- a/worldbuilder.cpp +++ b/worldbuilder.cpp @@ -184,7 +184,7 @@ void WorldBuilder::configure_starting_items(DinkyECS::World &world) { world.make_constant(torch_id); auto healing = System::spawn_item(world, "POTION_HEALING_SMALL"); - inventory.add("hand_l", healing); + inventory.add("pocket_l", healing); world.make_constant(healing); }