diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-07-03 21:20:31 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-07-03 21:20:31 +0300 |
commit | cb573ac24373a908ff549c35c3a80dd31b2fdea5 (patch) | |
tree | e63d24c33a760fc6d408a09900fc1e02dc603c00 /src | |
parent | a1bd0179b28fa93c771bc5602f64746878f0ffad (diff) | |
download | plus-cb573ac24373a908ff549c35c3a80dd31b2fdea5.tar.gz plus-cb573ac24373a908ff549c35c3a80dd31b2fdea5.tar.bz2 plus-cb573ac24373a908ff549c35c3a80dd31b2fdea5.tar.xz plus-cb573ac24373a908ff549c35c3a80dd31b2fdea5.zip |
add drag and drop support between inventory and storage.
Diffstat (limited to 'src')
-rw-r--r-- | src/dragdrop.h | 9 | ||||
-rw-r--r-- | src/gui/widgets/itemcontainer.cpp | 69 | ||||
-rw-r--r-- | src/gui/widgets/itemcontainer.h | 2 | ||||
-rw-r--r-- | src/net/ea/inventoryhandler.h | 3 | ||||
-rw-r--r-- | src/net/inventoryhandler.h | 2 | ||||
-rw-r--r-- | src/playerinfo.cpp | 6 | ||||
-rw-r--r-- | src/playerinfo.h | 2 |
7 files changed, 69 insertions, 24 deletions
diff --git a/src/dragdrop.h b/src/dragdrop.h index e58263cc9..4ca9a2bc3 100644 --- a/src/dragdrop.h +++ b/src/dragdrop.h @@ -57,7 +57,7 @@ class DragDrop mSelItemColor(1), mSource(source), mText(), - mTag() + mTag(-1) { if (mItemImage) mItemImage->incRef(); @@ -107,7 +107,7 @@ class DragDrop mItemColor = 1; mItemImage = nullptr; mSource = DRAGDROP_SOURCE_EMPTY; - mTag = 0; + mTag = -1; } } @@ -131,7 +131,7 @@ class DragDrop else if (mText.empty()) { mSource = source; - mTag = 0; + mTag = -1; return; } mItem = command->getId(); @@ -156,7 +156,7 @@ class DragDrop mText.clear(); mItemImage = nullptr; mSource = DRAGDROP_SOURCE_EMPTY; - mTag = 0; + mTag = -1; if (info) { const SkillData *const data = info->data; @@ -182,6 +182,7 @@ class DragDrop mItemImage = nullptr; mSource = DRAGDROP_SOURCE_EMPTY; mText.clear(); + mTag = -1; } bool isEmpty() const diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index 972c066ac..11b9401ff 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -23,10 +23,11 @@ #include "gui/widgets/itemcontainer.h" #include "dragdrop.h" +#include "dropshortcut.h" #include "inventory.h" #include "item.h" #include "itemshortcut.h" -#include "dropshortcut.h" +#include "playerinfo.h" #include "gui/chatwindow.h" #include "gui/gui.h" @@ -172,8 +173,6 @@ ItemContainer::ItemContainer(const Widget2 *const widget, mForceQuantity(forceQuantity), mSwapItems(false), mDescItems(false), - mDragPosX(0), - mDragPosY(0), mTag(0), mSortType(0), mName(), @@ -401,9 +400,11 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event) if (item && mDescItems && chatWindow) chatWindow->addItemText(item->getInfo().getName()); + const DragDropSource src = mInventory->isMainInventory() + ? DRAGDROP_SOURCE_INVENTORY : DRAGDROP_SOURCE_STORAGE; if (mSelectedIndex == index && mClicks != 2) { - dragDrop.dragItem(item, DRAGDROP_SOURCE_INVENTORY); + dragDrop.dragItem(item, src, index); dragDrop.select(item); mSelectionStatus = SEL_DESELECTING; } @@ -411,7 +412,7 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event) { if (index >= 0) { - dragDrop.dragItem(item, DRAGDROP_SOURCE_INVENTORY); + dragDrop.dragItem(item, src, index); dragDrop.select(item); setSelectedIndex(index); mSelectionStatus = SEL_SELECTING; @@ -440,11 +441,7 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event) void ItemContainer::mouseDragged(gcn::MouseEvent &event) { if (mSelectionStatus != SEL_NONE) - { mSelectionStatus = SEL_DRAGGING; - mDragPosX = event.getX(); - mDragPosY = event.getY(); - } } void ItemContainer::mouseReleased(gcn::MouseEvent &event) @@ -456,25 +453,61 @@ void ItemContainer::mouseReleased(gcn::MouseEvent &event) { case SEL_SELECTING: mSelectionStatus = SEL_SELECTED; - return; + break; case SEL_DESELECTING: selectNone(); - return; + break; case SEL_DRAGGING: mSelectionStatus = SEL_SELECTED; break; case SEL_NONE: case SEL_SELECTED: default: - return; + break; }; - const int index = getSlotIndex(event.getX(), event.getY()); - if (index == Inventory::NO_SLOT_INDEX) - return; - if (index == mSelectedIndex || mSelectedIndex == -1) - return; - Net::getInventoryHandler()->moveItem(mSelectedIndex, index); + if (dragDrop.isEmpty()) + { + const int index = getSlotIndex(event.getX(), event.getY()); + if (index == Inventory::NO_SLOT_INDEX) + return; + if (index == mSelectedIndex || mSelectedIndex == -1) + return; + Net::getInventoryHandler()->moveItem(mSelectedIndex, index); + } + else + { + const DragDropSource src = dragDrop.getSource(); + const DragDropSource dst = mInventory->isMainInventory() + ? DRAGDROP_SOURCE_INVENTORY : DRAGDROP_SOURCE_STORAGE; + int srcContainer = -1; + int dstContainer = -1; + Inventory *inventory = nullptr; + if (src == DRAGDROP_SOURCE_INVENTORY + && dst == DRAGDROP_SOURCE_STORAGE) + { + srcContainer = Inventory::INVENTORY; + dstContainer = Inventory::STORAGE; + inventory = PlayerInfo::getInventory(); + } + else if (src == DRAGDROP_SOURCE_STORAGE + && dst == DRAGDROP_SOURCE_INVENTORY) + { + srcContainer = Inventory::STORAGE; + dstContainer = Inventory::INVENTORY; + inventory = PlayerInfo::getStorageInventory(); + } + if (srcContainer != -1 && inventory) + { + const Item *const item = inventory->getItem(dragDrop.getTag()); + if (item) + { + Net::getInventoryHandler()->moveItem2(srcContainer, + item->getInvIndex(), item->getQuantity(), dstContainer); + } + } + } + selectNone(); } diff --git a/src/gui/widgets/itemcontainer.h b/src/gui/widgets/itemcontainer.h index a422e654d..3358b113c 100644 --- a/src/gui/widgets/itemcontainer.h +++ b/src/gui/widgets/itemcontainer.h @@ -201,8 +201,6 @@ class ItemContainer final : public gcn::Widget, bool mForceQuantity; bool mSwapItems; bool mDescItems; - int mDragPosX; - int mDragPosY; int mTag; int mSortType; std::string mName; diff --git a/src/net/ea/inventoryhandler.h b/src/net/ea/inventoryhandler.h index 2497d9dd5..b21ba2fbc 100644 --- a/src/net/ea/inventoryhandler.h +++ b/src/net/ea/inventoryhandler.h @@ -201,6 +201,9 @@ class InventoryHandler : public Net::InventoryHandler void processPlayerArrowEquip(Net::MessageIn &msg); + Inventory *getStorage() const + { return mStorage; } + protected: EquipBackend mEquips; InventoryItems mInventoryItems; diff --git a/src/net/inventoryhandler.h b/src/net/inventoryhandler.h index 97a88ca04..a8443d691 100644 --- a/src/net/inventoryhandler.h +++ b/src/net/inventoryhandler.h @@ -65,6 +65,8 @@ class InventoryHandler virtual size_t getSize(const int type) const A_WARN_UNUSED = 0; + virtual Inventory *getStorage() const = 0; + virtual int convertFromServerSlot(const int eAthenaSlot) const = 0; }; diff --git a/src/playerinfo.cpp b/src/playerinfo.cpp index 4e780f4df..eb48c4b30 100644 --- a/src/playerinfo.cpp +++ b/src/playerinfo.cpp @@ -34,6 +34,7 @@ #include "resources/iteminfo.h" +#include "net/inventoryhandler.h" #include "net/playerhandler.h" #include "debug.h" @@ -202,6 +203,11 @@ Inventory *getInventory() return mInventory; } +Inventory *getStorageInventory() +{ + return Net::getInventoryHandler()->getStorage(); +} + void clearInventory() { if (mEquipment) diff --git a/src/playerinfo.h b/src/playerinfo.h index 6a1a25f81..1c6cbc353 100644 --- a/src/playerinfo.h +++ b/src/playerinfo.h @@ -176,6 +176,8 @@ namespace PlayerInfo */ Inventory *getInventory() A_WARN_UNUSED; + Inventory *getStorageInventory() A_WARN_UNUSED; + /** * Clears the player's inventory and equipment. */ |