Now the loot UI can work with any container and only uses an ECS id to work, not have its own contents.

This commit is contained in:
Zed A. Shaw 2025-06-21 10:51:45 -04:00
parent a0eff927b6
commit 812407c3df
6 changed files with 70 additions and 34 deletions

View file

@ -1,6 +1,7 @@
#include "gui/loot_ui.hpp"
#include "constants.hpp"
#include <fmt/xchar.h>
#include "systems.hpp"
namespace gui {
using namespace guecs;
@ -57,6 +58,10 @@ namespace gui {
}
void LootUI::update() {
if(!$level.world->has<inventory::Model>($target)) return;
auto& contents = $level.world->get<inventory::Model>($target);
for(size_t i = 0; i < INV_SLOTS; i++) {
auto id = $gui.entity("item_", int(i));
auto& slot_name = $slot_to_name.at(id);
@ -88,20 +93,15 @@ namespace gui {
void LootUI::remove_slot(DinkyECS::Entity slot_id) {
auto& name = $slot_to_name.at(slot_id);
contents.remove(name);
System::remove_from_container(*$level.world, $target, name);
update();
}
bool LootUI::place_slot(guecs::Entity id, DinkyECS::Entity world_entity) {
auto& name = $slot_to_name.at(id);
if(!contents.has(name)) {
contents.add(name, world_entity);
update();
return true;
} else {
return false;
}
bool worked = System::place_in_container(*$level.world, $target, name, world_entity);
if(worked) update();
return worked;
}
void LootUI::render(sf::RenderWindow& window) {