Quick start to making it possible to use healing items, or any item really. Going with a style that it has to be on your toolbar to use it, and the toolbelt looks in your inventory to see ifyou have healing items.

master
Zed A. Shaw 11 months ago
parent b9656013b0
commit 0d889cd0ff
  1. 2
      events.hpp
  2. 16
      gui/combat_ui.cpp
  3. 5
      gui/fsm.cpp
  4. 2
      worldbuilder.cpp

@ -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 {

@ -3,6 +3,7 @@
#include "rituals.hpp"
#include <fmt/xchar.h>
#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<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}));
} 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,

@ -503,6 +503,11 @@ namespace gui {
case eGUI::STAIRS_DOWN:
event(Event::STAIRS_DOWN);
break;
case eGUI::USE_ITEM: {
auto what = std::any_cast<DinkyECS::Entity>(data);
dbc::log(fmt::format("USE ITEM: {}", what));
break;
}
case eGUI::DEATH: {
$status_ui.update();
if(entity != player.entity) {

@ -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);
}