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.
This commit is contained in:
parent
b9656013b0
commit
0d889cd0ff
4 changed files with 22 additions and 3 deletions
|
@ -7,7 +7,7 @@ namespace Events {
|
||||||
ATTACK, NEW_RITUAL,
|
ATTACK, NEW_RITUAL,
|
||||||
UPDATE_SPRITE, ENTITY_SPAWN, NOOP,
|
UPDATE_SPRITE, ENTITY_SPAWN, NOOP,
|
||||||
LOOT_ITEM, LOOT_CONTAINER,
|
LOOT_ITEM, LOOT_CONTAINER,
|
||||||
LOOT_CLOSE, LOOT_SELECT, INV_SELECT, AIM_CLICK
|
LOOT_CLOSE, LOOT_SELECT, INV_SELECT, AIM_CLICK, USE_ITEM
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Combat {
|
struct Combat {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "rituals.hpp"
|
#include "rituals.hpp"
|
||||||
#include <fmt/xchar.h>
|
#include <fmt/xchar.h>
|
||||||
#include "gui/guecstra.hpp"
|
#include "gui/guecstra.hpp"
|
||||||
|
#include "inventory.hpp"
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
using namespace guecs;
|
using namespace guecs;
|
||||||
|
@ -13,7 +14,7 @@ namespace gui {
|
||||||
$gui.position(COMBAT_UI_X, COMBAT_UI_Y, COMBAT_UI_WIDTH, COMBAT_UI_HEIGHT);
|
$gui.position(COMBAT_UI_X, COMBAT_UI_Y, COMBAT_UI_WIDTH, COMBAT_UI_HEIGHT);
|
||||||
$gui.layout(
|
$gui.layout(
|
||||||
"[button_0 | button_1 | button_2 | button_3"
|
"[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");
|
auto hp_gauge = $gui.entity("hp_gauge");
|
||||||
$gui.set<Sprite>(hp_gauge, {"stone_doll_cursed"});
|
$gui.set<Sprite>(hp_gauge, {"stone_doll_cursed"});
|
||||||
$gui.set<Clickable>(hp_gauge,
|
$gui.set<Clickable>(hp_gauge,
|
||||||
|
|
|
@ -503,6 +503,11 @@ namespace gui {
|
||||||
case eGUI::STAIRS_DOWN:
|
case eGUI::STAIRS_DOWN:
|
||||||
event(Event::STAIRS_DOWN);
|
event(Event::STAIRS_DOWN);
|
||||||
break;
|
break;
|
||||||
|
case eGUI::USE_ITEM: {
|
||||||
|
auto what = std::any_cast<DinkyECS::Entity>(data);
|
||||||
|
dbc::log(fmt::format("USE ITEM: {}", what));
|
||||||
|
break;
|
||||||
|
}
|
||||||
case eGUI::DEATH: {
|
case eGUI::DEATH: {
|
||||||
$status_ui.update();
|
$status_ui.update();
|
||||||
if(entity != player.entity) {
|
if(entity != player.entity) {
|
||||||
|
|
|
@ -184,7 +184,7 @@ void WorldBuilder::configure_starting_items(DinkyECS::World &world) {
|
||||||
world.make_constant(torch_id);
|
world.make_constant(torch_id);
|
||||||
|
|
||||||
auto healing = System::spawn_item(world, "POTION_HEALING_SMALL");
|
auto healing = System::spawn_item(world, "POTION_HEALING_SMALL");
|
||||||
inventory.add("hand_l", healing);
|
inventory.add("pocket_l", healing);
|
||||||
world.make_constant(healing);
|
world.make_constant(healing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue