diff --git a/gui/dnd_loot.cpp b/gui/dnd_loot.cpp index fb99994..b53e4f6 100644 --- a/gui/dnd_loot.cpp +++ b/gui/dnd_loot.cpp @@ -62,8 +62,9 @@ namespace gui { END(CLOSE); break; case LOOT_SELECT: - commit_move($loot_ui.$gui, $grab_source, data); - state(DNDState::LOOTING); + if(commit_move($loot_ui.$gui, $grab_source, data)) { + state(DNDState::LOOTING); + } break; case INV_SELECT: if(commit_drop($loot_ui.$gui, @@ -92,9 +93,9 @@ namespace gui { } break; case INV_SELECT: - // BUG: should I do a bool here and not transition? - commit_move($status_ui.$gui, $grab_source, data); - state(DNDState::LOOTING); + if(commit_move($status_ui.$gui, $grab_source, data)) { + state(DNDState::LOOTING); + } break; default: handle_mouse(ev, $status_ui.$gui); @@ -111,8 +112,9 @@ namespace gui { END(CLOSE); } break; case INV_SELECT: - commit_move($status_ui.$gui, $grab_source, data); - END(CLOSE); + if(commit_move($status_ui.$gui, $grab_source, data)) { + END(CLOSE); + } break; default: handle_mouse(ev, $status_ui.$gui); @@ -228,8 +230,8 @@ namespace gui { dbc::check(source.has(*source_id), "gui does not have a GrabSource at that slot"); - auto& drop = target.get(target_id); auto& grab = source.get(*source_id); + auto& drop = target.get(target_id); if(drop.commit(grab.world_entity)) { grab.commit(); @@ -240,8 +242,9 @@ namespace gui { } } - void DNDLoot::commit_move(guecs::UI& gui, std::optional source_id, std::any data) { + bool DNDLoot::commit_move(guecs::UI& gui, std::optional source_id, std::any data) { dbc::check(source_id != std::nullopt, "source_id must exist"); + auto& grab = gui.get(*source_id); grab.commit(); @@ -250,13 +253,11 @@ namespace gui { if(drop.commit(grab.world_entity)) { clear_grab(); + return true; } else { - dbc::log("commit drop didn't happen"); + // swap with the target instead + return false; } - - // 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? } bool DNDLoot::hold_world_item() { diff --git a/gui/dnd_loot.hpp b/gui/dnd_loot.hpp index 68ed327..7ca64a5 100644 --- a/gui/dnd_loot.hpp +++ b/gui/dnd_loot.hpp @@ -49,7 +49,7 @@ namespace gui { bool commit_drop(guecs::UI& source, guecs::UI& target, std::optional source_id, std::any data); - void commit_move(guecs::UI& gui, + bool commit_move(guecs::UI& gui, std::optional source_id, std::any data); bool hold_world_item(); diff --git a/gui/loot_ui.cpp b/gui/loot_ui.cpp index 6fe1f32..f9c9239 100644 --- a/gui/loot_ui.cpp +++ b/gui/loot_ui.cpp @@ -131,5 +131,4 @@ namespace gui { return $gui.mouse(x, y, hover); } - } diff --git a/gui/status_ui.cpp b/gui/status_ui.cpp index 4e73fac..debf30b 100644 --- a/gui/status_ui.cpp +++ b/gui/status_ui.cpp @@ -104,8 +104,6 @@ namespace gui { auto& slot_name = $slot_to_name.at(gui_id); auto& inventory = $level.world->get_the(); - inventory.dump(); - if(inventory.add(slot_name, world_entity)) { $level.world->make_constant(world_entity); update();