diff --git a/Makefile b/Makefile index 77b1ba6..111d1ad 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ tracy_build: meson compile -j 10 -C builddir test: build - ./builddir/runtests + ./builddir/runtests "[inventory]" run: build test ifeq '$(OS)' 'Windows_NT' @@ -57,7 +57,7 @@ clean: meson compile --clean -C builddir debug_test: build - gdb --nx -x .gdbinit --ex run --args builddir/runtests -e + gdb --nx -x .gdbinit --ex run --args builddir/runtests -e "[inventory]" win_installer: powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp' diff --git a/gui/dnd_loot.cpp b/gui/dnd_loot.cpp index 5db500f..e4a8649 100644 --- a/gui/dnd_loot.cpp +++ b/gui/dnd_loot.cpp @@ -107,7 +107,8 @@ namespace gui { switch(ev) { case AIM_CLICK: { - bool worked = throw_on_floor(); + // take from inventory, drop on floor + bool worked = throw_on_floor($status_ui.$gui, true); dbc::check(worked, "Need to fix this, should be able to abort."); END(CLOSE); } break; @@ -137,12 +138,12 @@ namespace gui { END(CLOSE); } break; - case AIM_CLICK: - // BUG: because I put things into fake loot containers it's actually - // hard to put things back. It's probably a System::remove from the - // loot container combined with a System::drop_item - dbc::log("Put it back?"); - break; + case AIM_CLICK: { + // THIS IS PUT IT BACK ON THE FLOOR + bool worked = throw_on_floor($loot_ui.$gui, false); + dbc::check(worked, "Failed to drop it back on the floor."); + END(CLOSE); + } break; default: handle_mouse(ev, $loot_ui.$gui); } @@ -174,7 +175,7 @@ namespace gui { case TICK: // ignored break; default: - dbc::sentinel(fmt::format("invalid event: {}", int(ev))); + dbc::log(fmt::format("invalid event: {}", int(ev))); } } @@ -296,15 +297,22 @@ namespace gui { * Dropping on the ground is only possible from the * status_ui for now. */ - bool DNDLoot::throw_on_floor() { + bool DNDLoot::throw_on_floor(guecs::UI& gui, bool from_status) { dbc::check($grab_source != std::nullopt, "attempt to commit_drop but no grab_source set"); - dbc::check($status_ui.$gui.has(*$grab_source), + dbc::check(gui.has(*$grab_source), "StatusUI doesn't actually have that GrabSource in the gui."); - auto& grab = $status_ui.$gui.get(*$grab_source); + auto& grab = gui.get(*$grab_source); grab.commit(); - bool result = $status_ui.drop_item(grab.world_entity); + bool result = false; + + if(from_status) { + result = $status_ui.drop_item(grab.world_entity); + } else { + result = $loot_ui.drop_item(grab.world_entity); + } + clear_grab(); return result; } diff --git a/gui/dnd_loot.hpp b/gui/dnd_loot.hpp index 7ca64a5..922823c 100644 --- a/gui/dnd_loot.hpp +++ b/gui/dnd_loot.hpp @@ -54,7 +54,7 @@ namespace gui { bool hold_world_item(); bool hold_inv_item(std::any& data); - bool throw_on_floor(); + bool throw_on_floor(guecs::UI& gui, bool from_status); void clear_grab(); diff --git a/gui/fsm.cpp b/gui/fsm.cpp index c080988..6687018 100644 --- a/gui/fsm.cpp +++ b/gui/fsm.cpp @@ -463,15 +463,17 @@ namespace gui { case eGUI::INV_SELECT: event(Event::INV_SELECT, data); break; - case eGUI::AIM_CLICK: - if(auto aimed_at = $main_ui.camera_aim()) { - fmt::println("clicked on a thing: {}", aimed_at); - System::pickup($level, aimed_at); - } else { - fmt::println("SENDING AIM_CLICK"); - event(Event::AIM_CLICK); - } - break; + case eGUI::AIM_CLICK: { + auto aimed_at = $main_ui.camera_aim(); + + if(aimed_at && !in_state(State::LOOTING)) { + // aimed at something and not looting so it's a pickup + System::pickup($level, aimed_at); + } else { + // otherwise just repeat the event and let the FSM deal + event(Event::AIM_CLICK); + } + } break; case eGUI::LOOT_ITEM: { dbc::check(world.has(entity), "INVALID LOOT_ITEM, that entity has no InventoryItem"); diff --git a/gui/loot_ui.cpp b/gui/loot_ui.cpp index f9c9239..664ea6e 100644 --- a/gui/loot_ui.cpp +++ b/gui/loot_ui.cpp @@ -127,8 +127,13 @@ namespace gui { update(); } + bool LootUI::drop_item(DinkyECS::Entity item_id) { + bool dropped = System::drop_item($level, item_id); + if(dropped) update(); + return dropped; + } + 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 78fa631..4727ff3 100644 --- a/gui/loot_ui.hpp +++ b/gui/loot_ui.hpp @@ -33,5 +33,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); + bool drop_item(DinkyECS::Entity item_id); }; }