From b6d1ae270085e5a4f5d7740047208be9923a7e7c Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Tue, 1 Jul 2025 14:26:39 -0400 Subject: [PATCH] Move the management of the 'fake loose items container' into the loot_ui.cpp rather than get rid of it. Closes #34. --- gui/dnd_loot.cpp | 2 -- gui/fsm.cpp | 19 +++++-------------- gui/fsm.hpp | 1 - gui/loot_ui.cpp | 24 +++++++++++++++++------- gui/loot_ui.hpp | 2 ++ 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/gui/dnd_loot.cpp b/gui/dnd_loot.cpp index f322ba5..fb99994 100644 --- a/gui/dnd_loot.cpp +++ b/gui/dnd_loot.cpp @@ -222,8 +222,6 @@ namespace gui { { if(!source_id) return false; auto target_id = std::any_cast(data); - fmt::println("!!!!!!!!!source_id = {} target_id = {}", - *source_id, target_id); dbc::check(target.has(target_id), "gui does not have a DropTarget at that slot"); diff --git a/gui/fsm.cpp b/gui/fsm.cpp index a602fae..c080988 100644 --- a/gui/fsm.cpp +++ b/gui/fsm.cpp @@ -27,8 +27,7 @@ namespace gui { $mini_map($level), $loot_ui($level), $font{FONT_FILE_NAME}, - $dnd_loot($status_ui, $loot_ui, $window, $router), - $temp_loot($level.world->entity()) + $dnd_loot($status_ui, $loot_ui, $window, $router) { $window.setPosition({0,0}); } @@ -67,8 +66,6 @@ namespace gui { $map_ui.log(L"Welcome to the game!"); $mini_map.init($main_ui.$overlay_ui.$gui); - $level.world->set($temp_loot, {}); - run_systems(); state(State::IDLE); @@ -344,7 +341,8 @@ namespace gui { autowalking = true; break; case KEY::L: - $loot_ui.set_target($temp_loot); + // This will go away as soon as containers work + $loot_ui.set_target($loot_ui.$temp_loot); $loot_ui.update(); event(Event::LOOT_OPEN); break; @@ -477,15 +475,12 @@ namespace gui { case eGUI::LOOT_ITEM: { dbc::check(world.has(entity), "INVALID LOOT_ITEM, that entity has no InventoryItem"); - fmt::println("in FSM LOOT_ITEM the entity is {}", entity); - System::place_in_container(*$level.world, $temp_loot, "item_0", entity); - $loot_ui.set_target($temp_loot); - $loot_ui.update(); + $loot_ui.add_loose_item(entity); event(Event::LOOT_ITEM); } break; case eGUI::LOOT_CONTAINER: { dbc::log("YEP container works."); - $loot_ui.set_target($temp_loot); + $loot_ui.set_target($loot_ui.$temp_loot); $loot_ui.update(); event(Event::LOOT_OPEN); } break; @@ -524,10 +519,6 @@ namespace gui { $levels.create_level($level.world); $level = $levels.next(); - // this has to go away, but clear out the inventory - $temp_loot = $level.world->entity(); - $level.world->set($temp_loot, {}); - $status_ui.update_level($level); $map_ui.update_level($level); $mini_map.update_level($level); diff --git a/gui/fsm.hpp b/gui/fsm.hpp index d43c1a7..6000820 100644 --- a/gui/fsm.hpp +++ b/gui/fsm.hpp @@ -49,7 +49,6 @@ namespace gui { sf::Font $font; gui::routing::Router $router; DNDLoot $dnd_loot; - DinkyECS::Entity $temp_loot; FSM(); diff --git a/gui/loot_ui.cpp b/gui/loot_ui.cpp index d8b19b8..6fe1f32 100644 --- a/gui/loot_ui.cpp +++ b/gui/loot_ui.cpp @@ -7,7 +7,9 @@ namespace gui { using namespace guecs; LootUI::LootUI(GameLevel level) : - $level(level) + $level(level), + $temp_loot($level.world->entity()), + $target($temp_loot) { $gui.position(RAY_VIEW_X+RAY_VIEW_WIDTH/2-200, RAY_VIEW_Y+RAY_VIEW_HEIGHT/2-200, 400, 400); @@ -17,8 +19,10 @@ namespace gui { "[item_4 | item_5 |item_6 | item_7 ]" "[item_8 | item_9 |item_10| item_11]" "[item_12| item_13|item_14|item_15 ]" - "[ =take_all | =close| =destroy]" - ); + "[ =take_all | =close| =destroy]"); + + $level.world->set($temp_loot, {}); + $level.world->make_constant($temp_loot); } void LootUI::make_button(const std::string &name, const std::wstring& label, Events::GUI event) { @@ -58,10 +62,8 @@ namespace gui { } void LootUI::update() { - if(!$level.world->has($target)) { - dbc::log("NO INV MODEL?!"); - return; - } + dbc::check($level.world->has($target), + "update called but $target isn't in world"); auto& contents = $level.world->get($target); @@ -119,7 +121,15 @@ namespace gui { init(); } + void LootUI::add_loose_item(DinkyECS::Entity entity) { + System::place_in_container(*$level.world, $temp_loot, "item_0", entity); + set_target($temp_loot); + update(); + } + bool LootUI::mouse(float x, float y, bool hover) { return $gui.mouse(x, y, hover); } + + } diff --git a/gui/loot_ui.hpp b/gui/loot_ui.hpp index 64ab48b..78fa631 100644 --- a/gui/loot_ui.hpp +++ b/gui/loot_ui.hpp @@ -14,6 +14,7 @@ namespace gui { guecs::UI $gui; GameLevel $level; std::unordered_map $slot_to_name; + DinkyECS::Entity $temp_loot; DinkyECS::Entity $target; LootUI(GameLevel level); @@ -31,5 +32,6 @@ namespace gui { void remove_slot(guecs::Entity slot_id); bool place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity); + void add_loose_item(DinkyECS::Entity entity); }; }