Move the management of the 'fake loose items container' into the loot_ui.cpp rather than get rid of it. Closes #34.

master
Zed A. Shaw 16 hours ago
parent efdb0cb119
commit b6d1ae2700
  1. 2
      gui/dnd_loot.cpp
  2. 19
      gui/fsm.cpp
  3. 1
      gui/fsm.hpp
  4. 24
      gui/loot_ui.cpp
  5. 2
      gui/loot_ui.hpp

@ -222,8 +222,6 @@ namespace gui {
{
if(!source_id) return false;
auto target_id = std::any_cast<guecs::Entity>(data);
fmt::println("!!!!!!!!!source_id = {} target_id = {}",
*source_id, target_id);
dbc::check(target.has<guecs::DropTarget>(target_id),
"gui does not have a DropTarget at that slot");

@ -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<inventory::Model>($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<components::InventoryItem>(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<inventory::Model>($temp_loot, {});
$status_ui.update_level($level);
$map_ui.update_level($level);
$mini_map.update_level($level);

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

@ -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<inventory::Model>($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<inventory::Model>($target)) {
dbc::log("NO INV MODEL?!");
return;
}
dbc::check($level.world->has<inventory::Model>($target),
"update called but $target isn't in world");
auto& contents = $level.world->get<inventory::Model>($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);
}
}

@ -14,6 +14,7 @@ namespace gui {
guecs::UI $gui;
GameLevel $level;
std::unordered_map<guecs::Entity, std::string> $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);
};
}

Loading…
Cancel
Save