Fix bag bar drag/drop with container bags

Allow equipped bags to be moved through the shared inventory pickup/drop flow, including dragging from bag contents to bag bar and back from bag bar into bag/backpack slots.

Changes:

- Add InventoryScreen APIs to begin pickup from an equipment slot and drop held item into a target equipment slot.

- Treat inventory type 18 (bags) as valid drops on BAG1-BAG4 during slot validation.

- Route equipment placement in online mode through swapContainerItems with explicit src/dst addressing for deterministic bag slot moves.

- Update bag bar hover-drop path to use InventoryScreen drop API instead of direct local slot mutation.

- On bag bar drag start, hand off to inventory held-item drag when inventory/character UI is open so drops into bag/backpack slots work.
This commit is contained in:
Kelsi 2026-02-20 17:41:19 -08:00
parent acb63d4f6e
commit 9a0415ad6b
3 changed files with 93 additions and 35 deletions

View file

@ -3670,10 +3670,10 @@ void GameScreen::renderBagBar(game::GameHandler& gameHandler) {
// Accept dragged item from inventory
if (hovered && inventoryScreen.isHoldingItem()) {
const auto& heldItem = inventoryScreen.getHeldItem();
if (heldItem.bagSlots > 0 && ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
if ((heldItem.inventoryType == 18 || heldItem.bagSlots > 0) &&
ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
auto& inventory = gameHandler.getInventory();
inventory.setEquipSlot(bagSlot, heldItem);
inventoryScreen.returnHeldItem(inventory);
inventoryScreen.dropHeldItemToEquipSlot(inventory, bagSlot);
}
}
@ -3685,8 +3685,20 @@ void GameScreen::renderBagBar(game::GameHandler& gameHandler) {
// releasing completes swap or click
if (bagBarDragSource_ >= 0) {
if (ImGui::IsMouseDragging(ImGuiMouseButton_Left, 3.0f) && bagBarPickedSlot_ < 0) {
// Mouse moved enough — start visual drag
bagBarPickedSlot_ = bagBarDragSource_;
// If an inventory window is open, hand off drag to inventory held-item
// so the bag can be dropped into backpack/bag slots.
if (inventoryScreen.isOpen() || inventoryScreen.isCharacterOpen()) {
auto equip = static_cast<game::EquipSlot>(
static_cast<int>(game::EquipSlot::BAG1) + bagBarDragSource_);
if (inventoryScreen.beginPickupFromEquipSlot(inv, equip)) {
bagBarDragSource_ = -1;
} else {
bagBarPickedSlot_ = bagBarDragSource_;
}
} else {
// Mouse moved enough — start visual drag
bagBarPickedSlot_ = bagBarDragSource_;
}
}
if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
if (bagBarPickedSlot_ >= 0) {