From 689bb150c601eac924fae9da58e263302e860960 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Tue, 24 Jun 2025 14:00:14 -0400 Subject: [PATCH] I think that's all the edge cases handled. You can more loot around fairly arbitrarily. --- gui/dnd_loot.cpp | 23 ++++++++++++++++------- gui/dnd_loot.hpp | 2 ++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/gui/dnd_loot.cpp b/gui/dnd_loot.cpp index 3dbd9c2..edce61c 100644 --- a/gui/dnd_loot.cpp +++ b/gui/dnd_loot.cpp @@ -61,8 +61,8 @@ namespace gui { END(Event::CLOSE); break; case LOOT_SELECT: - $grab_source = start_grab($loot_ui.$gui, data); - if($grab_source) state(DNDState::LOOTING); + commit_move($loot_ui.$gui, $grab_source, data); + state(DNDState::LOOTING); break; case INV_SELECT: if(commit_drop($loot_ui.$gui, @@ -91,7 +91,8 @@ namespace gui { } break; case INV_SELECT: - $grab_source = start_grab($status_ui.$gui, data); + // BUG: should I do a bool here and not transition? + commit_move($status_ui.$gui, $grab_source, data); state(DNDState::LOOTING); break; default: @@ -195,15 +196,19 @@ namespace gui { } } - void DNDLoot::open() { + // BUG: should I do this in the commit_ functions or in the FSM? + void DNDLoot::clear_grab() { $grab_source = std::nullopt; $grab_sprite = nullptr; + } + + void DNDLoot::open() { + clear_grab(); $loot_ui.active = true; } void DNDLoot::close() { - $grab_source = std::nullopt; - $grab_sprite = nullptr; + clear_grab(); $loot_ui.active = false; } @@ -242,6 +247,7 @@ namespace gui { if(drop.commit(grab.world_entity)) { grab.commit(); + clear_grab(); return true; } else { return false; @@ -256,6 +262,7 @@ namespace gui { auto& drop = gui.get(drop_id); drop.commit(grab.world_entity); + clear_grab(); // BUG: if the drop fails then need to put the grab back? // How to confirm the drop will work before doing it? // Or, maybe save the commit? @@ -269,6 +276,8 @@ namespace gui { dbc::check($grab_source != std::nullopt, "attempt to commit_drop but no grab_source set"); auto& grab = $status_ui.$gui.get(*$grab_source); grab.commit(); - return $status_ui.drop_item(grab.world_entity); + bool result = $status_ui.drop_item(grab.world_entity); + clear_grab(); + return result; } } diff --git a/gui/dnd_loot.hpp b/gui/dnd_loot.hpp index 94b9057..7e211ae 100644 --- a/gui/dnd_loot.hpp +++ b/gui/dnd_loot.hpp @@ -54,6 +54,8 @@ namespace gui { bool throw_on_floor(); + void clear_grab(); + sf::Vector2f mouse_position(); }; }