diff --git a/gui/dnd_loot.cpp b/gui/dnd_loot.cpp index b53e4f6..5db500f 100644 --- a/gui/dnd_loot.cpp +++ b/gui/dnd_loot.cpp @@ -111,10 +111,16 @@ namespace gui { dbc::check(worked, "Need to fix this, should be able to abort."); END(CLOSE); } break; - case INV_SELECT: - if(commit_move($status_ui.$gui, $grab_source, data)) { - END(CLOSE); - } + case INV_SELECT: { + auto drop_id = std::any_cast(data); + + if($status_ui.occupied(drop_id)) { + $status_ui.swap(*$grab_source, drop_id); + END(CLOSE); + } else if(commit_move($status_ui.$gui, $grab_source, data)) { + END(CLOSE); + } + } break; break; default: handle_mouse(ev, $status_ui.$gui); diff --git a/gui/status_ui.cpp b/gui/status_ui.cpp index 9a1e7f4..c88edfa 100644 --- a/gui/status_ui.cpp +++ b/gui/status_ui.cpp @@ -135,4 +135,25 @@ namespace gui { $gui.remove(slot_id); $gui.remove(slot_id); } + + void StatusUI::swap(guecs::Entity gui_a, guecs::Entity gui_b) { + if(gui_a != gui_b) { + auto& inventory = $level.world->get_the(); + auto& a_name = $slot_to_name.at(gui_a); + auto& b_name = $slot_to_name.at(gui_b); + auto a_ent = inventory.get(a_name); + auto b_ent = inventory.get(b_name); + inventory.swap(a_ent, b_ent); + } + + update(); + } + + bool StatusUI::occupied(guecs::Entity slot) { + dbc::check($slot_to_name.contains(slot), "jank ass slot to name thing isn't loaded right you idiot."); + + auto& inventory = $level.world->get_the(); + auto& slot_name = $slot_to_name.at(slot); + return inventory.has(slot_name); + } } diff --git a/gui/status_ui.hpp b/gui/status_ui.hpp index 5830efe..7df79c0 100644 --- a/gui/status_ui.hpp +++ b/gui/status_ui.hpp @@ -26,5 +26,8 @@ namespace gui { void remove_slot(guecs::Entity slot_id); bool place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity); bool drop_item(DinkyECS::Entity item_id); + + void swap(guecs::Entity gui_a, guecs::Entity gui_b); + bool occupied(guecs::Entity slot); }; }