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

@ -27,7 +27,8 @@ namespace gui {
$mini_map($level),
$loot_ui($level),
$font{FONT_FILE_NAME},
$dnd_loot($status_ui, $loot_ui, $window, $router)
$dnd_loot($status_ui, $loot_ui, $window, $router),
$temp_loot($level.world->entity())
{
$window.setPosition({0,0});
}
@ -66,6 +67,8 @@ namespace gui {
$map_ui.log(L"Welcome to the game!");
$mini_map.init($main_ui.$overlay_ui.$gui);
$level.world->set<inventory::Model>($temp_loot, {});
run_systems();
state(State::IDLE);
@ -458,8 +461,8 @@ namespace gui {
case eGUI::LOOT_ITEM: {
dbc::check(world.has<components::InventoryItem>(entity),
"INVALID LOOT_ITEM, that entity has no InventoryItem");
dbc::log("@@@@ SENDING LOOT_ITEM");
$loot_ui.contents.add("item_0", entity);
System::place_in_container(*$level.world, $temp_loot, "item_0", entity);
$loot_ui.set_target($temp_loot);
$loot_ui.update();
event(Event::LOOT_ITEM);
} break;

View file

@ -49,6 +49,7 @@ namespace gui {
sf::Font $font;
gui::routing::Router $router;
DNDLoot $dnd_loot;
DinkyECS::Entity $temp_loot;
FSM();

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

View file

@ -14,10 +14,14 @@ namespace gui {
guecs::UI $gui;
GameLevel $level;
std::unordered_map<guecs::Entity, std::string> $slot_to_name;
// NOTE: this should then become just an ECS id for a container
inventory::Model contents;
DinkyECS::Entity $target;
LootUI(GameLevel level);
void set_target(DinkyECS::Entity entity) {
$target = entity;
}
void init();
void update();
void render(sf::RenderWindow& window);