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);
|
||||
}
|
||||
|
|
|
@ -20,5 +20,6 @@ namespace gui {
|
|||
guecs::Entity make_button(std::string name, Events::GUI event,
|
||||
int action, const std::string &icon_name,
|
||||
const std::string &sound, const std::string &effect_name);
|
||||
void use_item(guecs::Entity gui_id, const string& slot);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -502,13 +502,18 @@ namespace gui {
|
|||
break;
|
||||
case eGUI::USE_ITEM: {
|
||||
auto what = std::any_cast<DinkyECS::Entity>(data);
|
||||
dbc::log(fmt::format("USE ITEM: {}", what));
|
||||
|
||||
if(System::use_item($level, what)) {
|
||||
$status_ui.update();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case eGUI::DEATH: {
|
||||
$status_ui.update();
|
||||
if(entity != player.entity) {
|
||||
$main_ui.dead_entity(entity);
|
||||
} else {
|
||||
dbc::log("NEED TO HANDLE PLAYER DYING.");
|
||||
}
|
||||
} break;
|
||||
case eGUI::NOOP: {
|
||||
|
|
|
@ -76,15 +76,27 @@ namespace gui {
|
|||
void StatusUI::update() {
|
||||
auto player = $level.world->get_the<components::Player>();
|
||||
auto& inventory = $level.world->get<inventory::Model>(player.entity);
|
||||
for(auto& [slot, world_entity] : inventory.by_slot) {
|
||||
auto gui_id = $gui.entity(slot);
|
||||
|
||||
auto& sprite = $level.world->get<components::Sprite>(world_entity);
|
||||
$gui.set_init<guecs::Icon>(gui_id, {sprite.name});
|
||||
guecs::GrabSource grabber{ world_entity,
|
||||
[&, gui_id]() { return remove_slot(gui_id); }};
|
||||
grabber.setSprite($gui, gui_id);
|
||||
$gui.set<guecs::GrabSource>(gui_id, grabber);
|
||||
for(const auto& [slot, cell] : $gui.cells()) {
|
||||
|
||||
if(inventory.has(slot)) {
|
||||
auto gui_id = $gui.entity(slot);
|
||||
auto world_entity = inventory.get(slot);
|
||||
|
||||
auto& sprite = $level.world->get<components::Sprite>(world_entity);
|
||||
$gui.set_init<guecs::Icon>(gui_id, {sprite.name});
|
||||
guecs::GrabSource grabber{ world_entity,
|
||||
[&, gui_id]() { return remove_slot(gui_id); }};
|
||||
grabber.setSprite($gui, gui_id);
|
||||
$gui.set<guecs::GrabSource>(gui_id, grabber);
|
||||
} else {
|
||||
auto gui_id = $gui.entity(slot);
|
||||
|
||||
if($gui.has<guecs::GrabSource>(gui_id)) {
|
||||
$gui.remove<guecs::GrabSource>(gui_id);
|
||||
$gui.remove<guecs::Icon>(gui_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,8 +135,7 @@ namespace gui {
|
|||
void StatusUI::remove_slot(guecs::Entity slot_id) {
|
||||
auto& slot_name = $gui.name_for(slot_id);
|
||||
System::remove_from_container(*$level.world, $level.player, slot_name);
|
||||
$gui.remove<guecs::GrabSource>(slot_id);
|
||||
$gui.remove<guecs::Icon>(slot_id);
|
||||
update();
|
||||
}
|
||||
|
||||
void StatusUI::swap(guecs::Entity gui_a, guecs::Entity gui_b) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue